FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/snow.c
Date: 2026-04-22 18:56:46
Exec Total Coverage
Lines: 386 408 94.6%
Functions: 33 38 86.8%
Branches: 180 210 85.7%

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 <assert.h>
22
23 #include "libavutil/avassert.h"
24 #include "libavutil/log.h"
25 #include "libavutil/mem.h"
26 #include "libavutil/thread.h"
27 #include "avcodec.h"
28 #include "snow_dwt.h"
29 #include "snow.h"
30 #include "snowdata.h"
31
32 #define pixeltmp int16_t
33 #define BIT_DEPTH 8
34 #define SNOW
35 #include "h264qpel_template.c"
36
37 58634 static void put_snow_qpel2_h_lowpass_8(uint8_t *dst, const uint8_t *restrict src, int dstStride, int srcStride)
38 {
39 58634 const int h = 2;
40
2/2
✓ Branch 0 taken 117268 times.
✓ Branch 1 taken 58634 times.
175902 for (int i = 0; i < h; ++i) {
41 117268 dst[0] = av_clip_uint8(((src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]) + 16) >> 5);
42 117268 dst[1] = av_clip_uint8(((src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]) + 16) >> 5);
43 117268 dst += dstStride;
44 117268 src += srcStride;
45 }
46 58634 }
47
48 65508 static void put_snow_qpel2_v_lowpass_8(uint8_t *dst, const uint8_t *restrict src, int dstStride, int srcStride)
49 {
50 65508 const int w = 2;
51
2/2
✓ Branch 0 taken 131016 times.
✓ Branch 1 taken 65508 times.
196524 for (int i = 0; i < w; ++i) {
52 131016 const int srcB = src[-2*srcStride];
53 131016 const int srcA = src[-1*srcStride];
54 131016 const int src0 = src[0 *srcStride];
55 131016 const int src1 = src[1 *srcStride];
56 131016 const int src2 = src[2 *srcStride];
57 131016 const int src3 = src[3 *srcStride];
58 131016 const int src4 = src[4 *srcStride];
59 131016 dst[0*dstStride] = av_clip_uint8(((src0+src1)*20 - (srcA+src2)*5 + (srcB+src3) + 16) >> 5);
60 131016 dst[1*dstStride] = av_clip_uint8(((src1+src2)*20 - (src0+src3)*5 + (srcA+src4) + 16) >> 5);
61 131016 dst++;
62 131016 src++;
63 }
64 65508 }
65
66 59440 static void put_snow_qpel2_hv_lowpass_8(uint8_t *dst, pixeltmp *tmp, const uint8_t *restrict src, int dstStride, int tmpStride, int srcStride)
67 {
68 59440 const int h = 2;
69 59440 const int w = 2;
70 59440 src -= 2*srcStride;
71
2/2
✓ Branch 0 taken 416080 times.
✓ Branch 1 taken 59440 times.
475520 for (int i = 0; i < h + 5; ++i) {
72 416080 tmp[0] = (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);
73 416080 tmp[1] = (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);
74 416080 tmp += tmpStride;
75 416080 src += srcStride;
76 }
77 59440 tmp -= tmpStride*(h+5-2);
78
2/2
✓ Branch 0 taken 118880 times.
✓ Branch 1 taken 59440 times.
178320 for (int i = 0; i < w; ++i) {
79 118880 const int tmpB = tmp[-2*tmpStride];
80 118880 const int tmpA = tmp[-1*tmpStride];
81 118880 const int tmp0 = tmp[0 *tmpStride];
82 118880 const int tmp1 = tmp[1 *tmpStride];
83 118880 const int tmp2 = tmp[2 *tmpStride];
84 118880 const int tmp3 = tmp[3 *tmpStride];
85 118880 const int tmp4 = tmp[4 *tmpStride];
86 118880 dst[0*dstStride] = av_clip_uint8(((tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3) + 512) >> 10);
87 118880 dst[1*dstStride] = av_clip_uint8(((tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4) + 512) >> 10);
88 118880 dst++;
89 118880 tmp++;
90 }
91 59440 }
92
93 391404 H264_MC(put_, snow, 2)
94
95 31 static av_cold void init_qpel(SnowContext *const s)
96 {
97 static_assert(offsetof(H264QpelContext, put_h264_qpel_pixels_tab) == 0,
98 "put_h264_qpel_pixels_tab not at start of H264QpelContext");
99 31 ff_h264qpel_init(&s->h264qpel, 8);
100 31 s->put_snow_qpel_pixels_tab[3][0] = put_snow_qpel2_mc00_8_c;
101 31 s->put_snow_qpel_pixels_tab[3][1] = put_snow_qpel2_mc10_8_c;
102 31 s->put_snow_qpel_pixels_tab[3][2] = put_snow_qpel2_mc20_8_c;
103 31 s->put_snow_qpel_pixels_tab[3][3] = put_snow_qpel2_mc30_8_c;
104 31 s->put_snow_qpel_pixels_tab[3][4] = put_snow_qpel2_mc01_8_c;
105 31 s->put_snow_qpel_pixels_tab[3][5] = put_snow_qpel2_mc11_8_c;
106 31 s->put_snow_qpel_pixels_tab[3][6] = put_snow_qpel2_mc21_8_c;
107 31 s->put_snow_qpel_pixels_tab[3][7] = put_snow_qpel2_mc31_8_c;
108 31 s->put_snow_qpel_pixels_tab[3][8] = put_snow_qpel2_mc02_8_c;
109 31 s->put_snow_qpel_pixels_tab[3][9] = put_snow_qpel2_mc12_8_c;
110 31 s->put_snow_qpel_pixels_tab[3][10] = put_snow_qpel2_mc22_8_c;
111 31 s->put_snow_qpel_pixels_tab[3][11] = put_snow_qpel2_mc32_8_c;
112 31 s->put_snow_qpel_pixels_tab[3][12] = put_snow_qpel2_mc03_8_c;
113 31 s->put_snow_qpel_pixels_tab[3][13] = put_snow_qpel2_mc13_8_c;
114 31 s->put_snow_qpel_pixels_tab[3][14] = put_snow_qpel2_mc23_8_c;
115 31 s->put_snow_qpel_pixels_tab[3][15] = put_snow_qpel2_mc33_8_c;
116 31 }
117
118 710805 void ff_snow_inner_add_yblock_c(const uint8_t *obmc, const int obmc_stride, uint8_t **block, int b_w, int b_h,
119 int src_x, int src_stride, IDWTELEM *const *lines, int add, uint8_t *dst8)
120 {
121 int y, x;
122
123
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 710805 times.
710805 av_assume(add); // add == 0 is currently unused
124
125
2/2
✓ Branch 0 taken 3810456 times.
✓ Branch 1 taken 710805 times.
4521261 for(y=0; y<b_h; y++){
126 //FIXME ugly misuse of obmc_stride
127 3810456 const uint8_t *obmc1= obmc + y*obmc_stride;
128 3810456 const uint8_t *obmc2= obmc1+ (obmc_stride>>1);
129 3810456 const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1);
130 3810456 const uint8_t *obmc4= obmc3+ (obmc_stride>>1);
131 3810456 IDWTELEM *dst = lines[y];
132 av_assert2(dst);
133
134
2/2
✓ Branch 0 taken 23847888 times.
✓ Branch 1 taken 3810456 times.
27658344 for(x=0; x<b_w; x++){
135 23847888 int v= obmc1[x] * block[3][x + y*src_stride]
136 23847888 +obmc2[x] * block[2][x + y*src_stride]
137 23847888 +obmc3[x] * block[1][x + y*src_stride]
138 23847888 +obmc4[x] * block[0][x + y*src_stride];
139
140 #if FRAC_BITS > LOG2_OBMC_MAX
141 v <<= FRAC_BITS - LOG2_OBMC_MAX;
142 #elif FRAC_BITS < LOG2_OBMC_MAX
143 23847888 v >>= LOG2_OBMC_MAX - FRAC_BITS;
144 #endif
145
1/2
✓ Branch 0 taken 23847888 times.
✗ Branch 1 not taken.
23847888 if(add){
146 23847888 v += dst[x + src_x];
147 23847888 v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS;
148
2/2
✓ Branch 0 taken 2425 times.
✓ Branch 1 taken 23845463 times.
23847888 if(v&(~255)) v= ~(v>>31);
149 23847888 dst8[x + y*src_stride] = v;
150 }else{
151 dst[x + src_x] -= v;
152 }
153 }
154 }
155 710805 }
156
157 103 void ff_snow_reset_contexts(SnowContext *s){ //FIXME better initial contexts
158 int plane_index, level, orientation;
159
160
2/2
✓ Branch 0 taken 309 times.
✓ Branch 1 taken 103 times.
412 for(plane_index=0; plane_index<3; plane_index++){
161
2/2
✓ Branch 0 taken 2472 times.
✓ Branch 1 taken 309 times.
2781 for(level=0; level<MAX_DECOMPOSITIONS; level++){
162
2/2
✓ Branch 0 taken 7725 times.
✓ Branch 1 taken 2472 times.
10197 for(orientation=level ? 1:0; orientation<4; orientation++){
163 7725 memset(s->plane[plane_index].band[level][orientation].state, MID_STATE, sizeof(s->plane[plane_index].band[level][orientation].state));
164 }
165 }
166 }
167 103 memset(s->header_state, MID_STATE, sizeof(s->header_state));
168 103 memset(s->block_state, MID_STATE, sizeof(s->block_state));
169 103 }
170
171 472 int ff_snow_alloc_blocks(SnowContext *s){
172 472 int w= AV_CEIL_RSHIFT(s->avctx->width, LOG2_MB_SIZE);
173 472 int h= AV_CEIL_RSHIFT(s->avctx->height, LOG2_MB_SIZE);
174
175 472 s->b_width = w;
176 472 s->b_height= h;
177
178 472 av_free(s->block);
179 472 s->block = av_calloc(w * h, sizeof(*s->block) << (s->block_max_depth*2));
180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 472 times.
472 if (!s->block)
181 return AVERROR(ENOMEM);
182
183 472 return 0;
184 }
185
186 3240046 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){
187 static const uint8_t weight[64]={
188 8,7,6,5,4,3,2,1,
189 7,7,0,0,0,0,0,1,
190 6,0,6,0,0,0,2,0,
191 5,0,0,5,0,3,0,0,
192 4,0,0,0,4,0,0,0,
193 3,0,0,5,0,3,0,0,
194 2,0,6,0,0,0,2,0,
195 1,7,0,0,0,0,0,1,
196 };
197
198 static const uint8_t brane[256]={
199 0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x11,0x12,0x12,0x12,0x12,0x12,0x12,0x12,
200 0x04,0x05,0xcc,0xcc,0xcc,0xcc,0xcc,0x41,0x15,0x16,0xcc,0xcc,0xcc,0xcc,0xcc,0x52,
201 0x04,0xcc,0x05,0xcc,0xcc,0xcc,0x41,0xcc,0x15,0xcc,0x16,0xcc,0xcc,0xcc,0x52,0xcc,
202 0x04,0xcc,0xcc,0x05,0xcc,0x41,0xcc,0xcc,0x15,0xcc,0xcc,0x16,0xcc,0x52,0xcc,0xcc,
203 0x04,0xcc,0xcc,0xcc,0x41,0xcc,0xcc,0xcc,0x15,0xcc,0xcc,0xcc,0x16,0xcc,0xcc,0xcc,
204 0x04,0xcc,0xcc,0x41,0xcc,0x05,0xcc,0xcc,0x15,0xcc,0xcc,0x52,0xcc,0x16,0xcc,0xcc,
205 0x04,0xcc,0x41,0xcc,0xcc,0xcc,0x05,0xcc,0x15,0xcc,0x52,0xcc,0xcc,0xcc,0x16,0xcc,
206 0x04,0x41,0xcc,0xcc,0xcc,0xcc,0xcc,0x05,0x15,0x52,0xcc,0xcc,0xcc,0xcc,0xcc,0x16,
207 0x44,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x55,0x56,0x56,0x56,0x56,0x56,0x56,0x56,
208 0x48,0x49,0xcc,0xcc,0xcc,0xcc,0xcc,0x85,0x59,0x5A,0xcc,0xcc,0xcc,0xcc,0xcc,0x96,
209 0x48,0xcc,0x49,0xcc,0xcc,0xcc,0x85,0xcc,0x59,0xcc,0x5A,0xcc,0xcc,0xcc,0x96,0xcc,
210 0x48,0xcc,0xcc,0x49,0xcc,0x85,0xcc,0xcc,0x59,0xcc,0xcc,0x5A,0xcc,0x96,0xcc,0xcc,
211 0x48,0xcc,0xcc,0xcc,0x49,0xcc,0xcc,0xcc,0x59,0xcc,0xcc,0xcc,0x96,0xcc,0xcc,0xcc,
212 0x48,0xcc,0xcc,0x85,0xcc,0x49,0xcc,0xcc,0x59,0xcc,0xcc,0x96,0xcc,0x5A,0xcc,0xcc,
213 0x48,0xcc,0x85,0xcc,0xcc,0xcc,0x49,0xcc,0x59,0xcc,0x96,0xcc,0xcc,0xcc,0x5A,0xcc,
214 0x48,0x85,0xcc,0xcc,0xcc,0xcc,0xcc,0x49,0x59,0x96,0xcc,0xcc,0xcc,0xcc,0xcc,0x5A,
215 };
216
217 static const uint8_t needs[16]={
218 0,1,0,0,
219 2,4,2,0,
220 0,1,0,0,
221 15
222 };
223
224 int x, y, b, r, l;
225 int16_t tmpIt [64*(32+HTAPS_MAX)];
226 uint8_t tmp2t[3][64*(32+HTAPS_MAX)];
227 3240046 int16_t *tmpI= tmpIt;
228 3240046 uint8_t *tmp2= tmp2t[0];
229 const uint8_t *hpel[11];
230 av_assert2(dx<16 && dy<16);
231 3240046 r= brane[dx + 16*dy]&15;
232 3240046 l= brane[dx + 16*dy]>>4;
233
234 3240046 b= needs[l] | needs[r];
235
3/4
✓ Branch 0 taken 3219792 times.
✓ Branch 1 taken 20254 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3219792 times.
3240046 if(p && !p->diag_mc)
236 b= 15;
237
238
2/2
✓ Branch 0 taken 2902303 times.
✓ Branch 1 taken 337743 times.
3240046 if(b&5){
239
2/2
✓ Branch 0 taken 32986489 times.
✓ Branch 1 taken 2902303 times.
35888792 for(y=0; y < b_h+HTAPS_MAX-1; y++){
240
2/2
✓ Branch 0 taken 151160584 times.
✓ Branch 1 taken 32986489 times.
184147073 for(x=0; x < b_w; x++){
241 151160584 int a_1=src[x + HTAPS_MAX/2-4];
242 151160584 int a0= src[x + HTAPS_MAX/2-3];
243 151160584 int a1= src[x + HTAPS_MAX/2-2];
244 151160584 int a2= src[x + HTAPS_MAX/2-1];
245 151160584 int a3= src[x + HTAPS_MAX/2+0];
246 151160584 int a4= src[x + HTAPS_MAX/2+1];
247 151160584 int a5= src[x + HTAPS_MAX/2+2];
248 151160584 int a6= src[x + HTAPS_MAX/2+3];
249 151160584 int am=0;
250
3/4
✓ Branch 0 taken 145535704 times.
✓ Branch 1 taken 5624880 times.
✓ Branch 2 taken 145535704 times.
✗ Branch 3 not taken.
151160584 if(!p || p->fast_mc){
251 151160584 am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5);
252 151160584 tmpI[x]= am;
253 151160584 am= (am+16)>>5;
254 }else{
255 am= p->hcoeff[0]*(a2+a3) + p->hcoeff[1]*(a1+a4) + p->hcoeff[2]*(a0+a5) + p->hcoeff[3]*(a_1+a6);
256 tmpI[x]= am;
257 am= (am+32)>>6;
258 }
259
260
2/2
✓ Branch 0 taken 6243 times.
✓ Branch 1 taken 151154341 times.
151160584 if(am&(~255)) am= ~(am>>31);
261 151160584 tmp2[x]= am;
262 }
263 32986489 tmpI+= 64;
264 32986489 tmp2+= 64;
265 32986489 src += stride;
266 }
267 2902303 src -= stride*y;
268 }
269 3240046 src += HTAPS_MAX/2 - 1;
270 3240046 tmp2= tmp2t[1];
271
272
2/2
✓ Branch 0 taken 1995647 times.
✓ Branch 1 taken 1244399 times.
3240046 if(b&2){
273
2/2
✓ Branch 0 taken 8675168 times.
✓ Branch 1 taken 1995647 times.
10670815 for(y=0; y < b_h; y++){
274
2/2
✓ Branch 0 taken 49883520 times.
✓ Branch 1 taken 8675168 times.
58558688 for(x=0; x < b_w+1; x++){
275 49883520 int a_1=src[x + (HTAPS_MAX/2-4)*stride];
276 49883520 int a0= src[x + (HTAPS_MAX/2-3)*stride];
277 49883520 int a1= src[x + (HTAPS_MAX/2-2)*stride];
278 49883520 int a2= src[x + (HTAPS_MAX/2-1)*stride];
279 49883520 int a3= src[x + (HTAPS_MAX/2+0)*stride];
280 49883520 int a4= src[x + (HTAPS_MAX/2+1)*stride];
281 49883520 int a5= src[x + (HTAPS_MAX/2+2)*stride];
282 49883520 int a6= src[x + (HTAPS_MAX/2+3)*stride];
283 49883520 int am=0;
284
3/4
✓ Branch 0 taken 48531952 times.
✓ Branch 1 taken 1351568 times.
✓ Branch 2 taken 48531952 times.
✗ Branch 3 not taken.
49883520 if(!p || p->fast_mc)
285 49883520 am= (20*(a2+a3) - 5*(a1+a4) + (a0+a5) + 16)>>5;
286 else
287 am= (p->hcoeff[0]*(a2+a3) + p->hcoeff[1]*(a1+a4) + p->hcoeff[2]*(a0+a5) + p->hcoeff[3]*(a_1+a6) + 32)>>6;
288
289
2/2
✓ Branch 0 taken 3684 times.
✓ Branch 1 taken 49879836 times.
49883520 if(am&(~255)) am= ~(am>>31);
290 49883520 tmp2[x]= am;
291 }
292 8675168 src += stride;
293 8675168 tmp2+= 64;
294 }
295 1995647 src -= stride*y;
296 }
297 3240046 src += stride*(HTAPS_MAX/2 - 1);
298 3240046 tmp2= tmp2t[2];
299 3240046 tmpI= tmpIt;
300
2/2
✓ Branch 0 taken 1956310 times.
✓ Branch 1 taken 1283736 times.
3240046 if(b&4){
301
2/2
✓ Branch 0 taken 8485272 times.
✓ Branch 1 taken 1956310 times.
10441582 for(y=0; y < b_h; y++){
302
2/2
✓ Branch 0 taken 40817200 times.
✓ Branch 1 taken 8485272 times.
49302472 for(x=0; x < b_w; x++){
303 40817200 int a_1=tmpI[x + (HTAPS_MAX/2-4)*64];
304 40817200 int a0= tmpI[x + (HTAPS_MAX/2-3)*64];
305 40817200 int a1= tmpI[x + (HTAPS_MAX/2-2)*64];
306 40817200 int a2= tmpI[x + (HTAPS_MAX/2-1)*64];
307 40817200 int a3= tmpI[x + (HTAPS_MAX/2+0)*64];
308 40817200 int a4= tmpI[x + (HTAPS_MAX/2+1)*64];
309 40817200 int a5= tmpI[x + (HTAPS_MAX/2+2)*64];
310 40817200 int a6= tmpI[x + (HTAPS_MAX/2+3)*64];
311 40817200 int am=0;
312
3/4
✓ Branch 0 taken 38320176 times.
✓ Branch 1 taken 2497024 times.
✓ Branch 2 taken 38320176 times.
✗ Branch 3 not taken.
40817200 if(!p || p->fast_mc)
313 40817200 am= (20*(a2+a3) - 5*(a1+a4) + (a0+a5) + 512)>>10;
314 else
315 am= (p->hcoeff[0]*(a2+a3) + p->hcoeff[1]*(a1+a4) + p->hcoeff[2]*(a0+a5) + p->hcoeff[3]*(a_1+a6) + 2048)>>12;
316
2/2
✓ Branch 0 taken 6658 times.
✓ Branch 1 taken 40810542 times.
40817200 if(am&(~255)) am= ~(am>>31);
317 40817200 tmp2[x]= am;
318 }
319 8485272 tmpI+= 64;
320 8485272 tmp2+= 64;
321 }
322 }
323
324 3240046 hpel[ 0]= src;
325 3240046 hpel[ 1]= tmp2t[0] + 64*(HTAPS_MAX/2-1);
326 3240046 hpel[ 2]= src + 1;
327
328 3240046 hpel[ 4]= tmp2t[1];
329 3240046 hpel[ 5]= tmp2t[2];
330 3240046 hpel[ 6]= tmp2t[1] + 1;
331
332 3240046 hpel[ 8]= src + stride;
333 3240046 hpel[ 9]= hpel[1] + 64;
334 3240046 hpel[10]= hpel[8] + 1;
335
336 #define MC_STRIDE(x) (needs[x] ? 64 : stride)
337
338
2/2
✓ Branch 0 taken 789096 times.
✓ Branch 1 taken 2450950 times.
3240046 if(b==15){
339 789096 int dxy = dx / 8 + dy / 8 * 4;
340 789096 const uint8_t *src1 = hpel[dxy ];
341 789096 const uint8_t *src2 = hpel[dxy + 1];
342 789096 const uint8_t *src3 = hpel[dxy + 4];
343 789096 const uint8_t *src4 = hpel[dxy + 5];
344
2/2
✓ Branch 0 taken 197858 times.
✓ Branch 1 taken 591238 times.
789096 int stride1 = MC_STRIDE(dxy);
345
2/2
✓ Branch 0 taken 202020 times.
✓ Branch 1 taken 587076 times.
789096 int stride2 = MC_STRIDE(dxy + 1);
346
2/2
✓ Branch 0 taken 191088 times.
✓ Branch 1 taken 598008 times.
789096 int stride3 = MC_STRIDE(dxy + 4);
347
2/2
✓ Branch 0 taken 198130 times.
✓ Branch 1 taken 590966 times.
789096 int stride4 = MC_STRIDE(dxy + 5);
348 789096 dx&=7;
349 789096 dy&=7;
350
2/2
✓ Branch 0 taken 3464504 times.
✓ Branch 1 taken 789096 times.
4253600 for(y=0; y < b_h; y++){
351
2/2
✓ Branch 0 taken 16562072 times.
✓ Branch 1 taken 3464504 times.
20026576 for(x=0; x < b_w; x++){
352 16562072 dst[x]= ((8-dx)*(8-dy)*src1[x] + dx*(8-dy)*src2[x]+
353 16562072 (8-dx)* dy *src3[x] + dx* dy *src4[x]+32)>>6;
354 }
355 3464504 src1+=stride1;
356 3464504 src2+=stride2;
357 3464504 src3+=stride3;
358 3464504 src4+=stride4;
359 3464504 dst +=stride;
360 }
361 }else{
362 2450950 const uint8_t *src1= hpel[l];
363 2450950 const uint8_t *src2= hpel[r];
364
2/2
✓ Branch 0 taken 600698 times.
✓ Branch 1 taken 1850252 times.
2450950 int stride1 = MC_STRIDE(l);
365
2/2
✓ Branch 0 taken 655540 times.
✓ Branch 1 taken 1795410 times.
2450950 int stride2 = MC_STRIDE(r);
366 2450950 int a= weight[((dx&7) + (8*(dy&7)))];
367 2450950 int b= 8-a;
368
2/2
✓ Branch 0 taken 10726636 times.
✓ Branch 1 taken 2450950 times.
13177586 for(y=0; y < b_h; y++){
369
2/2
✓ Branch 0 taken 52938552 times.
✓ Branch 1 taken 10726636 times.
63665188 for(x=0; x < b_w; x++){
370 52938552 dst[x]= (a*src1[x] + b*src2[x] + 4)>>3;
371 }
372 10726636 src1+=stride1;
373 10726636 src2+=stride2;
374 10726636 dst +=stride;
375 }
376 }
377 3240046 }
378
379 9378716 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){
380
2/2
✓ Branch 0 taken 1260713 times.
✓ Branch 1 taken 8118003 times.
9378716 if(block->type & BLOCK_INTRA){
381 int x, y;
382 1260713 const unsigned color = block->color[plane_index];
383 1260713 const unsigned color4 = color*0x01010101;
384
2/2
✓ Branch 0 taken 18314 times.
✓ Branch 1 taken 1242399 times.
1260713 if(b_w==32){
385
2/2
✓ Branch 0 taken 586048 times.
✓ Branch 1 taken 18314 times.
604362 for(y=0; y < b_h; y++){
386 586048 *(uint32_t*)&dst[0 + y*stride]= color4;
387 586048 *(uint32_t*)&dst[4 + y*stride]= color4;
388 586048 *(uint32_t*)&dst[8 + y*stride]= color4;
389 586048 *(uint32_t*)&dst[12+ y*stride]= color4;
390 586048 *(uint32_t*)&dst[16+ y*stride]= color4;
391 586048 *(uint32_t*)&dst[20+ y*stride]= color4;
392 586048 *(uint32_t*)&dst[24+ y*stride]= color4;
393 586048 *(uint32_t*)&dst[28+ y*stride]= color4;
394 }
395
2/2
✓ Branch 0 taken 131664 times.
✓ Branch 1 taken 1110735 times.
1242399 }else if(b_w==16){
396
2/2
✓ Branch 0 taken 1976224 times.
✓ Branch 1 taken 131664 times.
2107888 for(y=0; y < b_h; y++){
397 1976224 *(uint32_t*)&dst[0 + y*stride]= color4;
398 1976224 *(uint32_t*)&dst[4 + y*stride]= color4;
399 1976224 *(uint32_t*)&dst[8 + y*stride]= color4;
400 1976224 *(uint32_t*)&dst[12+ y*stride]= color4;
401 }
402
2/2
✓ Branch 0 taken 545322 times.
✓ Branch 1 taken 565413 times.
1110735 }else if(b_w==8){
403
2/2
✓ Branch 0 taken 4272760 times.
✓ Branch 1 taken 545322 times.
4818082 for(y=0; y < b_h; y++){
404 4272760 *(uint32_t*)&dst[0 + y*stride]= color4;
405 4272760 *(uint32_t*)&dst[4 + y*stride]= color4;
406 }
407
2/2
✓ Branch 0 taken 564463 times.
✓ Branch 1 taken 950 times.
565413 }else if(b_w==4){
408
2/2
✓ Branch 0 taken 2300276 times.
✓ Branch 1 taken 564463 times.
2864739 for(y=0; y < b_h; y++){
409 2300276 *(uint32_t*)&dst[0 + y*stride]= color4;
410 }
411 }else{
412
2/2
✓ Branch 0 taken 3740 times.
✓ Branch 1 taken 950 times.
4690 for(y=0; y < b_h; y++){
413
2/2
✓ Branch 0 taken 7480 times.
✓ Branch 1 taken 3740 times.
11220 for(x=0; x < b_w; x++){
414 7480 dst[x + y*stride]= color;
415 }
416 }
417 }
418 }else{
419 8118003 const uint8_t *src = s->last_picture[block->ref]->data[plane_index];
420
2/2
✓ Branch 0 taken 5219918 times.
✓ Branch 1 taken 2898085 times.
8118003 const int scale= plane_index ? (2*s->mv_scale)>>s->chroma_h_shift : 2*s->mv_scale;
421 8118003 int mx= block->mx*scale;
422 8118003 int my= block->my*scale;
423 8118003 const int dx= mx&15;
424 8118003 const int dy= my&15;
425 8118003 const int tab_index= 3 - (b_w>>2) + (b_w>>4);
426 8118003 sx += (mx>>4) - (HTAPS_MAX/2-1);
427 8118003 sy += (my>>4) - (HTAPS_MAX/2-1);
428 8118003 src += sx + sy*stride;
429
3/4
✓ Branch 0 taken 8118003 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7607887 times.
✓ Branch 3 taken 510116 times.
8118003 if( (unsigned)sx >= FFMAX(w - b_w - (HTAPS_MAX-2), 0)
430
3/4
✓ Branch 0 taken 7607887 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 642582 times.
✓ Branch 3 taken 6965305 times.
7607887 || (unsigned)sy >= FFMAX(h - b_h - (HTAPS_MAX-2), 0)){
431 1152698 s->vdsp.emulated_edge_mc(tmp + MB_SIZE, src,
432 stride, stride,
433 b_w+HTAPS_MAX-1, b_h+HTAPS_MAX-1,
434 sx, sy, w, h);
435 1152698 src= tmp + MB_SIZE;
436 }
437
438 av_assert2(s->chroma_h_shift == s->chroma_v_shift); // only one mv_scale
439
440 av_assert2((tab_index>=0 && tab_index<4) || b_w==32);
441
4/4
✓ Branch 0 taken 5952425 times.
✓ Branch 1 taken 2165578 times.
✓ Branch 2 taken 4898211 times.
✓ Branch 3 taken 1054214 times.
8118003 if( (dx&3) || (dy&3)
442
5/6
✓ Branch 0 taken 349199 times.
✓ Branch 1 taken 4549012 times.
✓ Branch 2 taken 204372 times.
✓ Branch 3 taken 144827 times.
✓ Branch 4 taken 204372 times.
✗ Branch 5 not taken.
4898211 || !(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h)
443
1/2
✓ Branch 0 taken 4898211 times.
✗ Branch 1 not taken.
4898211 || (b_w&(b_w-1))
444
1/2
✓ Branch 0 taken 4898211 times.
✗ Branch 1 not taken.
4898211 || b_w == 1
445
1/2
✓ Branch 0 taken 4898211 times.
✗ Branch 1 not taken.
4898211 || b_h == 1
446
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4898211 times.
4898211 || !s->plane[plane_index].fast_mc )
447 3219792 mc_block(&s->plane[plane_index], dst, src, stride, b_w, b_h, dx, dy);
448
2/2
✓ Branch 0 taken 288126 times.
✓ Branch 1 taken 4610085 times.
4898211 else if(b_w==32){
449 int y;
450
2/2
✓ Branch 0 taken 576252 times.
✓ Branch 1 taken 288126 times.
864378 for(y=0; y<b_h; y+=16){
451 576252 s->put_snow_qpel_pixels_tab[0][dy+(dx>>2)](dst + y*stride, src + 3 + (y+3)*stride,stride);
452 576252 s->put_snow_qpel_pixels_tab[0][dy+(dx>>2)](dst + 16 + y*stride, src + 19 + (y+3)*stride,stride);
453 }
454
2/2
✓ Branch 0 taken 4260886 times.
✓ Branch 1 taken 349199 times.
4610085 }else if(b_w==b_h)
455 4260886 s->put_snow_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst,src + 3 + 3*stride,stride);
456
2/2
✓ Branch 0 taken 204372 times.
✓ Branch 1 taken 144827 times.
349199 else if(b_w==2*b_h){
457 204372 s->put_snow_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst ,src + 3 + 3*stride,stride);
458 204372 s->put_snow_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst+b_h,src + 3 + b_h + 3*stride,stride);
459 }else{
460 av_assert2(2*b_w==b_h);
461 144827 s->put_snow_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst ,src + 3 + 3*stride ,stride);
462 144827 s->put_snow_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst+b_w*stride,src + 3 + 3*stride+b_w*stride,stride);
463 }
464 }
465 9378716 }
466
467 #define mca(dx,dy,b_w)\
468 static void mc_block_hpel ## dx ## dy ## b_w(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h){\
469 av_assert2(h==b_w);\
470 mc_block(NULL, dst, src-(HTAPS_MAX/2-1)-(HTAPS_MAX/2-1)*stride, stride, b_w, b_w, dx, dy);\
471 }
472
473 mca( 0, 0,16)
474 5531 mca( 8, 0,16)
475 4969 mca( 0, 8,16)
476 9754 mca( 8, 8,16)
477 mca( 0, 0,8)
478 mca( 8, 0,8)
479 mca( 0, 8,8)
480 mca( 8, 8,8)
481
482 22 static av_cold void snow_static_init(void)
483 {
484
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 22 times.
198 for (int i = 0; i < MAX_REF_FRAMES; i++)
485
2/2
✓ Branch 0 taken 1408 times.
✓ Branch 1 taken 176 times.
1584 for (int j = 0; j < MAX_REF_FRAMES; j++)
486 1408 ff_scale_mv_ref[i][j] = 256 * (i + 1) / (j + 1);
487 22 }
488
489 31 av_cold int ff_snow_common_init(AVCodecContext *avctx){
490 static AVOnce init_static_once = AV_ONCE_INIT;
491 31 SnowContext *s = avctx->priv_data;
492 int width, height;
493 int i;
494
495 31 s->avctx= avctx;
496 31 s->max_ref_frames=1; //just make sure it's not an invalid value in case of no initial keyframe
497 31 s->spatial_decomposition_count = 1;
498
499 31 ff_videodsp_init(&s->vdsp, 8);
500 31 ff_dwt_init(&s->dwt);
501
502 31 init_qpel(s);
503
504 #define mcfh(dx,dy)\
505 s->hdsp.put_pixels_tab [0][dy/4+dx/8]=\
506 s->hdsp.put_no_rnd_pixels_tab[0][dy/4+dx/8]=\
507 mc_block_hpel ## dx ## dy ## 16;\
508 s->hdsp.put_pixels_tab [1][dy/4+dx/8]=\
509 s->hdsp.put_no_rnd_pixels_tab[1][dy/4+dx/8]=\
510 mc_block_hpel ## dx ## dy ## 8;
511
512 31 mcfh(0, 0)
513 31 mcfh(8, 0)
514 31 mcfh(0, 8)
515 31 mcfh(8, 8)
516
517 // dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift);
518
519 31 width= s->avctx->width;
520 31 height= s->avctx->height;
521
522
1/2
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
31 if (!FF_ALLOCZ_TYPED_ARRAY(s->spatial_idwt_buffer, width * height) ||
523
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
524
1/2
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
31 !FF_ALLOCZ_TYPED_ARRAY(s->temp_dwt_buffer, width) ||
525
1/2
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
31 !FF_ALLOCZ_TYPED_ARRAY(s->temp_idwt_buffer, width) ||
526
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))
527 return AVERROR(ENOMEM);
528
529
2/2
✓ Branch 0 taken 248 times.
✓ Branch 1 taken 31 times.
279 for(i=0; i<MAX_REF_FRAMES; i++) {
530 248 s->last_picture[i] = av_frame_alloc();
531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 248 times.
248 if (!s->last_picture[i])
532 return AVERROR(ENOMEM);
533 }
534
535 31 s->mconly_picture = av_frame_alloc();
536 31 s->current_picture = av_frame_alloc();
537
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)
538 return AVERROR(ENOMEM);
539
540 31 ff_thread_once(&init_static_once, snow_static_init);
541
542 31 return 0;
543 }
544
545 973 int ff_snow_common_init_after_header(AVCodecContext *avctx) {
546 973 SnowContext *s = avctx->priv_data;
547 int plane_index, level, orientation;
548
549
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 942 times.
973 if(!s->scratchbuf) {
550
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
31 if (!FF_ALLOCZ_TYPED_ARRAY(s->scratchbuf, FFMAX(s->current_picture->linesize[0], 2*avctx->width+256) * 7 * MB_SIZE))
551 return AVERROR(ENOMEM);
552 }
553
554
2/2
✓ Branch 0 taken 2919 times.
✓ Branch 1 taken 973 times.
3892 for(plane_index=0; plane_index < s->nb_planes; plane_index++){
555 2919 int w= s->avctx->width;
556 2919 int h= s->avctx->height;
557
558
2/2
✓ Branch 0 taken 1946 times.
✓ Branch 1 taken 973 times.
2919 if(plane_index){
559 1946 w = AV_CEIL_RSHIFT(w, s->chroma_h_shift);
560 1946 h = AV_CEIL_RSHIFT(h, s->chroma_v_shift);
561 }
562 2919 s->plane[plane_index].width = w;
563 2919 s->plane[plane_index].height= h;
564
565
2/2
✓ Branch 0 taken 14595 times.
✓ Branch 1 taken 2919 times.
17514 for(level=s->spatial_decomposition_count-1; level>=0; level--){
566
2/2
✓ Branch 0 taken 46704 times.
✓ Branch 1 taken 14595 times.
61299 for(orientation=level ? 1 : 0; orientation<4; orientation++){
567 46704 SubBand *b= &s->plane[plane_index].band[level][orientation];
568
569 46704 b->buf= s->spatial_dwt_buffer;
570 46704 b->level= level;
571 46704 b->stride= s->plane[plane_index].width << (s->spatial_decomposition_count - level);
572 46704 b->width = (w + !(orientation&1))>>1;
573 46704 b->height= (h + !(orientation>1))>>1;
574
575 46704 b->stride_line = 1 << (s->spatial_decomposition_count - level);
576 46704 b->buf_x_offset = 0;
577 46704 b->buf_y_offset = 0;
578
579
2/2
✓ Branch 0 taken 29190 times.
✓ Branch 1 taken 17514 times.
46704 if(orientation&1){
580 29190 b->buf += (w+1)>>1;
581 29190 b->buf_x_offset = (w+1)>>1;
582 }
583
2/2
✓ Branch 0 taken 29190 times.
✓ Branch 1 taken 17514 times.
46704 if(orientation>1){
584 29190 b->buf += b->stride>>1;
585 29190 b->buf_y_offset = b->stride_line >> 1;
586 }
587 46704 b->ibuf= s->spatial_idwt_buffer + (b->buf - s->spatial_dwt_buffer);
588
589
2/2
✓ Branch 0 taken 35028 times.
✓ Branch 1 taken 11676 times.
46704 if(level)
590 35028 b->parent= &s->plane[plane_index].band[level-1][orientation];
591 //FIXME avoid this realloc
592 46704 av_freep(&b->x_coeff);
593 46704 b->x_coeff = av_calloc((b->width + 1) * b->height + 1,
594 sizeof(*b->x_coeff));
595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46704 times.
46704 if (!b->x_coeff)
596 return AVERROR(ENOMEM);
597 }
598 14595 w= (w+1)>>1;
599 14595 h= (h+1)>>1;
600 }
601 }
602
603 973 return 0;
604 }
605
606 973 int ff_snow_frames_prepare(SnowContext *s)
607 {
608 AVFrame *tmp;
609
610 973 tmp= s->last_picture[s->max_ref_frames-1];
611
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 973 times.
973 for (int i = s->max_ref_frames - 1; i > 0; i--)
612 s->last_picture[i] = s->last_picture[i-1];
613 973 s->last_picture[0] = s->current_picture;
614 973 s->current_picture = tmp;
615
616 973 av_frame_unref(s->current_picture);
617
618
2/2
✓ Branch 0 taken 103 times.
✓ Branch 1 taken 870 times.
973 if(s->keyframe){
619 103 s->ref_frames= 0;
620 103 s->current_picture->flags |= AV_FRAME_FLAG_KEY;
621 }else{
622 int i;
623
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++)
624
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))
625 break;
626 870 s->ref_frames= i;
627
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 870 times.
870 if(s->ref_frames==0){
628 av_log(s->avctx,AV_LOG_ERROR, "No reference frames\n");
629 return AVERROR_INVALIDDATA;
630 }
631 870 s->current_picture->flags &= ~AV_FRAME_FLAG_KEY;
632 }
633
634 973 return 0;
635 }
636
637 31 av_cold void ff_snow_common_end(SnowContext *s)
638 {
639 int plane_index, level, orientation, i;
640
641 31 av_freep(&s->spatial_dwt_buffer);
642 31 av_freep(&s->temp_dwt_buffer);
643 31 av_freep(&s->spatial_idwt_buffer);
644 31 av_freep(&s->temp_idwt_buffer);
645 31 av_freep(&s->run_buffer);
646
647 31 av_freep(&s->block);
648 31 av_freep(&s->scratchbuf);
649
650
2/2
✓ Branch 0 taken 248 times.
✓ Branch 1 taken 31 times.
279 for(i=0; i<MAX_REF_FRAMES; i++){
651 248 av_frame_free(&s->last_picture[i]);
652 }
653
654
2/2
✓ Branch 0 taken 124 times.
✓ Branch 1 taken 31 times.
155 for(plane_index=0; plane_index < MAX_PLANES; plane_index++){
655
2/2
✓ Branch 0 taken 992 times.
✓ Branch 1 taken 124 times.
1116 for(level=MAX_DECOMPOSITIONS-1; level>=0; level--){
656
2/2
✓ Branch 0 taken 3100 times.
✓ Branch 1 taken 992 times.
4092 for(orientation=level ? 1 : 0; orientation<4; orientation++){
657 3100 SubBand *b= &s->plane[plane_index].band[level][orientation];
658
659 3100 av_freep(&b->x_coeff);
660 }
661 }
662 }
663 31 av_frame_free(&s->mconly_picture);
664 31 av_frame_free(&s->current_picture);
665 31 }
666