2 * Copyright (C) 2004-2010 Michael Niedermayer <michaelni@gmx.at>
3 * Copyright (C) 2008 David Conrad
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/attributes.h"
25 #include "libavcodec/x86/dwt.h"
27 int ff_slice_buffer_init(slice_buffer *buf, int line_count,
28 int max_allocated_lines, int line_width,
29 IDWTELEM *base_buffer)
33 buf->base_buffer = base_buffer;
34 buf->line_count = line_count;
35 buf->line_width = line_width;
36 buf->data_count = max_allocated_lines;
37 buf->line = av_mallocz(sizeof(IDWTELEM *) * line_count);
39 return AVERROR(ENOMEM);
40 buf->data_stack = av_malloc(sizeof(IDWTELEM *) * max_allocated_lines);
41 if (!buf->data_stack) {
43 return AVERROR(ENOMEM);
46 for (i = 0; i < max_allocated_lines; i++) {
47 buf->data_stack[i] = av_malloc(sizeof(IDWTELEM) * line_width);
48 if (!buf->data_stack[i]) {
50 av_freep(&buf->data_stack[i]);
51 av_freep(&buf->data_stack);
53 return AVERROR(ENOMEM);
57 buf->data_stack_top = max_allocated_lines - 1;
61 IDWTELEM *ff_slice_buffer_load_line(slice_buffer *buf, int line)
65 assert(buf->data_stack_top >= 0);
66 // assert(!buf->line[line]);
68 return buf->line[line];
70 buffer = buf->data_stack[buf->data_stack_top];
71 buf->data_stack_top--;
72 buf->line[line] = buffer;
77 void ff_slice_buffer_release(slice_buffer *buf, int line)
81 assert(line >= 0 && line < buf->line_count);
82 assert(buf->line[line]);
84 buffer = buf->line[line];
85 buf->data_stack_top++;
86 buf->data_stack[buf->data_stack_top] = buffer;
87 buf->line[line] = NULL;
90 void ff_slice_buffer_flush(slice_buffer *buf)
93 for (i = 0; i < buf->line_count; i++)
95 ff_slice_buffer_release(buf, i);
98 void ff_slice_buffer_destroy(slice_buffer *buf)
101 ff_slice_buffer_flush(buf);
103 for (i = buf->data_count - 1; i >= 0; i--)
104 av_freep(&buf->data_stack[i]);
105 av_freep(&buf->data_stack);
106 av_freep(&buf->line);
109 static inline int mirror(int v, int m)
111 while ((unsigned)v > (unsigned)m) {
119 static av_always_inline void lift(DWTELEM *dst, DWTELEM *src, DWTELEM *ref,
120 int dst_step, int src_step, int ref_step,
121 int width, int mul, int add, int shift,
122 int highpass, int inverse)
124 const int mirror_left = !highpass;
125 const int mirror_right = (width & 1) ^ highpass;
126 const int w = (width >> 1) - 1 + (highpass & width);
129 #define LIFT(src, ref, inv) ((src) + ((inv) ? -(ref) : +(ref)))
131 dst[0] = LIFT(src[0], ((mul * 2 * ref[0] + add) >> shift), inverse);
136 for (i = 0; i < w; i++)
137 dst[i * dst_step] = LIFT(src[i * src_step],
138 ((mul * (ref[i * ref_step] +
139 ref[(i + 1) * ref_step]) +
144 dst[w * dst_step] = LIFT(src[w * src_step],
145 ((mul * 2 * ref[w * ref_step] + add) >> shift),
149 static av_always_inline void inv_lift(IDWTELEM *dst, IDWTELEM *src, IDWTELEM *ref,
150 int dst_step, int src_step, int ref_step,
151 int width, int mul, int add, int shift,
152 int highpass, int inverse)
154 const int mirror_left = !highpass;
155 const int mirror_right = (width & 1) ^ highpass;
156 const int w = (width >> 1) - 1 + (highpass & width);
159 #define LIFT(src, ref, inv) ((src) + ((inv) ? -(ref) : +(ref)))
161 dst[0] = LIFT(src[0], ((mul * 2 * ref[0] + add) >> shift), inverse);
166 for (i = 0; i < w; i++)
167 dst[i * dst_step] = LIFT(src[i * src_step],
168 ((mul * (ref[i * ref_step] +
169 ref[(i + 1) * ref_step]) +
174 dst[w * dst_step] = LIFT(src[w * src_step],
175 ((mul * 2 * ref[w * ref_step] + add) >> shift),
181 static av_always_inline void liftS(DWTELEM *dst, DWTELEM *src, DWTELEM *ref,
182 int dst_step, int src_step, int ref_step,
183 int width, int mul, int add, int shift,
184 int highpass, int inverse)
186 const int mirror_left = !highpass;
187 const int mirror_right = (width & 1) ^ highpass;
188 const int w = (width >> 1) - 1 + (highpass & width);
192 #define LIFTS(src, ref, inv) \
193 ((inv) ? (src) + (((ref) + 4 * (src)) >> shift) \
194 : -((-16 * (src) + (ref) + add / \
195 4 + 1 + (5 << 25)) / (5 * 4) - (1 << 23)))
197 dst[0] = LIFTS(src[0], mul * 2 * ref[0] + add, inverse);
202 for (i = 0; i < w; i++)
203 dst[i * dst_step] = LIFTS(src[i * src_step],
204 mul * (ref[i * ref_step] +
205 ref[(i + 1) * ref_step]) + add,
209 dst[w * dst_step] = LIFTS(src[w * src_step],
210 mul * 2 * ref[w * ref_step] + add,
214 static av_always_inline void inv_liftS(IDWTELEM *dst, IDWTELEM *src,
215 IDWTELEM *ref, int dst_step,
216 int src_step, int ref_step,
217 int width, int mul, int add, int shift,
218 int highpass, int inverse)
220 const int mirror_left = !highpass;
221 const int mirror_right = (width & 1) ^ highpass;
222 const int w = (width >> 1) - 1 + (highpass & width);
226 #define LIFTS(src, ref, inv) \
227 ((inv) ? (src) + (((ref) + 4 * (src)) >> shift) \
228 : -((-16 * (src) + (ref) + add / \
229 4 + 1 + (5 << 25)) / (5 * 4) - (1 << 23)))
231 dst[0] = LIFTS(src[0], mul * 2 * ref[0] + add, inverse);
236 for (i = 0; i < w; i++)
237 dst[i * dst_step] = LIFTS(src[i * src_step],
238 mul * (ref[i * ref_step] +
239 ref[(i + 1) * ref_step]) + add,
243 dst[w * dst_step] = LIFTS(src[w * src_step],
244 mul * 2 * ref[w * ref_step] + add, inverse);
248 static void horizontal_decompose53i(DWTELEM *b, int width)
251 const int width2 = width >> 1;
253 const int w2 = (width + 1) >> 1;
255 for (x = 0; x < width2; x++) {
257 temp[x + w2] = b[2 * x + 1];
266 A1 = temp[0 + width2];
267 A1 -= (A2 + A4) >> 1;
271 for (x = 1; x + 1 < width2; x += 2) {
272 A3 = temp[x + width2];
274 A3 -= (A2 + A4) >> 1;
275 A2 += (A1 + A3 + 2) >> 2;
279 A1 = temp[x + 1 + width2];
281 A1 -= (A2 + A4) >> 1;
282 A4 += (A1 + A3 + 2) >> 2;
283 b[x + 1 + width2] = A1;
286 A3 = temp[width - 1];
288 A2 += (A1 + A3 + 2) >> 2;
293 lift(b + w2, temp + w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0);
294 lift(b, temp, b + w2, 1, 1, 1, width, 1, 2, 2, 0, 0);
298 static void vertical_decompose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
303 for (i = 0; i < width; i++)
304 b1[i] -= (b0[i] + b2[i]) >> 1;
307 static void vertical_decompose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
312 for (i = 0; i < width; i++)
313 b1[i] += (b0[i] + b2[i] + 2) >> 2;
316 static void spatial_decompose53i(DWTELEM *buffer, int width, int height,
320 DWTELEM *b0 = buffer + mirror(-2 - 1, height - 1) * stride;
321 DWTELEM *b1 = buffer + mirror(-2, height - 1) * stride;
323 for (y = -2; y < height; y += 2) {
324 DWTELEM *b2 = buffer + mirror(y + 1, height - 1) * stride;
325 DWTELEM *b3 = buffer + mirror(y + 2, height - 1) * stride;
327 if (y + 1 < (unsigned)height)
328 horizontal_decompose53i(b2, width);
329 if (y + 2 < (unsigned)height)
330 horizontal_decompose53i(b3, width);
332 if (y + 1 < (unsigned)height)
333 vertical_decompose53iH0(b1, b2, b3, width);
334 if (y + 0 < (unsigned)height)
335 vertical_decompose53iL0(b0, b1, b2, width);
342 static void horizontal_decompose97i(DWTELEM *b, int width)
345 const int w2 = (width + 1) >> 1;
347 lift(temp + w2, b + 1, b, 1, 2, 2, width, W_AM, W_AO, W_AS, 1, 1);
348 liftS(temp, b, temp + w2, 1, 2, 1, width, W_BM, W_BO, W_BS, 0, 0);
349 lift(b + w2, temp + w2, temp, 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 0);
350 lift(b, temp, b + w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 0);
353 static void vertical_decompose97iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
358 for (i = 0; i < width; i++)
359 b1[i] -= (W_AM * (b0[i] + b2[i]) + W_AO) >> W_AS;
362 static void vertical_decompose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
367 for (i = 0; i < width; i++)
368 b1[i] += (W_CM * (b0[i] + b2[i]) + W_CO) >> W_CS;
371 static void vertical_decompose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
376 for (i = 0; i < width; i++)
378 b1[i] -= (W_BM * (b0[i] + b2[i]) + W_BO) >> W_BS;
380 b1[i] = (16 * 4 * b1[i] - 4 * (b0[i] + b2[i]) + W_BO * 5 + (5 << 27)) /
381 (5 * 16) - (1 << 23);
385 static void vertical_decompose97iL1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
390 for (i = 0; i < width; i++)
391 b1[i] += (W_DM * (b0[i] + b2[i]) + W_DO) >> W_DS;
394 static void spatial_decompose97i(DWTELEM *buffer, int width, int height,
398 DWTELEM *b0 = buffer + mirror(-4 - 1, height - 1) * stride;
399 DWTELEM *b1 = buffer + mirror(-4, height - 1) * stride;
400 DWTELEM *b2 = buffer + mirror(-4 + 1, height - 1) * stride;
401 DWTELEM *b3 = buffer + mirror(-4 + 2, height - 1) * stride;
403 for (y = -4; y < height; y += 2) {
404 DWTELEM *b4 = buffer + mirror(y + 3, height - 1) * stride;
405 DWTELEM *b5 = buffer + mirror(y + 4, height - 1) * stride;
407 if (y + 3 < (unsigned)height)
408 horizontal_decompose97i(b4, width);
409 if (y + 4 < (unsigned)height)
410 horizontal_decompose97i(b5, width);
412 if (y + 3 < (unsigned)height)
413 vertical_decompose97iH0(b3, b4, b5, width);
414 if (y + 2 < (unsigned)height)
415 vertical_decompose97iL0(b2, b3, b4, width);
416 if (y + 1 < (unsigned)height)
417 vertical_decompose97iH1(b1, b2, b3, width);
418 if (y + 0 < (unsigned)height)
419 vertical_decompose97iL1(b0, b1, b2, width);
428 void ff_spatial_dwt(DWTELEM *buffer, int width, int height, int stride,
429 int type, int decomposition_count)
433 for (level = 0; level < decomposition_count; level++) {
436 spatial_decompose97i(buffer,
437 width >> level, height >> level,
441 spatial_decompose53i(buffer,
442 width >> level, height >> level,
449 static void horizontal_compose53i(IDWTELEM *b, int width)
451 IDWTELEM temp[width];
452 const int width2 = width >> 1;
453 const int w2 = (width + 1) >> 1;
456 for (x = 0; x < width2; x++) {
458 temp[2 * x + 1] = b[x + w2];
463 b[0] = temp[0] - ((temp[1] + 1) >> 1);
464 for (x = 2; x < width - 1; x += 2) {
465 b[x] = temp[x] - ((temp[x - 1] + temp[x + 1] + 2) >> 2);
466 b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1);
469 b[x] = temp[x] - ((temp[x - 1] + 1) >> 1);
470 b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1);
472 b[x - 1] = temp[x - 1] + b[x - 2];
475 static void vertical_compose53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
480 for (i = 0; i < width; i++)
481 b1[i] += (b0[i] + b2[i]) >> 1;
484 static void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
489 for (i = 0; i < width; i++)
490 b1[i] -= (b0[i] + b2[i] + 2) >> 2;
493 static void spatial_compose53i_buffered_init(DWTCompose *cs, slice_buffer *sb,
494 int height, int stride_line)
496 cs->b0 = slice_buffer_get_line(sb,
497 mirror(-1 - 1, height - 1) * stride_line);
498 cs->b1 = slice_buffer_get_line(sb, mirror(-1, height - 1) * stride_line);
502 static void spatial_compose53i_init(DWTCompose *cs, IDWTELEM *buffer,
503 int height, int stride)
505 cs->b0 = buffer + mirror(-1 - 1, height - 1) * stride;
506 cs->b1 = buffer + mirror(-1, height - 1) * stride;
510 static void spatial_compose53i_dy_buffered(DWTCompose *cs, slice_buffer *sb,
511 int width, int height,
516 IDWTELEM *b0 = cs->b0;
517 IDWTELEM *b1 = cs->b1;
518 IDWTELEM *b2 = slice_buffer_get_line(sb,
519 mirror(y + 1, height - 1) *
521 IDWTELEM *b3 = slice_buffer_get_line(sb,
522 mirror(y + 2, height - 1) *
525 if (y + 1 < (unsigned)height && y < (unsigned)height) {
528 for (x = 0; x < width; x++) {
529 b2[x] -= (b1[x] + b3[x] + 2) >> 2;
530 b1[x] += (b0[x] + b2[x]) >> 1;
533 if (y + 1 < (unsigned)height)
534 vertical_compose53iL0(b1, b2, b3, width);
535 if (y + 0 < (unsigned)height)
536 vertical_compose53iH0(b0, b1, b2, width);
539 if (y - 1 < (unsigned)height)
540 horizontal_compose53i(b0, width);
541 if (y + 0 < (unsigned)height)
542 horizontal_compose53i(b1, width);
549 static void spatial_compose53i_dy(DWTCompose *cs, IDWTELEM *buffer, int width,
550 int height, int stride)
553 IDWTELEM *b0 = cs->b0;
554 IDWTELEM *b1 = cs->b1;
555 IDWTELEM *b2 = buffer + mirror(y + 1, height - 1) * stride;
556 IDWTELEM *b3 = buffer + mirror(y + 2, height - 1) * stride;
558 if (y + 1 < (unsigned)height)
559 vertical_compose53iL0(b1, b2, b3, width);
560 if (y + 0 < (unsigned)height)
561 vertical_compose53iH0(b0, b1, b2, width);
563 if (y - 1 < (unsigned)height)
564 horizontal_compose53i(b0, width);
565 if (y + 0 < (unsigned)height)
566 horizontal_compose53i(b1, width);
573 static void av_unused spatial_compose53i(IDWTELEM *buffer, int width,
574 int height, int stride)
577 spatial_compose53i_init(&cs, buffer, height, stride);
578 while (cs.y <= height)
579 spatial_compose53i_dy(&cs, buffer, width, height, stride);
582 void ff_snow_horizontal_compose97i(IDWTELEM *b, int width)
584 IDWTELEM temp[width];
585 const int w2 = (width + 1) >> 1;
587 #if 0 //maybe more understadable but slower
588 inv_lift(temp, b, b + w2, 2, 1, 1, width, W_DM, W_DO, W_DS, 0, 1);
589 inv_lift(temp + 1, b + w2, temp, 2, 1, 2, width, W_CM, W_CO, W_CS, 1, 1);
591 inv_liftS(b, temp, temp + 1, 2, 2, 2, width, W_BM, W_BO, W_BS, 0, 1);
592 inv_lift(b + 1, temp + 1, b, 2, 2, 2, width, W_AM, W_AO, W_AS, 1, 0);
595 temp[0] = b[0] - ((3 * b[w2] + 2) >> 2);
596 for (x = 1; x < (width >> 1); x++) {
597 temp[2 * x] = b[x] - ((3 * (b[x + w2 - 1] + b[x + w2]) + 4) >> 3);
598 temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x];
601 temp[2 * x] = b[x] - ((3 * b[x + w2 - 1] + 2) >> 2);
602 temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x];
604 temp[2 * x - 1] = b[x + w2 - 1] - 2 * temp[2 * x - 2];
606 b[0] = temp[0] + ((2 * temp[0] + temp[1] + 4) >> 3);
607 for (x = 2; x < width - 1; x += 2) {
608 b[x] = temp[x] + ((4 * temp[x] + temp[x - 1] + temp[x + 1] + 8) >> 4);
609 b[x - 1] = temp[x - 1] + ((3 * (b[x - 2] + b[x])) >> 1);
612 b[x] = temp[x] + ((2 * temp[x] + temp[x - 1] + 4) >> 3);
613 b[x - 1] = temp[x - 1] + ((3 * (b[x - 2] + b[x])) >> 1);
615 b[x - 1] = temp[x - 1] + 3 * b[x - 2];
619 static void vertical_compose97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
624 for (i = 0; i < width; i++)
625 b1[i] += (W_AM * (b0[i] + b2[i]) + W_AO) >> W_AS;
628 static void vertical_compose97iH1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
633 for (i = 0; i < width; i++)
634 b1[i] -= (W_CM * (b0[i] + b2[i]) + W_CO) >> W_CS;
637 static void vertical_compose97iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
642 for (i = 0; i < width; i++)
644 b1[i] += (W_BM * (b0[i] + b2[i]) + W_BO) >> W_BS;
646 b1[i] += (W_BM * (b0[i] + b2[i]) + 4 * b1[i] + W_BO) >> W_BS;
650 static void vertical_compose97iL1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
655 for (i = 0; i < width; i++)
656 b1[i] -= (W_DM * (b0[i] + b2[i]) + W_DO) >> W_DS;
659 void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
660 IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5,
665 for (i = 0; i < width; i++) {
666 b4[i] -= (W_DM * (b3[i] + b5[i]) + W_DO) >> W_DS;
667 b3[i] -= (W_CM * (b2[i] + b4[i]) + W_CO) >> W_CS;
669 b2[i] += (W_BM * (b1[i] + b3[i]) + W_BO) >> W_BS;
671 b2[i] += (W_BM * (b1[i] + b3[i]) + 4 * b2[i] + W_BO) >> W_BS;
673 b1[i] += (W_AM * (b0[i] + b2[i]) + W_AO) >> W_AS;
677 static void spatial_compose97i_buffered_init(DWTCompose *cs, slice_buffer *sb,
678 int height, int stride_line)
680 cs->b0 = slice_buffer_get_line(sb, mirror(-3 - 1, height - 1) * stride_line);
681 cs->b1 = slice_buffer_get_line(sb, mirror(-3, height - 1) * stride_line);
682 cs->b2 = slice_buffer_get_line(sb, mirror(-3 + 1, height - 1) * stride_line);
683 cs->b3 = slice_buffer_get_line(sb, mirror(-3 + 2, height - 1) * stride_line);
687 static void spatial_compose97i_init(DWTCompose *cs, IDWTELEM *buffer, int height,
690 cs->b0 = buffer + mirror(-3 - 1, height - 1) * stride;
691 cs->b1 = buffer + mirror(-3, height - 1) * stride;
692 cs->b2 = buffer + mirror(-3 + 1, height - 1) * stride;
693 cs->b3 = buffer + mirror(-3 + 2, height - 1) * stride;
697 static void spatial_compose97i_dy_buffered(DWTContext *dsp, DWTCompose *cs,
698 slice_buffer *sb, int width,
699 int height, int stride_line)
703 IDWTELEM *b0 = cs->b0;
704 IDWTELEM *b1 = cs->b1;
705 IDWTELEM *b2 = cs->b2;
706 IDWTELEM *b3 = cs->b3;
707 IDWTELEM *b4 = slice_buffer_get_line(sb,
708 mirror(y + 3, height - 1) *
710 IDWTELEM *b5 = slice_buffer_get_line(sb,
711 mirror(y + 4, height - 1) *
714 if (y > 0 && y + 4 < height) {
715 dsp->vertical_compose97i(b0, b1, b2, b3, b4, b5, width);
717 if (y + 3 < (unsigned)height)
718 vertical_compose97iL1(b3, b4, b5, width);
719 if (y + 2 < (unsigned)height)
720 vertical_compose97iH1(b2, b3, b4, width);
721 if (y + 1 < (unsigned)height)
722 vertical_compose97iL0(b1, b2, b3, width);
723 if (y + 0 < (unsigned)height)
724 vertical_compose97iH0(b0, b1, b2, width);
727 if (y - 1 < (unsigned)height)
728 dsp->horizontal_compose97i(b0, width);
729 if (y + 0 < (unsigned)height)
730 dsp->horizontal_compose97i(b1, width);
739 static void spatial_compose97i_dy(DWTCompose *cs, IDWTELEM *buffer, int width,
740 int height, int stride)
743 IDWTELEM *b0 = cs->b0;
744 IDWTELEM *b1 = cs->b1;
745 IDWTELEM *b2 = cs->b2;
746 IDWTELEM *b3 = cs->b3;
747 IDWTELEM *b4 = buffer + mirror(y + 3, height - 1) * stride;
748 IDWTELEM *b5 = buffer + mirror(y + 4, height - 1) * stride;
750 if (y + 3 < (unsigned)height)
751 vertical_compose97iL1(b3, b4, b5, width);
752 if (y + 2 < (unsigned)height)
753 vertical_compose97iH1(b2, b3, b4, width);
754 if (y + 1 < (unsigned)height)
755 vertical_compose97iL0(b1, b2, b3, width);
756 if (y + 0 < (unsigned)height)
757 vertical_compose97iH0(b0, b1, b2, width);
759 if (y - 1 < (unsigned)height)
760 ff_snow_horizontal_compose97i(b0, width);
761 if (y + 0 < (unsigned)height)
762 ff_snow_horizontal_compose97i(b1, width);
771 static void av_unused spatial_compose97i(IDWTELEM *buffer, int width,
772 int height, int stride)
775 spatial_compose97i_init(&cs, buffer, height, stride);
776 while (cs.y <= height)
777 spatial_compose97i_dy(&cs, buffer, width, height, stride);
780 void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer *sb, int width,
781 int height, int stride_line, int type,
782 int decomposition_count)
785 for (level = decomposition_count - 1; level >= 0; level--) {
788 spatial_compose97i_buffered_init(cs + level, sb, height >> level,
789 stride_line << level);
792 spatial_compose53i_buffered_init(cs + level, sb, height >> level,
793 stride_line << level);
799 void ff_spatial_idwt_buffered_slice(DWTContext *dsp, DWTCompose *cs,
800 slice_buffer *slice_buf, int width,
801 int height, int stride_line, int type,
802 int decomposition_count, int y)
804 const int support = type == 1 ? 3 : 5;
809 for (level = decomposition_count - 1; level >= 0; level--)
810 while (cs[level].y <= FFMIN((y >> level) + support, height >> level)) {
813 spatial_compose97i_dy_buffered(dsp, cs + level, slice_buf,
816 stride_line << level);
819 spatial_compose53i_dy_buffered(cs + level, slice_buf,
822 stride_line << level);
828 static void ff_spatial_idwt_init(DWTCompose *cs, IDWTELEM *buffer, int width,
829 int height, int stride, int type,
830 int decomposition_count)
833 for (level = decomposition_count - 1; level >= 0; level--) {
836 spatial_compose97i_init(cs + level, buffer, height >> level,
840 spatial_compose53i_init(cs + level, buffer, height >> level,
847 static void ff_spatial_idwt_slice(DWTCompose *cs, IDWTELEM *buffer, int width,
848 int height, int stride, int type,
849 int decomposition_count, int y)
851 const int support = type == 1 ? 3 : 5;
856 for (level = decomposition_count - 1; level >= 0; level--)
857 while (cs[level].y <= FFMIN((y >> level) + support, height >> level)) {
860 spatial_compose97i_dy(cs + level, buffer, width >> level,
861 height >> level, stride << level);
864 spatial_compose53i_dy(cs + level, buffer, width >> level,
865 height >> level, stride << level);
871 void ff_spatial_idwt(IDWTELEM *buffer, int width, int height, int stride,
872 int type, int decomposition_count)
874 DWTCompose cs[MAX_DECOMPOSITIONS];
876 ff_spatial_idwt_init(cs, buffer, width, height, stride, type,
877 decomposition_count);
878 for (y = 0; y < height; y += 4)
879 ff_spatial_idwt_slice(cs, buffer, width, height, stride, type,
880 decomposition_count, y);
883 static inline int w_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size,
884 int w, int h, int type)
887 const int dec_count = w == 8 ? 3 : 4;
890 static const int scale[2][2][4][4] = {
893 { 268, 239, 239, 213 },
894 { 0, 224, 224, 152 },
895 { 0, 135, 135, 110 },
897 { // 9/7 16x16 or 32x32 dec=4
898 { 344, 310, 310, 280 },
899 { 0, 320, 320, 228 },
900 { 0, 175, 175, 136 },
901 { 0, 129, 129, 102 },
906 { 275, 245, 245, 218 },
907 { 0, 230, 230, 156 },
908 { 0, 138, 138, 113 },
910 { // 5/3 16x16 or 32x32 dec=4
911 { 352, 317, 317, 286 },
912 { 0, 328, 328, 233 },
913 { 0, 180, 180, 140 },
914 { 0, 132, 132, 105 },
919 for (i = 0; i < h; i++) {
920 for (j = 0; j < w; j += 4) {
921 tmp[32 * i + j + 0] = (pix1[j + 0] - pix2[j + 0]) << 4;
922 tmp[32 * i + j + 1] = (pix1[j + 1] - pix2[j + 1]) << 4;
923 tmp[32 * i + j + 2] = (pix1[j + 2] - pix2[j + 2]) << 4;
924 tmp[32 * i + j + 3] = (pix1[j + 3] - pix2[j + 3]) << 4;
930 ff_spatial_dwt(tmp, w, h, 32, type, dec_count);
934 for (level = 0; level < dec_count; level++)
935 for (ori = level ? 1 : 0; ori < 4; ori++) {
936 int size = w >> (dec_count - level);
937 int sx = (ori & 1) ? size : 0;
938 int stride = 32 << (dec_count - level);
939 int sy = (ori & 2) ? stride >> 1 : 0;
941 for (i = 0; i < size; i++)
942 for (j = 0; j < size; j++) {
943 int v = tmp[sx + sy + i * stride + j] *
944 scale[type][dec_count - 3][level][ori];
952 static int w53_8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
954 return w_c(v, pix1, pix2, line_size, 8, h, 1);
957 static int w97_8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
959 return w_c(v, pix1, pix2, line_size, 8, h, 0);
962 static int w53_16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
964 return w_c(v, pix1, pix2, line_size, 16, h, 1);
967 static int w97_16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
969 return w_c(v, pix1, pix2, line_size, 16, h, 0);
972 int ff_w53_32_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
974 return w_c(v, pix1, pix2, line_size, 32, h, 1);
977 int ff_w97_32_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
979 return w_c(v, pix1, pix2, line_size, 32, h, 0);
982 void ff_dsputil_init_dwt(DSPContext *c)
984 c->w53[0] = w53_16_c;
986 c->w97[0] = w97_16_c;
990 void ff_dwt_init(DWTContext *c)
992 c->vertical_compose97i = ff_snow_vertical_compose97i;
993 c->horizontal_compose97i = ff_snow_horizontal_compose97i;
994 c->inner_add_yblock = ff_snow_inner_add_yblock;
1001 static av_always_inline
1002 void interleave(IDWTELEM *dst, IDWTELEM *src0, IDWTELEM *src1, int w2, int add, int shift)
1005 for (i = 0; i < w2; i++) {
1006 dst[2*i ] = (src0[i] + add) >> shift;
1007 dst[2*i+1] = (src1[i] + add) >> shift;
1011 static void horizontal_compose_dirac53i(IDWTELEM *b, IDWTELEM *temp, int w)
1013 const int w2 = w >> 1;
1016 temp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]);
1017 for (x = 1; x < w2; x++) {
1018 temp[x ] = COMPOSE_53iL0 (b[x+w2-1], b[x ], b[x+w2]);
1019 temp[x+w2-1] = COMPOSE_DIRAC53iH0(temp[x-1], b[x+w2-1], temp[x]);
1021 temp[w-1] = COMPOSE_DIRAC53iH0(temp[w2-1], b[w-1], temp[w2-1]);
1023 interleave(b, temp, temp+w2, w2, 1, 1);
1026 static void horizontal_compose_dd97i(IDWTELEM *b, IDWTELEM *tmp, int w)
1028 const int w2 = w >> 1;
1031 tmp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]);
1032 for (x = 1; x < w2; x++)
1033 tmp[x] = COMPOSE_53iL0(b[x+w2-1], b[x], b[x+w2]);
1037 tmp[w2+1] = tmp[w2] = tmp[w2-1];
1039 for (x = 0; x < w2; x++) {
1040 b[2*x ] = (tmp[x] + 1)>>1;
1041 b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1;
1045 static void horizontal_compose_dd137i(IDWTELEM *b, IDWTELEM *tmp, int w)
1047 const int w2 = w >> 1;
1050 tmp[0] = COMPOSE_DD137iL0(b[w2], b[w2], b[0], b[w2 ], b[w2+1]);
1051 tmp[1] = COMPOSE_DD137iL0(b[w2], b[w2], b[1], b[w2+1], b[w2+2]);
1052 for (x = 2; x < w2-1; x++)
1053 tmp[x] = COMPOSE_DD137iL0(b[x+w2-2], b[x+w2-1], b[x], b[x+w2], b[x+w2+1]);
1054 tmp[w2-1] = COMPOSE_DD137iL0(b[w-3], b[w-2], b[w2-1], b[w-1], b[w-1]);
1058 tmp[w2+1] = tmp[w2] = tmp[w2-1];
1060 for (x = 0; x < w2; x++) {
1061 b[2*x ] = (tmp[x] + 1)>>1;
1062 b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1;
1066 static av_always_inline
1067 void horizontal_compose_haari(IDWTELEM *b, IDWTELEM *temp, int w, int shift)
1069 const int w2 = w >> 1;
1072 for (x = 0; x < w2; x++) {
1073 temp[x ] = COMPOSE_HAARiL0(b[x ], b[x+w2]);
1074 temp[x+w2] = COMPOSE_HAARiH0(b[x+w2], temp[x]);
1077 interleave(b, temp, temp+w2, w2, shift, shift);
1080 static void horizontal_compose_haar0i(IDWTELEM *b, IDWTELEM *temp, int w)
1082 horizontal_compose_haari(b, temp, w, 0);
1085 static void horizontal_compose_haar1i(IDWTELEM *b, IDWTELEM *temp, int w)
1087 horizontal_compose_haari(b, temp, w, 1);
1090 static void horizontal_compose_fidelityi(IDWTELEM *b, IDWTELEM *tmp, int w)
1092 const int w2 = w >> 1;
1096 for (x = 0; x < w2; x++) {
1097 for (i = 0; i < 8; i++)
1098 v[i] = b[av_clip(x-3+i, 0, w2-1)];
1099 tmp[x] = COMPOSE_FIDELITYiH0(v[0], v[1], v[2], v[3], b[x+w2], v[4], v[5], v[6], v[7]);
1102 for (x = 0; x < w2; x++) {
1103 for (i = 0; i < 8; i++)
1104 v[i] = tmp[av_clip(x-4+i, 0, w2-1)];
1105 tmp[x+w2] = COMPOSE_FIDELITYiL0(v[0], v[1], v[2], v[3], b[x], v[4], v[5], v[6], v[7]);
1108 interleave(b, tmp+w2, tmp, w2, 0, 0);
1111 static void horizontal_compose_daub97i(IDWTELEM *b, IDWTELEM *temp, int w)
1113 const int w2 = w >> 1;
1116 temp[0] = COMPOSE_DAUB97iL1(b[w2], b[0], b[w2]);
1117 for (x = 1; x < w2; x++) {
1118 temp[x ] = COMPOSE_DAUB97iL1(b[x+w2-1], b[x ], b[x+w2]);
1119 temp[x+w2-1] = COMPOSE_DAUB97iH1(temp[x-1], b[x+w2-1], temp[x]);
1121 temp[w-1] = COMPOSE_DAUB97iH1(temp[w2-1], b[w-1], temp[w2-1]);
1123 // second stage combined with interleave and shift
1124 b0 = b2 = COMPOSE_DAUB97iL0(temp[w2], temp[0], temp[w2]);
1125 b[0] = (b0 + 1) >> 1;
1126 for (x = 1; x < w2; x++) {
1127 b2 = COMPOSE_DAUB97iL0(temp[x+w2-1], temp[x ], temp[x+w2]);
1128 b1 = COMPOSE_DAUB97iH0( b0, temp[x+w2-1], b2 );
1129 b[2*x-1] = (b1 + 1) >> 1;
1130 b[2*x ] = (b2 + 1) >> 1;
1133 b[w-1] = (COMPOSE_DAUB97iH0(b2, temp[w-1], b2) + 1) >> 1;
1136 static void vertical_compose_dirac53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1140 for(i=0; i<width; i++){
1141 b1[i] = COMPOSE_DIRAC53iH0(b0[i], b1[i], b2[i]);
1145 static void vertical_compose_dd97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
1146 IDWTELEM *b3, IDWTELEM *b4, int width)
1150 for(i=0; i<width; i++){
1151 b2[i] = COMPOSE_DD97iH0(b0[i], b1[i], b2[i], b3[i], b4[i]);
1155 static void vertical_compose_dd137iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
1156 IDWTELEM *b3, IDWTELEM *b4, int width)
1160 for(i=0; i<width; i++){
1161 b2[i] = COMPOSE_DD137iL0(b0[i], b1[i], b2[i], b3[i], b4[i]);
1165 static void vertical_compose_haar(IDWTELEM *b0, IDWTELEM *b1, int width)
1169 for (i = 0; i < width; i++) {
1170 b0[i] = COMPOSE_HAARiL0(b0[i], b1[i]);
1171 b1[i] = COMPOSE_HAARiH0(b1[i], b0[i]);
1175 static void vertical_compose_fidelityiH0(IDWTELEM *dst, IDWTELEM *b[8], int width)
1179 for(i=0; i<width; i++){
1180 dst[i] = COMPOSE_FIDELITYiH0(b[0][i], b[1][i], b[2][i], b[3][i], dst[i], b[4][i], b[5][i], b[6][i], b[7][i]);
1184 static void vertical_compose_fidelityiL0(IDWTELEM *dst, IDWTELEM *b[8], int width)
1188 for(i=0; i<width; i++){
1189 dst[i] = COMPOSE_FIDELITYiL0(b[0][i], b[1][i], b[2][i], b[3][i], dst[i], b[4][i], b[5][i], b[6][i], b[7][i]);
1193 static void vertical_compose_daub97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1197 for(i=0; i<width; i++){
1198 b1[i] = COMPOSE_DAUB97iH0(b0[i], b1[i], b2[i]);
1202 static void vertical_compose_daub97iH1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1206 for(i=0; i<width; i++){
1207 b1[i] = COMPOSE_DAUB97iH1(b0[i], b1[i], b2[i]);
1211 static void vertical_compose_daub97iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1215 for(i=0; i<width; i++){
1216 b1[i] = COMPOSE_DAUB97iL0(b0[i], b1[i], b2[i]);
1220 static void vertical_compose_daub97iL1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1224 for(i=0; i<width; i++){
1225 b1[i] = COMPOSE_DAUB97iL1(b0[i], b1[i], b2[i]);
1230 static void spatial_compose_dd97i_dy(DWTContext *d, int level, int width, int height, int stride)
1232 vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1233 vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1234 DWTCompose *cs = d->cs + level;
1238 for (i = 0; i < 6; i++)
1240 b[6] = d->buffer + av_clip(y+5, 0, height-2)*stride;
1241 b[7] = d->buffer + av_clip(y+6, 1, height-1)*stride;
1243 if(y+5<(unsigned)height) vertical_compose_l0( b[5], b[6], b[7], width);
1244 if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width);
1246 if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
1247 if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
1249 for (i = 0; i < 6; i++)
1254 static void spatial_compose_dirac53i_dy(DWTContext *d, int level, int width, int height, int stride)
1256 vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1257 vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1258 DWTCompose *cs = d->cs + level;
1261 IDWTELEM *b[4] = { cs->b[0], cs->b[1] };
1262 b[2] = d->buffer + mirror(y+1, height-1)*stride;
1263 b[3] = d->buffer + mirror(y+2, height-1)*stride;
1265 if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
1266 if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
1268 if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
1269 if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
1277 static void spatial_compose_dd137i_dy(DWTContext *d, int level, int width, int height, int stride)
1279 vertical_compose_5tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1280 vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1281 DWTCompose *cs = d->cs + level;
1285 for (i = 0; i < 8; i++)
1287 b[8] = d->buffer + av_clip(y+7, 0, height-2)*stride;
1288 b[9] = d->buffer + av_clip(y+8, 1, height-1)*stride;
1290 if(y+5<(unsigned)height) vertical_compose_l0(b[3], b[5], b[6], b[7], b[9], width);
1291 if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width);
1293 if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
1294 if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
1296 for (i = 0; i < 8; i++)
1301 // haar makes the assumption that height is even (always true for dirac)
1302 static void spatial_compose_haari_dy(DWTContext *d, int level, int width, int height, int stride)
1304 vertical_compose_2tap vertical_compose = (void*)d->vertical_compose;
1305 int y = d->cs[level].y;
1306 IDWTELEM *b0 = d->buffer + (y-1)*stride;
1307 IDWTELEM *b1 = d->buffer + (y )*stride;
1309 vertical_compose(b0, b1, width);
1310 d->horizontal_compose(b0, d->temp, width);
1311 d->horizontal_compose(b1, d->temp, width);
1313 d->cs[level].y += 2;
1316 // Don't do sliced idwt for fidelity; the 9 tap filter makes it a bit annoying
1317 // Fortunately, this filter isn't used in practice.
1318 static void spatial_compose_fidelity(DWTContext *d, int level, int width, int height, int stride)
1320 vertical_compose_9tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1321 vertical_compose_9tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1325 for (y = 1; y < height; y += 2) {
1326 for (i = 0; i < 8; i++)
1327 b[i] = d->buffer + av_clip((y-7 + 2*i), 0, height-2)*stride;
1328 vertical_compose_h0(d->buffer + y*stride, b, width);
1331 for (y = 0; y < height; y += 2) {
1332 for (i = 0; i < 8; i++)
1333 b[i] = d->buffer + av_clip((y-7 + 2*i), 1, height-1)*stride;
1334 vertical_compose_l0(d->buffer + y*stride, b, width);
1337 for (y = 0; y < height; y++)
1338 d->horizontal_compose(d->buffer + y*stride, d->temp, width);
1340 d->cs[level].y = height+1;
1343 static void spatial_compose_daub97i_dy(DWTContext *d, int level, int width, int height, int stride)
1345 vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1346 vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1347 vertical_compose_3tap vertical_compose_l1 = (void*)d->vertical_compose_l1;
1348 vertical_compose_3tap vertical_compose_h1 = (void*)d->vertical_compose_h1;
1349 DWTCompose *cs = d->cs + level;
1353 for (i = 0; i < 4; i++)
1355 b[4] = d->buffer + mirror(y+3, height-1)*stride;
1356 b[5] = d->buffer + mirror(y+4, height-1)*stride;
1358 if(y+3<(unsigned)height) vertical_compose_l1(b[3], b[4], b[5], width);
1359 if(y+2<(unsigned)height) vertical_compose_h1(b[2], b[3], b[4], width);
1360 if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
1361 if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
1363 if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
1364 if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
1366 for (i = 0; i < 4; i++)
1372 static void spatial_compose97i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
1374 cs->b[0] = buffer + mirror(-3-1, height-1)*stride;
1375 cs->b[1] = buffer + mirror(-3 , height-1)*stride;
1376 cs->b[2] = buffer + mirror(-3+1, height-1)*stride;
1377 cs->b[3] = buffer + mirror(-3+2, height-1)*stride;
1381 static void spatial_compose53i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
1383 cs->b[0] = buffer + mirror(-1-1, height-1)*stride;
1384 cs->b[1] = buffer + mirror(-1 , height-1)*stride;
1388 static void spatial_compose_dd97i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
1390 cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride;
1391 cs->b[1] = buffer + av_clip(-5 , 1, height-1)*stride;
1392 cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride;
1393 cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride;
1394 cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride;
1395 cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride;
1399 static void spatial_compose_dd137i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
1401 cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride;
1402 cs->b[1] = buffer + av_clip(-5 , 1, height-1)*stride;
1403 cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride;
1404 cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride;
1405 cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride;
1406 cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride;
1407 cs->b[6] = buffer + av_clip(-5+5, 0, height-2)*stride;
1408 cs->b[7] = buffer + av_clip(-5+6, 1, height-1)*stride;
1412 int ff_spatial_idwt_init2(DWTContext *d, IDWTELEM *buffer, int width, int height,
1413 int stride, enum dwt_type type, int decomposition_count,
1422 d->decomposition_count = decomposition_count;
1425 for(level=decomposition_count-1; level>=0; level--){
1426 int hl = height >> level;
1427 int stride_l = stride << level;
1430 case DWT_DIRAC_DD9_7:
1431 spatial_compose_dd97i_init(d->cs+level, buffer, hl, stride_l);
1433 case DWT_DIRAC_LEGALL5_3:
1434 spatial_compose53i_init2(d->cs+level, buffer, hl, stride_l);
1436 case DWT_DIRAC_DD13_7:
1437 spatial_compose_dd137i_init(d->cs+level, buffer, hl, stride_l);
1439 case DWT_DIRAC_HAAR0:
1440 case DWT_DIRAC_HAAR1:
1443 case DWT_DIRAC_DAUB9_7:
1444 spatial_compose97i_init2(d->cs+level, buffer, hl, stride_l);
1453 case DWT_DIRAC_DD9_7:
1454 d->spatial_compose = spatial_compose_dd97i_dy;
1455 d->vertical_compose_l0 = (void*)vertical_compose53iL0;
1456 d->vertical_compose_h0 = (void*)vertical_compose_dd97iH0;
1457 d->horizontal_compose = horizontal_compose_dd97i;
1460 case DWT_DIRAC_LEGALL5_3:
1461 d->spatial_compose = spatial_compose_dirac53i_dy;
1462 d->vertical_compose_l0 = (void*)vertical_compose53iL0;
1463 d->vertical_compose_h0 = (void*)vertical_compose_dirac53iH0;
1464 d->horizontal_compose = horizontal_compose_dirac53i;
1467 case DWT_DIRAC_DD13_7:
1468 d->spatial_compose = spatial_compose_dd137i_dy;
1469 d->vertical_compose_l0 = (void*)vertical_compose_dd137iL0;
1470 d->vertical_compose_h0 = (void*)vertical_compose_dd97iH0;
1471 d->horizontal_compose = horizontal_compose_dd137i;
1474 case DWT_DIRAC_HAAR0:
1475 case DWT_DIRAC_HAAR1:
1476 d->spatial_compose = spatial_compose_haari_dy;
1477 d->vertical_compose = (void*)vertical_compose_haar;
1478 if (type == DWT_DIRAC_HAAR0)
1479 d->horizontal_compose = horizontal_compose_haar0i;
1481 d->horizontal_compose = horizontal_compose_haar1i;
1484 case DWT_DIRAC_FIDELITY:
1485 d->spatial_compose = spatial_compose_fidelity;
1486 d->vertical_compose_l0 = (void*)vertical_compose_fidelityiL0;
1487 d->vertical_compose_h0 = (void*)vertical_compose_fidelityiH0;
1488 d->horizontal_compose = horizontal_compose_fidelityi;
1490 case DWT_DIRAC_DAUB9_7:
1491 d->spatial_compose = spatial_compose_daub97i_dy;
1492 d->vertical_compose_l0 = (void*)vertical_compose_daub97iL0;
1493 d->vertical_compose_h0 = (void*)vertical_compose_daub97iH0;
1494 d->vertical_compose_l1 = (void*)vertical_compose_daub97iL1;
1495 d->vertical_compose_h1 = (void*)vertical_compose_daub97iH1;
1496 d->horizontal_compose = horizontal_compose_daub97i;
1500 av_log(NULL, AV_LOG_ERROR, "Unknown wavelet type %d\n", type);
1504 if (HAVE_MMX) ff_spatial_idwt_init_mmx(d, type);
1509 void ff_spatial_idwt_slice2(DWTContext *d, int y)
1511 int level, support = d->support;
1513 for (level = d->decomposition_count-1; level >= 0; level--) {
1514 int wl = d->width >> level;
1515 int hl = d->height >> level;
1516 int stride_l = d->stride << level;
1518 while (d->cs[level].y <= FFMIN((y>>level)+support, hl))
1519 d->spatial_compose(d, level, wl, hl, stride_l);
1523 int ff_spatial_idwt2(IDWTELEM *buffer, int width, int height, int stride,
1524 enum dwt_type type, int decomposition_count, IDWTELEM *temp)
1529 if (ff_spatial_idwt_init2(&d, buffer, width, height, stride, type, decomposition_count, temp))
1532 for (y = 0; y < d.height; y += 4)
1533 ff_spatial_idwt_slice2(&d, y);