Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * huffyuv codec for libavcodec | ||
3 | * | ||
4 | * Copyright (c) 2002-2014 Michael Niedermayer <michaelni@gmx.at> | ||
5 | * | ||
6 | * see https://multimedia.cx/huffyuv.txt for a description of | ||
7 | * the algorithm used | ||
8 | * | ||
9 | * This file is part of FFmpeg. | ||
10 | * | ||
11 | * FFmpeg is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU Lesser General Public | ||
13 | * License as published by the Free Software Foundation; either | ||
14 | * version 2.1 of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * FFmpeg is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | * Lesser General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU Lesser General Public | ||
22 | * License along with FFmpeg; if not, write to the Free Software | ||
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
24 | */ | ||
25 | |||
26 | /** | ||
27 | * @file | ||
28 | * huffyuv codec for libavcodec. | ||
29 | */ | ||
30 | |||
31 | #include <stddef.h> | ||
32 | #include <stdint.h> | ||
33 | |||
34 | #include "libavutil/error.h" | ||
35 | #include "libavutil/log.h" | ||
36 | #include "libavutil/macros.h" | ||
37 | |||
38 | #include "huffyuv.h" | ||
39 | |||
40 | 351 | int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table, int n) | |
41 | { | ||
42 | 351 | int lens[33] = { 0 }; | |
43 | uint32_t codes[33]; | ||
44 | |||
45 |
2/2✓ Branch 0 taken 836352 times.
✓ Branch 1 taken 351 times.
|
836703 | for (int i = 0; i < n; i++) |
46 | 836352 | lens[len_table[i]]++; | |
47 | |||
48 | 351 | codes[32] = 0; | |
49 |
2/2✓ Branch 0 taken 11232 times.
✓ Branch 1 taken 351 times.
|
11583 | for (int i = FF_ARRAY_ELEMS(lens) - 1; i > 0; i--) { |
50 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11232 times.
|
11232 | if ((lens[i] + codes[i]) & 1) { |
51 | ✗ | av_log(NULL, AV_LOG_ERROR, "Error generating huffman table\n"); | |
52 | ✗ | return AVERROR_INVALIDDATA; | |
53 | } | ||
54 | 11232 | codes[i - 1] = (lens[i] + codes[i]) >> 1; | |
55 | } | ||
56 |
2/2✓ Branch 0 taken 836352 times.
✓ Branch 1 taken 351 times.
|
836703 | for (int i = 0; i < n; i++) { |
57 |
1/2✓ Branch 0 taken 836352 times.
✗ Branch 1 not taken.
|
836352 | if (len_table[i]) |
58 | 836352 | dst[i] = codes[len_table[i]]++; | |
59 | } | ||
60 | 351 | return 0; | |
61 | } | ||
62 |