FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/snow.c
Date: 2026-10-13 21:07:32
Exec Total Coverage
Lines: 385 405 95.1%
Functions: 33 36 91.7%
Branches: 183 210 87.1%

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 58660 static void put_snow_qpel2_h_lowpass_8(uint8_t *dst, const uint8_t *restrict src, int dstStride, int srcStride)
38 {
39 58660 const int h = 2;
40
2/2
✓ Branch 0 taken 117320 times.
✓ Branch 1 taken 58660 times.
175980 for (int i = 0; i < h; ++i) {
41 117320 dst[0] = av_clip_uint8(((src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]) + 16) >> 5);
42 117320 dst[1] = av_clip_uint8(((src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]) + 16) >> 5);
43 117320 dst += dstStride;
44 117320 src += srcStride;
45 }
46 58660 }
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 391516 H264_QPEL(put_, snow, 2)
94
95 37 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 37 ff_h264qpel_init(&s->h264qpel, 8);
100 37 s->put_snow_qpel_pixels_tab[3][0] = put_snow_qpel2_mc00_8_c;
101 37 s->put_snow_qpel_pixels_tab[3][1] = put_snow_qpel2_mc10_8_c;
102 37 s->put_snow_qpel_pixels_tab[3][2] = put_snow_qpel2_mc20_8_c;
103 37 s->put_snow_qpel_pixels_tab[3][3] = put_snow_qpel2_mc30_8_c;
104 37 s->put_snow_qpel_pixels_tab[3][4] = put_snow_qpel2_mc01_8_c;
105 37 s->put_snow_qpel_pixels_tab[3][5] = put_snow_qpel2_mc11_8_c;
106 37 s->put_snow_qpel_pixels_tab[3][6] = put_snow_qpel2_mc21_8_c;
107 37 s->put_snow_qpel_pixels_tab[3][7] = put_snow_qpel2_mc31_8_c;
108 37 s->put_snow_qpel_pixels_tab[3][8] = put_snow_qpel2_mc02_8_c;
109 37 s->put_snow_qpel_pixels_tab[3][9] = put_snow_qpel2_mc12_8_c;
110 37 s->put_snow_qpel_pixels_tab[3][10] = put_snow_qpel2_mc22_8_c;
111 37 s->put_snow_qpel_pixels_tab[3][11] = put_snow_qpel2_mc32_8_c;
112 37 s->put_snow_qpel_pixels_tab[3][12] = put_snow_qpel2_mc03_8_c;
113 37 s->put_snow_qpel_pixels_tab[3][13] = put_snow_qpel2_mc13_8_c;
114 37 s->put_snow_qpel_pixels_tab[3][14] = put_snow_qpel2_mc23_8_c;
115 37 s->put_snow_qpel_pixels_tab[3][15] = put_snow_qpel2_mc33_8_c;
116 37 }
117
118 712619 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 712619 times.
712619 av_assume(add); // add == 0 is currently unused
124
125
2/2
✓ Branch 0 taken 3827832 times.
✓ Branch 1 taken 712619 times.
4540451 for(y=0; y<b_h; y++){
126 //FIXME ugly misuse of obmc_stride
127 3827832 const uint8_t *obmc1= obmc + y*obmc_stride;
128 3827832 const uint8_t *obmc2= obmc1+ (obmc_stride>>1);
129 3827832 const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1);
130 3827832 const uint8_t *obmc4= obmc3+ (obmc_stride>>1);
131 3827832 IDWTELEM *dst = lines[y];
132 av_assert2(dst);
133
134
2/2
✓ Branch 0 taken 23952500 times.
✓ Branch 1 taken 3827832 times.
27780332 for(x=0; x<b_w; x++){
135 23952500 int v= obmc1[x] * block[3][x + y*src_stride]
136 23952500 +obmc2[x] * block[2][x + y*src_stride]
137 23952500 +obmc3[x] * block[1][x + y*src_stride]
138 23952500 +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 23952500 v >>= LOG2_OBMC_MAX - FRAC_BITS;
144 #endif
145
1/2
✓ Branch 0 taken 23952500 times.
✗ Branch 1 not taken.
23952500 if(add){
146 23952500 v += dst[x + src_x];
147 23952500 v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS;
148
2/2
✓ Branch 0 taken 3279 times.
✓ Branch 1 taken 23949221 times.
23952500 if(v&(~255)) v= ~(v>>31);
149 23952500 dst8[x + y*src_stride] = v;
150 }else{
151 ✗ dst[x + src_x] -= v;
152 }
153 }
154 }
155 712619 }
156
157 117 void ff_snow_reset_contexts(SnowContext *s){ //FIXME better initial contexts
158 int plane_index, level, orientation;
159
160
2/2
✓ Branch 0 taken 351 times.
✓ Branch 1 taken 117 times.
468 for(plane_index=0; plane_index<3; plane_index++){
161
2/2
✓ Branch 0 taken 2808 times.
✓ Branch 1 taken 351 times.
3159 for(level=0; level<MAX_DECOMPOSITIONS; level++){
162
2/2
✓ Branch 0 taken 8775 times.
✓ Branch 1 taken 2808 times.
11583 for(orientation=level ? 1:0; orientation<4; orientation++){
163 8775 memset(s->plane[plane_index].band[level][orientation].state, MID_STATE, sizeof(s->plane[plane_index].band[level][orientation].state));
164 }
165 }
166 }
167 117 memset(s->header_state, MID_STATE, sizeof(s->header_state));
168 117 memset(s->block_state, MID_STATE, sizeof(s->block_state));
169 117 }
170
171 510 int ff_snow_alloc_blocks(SnowContext *s){
172 510 int w= AV_CEIL_RSHIFT(s->avctx->width, LOG2_MB_SIZE);
173 510 int h= AV_CEIL_RSHIFT(s->avctx->height, LOG2_MB_SIZE);
174
175 510 s->b_width = w;
176 510 s->b_height= h;
177
178 510 av_free(s->block);
179 510 s->block = av_calloc(w * h, sizeof(*s->block) << (s->block_max_depth*2));
180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 510 times.
510 if (!s->block)
181 ✗ return AVERROR(ENOMEM);
182
183 510 return 0;
184 }
185
186 3242893 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 3242893 int16_t *tmpI= tmpIt;
228 3242893 uint8_t *tmp2= tmp2t[0];
229 const uint8_t *hpel[11];
230 av_assert2(dx<16 && dy<16);
231 3242893 r= brane[dx + 16*dy]&15;
232 3242893 l= brane[dx + 16*dy]>>4;
233
234 3242893 b= needs[l] | needs[r];
235
3/4
✓ Branch 0 taken 3220865 times.
✓ Branch 1 taken 22028 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3220865 times.
3242893 if(p && !p->diag_mc)
236 ✗ b= 15;
237
238
2/2
✓ Branch 0 taken 2903910 times.
✓ Branch 1 taken 338983 times.
3242893 if(b&5){
239
2/2
✓ Branch 0 taken 33018536 times.
✓ Branch 1 taken 2903910 times.
35922446 for(y=0; y < b_h+HTAPS_MAX-1; y++){
240
2/2
✓ Branch 0 taken 151648064 times.
✓ Branch 1 taken 33018536 times.
184666600 for(x=0; x < b_w; x++){
241 151648064 int a_1=src[x + HTAPS_MAX/2-4];
242 151648064 int a0= src[x + HTAPS_MAX/2-3];
243 151648064 int a1= src[x + HTAPS_MAX/2-2];
244 151648064 int a2= src[x + HTAPS_MAX/2-1];
245 151648064 int a3= src[x + HTAPS_MAX/2+0];
246 151648064 int a4= src[x + HTAPS_MAX/2+1];
247 151648064 int a5= src[x + HTAPS_MAX/2+2];
248 151648064 int a6= src[x + HTAPS_MAX/2+3];
249 151648064 int am=0;
250
3/4
✓ Branch 0 taken 145560976 times.
✓ Branch 1 taken 6087088 times.
✓ Branch 2 taken 145560976 times.
✗ Branch 3 not taken.
151648064 if(!p || p->fast_mc){
251 151648064 am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5);
252 151648064 tmpI[x]= am;
253 151648064 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 6287 times.
✓ Branch 1 taken 151641777 times.
151648064 if(am&(~255)) am= ~(am>>31);
261 151648064 tmp2[x]= am;
262 }
263 33018536 tmpI+= 64;
264 33018536 tmp2+= 64;
265 33018536 src += stride;
266 }
267 2903910 src -= stride*y;
268 }
269 3242893 src += HTAPS_MAX/2 - 1;
270 3242893 tmp2= tmp2t[1];
271
272
2/2
✓ Branch 0 taken 1996165 times.
✓ Branch 1 taken 1246728 times.
3242893 if(b&2){
273
2/2
✓ Branch 0 taken 8683456 times.
✓ Branch 1 taken 1996165 times.
10679621 for(y=0; y < b_h; y++){
274
2/2
✓ Branch 0 taken 50024416 times.
✓ Branch 1 taken 8683456 times.
58707872 for(x=0; x < b_w+1; x++){
275 50024416 int a_1=src[x + (HTAPS_MAX/2-4)*stride];
276 50024416 int a0= src[x + (HTAPS_MAX/2-3)*stride];
277 50024416 int a1= src[x + (HTAPS_MAX/2-2)*stride];
278 50024416 int a2= src[x + (HTAPS_MAX/2-1)*stride];
279 50024416 int a3= src[x + (HTAPS_MAX/2+0)*stride];
280 50024416 int a4= src[x + (HTAPS_MAX/2+1)*stride];
281 50024416 int a5= src[x + (HTAPS_MAX/2+2)*stride];
282 50024416 int a6= src[x + (HTAPS_MAX/2+3)*stride];
283 50024416 int am=0;
284
3/4
✓ Branch 0 taken 48531952 times.
✓ Branch 1 taken 1492464 times.
✓ Branch 2 taken 48531952 times.
✗ Branch 3 not taken.
50024416 if(!p || p->fast_mc)
285 50024416 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 50020732 times.
50024416 if(am&(~255)) am= ~(am>>31);
290 50024416 tmp2[x]= am;
291 }
292 8683456 src += stride;
293 8683456 tmp2+= 64;
294 }
295 1996165 src -= stride*y;
296 }
297 3242893 src += stride*(HTAPS_MAX/2 - 1);
298 3242893 tmp2= tmp2t[2];
299 3242893 tmpI= tmpIt;
300
2/2
✓ Branch 0 taken 1956790 times.
✓ Branch 1 taken 1286103 times.
3242893 if(b&4){
301
2/2
✓ Branch 0 taken 8492952 times.
✓ Branch 1 taken 1956790 times.
10449742 for(y=0; y < b_h; y++){
302
2/2
✓ Branch 0 taken 40940080 times.
✓ Branch 1 taken 8492952 times.
49433032 for(x=0; x < b_w; x++){
303 40940080 int a_1=tmpI[x + (HTAPS_MAX/2-4)*64];
304 40940080 int a0= tmpI[x + (HTAPS_MAX/2-3)*64];
305 40940080 int a1= tmpI[x + (HTAPS_MAX/2-2)*64];
306 40940080 int a2= tmpI[x + (HTAPS_MAX/2-1)*64];
307 40940080 int a3= tmpI[x + (HTAPS_MAX/2+0)*64];
308 40940080 int a4= tmpI[x + (HTAPS_MAX/2+1)*64];
309 40940080 int a5= tmpI[x + (HTAPS_MAX/2+2)*64];
310 40940080 int a6= tmpI[x + (HTAPS_MAX/2+3)*64];
311 40940080 int am=0;
312
3/4
✓ Branch 0 taken 38320176 times.
✓ Branch 1 taken 2619904 times.
✓ Branch 2 taken 38320176 times.
✗ Branch 3 not taken.
40940080 if(!p || p->fast_mc)
313 40940080 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 40933422 times.
40940080 if(am&(~255)) am= ~(am>>31);
317 40940080 tmp2[x]= am;
318 }
319 8492952 tmpI+= 64;
320 8492952 tmp2+= 64;
321 }
322 }
323
324 3242893 hpel[ 0]= src;
325 3242893 hpel[ 1]= tmp2t[0] + 64*(HTAPS_MAX/2-1);
326 3242893 hpel[ 2]= src + 1;
327
328 3242893 hpel[ 4]= tmp2t[1];
329 3242893 hpel[ 5]= tmp2t[2];
330 3242893 hpel[ 6]= tmp2t[1] + 1;
331
332 3242893 hpel[ 8]= src + stride;
333 3242893 hpel[ 9]= hpel[1] + 64;
334 3242893 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 2453797 times.
3242893 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 2453797 const uint8_t *src1= hpel[l];
363 2453797 const uint8_t *src2= hpel[r];
364
2/2
✓ Branch 0 taken 601434 times.
✓ Branch 1 taken 1852363 times.
2453797 int stride1 = MC_STRIDE(l);
365
2/2
✓ Branch 0 taken 656533 times.
✓ Branch 1 taken 1797264 times.
2453797 int stride2 = MC_STRIDE(r);
366 2453797 int a= weight[((dx&7) + (8*(dy&7)))];
367 2453797 int b= 8-a;
368
2/2
✓ Branch 0 taken 10758084 times.
✓ Branch 1 taken 2453797 times.
13211881 for(y=0; y < b_h; y++){
369
2/2
✓ Branch 0 taken 53408136 times.
✓ Branch 1 taken 10758084 times.
64166220 for(x=0; x < b_w; x++){
370 53408136 dst[x]= (a*src1[x] + b*src2[x] + 4)>>3;
371 }
372 10758084 src1+=stride1;
373 10758084 src2+=stride2;
374 10758084 dst +=stride;
375 }
376 }
377 3242893 }
378
379 9462697 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 1261844 times.
✓ Branch 1 taken 8200853 times.
9462697 if(block->type & BLOCK_INTRA){
381 int x, y;
382 1261844 const unsigned color = block->color[plane_index];
383 1261844 const unsigned color4 = color*0x01010101;
384
2/2
✓ Branch 0 taken 18314 times.
✓ Branch 1 taken 1243530 times.
1261844 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 131919 times.
✓ Branch 1 taken 1111611 times.
1243530 }else if(b_w==16){
396
2/2
✓ Branch 0 taken 1980304 times.
✓ Branch 1 taken 131919 times.
2112223 for(y=0; y < b_h; y++){
397 1980304 *(uint32_t*)&dst[0 + y*stride]= color4;
398 1980304 *(uint32_t*)&dst[4 + y*stride]= color4;
399 1980304 *(uint32_t*)&dst[8 + y*stride]= color4;
400 1980304 *(uint32_t*)&dst[12+ y*stride]= color4;
401 }
402
2/2
✓ Branch 0 taken 545961 times.
✓ Branch 1 taken 565650 times.
1111611 }else if(b_w==8){
403
2/2
✓ Branch 0 taken 4274902 times.
✓ Branch 1 taken 545961 times.
4820863 for(y=0; y < b_h; y++){
404 4274902 *(uint32_t*)&dst[0 + y*stride]= color4;
405 4274902 *(uint32_t*)&dst[4 + y*stride]= color4;
406 }
407
2/2
✓ Branch 0 taken 564556 times.
✓ Branch 1 taken 1094 times.
565650 }else if(b_w==4){
408
2/2
✓ Branch 0 taken 2300822 times.
✓ Branch 1 taken 564556 times.
2865378 for(y=0; y < b_h; y++){
409 2300822 *(uint32_t*)&dst[0 + y*stride]= color4;
410 }
411 }else{
412
2/2
✓ Branch 0 taken 4748 times.
✓ Branch 1 taken 1094 times.
5842 for(y=0; y < b_h; y++){
413
2/2
✓ Branch 0 taken 8488 times.
✓ Branch 1 taken 4748 times.
13236 for(x=0; x < b_w; x++){
414 8488 dst[x + y*stride]= color;
415 }
416 }
417 }
418 }else{
419 8200853 const uint8_t *src = s->last_picture[block->ref]->data[plane_index];
420
2/2
✓ Branch 0 taken 5273260 times.
✓ Branch 1 taken 2927593 times.
8200853 const int scale= plane_index ? (2*s->mv_scale)>>s->chroma_h_shift : 2*s->mv_scale;
421 8200853 int mx= block->mx*scale;
422 8200853 int my= block->my*scale;
423 8200853 const int dx= mx&15;
424 8200853 const int dy= my&15;
425 8200853 const int tab_index= 3 - (b_w>>2) + (b_w>>4);
426 8200853 sx += (mx>>4) - (HTAPS_MAX/2-1);
427 8200853 sy += (my>>4) - (HTAPS_MAX/2-1);
428 8200853 src += sx + sy*stride;
429
4/4
✓ Branch 0 taken 8200229 times.
✓ Branch 1 taken 624 times.
✓ Branch 2 taken 7683063 times.
✓ Branch 3 taken 517790 times.
8200853 if( (unsigned)sx >= FFMAX(w - b_w - (HTAPS_MAX-2), 0)
430
4/4
✓ Branch 0 taken 7680139 times.
✓ Branch 1 taken 2924 times.
✓ Branch 2 taken 654332 times.
✓ Branch 3 taken 7028731 times.
7683063 || (unsigned)sy >= FFMAX(h - b_h - (HTAPS_MAX-2), 0)){
431 1172122 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 1172122 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 6035275 times.
✓ Branch 1 taken 2165578 times.
✓ Branch 2 taken 4981061 times.
✓ Branch 3 taken 1054214 times.
8200853 if( (dx&3) || (dy&3)
442
6/6
✓ Branch 0 taken 364853 times.
✓ Branch 1 taken 4616208 times.
✓ Branch 2 taken 214239 times.
✓ Branch 3 taken 150614 times.
✓ Branch 4 taken 213166 times.
✓ Branch 5 taken 1073 times.
4981061 || !(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h)
443
1/2
✓ Branch 0 taken 4979988 times.
✗ Branch 1 not taken.
4979988 || (b_w&(b_w-1))
444
1/2
✓ Branch 0 taken 4979988 times.
✗ Branch 1 not taken.
4979988 || b_w == 1
445
1/2
✓ Branch 0 taken 4979988 times.
✗ Branch 1 not taken.
4979988 || b_h == 1
446
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4979988 times.
4979988 || !s->plane[plane_index].fast_mc )
447 3220865 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 4691862 times.
4979988 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 4328082 times.
✓ Branch 1 taken 363780 times.
4691862 }else if(b_w==b_h)
455 4328082 s->put_snow_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst,src + 3 + 3*stride,stride);
456
2/2
✓ Branch 0 taken 213166 times.
✓ Branch 1 taken 150614 times.
363780 else if(b_w==2*b_h){
457 213166 s->put_snow_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst ,src + 3 + 3*stride,stride);
458 213166 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 150614 s->put_snow_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst ,src + 3 + 3*stride ,stride);
462 150614 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 9462697 }
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 6307 mca( 8, 0,16)
474 5487 mca( 0, 8,16)
475 10234 mca( 8, 8,16)
476 ✗ mca( 8, 0,8)
477 ✗ mca( 0, 8,8)
478 ✗ mca( 8, 8,8)
479
480 26 static av_cold void snow_static_init(void)
481 {
482
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 26 times.
234 for (int i = 0; i < MAX_REF_FRAMES; i++)
483
2/2
✓ Branch 0 taken 1664 times.
✓ Branch 1 taken 208 times.
1872 for (int j = 0; j < MAX_REF_FRAMES; j++)
484 1664 ff_scale_mv_ref[i][j] = 256 * (i + 1) / (j + 1);
485 26 }
486
487 37 av_cold int ff_snow_common_init(AVCodecContext *avctx){
488 static AVOnce init_static_once = AV_ONCE_INIT;
489 37 SnowContext *s = avctx->priv_data;
490 int width, height;
491 int i;
492
493 37 s->avctx= avctx;
494 37 s->max_ref_frames=1; //just make sure it's not an invalid value in case of no initial keyframe
495 37 s->spatial_decomposition_count = 1;
496
497 37 ff_videodsp_init(&s->vdsp, 8);
498 37 ff_dwt_init(&s->dwt);
499
500 37 init_qpel(s);
501
502 #define mcfh(dx,dy)\
503 s->hdsp.put_pixels_tab [0][dy/4+dx/8]=\
504 s->hdsp.put_no_rnd_pixels_tab[0][dy/4+dx/8]=\
505 mc_block_hpel ## dx ## dy ## 16;\
506 s->hdsp.put_pixels_tab [1][dy/4+dx/8]=\
507 s->hdsp.put_no_rnd_pixels_tab[1][dy/4+dx/8]=\
508 mc_block_hpel ## dx ## dy ## 8;
509
510 37 mcfh(8, 0)
511 37 mcfh(0, 8)
512 37 mcfh(8, 8)
513
514 // dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift);
515
516 37 width= s->avctx->width;
517 37 height= s->avctx->height;
518
519
1/2
✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
37 if (!FF_ALLOCZ_TYPED_ARRAY(s->spatial_idwt_buffer, width * height) ||
520
1/2
✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
37 !FF_ALLOCZ_TYPED_ARRAY(s->spatial_dwt_buffer, width * height) || //FIXME this does not belong here
521
1/2
✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
37 !FF_ALLOCZ_TYPED_ARRAY(s->temp_dwt_buffer, width) ||
522
1/2
✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
37 !FF_ALLOCZ_TYPED_ARRAY(s->temp_idwt_buffer, width) ||
523
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
37 !FF_ALLOCZ_TYPED_ARRAY(s->run_buffer, ((width + 1) >> 1) * ((height + 1) >> 1) + 1))
524 ✗ return AVERROR(ENOMEM);
525
526
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 37 times.
333 for(i=0; i<MAX_REF_FRAMES; i++) {
527 296 s->last_picture[i] = av_frame_alloc();
528
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 296 times.
296 if (!s->last_picture[i])
529 ✗ return AVERROR(ENOMEM);
530 }
531
532 37 s->mconly_picture = av_frame_alloc();
533 37 s->current_picture = av_frame_alloc();
534
2/4
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37 times.
37 if (!s->mconly_picture || !s->current_picture)
535 ✗ return AVERROR(ENOMEM);
536
537 37 ff_thread_once(&init_static_once, snow_static_init);
538
539 37 return 0;
540 }
541
542 1049 int ff_snow_common_init_after_header(AVCodecContext *avctx) {
543 1049 SnowContext *s = avctx->priv_data;
544 int plane_index, level, orientation;
545
546
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 1012 times.
1049 if(!s->scratchbuf) {
547
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
37 if (!FF_ALLOCZ_TYPED_ARRAY(s->scratchbuf, FFMAX(s->current_picture->linesize[0], 2*avctx->width+256) * 7 * MB_SIZE))
548 ✗ return AVERROR(ENOMEM);
549 }
550
551
2/2
✓ Branch 0 taken 3147 times.
✓ Branch 1 taken 1049 times.
4196 for(plane_index=0; plane_index < s->nb_planes; plane_index++){
552 3147 int w= s->avctx->width;
553 3147 int h= s->avctx->height;
554
555
2/2
✓ Branch 0 taken 2098 times.
✓ Branch 1 taken 1049 times.
3147 if(plane_index){
556 2098 w = AV_CEIL_RSHIFT(w, s->chroma_h_shift);
557 2098 h = AV_CEIL_RSHIFT(h, s->chroma_v_shift);
558 }
559 3147 s->plane[plane_index].width = w;
560 3147 s->plane[plane_index].height= h;
561
562
2/2
✓ Branch 0 taken 15651 times.
✓ Branch 1 taken 3147 times.
18798 for(level=s->spatial_decomposition_count-1; level>=0; level--){
563
2/2
✓ Branch 0 taken 50100 times.
✓ Branch 1 taken 15651 times.
65751 for(orientation=level ? 1 : 0; orientation<4; orientation++){
564 50100 SubBand *b= &s->plane[plane_index].band[level][orientation];
565
566 50100 b->buf= s->spatial_dwt_buffer;
567 50100 b->level= level;
568 50100 b->stride= s->plane[plane_index].width << (s->spatial_decomposition_count - level);
569 50100 b->width = (w + !(orientation&1))>>1;
570 50100 b->height= (h + !(orientation>1))>>1;
571
572 50100 b->stride_line = 1 << (s->spatial_decomposition_count - level);
573 50100 b->buf_x_offset = 0;
574 50100 b->buf_y_offset = 0;
575
576
2/2
✓ Branch 0 taken 31302 times.
✓ Branch 1 taken 18798 times.
50100 if(orientation&1){
577 31302 b->buf += (w+1)>>1;
578 31302 b->buf_x_offset = (w+1)>>1;
579 }
580
2/2
✓ Branch 0 taken 31302 times.
✓ Branch 1 taken 18798 times.
50100 if(orientation>1){
581 31302 b->buf += b->stride>>1;
582 31302 b->buf_y_offset = b->stride_line >> 1;
583 }
584 50100 b->ibuf= s->spatial_idwt_buffer + (b->buf - s->spatial_dwt_buffer);
585
586
2/2
✓ Branch 0 taken 37512 times.
✓ Branch 1 taken 12588 times.
50100 if(level)
587 37512 b->parent= &s->plane[plane_index].band[level-1][orientation];
588 //FIXME avoid this realloc
589 50100 av_freep(&b->x_coeff);
590 50100 b->x_coeff = av_calloc((b->width + 1) * b->height + 1,
591 sizeof(*b->x_coeff));
592
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50100 times.
50100 if (!b->x_coeff)
593 ✗ return AVERROR(ENOMEM);
594 }
595 15651 w= (w+1)>>1;
596 15651 h= (h+1)>>1;
597 }
598 }
599
600 1049 return 0;
601 }
602
603 1049 int ff_snow_frames_prepare(SnowContext *s)
604 {
605 AVFrame *tmp;
606
607 1049 tmp= s->last_picture[s->max_ref_frames-1];
608
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1049 times.
1049 for (int i = s->max_ref_frames - 1; i > 0; i--)
609 ✗ s->last_picture[i] = s->last_picture[i-1];
610 1049 s->last_picture[0] = s->current_picture;
611 1049 s->current_picture = tmp;
612
613 1049 av_frame_unref(s->current_picture);
614
615
2/2
✓ Branch 0 taken 113 times.
✓ Branch 1 taken 936 times.
1049 if(s->keyframe){
616 113 s->ref_frames= 0;
617 113 s->current_picture->flags |= AV_FRAME_FLAG_KEY;
618 }else{
619 int i;
620
3/4
✓ Branch 0 taken 936 times.
✓ Branch 1 taken 936 times.
✓ Branch 2 taken 936 times.
✗ Branch 3 not taken.
1872 for(i=0; i<s->max_ref_frames && s->last_picture[i]->data[0]; i++)
621
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 936 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
936 if(i && (s->last_picture[i-1]->flags & AV_FRAME_FLAG_KEY))
622 ✗ break;
623 936 s->ref_frames= i;
624
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 936 times.
936 if(s->ref_frames==0){
625 ✗ av_log(s->avctx,AV_LOG_ERROR, "No reference frames\n");
626 ✗ return AVERROR_INVALIDDATA;
627 }
628 936 s->current_picture->flags &= ~AV_FRAME_FLAG_KEY;
629 }
630
631 1049 return 0;
632 }
633
634 37 av_cold void ff_snow_common_end(SnowContext *s)
635 {
636 int plane_index, level, orientation, i;
637
638 37 av_freep(&s->spatial_dwt_buffer);
639 37 av_freep(&s->temp_dwt_buffer);
640 37 av_freep(&s->spatial_idwt_buffer);
641 37 av_freep(&s->temp_idwt_buffer);
642 37 av_freep(&s->run_buffer);
643
644 37 av_freep(&s->block);
645 37 av_freep(&s->scratchbuf);
646
647
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 37 times.
333 for(i=0; i<MAX_REF_FRAMES; i++){
648 296 av_frame_free(&s->last_picture[i]);
649 }
650
651
2/2
✓ Branch 0 taken 148 times.
✓ Branch 1 taken 37 times.
185 for(plane_index=0; plane_index < MAX_PLANES; plane_index++){
652
2/2
✓ Branch 0 taken 1184 times.
✓ Branch 1 taken 148 times.
1332 for(level=MAX_DECOMPOSITIONS-1; level>=0; level--){
653
2/2
✓ Branch 0 taken 3700 times.
✓ Branch 1 taken 1184 times.
4884 for(orientation=level ? 1 : 0; orientation<4; orientation++){
654 3700 SubBand *b= &s->plane[plane_index].band[level][orientation];
655
656 3700 av_freep(&b->x_coeff);
657 }
658 }
659 }
660 37 av_frame_free(&s->mconly_picture);
661 37 av_frame_free(&s->current_picture);
662 37 }
663