1 |
|
|
/* |
2 |
|
|
* Copyright (C) 2004-2010 Michael Niedermayer <michaelni@gmx.at> |
3 |
|
|
* Copyright (C) 2008 David Conrad |
4 |
|
|
* Copyright (C) 2015 Open Broadcast Systems Ltd. |
5 |
|
|
* Author (C) 2015 Rostislav Pehlivanov <atomnuker@gmail.com> |
6 |
|
|
* |
7 |
|
|
* This file is part of FFmpeg. |
8 |
|
|
* |
9 |
|
|
* FFmpeg is free software; you can redistribute it and/or |
10 |
|
|
* modify it under the terms of the GNU Lesser General Public |
11 |
|
|
* License as published by the Free Software Foundation; either |
12 |
|
|
* version 2.1 of the License, or (at your option) any later version. |
13 |
|
|
* |
14 |
|
|
* FFmpeg is distributed in the hope that it will be useful, |
15 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 |
|
|
* Lesser General Public License for more details. |
18 |
|
|
* |
19 |
|
|
* You should have received a copy of the GNU Lesser General Public |
20 |
|
|
* License along with FFmpeg; if not, write to the Free Software |
21 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#if defined(TEMPLATE_8bit) |
25 |
|
|
|
26 |
|
|
# define RENAME(N) N ## _8bit |
27 |
|
|
# define TYPE int16_t |
28 |
|
|
# undef TEMPLATE_8bit |
29 |
|
|
|
30 |
|
|
#elif defined(TEMPLATE_10bit) |
31 |
|
|
|
32 |
|
|
# define RENAME(N) N ## _10bit |
33 |
|
|
# define TYPE int32_t |
34 |
|
|
# undef TEMPLATE_10bit |
35 |
|
|
|
36 |
|
|
#elif defined(TEMPLATE_12bit) |
37 |
|
|
|
38 |
|
|
# define RENAME(N) N ## _12bit |
39 |
|
|
# define TYPE int32_t |
40 |
|
|
# undef TEMPLATE_12bit |
41 |
|
|
|
42 |
|
|
#endif |
43 |
|
|
|
44 |
|
314520 |
static void RENAME(vertical_compose53iL0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2, |
45 |
|
|
int width) |
46 |
|
|
{ |
47 |
|
|
int i; |
48 |
|
314520 |
TYPE *b0 = (TYPE *)_b0; |
49 |
|
314520 |
TYPE *b1 = (TYPE *)_b1; |
50 |
|
314520 |
TYPE *b2 = (TYPE *)_b2; |
51 |
✓✓ |
61794600 |
for (i = 0; i < width; i++) |
52 |
|
61480080 |
b1[i] -= (unsigned)((int)(b0[i] + (unsigned)b2[i] + 2) >> 2); |
53 |
|
314520 |
} |
54 |
|
|
|
55 |
|
116640 |
static av_always_inline void RENAME(interleave)(TYPE *dst, TYPE *src0, TYPE *src1, int w2, |
56 |
|
|
int add, int shift) |
57 |
|
|
{ |
58 |
|
|
int i; |
59 |
✓✓ |
9810720 |
for (i = 0; i < w2; i++) { |
60 |
|
9694080 |
dst[2*i ] = ((int)(src0[i] + (unsigned)add)) >> shift; |
61 |
|
9694080 |
dst[2*i+1] = ((int)(src1[i] + (unsigned)add)) >> shift; |
62 |
|
|
} |
63 |
|
|
} |
64 |
|
|
|
65 |
|
58320 |
static void RENAME(horizontal_compose_dirac53i)(uint8_t *_b, uint8_t *_temp, int w) |
66 |
|
|
{ |
67 |
|
|
int x; |
68 |
|
58320 |
const int w2 = w >> 1; |
69 |
|
58320 |
TYPE *b = (TYPE *)_b; |
70 |
|
58320 |
TYPE *temp = (TYPE *)_temp; |
71 |
|
|
|
72 |
|
58320 |
temp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]); |
73 |
✓✓ |
4847040 |
for (x = 1; x < w2; x++) { |
74 |
|
4788720 |
temp[x ] = COMPOSE_53iL0 (b[x+w2-1], b[x ], b[x+w2]); |
75 |
|
4788720 |
temp[x+w2-1] = COMPOSE_DIRAC53iH0(temp[x-1], b[x+w2-1], temp[x]); |
76 |
|
|
} |
77 |
|
58320 |
temp[w-1] = COMPOSE_DIRAC53iH0(temp[w2-1], b[w-1], temp[w2-1]); |
78 |
|
|
|
79 |
|
58320 |
RENAME(interleave)(b, temp, temp+w2, w2, 1, 1); |
80 |
|
|
} |
81 |
|
|
|
82 |
|
570720 |
static void RENAME(horizontal_compose_dd97i)(uint8_t *_b, uint8_t *_tmp, int w) |
83 |
|
|
{ |
84 |
|
|
int x; |
85 |
|
570720 |
const int w2 = w >> 1; |
86 |
|
570720 |
TYPE *b = (TYPE *)_b; |
87 |
|
570720 |
TYPE *tmp = (TYPE *)_tmp; |
88 |
|
|
|
89 |
|
570720 |
tmp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]); |
90 |
✓✓ |
56633040 |
for (x = 1; x < w2; x++) |
91 |
|
56062320 |
tmp[x] = COMPOSE_53iL0(b[x+w2-1], b[x], b[x+w2]); |
92 |
|
|
|
93 |
|
|
// extend the edges |
94 |
|
570720 |
tmp[-1] = tmp[0]; |
95 |
|
570720 |
tmp[w2+1] = tmp[w2] = tmp[w2-1]; |
96 |
|
|
|
97 |
✓✓ |
57203760 |
for (x = 0; x < w2; x++) { |
98 |
|
56633040 |
b[2*x ] = ((int)(tmp[x] + 1U))>>1; |
99 |
|
56633040 |
b[2*x+1] = ((int)(COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1U))>>1; |
100 |
|
|
} |
101 |
|
570720 |
} |
102 |
|
|
|
103 |
|
|
static void RENAME(horizontal_compose_dd137i)(uint8_t *_b, uint8_t *_tmp, int w) |
104 |
|
|
{ |
105 |
|
|
const int w2 = w >> 1; |
106 |
|
|
int x; |
107 |
|
|
TYPE *b = (TYPE *)_b; |
108 |
|
|
TYPE *tmp = (TYPE *)_tmp; |
109 |
|
|
|
110 |
|
|
tmp[0] = COMPOSE_DD137iL0(b[w2], b[w2], b[0], b[w2 ], b[w2+1]); |
111 |
|
|
tmp[1] = COMPOSE_DD137iL0(b[w2], b[w2], b[1], b[w2+1], b[w2+2]); |
112 |
|
|
for (x = 2; x < w2-1; x++) |
113 |
|
|
tmp[x] = COMPOSE_DD137iL0(b[x+w2-2], b[x+w2-1], b[x], b[x+w2], b[x+w2+1]); |
114 |
|
|
tmp[w2-1] = COMPOSE_DD137iL0(b[w-3], b[w-2], b[w2-1], b[w-1], b[w-1]); |
115 |
|
|
|
116 |
|
|
// extend the edges |
117 |
|
|
tmp[-1] = tmp[0]; |
118 |
|
|
tmp[w2+1] = tmp[w2] = tmp[w2-1]; |
119 |
|
|
|
120 |
|
|
for (x = 0; x < w2; x++) { |
121 |
|
|
b[2*x ] = ((int)(tmp[x] + 1U))>>1; |
122 |
|
|
b[2*x+1] = ((int)(COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1U))>>1; |
123 |
|
|
} |
124 |
|
|
} |
125 |
|
|
|
126 |
|
58320 |
static av_always_inline void RENAME(horizontal_compose_haari)(TYPE *b, TYPE *temp, |
127 |
|
|
int w, int shift) |
128 |
|
|
{ |
129 |
|
58320 |
const int w2 = w >> 1; |
130 |
|
|
int x; |
131 |
|
|
|
132 |
✓✓ |
4905360 |
for (x = 0; x < w2; x++) { |
133 |
|
4847040 |
temp[x ] = COMPOSE_HAARiL0(b[x ], b[x+w2]); |
134 |
|
4847040 |
temp[x+w2] = COMPOSE_HAARiH0(b[x+w2], temp[x]); |
135 |
|
|
} |
136 |
|
|
|
137 |
|
58320 |
RENAME(interleave)(b, temp, temp+w2, w2, shift, shift); |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
static void RENAME(horizontal_compose_haar0i)(uint8_t *_b, uint8_t *_temp, int w) |
141 |
|
|
{ |
142 |
|
|
TYPE *b = (TYPE *)_b; |
143 |
|
|
TYPE *temp = (TYPE *)_temp; |
144 |
|
|
RENAME(horizontal_compose_haari)(b, temp, w, 0); |
145 |
|
|
} |
146 |
|
|
|
147 |
|
58320 |
static void RENAME(horizontal_compose_haar1i)(uint8_t *_b, uint8_t *_temp, int w) |
148 |
|
|
{ |
149 |
|
58320 |
TYPE *b = (TYPE *)_b; |
150 |
|
58320 |
TYPE *temp = (TYPE *)_temp; |
151 |
|
58320 |
RENAME(horizontal_compose_haari)(b, temp, w, 1); |
152 |
|
|
} |
153 |
|
|
|
154 |
|
|
static void RENAME(horizontal_compose_fidelityi)(uint8_t *_b, uint8_t *_tmp, int w) |
155 |
|
|
{ |
156 |
|
|
const int w2 = w >> 1; |
157 |
|
|
int i, x; |
158 |
|
|
TYPE v[8]; |
159 |
|
|
TYPE *b = (TYPE *)_b; |
160 |
|
|
TYPE *tmp = (TYPE *)_tmp; |
161 |
|
|
|
162 |
|
|
for (x = 0; x < w2; x++) { |
163 |
|
|
for (i = 0; i < 8; i++) |
164 |
|
|
v[i] = b[av_clip(x-3+i, 0, w2-1)]; |
165 |
|
|
tmp[x] = COMPOSE_FIDELITYiH0(v[0], v[1], v[2], v[3], b[x+w2], v[4], v[5], v[6], v[7]); |
166 |
|
|
} |
167 |
|
|
|
168 |
|
|
for (x = 0; x < w2; x++) { |
169 |
|
|
for (i = 0; i < 8; i++) |
170 |
|
|
v[i] = tmp[av_clip(x-4+i, 0, w2-1)]; |
171 |
|
|
tmp[x+w2] = COMPOSE_FIDELITYiL0(v[0], v[1], v[2], v[3], b[x], v[4], v[5], v[6], v[7]); |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
RENAME(interleave)(b, tmp+w2, tmp, w2, 0, 0); |
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
static void RENAME(horizontal_compose_daub97i)(uint8_t *_b, uint8_t *_temp, int w) |
178 |
|
|
{ |
179 |
|
|
const int w2 = w >> 1; |
180 |
|
|
int x, b0, b1, b2; |
181 |
|
|
TYPE *b = (TYPE *)_b; |
182 |
|
|
TYPE *temp = (TYPE *)_temp; |
183 |
|
|
|
184 |
|
|
temp[0] = COMPOSE_DAUB97iL1(b[w2], b[0], b[w2]); |
185 |
|
|
for (x = 1; x < w2; x++) { |
186 |
|
|
temp[x ] = COMPOSE_DAUB97iL1(b[x+w2-1], b[x ], b[x+w2]); |
187 |
|
|
temp[x+w2-1] = COMPOSE_DAUB97iH1(temp[x-1], b[x+w2-1], temp[x]); |
188 |
|
|
} |
189 |
|
|
temp[w-1] = COMPOSE_DAUB97iH1(temp[w2-1], b[w-1], temp[w2-1]); |
190 |
|
|
|
191 |
|
|
// second stage combined with interleave and shift |
192 |
|
|
b0 = b2 = COMPOSE_DAUB97iL0(temp[w2], temp[0], temp[w2]); |
193 |
|
|
b[0] = ~((~b0) >> 1); |
194 |
|
|
for (x = 1; x < w2; x++) { |
195 |
|
|
b2 = COMPOSE_DAUB97iL0(temp[x+w2-1], temp[x ], temp[x+w2]); |
196 |
|
|
b1 = COMPOSE_DAUB97iH0( b0, temp[x+w2-1], b2 ); |
197 |
|
|
b[2*x-1] = ~((~b1) >> 1); |
198 |
|
|
b[2*x ] = ~((~b2) >> 1); |
199 |
|
|
b0 = b2; |
200 |
|
|
} |
201 |
|
|
b[w-1] = ~((~COMPOSE_DAUB97iH0(b2, temp[w-1], b2)) >> 1); |
202 |
|
|
} |
203 |
|
|
|
204 |
|
29160 |
static void RENAME(vertical_compose_dirac53iH0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2, |
205 |
|
|
int width) |
206 |
|
|
{ |
207 |
|
|
int i; |
208 |
|
29160 |
TYPE *b0 = (TYPE *)_b0; |
209 |
|
29160 |
TYPE *b1 = (TYPE *)_b1; |
210 |
|
29160 |
TYPE *b2 = (TYPE *)_b2; |
211 |
✓✓ |
4876200 |
for(i=0; i<width; i++){ |
212 |
|
4847040 |
b1[i] = COMPOSE_DIRAC53iH0(b0[i], b1[i], b2[i]); |
213 |
|
|
} |
214 |
|
|
} |
215 |
|
|
|
216 |
|
285360 |
static void RENAME(vertical_compose_dd97iH0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2, |
217 |
|
|
uint8_t *_b3, uint8_t *_b4, int width) |
218 |
|
|
{ |
219 |
|
|
int i; |
220 |
|
285360 |
TYPE *b0 = (TYPE *)_b0; |
221 |
|
285360 |
TYPE *b1 = (TYPE *)_b1; |
222 |
|
285360 |
TYPE *b2 = (TYPE *)_b2; |
223 |
|
285360 |
TYPE *b3 = (TYPE *)_b3; |
224 |
|
285360 |
TYPE *b4 = (TYPE *)_b4; |
225 |
✓✓ |
56918400 |
for(i=0; i<width; i++){ |
226 |
|
56633040 |
b2[i] = COMPOSE_DD97iH0(b0[i], b1[i], b2[i], b3[i], b4[i]); |
227 |
|
|
} |
228 |
|
285360 |
} |
229 |
|
|
|
230 |
|
|
static void RENAME(vertical_compose_dd137iL0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2, |
231 |
|
|
uint8_t *_b3, uint8_t *_b4, int width) |
232 |
|
|
{ |
233 |
|
|
int i; |
234 |
|
|
TYPE *b0 = (TYPE *)_b0; |
235 |
|
|
TYPE *b1 = (TYPE *)_b1; |
236 |
|
|
TYPE *b2 = (TYPE *)_b2; |
237 |
|
|
TYPE *b3 = (TYPE *)_b3; |
238 |
|
|
TYPE *b4 = (TYPE *)_b4; |
239 |
|
|
for(i=0; i<width; i++){ |
240 |
|
|
b2[i] = COMPOSE_DD137iL0(b0[i], b1[i], b2[i], b3[i], b4[i]); |
241 |
|
|
} |
242 |
|
|
} |
243 |
|
|
|
244 |
|
29160 |
static void RENAME(vertical_compose_haar)(uint8_t *_b0, uint8_t *_b1, int width) |
245 |
|
|
{ |
246 |
|
|
int i; |
247 |
|
29160 |
TYPE *b0 = (TYPE *)_b0; |
248 |
|
29160 |
TYPE *b1 = (TYPE *)_b1; |
249 |
|
|
|
250 |
✓✓ |
4876200 |
for (i = 0; i < width; i++) { |
251 |
|
4847040 |
b0[i] = COMPOSE_HAARiL0(b0[i], b1[i]); |
252 |
|
4847040 |
b1[i] = COMPOSE_HAARiH0(b1[i], b0[i]); |
253 |
|
|
} |
254 |
|
|
} |
255 |
|
|
|
256 |
|
|
static void RENAME(vertical_compose_fidelityiH0)(uint8_t *_dst, uint8_t *_b[8], int width) |
257 |
|
|
{ |
258 |
|
|
int i; |
259 |
|
|
TYPE *dst = (TYPE *)_dst; |
260 |
|
|
TYPE *b0 = (TYPE *)_b[0]; |
261 |
|
|
TYPE *b1 = (TYPE *)_b[1]; |
262 |
|
|
TYPE *b2 = (TYPE *)_b[2]; |
263 |
|
|
TYPE *b3 = (TYPE *)_b[3]; |
264 |
|
|
TYPE *b4 = (TYPE *)_b[4]; |
265 |
|
|
TYPE *b5 = (TYPE *)_b[5]; |
266 |
|
|
TYPE *b6 = (TYPE *)_b[6]; |
267 |
|
|
TYPE *b7 = (TYPE *)_b[7]; |
268 |
|
|
for(i=0; i<width; i++){ |
269 |
|
|
dst[i] = COMPOSE_FIDELITYiH0(b0[i], b1[i], b2[i], b3[i], dst[i], b4[i], b5[i], b6[i], b7[i]); |
270 |
|
|
} |
271 |
|
|
} |
272 |
|
|
|
273 |
|
|
static void RENAME(vertical_compose_fidelityiL0)(uint8_t *_dst, uint8_t *_b[8], int width) |
274 |
|
|
{ |
275 |
|
|
int i; |
276 |
|
|
TYPE *dst = (TYPE *)_dst; |
277 |
|
|
TYPE *b0 = (TYPE *)_b[0]; |
278 |
|
|
TYPE *b1 = (TYPE *)_b[1]; |
279 |
|
|
TYPE *b2 = (TYPE *)_b[2]; |
280 |
|
|
TYPE *b3 = (TYPE *)_b[3]; |
281 |
|
|
TYPE *b4 = (TYPE *)_b[4]; |
282 |
|
|
TYPE *b5 = (TYPE *)_b[5]; |
283 |
|
|
TYPE *b6 = (TYPE *)_b[6]; |
284 |
|
|
TYPE *b7 = (TYPE *)_b[7]; |
285 |
|
|
|
286 |
|
|
for(i=0; i<width; i++){ |
287 |
|
|
dst[i] = COMPOSE_FIDELITYiL0(b0[i], b1[i], b2[i], b3[i], dst[i], b4[i], b5[i], b6[i], b7[i]); |
288 |
|
|
} |
289 |
|
|
} |
290 |
|
|
|
291 |
|
|
static void RENAME(vertical_compose_daub97iH0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2, int width) |
292 |
|
|
{ |
293 |
|
|
int i; |
294 |
|
|
TYPE *b0 = (TYPE *)_b0; |
295 |
|
|
TYPE *b1 = (TYPE *)_b1; |
296 |
|
|
TYPE *b2 = (TYPE *)_b2; |
297 |
|
|
|
298 |
|
|
for(i=0; i<width; i++){ |
299 |
|
|
b1[i] = COMPOSE_DAUB97iH0(b0[i], b1[i], b2[i]); |
300 |
|
|
} |
301 |
|
|
} |
302 |
|
|
|
303 |
|
|
static void RENAME(vertical_compose_daub97iH1)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2, int width) |
304 |
|
|
{ |
305 |
|
|
int i; |
306 |
|
|
TYPE *b0 = (TYPE *)_b0; |
307 |
|
|
TYPE *b1 = (TYPE *)_b1; |
308 |
|
|
TYPE *b2 = (TYPE *)_b2; |
309 |
|
|
|
310 |
|
|
for(i=0; i<width; i++){ |
311 |
|
|
b1[i] = COMPOSE_DAUB97iH1(b0[i], b1[i], b2[i]); |
312 |
|
|
} |
313 |
|
|
} |
314 |
|
|
|
315 |
|
|
static void RENAME(vertical_compose_daub97iL0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2, int width) |
316 |
|
|
{ |
317 |
|
|
int i; |
318 |
|
|
TYPE *b0 = (TYPE *)_b0; |
319 |
|
|
TYPE *b1 = (TYPE *)_b1; |
320 |
|
|
TYPE *b2 = (TYPE *)_b2; |
321 |
|
|
|
322 |
|
|
for(i=0; i<width; i++){ |
323 |
|
|
b1[i] = COMPOSE_DAUB97iL0(b0[i], b1[i], b2[i]); |
324 |
|
|
} |
325 |
|
|
} |
326 |
|
|
|
327 |
|
|
static void RENAME(vertical_compose_daub97iL1)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2, int width) |
328 |
|
|
{ |
329 |
|
|
int i; |
330 |
|
|
TYPE *b0 = (TYPE *)_b0; |
331 |
|
|
TYPE *b1 = (TYPE *)_b1; |
332 |
|
|
TYPE *b2 = (TYPE *)_b2; |
333 |
|
|
|
334 |
|
|
for(i=0; i<width; i++){ |
335 |
|
|
b1[i] = COMPOSE_DAUB97iL1(b0[i], b1[i], b2[i]); |
336 |
|
|
} |
337 |
|
|
} |
338 |
|
|
|
339 |
|
300372 |
static void RENAME(spatial_compose_dd97i_dy)(DWTContext *d, int level, int width, int height, int stride) |
340 |
|
|
{ |
341 |
|
300372 |
vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0; |
342 |
|
300372 |
vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0; |
343 |
|
300372 |
DWTCompose *cs = d->cs + level; |
344 |
|
|
|
345 |
|
300372 |
int i, y = cs->y; |
346 |
|
|
uint8_t *b[8]; |
347 |
✓✓ |
2102604 |
for (i = 0; i < 6; i++) |
348 |
|
1802232 |
b[i] = cs->b[i]; |
349 |
|
300372 |
b[6] = d->buffer + av_clip(y+5, 0, height-2)*stride; |
350 |
|
300372 |
b[7] = d->buffer + av_clip(y+6, 1, height-1)*stride; |
351 |
|
|
|
352 |
✓✓ |
300372 |
if(y+5<(unsigned)height) vertical_compose_l0( b[5], b[6], b[7], width); |
353 |
✓✓ |
300372 |
if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width); |
354 |
|
|
|
355 |
✓✓ |
300372 |
if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width); |
356 |
✓✓ |
300372 |
if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width); |
357 |
|
|
|
358 |
✓✓ |
2102604 |
for (i = 0; i < 6; i++) |
359 |
|
1802232 |
cs->b[i] = b[i+2]; |
360 |
|
300372 |
cs->y += 2; |
361 |
|
300372 |
} |
362 |
|
|
|
363 |
|
29592 |
static void RENAME(spatial_compose_dirac53i_dy)(DWTContext *d, int level, int width, int height, int stride) |
364 |
|
|
{ |
365 |
|
29592 |
vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0; |
366 |
|
29592 |
vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0; |
367 |
|
29592 |
DWTCompose *cs = d->cs + level; |
368 |
|
|
|
369 |
|
29592 |
int y= cs->y; |
370 |
|
29592 |
uint8_t *b[4] = { cs->b[0], cs->b[1] }; |
371 |
|
29592 |
b[2] = d->buffer + avpriv_mirror(y+1, height-1)*stride; |
372 |
|
29592 |
b[3] = d->buffer + avpriv_mirror(y+2, height-1)*stride; |
373 |
|
|
|
374 |
✓✓ |
29592 |
if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width); |
375 |
✓✓ |
29592 |
if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width); |
376 |
|
|
|
377 |
✓✓ |
29592 |
if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width); |
378 |
✓✓ |
29592 |
if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width); |
379 |
|
|
|
380 |
|
29592 |
cs->b[0] = b[2]; |
381 |
|
29592 |
cs->b[1] = b[3]; |
382 |
|
29592 |
cs->y += 2; |
383 |
|
|
} |
384 |
|
|
|
385 |
|
|
static void RENAME(spatial_compose_dd137i_dy)(DWTContext *d, int level, int width, int height, int stride) |
386 |
|
|
{ |
387 |
|
|
vertical_compose_5tap vertical_compose_l0 = (void*)d->vertical_compose_l0; |
388 |
|
|
vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0; |
389 |
|
|
DWTCompose *cs = d->cs + level; |
390 |
|
|
|
391 |
|
|
int i, y = cs->y; |
392 |
|
|
uint8_t *b[10]; |
393 |
|
|
for (i = 0; i < 8; i++) |
394 |
|
|
b[i] = cs->b[i]; |
395 |
|
|
b[8] = d->buffer + av_clip(y+7, 0, height-2)*stride; |
396 |
|
|
b[9] = d->buffer + av_clip(y+8, 1, height-1)*stride; |
397 |
|
|
|
398 |
|
|
if(y+5<(unsigned)height) vertical_compose_l0(b[3], b[5], b[6], b[7], b[9], width); |
399 |
|
|
if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width); |
400 |
|
|
|
401 |
|
|
if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width); |
402 |
|
|
if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width); |
403 |
|
|
|
404 |
|
|
for (i = 0; i < 8; i++) |
405 |
|
|
cs->b[i] = b[i+2]; |
406 |
|
|
cs->y += 2; |
407 |
|
|
} |
408 |
|
|
|
409 |
|
|
// haar makes the assumption that height is even (always true for dirac) |
410 |
|
29160 |
static void RENAME(spatial_compose_haari_dy)(DWTContext *d, int level, int width, int height, int stride) |
411 |
|
|
{ |
412 |
|
29160 |
vertical_compose_2tap vertical_compose = (void*)d->vertical_compose; |
413 |
|
29160 |
int y = d->cs[level].y; |
414 |
|
29160 |
uint8_t *b0 = d->buffer + (y-1)*stride; |
415 |
|
29160 |
uint8_t *b1 = d->buffer + (y )*stride; |
416 |
|
|
|
417 |
|
29160 |
vertical_compose(b0, b1, width); |
418 |
|
29160 |
d->horizontal_compose(b0, d->temp, width); |
419 |
|
29160 |
d->horizontal_compose(b1, d->temp, width); |
420 |
|
|
|
421 |
|
29160 |
d->cs[level].y += 2; |
422 |
|
|
} |
423 |
|
|
|
424 |
|
|
// Don't do sliced idwt for fidelity; the 9 tap filter makes it a bit annoying |
425 |
|
|
// Fortunately, this filter isn't used in practice. |
426 |
|
|
static void RENAME(spatial_compose_fidelity)(DWTContext *d, int level, int width, int height, int stride) |
427 |
|
|
{ |
428 |
|
|
vertical_compose_9tap vertical_compose_l0 = (void*)d->vertical_compose_l0; |
429 |
|
|
vertical_compose_9tap vertical_compose_h0 = (void*)d->vertical_compose_h0; |
430 |
|
|
int i, y; |
431 |
|
|
uint8_t *b[8]; |
432 |
|
|
|
433 |
|
|
for (y = 1; y < height; y += 2) { |
434 |
|
|
for (i = 0; i < 8; i++) |
435 |
|
|
b[i] = d->buffer + av_clip((y-7 + 2*i), 0, height-2)*stride; |
436 |
|
|
vertical_compose_h0(d->buffer + y*stride, b, width); |
437 |
|
|
} |
438 |
|
|
|
439 |
|
|
for (y = 0; y < height; y += 2) { |
440 |
|
|
for (i = 0; i < 8; i++) |
441 |
|
|
b[i] = d->buffer + av_clip((y-7 + 2*i), 1, height-1)*stride; |
442 |
|
|
vertical_compose_l0(d->buffer + y*stride, b, width); |
443 |
|
|
} |
444 |
|
|
|
445 |
|
|
for (y = 0; y < height; y++) |
446 |
|
|
d->horizontal_compose(d->buffer + y*stride, d->temp, width); |
447 |
|
|
|
448 |
|
|
d->cs[level].y = height+1; |
449 |
|
|
} |
450 |
|
|
|
451 |
|
|
static void RENAME(spatial_compose_daub97i_dy)(DWTContext *d, int level, int width, int height, int stride) |
452 |
|
|
{ |
453 |
|
|
vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0; |
454 |
|
|
vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0; |
455 |
|
|
vertical_compose_3tap vertical_compose_l1 = (void*)d->vertical_compose_l1; |
456 |
|
|
vertical_compose_3tap vertical_compose_h1 = (void*)d->vertical_compose_h1; |
457 |
|
|
DWTCompose *cs = d->cs + level; |
458 |
|
|
|
459 |
|
|
int i, y = cs->y; |
460 |
|
|
uint8_t *b[6]; |
461 |
|
|
for (i = 0; i < 4; i++) |
462 |
|
|
b[i] = cs->b[i]; |
463 |
|
|
b[4] = d->buffer + avpriv_mirror(y+3, height-1)*stride; |
464 |
|
|
b[5] = d->buffer + avpriv_mirror(y+4, height-1)*stride; |
465 |
|
|
|
466 |
|
|
if(y+3<(unsigned)height) vertical_compose_l1(b[3], b[4], b[5], width); |
467 |
|
|
if(y+2<(unsigned)height) vertical_compose_h1(b[2], b[3], b[4], width); |
468 |
|
|
if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width); |
469 |
|
|
if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width); |
470 |
|
|
|
471 |
|
|
if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width); |
472 |
|
|
if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width); |
473 |
|
|
|
474 |
|
|
for (i = 0; i < 4; i++) |
475 |
|
|
cs->b[i] = b[i+2]; |
476 |
|
|
cs->y += 2; |
477 |
|
|
} |
478 |
|
|
|
479 |
|
|
static void RENAME(spatial_compose97i_init)(DWTCompose *cs, uint8_t *buffer, int height, int stride) |
480 |
|
|
{ |
481 |
|
|
cs->b[0] = buffer + avpriv_mirror(-3-1, height-1)*stride; |
482 |
|
|
cs->b[1] = buffer + avpriv_mirror(-3 , height-1)*stride; |
483 |
|
|
cs->b[2] = buffer + avpriv_mirror(-3+1, height-1)*stride; |
484 |
|
|
cs->b[3] = buffer + avpriv_mirror(-3+2, height-1)*stride; |
485 |
|
|
cs->y = -3; |
486 |
|
|
} |
487 |
|
|
|
488 |
|
432 |
static void RENAME(spatial_compose53i_init)(DWTCompose *cs, uint8_t *buffer, int height, int stride) |
489 |
|
|
{ |
490 |
|
432 |
cs->b[0] = buffer + avpriv_mirror(-1-1, height-1)*stride; |
491 |
|
432 |
cs->b[1] = buffer + avpriv_mirror(-1 , height-1)*stride; |
492 |
|
432 |
cs->y = -1; |
493 |
|
|
} |
494 |
|
|
|
495 |
|
5004 |
static void RENAME(spatial_compose_dd97i_init)(DWTCompose *cs, uint8_t *buffer, int height, int stride) |
496 |
|
|
{ |
497 |
|
5004 |
cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride; |
498 |
|
5004 |
cs->b[1] = buffer + av_clip(-5 , 1, height-1)*stride; |
499 |
|
5004 |
cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride; |
500 |
|
5004 |
cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride; |
501 |
|
5004 |
cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride; |
502 |
|
5004 |
cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride; |
503 |
|
5004 |
cs->y = -5; |
504 |
|
5004 |
} |
505 |
|
|
|
506 |
|
|
static void RENAME(spatial_compose_dd137i_init)(DWTCompose *cs, uint8_t *buffer, int height, int stride) |
507 |
|
|
{ |
508 |
|
|
cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride; |
509 |
|
|
cs->b[1] = buffer + av_clip(-5 , 1, height-1)*stride; |
510 |
|
|
cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride; |
511 |
|
|
cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride; |
512 |
|
|
cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride; |
513 |
|
|
cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride; |
514 |
|
|
cs->b[6] = buffer + av_clip(-5+5, 0, height-2)*stride; |
515 |
|
|
cs->b[7] = buffer + av_clip(-5+6, 1, height-1)*stride; |
516 |
|
|
cs->y = -5; |
517 |
|
|
} |
518 |
|
|
|
519 |
|
780 |
static int RENAME(ff_spatial_idwt_init)(DWTContext *d, enum dwt_type type) |
520 |
|
|
{ |
521 |
|
|
int level; |
522 |
|
|
|
523 |
|
780 |
d->temp = (uint8_t *)(((TYPE *)d->temp) + 8); |
524 |
|
|
|
525 |
|
3714 |
for (level = d->decomposition_count - 1; level >= 0; level--){ |
526 |
|
2934 |
int hl = d->height >> level; |
527 |
|
2934 |
int stride_l = d->stride << level; |
528 |
|
|
|
529 |
|
2934 |
switch(type){ |
530 |
|
2502 |
case DWT_DIRAC_DD9_7: |
531 |
|
2502 |
RENAME(spatial_compose_dd97i_init)(d->cs+level, d->buffer, hl, stride_l); |
532 |
|
2502 |
break; |
533 |
|
216 |
case DWT_DIRAC_LEGALL5_3: |
534 |
|
216 |
RENAME(spatial_compose53i_init)(d->cs+level, d->buffer, hl, stride_l); |
535 |
|
216 |
break; |
536 |
|
|
case DWT_DIRAC_DD13_7: |
537 |
|
|
RENAME(spatial_compose_dd137i_init)(d->cs+level, d->buffer, hl, stride_l); |
538 |
|
|
break; |
539 |
|
216 |
case DWT_DIRAC_HAAR0: |
540 |
|
|
case DWT_DIRAC_HAAR1: |
541 |
|
216 |
d->cs[level].y = 1; |
542 |
|
216 |
break; |
543 |
|
|
case DWT_DIRAC_DAUB9_7: |
544 |
|
|
RENAME(spatial_compose97i_init)(d->cs+level, d->buffer, hl, stride_l); |
545 |
|
|
break; |
546 |
|
|
default: |
547 |
|
|
d->cs[level].y = 0; |
548 |
|
|
break; |
549 |
|
|
} |
550 |
|
|
} |
551 |
|
|
|
552 |
|
780 |
switch (type) { |
553 |
|
672 |
case DWT_DIRAC_DD9_7: |
554 |
|
672 |
d->spatial_compose = RENAME(spatial_compose_dd97i_dy); |
555 |
|
672 |
d->vertical_compose_l0 = (void*)RENAME(vertical_compose53iL0); |
556 |
|
672 |
d->vertical_compose_h0 = (void*)RENAME(vertical_compose_dd97iH0); |
557 |
|
672 |
d->horizontal_compose = RENAME(horizontal_compose_dd97i); |
558 |
|
672 |
d->support = 7; |
559 |
|
672 |
break; |
560 |
|
54 |
case DWT_DIRAC_LEGALL5_3: |
561 |
|
54 |
d->spatial_compose = RENAME(spatial_compose_dirac53i_dy); |
562 |
|
54 |
d->vertical_compose_l0 = (void*)RENAME(vertical_compose53iL0); |
563 |
|
54 |
d->vertical_compose_h0 = (void*)RENAME(vertical_compose_dirac53iH0); |
564 |
|
54 |
d->horizontal_compose = RENAME(horizontal_compose_dirac53i); |
565 |
|
54 |
d->support = 3; |
566 |
|
54 |
break; |
567 |
|
|
case DWT_DIRAC_DD13_7: |
568 |
|
|
d->spatial_compose = RENAME(spatial_compose_dd137i_dy); |
569 |
|
|
d->vertical_compose_l0 = (void*)RENAME(vertical_compose_dd137iL0); |
570 |
|
|
d->vertical_compose_h0 = (void*)RENAME(vertical_compose_dd97iH0); |
571 |
|
|
d->horizontal_compose = RENAME(horizontal_compose_dd137i); |
572 |
|
|
d->support = 7; |
573 |
|
|
break; |
574 |
|
54 |
case DWT_DIRAC_HAAR0: |
575 |
|
|
case DWT_DIRAC_HAAR1: |
576 |
|
54 |
d->spatial_compose = RENAME(spatial_compose_haari_dy); |
577 |
|
54 |
d->vertical_compose = (void*)RENAME(vertical_compose_haar); |
578 |
|
54 |
if (type == DWT_DIRAC_HAAR0) |
579 |
|
|
d->horizontal_compose = RENAME(horizontal_compose_haar0i); |
580 |
|
|
else |
581 |
|
54 |
d->horizontal_compose = RENAME(horizontal_compose_haar1i); |
582 |
|
54 |
d->support = 1; |
583 |
|
54 |
break; |
584 |
|
|
case DWT_DIRAC_FIDELITY: |
585 |
|
|
d->spatial_compose = RENAME(spatial_compose_fidelity); |
586 |
|
|
d->vertical_compose_l0 = (void*)RENAME(vertical_compose_fidelityiL0); |
587 |
|
|
d->vertical_compose_h0 = (void*)RENAME(vertical_compose_fidelityiH0); |
588 |
|
|
d->horizontal_compose = RENAME(horizontal_compose_fidelityi); |
589 |
|
|
d->support = 0; // not really used |
590 |
|
|
break; |
591 |
|
|
case DWT_DIRAC_DAUB9_7: |
592 |
|
|
d->spatial_compose = RENAME(spatial_compose_daub97i_dy); |
593 |
|
|
d->vertical_compose_l0 = (void*)RENAME(vertical_compose_daub97iL0); |
594 |
|
|
d->vertical_compose_h0 = (void*)RENAME(vertical_compose_daub97iH0); |
595 |
|
|
d->vertical_compose_l1 = (void*)RENAME(vertical_compose_daub97iL1); |
596 |
|
|
d->vertical_compose_h1 = (void*)RENAME(vertical_compose_daub97iH1); |
597 |
|
|
d->horizontal_compose = RENAME(horizontal_compose_daub97i); |
598 |
|
|
d->support = 5; |
599 |
|
|
break; |
600 |
|
|
default: |
601 |
|
|
return AVERROR_INVALIDDATA; |
602 |
|
|
} |
603 |
|
|
|
604 |
|
780 |
return 0; |
605 |
|
|
} |
606 |
|
|
|
607 |
|
|
#undef RENAME |
608 |
|
|
#undef TYPE |