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 | 3226960 | 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 | 3226960 | int16_t *tmpI= tmpIt; | |
134 | 3226960 | uint8_t *tmp2= tmp2t[0]; | |
135 | const uint8_t *hpel[11]; | ||
136 | av_assert2(dx<16 && dy<16); | ||
137 | 3226960 | r= brane[dx + 16*dy]&15; | |
138 | 3226960 | l= brane[dx + 16*dy]>>4; | |
139 | |||
140 | 3226960 | b= needs[l] | needs[r]; | |
141 |
3/4✓ Branch 0 taken 3206706 times.
✓ Branch 1 taken 20254 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3206706 times.
|
3226960 | if(p && !p->diag_mc) |
142 | ✗ | b= 15; | |
143 | |||
144 |
2/2✓ Branch 0 taken 2890899 times.
✓ Branch 1 taken 336061 times.
|
3226960 | if(b&5){ |
145 |
2/2✓ Branch 0 taken 32853085 times.
✓ Branch 1 taken 2890899 times.
|
35743984 | for(y=0; y < b_h+HTAPS_MAX-1; y++){ |
146 |
2/2✓ Branch 0 taken 150497304 times.
✓ Branch 1 taken 32853085 times.
|
183350389 | for(x=0; x < b_w; x++){ |
147 | 150497304 | int a_1=src[x + HTAPS_MAX/2-4]; | |
148 | 150497304 | int a0= src[x + HTAPS_MAX/2-3]; | |
149 | 150497304 | int a1= src[x + HTAPS_MAX/2-2]; | |
150 | 150497304 | int a2= src[x + HTAPS_MAX/2-1]; | |
151 | 150497304 | int a3= src[x + HTAPS_MAX/2+0]; | |
152 | 150497304 | int a4= src[x + HTAPS_MAX/2+1]; | |
153 | 150497304 | int a5= src[x + HTAPS_MAX/2+2]; | |
154 | 150497304 | int a6= src[x + HTAPS_MAX/2+3]; | |
155 | 150497304 | int am=0; | |
156 |
3/4✓ Branch 0 taken 144872424 times.
✓ Branch 1 taken 5624880 times.
✓ Branch 2 taken 144872424 times.
✗ Branch 3 not taken.
|
150497304 | if(!p || p->fast_mc){ |
157 | 150497304 | am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5); | |
158 | 150497304 | tmpI[x]= am; | |
159 | 150497304 | 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 150491061 times.
|
150497304 | if(am&(~255)) am= ~(am>>31); |
167 | 150497304 | tmp2[x]= am; | |
168 | } | ||
169 | 32853085 | tmpI+= 64; | |
170 | 32853085 | tmp2+= 64; | |
171 | 32853085 | src += stride; | |
172 | } | ||
173 | 2890899 | src -= stride*y; | |
174 | } | ||
175 | 3226960 | src += HTAPS_MAX/2 - 1; | |
176 | 3226960 | tmp2= tmp2t[1]; | |
177 | |||
178 |
2/2✓ Branch 0 taken 1986073 times.
✓ Branch 1 taken 1240887 times.
|
3226960 | if(b&2){ |
179 |
2/2✓ Branch 0 taken 8629972 times.
✓ Branch 1 taken 1986073 times.
|
10616045 | for(y=0; y < b_h; y++){ |
180 |
2/2✓ Branch 0 taken 49598708 times.
✓ Branch 1 taken 8629972 times.
|
58228680 | for(x=0; x < b_w+1; x++){ |
181 | 49598708 | int a_1=src[x + (HTAPS_MAX/2-4)*stride]; | |
182 | 49598708 | int a0= src[x + (HTAPS_MAX/2-3)*stride]; | |
183 | 49598708 | int a1= src[x + (HTAPS_MAX/2-2)*stride]; | |
184 | 49598708 | int a2= src[x + (HTAPS_MAX/2-1)*stride]; | |
185 | 49598708 | int a3= src[x + (HTAPS_MAX/2+0)*stride]; | |
186 | 49598708 | int a4= src[x + (HTAPS_MAX/2+1)*stride]; | |
187 | 49598708 | int a5= src[x + (HTAPS_MAX/2+2)*stride]; | |
188 | 49598708 | int a6= src[x + (HTAPS_MAX/2+3)*stride]; | |
189 | 49598708 | int am=0; | |
190 |
3/4✓ Branch 0 taken 48247140 times.
✓ Branch 1 taken 1351568 times.
✓ Branch 2 taken 48247140 times.
✗ Branch 3 not taken.
|
49598708 | if(!p || p->fast_mc) |
191 | 49598708 | 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 49595024 times.
|
49598708 | if(am&(~255)) am= ~(am>>31); |
196 | 49598708 | tmp2[x]= am; | |
197 | } | ||
198 | 8629972 | src += stride; | |
199 | 8629972 | tmp2+= 64; | |
200 | } | ||
201 | 1986073 | src -= stride*y; | |
202 | } | ||
203 | 3226960 | src += stride*(HTAPS_MAX/2 - 1); | |
204 | 3226960 | tmp2= tmp2t[2]; | |
205 | 3226960 | tmpI= tmpIt; | |
206 |
2/2✓ Branch 0 taken 1948890 times.
✓ Branch 1 taken 1278070 times.
|
3226960 | if(b&4){ |
207 |
2/2✓ Branch 0 taken 8451144 times.
✓ Branch 1 taken 1948890 times.
|
10400034 | for(y=0; y < b_h; y++){ |
208 |
2/2✓ Branch 0 taken 40641424 times.
✓ Branch 1 taken 8451144 times.
|
49092568 | for(x=0; x < b_w; x++){ |
209 | 40641424 | int a_1=tmpI[x + (HTAPS_MAX/2-4)*64]; | |
210 | 40641424 | int a0= tmpI[x + (HTAPS_MAX/2-3)*64]; | |
211 | 40641424 | int a1= tmpI[x + (HTAPS_MAX/2-2)*64]; | |
212 | 40641424 | int a2= tmpI[x + (HTAPS_MAX/2-1)*64]; | |
213 | 40641424 | int a3= tmpI[x + (HTAPS_MAX/2+0)*64]; | |
214 | 40641424 | int a4= tmpI[x + (HTAPS_MAX/2+1)*64]; | |
215 | 40641424 | int a5= tmpI[x + (HTAPS_MAX/2+2)*64]; | |
216 | 40641424 | int a6= tmpI[x + (HTAPS_MAX/2+3)*64]; | |
217 | 40641424 | int am=0; | |
218 |
3/4✓ Branch 0 taken 38144400 times.
✓ Branch 1 taken 2497024 times.
✓ Branch 2 taken 38144400 times.
✗ Branch 3 not taken.
|
40641424 | if(!p || p->fast_mc) |
219 | 40641424 | 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 40634766 times.
|
40641424 | if(am&(~255)) am= ~(am>>31); |
223 | 40641424 | tmp2[x]= am; | |
224 | } | ||
225 | 8451144 | tmpI+= 64; | |
226 | 8451144 | tmp2+= 64; | |
227 | } | ||
228 | } | ||
229 | |||
230 | 3226960 | hpel[ 0]= src; | |
231 | 3226960 | hpel[ 1]= tmp2t[0] + 64*(HTAPS_MAX/2-1); | |
232 | 3226960 | hpel[ 2]= src + 1; | |
233 | |||
234 | 3226960 | hpel[ 4]= tmp2t[1]; | |
235 | 3226960 | hpel[ 5]= tmp2t[2]; | |
236 | 3226960 | hpel[ 6]= tmp2t[1] + 1; | |
237 | |||
238 | 3226960 | hpel[ 8]= src + stride; | |
239 | 3226960 | hpel[ 9]= hpel[1] + 64; | |
240 | 3226960 | hpel[10]= hpel[8] + 1; | |
241 | |||
242 | #define MC_STRIDE(x) (needs[x] ? 64 : stride) | ||
243 | |||
244 |
2/2✓ Branch 0 taken 786570 times.
✓ Branch 1 taken 2440390 times.
|
3226960 | if(b==15){ |
245 | 786570 | int dxy = dx / 8 + dy / 8 * 4; | |
246 | 786570 | const uint8_t *src1 = hpel[dxy ]; | |
247 | 786570 | const uint8_t *src2 = hpel[dxy + 1]; | |
248 | 786570 | const uint8_t *src3 = hpel[dxy + 4]; | |
249 | 786570 | const uint8_t *src4 = hpel[dxy + 5]; | |
250 |
2/2✓ Branch 0 taken 197148 times.
✓ Branch 1 taken 589422 times.
|
786570 | int stride1 = MC_STRIDE(dxy); |
251 |
2/2✓ Branch 0 taken 201514 times.
✓ Branch 1 taken 585056 times.
|
786570 | int stride2 = MC_STRIDE(dxy + 1); |
252 |
2/2✓ Branch 0 taken 190394 times.
✓ Branch 1 taken 596176 times.
|
786570 | int stride3 = MC_STRIDE(dxy + 4); |
253 |
2/2✓ Branch 0 taken 197514 times.
✓ Branch 1 taken 589056 times.
|
786570 | int stride4 = MC_STRIDE(dxy + 5); |
254 | 786570 | dx&=7; | |
255 | 786570 | dy&=7; | |
256 |
2/2✓ Branch 0 taken 3452584 times.
✓ Branch 1 taken 786570 times.
|
4239154 | for(y=0; y < b_h; y++){ |
257 |
2/2✓ Branch 0 taken 16499096 times.
✓ Branch 1 taken 3452584 times.
|
19951680 | for(x=0; x < b_w; x++){ |
258 | 16499096 | dst[x]= ((8-dx)*(8-dy)*src1[x] + dx*(8-dy)*src2[x]+ | |
259 | 16499096 | (8-dx)* dy *src3[x] + dx* dy *src4[x]+32)>>6; | |
260 | } | ||
261 | 3452584 | src1+=stride1; | |
262 | 3452584 | src2+=stride2; | |
263 | 3452584 | src3+=stride3; | |
264 | 3452584 | src4+=stride4; | |
265 | 3452584 | dst +=stride; | |
266 | } | ||
267 | }else{ | ||
268 | 2440390 | const uint8_t *src1= hpel[l]; | |
269 | 2440390 | const uint8_t *src2= hpel[r]; | |
270 |
2/2✓ Branch 0 taken 598440 times.
✓ Branch 1 taken 1841950 times.
|
2440390 | int stride1 = MC_STRIDE(l); |
271 |
2/2✓ Branch 0 taken 652892 times.
✓ Branch 1 taken 1787498 times.
|
2440390 | int stride2 = MC_STRIDE(r); |
272 | 2440390 | int a= weight[((dx&7) + (8*(dy&7)))]; | |
273 | 2440390 | int b= 8-a; | |
274 |
2/2✓ Branch 0 taken 10676392 times.
✓ Branch 1 taken 2440390 times.
|
13116782 | for(y=0; y < b_h; y++){ |
275 |
2/2✓ Branch 0 taken 52670328 times.
✓ Branch 1 taken 10676392 times.
|
63346720 | for(x=0; x < b_w; x++){ |
276 | 52670328 | dst[x]= (a*src1[x] + b*src2[x] + 4)>>3; | |
277 | } | ||
278 | 10676392 | src1+=stride1; | |
279 | 10676392 | src2+=stride2; | |
280 | 10676392 | dst +=stride; | |
281 | } | ||
282 | } | ||
283 | 3226960 | } | |
284 | |||
285 | 9284876 | 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 1201940 times.
✓ Branch 1 taken 8082936 times.
|
9284876 | if(block->type & BLOCK_INTRA){ |
287 | int x, y; | ||
288 | 1201940 | const unsigned color = block->color[plane_index]; | |
289 | 1201940 | const unsigned color4 = color*0x01010101; | |
290 |
2/2✓ Branch 0 taken 18314 times.
✓ Branch 1 taken 1183626 times.
|
1201940 | 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 127575 times.
✓ Branch 1 taken 1056051 times.
|
1183626 | }else if(b_w==16){ |
302 |
2/2✓ Branch 0 taken 1911240 times.
✓ Branch 1 taken 127575 times.
|
2038815 | for(y=0; y < b_h; y++){ |
303 | 1911240 | *(uint32_t*)&dst[0 + y*stride]= color4; | |
304 | 1911240 | *(uint32_t*)&dst[4 + y*stride]= color4; | |
305 | 1911240 | *(uint32_t*)&dst[8 + y*stride]= color4; | |
306 | 1911240 | *(uint32_t*)&dst[12+ y*stride]= color4; | |
307 | } | ||
308 |
2/2✓ Branch 0 taken 521653 times.
✓ Branch 1 taken 534398 times.
|
1056051 | }else if(b_w==8){ |
309 |
2/2✓ Branch 0 taken 4084224 times.
✓ Branch 1 taken 521653 times.
|
4605877 | for(y=0; y < b_h; y++){ |
310 | 4084224 | *(uint32_t*)&dst[0 + y*stride]= color4; | |
311 | 4084224 | *(uint32_t*)&dst[4 + y*stride]= color4; | |
312 | } | ||
313 |
2/2✓ Branch 0 taken 533470 times.
✓ Branch 1 taken 928 times.
|
534398 | }else if(b_w==4){ |
314 |
2/2✓ Branch 0 taken 2176640 times.
✓ Branch 1 taken 533470 times.
|
2710110 | for(y=0; y < b_h; y++){ |
315 | 2176640 | *(uint32_t*)&dst[0 + y*stride]= color4; | |
316 | } | ||
317 | }else{ | ||
318 |
2/2✓ Branch 0 taken 3656 times.
✓ Branch 1 taken 928 times.
|
4584 | for(y=0; y < b_h; y++){ |
319 |
2/2✓ Branch 0 taken 7312 times.
✓ Branch 1 taken 3656 times.
|
10968 | for(x=0; x < b_w; x++){ |
320 | 7312 | dst[x + y*stride]= color; | |
321 | } | ||
322 | } | ||
323 | } | ||
324 | }else{ | ||
325 | 8082936 | const uint8_t *src = s->last_picture[block->ref]->data[plane_index]; | |
326 |
2/2✓ Branch 0 taken 5196540 times.
✓ Branch 1 taken 2886396 times.
|
8082936 | const int scale= plane_index ? (2*s->mv_scale)>>s->chroma_h_shift : 2*s->mv_scale; |
327 | 8082936 | int mx= block->mx*scale; | |
328 | 8082936 | int my= block->my*scale; | |
329 | 8082936 | const int dx= mx&15; | |
330 | 8082936 | const int dy= my&15; | |
331 | 8082936 | const int tab_index= 3 - (b_w>>2) + (b_w>>4); | |
332 | 8082936 | sx += (mx>>4) - (HTAPS_MAX/2-1); | |
333 | 8082936 | sy += (my>>4) - (HTAPS_MAX/2-1); | |
334 | 8082936 | src += sx + sy*stride; | |
335 |
3/4✓ Branch 0 taken 8082936 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7574313 times.
✓ Branch 3 taken 508623 times.
|
8082936 | if( (unsigned)sx >= FFMAX(w - b_w - (HTAPS_MAX-2), 0) |
336 |
3/4✓ Branch 0 taken 7574313 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 640831 times.
✓ Branch 3 taken 6933482 times.
|
7574313 | || (unsigned)sy >= FFMAX(h - b_h - (HTAPS_MAX-2), 0)){ |
337 | 1149454 | 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 | 1149454 | 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 5927358 times.
✓ Branch 1 taken 2155578 times.
✓ Branch 2 taken 4876230 times.
✓ Branch 3 taken 1051128 times.
|
8082936 | if( (dx&3) || (dy&3) |
348 |
5/6✓ Branch 0 taken 347714 times.
✓ Branch 1 taken 4528516 times.
✓ Branch 2 taken 203675 times.
✓ Branch 3 taken 144039 times.
✓ Branch 4 taken 203675 times.
✗ Branch 5 not taken.
|
4876230 | || !(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h) |
349 |
1/2✓ Branch 0 taken 4876230 times.
✗ Branch 1 not taken.
|
4876230 | || (b_w&(b_w-1)) |
350 |
1/2✓ Branch 0 taken 4876230 times.
✗ Branch 1 not taken.
|
4876230 | || b_w == 1 |
351 |
1/2✓ Branch 0 taken 4876230 times.
✗ Branch 1 not taken.
|
4876230 | || b_h == 1 |
352 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4876230 times.
|
4876230 | || !s->plane[plane_index].fast_mc ) |
353 | 3206706 | 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 4588104 times.
|
4876230 | 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 4240390 times.
✓ Branch 1 taken 347714 times.
|
4588104 | }else if(b_w==b_h) |
361 | 4240390 | s->h264qpel.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst,src + 3 + 3*stride,stride); | |
362 |
2/2✓ Branch 0 taken 203675 times.
✓ Branch 1 taken 144039 times.
|
347714 | else if(b_w==2*b_h){ |
363 | 203675 | s->h264qpel.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst ,src + 3 + 3*stride,stride); | |
364 | 203675 | 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 | 144039 | s->h264qpel.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst ,src + 3 + 3*stride ,stride); | |
368 | 144039 | 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 | 9284876 | } | |
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 | 971 | int ff_snow_common_init_after_header(AVCodecContext *avctx) { | |
451 | 971 | SnowContext *s = avctx->priv_data; | |
452 | int plane_index, level, orientation; | ||
453 | |||
454 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 940 times.
|
971 | 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 2913 times.
✓ Branch 1 taken 971 times.
|
3884 | for(plane_index=0; plane_index < s->nb_planes; plane_index++){ |
463 | 2913 | int w= s->avctx->width; | |
464 | 2913 | int h= s->avctx->height; | |
465 | |||
466 |
2/2✓ Branch 0 taken 1942 times.
✓ Branch 1 taken 971 times.
|
2913 | if(plane_index){ |
467 | 1942 | w = AV_CEIL_RSHIFT(w, s->chroma_h_shift); | |
468 | 1942 | h = AV_CEIL_RSHIFT(h, s->chroma_v_shift); | |
469 | } | ||
470 | 2913 | s->plane[plane_index].width = w; | |
471 | 2913 | s->plane[plane_index].height= h; | |
472 | |||
473 |
2/2✓ Branch 0 taken 14565 times.
✓ Branch 1 taken 2913 times.
|
17478 | for(level=s->spatial_decomposition_count-1; level>=0; level--){ |
474 |
2/2✓ Branch 0 taken 46608 times.
✓ Branch 1 taken 14565 times.
|
61173 | for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
475 | 46608 | SubBand *b= &s->plane[plane_index].band[level][orientation]; | |
476 | |||
477 | 46608 | b->buf= s->spatial_dwt_buffer; | |
478 | 46608 | b->level= level; | |
479 | 46608 | b->stride= s->plane[plane_index].width << (s->spatial_decomposition_count - level); | |
480 | 46608 | b->width = (w + !(orientation&1))>>1; | |
481 | 46608 | b->height= (h + !(orientation>1))>>1; | |
482 | |||
483 | 46608 | b->stride_line = 1 << (s->spatial_decomposition_count - level); | |
484 | 46608 | b->buf_x_offset = 0; | |
485 | 46608 | b->buf_y_offset = 0; | |
486 | |||
487 |
2/2✓ Branch 0 taken 29130 times.
✓ Branch 1 taken 17478 times.
|
46608 | if(orientation&1){ |
488 | 29130 | b->buf += (w+1)>>1; | |
489 | 29130 | b->buf_x_offset = (w+1)>>1; | |
490 | } | ||
491 |
2/2✓ Branch 0 taken 29130 times.
✓ Branch 1 taken 17478 times.
|
46608 | if(orientation>1){ |
492 | 29130 | b->buf += b->stride>>1; | |
493 | 29130 | b->buf_y_offset = b->stride_line >> 1; | |
494 | } | ||
495 | 46608 | b->ibuf= s->spatial_idwt_buffer + (b->buf - s->spatial_dwt_buffer); | |
496 | |||
497 |
2/2✓ Branch 0 taken 34956 times.
✓ Branch 1 taken 11652 times.
|
46608 | if(level) |
498 | 34956 | b->parent= &s->plane[plane_index].band[level-1][orientation]; | |
499 | //FIXME avoid this realloc | ||
500 | 46608 | av_freep(&b->x_coeff); | |
501 | 46608 | 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 46608 times.
|
46608 | if (!b->x_coeff) |
504 | ✗ | return AVERROR(ENOMEM); | |
505 | } | ||
506 | 14565 | w= (w+1)>>1; | |
507 | 14565 | h= (h+1)>>1; | |
508 | } | ||
509 | } | ||
510 | |||
511 | 971 | return 0; | |
512 | } | ||
513 | |||
514 | 1942 | void ff_snow_release_buffer(AVCodecContext *avctx) | |
515 | { | ||
516 | 1942 | SnowContext *s = avctx->priv_data; | |
517 | |||
518 |
2/2✓ Branch 0 taken 940 times.
✓ Branch 1 taken 1002 times.
|
1942 | if(s->last_picture[s->max_ref_frames-1]->data[0]){ |
519 | 940 | av_frame_unref(s->last_picture[s->max_ref_frames-1]); | |
520 | } | ||
521 | 1942 | } | |
522 | |||
523 | 971 | int ff_snow_frames_prepare(SnowContext *s) | |
524 | { | ||
525 | AVFrame *tmp; | ||
526 | |||
527 | 971 | ff_snow_release_buffer(s->avctx); | |
528 | |||
529 | 971 | tmp= s->last_picture[s->max_ref_frames-1]; | |
530 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 971 times.
|
971 | for (int i = s->max_ref_frames - 1; i > 0; i--) |
531 | ✗ | s->last_picture[i] = s->last_picture[i-1]; | |
532 | 971 | s->last_picture[0] = s->current_picture; | |
533 | 971 | s->current_picture = tmp; | |
534 | |||
535 |
2/2✓ Branch 0 taken 103 times.
✓ Branch 1 taken 868 times.
|
971 | if(s->keyframe){ |
536 | 103 | s->ref_frames= 0; | |
537 | 103 | s->current_picture->flags |= AV_FRAME_FLAG_KEY; | |
538 | }else{ | ||
539 | int i; | ||
540 |
3/4✓ Branch 0 taken 868 times.
✓ Branch 1 taken 868 times.
✓ Branch 2 taken 868 times.
✗ Branch 3 not taken.
|
1736 | for(i=0; i<s->max_ref_frames && s->last_picture[i]->data[0]; i++) |
541 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 868 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
868 | if(i && (s->last_picture[i-1]->flags & AV_FRAME_FLAG_KEY)) |
542 | ✗ | break; | |
543 | 868 | s->ref_frames= i; | |
544 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 868 times.
|
868 | if(s->ref_frames==0){ |
545 | ✗ | av_log(s->avctx,AV_LOG_ERROR, "No reference frames\n"); | |
546 | ✗ | return AVERROR_INVALIDDATA; | |
547 | } | ||
548 | 868 | s->current_picture->flags &= ~AV_FRAME_FLAG_KEY; | |
549 | } | ||
550 | |||
551 | 971 | return 0; | |
552 | } | ||
553 | |||
554 | 31 | av_cold void ff_snow_common_end(SnowContext *s) | |
555 | { | ||
556 | int plane_index, level, orientation, i; | ||
557 | |||
558 | 31 | av_freep(&s->spatial_dwt_buffer); | |
559 | 31 | av_freep(&s->temp_dwt_buffer); | |
560 | 31 | av_freep(&s->spatial_idwt_buffer); | |
561 | 31 | av_freep(&s->temp_idwt_buffer); | |
562 | 31 | av_freep(&s->run_buffer); | |
563 | |||
564 | 31 | av_freep(&s->block); | |
565 | 31 | av_freep(&s->scratchbuf); | |
566 | 31 | av_freep(&s->emu_edge_buffer); | |
567 | |||
568 |
2/2✓ Branch 0 taken 248 times.
✓ Branch 1 taken 31 times.
|
279 | for(i=0; i<MAX_REF_FRAMES; i++){ |
569 |
2/4✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 248 times.
|
248 | if(s->last_picture[i] && s->last_picture[i]->data[0]) { |
570 | ✗ | av_assert0(s->last_picture[i]->data[0] != s->current_picture->data[0]); | |
571 | } | ||
572 | 248 | av_frame_free(&s->last_picture[i]); | |
573 | } | ||
574 | |||
575 |
2/2✓ Branch 0 taken 124 times.
✓ Branch 1 taken 31 times.
|
155 | for(plane_index=0; plane_index < MAX_PLANES; plane_index++){ |
576 |
2/2✓ Branch 0 taken 992 times.
✓ Branch 1 taken 124 times.
|
1116 | for(level=MAX_DECOMPOSITIONS-1; level>=0; level--){ |
577 |
2/2✓ Branch 0 taken 3100 times.
✓ Branch 1 taken 992 times.
|
4092 | for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
578 | 3100 | SubBand *b= &s->plane[plane_index].band[level][orientation]; | |
579 | |||
580 | 3100 | av_freep(&b->x_coeff); | |
581 | } | ||
582 | } | ||
583 | } | ||
584 | 31 | av_frame_free(&s->mconly_picture); | |
585 | 31 | av_frame_free(&s->current_picture); | |
586 | 31 | } | |
587 |