FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/snow.c
Date: 2025-07-12 02:25:37
Exec Total Coverage
Lines: 323 345 93.6%
Functions: 13 18 72.2%
Branches: 173 204 84.8%

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/log.h"
22 #include "libavutil/mem.h"
23 #include "libavutil/thread.h"
24 #include "avcodec.h"
25 #include "snow_dwt.h"
26 #include "snow.h"
27 #include "snowdata.h"
28
29
30 710775 void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h,
31 int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){
32 int y, x;
33 IDWTELEM * dst;
34
2/2
✓ Branch 0 taken 3810240 times.
✓ Branch 1 taken 710775 times.
4521015 for(y=0; y<b_h; y++){
35 //FIXME ugly misuse of obmc_stride
36 3810240 const uint8_t *obmc1= obmc + y*obmc_stride;
37 3810240 const uint8_t *obmc2= obmc1+ (obmc_stride>>1);
38 3810240 const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1);
39 3810240 const uint8_t *obmc4= obmc3+ (obmc_stride>>1);
40
1/2
✓ Branch 0 taken 3810240 times.
✗ Branch 1 not taken.
3810240 dst = slice_buffer_get_line(sb, src_y + y);
41
2/2
✓ Branch 0 taken 23846400 times.
✓ Branch 1 taken 3810240 times.
27656640 for(x=0; x<b_w; x++){
42 23846400 int v= obmc1[x] * block[3][x + y*src_stride]
43 23846400 +obmc2[x] * block[2][x + y*src_stride]
44 23846400 +obmc3[x] * block[1][x + y*src_stride]
45 23846400 +obmc4[x] * block[0][x + y*src_stride];
46
47 23846400 v <<= 8 - LOG2_OBMC_MAX;
48 if(FRAC_BITS != 8){
49 23846400 v >>= 8 - FRAC_BITS;
50 }
51
1/2
✓ Branch 0 taken 23846400 times.
✗ Branch 1 not taken.
23846400 if(add){
52 23846400 v += dst[x + src_x];
53 23846400 v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS;
54
2/2
✓ Branch 0 taken 1126 times.
✓ Branch 1 taken 23845274 times.
23846400 if(v&(~255)) v= ~(v>>31);
55 23846400 dst8[x + y*src_stride] = v;
56 }else{
57 dst[x + src_x] -= v;
58 }
59 }
60 }
61 710775 }
62
63 103 void ff_snow_reset_contexts(SnowContext *s){ //FIXME better initial contexts
64 int plane_index, level, orientation;
65
66
2/2
✓ Branch 0 taken 309 times.
✓ Branch 1 taken 103 times.
412 for(plane_index=0; plane_index<3; plane_index++){
67
2/2
✓ Branch 0 taken 2472 times.
✓ Branch 1 taken 309 times.
2781 for(level=0; level<MAX_DECOMPOSITIONS; level++){
68
2/2
✓ Branch 0 taken 7725 times.
✓ Branch 1 taken 2472 times.
10197 for(orientation=level ? 1:0; orientation<4; orientation++){
69 7725 memset(s->plane[plane_index].band[level][orientation].state, MID_STATE, sizeof(s->plane[plane_index].band[level][orientation].state));
70 }
71 }
72 }
73 103 memset(s->header_state, MID_STATE, sizeof(s->header_state));
74 103 memset(s->block_state, MID_STATE, sizeof(s->block_state));
75 103 }
76
77 472 int ff_snow_alloc_blocks(SnowContext *s){
78 472 int w= AV_CEIL_RSHIFT(s->avctx->width, LOG2_MB_SIZE);
79 472 int h= AV_CEIL_RSHIFT(s->avctx->height, LOG2_MB_SIZE);
80
81 472 s->b_width = w;
82 472 s->b_height= h;
83
84 472 av_free(s->block);
85 472 s->block = av_calloc(w * h, sizeof(*s->block) << (s->block_max_depth*2));
86
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 472 times.
472 if (!s->block)
87 return AVERROR(ENOMEM);
88
89 472 return 0;
90 }
91
92 3238956 static void mc_block(Plane *p, uint8_t *dst, const uint8_t *src, int stride, int b_w, int b_h, int dx, int dy){
93 static const uint8_t weight[64]={
94 8,7,6,5,4,3,2,1,
95 7,7,0,0,0,0,0,1,
96 6,0,6,0,0,0,2,0,
97 5,0,0,5,0,3,0,0,
98 4,0,0,0,4,0,0,0,
99 3,0,0,5,0,3,0,0,
100 2,0,6,0,0,0,2,0,
101 1,7,0,0,0,0,0,1,
102 };
103
104 static const uint8_t brane[256]={
105 0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x11,0x12,0x12,0x12,0x12,0x12,0x12,0x12,
106 0x04,0x05,0xcc,0xcc,0xcc,0xcc,0xcc,0x41,0x15,0x16,0xcc,0xcc,0xcc,0xcc,0xcc,0x52,
107 0x04,0xcc,0x05,0xcc,0xcc,0xcc,0x41,0xcc,0x15,0xcc,0x16,0xcc,0xcc,0xcc,0x52,0xcc,
108 0x04,0xcc,0xcc,0x05,0xcc,0x41,0xcc,0xcc,0x15,0xcc,0xcc,0x16,0xcc,0x52,0xcc,0xcc,
109 0x04,0xcc,0xcc,0xcc,0x41,0xcc,0xcc,0xcc,0x15,0xcc,0xcc,0xcc,0x16,0xcc,0xcc,0xcc,
110 0x04,0xcc,0xcc,0x41,0xcc,0x05,0xcc,0xcc,0x15,0xcc,0xcc,0x52,0xcc,0x16,0xcc,0xcc,
111 0x04,0xcc,0x41,0xcc,0xcc,0xcc,0x05,0xcc,0x15,0xcc,0x52,0xcc,0xcc,0xcc,0x16,0xcc,
112 0x04,0x41,0xcc,0xcc,0xcc,0xcc,0xcc,0x05,0x15,0x52,0xcc,0xcc,0xcc,0xcc,0xcc,0x16,
113 0x44,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x55,0x56,0x56,0x56,0x56,0x56,0x56,0x56,
114 0x48,0x49,0xcc,0xcc,0xcc,0xcc,0xcc,0x85,0x59,0x5A,0xcc,0xcc,0xcc,0xcc,0xcc,0x96,
115 0x48,0xcc,0x49,0xcc,0xcc,0xcc,0x85,0xcc,0x59,0xcc,0x5A,0xcc,0xcc,0xcc,0x96,0xcc,
116 0x48,0xcc,0xcc,0x49,0xcc,0x85,0xcc,0xcc,0x59,0xcc,0xcc,0x5A,0xcc,0x96,0xcc,0xcc,
117 0x48,0xcc,0xcc,0xcc,0x49,0xcc,0xcc,0xcc,0x59,0xcc,0xcc,0xcc,0x96,0xcc,0xcc,0xcc,
118 0x48,0xcc,0xcc,0x85,0xcc,0x49,0xcc,0xcc,0x59,0xcc,0xcc,0x96,0xcc,0x5A,0xcc,0xcc,
119 0x48,0xcc,0x85,0xcc,0xcc,0xcc,0x49,0xcc,0x59,0xcc,0x96,0xcc,0xcc,0xcc,0x5A,0xcc,
120 0x48,0x85,0xcc,0xcc,0xcc,0xcc,0xcc,0x49,0x59,0x96,0xcc,0xcc,0xcc,0xcc,0xcc,0x5A,
121 };
122
123 static const uint8_t needs[16]={
124 0,1,0,0,
125 2,4,2,0,
126 0,1,0,0,
127 15
128 };
129
130 int x, y, b, r, l;
131 int16_t tmpIt [64*(32+HTAPS_MAX)];
132 uint8_t tmp2t[3][64*(32+HTAPS_MAX)];
133 3238956 int16_t *tmpI= tmpIt;
134 3238956 uint8_t *tmp2= tmp2t[0];
135 const uint8_t *hpel[11];
136 av_assert2(dx<16 && dy<16);
137 3238956 r= brane[dx + 16*dy]&15;
138 3238956 l= brane[dx + 16*dy]>>4;
139
140 3238956 b= needs[l] | needs[r];
141
3/4
✓ Branch 0 taken 3218702 times.
✓ Branch 1 taken 20254 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3218702 times.
3238956 if(p && !p->diag_mc)
142 b= 15;
143
144
2/2
✓ Branch 0 taken 2901279 times.
✓ Branch 1 taken 337677 times.
3238956 if(b&5){
145
2/2
✓ Branch 0 taken 32974513 times.
✓ Branch 1 taken 2901279 times.
35875792 for(y=0; y < b_h+HTAPS_MAX-1; y++){
146
2/2
✓ Branch 0 taken 151101864 times.
✓ Branch 1 taken 32974513 times.
184076377 for(x=0; x < b_w; x++){
147 151101864 int a_1=src[x + HTAPS_MAX/2-4];
148 151101864 int a0= src[x + HTAPS_MAX/2-3];
149 151101864 int a1= src[x + HTAPS_MAX/2-2];
150 151101864 int a2= src[x + HTAPS_MAX/2-1];
151 151101864 int a3= src[x + HTAPS_MAX/2+0];
152 151101864 int a4= src[x + HTAPS_MAX/2+1];
153 151101864 int a5= src[x + HTAPS_MAX/2+2];
154 151101864 int a6= src[x + HTAPS_MAX/2+3];
155 151101864 int am=0;
156
3/4
✓ Branch 0 taken 145476984 times.
✓ Branch 1 taken 5624880 times.
✓ Branch 2 taken 145476984 times.
✗ Branch 3 not taken.
151101864 if(!p || p->fast_mc){
157 151101864 am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5);
158 151101864 tmpI[x]= am;
159 151101864 am= (am+16)>>5;
160 }else{
161 am= p->hcoeff[0]*(a2+a3) + p->hcoeff[1]*(a1+a4) + p->hcoeff[2]*(a0+a5) + p->hcoeff[3]*(a_1+a6);
162 tmpI[x]= am;
163 am= (am+32)>>6;
164 }
165
166
2/2
✓ Branch 0 taken 6243 times.
✓ Branch 1 taken 151095621 times.
151101864 if(am&(~255)) am= ~(am>>31);
167 151101864 tmp2[x]= am;
168 }
169 32974513 tmpI+= 64;
170 32974513 tmp2+= 64;
171 32974513 src += stride;
172 }
173 2901279 src -= stride*y;
174 }
175 3238956 src += HTAPS_MAX/2 - 1;
176 3238956 tmp2= tmp2t[1];
177
178
2/2
✓ Branch 0 taken 1994649 times.
✓ Branch 1 taken 1244307 times.
3238956 if(b&2){
179
2/2
✓ Branch 0 taken 8670672 times.
✓ Branch 1 taken 1994649 times.
10665321 for(y=0; y < b_h; y++){
180
2/2
✓ Branch 0 taken 49856760 times.
✓ Branch 1 taken 8670672 times.
58527432 for(x=0; x < b_w+1; x++){
181 49856760 int a_1=src[x + (HTAPS_MAX/2-4)*stride];
182 49856760 int a0= src[x + (HTAPS_MAX/2-3)*stride];
183 49856760 int a1= src[x + (HTAPS_MAX/2-2)*stride];
184 49856760 int a2= src[x + (HTAPS_MAX/2-1)*stride];
185 49856760 int a3= src[x + (HTAPS_MAX/2+0)*stride];
186 49856760 int a4= src[x + (HTAPS_MAX/2+1)*stride];
187 49856760 int a5= src[x + (HTAPS_MAX/2+2)*stride];
188 49856760 int a6= src[x + (HTAPS_MAX/2+3)*stride];
189 49856760 int am=0;
190
3/4
✓ Branch 0 taken 48505192 times.
✓ Branch 1 taken 1351568 times.
✓ Branch 2 taken 48505192 times.
✗ Branch 3 not taken.
49856760 if(!p || p->fast_mc)
191 49856760 am= (20*(a2+a3) - 5*(a1+a4) + (a0+a5) + 16)>>5;
192 else
193 am= (p->hcoeff[0]*(a2+a3) + p->hcoeff[1]*(a1+a4) + p->hcoeff[2]*(a0+a5) + p->hcoeff[3]*(a_1+a6) + 32)>>6;
194
195
2/2
✓ Branch 0 taken 3684 times.
✓ Branch 1 taken 49853076 times.
49856760 if(am&(~255)) am= ~(am>>31);
196 49856760 tmp2[x]= am;
197 }
198 8670672 src += stride;
199 8670672 tmp2+= 64;
200 }
201 1994649 src -= stride*y;
202 }
203 3238956 src += stride*(HTAPS_MAX/2 - 1);
204 3238956 tmp2= tmp2t[2];
205 3238956 tmpI= tmpIt;
206
2/2
✓ Branch 0 taken 1955604 times.
✓ Branch 1 taken 1283352 times.
3238956 if(b&4){
207
2/2
✓ Branch 0 taken 8482028 times.
✓ Branch 1 taken 1955604 times.
10437632 for(y=0; y < b_h; y++){
208
2/2
✓ Branch 0 taken 40800992 times.
✓ Branch 1 taken 8482028 times.
49283020 for(x=0; x < b_w; x++){
209 40800992 int a_1=tmpI[x + (HTAPS_MAX/2-4)*64];
210 40800992 int a0= tmpI[x + (HTAPS_MAX/2-3)*64];
211 40800992 int a1= tmpI[x + (HTAPS_MAX/2-2)*64];
212 40800992 int a2= tmpI[x + (HTAPS_MAX/2-1)*64];
213 40800992 int a3= tmpI[x + (HTAPS_MAX/2+0)*64];
214 40800992 int a4= tmpI[x + (HTAPS_MAX/2+1)*64];
215 40800992 int a5= tmpI[x + (HTAPS_MAX/2+2)*64];
216 40800992 int a6= tmpI[x + (HTAPS_MAX/2+3)*64];
217 40800992 int am=0;
218
3/4
✓ Branch 0 taken 38303968 times.
✓ Branch 1 taken 2497024 times.
✓ Branch 2 taken 38303968 times.
✗ Branch 3 not taken.
40800992 if(!p || p->fast_mc)
219 40800992 am= (20*(a2+a3) - 5*(a1+a4) + (a0+a5) + 512)>>10;
220 else
221 am= (p->hcoeff[0]*(a2+a3) + p->hcoeff[1]*(a1+a4) + p->hcoeff[2]*(a0+a5) + p->hcoeff[3]*(a_1+a6) + 2048)>>12;
222
2/2
✓ Branch 0 taken 6658 times.
✓ Branch 1 taken 40794334 times.
40800992 if(am&(~255)) am= ~(am>>31);
223 40800992 tmp2[x]= am;
224 }
225 8482028 tmpI+= 64;
226 8482028 tmp2+= 64;
227 }
228 }
229
230 3238956 hpel[ 0]= src;
231 3238956 hpel[ 1]= tmp2t[0] + 64*(HTAPS_MAX/2-1);
232 3238956 hpel[ 2]= src + 1;
233
234 3238956 hpel[ 4]= tmp2t[1];
235 3238956 hpel[ 5]= tmp2t[2];
236 3238956 hpel[ 6]= tmp2t[1] + 1;
237
238 3238956 hpel[ 8]= src + stride;
239 3238956 hpel[ 9]= hpel[1] + 64;
240 3238956 hpel[10]= hpel[8] + 1;
241
242 #define MC_STRIDE(x) (needs[x] ? 64 : stride)
243
244
2/2
✓ Branch 0 taken 788972 times.
✓ Branch 1 taken 2449984 times.
3238956 if(b==15){
245 788972 int dxy = dx / 8 + dy / 8 * 4;
246 788972 const uint8_t *src1 = hpel[dxy ];
247 788972 const uint8_t *src2 = hpel[dxy + 1];
248 788972 const uint8_t *src3 = hpel[dxy + 4];
249 788972 const uint8_t *src4 = hpel[dxy + 5];
250
2/2
✓ Branch 0 taken 197818 times.
✓ Branch 1 taken 591154 times.
788972 int stride1 = MC_STRIDE(dxy);
251
2/2
✓ Branch 0 taken 202002 times.
✓ Branch 1 taken 586970 times.
788972 int stride2 = MC_STRIDE(dxy + 1);
252
2/2
✓ Branch 0 taken 191082 times.
✓ Branch 1 taken 597890 times.
788972 int stride3 = MC_STRIDE(dxy + 4);
253
2/2
✓ Branch 0 taken 198070 times.
✓ Branch 1 taken 590902 times.
788972 int stride4 = MC_STRIDE(dxy + 5);
254 788972 dx&=7;
255 788972 dy&=7;
256
2/2
✓ Branch 0 taken 3463864 times.
✓ Branch 1 taken 788972 times.
4252836 for(y=0; y < b_h; y++){
257
2/2
✓ Branch 0 taken 16558488 times.
✓ Branch 1 taken 3463864 times.
20022352 for(x=0; x < b_w; x++){
258 16558488 dst[x]= ((8-dx)*(8-dy)*src1[x] + dx*(8-dy)*src2[x]+
259 16558488 (8-dx)* dy *src3[x] + dx* dy *src4[x]+32)>>6;
260 }
261 3463864 src1+=stride1;
262 3463864 src2+=stride2;
263 3463864 src3+=stride3;
264 3463864 src4+=stride4;
265 3463864 dst +=stride;
266 }
267 }else{
268 2449984 const uint8_t *src1= hpel[l];
269 2449984 const uint8_t *src2= hpel[r];
270
2/2
✓ Branch 0 taken 600514 times.
✓ Branch 1 taken 1849470 times.
2449984 int stride1 = MC_STRIDE(l);
271
2/2
✓ Branch 0 taken 655574 times.
✓ Branch 1 taken 1794410 times.
2449984 int stride2 = MC_STRIDE(r);
272 2449984 int a= weight[((dx&7) + (8*(dy&7)))];
273 2449984 int b= 8-a;
274
2/2
✓ Branch 0 taken 10722180 times.
✓ Branch 1 taken 2449984 times.
13172164 for(y=0; y < b_h; y++){
275
2/2
✓ Branch 0 taken 52915648 times.
✓ Branch 1 taken 10722180 times.
63637828 for(x=0; x < b_w; x++){
276 52915648 dst[x]= (a*src1[x] + b*src2[x] + 4)>>3;
277 }
278 10722180 src1+=stride1;
279 10722180 src2+=stride2;
280 10722180 dst +=stride;
281 }
282 }
283 3238956 }
284
285 9378971 void ff_snow_pred_block(SnowContext *s, uint8_t *dst, uint8_t *tmp, ptrdiff_t stride, int sx, int sy, int b_w, int b_h, const BlockNode *block, int plane_index, int w, int h){
286
2/2
✓ Branch 0 taken 1264886 times.
✓ Branch 1 taken 8114085 times.
9378971 if(block->type & BLOCK_INTRA){
287 int x, y;
288 1264886 const unsigned color = block->color[plane_index];
289 1264886 const unsigned color4 = color*0x01010101;
290
2/2
✓ Branch 0 taken 18314 times.
✓ Branch 1 taken 1246572 times.
1264886 if(b_w==32){
291
2/2
✓ Branch 0 taken 586048 times.
✓ Branch 1 taken 18314 times.
604362 for(y=0; y < b_h; y++){
292 586048 *(uint32_t*)&dst[0 + y*stride]= color4;
293 586048 *(uint32_t*)&dst[4 + y*stride]= color4;
294 586048 *(uint32_t*)&dst[8 + y*stride]= color4;
295 586048 *(uint32_t*)&dst[12+ y*stride]= color4;
296 586048 *(uint32_t*)&dst[16+ y*stride]= color4;
297 586048 *(uint32_t*)&dst[20+ y*stride]= color4;
298 586048 *(uint32_t*)&dst[24+ y*stride]= color4;
299 586048 *(uint32_t*)&dst[28+ y*stride]= color4;
300 }
301
2/2
✓ Branch 0 taken 131925 times.
✓ Branch 1 taken 1114647 times.
1246572 }else if(b_w==16){
302
2/2
✓ Branch 0 taken 1980368 times.
✓ Branch 1 taken 131925 times.
2112293 for(y=0; y < b_h; y++){
303 1980368 *(uint32_t*)&dst[0 + y*stride]= color4;
304 1980368 *(uint32_t*)&dst[4 + y*stride]= color4;
305 1980368 *(uint32_t*)&dst[8 + y*stride]= color4;
306 1980368 *(uint32_t*)&dst[12+ y*stride]= color4;
307 }
308
2/2
✓ Branch 0 taken 546968 times.
✓ Branch 1 taken 567679 times.
1114647 }else if(b_w==8){
309
2/2
✓ Branch 0 taken 4285880 times.
✓ Branch 1 taken 546968 times.
4832848 for(y=0; y < b_h; y++){
310 4285880 *(uint32_t*)&dst[0 + y*stride]= color4;
311 4285880 *(uint32_t*)&dst[4 + y*stride]= color4;
312 }
313
2/2
✓ Branch 0 taken 566717 times.
✓ Branch 1 taken 962 times.
567679 }else if(b_w==4){
314
2/2
✓ Branch 0 taken 2309300 times.
✓ Branch 1 taken 566717 times.
2876017 for(y=0; y < b_h; y++){
315 2309300 *(uint32_t*)&dst[0 + y*stride]= color4;
316 }
317 }else{
318
2/2
✓ Branch 0 taken 3788 times.
✓ Branch 1 taken 962 times.
4750 for(y=0; y < b_h; y++){
319
2/2
✓ Branch 0 taken 7576 times.
✓ Branch 1 taken 3788 times.
11364 for(x=0; x < b_w; x++){
320 7576 dst[x + y*stride]= color;
321 }
322 }
323 }
324 }else{
325 8114085 const uint8_t *src = s->last_picture[block->ref]->data[plane_index];
326
2/2
✓ Branch 0 taken 5217306 times.
✓ Branch 1 taken 2896779 times.
8114085 const int scale= plane_index ? (2*s->mv_scale)>>s->chroma_h_shift : 2*s->mv_scale;
327 8114085 int mx= block->mx*scale;
328 8114085 int my= block->my*scale;
329 8114085 const int dx= mx&15;
330 8114085 const int dy= my&15;
331 8114085 const int tab_index= 3 - (b_w>>2) + (b_w>>4);
332 8114085 sx += (mx>>4) - (HTAPS_MAX/2-1);
333 8114085 sy += (my>>4) - (HTAPS_MAX/2-1);
334 8114085 src += sx + sy*stride;
335
3/4
✓ Branch 0 taken 8114085 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7603914 times.
✓ Branch 3 taken 510171 times.
8114085 if( (unsigned)sx >= FFMAX(w - b_w - (HTAPS_MAX-2), 0)
336
3/4
✓ Branch 0 taken 7603914 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 642542 times.
✓ Branch 3 taken 6961372 times.
7603914 || (unsigned)sy >= FFMAX(h - b_h - (HTAPS_MAX-2), 0)){
337 1152713 s->vdsp.emulated_edge_mc(tmp + MB_SIZE, src,
338 stride, stride,
339 b_w+HTAPS_MAX-1, b_h+HTAPS_MAX-1,
340 sx, sy, w, h);
341 1152713 src= tmp + MB_SIZE;
342 }
343
344 av_assert2(s->chroma_h_shift == s->chroma_v_shift); // only one mv_scale
345
346 av_assert2((tab_index>=0 && tab_index<4) || b_w==32);
347
4/4
✓ Branch 0 taken 5949457 times.
✓ Branch 1 taken 2164628 times.
✓ Branch 2 taken 4895383 times.
✓ Branch 3 taken 1054074 times.
8114085 if( (dx&3) || (dy&3)
348
5/6
✓ Branch 0 taken 349196 times.
✓ Branch 1 taken 4546187 times.
✓ Branch 2 taken 204358 times.
✓ Branch 3 taken 144838 times.
✓ Branch 4 taken 204358 times.
✗ Branch 5 not taken.
4895383 || !(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h)
349
1/2
✓ Branch 0 taken 4895383 times.
✗ Branch 1 not taken.
4895383 || (b_w&(b_w-1))
350
1/2
✓ Branch 0 taken 4895383 times.
✗ Branch 1 not taken.
4895383 || b_w == 1
351
1/2
✓ Branch 0 taken 4895383 times.
✗ Branch 1 not taken.
4895383 || b_h == 1
352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4895383 times.
4895383 || !s->plane[plane_index].fast_mc )
353 3218702 mc_block(&s->plane[plane_index], dst, src, stride, b_w, b_h, dx, dy);
354
2/2
✓ Branch 0 taken 288126 times.
✓ Branch 1 taken 4607257 times.
4895383 else if(b_w==32){
355 int y;
356
2/2
✓ Branch 0 taken 576252 times.
✓ Branch 1 taken 288126 times.
864378 for(y=0; y<b_h; y+=16){
357 576252 s->h264qpel.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + y*stride, src + 3 + (y+3)*stride,stride);
358 576252 s->h264qpel.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + 16 + y*stride, src + 19 + (y+3)*stride,stride);
359 }
360
2/2
✓ Branch 0 taken 4258061 times.
✓ Branch 1 taken 349196 times.
4607257 }else if(b_w==b_h)
361 4258061 s->h264qpel.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst,src + 3 + 3*stride,stride);
362
2/2
✓ Branch 0 taken 204358 times.
✓ Branch 1 taken 144838 times.
349196 else if(b_w==2*b_h){
363 204358 s->h264qpel.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst ,src + 3 + 3*stride,stride);
364 204358 s->h264qpel.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst+b_h,src + 3 + b_h + 3*stride,stride);
365 }else{
366 av_assert2(2*b_w==b_h);
367 144838 s->h264qpel.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst ,src + 3 + 3*stride ,stride);
368 144838 s->h264qpel.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst+b_w*stride,src + 3 + 3*stride+b_w*stride,stride);
369 }
370 }
371 9378971 }
372
373 #define mca(dx,dy,b_w)\
374 static void mc_block_hpel ## dx ## dy ## b_w(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h){\
375 av_assert2(h==b_w);\
376 mc_block(NULL, dst, src-(HTAPS_MAX/2-1)-(HTAPS_MAX/2-1)*stride, stride, b_w, b_w, dx, dy);\
377 }
378
379 mca( 0, 0,16)
380 5531 mca( 8, 0,16)
381 4969 mca( 0, 8,16)
382 9754 mca( 8, 8,16)
383 mca( 0, 0,8)
384 mca( 8, 0,8)
385 mca( 0, 8,8)
386 mca( 8, 8,8)
387
388 22 static av_cold void snow_static_init(void)
389 {
390
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 22 times.
198 for (int i = 0; i < MAX_REF_FRAMES; i++)
391
2/2
✓ Branch 0 taken 1408 times.
✓ Branch 1 taken 176 times.
1584 for (int j = 0; j < MAX_REF_FRAMES; j++)
392 1408 ff_scale_mv_ref[i][j] = 256 * (i + 1) / (j + 1);
393 22 }
394
395 31 av_cold int ff_snow_common_init(AVCodecContext *avctx){
396 static AVOnce init_static_once = AV_ONCE_INIT;
397 31 SnowContext *s = avctx->priv_data;
398 int width, height;
399 int i;
400
401 31 s->avctx= avctx;
402 31 s->max_ref_frames=1; //just make sure it's not an invalid value in case of no initial keyframe
403 31 s->spatial_decomposition_count = 1;
404
405 31 ff_videodsp_init(&s->vdsp, 8);
406 31 ff_dwt_init(&s->dwt);
407 31 ff_h264qpel_init(&s->h264qpel, 8);
408
409 #define mcfh(dx,dy)\
410 s->hdsp.put_pixels_tab [0][dy/4+dx/8]=\
411 s->hdsp.put_no_rnd_pixels_tab[0][dy/4+dx/8]=\
412 mc_block_hpel ## dx ## dy ## 16;\
413 s->hdsp.put_pixels_tab [1][dy/4+dx/8]=\
414 s->hdsp.put_no_rnd_pixels_tab[1][dy/4+dx/8]=\
415 mc_block_hpel ## dx ## dy ## 8;
416
417 31 mcfh(0, 0)
418 31 mcfh(8, 0)
419 31 mcfh(0, 8)
420 31 mcfh(8, 8)
421
422 // dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift);
423
424 31 width= s->avctx->width;
425 31 height= s->avctx->height;
426
427
1/2
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
31 if (!FF_ALLOCZ_TYPED_ARRAY(s->spatial_idwt_buffer, width * height) ||
428
1/2
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
31 !FF_ALLOCZ_TYPED_ARRAY(s->spatial_dwt_buffer, width * height) || //FIXME this does not belong here
429
1/2
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
31 !FF_ALLOCZ_TYPED_ARRAY(s->temp_dwt_buffer, width) ||
430
1/2
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
31 !FF_ALLOCZ_TYPED_ARRAY(s->temp_idwt_buffer, width) ||
431
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
31 !FF_ALLOCZ_TYPED_ARRAY(s->run_buffer, ((width + 1) >> 1) * ((height + 1) >> 1) + 1))
432 return AVERROR(ENOMEM);
433
434
2/2
✓ Branch 0 taken 248 times.
✓ Branch 1 taken 31 times.
279 for(i=0; i<MAX_REF_FRAMES; i++) {
435 248 s->last_picture[i] = av_frame_alloc();
436
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 248 times.
248 if (!s->last_picture[i])
437 return AVERROR(ENOMEM);
438 }
439
440 31 s->mconly_picture = av_frame_alloc();
441 31 s->current_picture = av_frame_alloc();
442
2/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31 times.
31 if (!s->mconly_picture || !s->current_picture)
443 return AVERROR(ENOMEM);
444
445 31 ff_thread_once(&init_static_once, snow_static_init);
446
447 31 return 0;
448 }
449
450 973 int ff_snow_common_init_after_header(AVCodecContext *avctx) {
451 973 SnowContext *s = avctx->priv_data;
452 int plane_index, level, orientation;
453
454
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 942 times.
973 if(!s->scratchbuf) {
455 int emu_buf_size;
456 31 emu_buf_size = FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * (2 * MB_SIZE + HTAPS_MAX - 1);
457
1/2
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
31 if (!FF_ALLOCZ_TYPED_ARRAY(s->scratchbuf, FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * 7 * MB_SIZE) ||
458
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
31 !FF_ALLOCZ_TYPED_ARRAY(s->emu_edge_buffer, emu_buf_size))
459 return AVERROR(ENOMEM);
460 }
461
462
2/2
✓ Branch 0 taken 2919 times.
✓ Branch 1 taken 973 times.
3892 for(plane_index=0; plane_index < s->nb_planes; plane_index++){
463 2919 int w= s->avctx->width;
464 2919 int h= s->avctx->height;
465
466
2/2
✓ Branch 0 taken 1946 times.
✓ Branch 1 taken 973 times.
2919 if(plane_index){
467 1946 w = AV_CEIL_RSHIFT(w, s->chroma_h_shift);
468 1946 h = AV_CEIL_RSHIFT(h, s->chroma_v_shift);
469 }
470 2919 s->plane[plane_index].width = w;
471 2919 s->plane[plane_index].height= h;
472
473
2/2
✓ Branch 0 taken 14595 times.
✓ Branch 1 taken 2919 times.
17514 for(level=s->spatial_decomposition_count-1; level>=0; level--){
474
2/2
✓ Branch 0 taken 46704 times.
✓ Branch 1 taken 14595 times.
61299 for(orientation=level ? 1 : 0; orientation<4; orientation++){
475 46704 SubBand *b= &s->plane[plane_index].band[level][orientation];
476
477 46704 b->buf= s->spatial_dwt_buffer;
478 46704 b->level= level;
479 46704 b->stride= s->plane[plane_index].width << (s->spatial_decomposition_count - level);
480 46704 b->width = (w + !(orientation&1))>>1;
481 46704 b->height= (h + !(orientation>1))>>1;
482
483 46704 b->stride_line = 1 << (s->spatial_decomposition_count - level);
484 46704 b->buf_x_offset = 0;
485 46704 b->buf_y_offset = 0;
486
487
2/2
✓ Branch 0 taken 29190 times.
✓ Branch 1 taken 17514 times.
46704 if(orientation&1){
488 29190 b->buf += (w+1)>>1;
489 29190 b->buf_x_offset = (w+1)>>1;
490 }
491
2/2
✓ Branch 0 taken 29190 times.
✓ Branch 1 taken 17514 times.
46704 if(orientation>1){
492 29190 b->buf += b->stride>>1;
493 29190 b->buf_y_offset = b->stride_line >> 1;
494 }
495 46704 b->ibuf= s->spatial_idwt_buffer + (b->buf - s->spatial_dwt_buffer);
496
497
2/2
✓ Branch 0 taken 35028 times.
✓ Branch 1 taken 11676 times.
46704 if(level)
498 35028 b->parent= &s->plane[plane_index].band[level-1][orientation];
499 //FIXME avoid this realloc
500 46704 av_freep(&b->x_coeff);
501 46704 b->x_coeff = av_calloc((b->width + 1) * b->height + 1,
502 sizeof(*b->x_coeff));
503
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46704 times.
46704 if (!b->x_coeff)
504 return AVERROR(ENOMEM);
505 }
506 14595 w= (w+1)>>1;
507 14595 h= (h+1)>>1;
508 }
509 }
510
511 973 return 0;
512 }
513
514 973 int ff_snow_frames_prepare(SnowContext *s)
515 {
516 AVFrame *tmp;
517
518 973 tmp= s->last_picture[s->max_ref_frames-1];
519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 973 times.
973 for (int i = s->max_ref_frames - 1; i > 0; i--)
520 s->last_picture[i] = s->last_picture[i-1];
521 973 s->last_picture[0] = s->current_picture;
522 973 s->current_picture = tmp;
523
524 973 av_frame_unref(s->current_picture);
525
526
2/2
✓ Branch 0 taken 103 times.
✓ Branch 1 taken 870 times.
973 if(s->keyframe){
527 103 s->ref_frames= 0;
528 103 s->current_picture->flags |= AV_FRAME_FLAG_KEY;
529 }else{
530 int i;
531
3/4
✓ Branch 0 taken 870 times.
✓ Branch 1 taken 870 times.
✓ Branch 2 taken 870 times.
✗ Branch 3 not taken.
1740 for(i=0; i<s->max_ref_frames && s->last_picture[i]->data[0]; i++)
532
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 870 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
870 if(i && (s->last_picture[i-1]->flags & AV_FRAME_FLAG_KEY))
533 break;
534 870 s->ref_frames= i;
535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 870 times.
870 if(s->ref_frames==0){
536 av_log(s->avctx,AV_LOG_ERROR, "No reference frames\n");
537 return AVERROR_INVALIDDATA;
538 }
539 870 s->current_picture->flags &= ~AV_FRAME_FLAG_KEY;
540 }
541
542 973 return 0;
543 }
544
545 31 av_cold void ff_snow_common_end(SnowContext *s)
546 {
547 int plane_index, level, orientation, i;
548
549 31 av_freep(&s->spatial_dwt_buffer);
550 31 av_freep(&s->temp_dwt_buffer);
551 31 av_freep(&s->spatial_idwt_buffer);
552 31 av_freep(&s->temp_idwt_buffer);
553 31 av_freep(&s->run_buffer);
554
555 31 av_freep(&s->block);
556 31 av_freep(&s->scratchbuf);
557 31 av_freep(&s->emu_edge_buffer);
558
559
2/2
✓ Branch 0 taken 248 times.
✓ Branch 1 taken 31 times.
279 for(i=0; i<MAX_REF_FRAMES; i++){
560 248 av_frame_free(&s->last_picture[i]);
561 }
562
563
2/2
✓ Branch 0 taken 124 times.
✓ Branch 1 taken 31 times.
155 for(plane_index=0; plane_index < MAX_PLANES; plane_index++){
564
2/2
✓ Branch 0 taken 992 times.
✓ Branch 1 taken 124 times.
1116 for(level=MAX_DECOMPOSITIONS-1; level>=0; level--){
565
2/2
✓ Branch 0 taken 3100 times.
✓ Branch 1 taken 992 times.
4092 for(orientation=level ? 1 : 0; orientation<4; orientation++){
566 3100 SubBand *b= &s->plane[plane_index].band[level][orientation];
567
568 3100 av_freep(&b->x_coeff);
569 }
570 }
571 }
572 31 av_frame_free(&s->mconly_picture);
573 31 av_frame_free(&s->current_picture);
574 31 }
575