Directory: | ../../../ffmpeg/ |
---|---|
File: | src/libavcodec/huffyuvdec.c |
Date: | 2022-07-07 01:21:54 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 388 | 749 | 51.8% |
Branches: | 320 | 587 | 54.5% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * huffyuv decoder | ||
3 | * | ||
4 | * Copyright (c) 2002-2014 Michael Niedermayer <michaelni@gmx.at> | ||
5 | * | ||
6 | * see http://www.pcisys.net/~melanson/codecs/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 | * yuva, gray, 4:4:4, 4:1:1, 4:1:0 and >8 bit per sample support sponsored by NOA | ||
26 | */ | ||
27 | |||
28 | /** | ||
29 | * @file | ||
30 | * huffyuv decoder | ||
31 | */ | ||
32 | |||
33 | #define UNCHECKED_BITSTREAM_READER 1 | ||
34 | |||
35 | #include "config_components.h" | ||
36 | |||
37 | #include "avcodec.h" | ||
38 | #include "codec_internal.h" | ||
39 | #include "get_bits.h" | ||
40 | #include "huffyuv.h" | ||
41 | #include "huffyuvdsp.h" | ||
42 | #include "lossless_videodsp.h" | ||
43 | #include "thread.h" | ||
44 | #include "libavutil/imgutils.h" | ||
45 | #include "libavutil/pixdesc.h" | ||
46 | |||
47 | #define classic_shift_luma_table_size 42 | ||
48 | static const unsigned char classic_shift_luma[classic_shift_luma_table_size + AV_INPUT_BUFFER_PADDING_SIZE] = { | ||
49 | 34, 36, 35, 69, 135, 232, 9, 16, 10, 24, 11, 23, 12, 16, 13, 10, | ||
50 | 14, 8, 15, 8, 16, 8, 17, 20, 16, 10, 207, 206, 205, 236, 11, 8, | ||
51 | 10, 21, 9, 23, 8, 8, 199, 70, 69, 68, 0, | ||
52 | 0,0,0,0,0,0,0,0, | ||
53 | }; | ||
54 | |||
55 | #define classic_shift_chroma_table_size 59 | ||
56 | static const unsigned char classic_shift_chroma[classic_shift_chroma_table_size + AV_INPUT_BUFFER_PADDING_SIZE] = { | ||
57 | 66, 36, 37, 38, 39, 40, 41, 75, 76, 77, 110, 239, 144, 81, 82, 83, | ||
58 | 84, 85, 118, 183, 56, 57, 88, 89, 56, 89, 154, 57, 58, 57, 26, 141, | ||
59 | 57, 56, 58, 57, 58, 57, 184, 119, 214, 245, 116, 83, 82, 49, 80, 79, | ||
60 | 78, 77, 44, 75, 41, 40, 39, 38, 37, 36, 34, 0, | ||
61 | 0,0,0,0,0,0,0,0, | ||
62 | }; | ||
63 | |||
64 | static const unsigned char classic_add_luma[256] = { | ||
65 | 3, 9, 5, 12, 10, 35, 32, 29, 27, 50, 48, 45, 44, 41, 39, 37, | ||
66 | 73, 70, 68, 65, 64, 61, 58, 56, 53, 50, 49, 46, 44, 41, 38, 36, | ||
67 | 68, 65, 63, 61, 58, 55, 53, 51, 48, 46, 45, 43, 41, 39, 38, 36, | ||
68 | 35, 33, 32, 30, 29, 27, 26, 25, 48, 47, 46, 44, 43, 41, 40, 39, | ||
69 | 37, 36, 35, 34, 32, 31, 30, 28, 27, 26, 24, 23, 22, 20, 19, 37, | ||
70 | 35, 34, 33, 31, 30, 29, 27, 26, 24, 23, 21, 20, 18, 17, 15, 29, | ||
71 | 27, 26, 24, 22, 21, 19, 17, 16, 14, 26, 25, 23, 21, 19, 18, 16, | ||
72 | 15, 27, 25, 23, 21, 19, 17, 16, 14, 26, 25, 23, 21, 18, 17, 14, | ||
73 | 12, 17, 19, 13, 4, 9, 2, 11, 1, 7, 8, 0, 16, 3, 14, 6, | ||
74 | 12, 10, 5, 15, 18, 11, 10, 13, 15, 16, 19, 20, 22, 24, 27, 15, | ||
75 | 18, 20, 22, 24, 26, 14, 17, 20, 22, 24, 27, 15, 18, 20, 23, 25, | ||
76 | 28, 16, 19, 22, 25, 28, 32, 36, 21, 25, 29, 33, 38, 42, 45, 49, | ||
77 | 28, 31, 34, 37, 40, 42, 44, 47, 49, 50, 52, 54, 56, 57, 59, 60, | ||
78 | 62, 64, 66, 67, 69, 35, 37, 39, 40, 42, 43, 45, 47, 48, 51, 52, | ||
79 | 54, 55, 57, 59, 60, 62, 63, 66, 67, 69, 71, 72, 38, 40, 42, 43, | ||
80 | 46, 47, 49, 51, 26, 28, 30, 31, 33, 34, 18, 19, 11, 13, 7, 8, | ||
81 | }; | ||
82 | |||
83 | static const unsigned char classic_add_chroma[256] = { | ||
84 | 3, 1, 2, 2, 2, 2, 3, 3, 7, 5, 7, 5, 8, 6, 11, 9, | ||
85 | 7, 13, 11, 10, 9, 8, 7, 5, 9, 7, 6, 4, 7, 5, 8, 7, | ||
86 | 11, 8, 13, 11, 19, 15, 22, 23, 20, 33, 32, 28, 27, 29, 51, 77, | ||
87 | 43, 45, 76, 81, 46, 82, 75, 55, 56, 144, 58, 80, 60, 74, 147, 63, | ||
88 | 143, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, | ||
89 | 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 27, 30, 21, 22, | ||
90 | 17, 14, 5, 6, 100, 54, 47, 50, 51, 53, 106, 107, 108, 109, 110, 111, | ||
91 | 112, 113, 114, 115, 4, 117, 118, 92, 94, 121, 122, 3, 124, 103, 2, 1, | ||
92 | 0, 129, 130, 131, 120, 119, 126, 125, 136, 137, 138, 139, 140, 141, 142, 134, | ||
93 | 135, 132, 133, 104, 64, 101, 62, 57, 102, 95, 93, 59, 61, 28, 97, 96, | ||
94 | 52, 49, 48, 29, 32, 25, 24, 46, 23, 98, 45, 44, 43, 20, 42, 41, | ||
95 | 19, 18, 99, 40, 15, 39, 38, 16, 13, 12, 11, 37, 10, 9, 8, 36, | ||
96 | 7, 128, 127, 105, 123, 116, 35, 34, 33, 145, 31, 79, 42, 146, 78, 26, | ||
97 | 83, 48, 49, 50, 44, 47, 26, 31, 30, 18, 17, 19, 21, 24, 25, 13, | ||
98 | 14, 16, 17, 18, 20, 21, 12, 14, 15, 9, 10, 6, 9, 6, 5, 8, | ||
99 | 6, 12, 8, 10, 7, 9, 6, 4, 6, 2, 2, 3, 3, 3, 3, 2, | ||
100 | }; | ||
101 | |||
102 | 255 | static int read_len_table(uint8_t *dst, GetBitContext *gb, int n) | |
103 | { | ||
104 | int i, val, repeat; | ||
105 | |||
106 |
2/2✓ Branch 0 taken 9327 times.
✓ Branch 1 taken 255 times.
|
9582 | for (i = 0; i < n;) { |
107 | 9327 | repeat = get_bits(gb, 3); | |
108 | 9327 | val = get_bits(gb, 5); | |
109 |
2/2✓ Branch 0 taken 5055 times.
✓ Branch 1 taken 4272 times.
|
9327 | if (repeat == 0) |
110 | 5055 | repeat = get_bits(gb, 8); | |
111 |
2/4✓ Branch 0 taken 9327 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 9327 times.
|
9327 | if (i + repeat > n || get_bits_left(gb) < 0) { |
112 | ✗ | av_log(NULL, AV_LOG_ERROR, "Error reading huffman table\n"); | |
113 | ✗ | return AVERROR_INVALIDDATA; | |
114 | } | ||
115 |
2/2✓ Branch 0 taken 562944 times.
✓ Branch 1 taken 9327 times.
|
572271 | while (repeat--) |
116 | 562944 | dst[i++] = val; | |
117 | } | ||
118 | 255 | return 0; | |
119 | } | ||
120 | |||
121 | 85 | static int generate_joint_tables(HYuvContext *s) | |
122 | { | ||
123 | int ret; | ||
124 | 85 | uint16_t *symbols = av_mallocz(5 << VLC_BITS); | |
125 | uint16_t *bits; | ||
126 | uint8_t *len; | ||
127 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 85 times.
|
85 | if (!symbols) |
128 | ✗ | return AVERROR(ENOMEM); | |
129 | 85 | bits = symbols + (1 << VLC_BITS); | |
130 | 85 | len = (uint8_t *)(bits + (1 << VLC_BITS)); | |
131 | |||
132 |
3/4✓ Branch 0 taken 16 times.
✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
|
154 | if (s->bitstream_bpp < 24 || s->version > 2) { |
133 | int p, i, y, u; | ||
134 |
2/2✓ Branch 0 taken 276 times.
✓ Branch 1 taken 69 times.
|
345 | for (p = 0; p < 4; p++) { |
135 |
2/2✓ Branch 0 taken 128 times.
✓ Branch 1 taken 148 times.
|
276 | int p0 = s->version > 2 ? p : 0; |
136 |
2/2✓ Branch 0 taken 734208 times.
✓ Branch 1 taken 276 times.
|
734484 | for (i = y = 0; y < s->vlc_n; y++) { |
137 | 734208 | int len0 = s->len[p0][y]; | |
138 | 734208 | int limit = VLC_BITS - len0; | |
139 |
4/4✓ Branch 0 taken 189916 times.
✓ Branch 1 taken 544292 times.
✓ Branch 2 taken 174080 times.
✓ Branch 3 taken 15836 times.
|
734208 | if (limit <= 0 || !len0) |
140 | 718372 | continue; | |
141 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15836 times.
|
15836 | if ((sign_extend(y, 8) & (s->vlc_n-1)) != y) |
142 | ✗ | continue; | |
143 |
2/2✓ Branch 0 taken 36015104 times.
✓ Branch 1 taken 15836 times.
|
36030940 | for (u = 0; u < s->vlc_n; u++) { |
144 | 36015104 | int len1 = s->len[p][u]; | |
145 |
4/4✓ Branch 0 taken 692951 times.
✓ Branch 1 taken 35322153 times.
✓ Branch 2 taken 615680 times.
✓ Branch 3 taken 77271 times.
|
36015104 | if (len1 > limit || !len1) |
146 | 35937833 | continue; | |
147 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 77271 times.
|
77271 | if ((sign_extend(u, 8) & (s->vlc_n-1)) != u) |
148 | ✗ | continue; | |
149 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 77271 times.
|
77271 | av_assert0(i < (1 << VLC_BITS)); |
150 | 77271 | len[i] = len0 + len1; | |
151 | 77271 | bits[i] = (s->bits[p0][y] << len1) + s->bits[p][u]; | |
152 | 77271 | symbols[i] = (y << 8) + (u & 0xFF); | |
153 | 77271 | i++; | |
154 | } | ||
155 | } | ||
156 | 276 | ff_free_vlc(&s->vlc[4 + p]); | |
157 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 276 times.
|
276 | if ((ret = ff_init_vlc_sparse(&s->vlc[4 + p], VLC_BITS, i, len, 1, 1, |
158 | bits, 2, 2, symbols, 2, 2, 0)) < 0) | ||
159 | ✗ | goto out; | |
160 | } | ||
161 | } else { | ||
162 | 16 | uint8_t (*map)[4] = (uint8_t(*)[4]) s->pix_bgr_map; | |
163 | int i, b, g, r, code; | ||
164 | 16 | int p0 = s->decorrelate; | |
165 | 16 | int p1 = !s->decorrelate; | |
166 | /* Restrict the range to +/-16 because that's pretty much guaranteed | ||
167 | * to cover all the combinations that fit in 11 bits total, and it | ||
168 | * does not matter if we miss a few rare codes. */ | ||
169 |
2/2✓ Branch 0 taken 512 times.
✓ Branch 1 taken 16 times.
|
528 | for (i = 0, g = -16; g < 16; g++) { |
170 | 512 | int len0 = s->len[p0][g & 255]; | |
171 | 512 | int limit0 = VLC_BITS - len0; | |
172 |
2/4✓ Branch 0 taken 512 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 512 times.
|
512 | if (limit0 < 2 || !len0) |
173 | ✗ | continue; | |
174 |
2/2✓ Branch 0 taken 16384 times.
✓ Branch 1 taken 512 times.
|
16896 | for (b = -16; b < 16; b++) { |
175 | 16384 | int len1 = s->len[p1][b & 255]; | |
176 | 16384 | int limit1 = limit0 - len1; | |
177 |
3/4✓ Branch 0 taken 3728 times.
✓ Branch 1 taken 12656 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3728 times.
|
16384 | if (limit1 < 1 || !len1) |
178 | 12656 | continue; | |
179 | 3728 | code = (s->bits[p0][g & 255] << len1) + s->bits[p1][b & 255]; | |
180 |
2/2✓ Branch 0 taken 119296 times.
✓ Branch 1 taken 3728 times.
|
123024 | for (r = -16; r < 16; r++) { |
181 | 119296 | int len2 = s->len[2][r & 255]; | |
182 |
3/4✓ Branch 0 taken 10928 times.
✓ Branch 1 taken 108368 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10928 times.
|
119296 | if (len2 > limit1 || !len2) |
183 | 108368 | continue; | |
184 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10928 times.
|
10928 | av_assert0(i < (1 << VLC_BITS)); |
185 | 10928 | len[i] = len0 + len1 + len2; | |
186 | 10928 | bits[i] = (code << len2) + s->bits[2][r & 255]; | |
187 |
1/2✓ Branch 0 taken 10928 times.
✗ Branch 1 not taken.
|
10928 | if (s->decorrelate) { |
188 | 10928 | map[i][G] = g; | |
189 | 10928 | map[i][B] = g + b; | |
190 | 10928 | map[i][R] = g + r; | |
191 | } else { | ||
192 | ✗ | map[i][B] = g; | |
193 | ✗ | map[i][G] = b; | |
194 | ✗ | map[i][R] = r; | |
195 | } | ||
196 | 10928 | i++; | |
197 | } | ||
198 | } | ||
199 | } | ||
200 | 16 | ff_free_vlc(&s->vlc[4]); | |
201 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
|
16 | if ((ret = init_vlc(&s->vlc[4], VLC_BITS, i, len, 1, 1, |
202 | bits, 2, 2, 0)) < 0) | ||
203 | ✗ | goto out; | |
204 | } | ||
205 | 85 | ret = 0; | |
206 | 85 | out: | |
207 | 85 | av_freep(&symbols); | |
208 | 85 | return ret; | |
209 | } | ||
210 | |||
211 | 85 | static int read_huffman_tables(HYuvContext *s, const uint8_t *src, int length) | |
212 | { | ||
213 | GetBitContext gb; | ||
214 | int i, ret; | ||
215 | 85 | int count = 3; | |
216 | |||
217 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 85 times.
|
85 | if ((ret = init_get_bits(&gb, src, length * 8)) < 0) |
218 | ✗ | return ret; | |
219 | |||
220 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 53 times.
|
85 | if (s->version > 2) |
221 | 32 | count = 1 + s->alpha + 2*s->chroma; | |
222 | |||
223 |
2/2✓ Branch 0 taken 255 times.
✓ Branch 1 taken 85 times.
|
340 | for (i = 0; i < count; i++) { |
224 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 255 times.
|
255 | if ((ret = read_len_table(s->len[i], &gb, s->vlc_n)) < 0) |
225 | ✗ | return ret; | |
226 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 255 times.
|
255 | if ((ret = ff_huffyuv_generate_bits_table(s->bits[i], s->len[i], s->vlc_n)) < 0) |
227 | ✗ | return ret; | |
228 | 255 | ff_free_vlc(&s->vlc[i]); | |
229 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 255 times.
|
255 | if ((ret = init_vlc(&s->vlc[i], VLC_BITS, s->vlc_n, s->len[i], 1, 1, |
230 | s->bits[i], 4, 4, 0)) < 0) | ||
231 | ✗ | return ret; | |
232 | } | ||
233 | |||
234 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 85 times.
|
85 | if ((ret = generate_joint_tables(s)) < 0) |
235 | ✗ | return ret; | |
236 | |||
237 | 85 | return (get_bits_count(&gb) + 7) / 8; | |
238 | } | ||
239 | |||
240 | ✗ | static int read_old_huffman_tables(HYuvContext *s) | |
241 | { | ||
242 | GetBitContext gb; | ||
243 | int i, ret; | ||
244 | |||
245 | ✗ | init_get_bits(&gb, classic_shift_luma, | |
246 | classic_shift_luma_table_size * 8); | ||
247 | ✗ | if ((ret = read_len_table(s->len[0], &gb, 256)) < 0) | |
248 | ✗ | return ret; | |
249 | |||
250 | ✗ | init_get_bits(&gb, classic_shift_chroma, | |
251 | classic_shift_chroma_table_size * 8); | ||
252 | ✗ | if ((ret = read_len_table(s->len[1], &gb, 256)) < 0) | |
253 | ✗ | return ret; | |
254 | |||
255 | ✗ | for (i = 0; i < 256; i++) | |
256 | ✗ | s->bits[0][i] = classic_add_luma[i]; | |
257 | ✗ | for (i = 0; i < 256; i++) | |
258 | ✗ | s->bits[1][i] = classic_add_chroma[i]; | |
259 | |||
260 | ✗ | if (s->bitstream_bpp >= 24) { | |
261 | ✗ | memcpy(s->bits[1], s->bits[0], 256 * sizeof(uint32_t)); | |
262 | ✗ | memcpy(s->len[1], s->len[0], 256 * sizeof(uint8_t)); | |
263 | } | ||
264 | ✗ | memcpy(s->bits[2], s->bits[1], 256 * sizeof(uint32_t)); | |
265 | ✗ | memcpy(s->len[2], s->len[1], 256 * sizeof(uint8_t)); | |
266 | |||
267 | ✗ | for (i = 0; i < 4; i++) { | |
268 | ✗ | ff_free_vlc(&s->vlc[i]); | |
269 | ✗ | if ((ret = init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, | |
270 | s->bits[i], 4, 4, 0)) < 0) | ||
271 | ✗ | return ret; | |
272 | } | ||
273 | |||
274 | ✗ | if ((ret = generate_joint_tables(s)) < 0) | |
275 | ✗ | return ret; | |
276 | |||
277 | ✗ | return 0; | |
278 | } | ||
279 | |||
280 | 85 | static av_cold int decode_end(AVCodecContext *avctx) | |
281 | { | ||
282 | 85 | HYuvContext *s = avctx->priv_data; | |
283 | int i; | ||
284 | |||
285 | 85 | ff_huffyuv_common_end(s); | |
286 | 85 | av_freep(&s->bitstream_buffer); | |
287 | |||
288 |
2/2✓ Branch 0 taken 680 times.
✓ Branch 1 taken 85 times.
|
765 | for (i = 0; i < 8; i++) |
289 | 680 | ff_free_vlc(&s->vlc[i]); | |
290 | |||
291 | 85 | return 0; | |
292 | } | ||
293 | |||
294 | 85 | static av_cold int decode_init(AVCodecContext *avctx) | |
295 | { | ||
296 | 85 | HYuvContext *s = avctx->priv_data; | |
297 | int ret; | ||
298 | |||
299 | 85 | ret = av_image_check_size(avctx->width, avctx->height, 0, avctx); | |
300 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 85 times.
|
85 | if (ret < 0) |
301 | ✗ | return ret; | |
302 | |||
303 | 85 | ff_huffyuvdsp_init(&s->hdsp, avctx->pix_fmt); | |
304 | 85 | ff_llviddsp_init(&s->llviddsp); | |
305 | 85 | memset(s->vlc, 0, 4 * sizeof(VLC)); | |
306 | |||
307 | 85 | s->interlaced = avctx->height > 288; | |
308 | 85 | s->bgr32 = 1; | |
309 | |||
310 |
1/2✓ Branch 0 taken 85 times.
✗ Branch 1 not taken.
|
85 | if (avctx->extradata_size) { |
311 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 57 times.
|
85 | if ((avctx->bits_per_coded_sample & 7) && |
312 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | avctx->bits_per_coded_sample != 12) |
313 | ✗ | s->version = 1; // do such files exist at all? | |
314 |
3/4✓ Branch 0 taken 85 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 53 times.
✓ Branch 3 taken 32 times.
|
85 | else if (avctx->extradata_size > 3 && avctx->extradata[3] == 0) |
315 | 53 | s->version = 2; | |
316 | else | ||
317 | 32 | s->version = 3; | |
318 | } else | ||
319 | ✗ | s->version = 0; | |
320 | |||
321 | 85 | s->bps = 8; | |
322 | 85 | s->n = 1<<s->bps; | |
323 | 85 | s->vlc_n = FFMIN(s->n, MAX_VLC_N); | |
324 | 85 | s->chroma = 1; | |
325 |
1/2✓ Branch 0 taken 85 times.
✗ Branch 1 not taken.
|
85 | if (s->version >= 2) { |
326 | int method, interlace; | ||
327 | |||
328 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 85 times.
|
85 | if (avctx->extradata_size < 4) |
329 | ✗ | return AVERROR_INVALIDDATA; | |
330 | |||
331 | 85 | method = avctx->extradata[0]; | |
332 | 85 | s->decorrelate = method & 64 ? 1 : 0; | |
333 | 85 | s->predictor = method & 63; | |
334 |
2/2✓ Branch 0 taken 53 times.
✓ Branch 1 taken 32 times.
|
85 | if (s->version == 2) { |
335 | 53 | s->bitstream_bpp = avctx->extradata[1]; | |
336 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
|
53 | if (s->bitstream_bpp == 0) |
337 | ✗ | s->bitstream_bpp = avctx->bits_per_coded_sample & ~7; | |
338 | } else { | ||
339 | 32 | s->bps = (avctx->extradata[1] >> 4) + 1; | |
340 | 32 | s->n = 1<<s->bps; | |
341 | 32 | s->vlc_n = FFMIN(s->n, MAX_VLC_N); | |
342 | 32 | s->chroma_h_shift = avctx->extradata[1] & 3; | |
343 | 32 | s->chroma_v_shift = (avctx->extradata[1] >> 2) & 3; | |
344 | 32 | s->yuv = !!(avctx->extradata[2] & 1); | |
345 | 32 | s->chroma= !!(avctx->extradata[2] & 3); | |
346 | 32 | s->alpha = !!(avctx->extradata[2] & 4); | |
347 | } | ||
348 | 85 | interlace = (avctx->extradata[2] & 0x30) >> 4; | |
349 |
2/4✓ Branch 0 taken 85 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 85 times.
|
85 | s->interlaced = (interlace == 1) ? 1 : (interlace == 2) ? 0 : s->interlaced; |
350 | 85 | s->context = avctx->extradata[2] & 0x40 ? 1 : 0; | |
351 | |||
352 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 85 times.
|
85 | if ((ret = read_huffman_tables(s, avctx->extradata + 4, |
353 | 85 | avctx->extradata_size - 4)) < 0) | |
354 | ✗ | return ret; | |
355 | } else { | ||
356 | ✗ | switch (avctx->bits_per_coded_sample & 7) { | |
357 | ✗ | case 1: | |
358 | ✗ | s->predictor = LEFT; | |
359 | ✗ | s->decorrelate = 0; | |
360 | ✗ | break; | |
361 | ✗ | case 2: | |
362 | ✗ | s->predictor = LEFT; | |
363 | ✗ | s->decorrelate = 1; | |
364 | ✗ | break; | |
365 | ✗ | case 3: | |
366 | ✗ | s->predictor = PLANE; | |
367 | ✗ | s->decorrelate = avctx->bits_per_coded_sample >= 24; | |
368 | ✗ | break; | |
369 | ✗ | case 4: | |
370 | ✗ | s->predictor = MEDIAN; | |
371 | ✗ | s->decorrelate = 0; | |
372 | ✗ | break; | |
373 | ✗ | default: | |
374 | ✗ | s->predictor = LEFT; // OLD | |
375 | ✗ | s->decorrelate = 0; | |
376 | ✗ | break; | |
377 | } | ||
378 | ✗ | s->bitstream_bpp = avctx->bits_per_coded_sample & ~7; | |
379 | ✗ | s->context = 0; | |
380 | |||
381 | ✗ | if ((ret = read_old_huffman_tables(s)) < 0) | |
382 | ✗ | return ret; | |
383 | } | ||
384 | |||
385 |
2/2✓ Branch 0 taken 53 times.
✓ Branch 1 taken 32 times.
|
85 | if (s->version <= 2) { |
386 |
4/5✓ Branch 0 taken 28 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
|
53 | switch (s->bitstream_bpp) { |
387 | 28 | case 12: | |
388 | 28 | avctx->pix_fmt = AV_PIX_FMT_YUV420P; | |
389 | 28 | s->yuv = 1; | |
390 | 28 | break; | |
391 | 9 | case 16: | |
392 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (s->yuy2) |
393 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUYV422; | |
394 | else | ||
395 | 9 | avctx->pix_fmt = AV_PIX_FMT_YUV422P; | |
396 | 9 | s->yuv = 1; | |
397 | 9 | break; | |
398 | 8 | case 24: | |
399 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | if (s->bgr32) |
400 | 8 | avctx->pix_fmt = AV_PIX_FMT_0RGB32; | |
401 | else | ||
402 | ✗ | avctx->pix_fmt = AV_PIX_FMT_BGR24; | |
403 | 8 | break; | |
404 | 8 | case 32: | |
405 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | av_assert0(s->bgr32); |
406 | 8 | avctx->pix_fmt = AV_PIX_FMT_RGB32; | |
407 | 8 | s->alpha = 1; | |
408 | 8 | break; | |
409 | ✗ | default: | |
410 | ✗ | return AVERROR_INVALIDDATA; | |
411 | } | ||
412 | 53 | av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, | |
413 | &s->chroma_h_shift, | ||
414 | &s->chroma_v_shift); | ||
415 | } else { | ||
416 |
4/43✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 8 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 8 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 8 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✓ Branch 26 taken 8 times.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
|
32 | switch ( (s->chroma<<10) | (s->yuv<<9) | (s->alpha<<8) | ((s->bps-1)<<4) | s->chroma_h_shift | (s->chroma_v_shift<<2)) { |
417 | ✗ | case 0x070: | |
418 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GRAY8; | |
419 | ✗ | break; | |
420 | ✗ | case 0x0F0: | |
421 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GRAY16; | |
422 | ✗ | break; | |
423 | ✗ | case 0x470: | |
424 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GBRP; | |
425 | ✗ | break; | |
426 | ✗ | case 0x480: | |
427 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GBRP9; | |
428 | ✗ | break; | |
429 | ✗ | case 0x490: | |
430 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GBRP10; | |
431 | ✗ | break; | |
432 | ✗ | case 0x4B0: | |
433 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GBRP12; | |
434 | ✗ | break; | |
435 | ✗ | case 0x4D0: | |
436 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GBRP14; | |
437 | ✗ | break; | |
438 | ✗ | case 0x4F0: | |
439 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GBRP16; | |
440 | ✗ | break; | |
441 | ✗ | case 0x570: | |
442 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GBRAP; | |
443 | ✗ | break; | |
444 | 8 | case 0x670: | |
445 | 8 | avctx->pix_fmt = AV_PIX_FMT_YUV444P; | |
446 | 8 | break; | |
447 | ✗ | case 0x680: | |
448 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV444P9; | |
449 | ✗ | break; | |
450 | ✗ | case 0x690: | |
451 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV444P10; | |
452 | ✗ | break; | |
453 | ✗ | case 0x6B0: | |
454 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV444P12; | |
455 | ✗ | break; | |
456 | ✗ | case 0x6D0: | |
457 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV444P14; | |
458 | ✗ | break; | |
459 | 8 | case 0x6F0: | |
460 | 8 | avctx->pix_fmt = AV_PIX_FMT_YUV444P16; | |
461 | 8 | break; | |
462 | ✗ | case 0x671: | |
463 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV422P; | |
464 | ✗ | break; | |
465 | ✗ | case 0x681: | |
466 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV422P9; | |
467 | ✗ | break; | |
468 | 8 | case 0x691: | |
469 | 8 | avctx->pix_fmt = AV_PIX_FMT_YUV422P10; | |
470 | 8 | break; | |
471 | ✗ | case 0x6B1: | |
472 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV422P12; | |
473 | ✗ | break; | |
474 | ✗ | case 0x6D1: | |
475 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV422P14; | |
476 | ✗ | break; | |
477 | ✗ | case 0x6F1: | |
478 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV422P16; | |
479 | ✗ | break; | |
480 | ✗ | case 0x672: | |
481 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV411P; | |
482 | ✗ | break; | |
483 | ✗ | case 0x674: | |
484 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV440P; | |
485 | ✗ | break; | |
486 | ✗ | case 0x675: | |
487 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV420P; | |
488 | ✗ | break; | |
489 | ✗ | case 0x685: | |
490 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV420P9; | |
491 | ✗ | break; | |
492 | ✗ | case 0x695: | |
493 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV420P10; | |
494 | ✗ | break; | |
495 | 8 | case 0x6B5: | |
496 | 8 | avctx->pix_fmt = AV_PIX_FMT_YUV420P12; | |
497 | 8 | break; | |
498 | ✗ | case 0x6D5: | |
499 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV420P14; | |
500 | ✗ | break; | |
501 | ✗ | case 0x6F5: | |
502 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV420P16; | |
503 | ✗ | break; | |
504 | ✗ | case 0x67A: | |
505 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV410P; | |
506 | ✗ | break; | |
507 | ✗ | case 0x770: | |
508 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUVA444P; | |
509 | ✗ | break; | |
510 | ✗ | case 0x780: | |
511 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUVA444P9; | |
512 | ✗ | break; | |
513 | ✗ | case 0x790: | |
514 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUVA444P10; | |
515 | ✗ | break; | |
516 | ✗ | case 0x7F0: | |
517 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUVA444P16; | |
518 | ✗ | break; | |
519 | ✗ | case 0x771: | |
520 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUVA422P; | |
521 | ✗ | break; | |
522 | ✗ | case 0x781: | |
523 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUVA422P9; | |
524 | ✗ | break; | |
525 | ✗ | case 0x791: | |
526 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUVA422P10; | |
527 | ✗ | break; | |
528 | ✗ | case 0x7F1: | |
529 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUVA422P16; | |
530 | ✗ | break; | |
531 | ✗ | case 0x775: | |
532 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUVA420P; | |
533 | ✗ | break; | |
534 | ✗ | case 0x785: | |
535 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUVA420P9; | |
536 | ✗ | break; | |
537 | ✗ | case 0x795: | |
538 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUVA420P10; | |
539 | ✗ | break; | |
540 | ✗ | case 0x7F5: | |
541 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUVA420P16; | |
542 | ✗ | break; | |
543 | ✗ | default: | |
544 | ✗ | return AVERROR_INVALIDDATA; | |
545 | } | ||
546 | } | ||
547 | |||
548 | 85 | ff_huffyuv_common_init(avctx); | |
549 | |||
550 |
5/6✓ Branch 0 taken 76 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 48 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 37 times.
|
85 | if ((avctx->pix_fmt == AV_PIX_FMT_YUV422P || avctx->pix_fmt == AV_PIX_FMT_YUV420P) && avctx->width & 1) { |
551 | ✗ | av_log(avctx, AV_LOG_ERROR, "width must be even for this colorspace\n"); | |
552 | ✗ | return AVERROR_INVALIDDATA; | |
553 | } | ||
554 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 85 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
85 | if (s->predictor == MEDIAN && avctx->pix_fmt == AV_PIX_FMT_YUV422P && |
555 | ✗ | avctx->width % 4) { | |
556 | ✗ | av_log(avctx, AV_LOG_ERROR, "width must be a multiple of 4 " | |
557 | "for this combination of colorspace and predictor type.\n"); | ||
558 | ✗ | return AVERROR_INVALIDDATA; | |
559 | } | ||
560 | |||
561 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 85 times.
|
85 | if ((ret = ff_huffyuv_alloc_temp(s)) < 0) |
562 | ✗ | return ret; | |
563 | |||
564 | 85 | return 0; | |
565 | } | ||
566 | |||
567 | /** Subset of GET_VLC for use in hand-roller VLC code */ | ||
568 | #define VLC_INTERN(dst, table, gb, name, bits, max_depth) \ | ||
569 | code = table[index].sym; \ | ||
570 | n = table[index].len; \ | ||
571 | if (max_depth > 1 && n < 0) { \ | ||
572 | LAST_SKIP_BITS(name, gb, bits); \ | ||
573 | UPDATE_CACHE(name, gb); \ | ||
574 | \ | ||
575 | nb_bits = -n; \ | ||
576 | index = SHOW_UBITS(name, gb, nb_bits) + code; \ | ||
577 | code = table[index].sym; \ | ||
578 | n = table[index].len; \ | ||
579 | if (max_depth > 2 && n < 0) { \ | ||
580 | LAST_SKIP_BITS(name, gb, nb_bits); \ | ||
581 | UPDATE_CACHE(name, gb); \ | ||
582 | \ | ||
583 | nb_bits = -n; \ | ||
584 | index = SHOW_UBITS(name, gb, nb_bits) + code; \ | ||
585 | code = table[index].sym; \ | ||
586 | n = table[index].len; \ | ||
587 | } \ | ||
588 | } \ | ||
589 | dst = code; \ | ||
590 | LAST_SKIP_BITS(name, gb, n) | ||
591 | |||
592 | |||
593 | #define GET_VLC_DUAL(dst0, dst1, name, gb, dtable, table1, table2, \ | ||
594 | bits, max_depth, OP) \ | ||
595 | do { \ | ||
596 | unsigned int index = SHOW_UBITS(name, gb, bits); \ | ||
597 | int code, n = dtable[index].len; \ | ||
598 | \ | ||
599 | if (n<=0) { \ | ||
600 | int nb_bits; \ | ||
601 | VLC_INTERN(dst0, table1, gb, name, bits, max_depth); \ | ||
602 | \ | ||
603 | UPDATE_CACHE(re, gb); \ | ||
604 | index = SHOW_UBITS(name, gb, bits); \ | ||
605 | VLC_INTERN(dst1, table2, gb, name, bits, max_depth); \ | ||
606 | } else { \ | ||
607 | code = dtable[index].sym; \ | ||
608 | OP(dst0, dst1, code); \ | ||
609 | LAST_SKIP_BITS(name, gb, n); \ | ||
610 | } \ | ||
611 | } while (0) | ||
612 | |||
613 | #define OP8bits(dst0, dst1, code) dst0 = code>>8; dst1 = code | ||
614 | |||
615 | #define READ_2PIX(dst0, dst1, plane1) \ | ||
616 | UPDATE_CACHE(re, &s->gb); \ | ||
617 | GET_VLC_DUAL(dst0, dst1, re, &s->gb, s->vlc[4+plane1].table, \ | ||
618 | s->vlc[0].table, s->vlc[plane1].table, VLC_BITS, 3, OP8bits) | ||
619 | |||
620 | 70390 | static void decode_422_bitstream(HYuvContext *s, int count) | |
621 | { | ||
622 | int i, icount; | ||
623 | 70390 | OPEN_READER(re, &s->gb); | |
624 | 70390 | count /= 2; | |
625 | |||
626 | 70390 | icount = get_bits_left(&s->gb) / (32 * 4); | |
627 |
2/2✓ Branch 0 taken 1665 times.
✓ Branch 1 taken 68725 times.
|
70390 | if (count >= icount) { |
628 |
2/2✓ Branch 0 taken 145894 times.
✓ Branch 1 taken 1665 times.
|
147559 | for (i = 0; i < icount; i++) { |
629 |
8/10✓ Branch 1 taken 35884 times.
✓ Branch 2 taken 110010 times.
✓ Branch 3 taken 5174 times.
✓ Branch 4 taken 30710 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 5174 times.
✓ Branch 10 taken 4241 times.
✓ Branch 11 taken 31643 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 4241 times.
|
145894 | READ_2PIX(s->temp[0][2 * i], s->temp[1][i], 1); |
630 |
8/10✓ Branch 1 taken 60494 times.
✓ Branch 2 taken 85400 times.
✓ Branch 3 taken 4323 times.
✓ Branch 4 taken 56171 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4323 times.
✓ Branch 10 taken 3011 times.
✓ Branch 11 taken 57483 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3011 times.
|
145894 | READ_2PIX(s->temp[0][2 * i + 1], s->temp[2][i], 2); |
631 | } | ||
632 |
3/4✓ Branch 0 taken 119540 times.
✓ Branch 1 taken 1665 times.
✓ Branch 2 taken 119540 times.
✗ Branch 3 not taken.
|
121205 | for (; i < count && BITS_LEFT(re, &s->gb) > 0; i++) { |
633 |
8/10✓ Branch 1 taken 30418 times.
✓ Branch 2 taken 89122 times.
✓ Branch 3 taken 3373 times.
✓ Branch 4 taken 27045 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 3373 times.
✓ Branch 10 taken 2240 times.
✓ Branch 11 taken 28178 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2240 times.
|
119540 | READ_2PIX(s->temp[0][2 * i ], s->temp[1][i], 1); |
634 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 119540 times.
|
119540 | if (BITS_LEFT(re, &s->gb) <= 0) break; |
635 |
8/10✓ Branch 1 taken 40541 times.
✓ Branch 2 taken 78999 times.
✓ Branch 3 taken 3330 times.
✓ Branch 4 taken 37211 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 3330 times.
✓ Branch 10 taken 1831 times.
✓ Branch 11 taken 38710 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1831 times.
|
119540 | READ_2PIX(s->temp[0][2 * i + 1], s->temp[2][i], 2); |
636 | } | ||
637 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1665 times.
|
1665 | for (; i < count; i++) |
638 | ✗ | s->temp[0][2 * i ] = s->temp[1][i] = | |
639 | ✗ | s->temp[0][2 * i + 1] = s->temp[2][i] = 0; | |
640 | } else { | ||
641 |
2/2✓ Branch 0 taken 12276706 times.
✓ Branch 1 taken 68725 times.
|
12345431 | for (i = 0; i < count; i++) { |
642 |
8/10✓ Branch 1 taken 3139971 times.
✓ Branch 2 taken 9136735 times.
✓ Branch 3 taken 424733 times.
✓ Branch 4 taken 2715238 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 424733 times.
✓ Branch 10 taken 405857 times.
✓ Branch 11 taken 2734114 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 405857 times.
|
12276706 | READ_2PIX(s->temp[0][2 * i], s->temp[1][i], 1); |
643 |
8/10✓ Branch 1 taken 5538372 times.
✓ Branch 2 taken 6738334 times.
✓ Branch 3 taken 393571 times.
✓ Branch 4 taken 5144801 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 393571 times.
✓ Branch 10 taken 279448 times.
✓ Branch 11 taken 5258924 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 279448 times.
|
12276706 | READ_2PIX(s->temp[0][2 * i + 1], s->temp[2][i], 2); |
644 | } | ||
645 | } | ||
646 | 70390 | CLOSE_READER(re, &s->gb); | |
647 | 70390 | } | |
648 | |||
649 | #define READ_2PIX_PLANE(dst0, dst1, plane, OP) \ | ||
650 | UPDATE_CACHE(re, &s->gb); \ | ||
651 | GET_VLC_DUAL(dst0, dst1, re, &s->gb, s->vlc[4+plane].table, \ | ||
652 | s->vlc[plane].table, s->vlc[plane].table, VLC_BITS, 3, OP) | ||
653 | |||
654 | #define OP14bits(dst0, dst1, code) dst0 = code>>8; dst1 = sign_extend(code, 8) | ||
655 | |||
656 | /* TODO instead of restarting the read when the code isn't in the first level | ||
657 | * of the joint table, jump into the 2nd level of the individual table. */ | ||
658 | #define READ_2PIX_PLANE16(dst0, dst1, plane){\ | ||
659 | dst0 = get_vlc2(&s->gb, s->vlc[plane].table, VLC_BITS, 3)<<2;\ | ||
660 | dst0 += get_bits(&s->gb, 2);\ | ||
661 | dst1 = get_vlc2(&s->gb, s->vlc[plane].table, VLC_BITS, 3)<<2;\ | ||
662 | dst1 += get_bits(&s->gb, 2);\ | ||
663 | } | ||
664 | 493900 | static void decode_plane_bitstream(HYuvContext *s, int width, int plane) | |
665 | { | ||
666 | 493900 | int i, count = width/2; | |
667 | |||
668 |
2/2✓ Branch 0 taken 134700 times.
✓ Branch 1 taken 359200 times.
|
493900 | if (s->bps <= 8) { |
669 | 134700 | OPEN_READER(re, &s->gb); | |
670 |
2/2✓ Branch 1 taken 1387 times.
✓ Branch 2 taken 133313 times.
|
134700 | if (count >= (get_bits_left(&s->gb)) / (32 * 2)) { |
671 |
3/4✓ Branch 0 taken 212153 times.
✓ Branch 1 taken 1387 times.
✓ Branch 2 taken 212153 times.
✗ Branch 3 not taken.
|
213540 | for (i = 0; i < count && BITS_LEFT(re, &s->gb) > 0; i++) { |
672 |
8/10✓ Branch 1 taken 24131 times.
✓ Branch 2 taken 188022 times.
✓ Branch 3 taken 542 times.
✓ Branch 4 taken 23589 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 542 times.
✓ Branch 10 taken 65 times.
✓ Branch 11 taken 24066 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 65 times.
|
212153 | READ_2PIX_PLANE(s->temp[0][2 * i], s->temp[0][2 * i + 1], plane, OP8bits); |
673 | } | ||
674 | } else { | ||
675 |
2/2✓ Branch 0 taken 22684147 times.
✓ Branch 1 taken 133313 times.
|
22817460 | for(i=0; i<count; i++){ |
676 |
8/10✓ Branch 1 taken 6319215 times.
✓ Branch 2 taken 16364932 times.
✓ Branch 3 taken 350124 times.
✓ Branch 4 taken 5969091 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 350124 times.
✓ Branch 10 taken 266353 times.
✓ Branch 11 taken 6052862 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 266353 times.
|
22684147 | READ_2PIX_PLANE(s->temp[0][2 * i], s->temp[0][2 * i + 1], plane, OP8bits); |
677 | } | ||
678 | } | ||
679 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 134700 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
134700 | if( width&1 && BITS_LEFT(re, &s->gb)>0 ) { |
680 | unsigned int index; | ||
681 | int nb_bits, code, n; | ||
682 | ✗ | UPDATE_CACHE(re, &s->gb); | |
683 | ✗ | index = SHOW_UBITS(re, &s->gb, VLC_BITS); | |
684 | ✗ | VLC_INTERN(s->temp[0][width-1], s->vlc[plane].table, | |
685 | &s->gb, re, VLC_BITS, 3); | ||
686 | } | ||
687 | 134700 | CLOSE_READER(re, &s->gb); | |
688 |
2/2✓ Branch 0 taken 224500 times.
✓ Branch 1 taken 134700 times.
|
359200 | } else if (s->bps <= 14) { |
689 | 224500 | OPEN_READER(re, &s->gb); | |
690 |
2/2✓ Branch 1 taken 1073 times.
✓ Branch 2 taken 223427 times.
|
224500 | if (count >= (get_bits_left(&s->gb)) / (32 * 2)) { |
691 |
3/4✓ Branch 0 taken 82104 times.
✓ Branch 1 taken 1073 times.
✓ Branch 2 taken 82104 times.
✗ Branch 3 not taken.
|
83177 | for (i = 0; i < count && BITS_LEFT(re, &s->gb) > 0; i++) { |
692 |
8/10✓ Branch 1 taken 57626 times.
✓ Branch 2 taken 24478 times.
✓ Branch 3 taken 21687 times.
✓ Branch 4 taken 35939 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 21687 times.
✓ Branch 10 taken 21105 times.
✓ Branch 11 taken 36521 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 21105 times.
|
82104 | READ_2PIX_PLANE(s->temp16[0][2 * i], s->temp16[0][2 * i + 1], plane, OP14bits); |
693 | } | ||
694 | } else { | ||
695 |
2/2✓ Branch 0 taken 26627696 times.
✓ Branch 1 taken 223427 times.
|
26851123 | for(i=0; i<count; i++){ |
696 |
8/10✓ Branch 1 taken 21066126 times.
✓ Branch 2 taken 5561570 times.
✓ Branch 3 taken 9246504 times.
✓ Branch 4 taken 11819622 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 9246504 times.
✓ Branch 10 taken 9120068 times.
✓ Branch 11 taken 11946058 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 9120068 times.
|
26627696 | READ_2PIX_PLANE(s->temp16[0][2 * i], s->temp16[0][2 * i + 1], plane, OP14bits); |
697 | } | ||
698 | } | ||
699 |
3/4✓ Branch 0 taken 5100 times.
✓ Branch 1 taken 219400 times.
✓ Branch 2 taken 5100 times.
✗ Branch 3 not taken.
|
224500 | if( width&1 && BITS_LEFT(re, &s->gb)>0 ) { |
700 | unsigned int index; | ||
701 | int nb_bits, code, n; | ||
702 | 5100 | UPDATE_CACHE(re, &s->gb); | |
703 | 5100 | index = SHOW_UBITS(re, &s->gb, VLC_BITS); | |
704 |
3/4✓ Branch 0 taken 2272 times.
✓ Branch 1 taken 2828 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2272 times.
|
5100 | VLC_INTERN(s->temp16[0][width-1], s->vlc[plane].table, |
705 | &s->gb, re, VLC_BITS, 3); | ||
706 | } | ||
707 | 224500 | CLOSE_READER(re, &s->gb); | |
708 | } else { | ||
709 |
2/2✓ Branch 1 taken 372 times.
✓ Branch 2 taken 134328 times.
|
134700 | if (count >= (get_bits_left(&s->gb)) / (32 * 2)) { |
710 |
3/4✓ Branch 0 taken 56886 times.
✓ Branch 1 taken 372 times.
✓ Branch 3 taken 56886 times.
✗ Branch 4 not taken.
|
57258 | for (i = 0; i < count && get_bits_left(&s->gb) > 0; i++) { |
711 | 56886 | READ_2PIX_PLANE16(s->temp16[0][2 * i], s->temp16[0][2 * i + 1], plane); | |
712 | } | ||
713 | } else { | ||
714 |
2/2✓ Branch 0 taken 22839414 times.
✓ Branch 1 taken 134328 times.
|
22973742 | for(i=0; i<count; i++){ |
715 | 22839414 | READ_2PIX_PLANE16(s->temp16[0][2 * i], s->temp16[0][2 * i + 1], plane); | |
716 | } | ||
717 | } | ||
718 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 134700 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
134700 | if( width&1 && get_bits_left(&s->gb)>0 ) { |
719 | ✗ | int dst = get_vlc2(&s->gb, s->vlc[plane].table, VLC_BITS, 3)<<2; | |
720 | ✗ | s->temp16[0][width-1] = dst + get_bits(&s->gb, 2); | |
721 | } | ||
722 | } | ||
723 | 493900 | } | |
724 | |||
725 | 25490 | static void decode_gray_bitstream(HYuvContext *s, int count) | |
726 | { | ||
727 | int i; | ||
728 | 25490 | OPEN_READER(re, &s->gb); | |
729 | 25490 | count /= 2; | |
730 | |||
731 |
2/2✓ Branch 1 taken 427 times.
✓ Branch 2 taken 25063 times.
|
25490 | if (count >= (get_bits_left(&s->gb)) / (32 * 2)) { |
732 |
3/4✓ Branch 0 taken 74930 times.
✓ Branch 1 taken 427 times.
✓ Branch 2 taken 74930 times.
✗ Branch 3 not taken.
|
75357 | for (i = 0; i < count && BITS_LEFT(re, &s->gb) > 0; i++) { |
733 |
8/10✓ Branch 1 taken 31336 times.
✓ Branch 2 taken 43594 times.
✓ Branch 3 taken 1978 times.
✓ Branch 4 taken 29358 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1978 times.
✓ Branch 10 taken 1840 times.
✓ Branch 11 taken 29496 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1840 times.
|
74930 | READ_2PIX(s->temp[0][2 * i], s->temp[0][2 * i + 1], 0); |
734 | } | ||
735 | } else { | ||
736 |
2/2✓ Branch 0 taken 4835520 times.
✓ Branch 1 taken 25063 times.
|
4860583 | for (i = 0; i < count; i++) { |
737 |
8/10✓ Branch 1 taken 2242950 times.
✓ Branch 2 taken 2592570 times.
✓ Branch 3 taken 144924 times.
✓ Branch 4 taken 2098026 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 144924 times.
✓ Branch 10 taken 134202 times.
✓ Branch 11 taken 2108748 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 134202 times.
|
4835520 | READ_2PIX(s->temp[0][2 * i], s->temp[0][2 * i + 1], 0); |
738 | } | ||
739 | } | ||
740 | 25490 | CLOSE_READER(re, &s->gb); | |
741 | 25490 | } | |
742 | |||
743 | 89800 | static av_always_inline void decode_bgr_1(HYuvContext *s, int count, | |
744 | int decorrelate, int alpha) | ||
745 | { | ||
746 | int i; | ||
747 | 89800 | OPEN_READER(re, &s->gb); | |
748 | |||
749 |
3/4✓ Branch 0 taken 30528000 times.
✓ Branch 1 taken 89800 times.
✓ Branch 2 taken 30528000 times.
✗ Branch 3 not taken.
|
30617800 | for (i = 0; i < count && BITS_LEFT(re, &s->gb) > 0; i++) { |
750 | unsigned int index; | ||
751 | int code, n, nb_bits; | ||
752 | |||
753 | 30528000 | UPDATE_CACHE(re, &s->gb); | |
754 | 30528000 | index = SHOW_UBITS(re, &s->gb, VLC_BITS); | |
755 | 30528000 | n = s->vlc[4].table[index].len; | |
756 | |||
757 |
2/2✓ Branch 0 taken 13538088 times.
✓ Branch 1 taken 16989912 times.
|
30528000 | if (n>0) { |
758 | 13538088 | code = s->vlc[4].table[index].sym; | |
759 | 13538088 | *(uint32_t *) &s->temp[0][4 * i] = s->pix_bgr_map[code]; | |
760 | 13538088 | LAST_SKIP_BITS(re, &s->gb, n); | |
761 | } else { | ||
762 |
1/2✓ Branch 0 taken 16989912 times.
✗ Branch 1 not taken.
|
16989912 | if (decorrelate) { |
763 |
3/4✓ Branch 0 taken 1469318 times.
✓ Branch 1 taken 15520594 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1469318 times.
|
16989912 | VLC_INTERN(s->temp[0][4 * i + G], s->vlc[1].table, |
764 | &s->gb, re, VLC_BITS, 3); | ||
765 | |||
766 | 16989912 | UPDATE_CACHE(re, &s->gb); | |
767 | 16989912 | index = SHOW_UBITS(re, &s->gb, VLC_BITS); | |
768 |
3/4✓ Branch 0 taken 1019554 times.
✓ Branch 1 taken 15970358 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1019554 times.
|
16989912 | VLC_INTERN(code, s->vlc[0].table, &s->gb, re, VLC_BITS, 3); |
769 | 16989912 | s->temp[0][4 * i + B] = code + s->temp[0][4 * i + G]; | |
770 | |||
771 | 16989912 | UPDATE_CACHE(re, &s->gb); | |
772 | 16989912 | index = SHOW_UBITS(re, &s->gb, VLC_BITS); | |
773 |
3/4✓ Branch 0 taken 957442 times.
✓ Branch 1 taken 16032470 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 957442 times.
|
16989912 | VLC_INTERN(code, s->vlc[2].table, &s->gb, re, VLC_BITS, 3); |
774 | 16989912 | s->temp[0][4 * i + R] = code + s->temp[0][4 * i + G]; | |
775 | } else { | ||
776 | ✗ | VLC_INTERN(s->temp[0][4 * i + B], s->vlc[0].table, | |
777 | &s->gb, re, VLC_BITS, 3); | ||
778 | |||
779 | ✗ | UPDATE_CACHE(re, &s->gb); | |
780 | ✗ | index = SHOW_UBITS(re, &s->gb, VLC_BITS); | |
781 | ✗ | VLC_INTERN(s->temp[0][4 * i + G], s->vlc[1].table, | |
782 | &s->gb, re, VLC_BITS, 3); | ||
783 | |||
784 | ✗ | UPDATE_CACHE(re, &s->gb); | |
785 | ✗ | index = SHOW_UBITS(re, &s->gb, VLC_BITS); | |
786 | ✗ | VLC_INTERN(s->temp[0][4 * i + R], s->vlc[2].table, | |
787 | &s->gb, re, VLC_BITS, 3); | ||
788 | } | ||
789 | } | ||
790 |
2/2✓ Branch 0 taken 15264000 times.
✓ Branch 1 taken 15264000 times.
|
30528000 | if (alpha) { |
791 | 15264000 | UPDATE_CACHE(re, &s->gb); | |
792 | 15264000 | index = SHOW_UBITS(re, &s->gb, VLC_BITS); | |
793 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 15264000 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
15264000 | VLC_INTERN(s->temp[0][4 * i + A], s->vlc[2].table, |
794 | &s->gb, re, VLC_BITS, 3); | ||
795 | } else | ||
796 | 15264000 | s->temp[0][4 * i + A] = 0; | |
797 | } | ||
798 | 89800 | CLOSE_READER(re, &s->gb); | |
799 | 89800 | } | |
800 | |||
801 | 89800 | static void decode_bgr_bitstream(HYuvContext *s, int count) | |
802 | { | ||
803 |
1/2✓ Branch 0 taken 89800 times.
✗ Branch 1 not taken.
|
89800 | if (s->decorrelate) { |
804 |
2/2✓ Branch 0 taken 44900 times.
✓ Branch 1 taken 44900 times.
|
89800 | if (s->bitstream_bpp == 24) |
805 | 44900 | decode_bgr_1(s, count, 1, 0); | |
806 | else | ||
807 | 44900 | decode_bgr_1(s, count, 1, 1); | |
808 | } else { | ||
809 | ✗ | if (s->bitstream_bpp == 24) | |
810 | ✗ | decode_bgr_1(s, count, 0, 0); | |
811 | else | ||
812 | ✗ | decode_bgr_1(s, count, 0, 1); | |
813 | } | ||
814 | 89800 | } | |
815 | |||
816 | 71590 | static void draw_slice(HYuvContext *s, AVFrame *frame, int y) | |
817 | { | ||
818 | int h, cy, i; | ||
819 | int offset[AV_NUM_DATA_POINTERS]; | ||
820 | |||
821 |
1/2✓ Branch 0 taken 71590 times.
✗ Branch 1 not taken.
|
71590 | if (!s->avctx->draw_horiz_band) |
822 | 71590 | return; | |
823 | |||
824 | ✗ | h = y - s->last_slice_end; | |
825 | ✗ | y -= h; | |
826 | |||
827 | ✗ | if (s->bitstream_bpp == 12) | |
828 | ✗ | cy = y >> 1; | |
829 | else | ||
830 | ✗ | cy = y; | |
831 | |||
832 | ✗ | offset[0] = frame->linesize[0] * y; | |
833 | ✗ | offset[1] = frame->linesize[1] * cy; | |
834 | ✗ | offset[2] = frame->linesize[2] * cy; | |
835 | ✗ | for (i = 3; i < AV_NUM_DATA_POINTERS; i++) | |
836 | ✗ | offset[i] = 0; | |
837 | ✗ | emms_c(); | |
838 | |||
839 | ✗ | s->avctx->draw_horiz_band(s->avctx, frame, offset, y, 3, h); | |
840 | |||
841 | ✗ | s->last_slice_end = y + h; | |
842 | } | ||
843 | |||
844 | 493900 | static int left_prediction(HYuvContext *s, uint8_t *dst, const uint8_t *src, int w, int acc) | |
845 | { | ||
846 |
2/2✓ Branch 0 taken 134700 times.
✓ Branch 1 taken 359200 times.
|
493900 | if (s->bps <= 8) { |
847 | 134700 | return s->llviddsp.add_left_pred(dst, src, w, acc); | |
848 | } else { | ||
849 | 359200 | return s->llviddsp.add_left_pred_int16(( uint16_t *)dst, (const uint16_t *)src, s->n-1, w, acc); | |
850 | } | ||
851 | } | ||
852 | |||
853 | 134100 | static void add_bytes(HYuvContext *s, uint8_t *dst, uint8_t *src, int w) | |
854 | { | ||
855 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 134100 times.
|
134100 | if (s->bps <= 8) { |
856 | ✗ | s->llviddsp.add_bytes(dst, src, w); | |
857 | } else { | ||
858 | 134100 | s->hdsp.add_int16((uint16_t*)dst, (const uint16_t*)src, s->n - 1, w); | |
859 | } | ||
860 | 134100 | } | |
861 | |||
862 | ✗ | static void add_median_prediction(HYuvContext *s, uint8_t *dst, const uint8_t *src, const uint8_t *diff, int w, int *left, int *left_top) | |
863 | { | ||
864 | ✗ | if (s->bps <= 8) { | |
865 | ✗ | s->llviddsp.add_median_pred(dst, src, diff, w, left, left_top); | |
866 | } else { | ||
867 | ✗ | s->hdsp.add_hfyu_median_pred_int16((uint16_t *)dst, (const uint16_t *)src, (const uint16_t *)diff, s->n-1, w, left, left_top); | |
868 | } | ||
869 | } | ||
870 | |||
871 | 1610 | static int decode_slice(AVCodecContext *avctx, AVFrame *p, int height, | |
872 | int buf_size, int y_offset, int table_size) | ||
873 | { | ||
874 | 1610 | HYuvContext *s = avctx->priv_data; | |
875 | int fake_ystride, fake_ustride, fake_vstride; | ||
876 | 1610 | const int width = s->width; | |
877 | 1610 | const int width2 = s->width >> 1; | |
878 | int ret; | ||
879 | |||
880 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1610 times.
|
1610 | if ((ret = init_get_bits8(&s->gb, s->bitstream_buffer + table_size, buf_size - table_size)) < 0) |
881 | ✗ | return ret; | |
882 | |||
883 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1610 times.
|
1610 | fake_ystride = s->interlaced ? p->linesize[0] * 2 : p->linesize[0]; |
884 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1610 times.
|
1610 | fake_ustride = s->interlaced ? p->linesize[1] * 2 : p->linesize[1]; |
885 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1610 times.
|
1610 | fake_vstride = s->interlaced ? p->linesize[2] * 2 : p->linesize[2]; |
886 | |||
887 |
2/2✓ Branch 0 taken 800 times.
✓ Branch 1 taken 810 times.
|
1610 | if (s->version > 2) { |
888 | int plane; | ||
889 |
2/2✓ Branch 0 taken 2400 times.
✓ Branch 1 taken 800 times.
|
3200 | for(plane = 0; plane < 1 + 2*s->chroma + s->alpha; plane++) { |
890 | int left, lefttop, y; | ||
891 | 2400 | int w = width; | |
892 | 2400 | int h = height; | |
893 | 2400 | int fake_stride = fake_ystride; | |
894 | |||
895 |
5/6✓ Branch 0 taken 2400 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1600 times.
✓ Branch 3 taken 800 times.
✓ Branch 4 taken 800 times.
✓ Branch 5 taken 800 times.
|
2400 | if (s->chroma && (plane == 1 || plane == 2)) { |
896 | 1600 | w >>= s->chroma_h_shift; | |
897 | 1600 | h >>= s->chroma_v_shift; | |
898 |
2/2✓ Branch 0 taken 800 times.
✓ Branch 1 taken 800 times.
|
1600 | fake_stride = plane == 1 ? fake_ustride : fake_vstride; |
899 | } | ||
900 | |||
901 |
1/3✓ Branch 0 taken 2400 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
2400 | switch (s->predictor) { |
902 | 2400 | case LEFT: | |
903 | case PLANE: | ||
904 | 2400 | decode_plane_bitstream(s, w, plane); | |
905 | 2400 | left = left_prediction(s, p->data[plane], s->temp[0], w, 0); | |
906 | |||
907 |
2/2✓ Branch 0 taken 491500 times.
✓ Branch 1 taken 2400 times.
|
493900 | for (y = 1; y < h; y++) { |
908 | 491500 | uint8_t *dst = p->data[plane] + p->linesize[plane]*y; | |
909 | |||
910 | 491500 | decode_plane_bitstream(s, w, plane); | |
911 | 491500 | left = left_prediction(s, dst, s->temp[0], w, left); | |
912 |
2/2✓ Branch 0 taken 134100 times.
✓ Branch 1 taken 357400 times.
|
491500 | if (s->predictor == PLANE) { |
913 |
1/2✓ Branch 0 taken 134100 times.
✗ Branch 1 not taken.
|
134100 | if (y > s->interlaced) { |
914 | 134100 | add_bytes(s, dst, dst - fake_stride, w); | |
915 | } | ||
916 | } | ||
917 | } | ||
918 | |||
919 | 2400 | break; | |
920 | ✗ | case MEDIAN: | |
921 | ✗ | decode_plane_bitstream(s, w, plane); | |
922 | ✗ | left= left_prediction(s, p->data[plane], s->temp[0], w, 0); | |
923 | |||
924 | ✗ | y = 1; | |
925 | ✗ | if (y >= h) | |
926 | ✗ | break; | |
927 | |||
928 | /* second line is left predicted for interlaced case */ | ||
929 | ✗ | if (s->interlaced) { | |
930 | ✗ | decode_plane_bitstream(s, w, plane); | |
931 | ✗ | left = left_prediction(s, p->data[plane] + p->linesize[plane], s->temp[0], w, left); | |
932 | ✗ | y++; | |
933 | ✗ | if (y >= h) | |
934 | ✗ | break; | |
935 | } | ||
936 | |||
937 | ✗ | lefttop = p->data[plane][0]; | |
938 | ✗ | decode_plane_bitstream(s, w, plane); | |
939 | ✗ | add_median_prediction(s, p->data[plane] + fake_stride, p->data[plane], s->temp[0], w, &left, &lefttop); | |
940 | ✗ | y++; | |
941 | |||
942 | ✗ | for (; y<h; y++) { | |
943 | uint8_t *dst; | ||
944 | |||
945 | ✗ | decode_plane_bitstream(s, w, plane); | |
946 | |||
947 | ✗ | dst = p->data[plane] + p->linesize[plane] * y; | |
948 | |||
949 | ✗ | add_median_prediction(s, dst, dst - fake_stride, s->temp[0], w, &left, &lefttop); | |
950 | } | ||
951 | |||
952 | ✗ | break; | |
953 | } | ||
954 | } | ||
955 | 800 | draw_slice(s, p, height); | |
956 |
2/2✓ Branch 0 taken 410 times.
✓ Branch 1 taken 400 times.
|
810 | } else if (s->bitstream_bpp < 24) { |
957 | int y, cy; | ||
958 | int lefty, leftu, leftv; | ||
959 | int lefttopy, lefttopu, lefttopv; | ||
960 | |||
961 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 410 times.
|
410 | if (s->yuy2) { |
962 | ✗ | p->data[0][3] = get_bits(&s->gb, 8); | |
963 | ✗ | p->data[0][2] = get_bits(&s->gb, 8); | |
964 | ✗ | p->data[0][1] = get_bits(&s->gb, 8); | |
965 | ✗ | p->data[0][0] = get_bits(&s->gb, 8); | |
966 | |||
967 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
968 | "YUY2 output is not implemented yet\n"); | ||
969 | ✗ | return AVERROR_PATCHWELCOME; | |
970 | } else { | ||
971 | 410 | leftv = | |
972 | 410 | p->data[2][0 + y_offset * p->linesize[2]] = get_bits(&s->gb, 8); | |
973 | 410 | lefty = | |
974 | 410 | p->data[0][1 + y_offset * p->linesize[0]] = get_bits(&s->gb, 8); | |
975 | 410 | leftu = | |
976 | 410 | p->data[1][0 + y_offset * p->linesize[1]] = get_bits(&s->gb, 8); | |
977 | 410 | p->data[0][0 + y_offset * p->linesize[0]] = get_bits(&s->gb, 8); | |
978 | |||
979 |
1/3✓ Branch 0 taken 410 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
410 | switch (s->predictor) { |
980 | 410 | case LEFT: | |
981 | case PLANE: | ||
982 | 410 | decode_422_bitstream(s, width - 2); | |
983 | 820 | lefty = s->llviddsp.add_left_pred(p->data[0] + p->linesize[0] * y_offset + 2, s->temp[0], | |
984 | 410 | width - 2, lefty); | |
985 |
1/2✓ Branch 0 taken 410 times.
✗ Branch 1 not taken.
|
410 | if (!(s->flags & AV_CODEC_FLAG_GRAY)) { |
986 | 410 | leftu = s->llviddsp.add_left_pred(p->data[1] + p->linesize[1] * y_offset + 1, s->temp[1], width2 - 1, leftu); | |
987 | 410 | leftv = s->llviddsp.add_left_pred(p->data[2] + p->linesize[2] * y_offset + 1, s->temp[2], width2 - 1, leftv); | |
988 | } | ||
989 | |||
990 |
2/2✓ Branch 0 taken 70190 times.
✓ Branch 1 taken 200 times.
|
70390 | for (cy = y = 1; y < height; y++, cy++) { |
991 | uint8_t *ydst, *udst, *vdst; | ||
992 | |||
993 |
2/2✓ Branch 0 taken 25490 times.
✓ Branch 1 taken 44700 times.
|
70190 | if (s->bitstream_bpp == 12) { |
994 | 25490 | decode_gray_bitstream(s, width); | |
995 | |||
996 | 25490 | ydst = p->data[0] + p->linesize[0] * (y + y_offset); | |
997 | |||
998 | 25490 | lefty = s->llviddsp.add_left_pred(ydst, s->temp[0], | |
999 | width, lefty); | ||
1000 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25490 times.
|
25490 | if (s->predictor == PLANE) { |
1001 | ✗ | if (y > s->interlaced) | |
1002 | ✗ | s->llviddsp.add_bytes(ydst, ydst - fake_ystride, width); | |
1003 | } | ||
1004 | 25490 | y++; | |
1005 |
2/2✓ Branch 0 taken 210 times.
✓ Branch 1 taken 25280 times.
|
25490 | if (y >= height) |
1006 | 210 | break; | |
1007 | } | ||
1008 | |||
1009 | 69980 | draw_slice(s, p, y); | |
1010 | |||
1011 | 69980 | ydst = p->data[0] + p->linesize[0] * (y + y_offset); | |
1012 | 69980 | udst = p->data[1] + p->linesize[1] * (cy + y_offset); | |
1013 | 69980 | vdst = p->data[2] + p->linesize[2] * (cy + y_offset); | |
1014 | |||
1015 | 69980 | decode_422_bitstream(s, width); | |
1016 | 69980 | lefty = s->llviddsp.add_left_pred(ydst, s->temp[0], | |
1017 | width, lefty); | ||
1018 |
1/2✓ Branch 0 taken 69980 times.
✗ Branch 1 not taken.
|
69980 | if (!(s->flags & AV_CODEC_FLAG_GRAY)) { |
1019 | 69980 | leftu = s->llviddsp.add_left_pred(udst, s->temp[1], width2, leftu); | |
1020 | 69980 | leftv = s->llviddsp.add_left_pred(vdst, s->temp[2], width2, leftv); | |
1021 | } | ||
1022 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 69980 times.
|
69980 | if (s->predictor == PLANE) { |
1023 | ✗ | if (cy > s->interlaced) { | |
1024 | ✗ | s->llviddsp.add_bytes(ydst, ydst - fake_ystride, width); | |
1025 | ✗ | if (!(s->flags & AV_CODEC_FLAG_GRAY)) { | |
1026 | ✗ | s->llviddsp.add_bytes(udst, udst - fake_ustride, width2); | |
1027 | ✗ | s->llviddsp.add_bytes(vdst, vdst - fake_vstride, width2); | |
1028 | } | ||
1029 | } | ||
1030 | } | ||
1031 | } | ||
1032 | 410 | draw_slice(s, p, height); | |
1033 | |||
1034 | 410 | break; | |
1035 | ✗ | case MEDIAN: | |
1036 | /* first line except first 2 pixels is left predicted */ | ||
1037 | ✗ | decode_422_bitstream(s, width - 2); | |
1038 | ✗ | lefty = s->llviddsp.add_left_pred(p->data[0] + 2, s->temp[0], | |
1039 | ✗ | width - 2, lefty); | |
1040 | ✗ | if (!(s->flags & AV_CODEC_FLAG_GRAY)) { | |
1041 | ✗ | leftu = s->llviddsp.add_left_pred(p->data[1] + 1, s->temp[1], width2 - 1, leftu); | |
1042 | ✗ | leftv = s->llviddsp.add_left_pred(p->data[2] + 1, s->temp[2], width2 - 1, leftv); | |
1043 | } | ||
1044 | |||
1045 | ✗ | cy = y = 1; | |
1046 | ✗ | if (y >= height) | |
1047 | ✗ | break; | |
1048 | |||
1049 | /* second line is left predicted for interlaced case */ | ||
1050 | ✗ | if (s->interlaced) { | |
1051 | ✗ | decode_422_bitstream(s, width); | |
1052 | ✗ | lefty = s->llviddsp.add_left_pred(p->data[0] + p->linesize[0], | |
1053 | ✗ | s->temp[0], width, lefty); | |
1054 | ✗ | if (!(s->flags & AV_CODEC_FLAG_GRAY)) { | |
1055 | ✗ | leftu = s->llviddsp.add_left_pred(p->data[1] + p->linesize[2], s->temp[1], width2, leftu); | |
1056 | ✗ | leftv = s->llviddsp.add_left_pred(p->data[2] + p->linesize[1], s->temp[2], width2, leftv); | |
1057 | } | ||
1058 | ✗ | y++; | |
1059 | ✗ | cy++; | |
1060 | ✗ | if (y >= height) | |
1061 | ✗ | break; | |
1062 | } | ||
1063 | |||
1064 | /* next 4 pixels are left predicted too */ | ||
1065 | ✗ | decode_422_bitstream(s, 4); | |
1066 | ✗ | lefty = s->llviddsp.add_left_pred(p->data[0] + fake_ystride, | |
1067 | ✗ | s->temp[0], 4, lefty); | |
1068 | ✗ | if (!(s->flags & AV_CODEC_FLAG_GRAY)) { | |
1069 | ✗ | leftu = s->llviddsp.add_left_pred(p->data[1] + fake_ustride, s->temp[1], 2, leftu); | |
1070 | ✗ | leftv = s->llviddsp.add_left_pred(p->data[2] + fake_vstride, s->temp[2], 2, leftv); | |
1071 | } | ||
1072 | |||
1073 | /* next line except the first 4 pixels is median predicted */ | ||
1074 | ✗ | lefttopy = p->data[0][3]; | |
1075 | ✗ | decode_422_bitstream(s, width - 4); | |
1076 | ✗ | s->llviddsp.add_median_pred(p->data[0] + fake_ystride + 4, | |
1077 | ✗ | p->data[0] + 4, s->temp[0], | |
1078 | ✗ | width - 4, &lefty, &lefttopy); | |
1079 | ✗ | if (!(s->flags & AV_CODEC_FLAG_GRAY)) { | |
1080 | ✗ | lefttopu = p->data[1][1]; | |
1081 | ✗ | lefttopv = p->data[2][1]; | |
1082 | ✗ | s->llviddsp.add_median_pred(p->data[1] + fake_ustride + 2, p->data[1] + 2, s->temp[1], width2 - 2, &leftu, &lefttopu); | |
1083 | ✗ | s->llviddsp.add_median_pred(p->data[2] + fake_vstride + 2, p->data[2] + 2, s->temp[2], width2 - 2, &leftv, &lefttopv); | |
1084 | } | ||
1085 | ✗ | y++; | |
1086 | ✗ | cy++; | |
1087 | |||
1088 | ✗ | for (; y < height; y++, cy++) { | |
1089 | uint8_t *ydst, *udst, *vdst; | ||
1090 | |||
1091 | ✗ | if (s->bitstream_bpp == 12) { | |
1092 | ✗ | while (2 * cy > y) { | |
1093 | ✗ | decode_gray_bitstream(s, width); | |
1094 | ✗ | ydst = p->data[0] + p->linesize[0] * y; | |
1095 | ✗ | s->llviddsp.add_median_pred(ydst, ydst - fake_ystride, | |
1096 | ✗ | s->temp[0], width, | |
1097 | &lefty, &lefttopy); | ||
1098 | ✗ | y++; | |
1099 | } | ||
1100 | ✗ | if (y >= height) | |
1101 | ✗ | break; | |
1102 | } | ||
1103 | ✗ | draw_slice(s, p, y); | |
1104 | |||
1105 | ✗ | decode_422_bitstream(s, width); | |
1106 | |||
1107 | ✗ | ydst = p->data[0] + p->linesize[0] * y; | |
1108 | ✗ | udst = p->data[1] + p->linesize[1] * cy; | |
1109 | ✗ | vdst = p->data[2] + p->linesize[2] * cy; | |
1110 | |||
1111 | ✗ | s->llviddsp.add_median_pred(ydst, ydst - fake_ystride, | |
1112 | ✗ | s->temp[0], width, | |
1113 | &lefty, &lefttopy); | ||
1114 | ✗ | if (!(s->flags & AV_CODEC_FLAG_GRAY)) { | |
1115 | ✗ | s->llviddsp.add_median_pred(udst, udst - fake_ustride, s->temp[1], width2, &leftu, &lefttopu); | |
1116 | ✗ | s->llviddsp.add_median_pred(vdst, vdst - fake_vstride, s->temp[2], width2, &leftv, &lefttopv); | |
1117 | } | ||
1118 | } | ||
1119 | |||
1120 | ✗ | draw_slice(s, p, height); | |
1121 | ✗ | break; | |
1122 | } | ||
1123 | } | ||
1124 | } else { | ||
1125 | int y; | ||
1126 | uint8_t left[4]; | ||
1127 | 400 | const int last_line = (y_offset + height - 1) * p->linesize[0]; | |
1128 | |||
1129 |
2/2✓ Branch 0 taken 200 times.
✓ Branch 1 taken 200 times.
|
400 | if (s->bitstream_bpp == 32) { |
1130 | 200 | left[A] = p->data[0][last_line + A] = get_bits(&s->gb, 8); | |
1131 | 200 | left[R] = p->data[0][last_line + R] = get_bits(&s->gb, 8); | |
1132 | 200 | left[G] = p->data[0][last_line + G] = get_bits(&s->gb, 8); | |
1133 | 200 | left[B] = p->data[0][last_line + B] = get_bits(&s->gb, 8); | |
1134 | } else { | ||
1135 | 200 | left[R] = p->data[0][last_line + R] = get_bits(&s->gb, 8); | |
1136 | 200 | left[G] = p->data[0][last_line + G] = get_bits(&s->gb, 8); | |
1137 | 200 | left[B] = p->data[0][last_line + B] = get_bits(&s->gb, 8); | |
1138 | 200 | left[A] = p->data[0][last_line + A] = 255; | |
1139 | 200 | skip_bits(&s->gb, 8); | |
1140 | } | ||
1141 | |||
1142 |
1/2✓ Branch 0 taken 400 times.
✗ Branch 1 not taken.
|
400 | if (s->bgr32) { |
1143 |
1/2✓ Branch 0 taken 400 times.
✗ Branch 1 not taken.
|
400 | switch (s->predictor) { |
1144 | 400 | case LEFT: | |
1145 | case PLANE: | ||
1146 | 400 | decode_bgr_bitstream(s, width - 1); | |
1147 | 400 | s->hdsp.add_hfyu_left_pred_bgr32(p->data[0] + last_line + 4, | |
1148 | 400 | s->temp[0], width - 1, left); | |
1149 | |||
1150 |
2/2✓ Branch 0 taken 89400 times.
✓ Branch 1 taken 400 times.
|
89800 | for (y = height - 2; y >= 0; y--) { // Yes it is stored upside down. |
1151 | 89400 | decode_bgr_bitstream(s, width); | |
1152 | |||
1153 | 89400 | s->hdsp.add_hfyu_left_pred_bgr32(p->data[0] + p->linesize[0] * (y + y_offset), | |
1154 | 89400 | s->temp[0], width, left); | |
1155 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 89400 times.
|
89400 | if (s->predictor == PLANE) { |
1156 | ✗ | if (s->bitstream_bpp != 32) | |
1157 | ✗ | left[A] = 0; | |
1158 | ✗ | if (y < height - 1 - s->interlaced) { | |
1159 | ✗ | s->llviddsp.add_bytes(p->data[0] + p->linesize[0] * (y + y_offset), | |
1160 | ✗ | p->data[0] + p->linesize[0] * (y + y_offset) + | |
1161 | ✗ | fake_ystride, 4 * width); | |
1162 | } | ||
1163 | } | ||
1164 | } | ||
1165 | // just 1 large slice as this is not possible in reverse order | ||
1166 | 400 | draw_slice(s, p, height); | |
1167 | 400 | break; | |
1168 | ✗ | default: | |
1169 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1170 | "prediction type not supported!\n"); | ||
1171 | } | ||
1172 | } else { | ||
1173 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
1174 | "BGR24 output is not implemented yet\n"); | ||
1175 | ✗ | return AVERROR_PATCHWELCOME; | |
1176 | } | ||
1177 | } | ||
1178 | |||
1179 | 1610 | return 0; | |
1180 | } | ||
1181 | |||
1182 | 1610 | static int decode_frame(AVCodecContext *avctx, AVFrame *p, | |
1183 | int *got_frame, AVPacket *avpkt) | ||
1184 | { | ||
1185 | 1610 | const uint8_t *buf = avpkt->data; | |
1186 | 1610 | int buf_size = avpkt->size; | |
1187 | 1610 | HYuvContext *s = avctx->priv_data; | |
1188 | 1610 | const int width = s->width; | |
1189 | 1610 | const int height = s->height; | |
1190 | 1610 | int slice, table_size = 0, ret, nb_slices; | |
1191 | unsigned slices_info_offset; | ||
1192 | int slice_height; | ||
1193 | |||
1194 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1610 times.
|
1610 | if (buf_size < (width * height + 7)/8) |
1195 | ✗ | return AVERROR_INVALIDDATA; | |
1196 | |||
1197 | 1610 | av_fast_padded_malloc(&s->bitstream_buffer, | |
1198 | &s->bitstream_buffer_size, | ||
1199 | buf_size); | ||
1200 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1610 times.
|
1610 | if (!s->bitstream_buffer) |
1201 | ✗ | return AVERROR(ENOMEM); | |
1202 | |||
1203 | 1610 | s->bdsp.bswap_buf((uint32_t *) s->bitstream_buffer, | |
1204 | (const uint32_t *) buf, buf_size / 4); | ||
1205 | |||
1206 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1610 times.
|
1610 | if ((ret = ff_thread_get_buffer(avctx, p, 0)) < 0) |
1207 | ✗ | return ret; | |
1208 | |||
1209 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1610 times.
|
1610 | if (s->context) { |
1210 | ✗ | table_size = read_huffman_tables(s, s->bitstream_buffer, buf_size); | |
1211 | ✗ | if (table_size < 0) | |
1212 | ✗ | return table_size; | |
1213 | } | ||
1214 | |||
1215 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1610 times.
|
1610 | if ((unsigned) (buf_size - table_size) >= INT_MAX / 8) |
1216 | ✗ | return AVERROR_INVALIDDATA; | |
1217 | |||
1218 | 1610 | s->last_slice_end = 0; | |
1219 | |||
1220 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1610 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
1610 | if (avctx->codec_id == AV_CODEC_ID_HYMT && |
1221 | ✗ | (buf_size > 32 && AV_RL32(avpkt->data + buf_size - 16) == 0)) { | |
1222 | ✗ | slices_info_offset = AV_RL32(avpkt->data + buf_size - 4); | |
1223 | ✗ | slice_height = AV_RL32(avpkt->data + buf_size - 8); | |
1224 | ✗ | nb_slices = AV_RL32(avpkt->data + buf_size - 12); | |
1225 | ✗ | if (nb_slices * 8LL + slices_info_offset > buf_size - 16 || | |
1226 | ✗ | s->chroma_v_shift || | |
1227 | ✗ | slice_height <= 0 || nb_slices * (uint64_t)slice_height > height) | |
1228 | ✗ | return AVERROR_INVALIDDATA; | |
1229 | } else { | ||
1230 | 1610 | slice_height = height; | |
1231 | 1610 | nb_slices = 1; | |
1232 | } | ||
1233 | |||
1234 |
2/2✓ Branch 0 taken 1610 times.
✓ Branch 1 taken 1610 times.
|
3220 | for (slice = 0; slice < nb_slices; slice++) { |
1235 | int y_offset, slice_offset, slice_size; | ||
1236 | |||
1237 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1610 times.
|
1610 | if (nb_slices > 1) { |
1238 | ✗ | slice_offset = AV_RL32(avpkt->data + slices_info_offset + slice * 8); | |
1239 | ✗ | slice_size = AV_RL32(avpkt->data + slices_info_offset + slice * 8 + 4); | |
1240 | |||
1241 | ✗ | if (slice_offset < 0 || slice_size <= 0 || (slice_offset&3) || | |
1242 | ✗ | slice_offset + (int64_t)slice_size > buf_size) | |
1243 | ✗ | return AVERROR_INVALIDDATA; | |
1244 | |||
1245 | ✗ | y_offset = height - (slice + 1) * slice_height; | |
1246 | ✗ | s->bdsp.bswap_buf((uint32_t *)s->bitstream_buffer, | |
1247 | ✗ | (const uint32_t *)(buf + slice_offset), slice_size / 4); | |
1248 | } else { | ||
1249 | 1610 | y_offset = 0; | |
1250 | 1610 | slice_offset = 0; | |
1251 | 1610 | slice_size = buf_size; | |
1252 | } | ||
1253 | |||
1254 | 1610 | ret = decode_slice(avctx, p, slice_height, slice_size, y_offset, table_size); | |
1255 | 1610 | emms_c(); | |
1256 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1610 times.
|
1610 | if (ret < 0) |
1257 | ✗ | return ret; | |
1258 | } | ||
1259 | |||
1260 | 1610 | *got_frame = 1; | |
1261 | |||
1262 | 1610 | return (get_bits_count(&s->gb) + 31) / 32 * 4 + table_size; | |
1263 | } | ||
1264 | |||
1265 | const FFCodec ff_huffyuv_decoder = { | ||
1266 | .p.name = "huffyuv", | ||
1267 | .p.long_name = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"), | ||
1268 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
1269 | .p.id = AV_CODEC_ID_HUFFYUV, | ||
1270 | .priv_data_size = sizeof(HYuvContext), | ||
1271 | .init = decode_init, | ||
1272 | .close = decode_end, | ||
1273 | FF_CODEC_DECODE_CB(decode_frame), | ||
1274 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DRAW_HORIZ_BAND | | ||
1275 | AV_CODEC_CAP_FRAME_THREADS, | ||
1276 | .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, | ||
1277 | }; | ||
1278 | |||
1279 | #if CONFIG_FFVHUFF_DECODER | ||
1280 | const FFCodec ff_ffvhuff_decoder = { | ||
1281 | .p.name = "ffvhuff", | ||
1282 | .p.long_name = NULL_IF_CONFIG_SMALL("Huffyuv FFmpeg variant"), | ||
1283 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
1284 | .p.id = AV_CODEC_ID_FFVHUFF, | ||
1285 | .priv_data_size = sizeof(HYuvContext), | ||
1286 | .init = decode_init, | ||
1287 | .close = decode_end, | ||
1288 | FF_CODEC_DECODE_CB(decode_frame), | ||
1289 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DRAW_HORIZ_BAND | | ||
1290 | AV_CODEC_CAP_FRAME_THREADS, | ||
1291 | .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, | ||
1292 | }; | ||
1293 | #endif /* CONFIG_FFVHUFF_DECODER */ | ||
1294 | |||
1295 | #if CONFIG_HYMT_DECODER | ||
1296 | const FFCodec ff_hymt_decoder = { | ||
1297 | .p.name = "hymt", | ||
1298 | .p.long_name = NULL_IF_CONFIG_SMALL("HuffYUV MT"), | ||
1299 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
1300 | .p.id = AV_CODEC_ID_HYMT, | ||
1301 | .priv_data_size = sizeof(HYuvContext), | ||
1302 | .init = decode_init, | ||
1303 | .close = decode_end, | ||
1304 | FF_CODEC_DECODE_CB(decode_frame), | ||
1305 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DRAW_HORIZ_BAND | | ||
1306 | AV_CODEC_CAP_FRAME_THREADS, | ||
1307 | .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, | ||
1308 | }; | ||
1309 | #endif /* CONFIG_HYMT_DECODER */ | ||
1310 |