tests: fix build on os/x
[schroedinger.git] / schroedinger / schrowaveletorc.c
blobebc03bf613bce5fcc51a39a201c6aad1391c7391
2 #ifdef HAVE_CONFIG_H
3 #include "config.h"
4 #endif
6 #include <schroedinger/schro.h>
7 #include <schroedinger/schroorc.h>
8 #include <schroedinger/schrovirtframe.h>
9 #include <orc/orc.h>
11 static void schro_iwt_desl_9_3 (SchroFrameData *fd, int16_t *tmp);
12 static void schro_iwt_5_3 (SchroFrameData *fd, int16_t *tmp);
13 static void schro_iwt_13_5 (SchroFrameData *fd, int16_t *tmp);
14 static void schro_iwt_haar0 (SchroFrameData *fd, int16_t *tmp);
15 static void schro_iwt_haar1 (SchroFrameData *fd, int16_t *tmp);
16 static void schro_iwt_fidelity (SchroFrameData *fd, int16_t *tmp);
17 static void schro_iwt_daub_9_7 (SchroFrameData *fd, int16_t *tmp);
19 static void schro_iwt_desl_9_3_s32 (SchroFrameData *fd, int32_t *tmp);
20 static void schro_iwt_5_3_s32 (SchroFrameData *fd, int32_t *tmp);
21 static void schro_iwt_13_5_s32 (SchroFrameData *fd, int32_t *tmp);
22 static void schro_iwt_haar0_s32 (SchroFrameData *fd, int32_t *tmp);
23 static void schro_iwt_haar1_s32 (SchroFrameData *fd, int32_t *tmp);
24 static void schro_iwt_fidelity_s32 (SchroFrameData *fd, int32_t *tmp);
25 static void schro_iwt_daub_9_7_s32 (SchroFrameData *fd, int32_t *tmp);
27 static void schro_iiwt_desl_9_3 (SchroFrameData *dest, SchroFrameData *src,
28 int16_t *tmp);
29 static void schro_iiwt_5_3 (SchroFrameData *dest, SchroFrameData *src,
30 int16_t *tmp);
31 static void schro_iiwt_13_5 (SchroFrameData *dest, SchroFrameData *src,
32 int16_t *tmp);
33 static void schro_iiwt_haar0 (SchroFrameData *dest, SchroFrameData *src,
34 int16_t *tmp);
35 static void schro_iiwt_haar1 (SchroFrameData *dest, SchroFrameData *src,
36 int16_t *tmp);
37 static void schro_iiwt_fidelity (SchroFrameData *dest, SchroFrameData *src,
38 int16_t *tmp);
39 static void schro_iiwt_daub_9_7 (SchroFrameData *dest, SchroFrameData *src,
40 int16_t *tmp);
42 static void schro_iiwt_desl_9_3_s32 (SchroFrameData *dest, SchroFrameData *src,
43 int32_t *tmp);
44 static void schro_iiwt_5_3_s32 (SchroFrameData *dest, SchroFrameData *src,
45 int32_t *tmp);
46 static void schro_iiwt_13_5_s32 (SchroFrameData *dest, SchroFrameData *src,
47 int32_t *tmp);
48 static void schro_iiwt_haar0_s32 (SchroFrameData *dest, SchroFrameData *src,
49 int32_t *tmp);
50 static void schro_iiwt_haar1_s32 (SchroFrameData *dest, SchroFrameData *src,
51 int32_t *tmp);
52 static void schro_iiwt_fidelity_s32 (SchroFrameData *dest, SchroFrameData *src,
53 int32_t *tmp);
54 static void schro_iiwt_daub_9_7_s32 (SchroFrameData *dest, SchroFrameData *src,
55 int32_t *tmp);
58 /* Forward transform splitter function */
60 void
61 schro_wavelet_transform_2d (SchroFrameData * fd, int filter, int16_t * tmp)
63 if ((SCHRO_FRAME_FORMAT_DEPTH (fd->format) ==
64 SCHRO_FRAME_FORMAT_DEPTH_S16)) {
65 switch (filter) {
66 case SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7:
67 schro_iwt_desl_9_3 (fd, tmp);
68 break;
69 case SCHRO_WAVELET_LE_GALL_5_3:
70 schro_iwt_5_3 (fd, tmp);
71 break;
72 case SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7:
73 schro_iwt_13_5 (fd, tmp);
74 break;
75 case SCHRO_WAVELET_HAAR_0:
76 schro_iwt_haar0 (fd, tmp);
77 break;
78 case SCHRO_WAVELET_HAAR_1:
79 schro_iwt_haar1 (fd, tmp);
80 break;
81 case SCHRO_WAVELET_FIDELITY:
82 schro_iwt_fidelity (fd, tmp);
83 break;
84 case SCHRO_WAVELET_DAUBECHIES_9_7:
85 schro_iwt_daub_9_7 (fd, tmp);
86 break;
87 default:
88 SCHRO_ASSERT (0);
90 } else {
91 switch (filter) {
92 case SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7:
93 schro_iwt_desl_9_3_s32 (fd, (orc_int32 *)tmp);
94 break;
95 case SCHRO_WAVELET_LE_GALL_5_3:
96 schro_iwt_5_3_s32 (fd, (orc_int32 *)tmp);
97 break;
98 case SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7:
99 schro_iwt_13_5_s32 (fd, (orc_int32 *)tmp);
100 break;
101 case SCHRO_WAVELET_HAAR_0:
102 schro_iwt_haar0_s32 (fd, (orc_int32 *)tmp);
103 break;
104 case SCHRO_WAVELET_HAAR_1:
105 schro_iwt_haar1_s32 (fd, (orc_int32 *)tmp);
106 break;
107 case SCHRO_WAVELET_FIDELITY:
108 schro_iwt_fidelity_s32 (fd, (orc_int32 *)tmp);
109 break;
110 case SCHRO_WAVELET_DAUBECHIES_9_7:
111 schro_iwt_daub_9_7_s32 (fd, (orc_int32 *)tmp);
112 break;
113 default:
114 SCHRO_ASSERT (0);
119 /* Inverse transform splitter function */
121 void
122 schro_wavelet_inverse_transform_2d (SchroFrameData * fd_dest,
123 SchroFrameData *fd_src, int filter, int16_t * tmp)
126 if ((SCHRO_FRAME_FORMAT_DEPTH (fd_dest->format) ==
127 SCHRO_FRAME_FORMAT_DEPTH_S16)) {
128 SCHRO_ASSERT (SCHRO_FRAME_FORMAT_DEPTH (fd_src->format) ==
129 SCHRO_FRAME_FORMAT_DEPTH_S16);
131 switch (filter) {
132 case SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7:
133 schro_iiwt_desl_9_3 (fd_dest, fd_src, tmp);
134 break;
135 case SCHRO_WAVELET_LE_GALL_5_3:
136 schro_iiwt_5_3 (fd_dest, fd_src, tmp);
137 break;
138 case SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7:
139 schro_iiwt_13_5 (fd_dest, fd_src, tmp);
140 break;
141 case SCHRO_WAVELET_HAAR_0:
142 schro_iiwt_haar0 (fd_dest, fd_src, tmp);
143 break;
144 case SCHRO_WAVELET_HAAR_1:
145 schro_iiwt_haar1 (fd_dest, fd_src, tmp);
146 break;
147 case SCHRO_WAVELET_FIDELITY:
148 schro_iiwt_fidelity (fd_dest, fd_src, tmp);
149 break;
150 case SCHRO_WAVELET_DAUBECHIES_9_7:
151 schro_iiwt_daub_9_7 (fd_dest, fd_src, tmp);
152 break;
153 default:
154 SCHRO_ASSERT (0);
156 } else if ((SCHRO_FRAME_FORMAT_DEPTH (fd_dest->format) ==
157 SCHRO_FRAME_FORMAT_DEPTH_S32)) {
158 SCHRO_ASSERT (SCHRO_FRAME_FORMAT_DEPTH (fd_src->format) ==
159 SCHRO_FRAME_FORMAT_DEPTH_S32);
161 switch (filter) {
162 case SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7:
163 schro_iiwt_desl_9_3_s32 (fd_dest, fd_src, (int32_t *)tmp);
164 break;
165 case SCHRO_WAVELET_LE_GALL_5_3:
166 schro_iiwt_5_3_s32 (fd_dest, fd_src, (int32_t *)tmp);
167 break;
168 case SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7:
169 schro_iiwt_13_5_s32 (fd_dest, fd_src, (int32_t *)tmp);
170 break;
171 case SCHRO_WAVELET_HAAR_0:
172 schro_iiwt_haar0_s32 (fd_dest, fd_src, (int32_t *)tmp);
173 break;
174 case SCHRO_WAVELET_HAAR_1:
175 schro_iiwt_haar1_s32 (fd_dest, fd_src, (int32_t *)tmp);
176 break;
177 case SCHRO_WAVELET_FIDELITY:
178 schro_iiwt_fidelity_s32 (fd_dest, fd_src, (int32_t *)tmp);
179 break;
180 case SCHRO_WAVELET_DAUBECHIES_9_7:
181 schro_iiwt_daub_9_7_s32 (fd_dest, fd_src, (int32_t *)tmp);
182 break;
183 default:
184 SCHRO_ASSERT (0);
190 /* some utility functions */
192 static void
193 extend_1_2 (orc_int16 *data, int n)
195 data[-1] = data[0];
197 data[n] = data[n - 1];
198 data[n + 1] = data[n - 1];
201 static void
202 extend_2_1 (orc_int16 *data, int n)
204 data[-2] = data[0];
205 data[-1] = data[0];
207 data[n] = data[n - 1];
210 static void
211 extend_1_1 (orc_int16 *data, int n)
213 data[-1] = data[0];
215 data[n] = data[n - 1];
218 static void
219 extend_1_0 (orc_int16 *data, int n)
221 data[-1] = data[0];
224 static void
225 extend_2_2 (orc_int16 *data, int n)
227 data[-2] = data[0];
228 data[-1] = data[0];
230 data[n] = data[n - 1];
231 data[n+1] = data[n - 1];
234 #define extend_4_3 extend_4_4
235 #define extend_3_4 extend_4_4
236 static void
237 extend_4_4 (orc_int16 *data, int n)
239 data[-4] = data[0];
240 data[-3] = data[0];
241 data[-2] = data[0];
242 data[-1] = data[0];
244 data[n] = data[n - 1];
245 data[n+1] = data[n - 1];
246 data[n+2] = data[n - 1];
247 data[n+3] = data[n - 1];
250 #define extend_1_0_s32 extend_4_4_s32
251 #define extend_1_1_s32 extend_4_4_s32
252 #define extend_2_2_s32 extend_4_4_s32
253 #define extend_1_2_s32 extend_4_4_s32
254 #define extend_2_1_s32 extend_4_4_s32
255 #define extend_4_3_s32 extend_4_4_s32
256 #define extend_3_4_s32 extend_4_4_s32
257 static void
258 extend_4_4_s32 (orc_int32 *data, int n)
260 data[-4] = data[0];
261 data[-3] = data[0];
262 data[-2] = data[0];
263 data[-1] = data[0];
265 data[n] = data[n - 1];
266 data[n+1] = data[n - 1];
267 data[n+2] = data[n - 1];
268 data[n+3] = data[n - 1];
271 static void
272 join (orc_int16 *dest, orc_int16 *src1, orc_int16 *src2, int width)
274 orc_memcpy (dest, src1, width / 2 * sizeof (int16_t));
275 orc_memcpy (dest + width / 2, src2, width / 2 * sizeof (int16_t));
278 static void
279 join_s32 (orc_int32 *dest, orc_int32 *src1, orc_int32 *src2, int width)
281 orc_memcpy (dest, src1, width / 2 * sizeof (int32_t));
282 orc_memcpy (dest + width / 2, src2, width / 2 * sizeof (int32_t));
285 /* Forward, 16-bit, Wavelet #0: Deslauriers-Dubuc 9,7 */
287 static void
288 wavelet_iwt_desl_9_3_horiz (SchroFrameData * fd, int i, orc_int16 *tmp)
290 int width = fd->width;
291 int16_t *line = SCHRO_FRAME_DATA_GET_LINE (fd, i);
292 int16_t *hi = tmp + 4;
293 int16_t *lo = tmp + width/2 + 12;
295 orc_deinterleave2_lshift1_s16 (hi, lo, line, width / 2);
296 extend_1_2 (hi, width/2);
297 orc_mas4_horiz_sub_s16_1991_ip (lo, hi - 1, 1 << 3, 4, width/2);
298 extend_1_0 (lo, width/2);
299 orc_add2_rshift_add_s16_22 (hi, lo - 1, width/2);
300 join (line, hi, lo, width);
303 static void
304 wavelet_iwt_desl_9_3_vert_odd (SchroFrameData *fd, int i)
306 int width = fd->width;
307 int height = fd->height;
309 if (i & 1) {
310 if (i < 3 || i >= height - 3) {
311 orc_mas4_vert_sub_s16_1991 (
312 SCHRO_FRAME_DATA_GET_LINE (fd, i),
313 SCHRO_FRAME_DATA_GET_LINE (fd, CLAMP (i - 3, 0, height - 2)),
314 SCHRO_FRAME_DATA_GET_LINE (fd, CLAMP (i - 1, 0, height - 2)),
315 SCHRO_FRAME_DATA_GET_LINE (fd, CLAMP (i + 1, 0, height - 2)),
316 SCHRO_FRAME_DATA_GET_LINE (fd, CLAMP (i + 3, 0, height - 2)), 1 << 3, 4, width);
317 } else {
318 orc_mas4_vert_sub_s16_1991 (
319 SCHRO_FRAME_DATA_GET_LINE (fd, i),
320 SCHRO_FRAME_DATA_GET_LINE (fd, i - 3),
321 SCHRO_FRAME_DATA_GET_LINE (fd, i - 1),
322 SCHRO_FRAME_DATA_GET_LINE (fd, i + 1),
323 SCHRO_FRAME_DATA_GET_LINE (fd, i + 3), 1 << 3, 4, width);
328 static void
329 wavelet_iwt_desl_9_3_vert_even (SchroFrameData *fd, int i)
331 int width = fd->width;
333 if ((i & 1) == 0) {
334 int16_t *lo;
335 int16_t *hi1, *hi2;
337 lo = SCHRO_FRAME_DATA_GET_LINE (fd, i);
338 if (i == 0) {
339 hi1 = SCHRO_FRAME_DATA_GET_LINE (fd, 1);
340 } else {
341 hi1 = SCHRO_FRAME_DATA_GET_LINE (fd, i-1);
343 hi2 = SCHRO_FRAME_DATA_GET_LINE (fd, i+1);
345 orc_add2_rshift_add_s16_22_vert (lo, hi1, hi2, width);
349 void
350 schro_iwt_desl_9_3 (SchroFrameData *fd, int16_t * tmp)
352 int i;
353 int j;
355 for(i=-6;i<fd->height;i++) {
356 j = i+6;
357 if (j >= 0 && j < fd->height) {
358 wavelet_iwt_desl_9_3_horiz (fd, j, tmp);
361 j = i+3;
362 if (j >= 0 && j < fd->height && (j&1) == 1) {
363 wavelet_iwt_desl_9_3_vert_odd (fd, j);
366 j = i;
367 if (j >= 0 && j < fd->height && (j&1) == 0) {
368 wavelet_iwt_desl_9_3_vert_even (fd, j);
374 /* Forward, 16-bit, Wavelet #1: LeGall 5,3 */
376 static void
377 wavelet_iwt_5_3_horiz (SchroFrameData *fd, int i, orc_int16 *tmp)
379 int width = fd->width;
380 int16_t *line = SCHRO_FRAME_DATA_GET_LINE (fd, i);
381 int16_t *hi = tmp + 4;
382 int16_t *lo = tmp + width/2 + 12;
384 orc_deinterleave2_lshift1_s16 (hi, lo, line, width / 2);
385 extend_1_1 (hi, width/2);
386 orc_add2_rshift_sub_s16_11 (lo, hi, width/2);
387 extend_1_1 (lo, width/2);
388 orc_add2_rshift_add_s16_22 (hi, lo - 1, width/2);
389 join (line, hi, lo, width);
392 static void
393 wavelet_iwt_5_3_vert_odd (SchroFrameData * fd, int i)
396 if (i & 1) {
397 int16_t *hi;
398 int16_t *lo1, *lo2;
400 hi = SCHRO_FRAME_DATA_GET_LINE (fd, i);
401 lo1 = SCHRO_FRAME_DATA_GET_LINE (fd, i - 1);
402 if (i + 1 < fd->height) {
403 lo2 = SCHRO_FRAME_DATA_GET_LINE (fd, i + 1);
404 } else {
405 lo2 = lo1;
408 orc_add2_rshift_sub_s16_11_vert (hi, lo1, lo2, fd->width);
412 static void
413 wavelet_iwt_5_3_vert_even (SchroFrameData *fd, int i)
416 if ((i & 1) == 0) {
417 int16_t *lo;
418 int16_t *hi1, *hi2;
420 lo = SCHRO_FRAME_DATA_GET_LINE (fd, i);
421 if (i == 0) {
422 hi1 = SCHRO_FRAME_DATA_GET_LINE (fd, 1);
423 } else {
424 hi1 = SCHRO_FRAME_DATA_GET_LINE (fd, i - 1);
426 hi2 = SCHRO_FRAME_DATA_GET_LINE (fd, i + 1);
428 orc_add2_rshift_add_s16_22_vert (lo, hi1, hi2, fd->width);
432 void
433 schro_iwt_5_3 (SchroFrameData *fd, int16_t * tmp)
435 int i;
436 int j;
438 for(i=-2;i<fd->height;i++) {
439 j = i+2;
440 if (j >= 0 && j < fd->height) {
441 wavelet_iwt_5_3_horiz (fd, j, tmp);
444 j = i+1;
445 if (j >= 0 && j < fd->height && (j&1) == 1) {
446 wavelet_iwt_5_3_vert_odd (fd, j);
449 j = i;
450 if (j >= 0 && j < fd->height && (j&1) == 0) {
451 wavelet_iwt_5_3_vert_even (fd, j);
457 /* Forward, 16-bit, Wavelet #2: Deslauriers-Dubuc 13,7 */
459 static void
460 wavelet_iwt_13_5_horiz (SchroFrameData *fd, int i, orc_int16 *tmp)
462 int width = fd->width;
463 int16_t *line = SCHRO_FRAME_DATA_GET_LINE (fd, i);
464 int16_t *hi = tmp + 4;
465 int16_t *lo = tmp + width/2 + 12;
467 orc_deinterleave2_lshift1_s16 (hi, lo, line, width / 2);
468 extend_1_2 (hi, width/2);
469 orc_mas4_horiz_sub_s16_1991_ip (lo, hi - 1, 1 << 3, 4, width/2);
470 extend_2_1 (lo, width/2);
471 orc_mas4_horiz_add_s16_1991_ip (hi, lo - 2, 1 << 4, 5, width/2);
472 join (line, hi, lo, width);
475 static void
476 wavelet_iwt_13_5_vert_odd (SchroFrameData *fd, int i)
478 int16_t *dest, *s1, *s2, *s3, *s4;
480 if (i & 1) {
481 if (i < 3 || i >= fd->height - 3) {
482 s1 = SCHRO_FRAME_DATA_GET_LINE(fd, CLAMP (i - 3, 0, fd->height - 2));
483 s2 = SCHRO_FRAME_DATA_GET_LINE(fd, CLAMP (i - 1, 0, fd->height - 2));
484 s3 = SCHRO_FRAME_DATA_GET_LINE(fd, CLAMP (i + 1, 0, fd->height - 2));
485 s4 = SCHRO_FRAME_DATA_GET_LINE(fd, CLAMP (i + 3, 0, fd->height - 2));
486 } else {
487 s1 = SCHRO_FRAME_DATA_GET_LINE(fd, i - 3);
488 s2 = SCHRO_FRAME_DATA_GET_LINE(fd, i - 1);
489 s3 = SCHRO_FRAME_DATA_GET_LINE(fd, i + 1);
490 s4 = SCHRO_FRAME_DATA_GET_LINE(fd, i + 3);
492 dest = SCHRO_FRAME_DATA_GET_LINE(fd, i);
493 orc_mas4_vert_sub_s16_1991 (dest, s1, s2, s3, s4, 1 << 3, 4, fd->width);
497 static void
498 wavelet_iwt_13_5_vert_even (SchroFrameData *fd, int i)
500 int16_t *dest, *s1, *s2, *s3, *s4;
502 if ((i & 1) == 0) {
503 if (i < 3 || i >= fd->height - 3) {
504 s1 = SCHRO_FRAME_DATA_GET_LINE(fd, CLAMP (i - 3, 1, fd->height - 1));
505 s2 = SCHRO_FRAME_DATA_GET_LINE(fd, CLAMP (i - 1, 1, fd->height - 1));
506 s3 = SCHRO_FRAME_DATA_GET_LINE(fd, CLAMP (i + 1, 1, fd->height - 1));
507 s4 = SCHRO_FRAME_DATA_GET_LINE(fd, CLAMP (i + 3, 1, fd->height - 1));
508 } else {
509 s1 = SCHRO_FRAME_DATA_GET_LINE(fd, i - 3);
510 s2 = SCHRO_FRAME_DATA_GET_LINE(fd, i - 1);
511 s3 = SCHRO_FRAME_DATA_GET_LINE(fd, i + 1);
512 s4 = SCHRO_FRAME_DATA_GET_LINE(fd, i + 3);
514 dest = SCHRO_FRAME_DATA_GET_LINE(fd, i);
515 orc_mas4_vert_add_s16_1991 (dest, s1, s2, s3, s4, 1 << 4, 5, fd->width);
519 void
520 schro_iwt_13_5 (SchroFrameData *fd, int16_t * tmp)
522 int i;
523 int j;
525 for(i=-6;i<fd->height;i++) {
526 j = i+6;
527 if (j >= 0 && j < fd->height) {
528 wavelet_iwt_13_5_horiz (fd, j, tmp);
531 j = i+3;
532 if (j >= 0 && j < fd->height && (j&1) == 1) {
533 wavelet_iwt_13_5_vert_odd (fd, j);
536 j = i;
537 if (j >= 0 && j < fd->height && (j&1) == 0) {
538 wavelet_iwt_13_5_vert_even (fd, j);
543 /* Forward, 16-bit, Wavelet #3,4: Haar 0 and Haar 1 */
545 static void
546 wavelet_iwt_haar_horiz (SchroFrameData *fd, int i, orc_int16 *tmp)
548 int width = fd->width;
549 int16_t *line = SCHRO_FRAME_DATA_GET_LINE (fd, i);
550 int16_t *hi = tmp + width / 2;
551 int16_t *lo = tmp;
553 orc_haar_deint_split_s16 (lo, hi, line, width / 2);
554 join (line, hi, lo, width);
557 static void
558 wavelet_iwt_haar_shift1_horiz (SchroFrameData *fd, int i, orc_int16 *tmp)
560 int width = fd->width;
561 int16_t *line = SCHRO_FRAME_DATA_GET_LINE (fd, i);
562 int16_t *hi = tmp + width / 2;
563 int16_t *lo = tmp;
565 orc_haar_deint_lshift1_split_s16 (lo, hi, line, width / 2);
566 join (line, hi, lo, width);
569 static void
570 wavelet_iwt_haar_vert (SchroFrameData *fd, int i, orc_int16 *tmp)
572 int16_t *hi = SCHRO_FRAME_DATA_GET_LINE (fd, i);
573 int16_t *lo = SCHRO_FRAME_DATA_GET_LINE (fd, i + 1);
575 orc_haar_split_s16_op (hi, lo, tmp, tmp + fd->width, fd->width);
578 static void
579 schro_iwt_haar0 (SchroFrameData *fd, int16_t * tmp)
581 int i;
583 for(i=0;i<fd->height;i+=2) {
584 wavelet_iwt_haar_horiz (fd, i, tmp);
585 wavelet_iwt_haar_horiz (fd, i+1, tmp + fd->width);
587 wavelet_iwt_haar_vert (fd, i, tmp);
591 static void
592 schro_iwt_haar1 (SchroFrameData *fd, int16_t * tmp)
594 int i;
596 for(i=0;i<fd->height;i+=2) {
597 wavelet_iwt_haar_shift1_horiz (fd, i, tmp);
598 wavelet_iwt_haar_shift1_horiz (fd, i+1, tmp + fd->width);
600 wavelet_iwt_haar_vert (fd, i, tmp);
604 /* Forward, 16-bit, Wavelet #5: Fidelity */
606 static void
607 mas8_add_s16 (int16_t * dest, const int16_t * src, const int16_t * weights,
608 int offset, int shift, int n)
610 int i;
611 for (i = 0; i < n; i++) {
612 int x = offset;
613 x += src[i + 0] * weights[0];
614 x += src[i + 1] * weights[1];
615 x += src[i + 2] * weights[2];
616 x += src[i + 3] * weights[3];
617 x += src[i + 4] * weights[4];
618 x += src[i + 5] * weights[5];
619 x += src[i + 6] * weights[6];
620 x += src[i + 7] * weights[7];
621 dest[i] += x >> shift;
625 static void
626 schro_split_ext_fidelity (int16_t * hi, int16_t * lo, int n)
628 static const int16_t stage1_weights[] = { -8, 21, -46, 161, 161, -46, 21, -8 };
629 static const int16_t stage2_weights[] = { 2, -10, 25, -81, -81, 25, -10, 2 };
631 extend_4_3 (lo, n);
632 mas8_add_s16 (hi, lo - 4, stage1_weights, 128, 8, n);
633 extend_3_4 (hi, n);
634 mas8_add_s16 (lo, hi - 3, stage2_weights, 127, 8, n);
637 static void
638 wavelet_iwt_fidelity_horiz (SchroFrameData *fd, int i, orc_int16 *tmp)
640 int width = fd->width;
641 int16_t *line = SCHRO_FRAME_DATA_GET_LINE (fd, i);
642 int16_t *hi = tmp + 4;
643 int16_t *lo = tmp + width/2 + 12;
645 orc_deinterleave2_s16 (hi, lo, line, width / 2);
646 schro_split_ext_fidelity (hi, lo, width / 2);
647 join (line, hi, lo, width);
650 static void
651 mas8_vert_add_s16_2 (int16_t * dest, const int16_t * src,
652 int16_t ** s, const int *weights, int offset, int shift, int n)
654 int i;
655 int j;
656 for (i = 0; i < n; i++) {
657 int x = offset;
658 for (j = 0; j < 8; j++) {
659 x += s[j][i] * weights[j];
661 dest[i] = src[i] + (x >> shift);
665 static void
666 wavelet_iwt_fidelity_vert_odd (SchroFrameData *fd, int i)
668 int width = fd->width;
669 int height = fd->height;
670 int16_t *s[8];
671 int j;
673 if (i & 1) {
674 static const int weights[] = { 2, -10, 25, -81, -81, 25, -10, 2 };
675 for (j = 0; j < 8; j++) {
676 s[j] = SCHRO_FRAME_DATA_GET_LINE (fd, CLAMP (i - 7 + j * 2, 0, height - 2));
678 mas8_vert_add_s16_2 (SCHRO_FRAME_DATA_GET_LINE (fd, i),
679 SCHRO_FRAME_DATA_GET_LINE (fd, i), s,
680 weights, 127, 8, width);
684 static void
685 wavelet_iwt_fidelity_vert_even (SchroFrameData *fd, int i)
687 int width = fd->width;
688 int height = fd->height;
689 int16_t *s[8];
690 int j;
692 if ((i & 1) == 0) {
693 static const int weights[] = { -8, 21, -46, 161, 161, -46, 21, -8 };
694 for (j = 0; j < 8; j++) {
695 s[j] = SCHRO_FRAME_DATA_GET_LINE (fd, CLAMP (i - 7 + j * 2, 1, height - 1));
697 mas8_vert_add_s16_2 (SCHRO_FRAME_DATA_GET_LINE (fd, i),
698 SCHRO_FRAME_DATA_GET_LINE (fd, i), s,
699 weights, 128, 8, width);
703 void
704 schro_iwt_fidelity (SchroFrameData *fd, int16_t * tmp)
706 int i;
707 int j;
709 for(i=-14;i<fd->height;i++) {
710 j = i+14;
711 if (j >= 0 && j < fd->height) {
712 wavelet_iwt_fidelity_horiz (fd, j, tmp);
715 j = i+7;
716 if (j >= 0 && j < fd->height && (j&1) == 0) {
717 wavelet_iwt_fidelity_vert_even (fd, j);
720 j = i;
721 if (j >= 0 && j < fd->height && (j&1) == 1) {
722 wavelet_iwt_fidelity_vert_odd (fd, j);
727 /* Forward, 16-bit, Wavelet #6: Daubechies 9,7 */
729 static void
730 schro_split_ext_daub97 (int16_t * hi, int16_t * lo, int n)
732 extend_1_1 (hi, n);
733 orc_mas2_sub_s16_ip (lo, hi, 6497, 2048, 12, n);
734 extend_1_1 (lo, n);
735 orc_mas2_sub_s16_ip (hi, lo - 1, 217, 2048, 12, n);
736 extend_1_1 (hi, n);
737 orc_mas2_add_s16_ip (lo, hi, 3616, 2048, 12, n);
738 extend_1_1 (lo, n);
739 orc_mas2_add_s16_ip (hi, lo - 1, 1817, 2048, 12, n);
742 static void
743 wavelet_iwt_daub97_horiz (SchroFrameData *fd, int i, orc_int16 *tmp)
745 int width = fd->width;
746 int16_t *line = SCHRO_FRAME_DATA_GET_LINE (fd, i);
747 int16_t *hi = tmp + 4;
748 int16_t *lo = tmp + width/2 + 12;
750 orc_deinterleave2_lshift1_s16 (hi, lo, line, width / 2);
751 schro_split_ext_daub97 (hi, lo, width / 2);
752 join (line, hi, lo, width);
755 static void
756 wavelet_iwt_daub97_vert1_odd (SchroFrameData *fd, int i)
758 int width = fd->width;
760 if (i & 1) {
761 int16_t *hi;
762 int16_t *lo1, *lo2;
764 hi = SCHRO_FRAME_DATA_GET_LINE(fd, i);
765 lo1 = SCHRO_FRAME_DATA_GET_LINE(fd, i - 1);
766 if (i + 1 < fd->height) {
767 lo2 = SCHRO_FRAME_DATA_GET_LINE(fd, i + 1);
768 } else {
769 lo2 = lo1;
772 orc_mas2_sub_s16_op (hi, hi, lo1, lo2, 6497, 2048, 12, width);
776 static void
777 wavelet_iwt_daub97_vert1_even (SchroFrameData *fd, int i)
779 int width = fd->width;
781 if ((i & 1) == 0) {
782 int16_t *lo;
783 int16_t *hi1, *hi2;
785 lo = SCHRO_FRAME_DATA_GET_LINE(fd, i);
786 if (i == 0) {
787 hi1 = SCHRO_FRAME_DATA_GET_LINE (fd, 1);
788 } else {
789 hi1 = SCHRO_FRAME_DATA_GET_LINE (fd, i-1);
791 hi2 = SCHRO_FRAME_DATA_GET_LINE (fd, i + 1);
793 orc_mas2_sub_s16_op (lo, lo, hi1, hi2, 217, 2048, 12, width);
797 static void
798 wavelet_iwt_daub97_vert2_odd (SchroFrameData *fd, int i)
800 int width = fd->width;
802 if (i & 1) {
803 int16_t *hi;
804 int16_t *lo1, *lo2;
806 hi = SCHRO_FRAME_DATA_GET_LINE(fd, i);
807 lo1 = SCHRO_FRAME_DATA_GET_LINE(fd, i - 1);
808 if (i + 1 < fd->height) {
809 lo2 = SCHRO_FRAME_DATA_GET_LINE(fd, i + 1);
810 } else {
811 lo2 = lo1;
814 orc_mas2_add_s16_op (hi, hi, lo1, lo2, 3616, 2048, 12, width);
818 static void
819 wavelet_iwt_daub97_vert2_even (SchroFrameData *fd, int i)
821 int width = fd->width;
823 if ((i & 1) == 0) {
824 int16_t *lo;
825 int16_t *hi1, *hi2;
827 lo = SCHRO_FRAME_DATA_GET_LINE(fd, i);
828 if (i == 0) {
829 hi1 = SCHRO_FRAME_DATA_GET_LINE (fd, 1);
830 } else {
831 hi1 = SCHRO_FRAME_DATA_GET_LINE (fd, i-1);
833 hi2 = SCHRO_FRAME_DATA_GET_LINE (fd, i + 1);
835 orc_mas2_add_s16_op (lo, lo, hi1, hi2, 1817, 2048, 12, width);
839 void
840 schro_iwt_daub_9_7 (SchroFrameData *fd, int16_t * tmp)
842 int i;
843 int j;
845 for(i=-4;i<fd->height;i++) {
846 j = i+4;
847 if (j >= 0 && j < fd->height) {
848 wavelet_iwt_daub97_horiz (fd, j, tmp);
851 j = i+3;
852 if (j >= 0 && j < fd->height && (j&1) == 1) {
853 wavelet_iwt_daub97_vert1_odd (fd, j);
856 j = i+2;
857 if (j >= 0 && j < fd->height && (j&1) == 0) {
858 wavelet_iwt_daub97_vert1_even (fd, j);
861 j = i+1;
862 if (j >= 0 && j < fd->height && (j&1) == 1) {
863 wavelet_iwt_daub97_vert2_odd (fd, j);
866 j = i;
867 if (j >= 0 && j < fd->height && (j&1) == 0) {
868 wavelet_iwt_daub97_vert2_even (fd, j);
873 /* Forward, 32-bit, Wavelet #0: Deslauriers-Dubuc 9,7 */
875 static void
876 wavelet_iwt_desl_9_3_horiz_s32 (SchroFrameData * fd, int i, orc_int32 *tmp)
878 int width = fd->width;
879 int32_t *line = SCHRO_FRAME_DATA_GET_LINE (fd, i);
880 int32_t *hi = tmp + 4;
881 int32_t *lo = tmp + width/2 + 12;
883 orc_deinterleave2_lshift1_s32 (hi, lo, line, width / 2);
884 extend_1_2_s32 (hi, width/2);
885 orc_mas4_horiz_sub_s32_1991_ip (lo, hi - 1, 1 << 3, 4, width/2);
886 extend_1_0_s32 (lo, width/2);
887 orc_add2_rshift_add_s32_22 (hi, lo - 1, width/2);
888 join_s32 (line, hi, lo, width);
891 static void
892 wavelet_iwt_desl_9_3_vert_odd_s32 (SchroFrameData *fd, int i)
894 int width = fd->width;
895 int height = fd->height;
897 if (i & 1) {
898 if (i < 3 || i >= height - 3) {
899 orc_mas4_vert_sub_s32_1991 (
900 SCHRO_FRAME_DATA_GET_LINE (fd, i),
901 SCHRO_FRAME_DATA_GET_LINE (fd, CLAMP (i - 3, 0, height - 2)),
902 SCHRO_FRAME_DATA_GET_LINE (fd, CLAMP (i - 1, 0, height - 2)),
903 SCHRO_FRAME_DATA_GET_LINE (fd, CLAMP (i + 1, 0, height - 2)),
904 SCHRO_FRAME_DATA_GET_LINE (fd, CLAMP (i + 3, 0, height - 2)), 1 << 3, 4, width);
905 } else {
906 orc_mas4_vert_sub_s32_1991 (
907 SCHRO_FRAME_DATA_GET_LINE (fd, i),
908 SCHRO_FRAME_DATA_GET_LINE (fd, i - 3),
909 SCHRO_FRAME_DATA_GET_LINE (fd, i - 1),
910 SCHRO_FRAME_DATA_GET_LINE (fd, i + 1),
911 SCHRO_FRAME_DATA_GET_LINE (fd, i + 3), 1 << 3, 4, width);
916 static void
917 wavelet_iwt_desl_9_3_vert_even_s32 (SchroFrameData *fd, int i)
919 int width = fd->width;
921 if ((i & 1) == 0) {
922 int32_t *lo;
923 int32_t *hi1, *hi2;
925 lo = SCHRO_FRAME_DATA_GET_LINE (fd, i);
926 if (i == 0) {
927 hi1 = SCHRO_FRAME_DATA_GET_LINE (fd, 1);
928 } else {
929 hi1 = SCHRO_FRAME_DATA_GET_LINE (fd, i-1);
931 hi2 = SCHRO_FRAME_DATA_GET_LINE (fd, i+1);
933 orc_add2_rshift_add_s32_22_vert (lo, hi1, hi2, width);
937 void
938 schro_iwt_desl_9_3_s32 (SchroFrameData *fd, int32_t * tmp)
940 int i;
941 int j;
943 for(i=-6;i<fd->height;i++) {
944 j = i+6;
945 if (j >= 0 && j < fd->height) {
946 wavelet_iwt_desl_9_3_horiz_s32 (fd, j, tmp);
949 j = i+3;
950 if (j >= 0 && j < fd->height && (j&1) == 1) {
951 wavelet_iwt_desl_9_3_vert_odd_s32 (fd, j);
954 j = i;
955 if (j >= 0 && j < fd->height && (j&1) == 0) {
956 wavelet_iwt_desl_9_3_vert_even_s32 (fd, j);
962 /* Forward, 32-bit, Wavelet #1: LeGall 5,3 */
964 static void
965 wavelet_iwt_5_3_horiz_s32 (SchroFrameData *fd, int i, orc_int32 *tmp)
967 int width = fd->width;
968 int32_t *line = SCHRO_FRAME_DATA_GET_LINE (fd, i);
969 int32_t *hi = tmp + 4;
970 int32_t *lo = tmp + width/2 + 12;
972 orc_deinterleave2_lshift1_s32 (hi, lo, line, width / 2);
973 extend_1_1_s32 (hi, width/2);
974 orc_add2_rshift_sub_s32_11 (lo, hi, width/2);
975 extend_1_1_s32 (lo, width/2);
976 orc_add2_rshift_add_s32_22 (hi, lo - 1, width/2);
977 join_s32 (line, hi, lo, width);
980 static void
981 wavelet_iwt_5_3_vert_odd_s32 (SchroFrameData * fd, int i)
984 if (i & 1) {
985 int32_t *hi;
986 int32_t *lo1, *lo2;
988 hi = SCHRO_FRAME_DATA_GET_LINE (fd, i);
989 lo1 = SCHRO_FRAME_DATA_GET_LINE (fd, i - 1);
990 if (i + 1 < fd->height) {
991 lo2 = SCHRO_FRAME_DATA_GET_LINE (fd, i + 1);
992 } else {
993 lo2 = lo1;
996 orc_add2_rshift_sub_s32_11_vert (hi, lo1, lo2, fd->width);
1000 static void
1001 wavelet_iwt_5_3_vert_even_s32 (SchroFrameData *fd, int i)
1004 if ((i & 1) == 0) {
1005 int32_t *lo;
1006 int32_t *hi1, *hi2;
1008 lo = SCHRO_FRAME_DATA_GET_LINE (fd, i);
1009 if (i == 0) {
1010 hi1 = SCHRO_FRAME_DATA_GET_LINE (fd, 1);
1011 } else {
1012 hi1 = SCHRO_FRAME_DATA_GET_LINE (fd, i - 1);
1014 hi2 = SCHRO_FRAME_DATA_GET_LINE (fd, i + 1);
1016 orc_add2_rshift_add_s32_22_vert (lo, hi1, hi2, fd->width);
1020 void
1021 schro_iwt_5_3_s32 (SchroFrameData *fd, int32_t * tmp)
1023 int i;
1024 int j;
1026 for(i=-6;i<fd->height;i++) {
1027 j = i+6;
1028 if (j >= 0 && j < fd->height) {
1029 wavelet_iwt_5_3_horiz_s32 (fd, j, tmp);
1032 j = i+3;
1033 if (j >= 0 && j < fd->height && (j&1) == 1) {
1034 wavelet_iwt_5_3_vert_odd_s32 (fd, j);
1037 j = i;
1038 if (j >= 0 && j < fd->height && (j&1) == 0) {
1039 wavelet_iwt_5_3_vert_even_s32 (fd, j);
1045 /* Forward, 32-bit, Wavelet #2: Deslauriers-Dubuc 13,7 */
1047 static void
1048 wavelet_iwt_13_5_horiz_s32 (SchroFrameData *fd, int i, orc_int32 *tmp)
1050 int width = fd->width;
1051 int32_t *line = SCHRO_FRAME_DATA_GET_LINE (fd, i);
1052 int32_t *hi = tmp + 4;
1053 int32_t *lo = tmp + width/2 + 12;
1055 orc_deinterleave2_lshift1_s32 (hi, lo, line, width / 2);
1056 extend_1_2_s32 (hi, width/2);
1057 orc_mas4_horiz_sub_s32_1991_ip (lo, hi - 1, 1 << 3, 4, width/2);
1058 extend_2_1_s32 (lo, width/2);
1059 orc_mas4_horiz_add_s32_1991_ip (hi, lo - 2, 1 << 4, 5, width/2);
1060 join_s32 (line, hi, lo, width);
1063 static void
1064 wavelet_iwt_13_5_vert_odd_s32 (SchroFrameData *fd, int i)
1066 int32_t *dest, *s1, *s2, *s3, *s4;
1068 if (i & 1) {
1069 if (i < 3 || i >= fd->height - 3) {
1070 s1 = SCHRO_FRAME_DATA_GET_LINE(fd, CLAMP (i - 3, 0, fd->height - 2));
1071 s2 = SCHRO_FRAME_DATA_GET_LINE(fd, CLAMP (i - 1, 0, fd->height - 2));
1072 s3 = SCHRO_FRAME_DATA_GET_LINE(fd, CLAMP (i + 1, 0, fd->height - 2));
1073 s4 = SCHRO_FRAME_DATA_GET_LINE(fd, CLAMP (i + 3, 0, fd->height - 2));
1074 } else {
1075 s1 = SCHRO_FRAME_DATA_GET_LINE(fd, i - 3);
1076 s2 = SCHRO_FRAME_DATA_GET_LINE(fd, i - 1);
1077 s3 = SCHRO_FRAME_DATA_GET_LINE(fd, i + 1);
1078 s4 = SCHRO_FRAME_DATA_GET_LINE(fd, i + 3);
1080 dest = SCHRO_FRAME_DATA_GET_LINE(fd, i);
1081 orc_mas4_vert_sub_s32_1991 (dest, s1, s2, s3, s4, 1 << 3, 4, fd->width);
1085 static void
1086 wavelet_iwt_13_5_vert_even_s32 (SchroFrameData *fd, int i)
1088 int32_t *dest, *s1, *s2, *s3, *s4;
1090 if ((i & 1) == 0) {
1091 if (i < 3 || i >= fd->height - 3) {
1092 s1 = SCHRO_FRAME_DATA_GET_LINE(fd, CLAMP (i - 3, 1, fd->height - 1));
1093 s2 = SCHRO_FRAME_DATA_GET_LINE(fd, CLAMP (i - 1, 1, fd->height - 1));
1094 s3 = SCHRO_FRAME_DATA_GET_LINE(fd, CLAMP (i + 1, 1, fd->height - 1));
1095 s4 = SCHRO_FRAME_DATA_GET_LINE(fd, CLAMP (i + 3, 1, fd->height - 1));
1096 } else {
1097 s1 = SCHRO_FRAME_DATA_GET_LINE(fd, i - 3);
1098 s2 = SCHRO_FRAME_DATA_GET_LINE(fd, i - 1);
1099 s3 = SCHRO_FRAME_DATA_GET_LINE(fd, i + 1);
1100 s4 = SCHRO_FRAME_DATA_GET_LINE(fd, i + 3);
1102 dest = SCHRO_FRAME_DATA_GET_LINE(fd, i);
1103 orc_mas4_vert_add_s32_1991 (dest, s1, s2, s3, s4, 1 << 4, 5, fd->width);
1107 void
1108 schro_iwt_13_5_s32 (SchroFrameData *fd, int32_t * tmp)
1110 int i;
1111 int j;
1113 for(i=-6;i<fd->height;i++) {
1114 j = i+6;
1115 if (j >= 0 && j < fd->height) {
1116 wavelet_iwt_13_5_horiz_s32 (fd, j, tmp);
1119 j = i+3;
1120 if (j >= 0 && j < fd->height && (j&1) == 1) {
1121 wavelet_iwt_13_5_vert_odd_s32 (fd, j);
1124 j = i;
1125 if (j >= 0 && j < fd->height && (j&1) == 0) {
1126 wavelet_iwt_13_5_vert_even_s32 (fd, j);
1131 /* Forward, 32-bit, Wavelet #3,4: Haar 0 and Haar 1 */
1133 static void
1134 wavelet_iwt_haar_horiz_s32 (SchroFrameData *fd, int i, orc_int32 *tmp)
1136 int width = fd->width;
1137 int32_t *line = SCHRO_FRAME_DATA_GET_LINE (fd, i);
1138 int32_t *hi = tmp + width / 2;
1139 int32_t *lo = tmp;
1141 orc_haar_deint_split_s32 (lo, hi, line, width / 2);
1142 join_s32 (line, hi, lo, width);
1145 static void
1146 wavelet_iwt_haar_shift1_horiz_s32 (SchroFrameData *fd, int i, orc_int32 *tmp)
1148 int width = fd->width;
1149 int32_t *line = SCHRO_FRAME_DATA_GET_LINE (fd, i);
1150 int32_t *hi = tmp + width / 2;
1151 int32_t *lo = tmp;
1153 orc_haar_deint_lshift1_split_s32 (lo, hi, line, width / 2);
1154 join_s32 (line, hi, lo, width);
1157 static void
1158 wavelet_iwt_haar_vert_s32 (SchroFrameData *fd, int i, orc_int32 *tmp)
1160 int32_t *hi = SCHRO_FRAME_DATA_GET_LINE (fd, i);
1161 int32_t *lo = SCHRO_FRAME_DATA_GET_LINE (fd, i + 1);
1163 orc_haar_split_s32_op (hi, lo, tmp, tmp + fd->width, fd->width);
1166 static void
1167 schro_iwt_haar0_s32 (SchroFrameData *fd, int32_t * tmp)
1169 int i;
1171 for(i=0;i<fd->height;i+=2) {
1172 wavelet_iwt_haar_horiz_s32 (fd, i, tmp);
1173 wavelet_iwt_haar_horiz_s32 (fd, i+1, tmp + fd->width);
1175 wavelet_iwt_haar_vert_s32 (fd, i, tmp);
1179 static void
1180 schro_iwt_haar1_s32 (SchroFrameData *fd, int32_t * tmp)
1182 int i;
1184 for(i=0;i<fd->height;i+=2) {
1185 wavelet_iwt_haar_shift1_horiz_s32 (fd, i, tmp);
1186 wavelet_iwt_haar_shift1_horiz_s32 (fd, i+1, tmp + fd->width);
1188 wavelet_iwt_haar_vert_s32 (fd, i, tmp);
1192 /* Forward, 32-bit, Wavelet #5: Fidelity */
1194 static void
1195 mas8_add_s32 (int32_t * dest, const int32_t * src, const int32_t * weights,
1196 int offset, int shift, int n)
1198 int i;
1199 for (i = 0; i < n; i++) {
1200 int x = offset;
1201 x += src[i + 0] * weights[0];
1202 x += src[i + 1] * weights[1];
1203 x += src[i + 2] * weights[2];
1204 x += src[i + 3] * weights[3];
1205 x += src[i + 4] * weights[4];
1206 x += src[i + 5] * weights[5];
1207 x += src[i + 6] * weights[6];
1208 x += src[i + 7] * weights[7];
1209 dest[i] += x >> shift;
1213 static void
1214 schro_split_ext_fidelity_s32 (int32_t * hi, int32_t * lo, int n)
1216 static const int32_t stage1_weights[] = { -8, 21, -46, 161, 161, -46, 21, -8 };
1217 static const int32_t stage2_weights[] = { 2, -10, 25, -81, -81, 25, -10, 2 };
1219 extend_4_3_s32 (lo, n);
1220 mas8_add_s32 (hi, lo - 4, stage1_weights, 128, 8, n);
1221 extend_3_4_s32 (hi, n);
1222 mas8_add_s32 (lo, hi - 3, stage2_weights, 127, 8, n);
1225 static void
1226 wavelet_iwt_fidelity_horiz_s32 (SchroFrameData *fd, int i, orc_int32 *tmp)
1228 int width = fd->width;
1229 int32_t *line = SCHRO_FRAME_DATA_GET_LINE (fd, i);
1230 int32_t *hi = tmp + 4;
1231 int32_t *lo = tmp + width/2 + 12;
1233 orc_deinterleave2_s32 (hi, lo, line, width / 2);
1234 schro_split_ext_fidelity_s32 (hi, lo, width / 2);
1235 join_s32 (line, hi, lo, width);
1238 static void
1239 mas8_vert_add_s32_2 (int32_t * dest, const int32_t * src,
1240 int32_t ** s, const int32_t *weights, int offset, int shift, int n)
1242 int i;
1243 int j;
1244 for (i = 0; i < n; i++) {
1245 int x = offset;
1246 for (j = 0; j < 8; j++) {
1247 x += s[j][i] * weights[j];
1249 dest[i] = src[i] + (x >> shift);
1253 static void
1254 wavelet_iwt_fidelity_vert_odd_s32 (SchroFrameData *fd, int i)
1256 int width = fd->width;
1257 int height = fd->height;
1258 int32_t *s[8];
1259 int j;
1261 if (i & 1) {
1262 static const int32_t weights[] = { 2, -10, 25, -81, -81, 25, -10, 2 };
1263 for (j = 0; j < 8; j++) {
1264 s[j] = SCHRO_FRAME_DATA_GET_LINE (fd, CLAMP (i - 7 + j * 2, 0, height - 2));
1266 mas8_vert_add_s32_2 (SCHRO_FRAME_DATA_GET_LINE (fd, i),
1267 SCHRO_FRAME_DATA_GET_LINE (fd, i), s,
1268 weights, 127, 8, width);
1272 static void
1273 wavelet_iwt_fidelity_vert_even_s32 (SchroFrameData *fd, int i)
1275 int width = fd->width;
1276 int height = fd->height;
1277 int32_t *s[8];
1278 int j;
1280 if ((i & 1) == 0) {
1281 static const int32_t weights[] = { -8, 21, -46, 161, 161, -46, 21, -8 };
1282 for (j = 0; j < 8; j++) {
1283 s[j] = SCHRO_FRAME_DATA_GET_LINE (fd, CLAMP (i - 7 + j * 2, 1, height - 1));
1285 mas8_vert_add_s32_2 (SCHRO_FRAME_DATA_GET_LINE (fd, i),
1286 SCHRO_FRAME_DATA_GET_LINE (fd, i), s,
1287 weights, 128, 8, width);
1291 void
1292 schro_iwt_fidelity_s32 (SchroFrameData *fd, int32_t * tmp)
1294 int i;
1295 int j;
1297 for(i=-14;i<fd->height;i++) {
1298 j = i+14;
1299 if (j >= 0 && j < fd->height) {
1300 wavelet_iwt_fidelity_horiz_s32 (fd, j, tmp);
1303 j = i+7;
1304 if (j >= 0 && j < fd->height && (j&1) == 0) {
1305 wavelet_iwt_fidelity_vert_even_s32 (fd, j);
1308 j = i;
1309 if (j >= 0 && j < fd->height && (j&1) == 1) {
1310 wavelet_iwt_fidelity_vert_odd_s32 (fd, j);
1315 /* Forward, 32-bit, Wavelet #6: Daubechies 9,7 */
1317 static void
1318 schro_split_ext_daub97_s32 (int32_t * hi, int32_t * lo, int n)
1320 extend_1_1_s32 (hi, n);
1321 orc_mas2_sub_s32_ip (lo, hi, 6497, 2048, 12, n);
1322 extend_1_1_s32 (lo, n);
1323 orc_mas2_sub_s32_ip (hi, lo - 1, 217, 2048, 12, n);
1324 extend_1_1_s32 (hi, n);
1325 orc_mas2_add_s32_ip (lo, hi, 3616, 2048, 12, n);
1326 extend_1_1_s32 (lo, n);
1327 orc_mas2_add_s32_ip (hi, lo - 1, 1817, 2048, 12, n);
1330 static void
1331 wavelet_iwt_daub97_horiz_s32 (SchroFrameData *fd, int i, orc_int32 *tmp)
1333 int width = fd->width;
1334 int32_t *line = SCHRO_FRAME_DATA_GET_LINE (fd, i);
1335 int32_t *hi = tmp + 4;
1336 int32_t *lo = tmp + width/2 + 12;
1338 orc_deinterleave2_lshift1_s32 (hi, lo, line, width / 2);
1339 schro_split_ext_daub97_s32 (hi, lo, width / 2);
1340 join_s32 (line, hi, lo, width);
1343 static void
1344 wavelet_iwt_daub97_vert1_odd_s32 (SchroFrameData *fd, int i)
1346 int width = fd->width;
1348 if (i & 1) {
1349 int32_t *hi;
1350 int32_t *lo1, *lo2;
1352 hi = SCHRO_FRAME_DATA_GET_LINE(fd, i);
1353 lo1 = SCHRO_FRAME_DATA_GET_LINE(fd, i - 1);
1354 if (i + 1 < fd->height) {
1355 lo2 = SCHRO_FRAME_DATA_GET_LINE(fd, i + 1);
1356 } else {
1357 lo2 = lo1;
1360 orc_mas2_sub_s32_op (hi, hi, lo1, lo2, 6497, 2048, 12, width);
1364 static void
1365 wavelet_iwt_daub97_vert1_even_s32 (SchroFrameData *fd, int i)
1367 int width = fd->width;
1369 if ((i & 1) == 0) {
1370 int32_t *lo;
1371 int32_t *hi1, *hi2;
1373 lo = SCHRO_FRAME_DATA_GET_LINE(fd, i);
1374 if (i == 0) {
1375 hi1 = SCHRO_FRAME_DATA_GET_LINE (fd, 1);
1376 } else {
1377 hi1 = SCHRO_FRAME_DATA_GET_LINE (fd, i-1);
1379 hi2 = SCHRO_FRAME_DATA_GET_LINE (fd, i + 1);
1381 orc_mas2_sub_s32_op (lo, lo, hi1, hi2, 217, 2048, 12, width);
1385 static void
1386 wavelet_iwt_daub97_vert2_odd_s32 (SchroFrameData *fd, int i)
1388 int width = fd->width;
1390 if (i & 1) {
1391 int32_t *hi;
1392 int32_t *lo1, *lo2;
1394 hi = SCHRO_FRAME_DATA_GET_LINE(fd, i);
1395 lo1 = SCHRO_FRAME_DATA_GET_LINE(fd, i - 1);
1396 if (i + 1 < fd->height) {
1397 lo2 = SCHRO_FRAME_DATA_GET_LINE(fd, i + 1);
1398 } else {
1399 lo2 = lo1;
1402 orc_mas2_add_s32_op (hi, hi, lo1, lo2, 3616, 2048, 12, width);
1406 static void
1407 wavelet_iwt_daub97_vert2_even_s32 (SchroFrameData *fd, int i)
1409 int width = fd->width;
1411 if ((i & 1) == 0) {
1412 int32_t *lo;
1413 int32_t *hi1, *hi2;
1415 lo = SCHRO_FRAME_DATA_GET_LINE(fd, i);
1416 if (i == 0) {
1417 hi1 = SCHRO_FRAME_DATA_GET_LINE (fd, 1);
1418 } else {
1419 hi1 = SCHRO_FRAME_DATA_GET_LINE (fd, i-1);
1421 hi2 = SCHRO_FRAME_DATA_GET_LINE (fd, i + 1);
1423 orc_mas2_add_s32_op (lo, lo, hi1, hi2, 1817, 2048, 12, width);
1427 void
1428 schro_iwt_daub_9_7_s32 (SchroFrameData *fd, int32_t * tmp)
1430 int i;
1431 int j;
1433 for(i=-4;i<fd->height;i++) {
1434 j = i+4;
1435 if (j >= 0 && j < fd->height) {
1436 wavelet_iwt_daub97_horiz_s32 (fd, j, tmp);
1439 j = i+3;
1440 if (j >= 0 && j < fd->height && (j&1) == 1) {
1441 wavelet_iwt_daub97_vert1_odd_s32 (fd, j);
1444 j = i+2;
1445 if (j >= 0 && j < fd->height && (j&1) == 0) {
1446 wavelet_iwt_daub97_vert1_even_s32 (fd, j);
1449 j = i+1;
1450 if (j >= 0 && j < fd->height && (j&1) == 1) {
1451 wavelet_iwt_daub97_vert2_odd_s32 (fd, j);
1454 j = i;
1455 if (j >= 0 && j < fd->height && (j&1) == 0) {
1456 wavelet_iwt_daub97_vert2_even_s32 (fd, j);
1462 /* Reverse transforms */
1464 /* Reverse, 16-bit, Wavelet #0: Deslauriers-Dubuc 9,7 */
1466 static void
1467 schro_synth_ext_desl93 (int16_t * hi, int16_t * lo, int n)
1469 extend_2_2 (lo, n);
1470 orc_add2_rshift_sub_s16_22 (hi, lo - 1, n);
1471 extend_2_2 (hi, n);
1472 orc_mas4_horiz_add_s16_1991_ip (lo, hi - 1, 1 << 3, 4, n);
1475 void
1476 schro_iiwt_desl_9_3 (SchroFrameData *dest, SchroFrameData *src, int16_t * tmp)
1478 int i;
1479 int j;
1481 for(i=-7;i<dest->height;i++){
1482 j = i + 7;
1483 if (j == CLAMP(j,0,src->height-1)) {
1484 if (!(j & 1)) {
1485 int16_t *lo;
1486 int16_t *hi1, *hi2;
1488 lo = SCHRO_FRAME_DATA_GET_LINE (src, j);
1489 if (j == 0) {
1490 hi1 = SCHRO_FRAME_DATA_GET_LINE (src, 1);
1491 } else {
1492 hi1 = SCHRO_FRAME_DATA_GET_LINE (src, j-1);
1494 hi2 = SCHRO_FRAME_DATA_GET_LINE (src, j+1);
1496 orc_add2_rshift_sub_s16_22_vert (lo, hi1, hi2, src->width);
1500 j = i + 3;
1501 if (j == CLAMP(j,0,src->height-1)) {
1502 if (j & 1) {
1503 if (j < 3 || j >= src->height - 3) {
1504 orc_mas4_vert_add_s16_1991 (
1505 SCHRO_FRAME_DATA_GET_LINE (src, j),
1506 SCHRO_FRAME_DATA_GET_LINE (src, CLAMP (j - 3, 0, src->height - 2)),
1507 SCHRO_FRAME_DATA_GET_LINE (src, CLAMP (j - 1, 0, src->height - 2)),
1508 SCHRO_FRAME_DATA_GET_LINE (src, CLAMP (j + 1, 0, src->height - 2)),
1509 SCHRO_FRAME_DATA_GET_LINE (src, CLAMP (j + 3, 0, src->height - 2)),
1510 1 << 3, 4, src->width);
1511 } else {
1512 orc_mas4_vert_add_s16_1991 (
1513 SCHRO_FRAME_DATA_GET_LINE (src, j),
1514 SCHRO_FRAME_DATA_GET_LINE (src, j - 3),
1515 SCHRO_FRAME_DATA_GET_LINE (src, j - 1),
1516 SCHRO_FRAME_DATA_GET_LINE (src, j + 1),
1517 SCHRO_FRAME_DATA_GET_LINE (src, j + 3),
1518 1 << 3, 4, src->width);
1523 j = i;
1524 /* horizontal wavelet */
1525 if (j == CLAMP(j,0,src->height-1)) {
1526 int16_t *hi = tmp + 4;
1527 int16_t *lo = tmp + src->width/2 + 12;
1529 orc_memcpy (hi, SCHRO_FRAME_DATA_GET_PIXEL_S16(src, 0, j),
1530 src->width / 2 * sizeof (int16_t));
1531 orc_memcpy (lo, SCHRO_FRAME_DATA_GET_PIXEL_S16(src, src->width/2, j),
1532 src->width / 2 * sizeof (int16_t));
1533 schro_synth_ext_desl93 (hi, lo, src->width / 2);
1534 orc_interleave2_rrshift1_s16 (
1535 SCHRO_FRAME_DATA_GET_PIXEL_S16 (dest, 0, j), hi, lo, src->width / 2);
1540 /* Reverse, 16-bit, Wavelet #1: LeGall 5,3 */
1542 static void
1543 schro_synth_ext_53 (int16_t * hi, int16_t * lo, int n)
1545 extend_1_1 (lo, n);
1546 orc_add2_rshift_sub_s16_22 (hi, lo - 1, n);
1547 extend_1_1 (hi, n);
1548 orc_add2_rshift_add_s16_11 (lo, hi, n);
1551 void
1552 schro_iiwt_5_3 (SchroFrameData *dest, SchroFrameData *src, int16_t * tmp)
1554 int i;
1555 int j;
1557 for(i=-2;i<dest->height;i++){
1558 j = i + 2;
1559 if (j == CLAMP(j,0,src->height-1)) {
1560 if (!(j & 1)) {
1561 int16_t *lo;
1562 int16_t *hi1, *hi2;
1564 lo = SCHRO_FRAME_DATA_GET_LINE (src, j);
1565 if (j == 0) {
1566 hi1 = SCHRO_FRAME_DATA_GET_LINE (src, 1);
1567 } else {
1568 hi1 = SCHRO_FRAME_DATA_GET_LINE (src, j-1);
1570 hi2 = SCHRO_FRAME_DATA_GET_LINE (src, j+1);
1572 orc_add2_rshift_sub_s16_22_vert (lo, hi1, hi2, src->width);
1576 j = i + 1;
1577 if (j == CLAMP(j,0,src->height-1)) {
1578 if (j & 1) {
1579 int16_t *hi;
1580 int16_t *lo1, *lo2;
1582 hi = SCHRO_FRAME_DATA_GET_LINE (src, j);
1583 lo1 = SCHRO_FRAME_DATA_GET_LINE (src, j-1);
1584 if (j + 1 < src->height) {
1585 lo2 = SCHRO_FRAME_DATA_GET_LINE (src, j + 1);
1586 } else {
1587 lo2 = lo1;
1590 orc_add2_rshift_add_s16_11_op (SCHRO_FRAME_DATA_GET_LINE (src, j),
1591 hi, lo1, lo2, src->width);
1595 j = i;
1596 /* horizontal wavelet */
1597 if (j == CLAMP(j,0,src->height-1)) {
1598 int16_t *hi = tmp + 4;
1599 int16_t *lo = tmp + src->width/2 + 12;
1601 orc_memcpy (hi,
1602 SCHRO_FRAME_DATA_GET_PIXEL_S16(src, 0, j),
1603 src->width / 2 * sizeof (int16_t));
1604 orc_memcpy (lo,
1605 SCHRO_FRAME_DATA_GET_PIXEL_S16(src, src->width/2, j),
1606 src->width / 2 * sizeof (int16_t));
1607 schro_synth_ext_53 (hi, lo, src->width / 2);
1608 orc_interleave2_rrshift1_s16 (
1609 SCHRO_FRAME_DATA_GET_PIXEL_S16 (dest, 0, j), hi, lo, src->width / 2);
1614 /* Reverse, 16-bit, Wavelet #2: */
1616 static void
1617 schro_synth_ext_135 (int16_t * hi, int16_t * lo, int n)
1619 extend_2_1 (lo, n);
1620 orc_mas4_horiz_sub_s16_1991_ip (hi, lo - 2, 1 << 4, 5, n);
1621 extend_1_2 (hi, n);
1622 orc_mas4_horiz_add_s16_1991_ip (lo, hi - 1, 1 << 3, 4, n);
1625 void
1626 schro_iiwt_13_5 (SchroFrameData *dest, SchroFrameData *src,
1627 int16_t * tmp)
1629 int i;
1630 int j;
1631 int16_t *srcline, *s1, *s2, *s3, *s4;
1632 int height = src->height;
1633 int width = src->width;
1635 #define ROW(x) SCHRO_FRAME_DATA_GET_LINE (src, (x))
1636 for(i=-8;i<dest->height;i++){
1637 j = i + 8;
1638 if (j == CLAMP(j,0,src->height-1)) {
1639 if (!(j & 1)) {
1640 if (j < 3 || j >= height - 3) {
1641 s1 = ROW (CLAMP (j - 3, 1, height - 1));
1642 s2 = ROW (CLAMP (j - 1, 1, height - 1));
1643 srcline = ROW (j);
1644 s3 = ROW (CLAMP (j + 1, 1, height - 1));
1645 s4 = ROW (CLAMP (j + 3, 1, height - 1));
1646 } else {
1647 s1 = ROW (j - 3);
1648 s2 = ROW (j - 1);
1649 srcline = ROW (j);
1650 s3 = ROW (j + 1);
1651 s4 = ROW (j + 3);
1653 orc_mas4_vert_sub_s16_1991 (srcline, s1, s2, s3, s4, 1 << 4, 5, width);
1657 j = i + 4;
1658 if (j == CLAMP(j,0,src->height-1)) {
1659 if (j & 1) {
1660 if (j < 3 || j >= height - 3) {
1661 s1 = ROW (CLAMP (j - 3, 0, height - 2));
1662 s2 = ROW (CLAMP (j - 1, 0, height - 2));
1663 srcline = ROW (j);
1664 s3 = ROW (CLAMP (j + 1, 0, height - 2));
1665 s4 = ROW (CLAMP (j + 3, 0, height - 2));
1666 } else {
1667 s1 = ROW (j - 3);
1668 s2 = ROW (j - 1);
1669 srcline = ROW (j);
1670 s3 = ROW (j + 1);
1671 s4 = ROW (j + 3);
1673 orc_mas4_vert_add_s16_1991 (srcline, s1, s2, s3, s4, 1 << 3, 4, width);
1676 #undef ROW
1678 j = i;
1679 if (j == CLAMP(j,0,src->height-1)) {
1680 int16_t *hi = tmp + 4;
1681 int16_t *lo = tmp + width/2 + 12;
1683 srcline = SCHRO_FRAME_DATA_GET_LINE(dest, j);
1685 orc_memcpy (hi, srcline, width / 2 * sizeof (int16_t));
1686 orc_memcpy (lo, srcline + width / 2, width / 2 * sizeof (int16_t));
1687 schro_synth_ext_135 (hi, lo, width / 2);
1688 orc_interleave2_rrshift1_s16 (
1689 SCHRO_FRAME_DATA_GET_LINE(dest, j), hi, lo, width / 2);
1695 /* Reverse, 16-bit, Wavelet #3,4: Haar 0 and Haar 1 */
1697 void
1698 schro_iiwt_haar0 (SchroFrameData *dest, SchroFrameData *src, int16_t * tmp)
1700 int i;
1701 int j;
1702 int width = src->width;
1704 for(i=-8;i<dest->height;i++){
1705 j = i + 1;
1706 if (j == CLAMP(j,0,src->height-1)) {
1707 if (!(j & 1)) {
1708 orc_haar_synth_s16 (
1709 SCHRO_FRAME_DATA_GET_LINE (src, j),
1710 SCHRO_FRAME_DATA_GET_LINE (src, j+1),
1711 width);
1715 j = i;
1716 if (j == CLAMP(j,0,src->height-1)) {
1717 int16_t *hi = tmp + 4;
1718 int16_t *lo = tmp + width/2 + 12;
1720 orc_memcpy (lo, SCHRO_FRAME_DATA_GET_LINE(dest,j),
1721 width / 2 * sizeof (int16_t));
1722 orc_memcpy (hi, SCHRO_FRAME_DATA_GET_PIXEL_S16(src, src->width/2, j),
1723 width / 2 * sizeof (int16_t));
1724 orc_haar_synth_int_s16 (
1725 SCHRO_FRAME_DATA_GET_PIXEL_S16(dest, 0, j), lo, hi,
1726 width / 2);
1731 void
1732 schro_iiwt_haar1 (SchroFrameData *dest, SchroFrameData *src,
1733 int16_t * tmp)
1735 int i;
1736 int j;
1737 int width = src->width;
1739 for(i=-8;i<dest->height;i++){
1740 j = i + 1;
1741 if (j == CLAMP(j,0,src->height-1)) {
1742 if (!(j & 1)) {
1743 orc_haar_synth_s16 (
1744 SCHRO_FRAME_DATA_GET_LINE (src, j),
1745 SCHRO_FRAME_DATA_GET_LINE (src, j+1),
1746 width);
1750 j = i;
1751 if (j == CLAMP(j,0,src->height-1)) {
1752 int16_t *hi = tmp + 4;
1753 int16_t *lo = tmp + width/2 + 12;
1755 orc_memcpy (lo, SCHRO_FRAME_DATA_GET_LINE(dest,j),
1756 width / 2 * sizeof (int16_t));
1757 orc_memcpy (hi, SCHRO_FRAME_DATA_GET_PIXEL_S16(src, src->width/2, j),
1758 width / 2 * sizeof (int16_t));
1759 orc_haar_synth_rrshift1_int_s16 (
1760 SCHRO_FRAME_DATA_GET_PIXEL_S16(dest, 0, j), lo, hi,
1761 width / 2);
1766 /* Reverse, 16-bit, Wavelet #5: Fidelity */
1768 static void
1769 schro_synth_ext_fidelity (int16_t * hi, int16_t * lo, int n)
1771 static const int16_t stage1_weights[] = { -2, 10, -25, 81, 81, -25, 10, -2 };
1772 static const int16_t stage2_weights[] =
1773 { 8, -21, 46, -161, -161, 46, -21, 8 };
1775 extend_3_4 (hi, n);
1776 mas8_add_s16 (lo, hi - 3, stage1_weights, 128, 8, n);
1777 extend_4_3 (lo, n);
1778 mas8_add_s16 (hi, lo - 4, stage2_weights, 127, 8, n);
1781 static void
1782 wavelet_iiwt_fidelity_horiz (SchroFrame * frame, void *_dest, int component,
1783 int i)
1785 int16_t *dest = _dest;
1786 int width = frame->components[component].width;
1787 int16_t *tmp = frame->virt_priv2;
1788 int16_t *src = schro_virt_frame_get_line (frame->virt_frame1, component, i);
1789 int16_t *hi = tmp + 4;
1790 int16_t *lo = tmp + width/2 + 12;
1792 orc_memcpy (hi, src, width / 2 * sizeof (int16_t));
1793 orc_memcpy (lo, src + width / 2, width / 2 * sizeof (int16_t));
1794 schro_synth_ext_fidelity (hi, lo, width / 2);
1795 orc_interleave2_s16 (dest, hi, lo, width / 2);
1798 static void
1799 mas8_vert_sub_s16_2 (int16_t * dest, const int16_t * src,
1800 int16_t ** s, const int *weights, int offset, int shift, int n)
1802 int i;
1803 int j;
1804 for (i = 0; i < n; i++) {
1805 int x = offset;
1806 for (j = 0; j < 8; j++) {
1807 x += s[j][i] * weights[j];
1809 dest[i] = src[i] - (x >> shift);
1813 static void
1814 wavelet_iiwt_fidelity_vert (SchroFrame * frame, void *_dest, int component,
1815 int i)
1817 int16_t *dest = _dest;
1818 int width = frame->components[component].width;
1819 int height = frame->components[component].height;
1820 int16_t *s[8];
1821 int j;
1823 if (i & 1) {
1824 static const int weights[] = { 2, -10, 25, -81, -81, 25, -10, 2 };
1825 #define ROW(x) \
1826 schro_virt_frame_get_line (frame->virt_frame1, component, (x))
1827 #define ROW2(x) \
1828 schro_virt_frame_get_line (frame, component, (x))
1829 for (j = 0; j < 8; j++) {
1830 s[j] = ROW (CLAMP (i - 7 + j * 2, 0, height - 2));
1832 mas8_vert_sub_s16_2 (dest, ROW (i), s, weights, 127, 8, width);
1833 } else {
1834 static const int weights[] = { -8, 21, -46, 161, 161, -46, 21, -8 };
1835 for (j = 0; j < 8; j++) {
1836 s[j] = ROW2 (CLAMP (i - 7 + j * 2, 1, height - 1));
1838 mas8_vert_sub_s16_2 (dest, ROW (i), s, weights, 128, 8, width);
1840 #undef ROW
1841 #undef ROW2
1844 void
1845 schro_iiwt_fidelity (SchroFrameData *dest, SchroFrameData *src,
1846 int16_t * tmp)
1848 SchroFrame *frame;
1849 SchroFrame *frame2;
1850 SchroFrame *vf1;
1851 SchroFrame *vf2;
1853 frame = schro_frame_new ();
1855 frame->format = SCHRO_FRAME_FORMAT_S16_444;
1856 frame->width = src->width;
1857 frame->height = src->height;
1859 frame->components[0].format = SCHRO_FRAME_FORMAT_S16_444;
1860 frame->components[0].width = src->width;
1861 frame->components[0].height = src->height;
1862 frame->components[0].stride = src->stride;
1863 frame->components[0].data = src->data;
1865 vf1 = schro_frame_new_virtual (NULL, frame->format, src->width, src->height);
1866 vf1->virt_frame1 = frame;
1867 vf1->render_line = wavelet_iiwt_fidelity_vert;
1869 vf2 = schro_frame_new_virtual (NULL, frame->format, src->width, src->height);
1870 vf2->virt_frame1 = vf1;
1871 vf2->virt_priv2 = tmp;
1872 vf2->render_line = wavelet_iiwt_fidelity_horiz;
1874 frame2 = schro_frame_new ();
1876 frame2->format = SCHRO_FRAME_FORMAT_S16_444;
1877 frame2->width = dest->width;
1878 frame2->height = dest->height;
1880 frame2->components[0].format = SCHRO_FRAME_FORMAT_S16_444;
1881 frame2->components[0].width = dest->width;
1882 frame2->components[0].height = dest->height;
1883 frame2->components[0].stride = dest->stride;
1884 frame2->components[0].data = dest->data;
1886 schro_virt_frame_render (vf2, frame2);
1888 schro_frame_unref (vf2);
1889 schro_frame_unref (frame2);
1892 /* Reverse, 16-bit, Wavelet #6: Daubechies 9,7 */
1894 static void
1895 schro_synth_ext_daub97 (int16_t * hi, int16_t * lo, int n)
1897 extend_1_1 (lo, n);
1898 orc_mas2_sub_s16_ip (hi, lo - 1, 1817, 2048, 12, n);
1899 extend_1_1 (hi, n);
1900 orc_mas2_sub_s16_ip (lo, hi, 3616, 2048, 12, n);
1901 extend_1_1 (lo, n);
1902 orc_mas2_add_s16_ip (hi, lo - 1, 217, 2048, 12, n);
1903 extend_1_1 (hi, n);
1904 orc_mas2_add_s16_ip (lo, hi, 6497, 2048, 12, n);
1907 static void
1908 wavelet_iiwt_daub97_horiz (SchroFrame * frame, void *_dest, int component,
1909 int i)
1911 int16_t *dest = _dest;
1912 int width = frame->components[component].width;
1913 int16_t *tmp = frame->virt_priv2;
1914 int16_t *src = schro_virt_frame_get_line (frame->virt_frame1, component, i);
1915 int16_t *hi = tmp + 4;
1916 int16_t *lo = tmp + width/2 + 12;
1918 orc_memcpy (hi, src, width / 2 * sizeof (int16_t));
1919 orc_memcpy (lo, src + width / 2, width / 2 * sizeof (int16_t));
1920 schro_synth_ext_daub97 (hi, lo, width / 2);
1921 orc_interleave2_rrshift1_s16 (dest, hi, lo, width / 2);
1924 static void
1925 wavelet_iiwt_daub97_vert1 (SchroFrame * frame, void *_dest, int component,
1926 int i)
1928 int16_t *dest = _dest;
1929 int width = frame->components[component].width;
1931 if (i & 1) {
1932 int16_t *hi;
1933 int16_t *lo1, *lo2;
1935 hi = schro_virt_frame_get_line (frame->virt_frame1, component, i);
1936 lo1 = schro_virt_frame_get_line (frame, component, i - 1);
1937 if (i + 1 < frame->height) {
1938 lo2 = schro_virt_frame_get_line (frame, component, i + 1);
1939 } else {
1940 lo2 = lo1;
1943 orc_mas2_add_s16_op (dest, hi, lo1, lo2, 6497, 2048, 12, width);
1944 } else {
1945 int16_t *lo;
1946 int16_t *hi1, *hi2;
1948 lo = schro_virt_frame_get_line (frame->virt_frame1, component, i);
1949 if (i == 0) {
1950 hi1 = schro_virt_frame_get_line (frame->virt_frame1, component, 1);
1951 } else {
1952 hi1 = schro_virt_frame_get_line (frame->virt_frame1, component, i - 1);
1954 hi2 = schro_virt_frame_get_line (frame->virt_frame1, component, i + 1);
1956 orc_mas2_add_s16_op (dest, lo, hi1, hi2, 217, 2048, 12, width);
1960 static void
1961 wavelet_iiwt_daub97_vert2 (SchroFrame * frame, void *_dest, int component,
1962 int i)
1964 int16_t *dest = _dest;
1965 int width = frame->components[component].width;
1967 if (i & 1) {
1968 int16_t *hi;
1969 int16_t *lo1, *lo2;
1971 hi = schro_virt_frame_get_line (frame->virt_frame1, component, i);
1972 lo1 = schro_virt_frame_get_line (frame, component, i - 1);
1973 if (i + 1 < frame->height) {
1974 lo2 = schro_virt_frame_get_line (frame, component, i + 1);
1975 } else {
1976 lo2 = lo1;
1979 orc_mas2_sub_s16_op (dest, hi, lo1, lo2, 3616, 2048, 12, width);
1980 } else {
1981 int16_t *lo;
1982 int16_t *hi1, *hi2;
1984 lo = schro_virt_frame_get_line (frame->virt_frame1, component, i);
1985 if (i == 0) {
1986 hi1 = schro_virt_frame_get_line (frame->virt_frame1, component, 1);
1987 } else {
1988 hi1 = schro_virt_frame_get_line (frame->virt_frame1, component, i - 1);
1990 hi2 = schro_virt_frame_get_line (frame->virt_frame1, component, i + 1);
1992 orc_mas2_sub_s16_op (dest, lo, hi1, hi2, 1817, 2048, 12, width);
1996 void
1997 schro_iiwt_daub_9_7 (SchroFrameData *dest, SchroFrameData *src,
1998 int16_t * tmp)
2000 SchroFrame *frame;
2001 SchroFrame *frame2;
2002 SchroFrame *vf1;
2003 SchroFrame *vf2;
2004 SchroFrame *vf3;
2006 frame = schro_frame_new ();
2008 frame->format = SCHRO_FRAME_FORMAT_S16_444;
2009 frame->width = src->width;
2010 frame->height = src->height;
2012 frame->components[0].format = SCHRO_FRAME_FORMAT_S16_444;
2013 frame->components[0].width = src->width;
2014 frame->components[0].height = src->height;
2015 frame->components[0].stride = src->stride;
2016 frame->components[0].data = src->data;
2018 vf1 = schro_frame_new_virtual (NULL, frame->format, src->width, src->height);
2019 vf1->virt_frame1 = frame;
2020 vf1->virt_priv2 = tmp;
2021 vf1->render_line = wavelet_iiwt_daub97_vert2;
2023 vf2 = schro_frame_new_virtual (NULL, frame->format, src->width, src->height);
2024 vf2->virt_frame1 = vf1;
2025 vf2->virt_priv2 = tmp;
2026 vf2->render_line = wavelet_iiwt_daub97_vert1;
2028 vf3 = schro_frame_new_virtual (NULL, frame->format, src->width, src->height);
2029 vf3->virt_frame1 = vf2;
2030 vf3->virt_priv2 = tmp;
2031 vf3->render_line = wavelet_iiwt_daub97_horiz;
2033 frame2 = schro_frame_new ();
2035 frame2->format = SCHRO_FRAME_FORMAT_S16_444;
2036 frame2->width = dest->width;
2037 frame2->height = dest->height;
2039 frame2->components[0].format = SCHRO_FRAME_FORMAT_S16_444;
2040 frame2->components[0].width = dest->width;
2041 frame2->components[0].height = dest->height;
2042 frame2->components[0].stride = dest->stride;
2043 frame2->components[0].data = dest->data;
2045 schro_virt_frame_render (vf3, frame2);
2047 schro_frame_unref (vf3);
2048 schro_frame_unref (frame2);
2051 /* 32 bit versions */
2053 /* Reverse, 32-bit, Wavelet #0: Deslauriers-Dubuc 9,7 */
2055 static void
2056 schro_synth_ext_desl93_s32 (int32_t * hi, int32_t * lo, int n)
2058 extend_2_2_s32 (lo, n);
2059 orc_add2_rshift_sub_s32_22 (hi, lo - 1, n);
2060 extend_2_2_s32 (hi, n);
2061 orc_mas4_horiz_add_s32_1991_ip (lo, hi - 1, 1 << 3, 4, n);
2064 void
2065 schro_iiwt_desl_9_3_s32 (SchroFrameData *dest, SchroFrameData *src, int32_t * tmp)
2067 int i;
2068 int j;
2070 for(i=-7;i<dest->height;i++){
2071 j = i + 7;
2072 if (j == CLAMP(j,0,src->height-1)) {
2073 if (!(j & 1)) {
2074 int32_t *lo;
2075 int32_t *hi1, *hi2;
2077 lo = SCHRO_FRAME_DATA_GET_LINE (src, j);
2078 if (j == 0) {
2079 hi1 = SCHRO_FRAME_DATA_GET_LINE (src, 1);
2080 } else {
2081 hi1 = SCHRO_FRAME_DATA_GET_LINE (src, j-1);
2083 hi2 = SCHRO_FRAME_DATA_GET_LINE (src, j+1);
2085 orc_add2_rshift_sub_s32_22_op (SCHRO_FRAME_DATA_GET_LINE (src, j),
2086 lo, hi1, hi2, src->width);
2090 j = i + 3;
2091 if (j == CLAMP(j,0,src->height-1)) {
2092 if (j & 1) {
2093 if (j < 3 || j >= src->height - 3) {
2094 orc_mas4_vert_add_s32_1991_op (
2095 SCHRO_FRAME_DATA_GET_LINE (src, j),
2096 SCHRO_FRAME_DATA_GET_LINE (src, j),
2097 SCHRO_FRAME_DATA_GET_LINE (src, CLAMP (j - 3, 0, src->height - 2)),
2098 SCHRO_FRAME_DATA_GET_LINE (src, CLAMP (j - 1, 0, src->height - 2)),
2099 SCHRO_FRAME_DATA_GET_LINE (src, CLAMP (j + 1, 0, src->height - 2)),
2100 SCHRO_FRAME_DATA_GET_LINE (src, CLAMP (j + 3, 0, src->height - 2)),
2101 1 << 3, 4, src->width);
2102 } else {
2103 orc_mas4_vert_add_s32_1991_op (
2104 SCHRO_FRAME_DATA_GET_LINE (src, j),
2105 SCHRO_FRAME_DATA_GET_LINE (src, j),
2106 SCHRO_FRAME_DATA_GET_LINE (src, j - 3),
2107 SCHRO_FRAME_DATA_GET_LINE (src, j - 1),
2108 SCHRO_FRAME_DATA_GET_LINE (src, j + 1),
2109 SCHRO_FRAME_DATA_GET_LINE (src, j + 3),
2110 1 << 3, 4, src->width);
2115 j = i;
2116 /* horizontal wavelet */
2117 if (j == CLAMP(j,0,src->height-1)) {
2118 int32_t *hi = tmp + 4;
2119 int32_t *lo = tmp + src->width/2 + 12;
2121 orc_memcpy (hi, SCHRO_FRAME_DATA_GET_PIXEL_S32(src, 0, j),
2122 src->width / 2 * sizeof (int32_t));
2123 orc_memcpy (lo, SCHRO_FRAME_DATA_GET_PIXEL_S32(src, src->width/2, j),
2124 src->width / 2 * sizeof (int32_t));
2125 schro_synth_ext_desl93_s32 (hi, lo, src->width / 2);
2126 orc_interleave2_rrshift1_s32 (
2127 SCHRO_FRAME_DATA_GET_PIXEL_S32 (dest, 0, j), hi, lo, src->width / 2);
2132 /* Reverse, 32-bit, Wavelet #1: LeGall 5,3 */
2134 static void
2135 schro_synth_ext_53_s32 (int32_t * hi, int32_t * lo, int n)
2137 extend_1_1_s32 (lo, n);
2138 orc_add2_rshift_sub_s32_22 (hi, lo - 1, n);
2139 extend_1_1_s32 (hi, n);
2140 orc_add2_rshift_add_s32_11 (lo, hi, n);
2143 void
2144 schro_iiwt_5_3_s32 (SchroFrameData *dest, SchroFrameData *src, int32_t * tmp)
2146 int i;
2147 int j;
2149 for(i=-2;i<dest->height;i++){
2150 j = i + 2;
2151 if (j == CLAMP(j,0,src->height-1)) {
2152 if (!(j & 1)) {
2153 int32_t *lo;
2154 int32_t *hi1, *hi2;
2156 lo = SCHRO_FRAME_DATA_GET_LINE (src, j);
2157 if (j == 0) {
2158 hi1 = SCHRO_FRAME_DATA_GET_LINE (src, 1);
2159 } else {
2160 hi1 = SCHRO_FRAME_DATA_GET_LINE (src, j-1);
2162 hi2 = SCHRO_FRAME_DATA_GET_LINE (src, j+1);
2164 orc_add2_rshift_sub_s32_22_op (SCHRO_FRAME_DATA_GET_LINE (src, j),
2165 lo, hi1, hi2, src->width);
2169 j = i + 1;
2170 if (j == CLAMP(j,0,src->height-1)) {
2171 if (j & 1) {
2172 int32_t *hi;
2173 int32_t *lo1, *lo2;
2175 hi = SCHRO_FRAME_DATA_GET_LINE (src, j);
2176 lo1 = SCHRO_FRAME_DATA_GET_LINE (src, j-1);
2177 if (j + 1 < src->height) {
2178 lo2 = SCHRO_FRAME_DATA_GET_LINE (src, j + 1);
2179 } else {
2180 lo2 = lo1;
2183 orc_add2_rshift_add_s32_11_op (SCHRO_FRAME_DATA_GET_LINE (src, j),
2184 hi, lo1, lo2, src->width);
2188 j = i;
2189 /* horizontal wavelet */
2190 if (j == CLAMP(j,0,src->height-1)) {
2191 int32_t *hi = tmp + 4;
2192 int32_t *lo = tmp + src->width/2 + 12;
2194 orc_memcpy (hi,
2195 SCHRO_FRAME_DATA_GET_PIXEL_S32(src, 0, j),
2196 src->width / 2 * sizeof (int32_t));
2197 orc_memcpy (lo,
2198 SCHRO_FRAME_DATA_GET_PIXEL_S32(src, src->width/2, j),
2199 src->width / 2 * sizeof (int32_t));
2200 schro_synth_ext_53_s32 (hi, lo, src->width / 2);
2201 orc_interleave2_rrshift1_s32 (
2202 SCHRO_FRAME_DATA_GET_PIXEL_S32 (dest, 0, j), hi, lo, src->width / 2);
2207 /* Reverse, 32-bit, Wavelet #2: */
2209 static void
2210 schro_synth_ext_135_s32 (int32_t * hi, int32_t * lo, int n)
2212 extend_2_1_s32 (lo, n);
2213 orc_mas4_horiz_sub_s32_1991_ip (hi, lo - 2, 1 << 4, 5, n);
2214 extend_1_2_s32 (hi, n);
2215 orc_mas4_horiz_add_s32_1991_ip (lo, hi - 1, 1 << 3, 4, n);
2218 void
2219 schro_iiwt_13_5_s32 (SchroFrameData *dest, SchroFrameData *src,
2220 int32_t * tmp)
2222 int i;
2223 int j;
2224 int32_t *srcline, *s1, *s2, *s3, *s4;
2225 int height = src->height;
2226 int width = src->width;
2228 #define ROW(x) SCHRO_FRAME_DATA_GET_LINE (src, (x))
2229 for(i=-8;i<dest->height;i++){
2230 j = i + 8;
2231 if (j == CLAMP(j,0,src->height-1)) {
2232 if (!(j & 1)) {
2233 if (j < 3 || j >= height - 3) {
2234 s1 = ROW (CLAMP (j - 3, 1, height - 1));
2235 s2 = ROW (CLAMP (j - 1, 1, height - 1));
2236 srcline = ROW (j);
2237 s3 = ROW (CLAMP (j + 1, 1, height - 1));
2238 s4 = ROW (CLAMP (j + 3, 1, height - 1));
2239 } else {
2240 s1 = ROW (j - 3);
2241 s2 = ROW (j - 1);
2242 srcline = ROW (j);
2243 s3 = ROW (j + 1);
2244 s4 = ROW (j + 3);
2246 orc_mas4_vert_sub_s32_1991_op (srcline,
2247 srcline, s1, s2, s3, s4, 1 << 4, 5, width);
2251 j = i + 4;
2252 if (j == CLAMP(j,0,src->height-1)) {
2253 if (j & 1) {
2254 if (j < 3 || j >= height - 3) {
2255 s1 = ROW (CLAMP (j - 3, 0, height - 2));
2256 s2 = ROW (CLAMP (j - 1, 0, height - 2));
2257 srcline = ROW (j);
2258 s3 = ROW (CLAMP (j + 1, 0, height - 2));
2259 s4 = ROW (CLAMP (j + 3, 0, height - 2));
2260 } else {
2261 s1 = ROW (j - 3);
2262 s2 = ROW (j - 1);
2263 srcline = ROW (j);
2264 s3 = ROW (j + 1);
2265 s4 = ROW (j + 3);
2267 orc_mas4_vert_add_s32_1991_op (srcline,
2268 srcline, s1, s2, s3, s4, 1 << 3, 4, width);
2271 #undef ROW
2273 j = i;
2274 if (j == CLAMP(j,0,src->height-1)) {
2275 int32_t *hi = tmp + 4;
2276 int32_t *lo = tmp + width/2 + 12;
2278 srcline = SCHRO_FRAME_DATA_GET_LINE(dest, j);
2280 orc_memcpy (hi, srcline, width / 2 * sizeof (int32_t));
2281 orc_memcpy (lo, srcline + width / 2, width / 2 * sizeof (int32_t));
2282 schro_synth_ext_135_s32 (hi, lo, width / 2);
2283 orc_interleave2_rrshift1_s32 (
2284 SCHRO_FRAME_DATA_GET_LINE(dest, j), hi, lo, width / 2);
2290 /* Reverse, 32-bit, Wavelet #3,4: Haar 0 and Haar 1 */
2292 void
2293 schro_iiwt_haar0_s32 (SchroFrameData *dest, SchroFrameData *src,
2294 int32_t * tmp)
2296 int i;
2297 int j;
2298 int width = src->width;
2300 for(i=-8;i<dest->height;i++){
2301 j = i + 1;
2302 if (j == CLAMP(j,0,src->height-1)) {
2303 if (!(j & 1)) {
2304 orc_haar_synth_s32 (
2305 SCHRO_FRAME_DATA_GET_LINE (src, j),
2306 SCHRO_FRAME_DATA_GET_LINE (src, j+1),
2307 width);
2311 j = i;
2312 if (j == CLAMP(j,0,src->height-1)) {
2313 int32_t *hi = tmp + 4;
2314 int32_t *lo = tmp + width/2 + 12;
2316 orc_memcpy (lo, SCHRO_FRAME_DATA_GET_LINE(dest,j),
2317 width / 2 * sizeof (int32_t));
2318 orc_memcpy (hi, SCHRO_FRAME_DATA_GET_PIXEL_S32(src, src->width/2, j),
2319 width / 2 * sizeof (int32_t));
2320 orc_haar_synth_int_s32 (
2321 SCHRO_FRAME_DATA_GET_PIXEL_S32(dest, 0, j), lo, hi,
2322 width / 2);
2327 void
2328 schro_iiwt_haar1_s32 (SchroFrameData *dest, SchroFrameData *src,
2329 int32_t * tmp)
2331 int i;
2332 int j;
2333 int width = src->width;
2335 for(i=-8;i<dest->height;i++){
2336 j = i + 1;
2337 if (j == CLAMP(j,0,src->height-1)) {
2338 if (!(j & 1)) {
2339 orc_haar_synth_s32 (
2340 SCHRO_FRAME_DATA_GET_LINE (src, j),
2341 SCHRO_FRAME_DATA_GET_LINE (src, j+1),
2342 width);
2346 j = i;
2347 if (j == CLAMP(j,0,src->height-1)) {
2348 int32_t *hi = tmp + 4;
2349 int32_t *lo = tmp + width/2 + 12;
2351 orc_memcpy (lo, SCHRO_FRAME_DATA_GET_LINE(dest,j),
2352 width / 2 * sizeof (int32_t));
2353 orc_memcpy (hi, SCHRO_FRAME_DATA_GET_PIXEL_S32(src, src->width/2, j),
2354 width / 2 * sizeof (int32_t));
2355 orc_haar_synth_rrshift1_int_s32 (
2356 SCHRO_FRAME_DATA_GET_PIXEL_S32(dest, 0, j), lo, hi,
2357 width / 2);
2362 /* Reverse, 32-bit, Wavelet #5: Fidelity */
2364 #if 0
2365 /* already defined as part of forward transform */
2366 static void
2367 mas8_add_s32 (int32_t * dest, const int32_t * src, const int32_t * weights,
2368 int offset, int shift, int n)
2370 int i;
2371 for (i = 0; i < n; i++) {
2372 int x = offset;
2373 x += src[i + 0] * weights[0];
2374 x += src[i + 1] * weights[1];
2375 x += src[i + 2] * weights[2];
2376 x += src[i + 3] * weights[3];
2377 x += src[i + 4] * weights[4];
2378 x += src[i + 5] * weights[5];
2379 x += src[i + 6] * weights[6];
2380 x += src[i + 7] * weights[7];
2381 dest[i] += x >> shift;
2384 #endif
2386 static void
2387 schro_synth_ext_fidelity_s32 (int32_t * hi, int32_t * lo, int n)
2389 static const int32_t stage1_weights[] = { -2, 10, -25, 81, 81, -25, 10, -2 };
2390 static const int32_t stage2_weights[] =
2391 { 8, -21, 46, -161, -161, 46, -21, 8 };
2393 extend_3_4_s32 (hi, n);
2394 mas8_add_s32 (lo, hi - 3, stage1_weights, 128, 8, n);
2395 extend_4_3_s32 (lo, n);
2396 mas8_add_s32 (hi, lo - 4, stage2_weights, 127, 8, n);
2399 static void
2400 wavelet_iiwt_fidelity_horiz_s32 (SchroFrame * frame, void *_dest, int component,
2401 int i)
2403 int32_t *dest = _dest;
2404 int width = frame->components[component].width;
2405 int32_t *tmp = frame->virt_priv2;
2406 int32_t *src = schro_virt_frame_get_line (frame->virt_frame1, component, i);
2407 int32_t *hi = tmp + 4;
2408 int32_t *lo = tmp + width/2 + 12;
2410 orc_memcpy (hi, src, width / 2 * sizeof (int32_t));
2411 orc_memcpy (lo, src + width / 2, width / 2 * sizeof (int32_t));
2412 schro_synth_ext_fidelity_s32 (hi, lo, width / 2);
2413 orc_interleave2_s32 (dest, hi, lo, width / 2);
2416 static void
2417 mas8_vert_sub_s32_2 (int32_t * dest, const int32_t * src,
2418 int32_t ** s, const int *weights, int offset, int shift, int n)
2420 int i;
2421 int j;
2422 for (i = 0; i < n; i++) {
2423 int x = offset;
2424 for (j = 0; j < 8; j++) {
2425 x += s[j][i] * weights[j];
2427 dest[i] = src[i] - (x >> shift);
2431 static void
2432 wavelet_iiwt_fidelity_vert_s32 (SchroFrame * frame, void *_dest, int component,
2433 int i)
2435 int32_t *dest = _dest;
2436 int width = frame->components[component].width;
2437 int height = frame->components[component].height;
2438 int32_t *s[8];
2439 int j;
2441 if (i & 1) {
2442 static const int weights[] = { 2, -10, 25, -81, -81, 25, -10, 2 };
2443 #define ROW(x) \
2444 schro_virt_frame_get_line (frame->virt_frame1, component, (x))
2445 #define ROW2(x) \
2446 schro_virt_frame_get_line (frame, component, (x))
2447 for (j = 0; j < 8; j++) {
2448 s[j] = ROW (CLAMP (i - 7 + j * 2, 0, height - 2));
2450 mas8_vert_sub_s32_2 (dest, ROW (i), s, weights, 127, 8, width);
2451 } else {
2452 static const int weights[] = { -8, 21, -46, 161, 161, -46, 21, -8 };
2453 for (j = 0; j < 8; j++) {
2454 s[j] = ROW2 (CLAMP (i - 7 + j * 2, 1, height - 1));
2456 mas8_vert_sub_s32_2 (dest, ROW (i), s, weights, 128, 8, width);
2458 #undef ROW
2459 #undef ROW2
2462 void
2463 schro_iiwt_fidelity_s32 (SchroFrameData *dest, SchroFrameData *src,
2464 int32_t * tmp)
2466 SchroFrame *frame;
2467 SchroFrame *frame2;
2468 SchroFrame *vf1;
2469 SchroFrame *vf2;
2471 frame = schro_frame_new ();
2473 frame->format = SCHRO_FRAME_FORMAT_S32_444;
2474 frame->width = src->width;
2475 frame->height = src->height;
2477 frame->components[0].format = SCHRO_FRAME_FORMAT_S32_444;
2478 frame->components[0].width = src->width;
2479 frame->components[0].height = src->height;
2480 frame->components[0].stride = src->stride;
2481 frame->components[0].data = src->data;
2483 vf1 = schro_frame_new_virtual (NULL, frame->format, src->width, src->height);
2484 vf1->virt_frame1 = frame;
2485 vf1->render_line = wavelet_iiwt_fidelity_vert_s32;
2487 vf2 = schro_frame_new_virtual (NULL, frame->format, src->width, src->height);
2488 vf2->virt_frame1 = vf1;
2489 vf2->virt_priv2 = tmp;
2490 vf2->render_line = wavelet_iiwt_fidelity_horiz_s32;
2492 frame2 = schro_frame_new ();
2494 frame2->format = SCHRO_FRAME_FORMAT_S32_444;
2495 frame2->width = dest->width;
2496 frame2->height = dest->height;
2498 frame2->components[0].format = SCHRO_FRAME_FORMAT_S32_444;
2499 frame2->components[0].width = dest->width;
2500 frame2->components[0].height = dest->height;
2501 frame2->components[0].stride = dest->stride;
2502 frame2->components[0].data = dest->data;
2504 schro_virt_frame_render (vf2, frame2);
2506 schro_frame_unref (vf2);
2507 schro_frame_unref (frame2);
2510 /* Reverse, 32-bit, Wavelet #6: Daubechies 9,7 */
2512 static void
2513 schro_synth_ext_daub97_s32 (int32_t * hi, int32_t * lo, int n)
2515 extend_1_1_s32 (lo, n);
2516 orc_mas2_sub_s32_ip (hi, lo - 1, 1817, 2048, 12, n);
2517 extend_1_1_s32 (hi, n);
2518 orc_mas2_sub_s32_ip (lo, hi, 3616, 2048, 12, n);
2519 extend_1_1_s32 (lo, n);
2520 orc_mas2_add_s32_ip (hi, lo - 1, 217, 2048, 12, n);
2521 extend_1_1_s32 (hi, n);
2522 orc_mas2_add_s32_ip (lo, hi, 6497, 2048, 12, n);
2525 static void
2526 wavelet_iiwt_daub97_horiz_s32 (SchroFrame * frame, void *_dest, int component,
2527 int i)
2529 int32_t *dest = _dest;
2530 int width = frame->components[component].width;
2531 int32_t *tmp = frame->virt_priv2;
2532 int32_t *src = schro_virt_frame_get_line (frame->virt_frame1, component, i);
2533 int32_t *hi = tmp + 4;
2534 int32_t *lo = tmp + width/2 + 12;
2536 orc_memcpy (hi, src, width / 2 * sizeof (int32_t));
2537 orc_memcpy (lo, src + width / 2, width / 2 * sizeof (int32_t));
2538 schro_synth_ext_daub97_s32 (hi, lo, width / 2);
2539 orc_interleave2_rrshift1_s32 (dest, hi, lo, width / 2);
2542 static void
2543 wavelet_iiwt_daub97_vert1_s32 (SchroFrame * frame, void *_dest, int component,
2544 int i)
2546 int32_t *dest = _dest;
2547 int width = frame->components[component].width;
2549 if (i & 1) {
2550 int32_t *hi;
2551 int32_t *lo1, *lo2;
2553 hi = schro_virt_frame_get_line (frame->virt_frame1, component, i);
2554 lo1 = schro_virt_frame_get_line (frame, component, i - 1);
2555 if (i + 1 < frame->height) {
2556 lo2 = schro_virt_frame_get_line (frame, component, i + 1);
2557 } else {
2558 lo2 = lo1;
2561 orc_mas2_add_s32_op (dest, hi, lo1, lo2, 6497, 2048, 12, width);
2562 } else {
2563 int32_t *lo;
2564 int32_t *hi1, *hi2;
2566 lo = schro_virt_frame_get_line (frame->virt_frame1, component, i);
2567 if (i == 0) {
2568 hi1 = schro_virt_frame_get_line (frame->virt_frame1, component, 1);
2569 } else {
2570 hi1 = schro_virt_frame_get_line (frame->virt_frame1, component, i - 1);
2572 hi2 = schro_virt_frame_get_line (frame->virt_frame1, component, i + 1);
2574 orc_mas2_add_s32_op (dest, lo, hi1, hi2, 217, 2048, 12, width);
2578 static void
2579 wavelet_iiwt_daub97_vert2_s32 (SchroFrame * frame, void *_dest, int component,
2580 int i)
2582 int32_t *dest = _dest;
2583 int width = frame->components[component].width;
2585 if (i & 1) {
2586 int32_t *hi;
2587 int32_t *lo1, *lo2;
2589 hi = schro_virt_frame_get_line (frame->virt_frame1, component, i);
2590 lo1 = schro_virt_frame_get_line (frame, component, i - 1);
2591 if (i + 1 < frame->height) {
2592 lo2 = schro_virt_frame_get_line (frame, component, i + 1);
2593 } else {
2594 lo2 = lo1;
2597 orc_mas2_sub_s32_op (dest, hi, lo1, lo2, 3616, 2048, 12, width);
2598 } else {
2599 int32_t *lo;
2600 int32_t *hi1, *hi2;
2602 lo = schro_virt_frame_get_line (frame->virt_frame1, component, i);
2603 if (i == 0) {
2604 hi1 = schro_virt_frame_get_line (frame->virt_frame1, component, 1);
2605 } else {
2606 hi1 = schro_virt_frame_get_line (frame->virt_frame1, component, i - 1);
2608 hi2 = schro_virt_frame_get_line (frame->virt_frame1, component, i + 1);
2610 orc_mas2_sub_s32_op (dest, lo, hi1, hi2, 1817, 2048, 12, width);
2614 void
2615 schro_iiwt_daub_9_7_s32 (SchroFrameData *dest, SchroFrameData *src,
2616 int32_t * tmp)
2618 SchroFrame *frame;
2619 SchroFrame *frame2;
2620 SchroFrame *vf1;
2621 SchroFrame *vf2;
2622 SchroFrame *vf3;
2624 frame = schro_frame_new ();
2626 frame->format = SCHRO_FRAME_FORMAT_S32_444;
2627 frame->width = src->width;
2628 frame->height = src->height;
2630 frame->components[0].format = SCHRO_FRAME_FORMAT_S32_444;
2631 frame->components[0].width = src->width;
2632 frame->components[0].height = src->height;
2633 frame->components[0].stride = src->stride;
2634 frame->components[0].data = src->data;
2636 vf1 = schro_frame_new_virtual (NULL, frame->format, src->width, src->height);
2637 vf1->virt_frame1 = frame;
2638 vf1->virt_priv2 = tmp;
2639 vf1->render_line = wavelet_iiwt_daub97_vert2_s32;
2641 vf2 = schro_frame_new_virtual (NULL, frame->format, src->width, src->height);
2642 vf2->virt_frame1 = vf1;
2643 vf2->virt_priv2 = tmp;
2644 vf2->render_line = wavelet_iiwt_daub97_vert1_s32;
2646 vf3 = schro_frame_new_virtual (NULL, frame->format, src->width, src->height);
2647 vf3->virt_frame1 = vf2;
2648 vf3->virt_priv2 = tmp;
2649 vf3->render_line = wavelet_iiwt_daub97_horiz_s32;
2651 frame2 = schro_frame_new ();
2653 frame2->format = SCHRO_FRAME_FORMAT_S32_444;
2654 frame2->width = dest->width;
2655 frame2->height = dest->height;
2657 frame2->components[0].format = SCHRO_FRAME_FORMAT_S32_444;
2658 frame2->components[0].width = dest->width;
2659 frame2->components[0].height = dest->height;
2660 frame2->components[0].stride = dest->stride;
2661 frame2->components[0].data = dest->data;
2663 schro_virt_frame_render (vf3, frame2);
2665 schro_frame_unref (vf3);
2666 schro_frame_unref (frame2);