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"
23 #include "libavutil/avassert.h"
24 #include "libavutil/common.h"
27 #include "libavcodec/x86/dwt.h"
29 int ff_slice_buffer_init(slice_buffer *buf, int line_count,
30 int max_allocated_lines, int line_width,
31 IDWTELEM *base_buffer)
35 buf->base_buffer = base_buffer;
36 buf->line_count = line_count;
37 buf->line_width = line_width;
38 buf->data_count = max_allocated_lines;
39 buf->line = av_mallocz(sizeof(IDWTELEM *) * line_count);
41 return AVERROR(ENOMEM);
42 buf->data_stack = av_malloc(sizeof(IDWTELEM *) * max_allocated_lines);
43 if (!buf->data_stack) {
45 return AVERROR(ENOMEM);
48 for (i = 0; i < max_allocated_lines; i++) {
49 buf->data_stack[i] = av_malloc(sizeof(IDWTELEM) * line_width);
50 if (!buf->data_stack[i]) {
52 av_freep(&buf->data_stack[i]);
53 av_freep(&buf->data_stack);
55 return AVERROR(ENOMEM);
59 buf->data_stack_top = max_allocated_lines - 1;
63 IDWTELEM *ff_slice_buffer_load_line(slice_buffer *buf, int line)
67 av_assert0(buf->data_stack_top >= 0);
68 // av_assert1(!buf->line[line]);
70 return buf->line[line];
72 buffer = buf->data_stack[buf->data_stack_top];
73 buf->data_stack_top--;
74 buf->line[line] = buffer;
79 void ff_slice_buffer_release(slice_buffer *buf, int line)
83 av_assert1(line >= 0 && line < buf->line_count);
84 av_assert1(buf->line[line]);
86 buffer = buf->line[line];
87 buf->data_stack_top++;
88 buf->data_stack[buf->data_stack_top] = buffer;
89 buf->line[line] = NULL;
92 void ff_slice_buffer_flush(slice_buffer *buf)
95 for (i = 0; i < buf->line_count; i++)
97 ff_slice_buffer_release(buf, i);
100 void ff_slice_buffer_destroy(slice_buffer *buf)
103 ff_slice_buffer_flush(buf);
105 for (i = buf->data_count - 1; i >= 0; i--)
106 av_freep(&buf->data_stack[i]);
107 av_freep(&buf->data_stack);
108 av_freep(&buf->line);
111 static inline int mirror(int v, int m)
113 while ((unsigned)v > (unsigned)m) {
121 static av_always_inline void lift(DWTELEM *dst, DWTELEM *src, DWTELEM *ref,
122 int dst_step, int src_step, int ref_step,
123 int width, int mul, int add, int shift,
124 int highpass, int inverse)
126 const int mirror_left = !highpass;
127 const int mirror_right = (width & 1) ^ highpass;
128 const int w = (width >> 1) - 1 + (highpass & width);
131 #define LIFT(src, ref, inv) ((src) + ((inv) ? -(ref) : +(ref)))
133 dst[0] = LIFT(src[0], ((mul * 2 * ref[0] + add) >> shift), inverse);
138 for (i = 0; i < w; i++)
139 dst[i * dst_step] = LIFT(src[i * src_step],
140 ((mul * (ref[i * ref_step] +
141 ref[(i + 1) * ref_step]) +
146 dst[w * dst_step] = LIFT(src[w * src_step],
147 ((mul * 2 * ref[w * ref_step] + add) >> shift),
151 static av_always_inline void liftS(DWTELEM *dst, DWTELEM *src, DWTELEM *ref,
152 int dst_step, int src_step, int ref_step,
153 int width, int mul, int add, int shift,
154 int highpass, int inverse)
156 const int mirror_left = !highpass;
157 const int mirror_right = (width & 1) ^ highpass;
158 const int w = (width >> 1) - 1 + (highpass & width);
161 av_assert1(shift == 4);
162 #define LIFTS(src, ref, inv) \
163 ((inv) ? (src) + (((ref) + 4 * (src)) >> shift) \
164 : -((-16 * (src) + (ref) + add / \
165 4 + 1 + (5 << 25)) / (5 * 4) - (1 << 23)))
167 dst[0] = LIFTS(src[0], mul * 2 * ref[0] + add, inverse);
172 for (i = 0; i < w; i++)
173 dst[i * dst_step] = LIFTS(src[i * src_step],
174 mul * (ref[i * ref_step] +
175 ref[(i + 1) * ref_step]) + add,
179 dst[w * dst_step] = LIFTS(src[w * src_step],
180 mul * 2 * ref[w * ref_step] + add,
184 static void horizontal_decompose53i(DWTELEM *b, DWTELEM *temp, int width)
186 const int width2 = width >> 1;
188 const int w2 = (width + 1) >> 1;
190 for (x = 0; x < width2; x++) {
192 temp[x + w2] = b[2 * x + 1];
196 lift(b + w2, temp + w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0);
197 lift(b, temp, b + w2, 1, 1, 1, width, 1, 2, 2, 0, 0);
200 static void vertical_decompose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
205 for (i = 0; i < width; i++)
206 b1[i] -= (b0[i] + b2[i]) >> 1;
209 static void vertical_decompose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
214 for (i = 0; i < width; i++)
215 b1[i] += (b0[i] + b2[i] + 2) >> 2;
218 static void spatial_decompose53i(DWTELEM *buffer, DWTELEM *temp,
219 int width, int height, int stride)
222 DWTELEM *b0 = buffer + mirror(-2 - 1, height - 1) * stride;
223 DWTELEM *b1 = buffer + mirror(-2, height - 1) * stride;
225 for (y = -2; y < height; y += 2) {
226 DWTELEM *b2 = buffer + mirror(y + 1, height - 1) * stride;
227 DWTELEM *b3 = buffer + mirror(y + 2, height - 1) * stride;
229 if (y + 1 < (unsigned)height)
230 horizontal_decompose53i(b2, temp, width);
231 if (y + 2 < (unsigned)height)
232 horizontal_decompose53i(b3, temp, width);
234 if (y + 1 < (unsigned)height)
235 vertical_decompose53iH0(b1, b2, b3, width);
236 if (y + 0 < (unsigned)height)
237 vertical_decompose53iL0(b0, b1, b2, width);
244 static void horizontal_decompose97i(DWTELEM *b, DWTELEM *temp, int width)
246 const int w2 = (width + 1) >> 1;
248 lift(temp + w2, b + 1, b, 1, 2, 2, width, W_AM, W_AO, W_AS, 1, 1);
249 liftS(temp, b, temp + w2, 1, 2, 1, width, W_BM, W_BO, W_BS, 0, 0);
250 lift(b + w2, temp + w2, temp, 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 0);
251 lift(b, temp, b + w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 0);
254 static void vertical_decompose97iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
259 for (i = 0; i < width; i++)
260 b1[i] -= (W_AM * (b0[i] + b2[i]) + W_AO) >> W_AS;
263 static void vertical_decompose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
268 for (i = 0; i < width; i++)
269 b1[i] += (W_CM * (b0[i] + b2[i]) + W_CO) >> W_CS;
272 static void vertical_decompose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
277 for (i = 0; i < width; i++)
278 b1[i] = (16 * 4 * b1[i] - 4 * (b0[i] + b2[i]) + W_BO * 5 + (5 << 27)) /
279 (5 * 16) - (1 << 23);
282 static void vertical_decompose97iL1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
287 for (i = 0; i < width; i++)
288 b1[i] += (W_DM * (b0[i] + b2[i]) + W_DO) >> W_DS;
291 static void spatial_decompose97i(DWTELEM *buffer, DWTELEM *temp,
292 int width, int height, int stride)
295 DWTELEM *b0 = buffer + mirror(-4 - 1, height - 1) * stride;
296 DWTELEM *b1 = buffer + mirror(-4, height - 1) * stride;
297 DWTELEM *b2 = buffer + mirror(-4 + 1, height - 1) * stride;
298 DWTELEM *b3 = buffer + mirror(-4 + 2, height - 1) * stride;
300 for (y = -4; y < height; y += 2) {
301 DWTELEM *b4 = buffer + mirror(y + 3, height - 1) * stride;
302 DWTELEM *b5 = buffer + mirror(y + 4, height - 1) * stride;
304 if (y + 3 < (unsigned)height)
305 horizontal_decompose97i(b4, temp, width);
306 if (y + 4 < (unsigned)height)
307 horizontal_decompose97i(b5, temp, width);
309 if (y + 3 < (unsigned)height)
310 vertical_decompose97iH0(b3, b4, b5, width);
311 if (y + 2 < (unsigned)height)
312 vertical_decompose97iL0(b2, b3, b4, width);
313 if (y + 1 < (unsigned)height)
314 vertical_decompose97iH1(b1, b2, b3, width);
315 if (y + 0 < (unsigned)height)
316 vertical_decompose97iL1(b0, b1, b2, width);
325 void ff_spatial_dwt(DWTELEM *buffer, DWTELEM *temp, int width, int height,
326 int stride, int type, int decomposition_count)
330 for (level = 0; level < decomposition_count; level++) {
333 spatial_decompose97i(buffer, temp,
334 width >> level, height >> level,
338 spatial_decompose53i(buffer, temp,
339 width >> level, height >> level,
346 static void horizontal_compose53i(IDWTELEM *b, IDWTELEM *temp, int width)
348 const int width2 = width >> 1;
349 const int w2 = (width + 1) >> 1;
352 for (x = 0; x < width2; x++) {
354 temp[2 * x + 1] = b[x + w2];
359 b[0] = temp[0] - ((temp[1] + 1) >> 1);
360 for (x = 2; x < width - 1; x += 2) {
361 b[x] = temp[x] - ((temp[x - 1] + temp[x + 1] + 2) >> 2);
362 b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1);
365 b[x] = temp[x] - ((temp[x - 1] + 1) >> 1);
366 b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1);
368 b[x - 1] = temp[x - 1] + b[x - 2];
371 static void vertical_compose53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
376 for (i = 0; i < width; i++)
377 b1[i] += (b0[i] + b2[i]) >> 1;
380 static void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
385 for (i = 0; i < width; i++)
386 b1[i] -= (b0[i] + b2[i] + 2) >> 2;
389 static void spatial_compose53i_buffered_init(DWTCompose *cs, slice_buffer *sb,
390 int height, int stride_line)
392 cs->b0 = slice_buffer_get_line(sb,
393 mirror(-1 - 1, height - 1) * stride_line);
394 cs->b1 = slice_buffer_get_line(sb, mirror(-1, height - 1) * stride_line);
398 static void spatial_compose53i_init(DWTCompose *cs, IDWTELEM *buffer,
399 int height, int stride)
401 cs->b0 = buffer + mirror(-1 - 1, height - 1) * stride;
402 cs->b1 = buffer + mirror(-1, height - 1) * stride;
406 static void spatial_compose53i_dy_buffered(DWTCompose *cs, slice_buffer *sb,
408 int width, int height,
413 IDWTELEM *b0 = cs->b0;
414 IDWTELEM *b1 = cs->b1;
415 IDWTELEM *b2 = slice_buffer_get_line(sb,
416 mirror(y + 1, height - 1) *
418 IDWTELEM *b3 = slice_buffer_get_line(sb,
419 mirror(y + 2, height - 1) *
422 if (y + 1 < (unsigned)height && y < (unsigned)height) {
425 for (x = 0; x < width; x++) {
426 b2[x] -= (b1[x] + b3[x] + 2) >> 2;
427 b1[x] += (b0[x] + b2[x]) >> 1;
430 if (y + 1 < (unsigned)height)
431 vertical_compose53iL0(b1, b2, b3, width);
432 if (y + 0 < (unsigned)height)
433 vertical_compose53iH0(b0, b1, b2, width);
436 if (y - 1 < (unsigned)height)
437 horizontal_compose53i(b0, temp, width);
438 if (y + 0 < (unsigned)height)
439 horizontal_compose53i(b1, temp, width);
446 static void spatial_compose53i_dy(DWTCompose *cs, IDWTELEM *buffer,
447 IDWTELEM *temp, int width, int height,
451 IDWTELEM *b0 = cs->b0;
452 IDWTELEM *b1 = cs->b1;
453 IDWTELEM *b2 = buffer + mirror(y + 1, height - 1) * stride;
454 IDWTELEM *b3 = buffer + mirror(y + 2, height - 1) * stride;
456 if (y + 1 < (unsigned)height)
457 vertical_compose53iL0(b1, b2, b3, width);
458 if (y + 0 < (unsigned)height)
459 vertical_compose53iH0(b0, b1, b2, width);
461 if (y - 1 < (unsigned)height)
462 horizontal_compose53i(b0, temp, width);
463 if (y + 0 < (unsigned)height)
464 horizontal_compose53i(b1, temp, width);
471 static void av_unused spatial_compose53i(IDWTELEM *buffer, IDWTELEM *temp,
472 int width, int height, int stride)
475 spatial_compose53i_init(&cs, buffer, height, stride);
476 while (cs.y <= height)
477 spatial_compose53i_dy(&cs, buffer, temp, width, height, stride);
480 void ff_snow_horizontal_compose97i(IDWTELEM *b, IDWTELEM *temp, int width)
482 const int w2 = (width + 1) >> 1;
485 temp[0] = b[0] - ((3 * b[w2] + 2) >> 2);
486 for (x = 1; x < (width >> 1); x++) {
487 temp[2 * x] = b[x] - ((3 * (b[x + w2 - 1] + b[x + w2]) + 4) >> 3);
488 temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x];
491 temp[2 * x] = b[x] - ((3 * b[x + w2 - 1] + 2) >> 2);
492 temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x];
494 temp[2 * x - 1] = b[x + w2 - 1] - 2 * temp[2 * x - 2];
496 b[0] = temp[0] + ((2 * temp[0] + temp[1] + 4) >> 3);
497 for (x = 2; x < width - 1; x += 2) {
498 b[x] = temp[x] + ((4 * temp[x] + temp[x - 1] + temp[x + 1] + 8) >> 4);
499 b[x - 1] = temp[x - 1] + ((3 * (b[x - 2] + b[x])) >> 1);
502 b[x] = temp[x] + ((2 * temp[x] + temp[x - 1] + 4) >> 3);
503 b[x - 1] = temp[x - 1] + ((3 * (b[x - 2] + b[x])) >> 1);
505 b[x - 1] = temp[x - 1] + 3 * b[x - 2];
508 static void vertical_compose97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
513 for (i = 0; i < width; i++)
514 b1[i] += (W_AM * (b0[i] + b2[i]) + W_AO) >> W_AS;
517 static void vertical_compose97iH1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
522 for (i = 0; i < width; i++)
523 b1[i] -= (W_CM * (b0[i] + b2[i]) + W_CO) >> W_CS;
526 static void vertical_compose97iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
531 for (i = 0; i < width; i++)
532 b1[i] += (W_BM * (b0[i] + b2[i]) + 4 * b1[i] + W_BO) >> W_BS;
535 static void vertical_compose97iL1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
540 for (i = 0; i < width; i++)
541 b1[i] -= (W_DM * (b0[i] + b2[i]) + W_DO) >> W_DS;
544 void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
545 IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5,
550 for (i = 0; i < width; i++) {
551 b4[i] -= (W_DM * (b3[i] + b5[i]) + W_DO) >> W_DS;
552 b3[i] -= (W_CM * (b2[i] + b4[i]) + W_CO) >> W_CS;
553 b2[i] += (W_BM * (b1[i] + b3[i]) + 4 * b2[i] + W_BO) >> W_BS;
554 b1[i] += (W_AM * (b0[i] + b2[i]) + W_AO) >> W_AS;
558 static void spatial_compose97i_buffered_init(DWTCompose *cs, slice_buffer *sb,
559 int height, int stride_line)
561 cs->b0 = slice_buffer_get_line(sb, mirror(-3 - 1, height - 1) * stride_line);
562 cs->b1 = slice_buffer_get_line(sb, mirror(-3, height - 1) * stride_line);
563 cs->b2 = slice_buffer_get_line(sb, mirror(-3 + 1, height - 1) * stride_line);
564 cs->b3 = slice_buffer_get_line(sb, mirror(-3 + 2, height - 1) * stride_line);
568 static void spatial_compose97i_init(DWTCompose *cs, IDWTELEM *buffer, int height,
571 cs->b0 = buffer + mirror(-3 - 1, height - 1) * stride;
572 cs->b1 = buffer + mirror(-3, height - 1) * stride;
573 cs->b2 = buffer + mirror(-3 + 1, height - 1) * stride;
574 cs->b3 = buffer + mirror(-3 + 2, height - 1) * stride;
578 static void spatial_compose97i_dy_buffered(DWTContext *dsp, DWTCompose *cs,
579 slice_buffer * sb, IDWTELEM *temp,
580 int width, int height,
585 IDWTELEM *b0 = cs->b0;
586 IDWTELEM *b1 = cs->b1;
587 IDWTELEM *b2 = cs->b2;
588 IDWTELEM *b3 = cs->b3;
589 IDWTELEM *b4 = slice_buffer_get_line(sb,
590 mirror(y + 3, height - 1) *
592 IDWTELEM *b5 = slice_buffer_get_line(sb,
593 mirror(y + 4, height - 1) *
596 if (y > 0 && y + 4 < height) {
597 dsp->vertical_compose97i(b0, b1, b2, b3, b4, b5, width);
599 if (y + 3 < (unsigned)height)
600 vertical_compose97iL1(b3, b4, b5, width);
601 if (y + 2 < (unsigned)height)
602 vertical_compose97iH1(b2, b3, b4, width);
603 if (y + 1 < (unsigned)height)
604 vertical_compose97iL0(b1, b2, b3, width);
605 if (y + 0 < (unsigned)height)
606 vertical_compose97iH0(b0, b1, b2, width);
609 if (y - 1 < (unsigned)height)
610 dsp->horizontal_compose97i(b0, temp, width);
611 if (y + 0 < (unsigned)height)
612 dsp->horizontal_compose97i(b1, temp, width);
621 static void spatial_compose97i_dy(DWTCompose *cs, IDWTELEM *buffer,
622 IDWTELEM *temp, int width, int height,
626 IDWTELEM *b0 = cs->b0;
627 IDWTELEM *b1 = cs->b1;
628 IDWTELEM *b2 = cs->b2;
629 IDWTELEM *b3 = cs->b3;
630 IDWTELEM *b4 = buffer + mirror(y + 3, height - 1) * stride;
631 IDWTELEM *b5 = buffer + mirror(y + 4, height - 1) * stride;
633 if (y + 3 < (unsigned)height)
634 vertical_compose97iL1(b3, b4, b5, width);
635 if (y + 2 < (unsigned)height)
636 vertical_compose97iH1(b2, b3, b4, width);
637 if (y + 1 < (unsigned)height)
638 vertical_compose97iL0(b1, b2, b3, width);
639 if (y + 0 < (unsigned)height)
640 vertical_compose97iH0(b0, b1, b2, width);
642 if (y - 1 < (unsigned)height)
643 ff_snow_horizontal_compose97i(b0, temp, width);
644 if (y + 0 < (unsigned)height)
645 ff_snow_horizontal_compose97i(b1, temp, width);
654 static void av_unused spatial_compose97i(IDWTELEM *buffer, IDWTELEM *temp,
655 int width, int height, int stride)
658 spatial_compose97i_init(&cs, buffer, height, stride);
659 while (cs.y <= height)
660 spatial_compose97i_dy(&cs, buffer, temp, width, height, stride);
663 void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer *sb, int width,
664 int height, int stride_line, int type,
665 int decomposition_count)
668 for (level = decomposition_count - 1; level >= 0; level--) {
671 spatial_compose97i_buffered_init(cs + level, sb, height >> level,
672 stride_line << level);
675 spatial_compose53i_buffered_init(cs + level, sb, height >> level,
676 stride_line << level);
682 void ff_spatial_idwt_buffered_slice(DWTContext *dsp, DWTCompose *cs,
683 slice_buffer *slice_buf, IDWTELEM *temp,
684 int width, int height, int stride_line,
685 int type, int decomposition_count, int y)
687 const int support = type == 1 ? 3 : 5;
692 for (level = decomposition_count - 1; level >= 0; level--)
693 while (cs[level].y <= FFMIN((y >> level) + support, height >> level)) {
696 spatial_compose97i_dy_buffered(dsp, cs + level, slice_buf, temp,
699 stride_line << level);
702 spatial_compose53i_dy_buffered(cs + level, slice_buf, temp,
705 stride_line << level);
711 static void ff_spatial_idwt_init(DWTCompose *cs, IDWTELEM *buffer, int width,
712 int height, int stride, int type,
713 int decomposition_count)
716 for (level = decomposition_count - 1; level >= 0; level--) {
719 spatial_compose97i_init(cs + level, buffer, height >> level,
723 spatial_compose53i_init(cs + level, buffer, height >> level,
730 static void ff_spatial_idwt_slice(DWTCompose *cs, IDWTELEM *buffer,
731 IDWTELEM *temp, int width, int height,
732 int stride, int type,
733 int decomposition_count, int y)
735 const int support = type == 1 ? 3 : 5;
740 for (level = decomposition_count - 1; level >= 0; level--)
741 while (cs[level].y <= FFMIN((y >> level) + support, height >> level)) {
744 spatial_compose97i_dy(cs + level, buffer, temp, width >> level,
745 height >> level, stride << level);
748 spatial_compose53i_dy(cs + level, buffer, temp, width >> level,
749 height >> level, stride << level);
755 void ff_spatial_idwt(IDWTELEM *buffer, IDWTELEM *temp, int width, int height,
756 int stride, int type, int decomposition_count)
758 DWTCompose cs[MAX_DECOMPOSITIONS];
760 ff_spatial_idwt_init(cs, buffer, width, height, stride, type,
761 decomposition_count);
762 for (y = 0; y < height; y += 4)
763 ff_spatial_idwt_slice(cs, buffer, temp, width, height, stride, type,
764 decomposition_count, y);
767 static inline int w_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size,
768 int w, int h, int type)
771 const int dec_count = w == 8 ? 3 : 4;
772 int tmp[32 * 32], tmp2[32];
774 static const int scale[2][2][4][4] = {
777 { 268, 239, 239, 213 },
778 { 0, 224, 224, 152 },
779 { 0, 135, 135, 110 },
781 { // 9/7 16x16 or 32x32 dec=4
782 { 344, 310, 310, 280 },
783 { 0, 320, 320, 228 },
784 { 0, 175, 175, 136 },
785 { 0, 129, 129, 102 },
790 { 275, 245, 245, 218 },
791 { 0, 230, 230, 156 },
792 { 0, 138, 138, 113 },
794 { // 5/3 16x16 or 32x32 dec=4
795 { 352, 317, 317, 286 },
796 { 0, 328, 328, 233 },
797 { 0, 180, 180, 140 },
798 { 0, 132, 132, 105 },
803 for (i = 0; i < h; i++) {
804 for (j = 0; j < w; j += 4) {
805 tmp[32 * i + j + 0] = (pix1[j + 0] - pix2[j + 0]) << 4;
806 tmp[32 * i + j + 1] = (pix1[j + 1] - pix2[j + 1]) << 4;
807 tmp[32 * i + j + 2] = (pix1[j + 2] - pix2[j + 2]) << 4;
808 tmp[32 * i + j + 3] = (pix1[j + 3] - pix2[j + 3]) << 4;
814 ff_spatial_dwt(tmp, tmp2, w, h, 32, type, dec_count);
818 for (level = 0; level < dec_count; level++)
819 for (ori = level ? 1 : 0; ori < 4; ori++) {
820 int size = w >> (dec_count - level);
821 int sx = (ori & 1) ? size : 0;
822 int stride = 32 << (dec_count - level);
823 int sy = (ori & 2) ? stride >> 1 : 0;
825 for (i = 0; i < size; i++)
826 for (j = 0; j < size; j++) {
827 int v = tmp[sx + sy + i * stride + j] *
828 scale[type][dec_count - 3][level][ori];
836 static int w53_8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
838 return w_c(v, pix1, pix2, line_size, 8, h, 1);
841 static int w97_8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
843 return w_c(v, pix1, pix2, line_size, 8, h, 0);
846 static int w53_16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
848 return w_c(v, pix1, pix2, line_size, 16, h, 1);
851 static int w97_16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
853 return w_c(v, pix1, pix2, line_size, 16, h, 0);
856 int ff_w53_32_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
858 return w_c(v, pix1, pix2, line_size, 32, h, 1);
861 int ff_w97_32_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
863 return w_c(v, pix1, pix2, line_size, 32, h, 0);
866 void ff_dsputil_init_dwt(DSPContext *c)
868 c->w53[0] = w53_16_c;
870 c->w97[0] = w97_16_c;
874 void ff_dwt_init(DWTContext *c)
876 c->vertical_compose97i = ff_snow_vertical_compose97i;
877 c->horizontal_compose97i = ff_snow_horizontal_compose97i;
878 c->inner_add_yblock = ff_snow_inner_add_yblock;
885 static av_always_inline
886 void interleave(IDWTELEM *dst, IDWTELEM *src0, IDWTELEM *src1, int w2, int add, int shift)
889 for (i = 0; i < w2; i++) {
890 dst[2*i ] = (src0[i] + add) >> shift;
891 dst[2*i+1] = (src1[i] + add) >> shift;
895 static void horizontal_compose_dirac53i(IDWTELEM *b, IDWTELEM *temp, int w)
897 const int w2 = w >> 1;
900 temp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]);
901 for (x = 1; x < w2; x++) {
902 temp[x ] = COMPOSE_53iL0 (b[x+w2-1], b[x ], b[x+w2]);
903 temp[x+w2-1] = COMPOSE_DIRAC53iH0(temp[x-1], b[x+w2-1], temp[x]);
905 temp[w-1] = COMPOSE_DIRAC53iH0(temp[w2-1], b[w-1], temp[w2-1]);
907 interleave(b, temp, temp+w2, w2, 1, 1);
910 static void horizontal_compose_dd97i(IDWTELEM *b, IDWTELEM *tmp, int w)
912 const int w2 = w >> 1;
915 tmp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]);
916 for (x = 1; x < w2; x++)
917 tmp[x] = COMPOSE_53iL0(b[x+w2-1], b[x], b[x+w2]);
921 tmp[w2+1] = tmp[w2] = tmp[w2-1];
923 for (x = 0; x < w2; x++) {
924 b[2*x ] = (tmp[x] + 1)>>1;
925 b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1;
929 static void horizontal_compose_dd137i(IDWTELEM *b, IDWTELEM *tmp, int w)
931 const int w2 = w >> 1;
934 tmp[0] = COMPOSE_DD137iL0(b[w2], b[w2], b[0], b[w2 ], b[w2+1]);
935 tmp[1] = COMPOSE_DD137iL0(b[w2], b[w2], b[1], b[w2+1], b[w2+2]);
936 for (x = 2; x < w2-1; x++)
937 tmp[x] = COMPOSE_DD137iL0(b[x+w2-2], b[x+w2-1], b[x], b[x+w2], b[x+w2+1]);
938 tmp[w2-1] = COMPOSE_DD137iL0(b[w-3], b[w-2], b[w2-1], b[w-1], b[w-1]);
942 tmp[w2+1] = tmp[w2] = tmp[w2-1];
944 for (x = 0; x < w2; x++) {
945 b[2*x ] = (tmp[x] + 1)>>1;
946 b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1;
950 static av_always_inline
951 void horizontal_compose_haari(IDWTELEM *b, IDWTELEM *temp, int w, int shift)
953 const int w2 = w >> 1;
956 for (x = 0; x < w2; x++) {
957 temp[x ] = COMPOSE_HAARiL0(b[x ], b[x+w2]);
958 temp[x+w2] = COMPOSE_HAARiH0(b[x+w2], temp[x]);
961 interleave(b, temp, temp+w2, w2, shift, shift);
964 static void horizontal_compose_haar0i(IDWTELEM *b, IDWTELEM *temp, int w)
966 horizontal_compose_haari(b, temp, w, 0);
969 static void horizontal_compose_haar1i(IDWTELEM *b, IDWTELEM *temp, int w)
971 horizontal_compose_haari(b, temp, w, 1);
974 static void horizontal_compose_fidelityi(IDWTELEM *b, IDWTELEM *tmp, int w)
976 const int w2 = w >> 1;
980 for (x = 0; x < w2; x++) {
981 for (i = 0; i < 8; i++)
982 v[i] = b[av_clip(x-3+i, 0, w2-1)];
983 tmp[x] = COMPOSE_FIDELITYiH0(v[0], v[1], v[2], v[3], b[x+w2], v[4], v[5], v[6], v[7]);
986 for (x = 0; x < w2; x++) {
987 for (i = 0; i < 8; i++)
988 v[i] = tmp[av_clip(x-4+i, 0, w2-1)];
989 tmp[x+w2] = COMPOSE_FIDELITYiL0(v[0], v[1], v[2], v[3], b[x], v[4], v[5], v[6], v[7]);
992 interleave(b, tmp+w2, tmp, w2, 0, 0);
995 static void horizontal_compose_daub97i(IDWTELEM *b, IDWTELEM *temp, int w)
997 const int w2 = w >> 1;
1000 temp[0] = COMPOSE_DAUB97iL1(b[w2], b[0], b[w2]);
1001 for (x = 1; x < w2; x++) {
1002 temp[x ] = COMPOSE_DAUB97iL1(b[x+w2-1], b[x ], b[x+w2]);
1003 temp[x+w2-1] = COMPOSE_DAUB97iH1(temp[x-1], b[x+w2-1], temp[x]);
1005 temp[w-1] = COMPOSE_DAUB97iH1(temp[w2-1], b[w-1], temp[w2-1]);
1007 // second stage combined with interleave and shift
1008 b0 = b2 = COMPOSE_DAUB97iL0(temp[w2], temp[0], temp[w2]);
1009 b[0] = (b0 + 1) >> 1;
1010 for (x = 1; x < w2; x++) {
1011 b2 = COMPOSE_DAUB97iL0(temp[x+w2-1], temp[x ], temp[x+w2]);
1012 b1 = COMPOSE_DAUB97iH0( b0, temp[x+w2-1], b2 );
1013 b[2*x-1] = (b1 + 1) >> 1;
1014 b[2*x ] = (b2 + 1) >> 1;
1017 b[w-1] = (COMPOSE_DAUB97iH0(b2, temp[w-1], b2) + 1) >> 1;
1020 static void vertical_compose_dirac53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1024 for(i=0; i<width; i++){
1025 b1[i] = COMPOSE_DIRAC53iH0(b0[i], b1[i], b2[i]);
1029 static void vertical_compose_dd97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
1030 IDWTELEM *b3, IDWTELEM *b4, int width)
1034 for(i=0; i<width; i++){
1035 b2[i] = COMPOSE_DD97iH0(b0[i], b1[i], b2[i], b3[i], b4[i]);
1039 static void vertical_compose_dd137iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
1040 IDWTELEM *b3, IDWTELEM *b4, int width)
1044 for(i=0; i<width; i++){
1045 b2[i] = COMPOSE_DD137iL0(b0[i], b1[i], b2[i], b3[i], b4[i]);
1049 static void vertical_compose_haar(IDWTELEM *b0, IDWTELEM *b1, int width)
1053 for (i = 0; i < width; i++) {
1054 b0[i] = COMPOSE_HAARiL0(b0[i], b1[i]);
1055 b1[i] = COMPOSE_HAARiH0(b1[i], b0[i]);
1059 static void vertical_compose_fidelityiH0(IDWTELEM *dst, IDWTELEM *b[8], int width)
1063 for(i=0; i<width; i++){
1064 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]);
1068 static void vertical_compose_fidelityiL0(IDWTELEM *dst, IDWTELEM *b[8], int width)
1072 for(i=0; i<width; i++){
1073 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]);
1077 static void vertical_compose_daub97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1081 for(i=0; i<width; i++){
1082 b1[i] = COMPOSE_DAUB97iH0(b0[i], b1[i], b2[i]);
1086 static void vertical_compose_daub97iH1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1090 for(i=0; i<width; i++){
1091 b1[i] = COMPOSE_DAUB97iH1(b0[i], b1[i], b2[i]);
1095 static void vertical_compose_daub97iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1099 for(i=0; i<width; i++){
1100 b1[i] = COMPOSE_DAUB97iL0(b0[i], b1[i], b2[i]);
1104 static void vertical_compose_daub97iL1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1108 for(i=0; i<width; i++){
1109 b1[i] = COMPOSE_DAUB97iL1(b0[i], b1[i], b2[i]);
1114 static void spatial_compose_dd97i_dy(DWTContext *d, int level, int width, int height, int stride)
1116 vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1117 vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1118 DWTCompose *cs = d->cs + level;
1122 for (i = 0; i < 6; i++)
1124 b[6] = d->buffer + av_clip(y+5, 0, height-2)*stride;
1125 b[7] = d->buffer + av_clip(y+6, 1, height-1)*stride;
1127 if(y+5<(unsigned)height) vertical_compose_l0( b[5], b[6], b[7], width);
1128 if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width);
1130 if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
1131 if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
1133 for (i = 0; i < 6; i++)
1138 static void spatial_compose_dirac53i_dy(DWTContext *d, int level, int width, int height, int stride)
1140 vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1141 vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1142 DWTCompose *cs = d->cs + level;
1145 IDWTELEM *b[4] = { cs->b[0], cs->b[1] };
1146 b[2] = d->buffer + mirror(y+1, height-1)*stride;
1147 b[3] = d->buffer + mirror(y+2, height-1)*stride;
1149 if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
1150 if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
1152 if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
1153 if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
1161 static void spatial_compose_dd137i_dy(DWTContext *d, int level, int width, int height, int stride)
1163 vertical_compose_5tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1164 vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1165 DWTCompose *cs = d->cs + level;
1169 for (i = 0; i < 8; i++)
1171 b[8] = d->buffer + av_clip(y+7, 0, height-2)*stride;
1172 b[9] = d->buffer + av_clip(y+8, 1, height-1)*stride;
1174 if(y+5<(unsigned)height) vertical_compose_l0(b[3], b[5], b[6], b[7], b[9], width);
1175 if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width);
1177 if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
1178 if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
1180 for (i = 0; i < 8; i++)
1185 // haar makes the assumption that height is even (always true for dirac)
1186 static void spatial_compose_haari_dy(DWTContext *d, int level, int width, int height, int stride)
1188 vertical_compose_2tap vertical_compose = (void*)d->vertical_compose;
1189 int y = d->cs[level].y;
1190 IDWTELEM *b0 = d->buffer + (y-1)*stride;
1191 IDWTELEM *b1 = d->buffer + (y )*stride;
1193 vertical_compose(b0, b1, width);
1194 d->horizontal_compose(b0, d->temp, width);
1195 d->horizontal_compose(b1, d->temp, width);
1197 d->cs[level].y += 2;
1200 // Don't do sliced idwt for fidelity; the 9 tap filter makes it a bit annoying
1201 // Fortunately, this filter isn't used in practice.
1202 static void spatial_compose_fidelity(DWTContext *d, int level, int width, int height, int stride)
1204 vertical_compose_9tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1205 vertical_compose_9tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1209 for (y = 1; y < height; y += 2) {
1210 for (i = 0; i < 8; i++)
1211 b[i] = d->buffer + av_clip((y-7 + 2*i), 0, height-2)*stride;
1212 vertical_compose_h0(d->buffer + y*stride, b, width);
1215 for (y = 0; y < height; y += 2) {
1216 for (i = 0; i < 8; i++)
1217 b[i] = d->buffer + av_clip((y-7 + 2*i), 1, height-1)*stride;
1218 vertical_compose_l0(d->buffer + y*stride, b, width);
1221 for (y = 0; y < height; y++)
1222 d->horizontal_compose(d->buffer + y*stride, d->temp, width);
1224 d->cs[level].y = height+1;
1227 static void spatial_compose_daub97i_dy(DWTContext *d, int level, int width, int height, int stride)
1229 vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1230 vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1231 vertical_compose_3tap vertical_compose_l1 = (void*)d->vertical_compose_l1;
1232 vertical_compose_3tap vertical_compose_h1 = (void*)d->vertical_compose_h1;
1233 DWTCompose *cs = d->cs + level;
1237 for (i = 0; i < 4; i++)
1239 b[4] = d->buffer + mirror(y+3, height-1)*stride;
1240 b[5] = d->buffer + mirror(y+4, height-1)*stride;
1242 if(y+3<(unsigned)height) vertical_compose_l1(b[3], b[4], b[5], width);
1243 if(y+2<(unsigned)height) vertical_compose_h1(b[2], b[3], b[4], width);
1244 if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
1245 if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
1247 if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
1248 if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
1250 for (i = 0; i < 4; i++)
1256 static void spatial_compose97i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
1258 cs->b[0] = buffer + mirror(-3-1, height-1)*stride;
1259 cs->b[1] = buffer + mirror(-3 , height-1)*stride;
1260 cs->b[2] = buffer + mirror(-3+1, height-1)*stride;
1261 cs->b[3] = buffer + mirror(-3+2, height-1)*stride;
1265 static void spatial_compose53i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
1267 cs->b[0] = buffer + mirror(-1-1, height-1)*stride;
1268 cs->b[1] = buffer + mirror(-1 , height-1)*stride;
1272 static void spatial_compose_dd97i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
1274 cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride;
1275 cs->b[1] = buffer + av_clip(-5 , 1, height-1)*stride;
1276 cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride;
1277 cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride;
1278 cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride;
1279 cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride;
1283 static void spatial_compose_dd137i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
1285 cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride;
1286 cs->b[1] = buffer + av_clip(-5 , 1, height-1)*stride;
1287 cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride;
1288 cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride;
1289 cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride;
1290 cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride;
1291 cs->b[6] = buffer + av_clip(-5+5, 0, height-2)*stride;
1292 cs->b[7] = buffer + av_clip(-5+6, 1, height-1)*stride;
1296 int ff_spatial_idwt_init2(DWTContext *d, IDWTELEM *buffer, int width, int height,
1297 int stride, enum dwt_type type, int decomposition_count,
1306 d->decomposition_count = decomposition_count;
1309 for(level=decomposition_count-1; level>=0; level--){
1310 int hl = height >> level;
1311 int stride_l = stride << level;
1314 case DWT_DIRAC_DD9_7:
1315 spatial_compose_dd97i_init(d->cs+level, buffer, hl, stride_l);
1317 case DWT_DIRAC_LEGALL5_3:
1318 spatial_compose53i_init2(d->cs+level, buffer, hl, stride_l);
1320 case DWT_DIRAC_DD13_7:
1321 spatial_compose_dd137i_init(d->cs+level, buffer, hl, stride_l);
1323 case DWT_DIRAC_HAAR0:
1324 case DWT_DIRAC_HAAR1:
1327 case DWT_DIRAC_DAUB9_7:
1328 spatial_compose97i_init2(d->cs+level, buffer, hl, stride_l);
1337 case DWT_DIRAC_DD9_7:
1338 d->spatial_compose = spatial_compose_dd97i_dy;
1339 d->vertical_compose_l0 = (void*)vertical_compose53iL0;
1340 d->vertical_compose_h0 = (void*)vertical_compose_dd97iH0;
1341 d->horizontal_compose = horizontal_compose_dd97i;
1344 case DWT_DIRAC_LEGALL5_3:
1345 d->spatial_compose = spatial_compose_dirac53i_dy;
1346 d->vertical_compose_l0 = (void*)vertical_compose53iL0;
1347 d->vertical_compose_h0 = (void*)vertical_compose_dirac53iH0;
1348 d->horizontal_compose = horizontal_compose_dirac53i;
1351 case DWT_DIRAC_DD13_7:
1352 d->spatial_compose = spatial_compose_dd137i_dy;
1353 d->vertical_compose_l0 = (void*)vertical_compose_dd137iL0;
1354 d->vertical_compose_h0 = (void*)vertical_compose_dd97iH0;
1355 d->horizontal_compose = horizontal_compose_dd137i;
1358 case DWT_DIRAC_HAAR0:
1359 case DWT_DIRAC_HAAR1:
1360 d->spatial_compose = spatial_compose_haari_dy;
1361 d->vertical_compose = (void*)vertical_compose_haar;
1362 if (type == DWT_DIRAC_HAAR0)
1363 d->horizontal_compose = horizontal_compose_haar0i;
1365 d->horizontal_compose = horizontal_compose_haar1i;
1368 case DWT_DIRAC_FIDELITY:
1369 d->spatial_compose = spatial_compose_fidelity;
1370 d->vertical_compose_l0 = (void*)vertical_compose_fidelityiL0;
1371 d->vertical_compose_h0 = (void*)vertical_compose_fidelityiH0;
1372 d->horizontal_compose = horizontal_compose_fidelityi;
1374 case DWT_DIRAC_DAUB9_7:
1375 d->spatial_compose = spatial_compose_daub97i_dy;
1376 d->vertical_compose_l0 = (void*)vertical_compose_daub97iL0;
1377 d->vertical_compose_h0 = (void*)vertical_compose_daub97iH0;
1378 d->vertical_compose_l1 = (void*)vertical_compose_daub97iL1;
1379 d->vertical_compose_h1 = (void*)vertical_compose_daub97iH1;
1380 d->horizontal_compose = horizontal_compose_daub97i;
1384 av_log(NULL, AV_LOG_ERROR, "Unknown wavelet type %d\n", type);
1388 if (HAVE_MMX) ff_spatial_idwt_init_mmx(d, type);
1393 void ff_spatial_idwt_slice2(DWTContext *d, int y)
1395 int level, support = d->support;
1397 for (level = d->decomposition_count-1; level >= 0; level--) {
1398 int wl = d->width >> level;
1399 int hl = d->height >> level;
1400 int stride_l = d->stride << level;
1402 while (d->cs[level].y <= FFMIN((y>>level)+support, hl))
1403 d->spatial_compose(d, level, wl, hl, stride_l);
1407 int ff_spatial_idwt2(IDWTELEM *buffer, int width, int height, int stride,
1408 enum dwt_type type, int decomposition_count, IDWTELEM *temp)
1413 if (ff_spatial_idwt_init2(&d, buffer, width, height, stride, type, decomposition_count, temp))
1416 for (y = 0; y < d.height; y += 4)
1417 ff_spatial_idwt_slice2(&d, y);