FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/snowdec.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 403 500 80.6%
Functions: 13 13 100.0%
Branches: 289 400 72.2%

Line Branch Exec Source
1 /*
2 * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "libavutil/emms.h"
22 #include "libavutil/intmath.h"
23 #include "libavutil/log.h"
24 #include "libavutil/mem.h"
25 #include "avcodec.h"
26 #include "codec_internal.h"
27 #include "decode.h"
28 #include "snow_dwt.h"
29 #include "snow.h"
30
31 #include "rangecoder.h"
32 #include "mathops.h"
33
34 398674 static inline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed)
35 {
36
2/2
✓ Branch 1 taken 181336 times.
✓ Branch 2 taken 217338 times.
398674 if (get_rac(c, state + 0))
37 181336 return 0;
38 else {
39 int e;
40 unsigned a;
41 217338 e = 0;
42
3/4
✓ Branch 0 taken 396567 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 179229 times.
✓ Branch 4 taken 217338 times.
396567 while (get_rac(c, state + 1 + FFMIN(e, 9))) { //1..10
43 179229 e++;
44
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 179229 times.
179229 if (e > 31)
45 return AVERROR_INVALIDDATA;
46 }
47
48 217338 a = 1;
49
2/2
✓ Branch 0 taken 179229 times.
✓ Branch 1 taken 217338 times.
396567 for (int i = e - 1; i >= 0; i--)
50
1/2
✓ Branch 0 taken 179229 times.
✗ Branch 1 not taken.
179229 a += a + get_rac(c, state + 22 + FFMIN(i, 9)); //22..31
51
52
5/6
✓ Branch 0 taken 216900 times.
✓ Branch 1 taken 438 times.
✓ Branch 2 taken 216900 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 84748 times.
✓ Branch 6 taken 132152 times.
217338 e = -(is_signed && get_rac(c, state + 11 + FFMIN(e, 10))); //11..21
53 217338 return (a ^ e) - e;
54 }
55 }
56
57 16813713 static inline int get_symbol2(RangeCoder *c, uint8_t *state, int log2)
58 {
59
2/2
✓ Branch 0 taken 7066249 times.
✓ Branch 1 taken 9747464 times.
16813713 int r = log2 >= 0 ? 1 << log2 : 1;
60 16813713 int v = 0;
61
62 av_assert2(log2 >= -4);
63
64
3/4
✓ Branch 0 taken 29173192 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 12359479 times.
✓ Branch 4 taken 16813713 times.
29173192 while (log2 < 28 && get_rac(c, state + 4 + log2)) {
65 12359479 v += r;
66 12359479 log2++;
67
2/2
✓ Branch 0 taken 9002801 times.
✓ Branch 1 taken 3356678 times.
12359479 if (log2 > 0) r += r;
68 }
69
70
2/2
✓ Branch 0 taken 17512479 times.
✓ Branch 1 taken 16813713 times.
34326192 for (int i = log2 - 1; i >= 0; i--)
71 17512479 v += get_rac(c, state + 31 - i) << i;
72
73 16813713 return v;
74 }
75
76 22128 static void unpack_coeffs(SnowContext *s, SubBand *b, SubBand * parent, int orientation)
77 {
78 22128 const int w = b->width;
79 22128 const int h = b->height;
80
81 int run, runs;
82 22128 x_and_coeff *xc = b->x_coeff;
83 22128 x_and_coeff *prev_xc = NULL;
84 22128 x_and_coeff *prev2_xc = xc;
85
2/2
✓ Branch 0 taken 16596 times.
✓ Branch 1 taken 5532 times.
22128 x_and_coeff *parent_xc = parent ? parent->x_coeff : NULL;
86 22128 x_and_coeff *prev_parent_xc = parent_xc;
87
88 22128 runs = get_symbol2(&s->c, b->state[30], 0);
89
2/2
✓ Branch 0 taken 17295 times.
✓ Branch 1 taken 4833 times.
22128 if (runs-- > 0) run = get_symbol2(&s->c, b->state[1], 3);
90 4833 else run = INT_MAX;
91
92
2/2
✓ Branch 0 taken 376000 times.
✓ Branch 1 taken 22128 times.
398128 for (int y = 0; y < h; y++) {
93 376000 int v = 0;
94 376000 int lt = 0, t = 0, rt = 0;
95
96
4/4
✓ Branch 0 taken 353872 times.
✓ Branch 1 taken 22128 times.
✓ Branch 2 taken 214455 times.
✓ Branch 3 taken 139417 times.
376000 if (y && prev_xc->x == 0)
97 214455 rt = prev_xc->coeff;
98
99
2/2
✓ Branch 0 taken 25206764 times.
✓ Branch 1 taken 376000 times.
25582764 for (int x = 0; x < w; x++) {
100 25206764 int p = 0;
101 25206764 const int l = v;
102
103 25206764 lt= t; t= rt;
104
105
2/2
✓ Branch 0 taken 24754930 times.
✓ Branch 1 taken 451834 times.
25206764 if (y) {
106
2/2
✓ Branch 0 taken 16207985 times.
✓ Branch 1 taken 8546945 times.
24754930 if (prev_xc->x <= x)
107 16207985 prev_xc++;
108
2/2
✓ Branch 0 taken 15993530 times.
✓ Branch 1 taken 8761400 times.
24754930 if (prev_xc->x == x + 1)
109 15993530 rt = prev_xc->coeff;
110 else
111 8761400 rt = 0;
112 }
113
2/2
✓ Branch 0 taken 25102735 times.
✓ Branch 1 taken 104029 times.
25206764 if (parent_xc) {
114
2/2
✓ Branch 0 taken 8437658 times.
✓ Branch 1 taken 16665077 times.
25102735 if (x>>1 > parent_xc->x)
115 8437658 parent_xc++;
116
2/2
✓ Branch 0 taken 17312584 times.
✓ Branch 1 taken 7790151 times.
25102735 if (x>>1 == parent_xc->x)
117 17312584 p = parent_xc->coeff;
118 }
119
2/2
✓ Branch 0 taken 24346735 times.
✓ Branch 1 taken 860029 times.
25206764 if (/*ll|*/l|lt|t|rt|p) {
120 24346735 int context = av_log2(/*FFABS(ll) + */3*(l>>1) + (lt>>1) + (t&~1) + (rt>>1) + (p>>1));
121
122 24346735 v = get_rac(&s->c, &b->state[0][context]);
123
2/2
✓ Branch 0 taken 16203821 times.
✓ Branch 1 taken 8142914 times.
24346735 if (v) {
124 16203821 v = 2*(get_symbol2(&s->c, b->state[context + 2], context-4) + 1);
125 16203821 v += get_rac(&s->c, &b->state[0][16 + 1 + 3 + ff_quant3bA[l&0xFF] + 3 * ff_quant3bA[t&0xFF]]);
126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16203821 times.
16203821 if ((uint16_t)v != v) {
127 av_log(s->avctx, AV_LOG_ERROR, "Coefficient damaged\n");
128 v = 1;
129 }
130 16203821 xc->x = x;
131 16203821 (xc++)->coeff = v;
132 }
133 } else {
134
2/2
✓ Branch 0 taken 293882 times.
✓ Branch 1 taken 566147 times.
860029 if (!run) {
135
2/2
✓ Branch 0 taken 276587 times.
✓ Branch 1 taken 17295 times.
293882 if (runs-- > 0) run = get_symbol2(&s->c, b->state[1], 3);
136 17295 else run = INT_MAX;
137 293882 v = 2 * (get_symbol2(&s->c, b->state[0 + 2], 0-4) + 1);
138 293882 v += get_rac(&s->c, &b->state[0][16 + 1 + 3]);
139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 293882 times.
293882 if ((uint16_t)v != v) {
140 av_log(s->avctx, AV_LOG_ERROR, "Coefficient damaged\n");
141 v = 1;
142 }
143
144 293882 xc->x = x;
145 293882 (xc++)->coeff = v;
146 } else {
147 int max_run;
148 566147 run--;
149 566147 v = 0;
150 av_assert2(run >= 0);
151
4/4
✓ Branch 0 taken 534471 times.
✓ Branch 1 taken 31676 times.
✓ Branch 2 taken 314287 times.
✓ Branch 3 taken 220184 times.
566147 if (y) max_run = FFMIN(run, prev_xc->x - x - 2);
152
2/2
✓ Branch 0 taken 8112 times.
✓ Branch 1 taken 23564 times.
31676 else max_run = FFMIN(run, w-x-1);
153
2/2
✓ Branch 0 taken 562248 times.
✓ Branch 1 taken 3899 times.
566147 if (parent_xc)
154
2/2
✓ Branch 0 taken 118292 times.
✓ Branch 1 taken 443956 times.
562248 max_run = FFMIN(max_run, 2*parent_xc->x - x - 1);
155 av_assert2(max_run >= 0 && max_run <= run);
156
157 566147 x += max_run;
158 566147 run -= max_run;
159 }
160 }
161 }
162 376000 (xc++)->x = w+1; //end marker
163 376000 prev_xc = prev2_xc;
164 376000 prev2_xc = xc;
165
166
2/2
✓ Branch 0 taken 360000 times.
✓ Branch 1 taken 16000 times.
376000 if (parent_xc) {
167
2/2
✓ Branch 0 taken 179538 times.
✓ Branch 1 taken 180462 times.
360000 if (y & 1) {
168
2/2
✓ Branch 0 taken 109725 times.
✓ Branch 1 taken 179538 times.
289263 while (parent_xc->x != parent->width+1)
169 109725 parent_xc++;
170 179538 parent_xc++;
171 179538 prev_parent_xc= parent_xc;
172 } else {
173 180462 parent_xc= prev_parent_xc;
174 }
175 }
176 }
177
178 22128 (xc++)->x = w + 1; //end marker
179 22128 }
180
181 21699 static av_always_inline void predict_slice_buffered(SnowContext *s, slice_buffer * sb, IDWTELEM * old_buffer, int plane_index, int add, int mb_y){
182 21699 Plane *p= &s->plane[plane_index];
183 21699 const int mb_w= s->b_width << s->block_max_depth;
184 21699 const int mb_h= s->b_height << s->block_max_depth;
185 int x, y, mb_x;
186 21699 int block_size = MB_SIZE >> s->block_max_depth;
187
2/2
✓ Branch 0 taken 14466 times.
✓ Branch 1 taken 7233 times.
21699 int block_w = plane_index ? block_size>>s->chroma_h_shift : block_size;
188
2/2
✓ Branch 0 taken 14466 times.
✓ Branch 1 taken 7233 times.
21699 int block_h = plane_index ? block_size>>s->chroma_v_shift : block_size;
189
2/2
✓ Branch 0 taken 14466 times.
✓ Branch 1 taken 7233 times.
21699 const uint8_t *obmc = plane_index ? ff_obmc_tab[s->block_max_depth+s->chroma_h_shift] : ff_obmc_tab[s->block_max_depth];
190
2/2
✓ Branch 0 taken 14466 times.
✓ Branch 1 taken 7233 times.
21699 int obmc_stride= plane_index ? (2*block_size)>>s->chroma_h_shift : 2*block_size;
191 21699 int ref_stride= s->current_picture->linesize[plane_index];
192 21699 uint8_t *dst8= s->current_picture->data[plane_index];
193 21699 int w= p->width;
194 21699 int h= p->height;
195
196
3/4
✓ Branch 0 taken 19035 times.
✓ Branch 1 taken 2664 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19035 times.
21699 if(s->keyframe || (s->avctx->debug&512)){
197
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 2496 times.
2664 if(mb_y==mb_h)
198 168 return;
199
200
1/2
✓ Branch 0 taken 2496 times.
✗ Branch 1 not taken.
2496 if(add){
201
2/2
✓ Branch 0 taken 15680 times.
✓ Branch 1 taken 2496 times.
18176 for(y=block_h*mb_y; y<FFMIN(h,block_h*(mb_y+1)); y++){
202 // DWTELEM * line = slice_buffer_get_line(sb, y);
203 15680 IDWTELEM * line = sb->line[y];
204
2/2
✓ Branch 0 taken 3343872 times.
✓ Branch 1 taken 15680 times.
3359552 for(x=0; x<w; x++){
205 // int v= buf[x + y*w] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1));
206 3343872 int v= line[x] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1));
207 3343872 v >>= FRAC_BITS;
208
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 3343746 times.
3343872 if(v&(~255)) v= ~(v>>31);
209 3343872 dst8[x + y*ref_stride]= v;
210 }
211 }
212 }else{
213 for(y=block_h*mb_y; y<FFMIN(h,block_h*(mb_y+1)); y++){
214 // DWTELEM * line = slice_buffer_get_line(sb, y);
215 IDWTELEM * line = sb->line[y];
216 for(x=0; x<w; x++){
217 line[x] -= 128 << FRAC_BITS;
218 // buf[x + y*w]-= 128<<FRAC_BITS;
219 }
220 }
221 }
222
223 2496 return;
224 }
225
226
2/2
✓ Branch 0 taken 710775 times.
✓ Branch 1 taken 19035 times.
729810 for(mb_x=0; mb_x<=mb_w; mb_x++){
227 710775 add_yblock(s, 1, sb, old_buffer, dst8, obmc,
228 710775 block_w*mb_x - block_w/2,
229 710775 block_h*mb_y - block_h/2,
230 block_w, block_h,
231 w, h,
232 w, ref_stride, obmc_stride,
233 mb_x - 1, mb_y - 1,
234 add, 0, plane_index);
235 }
236
237
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 19035 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
19035 if(s->avmv && mb_y < mb_h && plane_index == 0)
238 for(mb_x=0; mb_x<mb_w; mb_x++){
239 AVMotionVector *avmv = s->avmv + s->avmv_index;
240 const int b_width = s->b_width << s->block_max_depth;
241 const int b_stride= b_width;
242 BlockNode *bn= &s->block[mb_x + mb_y*b_stride];
243
244 if (bn->type)
245 continue;
246
247 s->avmv_index++;
248
249 avmv->w = block_w;
250 avmv->h = block_h;
251 avmv->dst_x = block_w*mb_x - block_w/2;
252 avmv->dst_y = block_h*mb_y - block_h/2;
253 avmv->motion_scale = 8;
254 avmv->motion_x = bn->mx * s->mv_scale;
255 avmv->motion_y = bn->my * s->mv_scale;
256 avmv->src_x = avmv->dst_x + avmv->motion_x / 8;
257 avmv->src_y = avmv->dst_y + avmv->motion_y / 8;
258 avmv->source= -1 - bn->ref;
259 avmv->flags = 0;
260 }
261 }
262
263 157912 static inline void decode_subband_slice_buffered(SnowContext *s, SubBand *b, slice_buffer * sb, int start_y, int h, int save_state[1]){
264 157912 const int w= b->width;
265 int y;
266 157912 const int qlog= av_clip(s->qlog + (int64_t)b->qlog, 0, QROOT*16);
267 157912 int qmul= ff_qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT);
268 157912 int qadd= (s->qbias*qmul)>>QBIAS_SHIFT;
269 157912 int new_index = 0;
270
271
4/4
✓ Branch 0 taken 156375 times.
✓ Branch 1 taken 1537 times.
✓ Branch 2 taken 129189 times.
✓ Branch 3 taken 27186 times.
157912 if(b->ibuf == s->spatial_idwt_buffer || s->qlog == LOSSLESS_QLOG){
272 130726 qadd= 0;
273 130726 qmul= 1<<QEXPSHIFT;
274 }
275
276 /* If we are on the second or later slice, restore our index. */
277
2/2
✓ Branch 0 taken 135784 times.
✓ Branch 1 taken 22128 times.
157912 if (start_y != 0)
278 135784 new_index = save_state[0];
279
280
281
2/2
✓ Branch 0 taken 376000 times.
✓ Branch 1 taken 157912 times.
533912 for(y=start_y; y<h; y++){
282 376000 int x = 0;
283 int v;
284
2/2
✓ Branch 0 taken 260289 times.
✓ Branch 1 taken 115711 times.
376000 IDWTELEM * line = slice_buffer_get_line(sb, y * b->stride_line + b->buf_y_offset) + b->buf_x_offset;
285 376000 memset(line, 0, b->width*sizeof(IDWTELEM));
286 376000 v = b->x_coeff[new_index].coeff;
287 376000 x = b->x_coeff[new_index++].x;
288
2/2
✓ Branch 0 taken 16497703 times.
✓ Branch 1 taken 376000 times.
16873703 while(x < w){
289 16497703 register int t= (int)( (v>>1)*(unsigned)qmul + qadd)>>QEXPSHIFT;
290 16497703 register int u= -(v&1);
291 16497703 line[x] = (t^u) - u;
292
293 16497703 v = b->x_coeff[new_index].coeff;
294 16497703 x = b->x_coeff[new_index++].x;
295 }
296 }
297
298 /* Save our variables for the next slice. */
299 157912 save_state[0] = new_index;
300
301 157912 return;
302 }
303
304 250860 static int decode_q_branch(SnowContext *s, int level, int x, int y){
305 250860 const int w= s->b_width << s->block_max_depth;
306 250860 const int rem_depth= s->block_max_depth - level;
307 250860 const int index= (x + y*w) << rem_depth;
308 250860 int trx= (x+1)<<rem_depth;
309
2/2
✓ Branch 0 taken 242678 times.
✓ Branch 1 taken 8182 times.
250860 const BlockNode *left = x ? &s->block[index-1] : &null_block;
310
2/2
✓ Branch 0 taken 239944 times.
✓ Branch 1 taken 10916 times.
250860 const BlockNode *top = y ? &s->block[index-w] : &null_block;
311
4/4
✓ Branch 0 taken 239944 times.
✓ Branch 1 taken 10916 times.
✓ Branch 2 taken 232338 times.
✓ Branch 3 taken 7606 times.
250860 const BlockNode *tl = y && x ? &s->block[index-w-1] : left;
312
8/8
✓ Branch 0 taken 239944 times.
✓ Branch 1 taken 10916 times.
✓ Branch 2 taken 232222 times.
✓ Branch 3 taken 7722 times.
✓ Branch 4 taken 112250 times.
✓ Branch 5 taken 119972 times.
✓ Branch 6 taken 28943 times.
✓ Branch 7 taken 83307 times.
250860 const BlockNode *tr = y && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt
313 250860 int s_context= 2*left->level + 2*top->level + tl->level + tr->level;
314 int res;
315
316
2/2
✓ Branch 0 taken 8708 times.
✓ Branch 1 taken 242152 times.
250860 if(s->keyframe){
317 8708 set_blocks(s, level, x, y, null_block.color[0], null_block.color[1], null_block.color[2], null_block.mx, null_block.my, null_block.ref, BLOCK_INTRA);
318 8708 return 0;
319 }
320
321
4/4
✓ Branch 0 taken 53460 times.
✓ Branch 1 taken 188692 times.
✓ Branch 3 taken 8447 times.
✓ Branch 4 taken 45013 times.
439291 if(level==s->block_max_depth || get_rac(&s->c, &s->block_state[4 + s_context])){
322 int type, mx, my;
323 197139 int l = left->color[0];
324 197139 int cb= left->color[1];
325 197139 int cr= left->color[2];
326 197139 unsigned ref = 0;
327 197139 int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref);
328 197139 int mx_context= av_log2(2*FFABS(left->mx - top->mx)) + 0*av_log2(2*FFABS(tr->mx - top->mx));
329 197139 int my_context= av_log2(2*FFABS(left->my - top->my)) + 0*av_log2(2*FFABS(tr->my - top->my));
330
331 197139 type= get_rac(&s->c, &s->block_state[1 + left->type + top->type]) ? BLOCK_INTRA : 0;
332
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 197088 times.
197139 if(type){
333 int ld, cbd, crd;
334 51 pred_mv(s, &mx, &my, 0, left, top, tr);
335 51 ld = get_symbol(&s->c, &s->block_state[32], 1);
336
2/4
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 51 times.
51 if (ld < -255 || ld > 255) {
337 return AVERROR_INVALIDDATA;
338 }
339 51 l += ld;
340
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 if (s->nb_planes > 2) {
341 51 cbd = get_symbol(&s->c, &s->block_state[64], 1);
342 51 crd = get_symbol(&s->c, &s->block_state[96], 1);
343
4/8
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 51 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 51 times.
51 if (cbd < -255 || cbd > 255 || crd < -255 || crd > 255) {
344 return AVERROR_INVALIDDATA;
345 }
346 51 cb += cbd;
347 51 cr += crd;
348 }
349 }else{
350
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 197088 times.
197088 if(s->ref_frames > 1)
351 ref= get_symbol(&s->c, &s->block_state[128 + 1024 + 32*ref_context], 0);
352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 197088 times.
197088 if (ref >= s->ref_frames) {
353 av_log(s->avctx, AV_LOG_ERROR, "Invalid ref\n");
354 return AVERROR_INVALIDDATA;
355 }
356 197088 pred_mv(s, &mx, &my, ref, left, top, tr);
357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 197088 times.
197088 mx+= (unsigned)get_symbol(&s->c, &s->block_state[128 + 32*(mx_context + 16*!!ref)], 1);
358
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 197088 times.
197088 my+= (unsigned)get_symbol(&s->c, &s->block_state[128 + 32*(my_context + 16*!!ref)], 1);
359 }
360 197139 set_blocks(s, level, x, y, l, cb, cr, mx, my, ref, type);
361 }else{
362
2/4
✓ Branch 1 taken 45013 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45013 times.
✗ Branch 4 not taken.
90026 if ((res = decode_q_branch(s, level+1, 2*x+0, 2*y+0)) < 0 ||
363
1/2
✓ Branch 1 taken 45013 times.
✗ Branch 2 not taken.
90026 (res = decode_q_branch(s, level+1, 2*x+1, 2*y+0)) < 0 ||
364
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45013 times.
90026 (res = decode_q_branch(s, level+1, 2*x+0, 2*y+1)) < 0 ||
365 45013 (res = decode_q_branch(s, level+1, 2*x+1, 2*y+1)) < 0)
366 return res;
367 }
368 242152 return 0;
369 }
370
371 1537 static void dequantize_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, IDWTELEM *src, int stride, int start_y, int end_y){
372 1537 const int w= b->width;
373 1537 const int qlog= av_clip(s->qlog + (int64_t)b->qlog, 0, QROOT*16);
374 1537 const int qmul= ff_qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT);
375 1537 const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT;
376 int x,y;
377
378
2/2
✓ Branch 0 taken 616 times.
✓ Branch 1 taken 921 times.
1537 if(s->qlog == LOSSLESS_QLOG) return;
379
380
2/2
✓ Branch 0 taken 1228 times.
✓ Branch 1 taken 921 times.
2149 for(y=start_y; y<end_y; y++){
381 // DWTELEM * line = slice_buffer_get_line_from_address(sb, src + (y * stride));
382
1/2
✓ Branch 0 taken 1228 times.
✗ Branch 1 not taken.
1228 IDWTELEM * line = slice_buffer_get_line(sb, (y * b->stride_line) + b->buf_y_offset) + b->buf_x_offset;
383
2/2
✓ Branch 0 taken 3684 times.
✓ Branch 1 taken 1228 times.
4912 for(x=0; x<w; x++){
384 3684 int i= line[x];
385
2/2
✓ Branch 0 taken 1595 times.
✓ Branch 1 taken 2089 times.
3684 if(i<0){
386 1595 line[x]= -((-i*(unsigned)qmul + qadd)>>(QEXPSHIFT)); //FIXME try different bias
387
2/2
✓ Branch 0 taken 980 times.
✓ Branch 1 taken 1109 times.
2089 }else if(i>0){
388 980 line[x]= (( i*(unsigned)qmul + qadd)>>(QEXPSHIFT));
389 }
390 }
391 }
392 }
393
394 1537 static void correlate_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median, int start_y, int end_y){
395 1537 const int w= b->width;
396 int x,y;
397
398 1537 IDWTELEM * line=0; // silence silly "could be used without having been initialized" warning
399 IDWTELEM * prev;
400
401
2/2
✓ Branch 0 taken 154 times.
✓ Branch 1 taken 1383 times.
1537 if (start_y != 0)
402
1/2
✓ Branch 0 taken 154 times.
✗ Branch 1 not taken.
154 line = slice_buffer_get_line(sb, ((start_y - 1) * b->stride_line) + b->buf_y_offset) + b->buf_x_offset;
403
404
2/2
✓ Branch 0 taken 4154 times.
✓ Branch 1 taken 1537 times.
5691 for(y=start_y; y<end_y; y++){
405 4154 prev = line;
406 // line = slice_buffer_get_line_from_address(sb, src + (y * stride));
407
1/2
✓ Branch 0 taken 4154 times.
✗ Branch 1 not taken.
4154 line = slice_buffer_get_line(sb, (y * b->stride_line) + b->buf_y_offset) + b->buf_x_offset;
408
2/2
✓ Branch 0 taken 28170 times.
✓ Branch 1 taken 4154 times.
32324 for(x=0; x<w; x++){
409
2/2
✓ Branch 0 taken 24016 times.
✓ Branch 1 taken 4154 times.
28170 if(x){
410
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24016 times.
24016 if(use_median){
411 if(y && x+1<w) line[x] += mid_pred(line[x - 1], prev[x], prev[x + 1]);
412 else line[x] += line[x - 1];
413 }else{
414
2/2
✓ Branch 0 taken 19401 times.
✓ Branch 1 taken 4615 times.
24016 if(y) line[x] += mid_pred(line[x - 1], prev[x], line[x - 1] + prev[x] - prev[x - 1]);
415 4615 else line[x] += line[x - 1];
416 }
417 }else{
418
2/2
✓ Branch 0 taken 2771 times.
✓ Branch 1 taken 1383 times.
4154 if(y) line[x] += prev[x];
419 }
420 }
421 }
422 1537 }
423
424 56 static void decode_qlogs(SnowContext *s){
425 int plane_index, level, orientation;
426
427
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 56 times.
224 for(plane_index=0; plane_index < s->nb_planes; plane_index++){
428
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 168 times.
1008 for(level=0; level<s->spatial_decomposition_count; level++){
429
2/2
✓ Branch 0 taken 2688 times.
✓ Branch 1 taken 840 times.
3528 for(orientation=level ? 1:0; orientation<4; orientation++){
430 int q;
431
2/2
✓ Branch 0 taken 896 times.
✓ Branch 1 taken 1792 times.
2688 if (plane_index==2) q= s->plane[1].band[level][orientation].qlog;
432
2/2
✓ Branch 0 taken 560 times.
✓ Branch 1 taken 1232 times.
1792 else if(orientation==2) q= s->plane[plane_index].band[level][1].qlog;
433 1232 else q= get_symbol(&s->c, s->header_state, 1);
434 2688 s->plane[plane_index].band[level][orientation].qlog= q;
435 }
436 }
437 }
438 56 }
439
440 #define GET_S(dst, check) \
441 tmp= get_symbol(&s->c, s->header_state, 0);\
442 if(!(check)){\
443 av_log(s->avctx, AV_LOG_ERROR, "Error " #dst " is %d\n", tmp);\
444 return AVERROR_INVALIDDATA;\
445 }\
446 dst= tmp;
447
448 461 static int decode_header(SnowContext *s){
449 int plane_index, tmp;
450 uint8_t kstate[32];
451
452 461 memset(kstate, MID_STATE, sizeof(kstate));
453
454 461 s->keyframe= get_rac(&s->c, kstate);
455
3/4
✓ Branch 0 taken 405 times.
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 405 times.
461 if(s->keyframe || s->always_reset){
456 56 ff_snow_reset_contexts(s);
457 56 s->spatial_decomposition_type=
458 56 s->qlog=
459 56 s->qbias=
460 56 s->mv_scale=
461 56 s->block_max_depth= 0;
462 }
463
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 405 times.
461 if(s->keyframe){
464
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
56 GET_S(s->version, tmp <= 0U)
465 56 s->always_reset= get_rac(&s->c, s->header_state);
466 56 s->temporal_decomposition_type= get_symbol(&s->c, s->header_state, 0);
467 56 s->temporal_decomposition_count= get_symbol(&s->c, s->header_state, 0);
468
2/4
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 56 times.
56 GET_S(s->spatial_decomposition_count, 0 < tmp && tmp <= MAX_DECOMPOSITIONS)
469 56 s->colorspace_type= get_symbol(&s->c, s->header_state, 0);
470
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 if (s->colorspace_type == 1) {
471 s->avctx->pix_fmt= AV_PIX_FMT_GRAY8;
472 s->nb_planes = 1;
473
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 } else if(s->colorspace_type == 0) {
474 56 s->chroma_h_shift= get_symbol(&s->c, s->header_state, 0);
475 56 s->chroma_v_shift= get_symbol(&s->c, s->header_state, 0);
476
477
2/4
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
✗ Branch 3 not taken.
56 if(s->chroma_h_shift == 1 && s->chroma_v_shift==1){
478 56 s->avctx->pix_fmt= AV_PIX_FMT_YUV420P;
479 }else if(s->chroma_h_shift == 0 && s->chroma_v_shift==0){
480 s->avctx->pix_fmt= AV_PIX_FMT_YUV444P;
481 }else if(s->chroma_h_shift == 2 && s->chroma_v_shift==2){
482 s->avctx->pix_fmt= AV_PIX_FMT_YUV410P;
483 } else {
484 av_log(s, AV_LOG_ERROR, "unsupported color subsample mode %d %d\n", s->chroma_h_shift, s->chroma_v_shift);
485 s->chroma_h_shift = s->chroma_v_shift = 1;
486 s->avctx->pix_fmt= AV_PIX_FMT_YUV420P;
487 return AVERROR_INVALIDDATA;
488 }
489 56 s->nb_planes = 3;
490 } else {
491 av_log(s, AV_LOG_ERROR, "unsupported color space\n");
492 s->chroma_h_shift = s->chroma_v_shift = 1;
493 s->avctx->pix_fmt= AV_PIX_FMT_YUV420P;
494 return AVERROR_INVALIDDATA;
495 }
496
497
498 56 s->spatial_scalability= get_rac(&s->c, s->header_state);
499 // s->rate_scalability= get_rac(&s->c, s->header_state);
500
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
56 GET_S(s->max_ref_frames, tmp < (unsigned)MAX_REF_FRAMES)
501 56 s->max_ref_frames++;
502
503 56 decode_qlogs(s);
504 }
505
506
2/2
✓ Branch 0 taken 405 times.
✓ Branch 1 taken 56 times.
461 if(!s->keyframe){
507
2/2
✓ Branch 1 taken 45 times.
✓ Branch 2 taken 360 times.
405 if(get_rac(&s->c, s->header_state)){
508
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 45 times.
135 for(plane_index=0; plane_index<FFMIN(s->nb_planes, 2); plane_index++){
509 90 int htaps, i, sum=0;
510 90 Plane *p= &s->plane[plane_index];
511 90 p->diag_mc= get_rac(&s->c, s->header_state);
512 90 htaps= get_symbol(&s->c, s->header_state, 0);
513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 90 times.
90 if((unsigned)htaps >= HTAPS_MAX/2 - 1)
514 return AVERROR_INVALIDDATA;
515 90 htaps = htaps*2 + 2;
516 90 p->htaps= htaps;
517
2/2
✓ Branch 0 taken 270 times.
✓ Branch 1 taken 90 times.
360 for(i= htaps/2; i; i--){
518 270 unsigned hcoeff = get_symbol(&s->c, s->header_state, 0);
519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 270 times.
270 if (hcoeff > 127)
520 return AVERROR_INVALIDDATA;
521 270 p->hcoeff[i]= hcoeff * (1-2*(i&1));
522 270 sum += p->hcoeff[i];
523 }
524 90 p->hcoeff[0]= 32-sum;
525 }
526 45 s->plane[2].diag_mc= s->plane[1].diag_mc;
527 45 s->plane[2].htaps = s->plane[1].htaps;
528 45 memcpy(s->plane[2].hcoeff, s->plane[1].hcoeff, sizeof(s->plane[1].hcoeff));
529 }
530
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 405 times.
405 if(get_rac(&s->c, s->header_state)){
531 GET_S(s->spatial_decomposition_count, 0 < tmp && tmp <= MAX_DECOMPOSITIONS)
532 decode_qlogs(s);
533 }
534 }
535
536 461 s->spatial_decomposition_type+= (unsigned)get_symbol(&s->c, s->header_state, 1);
537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if(s->spatial_decomposition_type > 1U){
538 av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_type %d not supported\n", s->spatial_decomposition_type);
539 return AVERROR_INVALIDDATA;
540 }
541 461 if(FFMIN(s->avctx-> width>>s->chroma_h_shift,
542
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 s->avctx->height>>s->chroma_v_shift) >> (s->spatial_decomposition_count-1) <= 1){
543 av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_count %d too large for size\n", s->spatial_decomposition_count);
544 return AVERROR_INVALIDDATA;
545 }
546
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if (s->avctx->width > 65536-4) {
547 av_log(s->avctx, AV_LOG_ERROR, "Width %d is too large\n", s->avctx->width);
548 return AVERROR_INVALIDDATA;
549 }
550
551
552 461 s->qlog += (unsigned)get_symbol(&s->c, s->header_state, 1);
553 461 s->mv_scale += (unsigned)get_symbol(&s->c, s->header_state, 1);
554 461 s->qbias += (unsigned)get_symbol(&s->c, s->header_state, 1);
555 461 s->block_max_depth+= (unsigned)get_symbol(&s->c, s->header_state, 1);
556
3/6
✓ Branch 0 taken 461 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 461 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 461 times.
461 if(s->block_max_depth > 1 || s->block_max_depth < 0 || s->mv_scale > 256U){
557 av_log(s->avctx, AV_LOG_ERROR, "block_max_depth= %d is too large\n", s->block_max_depth);
558 s->block_max_depth= 0;
559 s->mv_scale = 0;
560 return AVERROR_INVALIDDATA;
561 }
562
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if (FFABS(s->qbias) > 127) {
563 av_log(s->avctx, AV_LOG_ERROR, "qbias %d is too large\n", s->qbias);
564 s->qbias = 0;
565 return AVERROR_INVALIDDATA;
566 }
567
568 461 return 0;
569 }
570
571 461 static int decode_blocks(SnowContext *s){
572 int x, y;
573 461 int w= s->b_width;
574 461 int h= s->b_height;
575 int res;
576
577
2/2
✓ Branch 0 taken 4000 times.
✓ Branch 1 taken 461 times.
4461 for(y=0; y<h; y++){
578
2/2
✓ Branch 0 taken 70808 times.
✓ Branch 1 taken 4000 times.
74808 for(x=0; x<w; x++){
579
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70808 times.
70808 if (s->c.bytestream >= s->c.bytestream_end)
580 return AVERROR_INVALIDDATA;
581
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 70808 times.
70808 if ((res = decode_q_branch(s, 0, x, y)) < 0)
582 return res;
583 }
584 }
585 461 return 0;
586 }
587
588 461 static int decode_frame(AVCodecContext *avctx, AVFrame *picture,
589 int *got_frame, AVPacket *avpkt)
590 {
591 461 const uint8_t *buf = avpkt->data;
592 461 int buf_size = avpkt->size;
593 461 SnowContext *s = avctx->priv_data;
594 461 RangeCoder * const c= &s->c;
595 int bytes_read;
596 int level, orientation, plane_index;
597 int res;
598
599 461 ff_init_range_decoder(c, buf, buf_size);
600 461 ff_build_rac_states(c, 0.05*(1LL<<32), 256-8);
601
602 461 s->current_picture->pict_type= AV_PICTURE_TYPE_I; //FIXME I vs. P
603
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 461 times.
461 if ((res = decode_header(s)) < 0)
604 return res;
605
606
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 441 times.
461 if (!s->mconly_picture->data[0]) {
607 20 res = ff_get_buffer(avctx, s->mconly_picture, AV_GET_BUFFER_FLAG_REF);
608
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (res < 0)
609 return res;
610 }
611
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if (s->mconly_picture->format != avctx->pix_fmt) {
612 av_log(avctx, AV_LOG_ERROR, "pixel format changed\n");
613 return AVERROR_INVALIDDATA;
614 }
615
616
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 461 times.
461 if ((res=ff_snow_common_init_after_header(avctx)) < 0)
617 return res;
618
619 // realloc slice buffer for the case that spatial_decomposition_count changed
620 461 ff_slice_buffer_destroy(&s->sb);
621
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if ((res = ff_slice_buffer_init(&s->sb, s->plane[0].height,
622 461 (MB_SIZE >> s->block_max_depth) +
623 461 s->spatial_decomposition_count * 11 + 1,
624 s->plane[0].width,
625 s->spatial_idwt_buffer)) < 0)
626 return res;
627
628
2/2
✓ Branch 0 taken 1383 times.
✓ Branch 1 taken 461 times.
1844 for(plane_index=0; plane_index < s->nb_planes; plane_index++){
629 1383 Plane *p= &s->plane[plane_index];
630
2/4
✓ Branch 0 taken 1323 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1323 times.
✗ Branch 3 not taken.
2706 p->fast_mc= p->diag_mc && p->htaps==6 && p->hcoeff[0]==40
631
1/2
✓ Branch 0 taken 1323 times.
✗ Branch 1 not taken.
1323 && p->hcoeff[1]==-10
632
3/4
✓ Branch 0 taken 1323 times.
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 1323 times.
✗ Branch 3 not taken.
2706 && p->hcoeff[2]==2;
633 }
634
635 461 ff_snow_alloc_blocks(s);
636
637
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 461 times.
461 if ((res = ff_snow_frames_prepare(s)) < 0)
638 return res;
639
640 461 s->current_picture->width = s->avctx->width;
641 461 s->current_picture->height = s->avctx->height;
642 461 res = ff_get_buffer(s->avctx, s->current_picture, AV_GET_BUFFER_FLAG_REF);
643
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if (res < 0)
644 return res;
645
646
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 405 times.
461 s->current_picture->pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
647
648 //keyframe flag duplication mess FIXME
649
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if(avctx->debug&FF_DEBUG_PICT_INFO)
650 av_log(avctx, AV_LOG_ERROR,
651 "keyframe:%d qlog:%d qbias: %d mvscale: %d "
652 "decomposition_type:%d decomposition_count:%d\n",
653 s->keyframe, s->qlog, s->qbias, s->mv_scale,
654 s->spatial_decomposition_type,
655 s->spatial_decomposition_count
656 );
657
658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if (s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_MVS) {
659 size_t size;
660 res = av_size_mult(s->b_width * s->b_height, sizeof(AVMotionVector) << (s->block_max_depth*2), &size);
661 if (res)
662 return res;
663 av_fast_malloc(&s->avmv, &s->avmv_size, size);
664 if (!s->avmv)
665 return AVERROR(ENOMEM);
666 } else {
667 461 s->avmv_size = 0;
668 461 av_freep(&s->avmv);
669 }
670 461 s->avmv_index = 0;
671
672
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 461 times.
461 if ((res = decode_blocks(s)) < 0)
673 return res;
674
675
2/2
✓ Branch 0 taken 1383 times.
✓ Branch 1 taken 461 times.
1844 for(plane_index=0; plane_index < s->nb_planes; plane_index++){
676 1383 Plane *p= &s->plane[plane_index];
677 1383 int w= p->width;
678 1383 int h= p->height;
679 int x, y;
680 int decode_state[MAX_DECOMPOSITIONS][4][1]; /* Stored state info for unpack_coeffs. 1 variable per instance. */
681
682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1383 times.
1383 if(s->avctx->debug&2048){
683 memset(s->spatial_dwt_buffer, 0, sizeof(DWTELEM)*w*h);
684 predict_plane(s, s->spatial_idwt_buffer, plane_index, 1);
685
686 for(y=0; y<h; y++){
687 for(x=0; x<w; x++){
688 int v= s->current_picture->data[plane_index][y*s->current_picture->linesize[plane_index] + x];
689 s->mconly_picture->data[plane_index][y*s->mconly_picture->linesize[plane_index] + x]= v;
690 }
691 }
692 }
693
694
2/2
✓ Branch 0 taken 6915 times.
✓ Branch 1 taken 1383 times.
8298 for(level=0; level<s->spatial_decomposition_count; level++){
695
2/2
✓ Branch 0 taken 22128 times.
✓ Branch 1 taken 6915 times.
29043 for(orientation=level ? 1 : 0; orientation<4; orientation++){
696 22128 SubBand *b= &p->band[level][orientation];
697 22128 unpack_coeffs(s, b, b->parent, orientation);
698 }
699 }
700
701 {
702 1383 const int mb_h= s->b_height << s->block_max_depth;
703 1383 const int block_size = MB_SIZE >> s->block_max_depth;
704
2/2
✓ Branch 0 taken 922 times.
✓ Branch 1 taken 461 times.
1383 const int block_h = plane_index ? block_size>>s->chroma_v_shift : block_size;
705 int mb_y;
706 DWTCompose cs[MAX_DECOMPOSITIONS];
707 1383 int yd=0, yq=0;
708 int y;
709 int end_y;
710
711 1383 ff_spatial_idwt_buffered_init(cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count);
712
2/2
✓ Branch 0 taken 21699 times.
✓ Branch 1 taken 1383 times.
23082 for(mb_y=0; mb_y<=mb_h; mb_y++){
713
714 21699 int slice_starty = block_h*mb_y;
715 21699 int slice_h = block_h*(mb_y+1);
716
717
3/4
✓ Branch 0 taken 19035 times.
✓ Branch 1 taken 2664 times.
✓ Branch 2 taken 19035 times.
✗ Branch 3 not taken.
21699 if (!(s->keyframe || s->avctx->debug&512)){
718 19035 slice_starty = FFMAX(0, slice_starty - (block_h >> 1));
719 19035 slice_h -= (block_h >> 1);
720 }
721
722
2/2
✓ Branch 0 taken 108495 times.
✓ Branch 1 taken 21699 times.
130194 for(level=0; level<s->spatial_decomposition_count; level++){
723
2/2
✓ Branch 0 taken 347184 times.
✓ Branch 1 taken 108495 times.
455679 for(orientation=level ? 1 : 0; orientation<4; orientation++){
724 347184 SubBand *b= &p->band[level][orientation];
725 int start_y;
726 int end_y;
727 347184 int our_mb_start = mb_y;
728 347184 int our_mb_end = (mb_y + 1);
729 347184 const int extra= 3;
730
2/2
✓ Branch 0 taken 325056 times.
✓ Branch 1 taken 22128 times.
347184 start_y = (mb_y ? ((block_h * our_mb_start) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra: 0);
731 347184 end_y = (((block_h * our_mb_end) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra);
732
3/4
✓ Branch 0 taken 304560 times.
✓ Branch 1 taken 42624 times.
✓ Branch 2 taken 304560 times.
✗ Branch 3 not taken.
347184 if (!(s->keyframe || s->avctx->debug&512)){
733 304560 start_y = FFMAX(0, start_y - (block_h >> (1+s->spatial_decomposition_count - level)));
734 304560 end_y = FFMAX(0, end_y - (block_h >> (1+s->spatial_decomposition_count - level)));
735 }
736 347184 start_y = FFMIN(b->height, start_y);
737 347184 end_y = FFMIN(b->height, end_y);
738
739
2/2
✓ Branch 0 taken 157912 times.
✓ Branch 1 taken 189272 times.
347184 if (start_y != end_y){
740
2/2
✓ Branch 0 taken 1537 times.
✓ Branch 1 taken 156375 times.
157912 if (orientation == 0){
741 1537 SubBand * correlate_band = &p->band[0][0];
742 1537 int correlate_end_y = FFMIN(b->height, end_y + 1);
743
2/2
✓ Branch 0 taken 154 times.
✓ Branch 1 taken 1383 times.
1537 int correlate_start_y = FFMIN(b->height, (start_y ? start_y + 1 : 0));
744 1537 decode_subband_slice_buffered(s, correlate_band, &s->sb, correlate_start_y, correlate_end_y, decode_state[0][0]);
745 1537 correlate_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, 1, 0, correlate_start_y, correlate_end_y);
746 1537 dequantize_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, start_y, end_y);
747 }
748 else
749 156375 decode_subband_slice_buffered(s, b, &s->sb, start_y, end_y, decode_state[level][orientation]);
750 }
751 }
752 }
753
754
2/2
✓ Branch 0 taken 33857 times.
✓ Branch 1 taken 21699 times.
55556 for(; yd<slice_h; yd+=4){
755 33857 ff_spatial_idwt_buffered_slice(&s->dwt, cs, &s->sb, s->temp_idwt_buffer, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count, yd);
756 }
757
758
2/2
✓ Branch 0 taken 17094 times.
✓ Branch 1 taken 4605 times.
21699 if(s->qlog == LOSSLESS_QLOG){
759
4/4
✓ Branch 0 taken 89166 times.
✓ Branch 1 taken 16632 times.
✓ Branch 2 taken 88704 times.
✓ Branch 3 taken 462 times.
105798 for(; yq<slice_h && yq<h; yq++){
760
1/2
✓ Branch 0 taken 88704 times.
✗ Branch 1 not taken.
88704 IDWTELEM * line = slice_buffer_get_line(&s->sb, yq);
761
2/2
✓ Branch 0 taken 23417856 times.
✓ Branch 1 taken 88704 times.
23506560 for(x=0; x<w; x++){
762 23417856 line[x] *= 1<<FRAC_BITS;
763 }
764 }
765 }
766
767 21699 predict_slice_buffered(s, &s->sb, s->spatial_idwt_buffer, plane_index, 1, mb_y);
768
769 21699 y = FFMIN(p->height, slice_starty);
770 21699 end_y = FFMIN(p->height, slice_h);
771
2/2
✓ Branch 0 taken 128000 times.
✓ Branch 1 taken 21699 times.
149699 while(y < end_y)
772 128000 ff_slice_buffer_release(&s->sb, y++);
773 }
774
775 1383 ff_slice_buffer_flush(&s->sb);
776 }
777
778 }
779
780 461 emms_c();
781
782 461 ff_snow_release_buffer(avctx);
783
784
1/2
✓ Branch 0 taken 461 times.
✗ Branch 1 not taken.
461 if(!(s->avctx->debug&2048))
785 461 res = av_frame_ref(picture, s->current_picture);
786 else
787 res = av_frame_ref(picture, s->mconly_picture);
788
2/4
✓ Branch 0 taken 461 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 461 times.
461 if (res >= 0 && s->avmv_index) {
789 AVFrameSideData *sd;
790
791 sd = av_frame_new_side_data(picture, AV_FRAME_DATA_MOTION_VECTORS, s->avmv_index * sizeof(AVMotionVector));
792 if (!sd)
793 return AVERROR(ENOMEM);
794 memcpy(sd->data, s->avmv, s->avmv_index * sizeof(AVMotionVector));
795 }
796
797
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if (res < 0)
798 return res;
799
800 461 *got_frame = 1;
801
802 461 bytes_read= c->bytestream - c->bytestream_start;
803
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if(bytes_read ==0) av_log(s->avctx, AV_LOG_ERROR, "error at end of frame\n"); //FIXME
804
805 461 return bytes_read;
806 }
807
808 20 static av_cold int decode_end(AVCodecContext *avctx)
809 {
810 20 SnowContext *s = avctx->priv_data;
811
812 20 ff_slice_buffer_destroy(&s->sb);
813
814 20 ff_snow_common_end(s);
815
816 20 s->avmv_size = 0;
817 20 av_freep(&s->avmv);
818
819 20 return 0;
820 }
821
822 const FFCodec ff_snow_decoder = {
823 .p.name = "snow",
824 CODEC_LONG_NAME("Snow"),
825 .p.type = AVMEDIA_TYPE_VIDEO,
826 .p.id = AV_CODEC_ID_SNOW,
827 .priv_data_size = sizeof(SnowContext),
828 .init = ff_snow_common_init,
829 .close = decode_end,
830 FF_CODEC_DECODE_CB(decode_frame),
831 .p.capabilities = AV_CODEC_CAP_DR1,
832 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
833 };
834