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 inv_lift(IDWTELEM *dst, IDWTELEM *src, IDWTELEM *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 #define LIFT(src, ref, inv) ((src) + ((inv) ? -(ref) : +(ref)))
163 dst[0] = LIFT(src[0], ((mul * 2 * ref[0] + add) >> shift), inverse);
168 for (i = 0; i < w; i++)
169 dst[i * dst_step] = LIFT(src[i * src_step],
170 ((mul * (ref[i * ref_step] +
171 ref[(i + 1) * ref_step]) +
176 dst[w * dst_step] = LIFT(src[w * src_step],
177 ((mul * 2 * ref[w * ref_step] + add) >> shift),
183 static av_always_inline void liftS(DWTELEM *dst, DWTELEM *src, DWTELEM *ref,
184 int dst_step, int src_step, int ref_step,
185 int width, int mul, int add, int shift,
186 int highpass, int inverse)
188 const int mirror_left = !highpass;
189 const int mirror_right = (width & 1) ^ highpass;
190 const int w = (width >> 1) - 1 + (highpass & width);
193 av_assert1(shift == 4);
194 #define LIFTS(src, ref, inv) \
195 ((inv) ? (src) + (((ref) + 4 * (src)) >> shift) \
196 : -((-16 * (src) + (ref) + add / \
197 4 + 1 + (5 << 25)) / (5 * 4) - (1 << 23)))
199 dst[0] = LIFTS(src[0], mul * 2 * ref[0] + add, inverse);
204 for (i = 0; i < w; i++)
205 dst[i * dst_step] = LIFTS(src[i * src_step],
206 mul * (ref[i * ref_step] +
207 ref[(i + 1) * ref_step]) + add,
211 dst[w * dst_step] = LIFTS(src[w * src_step],
212 mul * 2 * ref[w * ref_step] + add,
216 static av_always_inline void inv_liftS(IDWTELEM *dst, IDWTELEM *src,
217 IDWTELEM *ref, int dst_step,
218 int src_step, int ref_step,
219 int width, int mul, int add, int shift,
220 int highpass, int inverse)
222 const int mirror_left = !highpass;
223 const int mirror_right = (width & 1) ^ highpass;
224 const int w = (width >> 1) - 1 + (highpass & width);
227 av_assert1(shift == 4);
228 #define LIFTS(src, ref, inv) \
229 ((inv) ? (src) + (((ref) + 4 * (src)) >> shift) \
230 : -((-16 * (src) + (ref) + add / \
231 4 + 1 + (5 << 25)) / (5 * 4) - (1 << 23)))
233 dst[0] = LIFTS(src[0], mul * 2 * ref[0] + add, inverse);
238 for (i = 0; i < w; i++)
239 dst[i * dst_step] = LIFTS(src[i * src_step],
240 mul * (ref[i * ref_step] +
241 ref[(i + 1) * ref_step]) + add,
245 dst[w * dst_step] = LIFTS(src[w * src_step],
246 mul * 2 * ref[w * ref_step] + add, inverse);
250 static void horizontal_decompose53i(DWTELEM *b, DWTELEM *temp, int width)
252 const int width2 = width >> 1;
254 const int w2 = (width + 1) >> 1;
256 for (x = 0; x < width2; x++) {
258 temp[x + w2] = b[2 * x + 1];
267 A1 = temp[0 + width2];
268 A1 -= (A2 + A4) >> 1;
272 for (x = 1; x + 1 < width2; x += 2) {
273 A3 = temp[x + width2];
275 A3 -= (A2 + A4) >> 1;
276 A2 += (A1 + A3 + 2) >> 2;
280 A1 = temp[x + 1 + width2];
282 A1 -= (A2 + A4) >> 1;
283 A4 += (A1 + A3 + 2) >> 2;
284 b[x + 1 + width2] = A1;
287 A3 = temp[width - 1];
289 A2 += (A1 + A3 + 2) >> 2;
294 lift(b + w2, temp + w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0);
295 lift(b, temp, b + w2, 1, 1, 1, width, 1, 2, 2, 0, 0);
299 static void vertical_decompose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
304 for (i = 0; i < width; i++)
305 b1[i] -= (b0[i] + b2[i]) >> 1;
308 static void vertical_decompose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2,
313 for (i = 0; i < width; i++)
314 b1[i] += (b0[i] + b2[i] + 2) >> 2;
317 static void spatial_decompose53i(DWTELEM *buffer, DWTELEM *temp,
318 int width, int height, int stride)
321 DWTELEM *b0 = buffer + mirror(-2 - 1, height - 1) * stride;
322 DWTELEM *b1 = buffer + mirror(-2, height - 1) * stride;
324 for (y = -2; y < height; y += 2) {
325 DWTELEM *b2 = buffer + mirror(y + 1, height - 1) * stride;
326 DWTELEM *b3 = buffer + mirror(y + 2, height - 1) * stride;
328 if (y + 1 < (unsigned)height)
329 horizontal_decompose53i(b2, temp, width);
330 if (y + 2 < (unsigned)height)
331 horizontal_decompose53i(b3, temp, width);
333 if (y + 1 < (unsigned)height)
334 vertical_decompose53iH0(b1, b2, b3, width);
335 if (y + 0 < (unsigned)height)
336 vertical_decompose53iL0(b0, b1, b2, width);
343 static void horizontal_decompose97i(DWTELEM *b, DWTELEM *temp, 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, DWTELEM *temp,
395 int width, int height, int stride)
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, temp, width);
409 if (y + 4 < (unsigned)height)
410 horizontal_decompose97i(b5, temp, 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, DWTELEM *temp, int width, int height,
429 int stride, int type, int decomposition_count)
433 for (level = 0; level < decomposition_count; level++) {
436 spatial_decompose97i(buffer, temp,
437 width >> level, height >> level,
441 spatial_decompose53i(buffer, temp,
442 width >> level, height >> level,
449 static void horizontal_compose53i(IDWTELEM *b, IDWTELEM *temp, int width)
451 const int width2 = width >> 1;
452 const int w2 = (width + 1) >> 1;
455 for (x = 0; x < width2; x++) {
457 temp[2 * x + 1] = b[x + w2];
462 b[0] = temp[0] - ((temp[1] + 1) >> 1);
463 for (x = 2; x < width - 1; x += 2) {
464 b[x] = temp[x] - ((temp[x - 1] + temp[x + 1] + 2) >> 2);
465 b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1);
468 b[x] = temp[x] - ((temp[x - 1] + 1) >> 1);
469 b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1);
471 b[x - 1] = temp[x - 1] + b[x - 2];
474 static void vertical_compose53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
479 for (i = 0; i < width; i++)
480 b1[i] += (b0[i] + b2[i]) >> 1;
483 static void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
488 for (i = 0; i < width; i++)
489 b1[i] -= (b0[i] + b2[i] + 2) >> 2;
492 static void spatial_compose53i_buffered_init(DWTCompose *cs, slice_buffer *sb,
493 int height, int stride_line)
495 cs->b0 = slice_buffer_get_line(sb,
496 mirror(-1 - 1, height - 1) * stride_line);
497 cs->b1 = slice_buffer_get_line(sb, mirror(-1, height - 1) * stride_line);
501 static void spatial_compose53i_init(DWTCompose *cs, IDWTELEM *buffer,
502 int height, int stride)
504 cs->b0 = buffer + mirror(-1 - 1, height - 1) * stride;
505 cs->b1 = buffer + mirror(-1, height - 1) * stride;
509 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, temp, width);
541 if (y + 0 < (unsigned)height)
542 horizontal_compose53i(b1, temp, width);
549 static void spatial_compose53i_dy(DWTCompose *cs, IDWTELEM *buffer,
550 IDWTELEM *temp, int width, int height,
554 IDWTELEM *b0 = cs->b0;
555 IDWTELEM *b1 = cs->b1;
556 IDWTELEM *b2 = buffer + mirror(y + 1, height - 1) * stride;
557 IDWTELEM *b3 = buffer + mirror(y + 2, height - 1) * stride;
559 if (y + 1 < (unsigned)height)
560 vertical_compose53iL0(b1, b2, b3, width);
561 if (y + 0 < (unsigned)height)
562 vertical_compose53iH0(b0, b1, b2, width);
564 if (y - 1 < (unsigned)height)
565 horizontal_compose53i(b0, temp, width);
566 if (y + 0 < (unsigned)height)
567 horizontal_compose53i(b1, temp, width);
574 static void av_unused spatial_compose53i(IDWTELEM *buffer, IDWTELEM *temp,
575 int width, int height, int stride)
578 spatial_compose53i_init(&cs, buffer, height, stride);
579 while (cs.y <= height)
580 spatial_compose53i_dy(&cs, buffer, temp, width, height, stride);
583 void ff_snow_horizontal_compose97i(IDWTELEM *b, IDWTELEM *temp, int 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, IDWTELEM *temp,
699 int width, int height,
704 IDWTELEM *b0 = cs->b0;
705 IDWTELEM *b1 = cs->b1;
706 IDWTELEM *b2 = cs->b2;
707 IDWTELEM *b3 = cs->b3;
708 IDWTELEM *b4 = slice_buffer_get_line(sb,
709 mirror(y + 3, height - 1) *
711 IDWTELEM *b5 = slice_buffer_get_line(sb,
712 mirror(y + 4, height - 1) *
715 if (y > 0 && y + 4 < height) {
716 dsp->vertical_compose97i(b0, b1, b2, b3, b4, b5, width);
718 if (y + 3 < (unsigned)height)
719 vertical_compose97iL1(b3, b4, b5, width);
720 if (y + 2 < (unsigned)height)
721 vertical_compose97iH1(b2, b3, b4, width);
722 if (y + 1 < (unsigned)height)
723 vertical_compose97iL0(b1, b2, b3, width);
724 if (y + 0 < (unsigned)height)
725 vertical_compose97iH0(b0, b1, b2, width);
728 if (y - 1 < (unsigned)height)
729 dsp->horizontal_compose97i(b0, temp, width);
730 if (y + 0 < (unsigned)height)
731 dsp->horizontal_compose97i(b1, temp, width);
740 static void spatial_compose97i_dy(DWTCompose *cs, IDWTELEM *buffer,
741 IDWTELEM *temp, int width, int height,
745 IDWTELEM *b0 = cs->b0;
746 IDWTELEM *b1 = cs->b1;
747 IDWTELEM *b2 = cs->b2;
748 IDWTELEM *b3 = cs->b3;
749 IDWTELEM *b4 = buffer + mirror(y + 3, height - 1) * stride;
750 IDWTELEM *b5 = buffer + mirror(y + 4, height - 1) * stride;
752 if (y + 3 < (unsigned)height)
753 vertical_compose97iL1(b3, b4, b5, width);
754 if (y + 2 < (unsigned)height)
755 vertical_compose97iH1(b2, b3, b4, width);
756 if (y + 1 < (unsigned)height)
757 vertical_compose97iL0(b1, b2, b3, width);
758 if (y + 0 < (unsigned)height)
759 vertical_compose97iH0(b0, b1, b2, width);
761 if (y - 1 < (unsigned)height)
762 ff_snow_horizontal_compose97i(b0, temp, width);
763 if (y + 0 < (unsigned)height)
764 ff_snow_horizontal_compose97i(b1, temp, width);
773 static void av_unused spatial_compose97i(IDWTELEM *buffer, IDWTELEM *temp,
774 int width, int height, int stride)
777 spatial_compose97i_init(&cs, buffer, height, stride);
778 while (cs.y <= height)
779 spatial_compose97i_dy(&cs, buffer, temp, width, height, stride);
782 void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer *sb, int width,
783 int height, int stride_line, int type,
784 int decomposition_count)
787 for (level = decomposition_count - 1; level >= 0; level--) {
790 spatial_compose97i_buffered_init(cs + level, sb, height >> level,
791 stride_line << level);
794 spatial_compose53i_buffered_init(cs + level, sb, height >> level,
795 stride_line << level);
801 void ff_spatial_idwt_buffered_slice(DWTContext *dsp, DWTCompose *cs,
802 slice_buffer *slice_buf, IDWTELEM *temp,
803 int width, int height, int stride_line,
804 int type, int decomposition_count, int y)
806 const int support = type == 1 ? 3 : 5;
811 for (level = decomposition_count - 1; level >= 0; level--)
812 while (cs[level].y <= FFMIN((y >> level) + support, height >> level)) {
815 spatial_compose97i_dy_buffered(dsp, cs + level, slice_buf, temp,
818 stride_line << level);
821 spatial_compose53i_dy_buffered(cs + level, slice_buf, temp,
824 stride_line << level);
830 static void ff_spatial_idwt_init(DWTCompose *cs, IDWTELEM *buffer, int width,
831 int height, int stride, int type,
832 int decomposition_count)
835 for (level = decomposition_count - 1; level >= 0; level--) {
838 spatial_compose97i_init(cs + level, buffer, height >> level,
842 spatial_compose53i_init(cs + level, buffer, height >> level,
849 static void ff_spatial_idwt_slice(DWTCompose *cs, IDWTELEM *buffer,
850 IDWTELEM *temp, int width, int height,
851 int stride, int type,
852 int decomposition_count, int y)
854 const int support = type == 1 ? 3 : 5;
859 for (level = decomposition_count - 1; level >= 0; level--)
860 while (cs[level].y <= FFMIN((y >> level) + support, height >> level)) {
863 spatial_compose97i_dy(cs + level, buffer, temp, width >> level,
864 height >> level, stride << level);
867 spatial_compose53i_dy(cs + level, buffer, temp, width >> level,
868 height >> level, stride << level);
874 void ff_spatial_idwt(IDWTELEM *buffer, IDWTELEM *temp, int width, int height,
875 int stride, int type, int decomposition_count)
877 DWTCompose cs[MAX_DECOMPOSITIONS];
879 ff_spatial_idwt_init(cs, buffer, width, height, stride, type,
880 decomposition_count);
881 for (y = 0; y < height; y += 4)
882 ff_spatial_idwt_slice(cs, buffer, temp, width, height, stride, type,
883 decomposition_count, y);
886 static inline int w_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size,
887 int w, int h, int type)
890 const int dec_count = w == 8 ? 3 : 4;
891 int tmp[32 * 32], tmp2[32];
893 static const int scale[2][2][4][4] = {
896 { 268, 239, 239, 213 },
897 { 0, 224, 224, 152 },
898 { 0, 135, 135, 110 },
900 { // 9/7 16x16 or 32x32 dec=4
901 { 344, 310, 310, 280 },
902 { 0, 320, 320, 228 },
903 { 0, 175, 175, 136 },
904 { 0, 129, 129, 102 },
909 { 275, 245, 245, 218 },
910 { 0, 230, 230, 156 },
911 { 0, 138, 138, 113 },
913 { // 5/3 16x16 or 32x32 dec=4
914 { 352, 317, 317, 286 },
915 { 0, 328, 328, 233 },
916 { 0, 180, 180, 140 },
917 { 0, 132, 132, 105 },
922 for (i = 0; i < h; i++) {
923 for (j = 0; j < w; j += 4) {
924 tmp[32 * i + j + 0] = (pix1[j + 0] - pix2[j + 0]) << 4;
925 tmp[32 * i + j + 1] = (pix1[j + 1] - pix2[j + 1]) << 4;
926 tmp[32 * i + j + 2] = (pix1[j + 2] - pix2[j + 2]) << 4;
927 tmp[32 * i + j + 3] = (pix1[j + 3] - pix2[j + 3]) << 4;
933 ff_spatial_dwt(tmp, tmp2, w, h, 32, type, dec_count);
937 for (level = 0; level < dec_count; level++)
938 for (ori = level ? 1 : 0; ori < 4; ori++) {
939 int size = w >> (dec_count - level);
940 int sx = (ori & 1) ? size : 0;
941 int stride = 32 << (dec_count - level);
942 int sy = (ori & 2) ? stride >> 1 : 0;
944 for (i = 0; i < size; i++)
945 for (j = 0; j < size; j++) {
946 int v = tmp[sx + sy + i * stride + j] *
947 scale[type][dec_count - 3][level][ori];
955 static int w53_8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
957 return w_c(v, pix1, pix2, line_size, 8, h, 1);
960 static int w97_8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
962 return w_c(v, pix1, pix2, line_size, 8, h, 0);
965 static int w53_16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
967 return w_c(v, pix1, pix2, line_size, 16, h, 1);
970 static int w97_16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
972 return w_c(v, pix1, pix2, line_size, 16, h, 0);
975 int ff_w53_32_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
977 return w_c(v, pix1, pix2, line_size, 32, h, 1);
980 int ff_w97_32_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
982 return w_c(v, pix1, pix2, line_size, 32, h, 0);
985 void ff_dsputil_init_dwt(DSPContext *c)
987 c->w53[0] = w53_16_c;
989 c->w97[0] = w97_16_c;
993 void ff_dwt_init(DWTContext *c)
995 c->vertical_compose97i = ff_snow_vertical_compose97i;
996 c->horizontal_compose97i = ff_snow_horizontal_compose97i;
997 c->inner_add_yblock = ff_snow_inner_add_yblock;
1004 static av_always_inline
1005 void interleave(IDWTELEM *dst, IDWTELEM *src0, IDWTELEM *src1, int w2, int add, int shift)
1008 for (i = 0; i < w2; i++) {
1009 dst[2*i ] = (src0[i] + add) >> shift;
1010 dst[2*i+1] = (src1[i] + add) >> shift;
1014 static void horizontal_compose_dirac53i(IDWTELEM *b, IDWTELEM *temp, int w)
1016 const int w2 = w >> 1;
1019 temp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]);
1020 for (x = 1; x < w2; x++) {
1021 temp[x ] = COMPOSE_53iL0 (b[x+w2-1], b[x ], b[x+w2]);
1022 temp[x+w2-1] = COMPOSE_DIRAC53iH0(temp[x-1], b[x+w2-1], temp[x]);
1024 temp[w-1] = COMPOSE_DIRAC53iH0(temp[w2-1], b[w-1], temp[w2-1]);
1026 interleave(b, temp, temp+w2, w2, 1, 1);
1029 static void horizontal_compose_dd97i(IDWTELEM *b, IDWTELEM *tmp, int w)
1031 const int w2 = w >> 1;
1034 tmp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]);
1035 for (x = 1; x < w2; x++)
1036 tmp[x] = COMPOSE_53iL0(b[x+w2-1], b[x], b[x+w2]);
1040 tmp[w2+1] = tmp[w2] = tmp[w2-1];
1042 for (x = 0; x < w2; x++) {
1043 b[2*x ] = (tmp[x] + 1)>>1;
1044 b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1;
1048 static void horizontal_compose_dd137i(IDWTELEM *b, IDWTELEM *tmp, int w)
1050 const int w2 = w >> 1;
1053 tmp[0] = COMPOSE_DD137iL0(b[w2], b[w2], b[0], b[w2 ], b[w2+1]);
1054 tmp[1] = COMPOSE_DD137iL0(b[w2], b[w2], b[1], b[w2+1], b[w2+2]);
1055 for (x = 2; x < w2-1; x++)
1056 tmp[x] = COMPOSE_DD137iL0(b[x+w2-2], b[x+w2-1], b[x], b[x+w2], b[x+w2+1]);
1057 tmp[w2-1] = COMPOSE_DD137iL0(b[w-3], b[w-2], b[w2-1], b[w-1], b[w-1]);
1061 tmp[w2+1] = tmp[w2] = tmp[w2-1];
1063 for (x = 0; x < w2; x++) {
1064 b[2*x ] = (tmp[x] + 1)>>1;
1065 b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1;
1069 static av_always_inline
1070 void horizontal_compose_haari(IDWTELEM *b, IDWTELEM *temp, int w, int shift)
1072 const int w2 = w >> 1;
1075 for (x = 0; x < w2; x++) {
1076 temp[x ] = COMPOSE_HAARiL0(b[x ], b[x+w2]);
1077 temp[x+w2] = COMPOSE_HAARiH0(b[x+w2], temp[x]);
1080 interleave(b, temp, temp+w2, w2, shift, shift);
1083 static void horizontal_compose_haar0i(IDWTELEM *b, IDWTELEM *temp, int w)
1085 horizontal_compose_haari(b, temp, w, 0);
1088 static void horizontal_compose_haar1i(IDWTELEM *b, IDWTELEM *temp, int w)
1090 horizontal_compose_haari(b, temp, w, 1);
1093 static void horizontal_compose_fidelityi(IDWTELEM *b, IDWTELEM *tmp, int w)
1095 const int w2 = w >> 1;
1099 for (x = 0; x < w2; x++) {
1100 for (i = 0; i < 8; i++)
1101 v[i] = b[av_clip(x-3+i, 0, w2-1)];
1102 tmp[x] = COMPOSE_FIDELITYiH0(v[0], v[1], v[2], v[3], b[x+w2], v[4], v[5], v[6], v[7]);
1105 for (x = 0; x < w2; x++) {
1106 for (i = 0; i < 8; i++)
1107 v[i] = tmp[av_clip(x-4+i, 0, w2-1)];
1108 tmp[x+w2] = COMPOSE_FIDELITYiL0(v[0], v[1], v[2], v[3], b[x], v[4], v[5], v[6], v[7]);
1111 interleave(b, tmp+w2, tmp, w2, 0, 0);
1114 static void horizontal_compose_daub97i(IDWTELEM *b, IDWTELEM *temp, int w)
1116 const int w2 = w >> 1;
1119 temp[0] = COMPOSE_DAUB97iL1(b[w2], b[0], b[w2]);
1120 for (x = 1; x < w2; x++) {
1121 temp[x ] = COMPOSE_DAUB97iL1(b[x+w2-1], b[x ], b[x+w2]);
1122 temp[x+w2-1] = COMPOSE_DAUB97iH1(temp[x-1], b[x+w2-1], temp[x]);
1124 temp[w-1] = COMPOSE_DAUB97iH1(temp[w2-1], b[w-1], temp[w2-1]);
1126 // second stage combined with interleave and shift
1127 b0 = b2 = COMPOSE_DAUB97iL0(temp[w2], temp[0], temp[w2]);
1128 b[0] = (b0 + 1) >> 1;
1129 for (x = 1; x < w2; x++) {
1130 b2 = COMPOSE_DAUB97iL0(temp[x+w2-1], temp[x ], temp[x+w2]);
1131 b1 = COMPOSE_DAUB97iH0( b0, temp[x+w2-1], b2 );
1132 b[2*x-1] = (b1 + 1) >> 1;
1133 b[2*x ] = (b2 + 1) >> 1;
1136 b[w-1] = (COMPOSE_DAUB97iH0(b2, temp[w-1], b2) + 1) >> 1;
1139 static void vertical_compose_dirac53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1143 for(i=0; i<width; i++){
1144 b1[i] = COMPOSE_DIRAC53iH0(b0[i], b1[i], b2[i]);
1148 static void vertical_compose_dd97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
1149 IDWTELEM *b3, IDWTELEM *b4, int width)
1153 for(i=0; i<width; i++){
1154 b2[i] = COMPOSE_DD97iH0(b0[i], b1[i], b2[i], b3[i], b4[i]);
1158 static void vertical_compose_dd137iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
1159 IDWTELEM *b3, IDWTELEM *b4, int width)
1163 for(i=0; i<width; i++){
1164 b2[i] = COMPOSE_DD137iL0(b0[i], b1[i], b2[i], b3[i], b4[i]);
1168 static void vertical_compose_haar(IDWTELEM *b0, IDWTELEM *b1, int width)
1172 for (i = 0; i < width; i++) {
1173 b0[i] = COMPOSE_HAARiL0(b0[i], b1[i]);
1174 b1[i] = COMPOSE_HAARiH0(b1[i], b0[i]);
1178 static void vertical_compose_fidelityiH0(IDWTELEM *dst, IDWTELEM *b[8], int width)
1182 for(i=0; i<width; i++){
1183 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]);
1187 static void vertical_compose_fidelityiL0(IDWTELEM *dst, IDWTELEM *b[8], int width)
1191 for(i=0; i<width; i++){
1192 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]);
1196 static void vertical_compose_daub97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1200 for(i=0; i<width; i++){
1201 b1[i] = COMPOSE_DAUB97iH0(b0[i], b1[i], b2[i]);
1205 static void vertical_compose_daub97iH1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1209 for(i=0; i<width; i++){
1210 b1[i] = COMPOSE_DAUB97iH1(b0[i], b1[i], b2[i]);
1214 static void vertical_compose_daub97iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1218 for(i=0; i<width; i++){
1219 b1[i] = COMPOSE_DAUB97iL0(b0[i], b1[i], b2[i]);
1223 static void vertical_compose_daub97iL1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width)
1227 for(i=0; i<width; i++){
1228 b1[i] = COMPOSE_DAUB97iL1(b0[i], b1[i], b2[i]);
1233 static void spatial_compose_dd97i_dy(DWTContext *d, int level, int width, int height, int stride)
1235 vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1236 vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1237 DWTCompose *cs = d->cs + level;
1241 for (i = 0; i < 6; i++)
1243 b[6] = d->buffer + av_clip(y+5, 0, height-2)*stride;
1244 b[7] = d->buffer + av_clip(y+6, 1, height-1)*stride;
1246 if(y+5<(unsigned)height) vertical_compose_l0( b[5], b[6], b[7], width);
1247 if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width);
1249 if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
1250 if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
1252 for (i = 0; i < 6; i++)
1257 static void spatial_compose_dirac53i_dy(DWTContext *d, int level, int width, int height, int stride)
1259 vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1260 vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1261 DWTCompose *cs = d->cs + level;
1264 IDWTELEM *b[4] = { cs->b[0], cs->b[1] };
1265 b[2] = d->buffer + mirror(y+1, height-1)*stride;
1266 b[3] = d->buffer + mirror(y+2, height-1)*stride;
1268 if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
1269 if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
1271 if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
1272 if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
1280 static void spatial_compose_dd137i_dy(DWTContext *d, int level, int width, int height, int stride)
1282 vertical_compose_5tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1283 vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1284 DWTCompose *cs = d->cs + level;
1288 for (i = 0; i < 8; i++)
1290 b[8] = d->buffer + av_clip(y+7, 0, height-2)*stride;
1291 b[9] = d->buffer + av_clip(y+8, 1, height-1)*stride;
1293 if(y+5<(unsigned)height) vertical_compose_l0(b[3], b[5], b[6], b[7], b[9], width);
1294 if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width);
1296 if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
1297 if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
1299 for (i = 0; i < 8; i++)
1304 // haar makes the assumption that height is even (always true for dirac)
1305 static void spatial_compose_haari_dy(DWTContext *d, int level, int width, int height, int stride)
1307 vertical_compose_2tap vertical_compose = (void*)d->vertical_compose;
1308 int y = d->cs[level].y;
1309 IDWTELEM *b0 = d->buffer + (y-1)*stride;
1310 IDWTELEM *b1 = d->buffer + (y )*stride;
1312 vertical_compose(b0, b1, width);
1313 d->horizontal_compose(b0, d->temp, width);
1314 d->horizontal_compose(b1, d->temp, width);
1316 d->cs[level].y += 2;
1319 // Don't do sliced idwt for fidelity; the 9 tap filter makes it a bit annoying
1320 // Fortunately, this filter isn't used in practice.
1321 static void spatial_compose_fidelity(DWTContext *d, int level, int width, int height, int stride)
1323 vertical_compose_9tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1324 vertical_compose_9tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1328 for (y = 1; y < height; y += 2) {
1329 for (i = 0; i < 8; i++)
1330 b[i] = d->buffer + av_clip((y-7 + 2*i), 0, height-2)*stride;
1331 vertical_compose_h0(d->buffer + y*stride, b, width);
1334 for (y = 0; y < height; y += 2) {
1335 for (i = 0; i < 8; i++)
1336 b[i] = d->buffer + av_clip((y-7 + 2*i), 1, height-1)*stride;
1337 vertical_compose_l0(d->buffer + y*stride, b, width);
1340 for (y = 0; y < height; y++)
1341 d->horizontal_compose(d->buffer + y*stride, d->temp, width);
1343 d->cs[level].y = height+1;
1346 static void spatial_compose_daub97i_dy(DWTContext *d, int level, int width, int height, int stride)
1348 vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
1349 vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
1350 vertical_compose_3tap vertical_compose_l1 = (void*)d->vertical_compose_l1;
1351 vertical_compose_3tap vertical_compose_h1 = (void*)d->vertical_compose_h1;
1352 DWTCompose *cs = d->cs + level;
1356 for (i = 0; i < 4; i++)
1358 b[4] = d->buffer + mirror(y+3, height-1)*stride;
1359 b[5] = d->buffer + mirror(y+4, height-1)*stride;
1361 if(y+3<(unsigned)height) vertical_compose_l1(b[3], b[4], b[5], width);
1362 if(y+2<(unsigned)height) vertical_compose_h1(b[2], b[3], b[4], width);
1363 if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
1364 if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
1366 if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
1367 if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
1369 for (i = 0; i < 4; i++)
1375 static void spatial_compose97i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
1377 cs->b[0] = buffer + mirror(-3-1, height-1)*stride;
1378 cs->b[1] = buffer + mirror(-3 , height-1)*stride;
1379 cs->b[2] = buffer + mirror(-3+1, height-1)*stride;
1380 cs->b[3] = buffer + mirror(-3+2, height-1)*stride;
1384 static void spatial_compose53i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
1386 cs->b[0] = buffer + mirror(-1-1, height-1)*stride;
1387 cs->b[1] = buffer + mirror(-1 , height-1)*stride;
1391 static void spatial_compose_dd97i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
1393 cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride;
1394 cs->b[1] = buffer + av_clip(-5 , 1, height-1)*stride;
1395 cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride;
1396 cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride;
1397 cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride;
1398 cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride;
1402 static void spatial_compose_dd137i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
1404 cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride;
1405 cs->b[1] = buffer + av_clip(-5 , 1, height-1)*stride;
1406 cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride;
1407 cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride;
1408 cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride;
1409 cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride;
1410 cs->b[6] = buffer + av_clip(-5+5, 0, height-2)*stride;
1411 cs->b[7] = buffer + av_clip(-5+6, 1, height-1)*stride;
1415 int ff_spatial_idwt_init2(DWTContext *d, IDWTELEM *buffer, int width, int height,
1416 int stride, enum dwt_type type, int decomposition_count,
1425 d->decomposition_count = decomposition_count;
1428 for(level=decomposition_count-1; level>=0; level--){
1429 int hl = height >> level;
1430 int stride_l = stride << level;
1433 case DWT_DIRAC_DD9_7:
1434 spatial_compose_dd97i_init(d->cs+level, buffer, hl, stride_l);
1436 case DWT_DIRAC_LEGALL5_3:
1437 spatial_compose53i_init2(d->cs+level, buffer, hl, stride_l);
1439 case DWT_DIRAC_DD13_7:
1440 spatial_compose_dd137i_init(d->cs+level, buffer, hl, stride_l);
1442 case DWT_DIRAC_HAAR0:
1443 case DWT_DIRAC_HAAR1:
1446 case DWT_DIRAC_DAUB9_7:
1447 spatial_compose97i_init2(d->cs+level, buffer, hl, stride_l);
1456 case DWT_DIRAC_DD9_7:
1457 d->spatial_compose = spatial_compose_dd97i_dy;
1458 d->vertical_compose_l0 = (void*)vertical_compose53iL0;
1459 d->vertical_compose_h0 = (void*)vertical_compose_dd97iH0;
1460 d->horizontal_compose = horizontal_compose_dd97i;
1463 case DWT_DIRAC_LEGALL5_3:
1464 d->spatial_compose = spatial_compose_dirac53i_dy;
1465 d->vertical_compose_l0 = (void*)vertical_compose53iL0;
1466 d->vertical_compose_h0 = (void*)vertical_compose_dirac53iH0;
1467 d->horizontal_compose = horizontal_compose_dirac53i;
1470 case DWT_DIRAC_DD13_7:
1471 d->spatial_compose = spatial_compose_dd137i_dy;
1472 d->vertical_compose_l0 = (void*)vertical_compose_dd137iL0;
1473 d->vertical_compose_h0 = (void*)vertical_compose_dd97iH0;
1474 d->horizontal_compose = horizontal_compose_dd137i;
1477 case DWT_DIRAC_HAAR0:
1478 case DWT_DIRAC_HAAR1:
1479 d->spatial_compose = spatial_compose_haari_dy;
1480 d->vertical_compose = (void*)vertical_compose_haar;
1481 if (type == DWT_DIRAC_HAAR0)
1482 d->horizontal_compose = horizontal_compose_haar0i;
1484 d->horizontal_compose = horizontal_compose_haar1i;
1487 case DWT_DIRAC_FIDELITY:
1488 d->spatial_compose = spatial_compose_fidelity;
1489 d->vertical_compose_l0 = (void*)vertical_compose_fidelityiL0;
1490 d->vertical_compose_h0 = (void*)vertical_compose_fidelityiH0;
1491 d->horizontal_compose = horizontal_compose_fidelityi;
1493 case DWT_DIRAC_DAUB9_7:
1494 d->spatial_compose = spatial_compose_daub97i_dy;
1495 d->vertical_compose_l0 = (void*)vertical_compose_daub97iL0;
1496 d->vertical_compose_h0 = (void*)vertical_compose_daub97iH0;
1497 d->vertical_compose_l1 = (void*)vertical_compose_daub97iL1;
1498 d->vertical_compose_h1 = (void*)vertical_compose_daub97iH1;
1499 d->horizontal_compose = horizontal_compose_daub97i;
1503 av_log(NULL, AV_LOG_ERROR, "Unknown wavelet type %d\n", type);
1507 if (HAVE_MMX) ff_spatial_idwt_init_mmx(d, type);
1512 void ff_spatial_idwt_slice2(DWTContext *d, int y)
1514 int level, support = d->support;
1516 for (level = d->decomposition_count-1; level >= 0; level--) {
1517 int wl = d->width >> level;
1518 int hl = d->height >> level;
1519 int stride_l = d->stride << level;
1521 while (d->cs[level].y <= FFMIN((y>>level)+support, hl))
1522 d->spatial_compose(d, level, wl, hl, stride_l);
1526 int ff_spatial_idwt2(IDWTELEM *buffer, int width, int height, int stride,
1527 enum dwt_type type, int decomposition_count, IDWTELEM *temp)
1532 if (ff_spatial_idwt_init2(&d, buffer, width, height, stride, type, decomposition_count, temp))
1535 for (y = 0; y < d.height; y += 4)
1536 ff_spatial_idwt_slice2(&d, y);