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
46 {
52 b1[
i] -= (
unsigned)((int)(
b0[
i] + (
unsigned)
b2[
i] + 2) >> 2);
53 }
54
57 {
59 for (
i = 0;
i < w2;
i++) {
62 }
63 }
64
65 static void RENAME(horizontal_compose_dirac53i)(uint8_t *_b, uint8_t *_temp,
int w)
66 {
67 int x;
68 const int w2 =
w >> 1;
71
73 for (x = 1; x < w2; x++) {
76 }
78
80 }
81
82 static void RENAME(horizontal_compose_dd97i)(uint8_t *_b, uint8_t *_tmp,
int w)
83 {
84 int x;
85 const int w2 =
w >> 1;
88
90 for (x = 1; x < w2; x++)
92
93 // extend the edges
96
97 for (x = 0; x < w2; x++) {
98 b[2*x ] = ((int)(
tmp[x] + 1
U))>>1;
100 }
101 }
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;
109
112 for (x = 2; x < w2-1; x++)
115
116 // extend the edges
119
120 for (x = 0; x < w2; x++) {
121 b[2*x ] = ((int)(
tmp[x] + 1
U))>>1;
123 }
124 }
125
128 {
129 const int w2 =
w >> 1;
130 int x;
131
132 for (x = 0; x < w2; x++) {
135 }
136
138 }
139
140 static void RENAME(horizontal_compose_haar0i)(uint8_t *_b, uint8_t *_temp,
int w)
141 {
145 }
146
147 static void RENAME(horizontal_compose_haar1i)(uint8_t *_b, uint8_t *_temp,
int w)
148 {
152 }
153
154 static void RENAME(horizontal_compose_fidelityi)(uint8_t *_b, uint8_t *_tmp,
int w)
155 {
156 const int w2 =
w >> 1;
161
162 for (x = 0; x < w2; x++) {
163 for (
i = 0;
i < 8;
i++)
166 }
167
168 for (x = 0; x < w2; x++) {
169 for (
i = 0;
i < 8;
i++)
172 }
173
175 }
176
177 static void RENAME(horizontal_compose_daub97i)(uint8_t *_b, uint8_t *_temp,
int w)
178 {
179 const int w2 =
w >> 1;
183
185 for (x = 1; x < w2; x++) {
188 }
190
191 // second stage combined with interleave and shift
193 b[0] = ~((~
b0) >> 1);
194 for (x = 1; x < w2; x++) {
197 b[2*x-1] = ~((~
b1) >> 1);
198 b[2*x ] = ~((~
b2) >> 1);
200 }
202 }
203
204 static void RENAME(vertical_compose_dirac53iH0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2,
206 {
213 }
214 }
215
216 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 {
227 }
228 }
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 {
241 }
242 }
243
244 static void RENAME(vertical_compose_haar)(uint8_t *_b0, uint8_t *_b1,
int width)
245 {
249
253 }
254 }
255
256 static void RENAME(vertical_compose_fidelityiH0)(uint8_t *
_dst, uint8_t *_b[8],
int width)
257 {
270 }
271 }
272
273 static void RENAME(vertical_compose_fidelityiL0)(uint8_t *
_dst, uint8_t *_b[8],
int width)
274 {
285
288 }
289 }
290
291 static void RENAME(vertical_compose_daub97iH0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2,
int width)
292 {
297
300 }
301 }
302
303 static void RENAME(vertical_compose_daub97iH1)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2,
int width)
304 {
309
312 }
313 }
314
315 static void RENAME(vertical_compose_daub97iL0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2,
int width)
316 {
321
324 }
325 }
326
327 static void RENAME(vertical_compose_daub97iL1)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2,
int width)
328 {
333
336 }
337 }
338
340 {
344
347 for (
i = 0;
i < 6;
i++)
351
352 if(y+5<(
unsigned)
height) vertical_compose_l0(
b[5],
b[6],
b[7],
width);
353 if(y+1<(
unsigned)
height) vertical_compose_h0(
b[0],
b[2],
b[3],
b[4],
b[6],
width);
354
355 if(y-1<(
unsigned)
height) d->horizontal_compose(
b[0], d->temp,
width);
356 if(y+0<(
unsigned)
height) d->horizontal_compose(
b[1], d->temp,
width);
357
358 for (
i = 0;
i < 6;
i++)
361 }
362
364 {
368
370 uint8_t *
b[4] = { cs->
b[0], cs->
b[1] };
373
374 if(y+1<(
unsigned)
height) vertical_compose_l0(
b[1],
b[2],
b[3],
width);
375 if(y+0<(
unsigned)
height) vertical_compose_h0(
b[0],
b[1],
b[2],
width);
376
377 if(y-1<(
unsigned)
height) d->horizontal_compose(
b[0], d->temp,
width);
378 if(y+0<(
unsigned)
height) d->horizontal_compose(
b[1], d->temp,
width);
379
383 }
384
386 {
390
393 for (
i = 0;
i < 8;
i++)
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++)
407 }
408
409 // haar makes the assumption that height is even (always true for dirac)
411 {
413 int y = d->cs[
level].y;
414 uint8_t *
b0 = d->buffer + (y-1)*
stride;
415 uint8_t *
b1 = d->buffer + (y )*
stride;
416
418 d->horizontal_compose(
b0, d->temp,
width);
419 d->horizontal_compose(
b1, d->temp,
width);
420
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.
427 {
432
433 for (y = 1; y <
height; y += 2) {
434 for (
i = 0;
i < 8;
i++)
437 }
438
439 for (y = 0; y <
height; y += 2) {
440 for (
i = 0;
i < 8;
i++)
443 }
444
445 for (y = 0; y <
height; y++)
446 d->horizontal_compose(d->buffer + y*
stride, d->temp,
width);
447
449 }
450
452 {
458
461 for (
i = 0;
i < 4;
i++)
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++)
477 }
478
480 {
485 cs->y = -3;
486 }
487
489 {
492 cs->y = -1;
493 }
494
496 {
503 cs->y = -5;
504 }
505
507 {
516 cs->y = -5;
517 }
518
520 {
522
523 d->temp = (uint8_t *)(((
TYPE *)d->temp) + 8);
524
526 int hl = d->height >>
level;
527 int stride_l = d->stride <<
level;
528
531 RENAME(spatial_compose_dd97i_init)(d->cs+
level, d->buffer, hl, stride_l);
532 break;
535 break;
537 RENAME(spatial_compose_dd137i_init)(d->cs+
level, d->buffer, hl, stride_l);
538 break;
542 break;
545 break;
546 default:
548 break;
549 }
550 }
551
554 d->spatial_compose =
RENAME(spatial_compose_dd97i_dy);
556 d->vertical_compose_h0.tap5 =
RENAME(vertical_compose_dd97iH0);
557 d->horizontal_compose =
RENAME(horizontal_compose_dd97i);
558 d->support = 7;
559 break;
561 d->spatial_compose =
RENAME(spatial_compose_dirac53i_dy);
563 d->vertical_compose_h0.tap3 =
RENAME(vertical_compose_dirac53iH0);
564 d->horizontal_compose =
RENAME(horizontal_compose_dirac53i);
565 d->support = 3;
566 break;
568 d->spatial_compose =
RENAME(spatial_compose_dd137i_dy);
569 d->vertical_compose_l0.tap5 =
RENAME(vertical_compose_dd137iL0);
570 d->vertical_compose_h0.tap5 =
RENAME(vertical_compose_dd97iH0);
571 d->horizontal_compose =
RENAME(horizontal_compose_dd137i);
572 d->support = 7;
573 break;
576 d->spatial_compose =
RENAME(spatial_compose_haari_dy);
577 d->vertical_compose =
RENAME(vertical_compose_haar);
579 d->horizontal_compose =
RENAME(horizontal_compose_haar0i);
580 else
581 d->horizontal_compose =
RENAME(horizontal_compose_haar1i);
582 d->support = 1;
583 break;
585 d->spatial_compose =
RENAME(spatial_compose_fidelity);
586 d->vertical_compose_l0.tap9 =
RENAME(vertical_compose_fidelityiL0);
587 d->vertical_compose_h0.tap9 =
RENAME(vertical_compose_fidelityiH0);
588 d->horizontal_compose =
RENAME(horizontal_compose_fidelityi);
589 d->support = 0; // not really used
590 break;
592 d->spatial_compose =
RENAME(spatial_compose_daub97i_dy);
593 d->vertical_compose_l0.tap3 =
RENAME(vertical_compose_daub97iL0);
594 d->vertical_compose_h0.tap3 =
RENAME(vertical_compose_daub97iH0);
595 d->vertical_compose_l1 =
RENAME(vertical_compose_daub97iL1);
596 d->vertical_compose_h1 =
RENAME(vertical_compose_daub97iH1);
597 d->horizontal_compose =
RENAME(horizontal_compose_daub97i);
598 d->support = 5;
599 break;
600 default:
602 }
603
604 return 0;
605 }
606
607 #undef RENAME
608 #undef TYPE