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, DWTELEM *temp, int width)
250 const int width2 = width >> 1;
252 const int w2 = (width + 1) >> 1;
254 for (x = 0; x < width2; x++) {
256 temp[x + w2] = b[2 * x + 1];
265 A1 = temp[0 + width2];
266 A1 -= (A2 + A4) >> 1;
270 for (x = 1; x + 1 < width2; x += 2) {
271 A3 = temp[x + width2];
273 A3 -= (A2 + A4) >> 1;
274 A2 += (A1 + A3 + 2) >> 2;
278 A1 = temp[x + 1 + width2];
280 A1 -= (A2 + A4) >> 1;
281 A4 += (A1 + A3 + 2) >> 2;
282 b[x + 1 + width2] = A1;
285 A3 = temp[width - 1];
287 A2 += (A1 + A3 + 2) >> 2;
292 lift(b + w2, temp + w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0);
293 lift(b, temp, b + w2, 1, 1, 1, width, 1, 2, 2, 0, 0);
297 static void vertical_decompose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
302 for (i = 0; i < width; i++)
303 b1[i] -= (b0[i] + b2[i]) >> 1;
306 static void vertical_decompose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
311 for (i = 0; i < width; i++)
312 b1[i] += (b0[i] + b2[i] + 2) >> 2;
315 static void spatial_decompose53i(DWTELEM *buffer, DWTELEM *temp,
316 int width, int height, int stride)
319 DWTELEM *b0 = buffer + mirror(-2 - 1, height - 1) * stride;
320 DWTELEM *b1 = buffer + mirror(-2, height - 1) * stride;
322 for (y = -2; y < height; y += 2) {
323 DWTELEM *b2 = buffer + mirror(y + 1, height - 1) * stride;
324 DWTELEM *b3 = buffer + mirror(y + 2, height - 1) * stride;
326 if (y + 1 < (unsigned)height)
327 horizontal_decompose53i(b2, temp, width);
328 if (y + 2 < (unsigned)height)
329 horizontal_decompose53i(b3, temp, width);
331 if (y + 1 < (unsigned)height)
332 vertical_decompose53iH0(b1, b2, b3, width);
333 if (y + 0 < (unsigned)height)
334 vertical_decompose53iL0(b0, b1, b2, width);
341 static void horizontal_decompose97i(DWTELEM *b, DWTELEM *temp, int width)
343 const int w2 = (width + 1) >> 1;
345 lift(temp + w2, b + 1, b, 1, 2, 2, width, W_AM, W_AO, W_AS, 1, 1);
346 liftS(temp, b, temp + w2, 1, 2, 1, width, W_BM, W_BO, W_BS, 0, 0);
347 lift(b + w2, temp + w2, temp, 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 0);
348 lift(b, temp, b + w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 0);
351 static void vertical_decompose97iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
356 for (i = 0; i < width; i++)
357 b1[i] -= (W_AM * (b0[i] + b2[i]) + W_AO) >> W_AS;
360 static void vertical_decompose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
365 for (i = 0; i < width; i++)
366 b1[i] += (W_CM * (b0[i] + b2[i]) + W_CO) >> W_CS;
369 static void vertical_decompose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
374 for (i = 0; i < width; i++)
376 b1[i] -= (W_BM * (b0[i] + b2[i]) + W_BO) >> W_BS;
378 b1[i] = (16 * 4 * b1[i] - 4 * (b0[i] + b2[i]) + W_BO * 5 + (5 << 27)) /
379 (5 * 16) - (1 << 23);
383 static void vertical_decompose97iL1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
388 for (i = 0; i < width; i++)
389 b1[i] += (W_DM * (b0[i] + b2[i]) + W_DO) >> W_DS;
392 static void spatial_decompose97i(DWTELEM *buffer, DWTELEM *temp,
393 int width, int height, int stride)
396 DWTELEM *b0 = buffer + mirror(-4 - 1, height - 1) * stride;
397 DWTELEM *b1 = buffer + mirror(-4, height - 1) * stride;
398 DWTELEM *b2 = buffer + mirror(-4 + 1, height - 1) * stride;
399 DWTELEM *b3 = buffer + mirror(-4 + 2, height - 1) * stride;
401 for (y = -4; y < height; y += 2) {
402 DWTELEM *b4 = buffer + mirror(y + 3, height - 1) * stride;
403 DWTELEM *b5 = buffer + mirror(y + 4, height - 1) * stride;
405 if (y + 3 < (unsigned)height)
406 horizontal_decompose97i(b4, temp, width);
407 if (y + 4 < (unsigned)height)
408 horizontal_decompose97i(b5, temp, width);
410 if (y + 3 < (unsigned)height)
411 vertical_decompose97iH0(b3, b4, b5, width);
412 if (y + 2 < (unsigned)height)
413 vertical_decompose97iL0(b2, b3, b4, width);
414 if (y + 1 < (unsigned)height)
415 vertical_decompose97iH1(b1, b2, b3, width);
416 if (y + 0 < (unsigned)height)
417 vertical_decompose97iL1(b0, b1, b2, width);
426 void ff_spatial_dwt(DWTELEM *buffer, DWTELEM *temp, int width, int height,
427 int stride, int type, int decomposition_count)
431 for (level = 0; level < decomposition_count; level++) {
434 spatial_decompose97i(buffer, temp,
435 width >> level, height >> level,
439 spatial_decompose53i(buffer, temp,
440 width >> level, height >> level,
447 static void horizontal_compose53i(IDWTELEM *b, IDWTELEM *temp, int width)
449 const int width2 = width >> 1;
450 const int w2 = (width + 1) >> 1;
453 for (x = 0; x < width2; x++) {
455 temp[2 * x + 1] = b[x + w2];
460 b[0] = temp[0] - ((temp[1] + 1) >> 1);
461 for (x = 2; x < width - 1; x += 2) {
462 b[x] = temp[x] - ((temp[x - 1] + temp[x + 1] + 2) >> 2);
463 b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1);
466 b[x] = temp[x] - ((temp[x - 1] + 1) >> 1);
467 b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1);
469 b[x - 1] = temp[x - 1] + b[x - 2];
472 static void vertical_compose53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
477 for (i = 0; i < width; i++)
478 b1[i] += (b0[i] + b2[i]) >> 1;
481 static void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
486 for (i = 0; i < width; i++)
487 b1[i] -= (b0[i] + b2[i] + 2) >> 2;
490 static void spatial_compose53i_buffered_init(DWTCompose *cs, slice_buffer *sb,
491 int height, int stride_line)
493 cs->b0 = slice_buffer_get_line(sb,
494 mirror(-1 - 1, height - 1) * stride_line);
495 cs->b1 = slice_buffer_get_line(sb, mirror(-1, height - 1) * stride_line);
499 static void spatial_compose53i_init(DWTCompose *cs, IDWTELEM *buffer,
500 int height, int stride)
502 cs->b0 = buffer + mirror(-1 - 1, height - 1) * stride;
503 cs->b1 = buffer + mirror(-1, height - 1) * stride;
507 static void spatial_compose53i_dy_buffered(DWTCompose *cs, slice_buffer *sb,
509 int width, int height,
514 IDWTELEM *b0 = cs->b0;
515 IDWTELEM *b1 = cs->b1;
516 IDWTELEM *b2 = slice_buffer_get_line(sb,
517 mirror(y + 1, height - 1) *
519 IDWTELEM *b3 = slice_buffer_get_line(sb,
520 mirror(y + 2, height - 1) *
523 if (y + 1 < (unsigned)height && y < (unsigned)height) {
526 for (x = 0; x < width; x++) {
527 b2[x] -= (b1[x] + b3[x] + 2) >> 2;
528 b1[x] += (b0[x] + b2[x]) >> 1;
531 if (y + 1 < (unsigned)height)
532 vertical_compose53iL0(b1, b2, b3, width);
533 if (y + 0 < (unsigned)height)
534 vertical_compose53iH0(b0, b1, b2, width);
537 if (y - 1 < (unsigned)height)
538 horizontal_compose53i(b0, temp, width);
539 if (y + 0 < (unsigned)height)
540 horizontal_compose53i(b1, temp, width);
547 static void spatial_compose53i_dy(DWTCompose *cs, IDWTELEM *buffer,
548 IDWTELEM *temp, int width, int height,
552 IDWTELEM *b0 = cs->b0;
553 IDWTELEM *b1 = cs->b1;
554 IDWTELEM *b2 = buffer + mirror(y + 1, height - 1) * stride;
555 IDWTELEM *b3 = buffer + mirror(y + 2, height - 1) * stride;
557 if (y + 1 < (unsigned)height)
558 vertical_compose53iL0(b1, b2, b3, width);
559 if (y + 0 < (unsigned)height)
560 vertical_compose53iH0(b0, b1, b2, width);
562 if (y - 1 < (unsigned)height)
563 horizontal_compose53i(b0, temp, width);
564 if (y + 0 < (unsigned)height)
565 horizontal_compose53i(b1, temp, width);
572 static void av_unused spatial_compose53i(IDWTELEM *buffer, IDWTELEM *temp,
573 int width, int height, int stride)
576 spatial_compose53i_init(&cs, buffer, height, stride);
577 while (cs.y <= height)
578 spatial_compose53i_dy(&cs, buffer, temp, width, height, stride);
581 void ff_snow_horizontal_compose97i(IDWTELEM *b, IDWTELEM *temp, int width)
583 const int w2 = (width + 1) >> 1;
585 #if 0 //maybe more understadable but slower
586 inv_lift(temp, b, b + w2, 2, 1, 1, width, W_DM, W_DO, W_DS, 0, 1);
587 inv_lift(temp + 1, b + w2, temp, 2, 1, 2, width, W_CM, W_CO, W_CS, 1, 1);
589 inv_liftS(b, temp, temp + 1, 2, 2, 2, width, W_BM, W_BO, W_BS, 0, 1);
590 inv_lift(b + 1, temp + 1, b, 2, 2, 2, width, W_AM, W_AO, W_AS, 1, 0);
593 temp[0] = b[0] - ((3 * b[w2] + 2) >> 2);
594 for (x = 1; x < (width >> 1); x++) {
595 temp[2 * x] = b[x] - ((3 * (b[x + w2 - 1] + b[x + w2]) + 4) >> 3);
596 temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x];
599 temp[2 * x] = b[x] - ((3 * b[x + w2 - 1] + 2) >> 2);
600 temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x];
602 temp[2 * x - 1] = b[x + w2 - 1] - 2 * temp[2 * x - 2];
604 b[0] = temp[0] + ((2 * temp[0] + temp[1] + 4) >> 3);
605 for (x = 2; x < width - 1; x += 2) {
606 b[x] = temp[x] + ((4 * temp[x] + temp[x - 1] + temp[x + 1] + 8) >> 4);
607 b[x - 1] = temp[x - 1] + ((3 * (b[x - 2] + b[x])) >> 1);
610 b[x] = temp[x] + ((2 * temp[x] + temp[x - 1] + 4) >> 3);
611 b[x - 1] = temp[x - 1] + ((3 * (b[x - 2] + b[x])) >> 1);
613 b[x - 1] = temp[x - 1] + 3 * b[x - 2];
617 static void vertical_compose97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
622 for (i = 0; i < width; i++)
623 b1[i] += (W_AM * (b0[i] + b2[i]) + W_AO) >> W_AS;
626 static void vertical_compose97iH1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
631 for (i = 0; i < width; i++)
632 b1[i] -= (W_CM * (b0[i] + b2[i]) + W_CO) >> W_CS;
635 static void vertical_compose97iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
640 for (i = 0; i < width; i++)
642 b1[i] += (W_BM * (b0[i] + b2[i]) + W_BO) >> W_BS;
644 b1[i] += (W_BM * (b0[i] + b2[i]) + 4 * b1[i] + W_BO) >> W_BS;
648 static void vertical_compose97iL1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
653 for (i = 0; i < width; i++)
654 b1[i] -= (W_DM * (b0[i] + b2[i]) + W_DO) >> W_DS;
657 void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
658 IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5,
663 for (i = 0; i < width; i++) {
664 b4[i] -= (W_DM * (b3[i] + b5[i]) + W_DO) >> W_DS;
665 b3[i] -= (W_CM * (b2[i] + b4[i]) + W_CO) >> W_CS;
667 b2[i] += (W_BM * (b1[i] + b3[i]) + W_BO) >> W_BS;
669 b2[i] += (W_BM * (b1[i] + b3[i]) + 4 * b2[i] + W_BO) >> W_BS;
671 b1[i] += (W_AM * (b0[i] + b2[i]) + W_AO) >> W_AS;
675 static void spatial_compose97i_buffered_init(DWTCompose *cs, slice_buffer *sb,
676 int height, int stride_line)
678 cs->b0 = slice_buffer_get_line(sb, mirror(-3 - 1, height - 1) * stride_line);
679 cs->b1 = slice_buffer_get_line(sb, mirror(-3, height - 1) * stride_line);
680 cs->b2 = slice_buffer_get_line(sb, mirror(-3 + 1, height - 1) * stride_line);
681 cs->b3 = slice_buffer_get_line(sb, mirror(-3 + 2, height - 1) * stride_line);
685 static void spatial_compose97i_init(DWTCompose *cs, IDWTELEM *buffer, int height,
688 cs->b0 = buffer + mirror(-3 - 1, height - 1) * stride;
689 cs->b1 = buffer + mirror(-3, height - 1) * stride;
690 cs->b2 = buffer + mirror(-3 + 1, height - 1) * stride;
691 cs->b3 = buffer + mirror(-3 + 2, height - 1) * stride;
695 static void spatial_compose97i_dy_buffered(DWTContext *dsp, DWTCompose *cs,
696 slice_buffer * sb, IDWTELEM *temp,
697 int width, int height,
702 IDWTELEM *b0 = cs->b0;
703 IDWTELEM *b1 = cs->b1;
704 IDWTELEM *b2 = cs->b2;
705 IDWTELEM *b3 = cs->b3;
706 IDWTELEM *b4 = slice_buffer_get_line(sb,
707 mirror(y + 3, height - 1) *
709 IDWTELEM *b5 = slice_buffer_get_line(sb,
710 mirror(y + 4, height - 1) *
713 if (y > 0 && y + 4 < height) {
714 dsp->vertical_compose97i(b0, b1, b2, b3, b4, b5, width);
716 if (y + 3 < (unsigned)height)
717 vertical_compose97iL1(b3, b4, b5, width);
718 if (y + 2 < (unsigned)height)
719 vertical_compose97iH1(b2, b3, b4, width);
720 if (y + 1 < (unsigned)height)
721 vertical_compose97iL0(b1, b2, b3, width);
722 if (y + 0 < (unsigned)height)
723 vertical_compose97iH0(b0, b1, b2, width);
726 if (y - 1 < (unsigned)height)
727 dsp->horizontal_compose97i(b0, temp, width);
728 if (y + 0 < (unsigned)height)
729 dsp->horizontal_compose97i(b1, temp, width);
738 static void spatial_compose97i_dy(DWTCompose *cs, IDWTELEM *buffer,
739 IDWTELEM *temp, int width, int height,
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, temp, width);
761 if (y + 0 < (unsigned)height)
762 ff_snow_horizontal_compose97i(b1, temp, width);
771 static void av_unused spatial_compose97i(IDWTELEM *buffer, IDWTELEM *temp,
772 int width, int height, int stride)
775 spatial_compose97i_init(&cs, buffer, height, stride);
776 while (cs.y <= height)
777 spatial_compose97i_dy(&cs, buffer, temp, 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, IDWTELEM *temp,
801 int width, int height, int stride_line,
802 int type, 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, temp,
816 stride_line << level);
819 spatial_compose53i_dy_buffered(cs + level, slice_buf, temp,
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,
848 IDWTELEM *temp, int width, int height,
849 int stride, int type,
850 int decomposition_count, int y)
852 const int support = type == 1 ? 3 : 5;
857 for (level = decomposition_count - 1; level >= 0; level--)
858 while (cs[level].y <= FFMIN((y >> level) + support, height >> level)) {
861 spatial_compose97i_dy(cs + level, buffer, temp, width >> level,
862 height >> level, stride << level);
865 spatial_compose53i_dy(cs + level, buffer, temp, width >> level,
866 height >> level, stride << level);
872 void ff_spatial_idwt(IDWTELEM *buffer, IDWTELEM *temp, int width, int height,
873 int stride, int type, int decomposition_count)
875 DWTCompose cs[MAX_DECOMPOSITIONS];
877 ff_spatial_idwt_init(cs, buffer, width, height, stride, type,
878 decomposition_count);
879 for (y = 0; y < height; y += 4)
880 ff_spatial_idwt_slice(cs, buffer, temp, width, height, stride, type,
881 decomposition_count, y);
884 static inline int w_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size,
885 int w, int h, int type)
888 const int dec_count = w == 8 ? 3 : 4;
889 int tmp[32 * 32], tmp2[32];
891 static const int scale[2][2][4][4] = {
894 { 268, 239, 239, 213 },
895 { 0, 224, 224, 152 },
896 { 0, 135, 135, 110 },
898 { // 9/7 16x16 or 32x32 dec=4
899 { 344, 310, 310, 280 },
900 { 0, 320, 320, 228 },
901 { 0, 175, 175, 136 },
902 { 0, 129, 129, 102 },
907 { 275, 245, 245, 218 },
908 { 0, 230, 230, 156 },
909 { 0, 138, 138, 113 },
911 { // 5/3 16x16 or 32x32 dec=4
912 { 352, 317, 317, 286 },
913 { 0, 328, 328, 233 },
914 { 0, 180, 180, 140 },
915 { 0, 132, 132, 105 },
920 for (i = 0; i < h; i++) {
921 for (j = 0; j < w; j += 4) {
922 tmp[32 * i + j + 0] = (pix1[j + 0] - pix2[j + 0]) << 4;
923 tmp[32 * i + j + 1] = (pix1[j + 1] - pix2[j + 1]) << 4;
924 tmp[32 * i + j + 2] = (pix1[j + 2] - pix2[j + 2]) << 4;
925 tmp[32 * i + j + 3] = (pix1[j + 3] - pix2[j + 3]) << 4;
931 ff_spatial_dwt(tmp, tmp2, w, h, 32, type, dec_count);
935 for (level = 0; level < dec_count; level++)
936 for (ori = level ? 1 : 0; ori < 4; ori++) {
937 int size = w >> (dec_count - level);
938 int sx = (ori & 1) ? size : 0;
939 int stride = 32 << (dec_count - level);
940 int sy = (ori & 2) ? stride >> 1 : 0;
942 for (i = 0; i < size; i++)
943 for (j = 0; j < size; j++) {
944 int v = tmp[sx + sy + i * stride + j] *
945 scale[type][dec_count - 3][level][ori];
953 static int w53_8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
955 return w_c(v, pix1, pix2, line_size, 8, h, 1);
958 static int w97_8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
960 return w_c(v, pix1, pix2, line_size, 8, h, 0);
963 static int w53_16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
965 return w_c(v, pix1, pix2, line_size, 16, h, 1);
968 static int w97_16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
970 return w_c(v, pix1, pix2, line_size, 16, h, 0);
973 int ff_w53_32_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
975 return w_c(v, pix1, pix2, line_size, 32, h, 1);
978 int ff_w97_32_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
980 return w_c(v, pix1, pix2, line_size, 32, h, 0);
983 void ff_dsputil_init_dwt(DSPContext *c)
985 c->w53[0] = w53_16_c;
987 c->w97[0] = w97_16_c;
991 void ff_dwt_init(DWTContext *c)
993 c->vertical_compose97i = ff_snow_vertical_compose97i;
994 c->horizontal_compose97i = ff_snow_horizontal_compose97i;
995 c->inner_add_yblock = ff_snow_inner_add_yblock;
1002 static av_always_inline
1003 void interleave(IDWTELEM *dst, IDWTELEM *src0, IDWTELEM *src1, int w2, int add, int shift)
1006 for (i = 0; i < w2; i++) {
1007 dst[2*i ] = (src0[i] + add) >> shift;
1008 dst[2*i+1] = (src1[i] + add) >> shift;
1012 static void horizontal_compose_dirac53i(IDWTELEM *b, IDWTELEM *temp, int w)
1014 const int w2 = w >> 1;
1017 temp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]);
1018 for (x = 1; x < w2; x++) {
1019 temp[x ] = COMPOSE_53iL0 (b[x+w2-1], b[x ], b[x+w2]);
1020 temp[x+w2-1] = COMPOSE_DIRAC53iH0(temp[x-1], b[x+w2-1], temp[x]);
1022 temp[w-1] = COMPOSE_DIRAC53iH0(temp[w2-1], b[w-1], temp[w2-1]);
1024 interleave(b, temp, temp+w2, w2, 1, 1);
1027 static void horizontal_compose_dd97i(IDWTELEM *b, IDWTELEM *tmp, int w)
1029 const int w2 = w >> 1;
1032 tmp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]);
1033 for (x = 1; x < w2; x++)
1034 tmp[x] = COMPOSE_53iL0(b[x+w2-1], b[x], b[x+w2]);
1038 tmp[w2+1] = tmp[w2] = tmp[w2-1];
1040 for (x = 0; x < w2; x++) {
1041 b[2*x ] = (tmp[x] + 1)>>1;
1042 b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1;
1046 static void horizontal_compose_dd137i(IDWTELEM *b, IDWTELEM *tmp, int w)
1048 const int w2 = w >> 1;
1051 tmp[0] = COMPOSE_DD137iL0(b[w2], b[w2], b[0], b[w2 ], b[w2+1]);
1052 tmp[1] = COMPOSE_DD137iL0(b[w2], b[w2], b[1], b[w2+1], b[w2+2]);
1053 for (x = 2; x < w2-1; x++)
1054 tmp[x] = COMPOSE_DD137iL0(b[x+w2-2], b[x+w2-1], b[x], b[x+w2], b[x+w2+1]);
1055 tmp[w2-1] = COMPOSE_DD137iL0(b[w-3], b[w-2], b[w2-1], b[w-1], b[w-1]);
1059 tmp[w2+1] = tmp[w2] = tmp[w2-1];
1061 for (x = 0; x < w2; x++) {
1062 b[2*x ] = (tmp[x] + 1)>>1;
1063 b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1;
1067 static av_always_inline
1068 void horizontal_compose_haari(IDWTELEM *b, IDWTELEM *temp, int w, int shift)
1070 const int w2 = w >> 1;
1073 for (x = 0; x < w2; x++) {
1074 temp[x ] = COMPOSE_HAARiL0(b[x ], b[x+w2]);
1075 temp[x+w2] = COMPOSE_HAARiH0(b[x+w2], temp[x]);
1078 interleave(b, temp, temp+w2, w2, shift, shift);
1081 static void horizontal_compose_haar0i(IDWTELEM *b, IDWTELEM *temp, int w)
1083 horizontal_compose_haari(b, temp, w, 0);
1086 static void horizontal_compose_haar1i(IDWTELEM *b, IDWTELEM *temp, int w)
1088 horizontal_compose_haari(b, temp, w, 1);
1091 static void horizontal_compose_fidelityi(IDWTELEM *b, IDWTELEM *tmp, int w)
1093 const int w2 = w >> 1;
1097 for (x = 0; x < w2; x++) {
1098 for (i = 0; i < 8; i++)
1099 v[i] = b[av_clip(x-3+i, 0, w2-1)];
1100 tmp[x] = COMPOSE_FIDELITYiH0(v[0], v[1], v[2], v[3], b[x+w2], v[4], v[5], v[6], v[7]);
1103 for (x = 0; x < w2; x++) {
1104 for (i = 0; i < 8; i++)
1105 v[i] = tmp[av_clip(x-4+i, 0, w2-1)];
1106 tmp[x+w2] = COMPOSE_FIDELITYiL0(v[0], v[1], v[2], v[3], b[x], v[4], v[5], v[6], v[7]);
1109 interleave(b, tmp+w2, tmp, w2, 0, 0);
1112 static void horizontal_compose_daub97i(IDWTELEM *b, IDWTELEM *temp, int w)
1114 const int w2 = w >> 1;
1117 temp[0] = COMPOSE_DAUB97iL1(b[w2], b[0], b[w2]);
1118 for (x = 1; x < w2; x++) {
1119 temp[x ] = COMPOSE_DAUB97iL1(b[x+w2-1], b[x ], b[x+w2]);
1120 temp[x+w2-1] = COMPOSE_DAUB97iH1(temp[x-1], b[x+w2-1], temp[x]);
1122 temp[w-1] = COMPOSE_DAUB97iH1(temp[w2-1], b[w-1], temp[w2-1]);
1124 // second stage combined with interleave and shift
1125 b0 = b2 = COMPOSE_DAUB97iL0(temp[w2], temp[0], temp[w2]);
1126 b[0] = (b0 + 1) >> 1;
1127 for (x = 1; x < w2; x++) {
1128 b2 = COMPOSE_DAUB97iL0(temp[x+w2-1], temp[x ], temp[x+w2]);
1129 b1 = COMPOSE_DAUB97iH0( b0, temp[x+w2-1], b2 );
1130 b[2*x-1] = (b1 + 1) >> 1;
1131 b[2*x ] = (b2 + 1) >> 1;
1134 b[w-1] = (COMPOSE_DAUB97iH0(b2, temp[w-1], b2) + 1) >> 1;
1137 static void vertical_compose_dirac53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1141 for(i=0; i<width; i++){
1142 b1[i] = COMPOSE_DIRAC53iH0(b0[i], b1[i], b2[i]);
1146 static void vertical_compose_dd97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
1147 IDWTELEM *b3, IDWTELEM *b4, int width)
1151 for(i=0; i<width; i++){
1152 b2[i] = COMPOSE_DD97iH0(b0[i], b1[i], b2[i], b3[i], b4[i]);
1156 static void vertical_compose_dd137iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
1157 IDWTELEM *b3, IDWTELEM *b4, int width)
1161 for(i=0; i<width; i++){
1162 b2[i] = COMPOSE_DD137iL0(b0[i], b1[i], b2[i], b3[i], b4[i]);
1166 static void vertical_compose_haar(IDWTELEM *b0, IDWTELEM *b1, int width)
1170 for (i = 0; i < width; i++) {
1171 b0[i] = COMPOSE_HAARiL0(b0[i], b1[i]);
1172 b1[i] = COMPOSE_HAARiH0(b1[i], b0[i]);
1176 static void vertical_compose_fidelityiH0(IDWTELEM *dst, IDWTELEM *b[8], int width)
1180 for(i=0; i<width; i++){
1181 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]);
1185 static void vertical_compose_fidelityiL0(IDWTELEM *dst, IDWTELEM *b[8], int width)
1189 for(i=0; i<width; i++){
1190 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]);
1194 static void vertical_compose_daub97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1198 for(i=0; i<width; i++){
1199 b1[i] = COMPOSE_DAUB97iH0(b0[i], b1[i], b2[i]);
1203 static void vertical_compose_daub97iH1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1207 for(i=0; i<width; i++){
1208 b1[i] = COMPOSE_DAUB97iH1(b0[i], b1[i], b2[i]);
1212 static void vertical_compose_daub97iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1216 for(i=0; i<width; i++){
1217 b1[i] = COMPOSE_DAUB97iL0(b0[i], b1[i], b2[i]);
1221 static void vertical_compose_daub97iL1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1225 for(i=0; i<width; i++){
1226 b1[i] = COMPOSE_DAUB97iL1(b0[i], b1[i], b2[i]);
1231 static void spatial_compose_dd97i_dy(DWTContext *d, int level, int width, int height, int stride)
1233 vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1234 vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1235 DWTCompose *cs = d->cs + level;
1239 for (i = 0; i < 6; i++)
1241 b[6] = d->buffer + av_clip(y+5, 0, height-2)*stride;
1242 b[7] = d->buffer + av_clip(y+6, 1, height-1)*stride;
1244 if(y+5<(unsigned)height) vertical_compose_l0( b[5], b[6], b[7], width);
1245 if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], 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 < 6; i++)
1255 static void spatial_compose_dirac53i_dy(DWTContext *d, int level, int width, int height, int stride)
1257 vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1258 vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1259 DWTCompose *cs = d->cs + level;
1262 IDWTELEM *b[4] = { cs->b[0], cs->b[1] };
1263 b[2] = d->buffer + mirror(y+1, height-1)*stride;
1264 b[3] = d->buffer + mirror(y+2, height-1)*stride;
1266 if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
1267 if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
1269 if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
1270 if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
1278 static void spatial_compose_dd137i_dy(DWTContext *d, int level, int width, int height, int stride)
1280 vertical_compose_5tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1281 vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1282 DWTCompose *cs = d->cs + level;
1286 for (i = 0; i < 8; i++)
1288 b[8] = d->buffer + av_clip(y+7, 0, height-2)*stride;
1289 b[9] = d->buffer + av_clip(y+8, 1, height-1)*stride;
1291 if(y+5<(unsigned)height) vertical_compose_l0(b[3], b[5], b[6], b[7], b[9], width);
1292 if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width);
1294 if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
1295 if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
1297 for (i = 0; i < 8; i++)
1302 // haar makes the assumption that height is even (always true for dirac)
1303 static void spatial_compose_haari_dy(DWTContext *d, int level, int width, int height, int stride)
1305 vertical_compose_2tap vertical_compose = (void*)d->vertical_compose;
1306 int y = d->cs[level].y;
1307 IDWTELEM *b0 = d->buffer + (y-1)*stride;
1308 IDWTELEM *b1 = d->buffer + (y )*stride;
1310 vertical_compose(b0, b1, width);
1311 d->horizontal_compose(b0, d->temp, width);
1312 d->horizontal_compose(b1, d->temp, width);
1314 d->cs[level].y += 2;
1317 // Don't do sliced idwt for fidelity; the 9 tap filter makes it a bit annoying
1318 // Fortunately, this filter isn't used in practice.
1319 static void spatial_compose_fidelity(DWTContext *d, int level, int width, int height, int stride)
1321 vertical_compose_9tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1322 vertical_compose_9tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1326 for (y = 1; y < height; y += 2) {
1327 for (i = 0; i < 8; i++)
1328 b[i] = d->buffer + av_clip((y-7 + 2*i), 0, height-2)*stride;
1329 vertical_compose_h0(d->buffer + y*stride, b, width);
1332 for (y = 0; y < height; y += 2) {
1333 for (i = 0; i < 8; i++)
1334 b[i] = d->buffer + av_clip((y-7 + 2*i), 1, height-1)*stride;
1335 vertical_compose_l0(d->buffer + y*stride, b, width);
1338 for (y = 0; y < height; y++)
1339 d->horizontal_compose(d->buffer + y*stride, d->temp, width);
1341 d->cs[level].y = height+1;
1344 static void spatial_compose_daub97i_dy(DWTContext *d, int level, int width, int height, int stride)
1346 vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1347 vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1348 vertical_compose_3tap vertical_compose_l1 = (void*)d->vertical_compose_l1;
1349 vertical_compose_3tap vertical_compose_h1 = (void*)d->vertical_compose_h1;
1350 DWTCompose *cs = d->cs + level;
1354 for (i = 0; i < 4; i++)
1356 b[4] = d->buffer + mirror(y+3, height-1)*stride;
1357 b[5] = d->buffer + mirror(y+4, height-1)*stride;
1359 if(y+3<(unsigned)height) vertical_compose_l1(b[3], b[4], b[5], width);
1360 if(y+2<(unsigned)height) vertical_compose_h1(b[2], b[3], b[4], width);
1361 if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
1362 if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
1364 if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
1365 if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
1367 for (i = 0; i < 4; i++)
1373 static void spatial_compose97i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
1375 cs->b[0] = buffer + mirror(-3-1, height-1)*stride;
1376 cs->b[1] = buffer + mirror(-3 , height-1)*stride;
1377 cs->b[2] = buffer + mirror(-3+1, height-1)*stride;
1378 cs->b[3] = buffer + mirror(-3+2, height-1)*stride;
1382 static void spatial_compose53i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
1384 cs->b[0] = buffer + mirror(-1-1, height-1)*stride;
1385 cs->b[1] = buffer + mirror(-1 , height-1)*stride;
1389 static void spatial_compose_dd97i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
1391 cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride;
1392 cs->b[1] = buffer + av_clip(-5 , 1, height-1)*stride;
1393 cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride;
1394 cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride;
1395 cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride;
1396 cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride;
1400 static void spatial_compose_dd137i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
1402 cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride;
1403 cs->b[1] = buffer + av_clip(-5 , 1, height-1)*stride;
1404 cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride;
1405 cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride;
1406 cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride;
1407 cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride;
1408 cs->b[6] = buffer + av_clip(-5+5, 0, height-2)*stride;
1409 cs->b[7] = buffer + av_clip(-5+6, 1, height-1)*stride;
1413 int ff_spatial_idwt_init2(DWTContext *d, IDWTELEM *buffer, int width, int height,
1414 int stride, enum dwt_type type, int decomposition_count,
1423 d->decomposition_count = decomposition_count;
1426 for(level=decomposition_count-1; level>=0; level--){
1427 int hl = height >> level;
1428 int stride_l = stride << level;
1431 case DWT_DIRAC_DD9_7:
1432 spatial_compose_dd97i_init(d->cs+level, buffer, hl, stride_l);
1434 case DWT_DIRAC_LEGALL5_3:
1435 spatial_compose53i_init2(d->cs+level, buffer, hl, stride_l);
1437 case DWT_DIRAC_DD13_7:
1438 spatial_compose_dd137i_init(d->cs+level, buffer, hl, stride_l);
1440 case DWT_DIRAC_HAAR0:
1441 case DWT_DIRAC_HAAR1:
1444 case DWT_DIRAC_DAUB9_7:
1445 spatial_compose97i_init2(d->cs+level, buffer, hl, stride_l);
1454 case DWT_DIRAC_DD9_7:
1455 d->spatial_compose = spatial_compose_dd97i_dy;
1456 d->vertical_compose_l0 = (void*)vertical_compose53iL0;
1457 d->vertical_compose_h0 = (void*)vertical_compose_dd97iH0;
1458 d->horizontal_compose = horizontal_compose_dd97i;
1461 case DWT_DIRAC_LEGALL5_3:
1462 d->spatial_compose = spatial_compose_dirac53i_dy;
1463 d->vertical_compose_l0 = (void*)vertical_compose53iL0;
1464 d->vertical_compose_h0 = (void*)vertical_compose_dirac53iH0;
1465 d->horizontal_compose = horizontal_compose_dirac53i;
1468 case DWT_DIRAC_DD13_7:
1469 d->spatial_compose = spatial_compose_dd137i_dy;
1470 d->vertical_compose_l0 = (void*)vertical_compose_dd137iL0;
1471 d->vertical_compose_h0 = (void*)vertical_compose_dd97iH0;
1472 d->horizontal_compose = horizontal_compose_dd137i;
1475 case DWT_DIRAC_HAAR0:
1476 case DWT_DIRAC_HAAR1:
1477 d->spatial_compose = spatial_compose_haari_dy;
1478 d->vertical_compose = (void*)vertical_compose_haar;
1479 if (type == DWT_DIRAC_HAAR0)
1480 d->horizontal_compose = horizontal_compose_haar0i;
1482 d->horizontal_compose = horizontal_compose_haar1i;
1485 case DWT_DIRAC_FIDELITY:
1486 d->spatial_compose = spatial_compose_fidelity;
1487 d->vertical_compose_l0 = (void*)vertical_compose_fidelityiL0;
1488 d->vertical_compose_h0 = (void*)vertical_compose_fidelityiH0;
1489 d->horizontal_compose = horizontal_compose_fidelityi;
1491 case DWT_DIRAC_DAUB9_7:
1492 d->spatial_compose = spatial_compose_daub97i_dy;
1493 d->vertical_compose_l0 = (void*)vertical_compose_daub97iL0;
1494 d->vertical_compose_h0 = (void*)vertical_compose_daub97iH0;
1495 d->vertical_compose_l1 = (void*)vertical_compose_daub97iL1;
1496 d->vertical_compose_h1 = (void*)vertical_compose_daub97iH1;
1497 d->horizontal_compose = horizontal_compose_daub97i;
1501 av_log(NULL, AV_LOG_ERROR, "Unknown wavelet type %d\n", type);
1505 if (HAVE_MMX) ff_spatial_idwt_init_mmx(d, type);
1510 void ff_spatial_idwt_slice2(DWTContext *d, int y)
1512 int level, support = d->support;
1514 for (level = d->decomposition_count-1; level >= 0; level--) {
1515 int wl = d->width >> level;
1516 int hl = d->height >> level;
1517 int stride_l = d->stride << level;
1519 while (d->cs[level].y <= FFMIN((y>>level)+support, hl))
1520 d->spatial_compose(d, level, wl, hl, stride_l);
1524 int ff_spatial_idwt2(IDWTELEM *buffer, int width, int height, int stride,
1525 enum dwt_type type, int decomposition_count, IDWTELEM *temp)
1530 if (ff_spatial_idwt_init2(&d, buffer, width, height, stride, type, decomposition_count, temp))
1533 for (y = 0; y < d.height; y += 4)
1534 ff_spatial_idwt_slice2(&d, y);