2 * The copyright in this software is being made available under the 2-clauses
3 * BSD License, included below. This software may be subject to other third
4 * party and contributor rights, including patent rights, and no such rights
5 * are granted under this license.
7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
8 * Copyright (c) 2002-2014, Professor Benoit Macq
9 * Copyright (c) 2001-2003, David Janssens
10 * Copyright (c) 2002-2003, Yannick Verschueren
11 * Copyright (c) 2003-2007, Francois-Olivier Devaux
12 * Copyright (c) 2003-2014, Antonin Descampe
13 * Copyright (c) 2005, Herve Drolon, FreeImage Team
14 * Copyright (c) 2007, Jonathan Ballard <dzonatas@dzonux.net>
15 * Copyright (c) 2007, Callum Lerwick <seg@haxxed.com>
16 * All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
41 #include <xmmintrin.h>
44 #include "opj_includes.h"
46 /** @defgroup DWT DWT - Implementation of a discrete wavelet transform */
49 #define WS(i) v->mem[(i)*2]
50 #define WD(i) v->mem[(1+(i)*2)]
52 /** @name Local data structures */
55 typedef struct dwt_local {
66 typedef struct v4dwt_local {
73 static const float dwt_alpha = 1.586134342f; /* 12994 */
74 static const float dwt_beta = 0.052980118f; /* 434 */
75 static const float dwt_gamma = -0.882911075f; /* -7233 */
76 static const float dwt_delta = -0.443506852f; /* -3633 */
78 static const float K = 1.230174105f; /* 10078 */
79 /* FIXME: What is this constant? */
80 static const float c13318 = 1.625732422f;
85 Virtual function type for wavelet transform in 1-D
87 typedef void (*DWT1DFN)(dwt_t* v);
89 /** @name Local static functions */
93 Forward lazy transform (horizontal)
95 static void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas);
97 Forward lazy transform (vertical)
99 static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas);
101 Inverse lazy transform (horizontal)
103 static void dwt_interleave_h(dwt_t* h, int *a);
105 Inverse lazy transform (vertical)
107 static void dwt_interleave_v(dwt_t* v, int *a, int x);
109 Forward 5-3 wavelet transform in 1-D
111 static void dwt_encode_1(int *a, int dn, int sn, int cas);
113 Inverse 5-3 wavelet transform in 1-D
115 static void dwt_decode_1(dwt_t *v);
117 Forward 9-7 wavelet transform in 1-D
119 static void dwt_encode_1_real(int *a, int dn, int sn, int cas);
121 Explicit calculation of the Quantization Stepsizes
123 static void dwt_encode_stepsize(int stepsize, int numbps,
124 opj_stepsize_t *bandno_stepsize);
126 Inverse wavelet transform in 2-D.
128 static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int i, DWT1DFN fn);
134 #define S(i) a[(i)*2]
135 #define D(i) a[(1+(i)*2)]
136 #define S_(i) ((i)<0?S(0):((i)>=sn?S(sn-1):S(i)))
137 #define D_(i) ((i)<0?D(0):((i)>=dn?D(dn-1):D(i)))
139 #define SS_(i) ((i)<0?S(0):((i)>=dn?S(dn-1):S(i)))
140 #define DD_(i) ((i)<0?D(0):((i)>=sn?D(sn-1):D(i)))
143 /* This table contains the norms of the 5-3 wavelets for different bands. */
145 static const double dwt_norms[4][10] = {
146 {1.000, 1.500, 2.750, 5.375, 10.68, 21.34, 42.67, 85.33, 170.7, 341.3},
147 {1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9},
148 {1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9},
149 {.7186, .9218, 1.586, 3.043, 6.019, 12.01, 24.00, 47.97, 95.93}
153 /* This table contains the norms of the 9-7 wavelets for different bands. */
155 static const double dwt_norms_real[4][10] = {
156 {1.000, 1.965, 4.177, 8.403, 16.90, 33.84, 67.69, 135.3, 270.6, 540.9},
157 {2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0},
158 {2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0},
159 {2.080, 3.865, 8.307, 17.18, 34.71, 69.59, 139.3, 278.6, 557.2}
163 ==========================================================
165 ==========================================================
169 /* Forward lazy transform (horizontal). */
171 static void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas)
174 for (i = 0; i < sn; i++) {
175 b[i] = a[2 * i + cas];
177 for (i = 0; i < dn; i++) {
178 b[sn + i] = a[(2 * i + 1 - cas)];
183 /* Forward lazy transform (vertical). */
185 static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas)
188 for (i = 0; i < sn; i++) {
189 b[i * x] = a[2 * i + cas];
191 for (i = 0; i < dn; i++) {
192 b[(sn + i)*x] = a[(2 * i + 1 - cas)];
197 /* Inverse lazy transform (horizontal). */
199 static void dwt_interleave_h(dwt_t* h, int *a)
202 int *bi = h->mem + h->cas;
209 bi = h->mem + 1 - h->cas;
218 /* Inverse lazy transform (vertical). */
220 static void dwt_interleave_v(dwt_t* v, int *a, int x)
223 int *bi = v->mem + v->cas;
230 ai = a + (v->sn * x);
231 bi = v->mem + 1 - v->cas;
242 /* Forward 5-3 wavelet transform in 1-D. */
244 static void dwt_encode_1(int *a, int dn, int sn, int cas)
249 if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
250 for (i = 0; i < dn; i++) {
251 D(i) -= (S_(i) + S_(i + 1)) >> 1;
253 for (i = 0; i < sn; i++) {
254 S(i) += (D_(i - 1) + D_(i) + 2) >> 2;
258 if (!sn && dn == 1) { /* NEW : CASE ONE ELEMENT */
261 for (i = 0; i < dn; i++) {
262 S(i) -= (DD_(i) + DD_(i - 1)) >> 1;
264 for (i = 0; i < sn; i++) {
265 D(i) += (SS_(i) + SS_(i + 1) + 2) >> 2;
272 /* Inverse 5-3 wavelet transform in 1-D. */
274 static void dwt_decode_1_(int *a, int dn, int sn, int cas)
279 if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
280 for (i = 0; i < sn; i++) {
281 S(i) -= (D_(i - 1) + D_(i) + 2) >> 2;
283 for (i = 0; i < dn; i++) {
284 D(i) += (S_(i) + S_(i + 1)) >> 1;
288 if (!sn && dn == 1) { /* NEW : CASE ONE ELEMENT */
291 for (i = 0; i < sn; i++) {
292 D(i) -= (SS_(i) + SS_(i + 1) + 2) >> 2;
294 for (i = 0; i < dn; i++) {
295 S(i) += (DD_(i) + DD_(i - 1)) >> 1;
302 /* Inverse 5-3 wavelet transform in 1-D. */
304 static void dwt_decode_1(dwt_t *v)
306 dwt_decode_1_(v->mem, v->dn, v->sn, v->cas);
310 /* Forward 9-7 wavelet transform in 1-D. */
312 static void dwt_encode_1_real(int *a, int dn, int sn, int cas)
316 if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
317 for (i = 0; i < dn; i++) {
318 D(i) -= fix_mul(S_(i) + S_(i + 1), 12993);
320 for (i = 0; i < sn; i++) {
321 S(i) -= fix_mul(D_(i - 1) + D_(i), 434);
323 for (i = 0; i < dn; i++) {
324 D(i) += fix_mul(S_(i) + S_(i + 1), 7233);
326 for (i = 0; i < sn; i++) {
327 S(i) += fix_mul(D_(i - 1) + D_(i), 3633);
329 for (i = 0; i < dn; i++) {
330 D(i) = fix_mul(D(i), 5038); /*5038 */
332 for (i = 0; i < sn; i++) {
333 S(i) = fix_mul(S(i), 6659); /*6660 */
337 if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */
338 for (i = 0; i < dn; i++) {
339 S(i) -= fix_mul(DD_(i) + DD_(i - 1), 12993);
341 for (i = 0; i < sn; i++) {
342 D(i) -= fix_mul(SS_(i) + SS_(i + 1), 434);
344 for (i = 0; i < dn; i++) {
345 S(i) += fix_mul(DD_(i) + DD_(i - 1), 7233);
347 for (i = 0; i < sn; i++) {
348 D(i) += fix_mul(SS_(i) + SS_(i + 1), 3633);
350 for (i = 0; i < dn; i++) {
351 S(i) = fix_mul(S(i), 5038); /*5038 */
353 for (i = 0; i < sn; i++) {
354 D(i) = fix_mul(D(i), 6659); /*6660 */
360 static void dwt_encode_stepsize(int stepsize, int numbps,
361 opj_stepsize_t *bandno_stepsize)
364 p = int_floorlog2(stepsize) - 13;
365 n = 11 - int_floorlog2(stepsize);
366 bandno_stepsize->mant = (n < 0 ? stepsize >> -n : stepsize << n) & 0x7ff;
367 bandno_stepsize->expn = numbps - p;
371 ==========================================================
373 ==========================================================
377 /* Forward 5-3 wavelet transform in 2-D. */
379 void dwt_encode(opj_tcd_tilecomp_t * tilec)
387 w = tilec->x1 - tilec->x0;
388 l = tilec->numresolutions - 1;
391 for (i = 0; i < l; i++) {
392 int rw; /* width of the resolution level computed */
393 int rh; /* height of the resolution level computed */
394 int rw1; /* width of the resolution level once lower than computed one */
395 int rh1; /* height of the resolution level once lower than computed one */
396 int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
397 int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
400 rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
401 rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
402 rw1 = tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
403 rh1 = tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
405 cas_row = tilec->resolutions[l - i].x0 % 2;
406 cas_col = tilec->resolutions[l - i].y0 % 2;
410 bj = (int*)opj_malloc(rh * sizeof(int));
411 for (j = 0; j < rw; j++) {
413 for (k = 0; k < rh; k++) {
416 dwt_encode_1(bj, dn, sn, cas_col);
417 dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col);
423 bj = (int*)opj_malloc(rw * sizeof(int));
424 for (j = 0; j < rh; j++) {
426 for (k = 0; k < rw; k++) {
429 dwt_encode_1(bj, dn, sn, cas_row);
430 dwt_deinterleave_h(bj, aj, dn, sn, cas_row);
438 /* Inverse 5-3 wavelet transform in 2-D. */
440 void dwt_decode(opj_tcd_tilecomp_t* tilec, int numres)
442 dwt_decode_tile(tilec, numres, &dwt_decode_1);
447 /* Get gain of 5-3 wavelet transform. */
449 int dwt_getgain(int orient)
454 if (orient == 1 || orient == 2) {
461 /* Get norm of 5-3 wavelet. */
463 double dwt_getnorm(int level, int orient)
465 return dwt_norms[orient][level];
469 /* Forward 9-7 wavelet transform in 2-D. */
472 void dwt_encode_real(opj_tcd_tilecomp_t * tilec)
480 w = tilec->x1 - tilec->x0;
481 l = tilec->numresolutions - 1;
484 for (i = 0; i < l; i++) {
485 int rw; /* width of the resolution level computed */
486 int rh; /* height of the resolution level computed */
487 int rw1; /* width of the resolution level once lower than computed one */
488 int rh1; /* height of the resolution level once lower than computed one */
489 int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
490 int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
493 rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
494 rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
495 rw1 = tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
496 rh1 = tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
498 cas_row = tilec->resolutions[l - i].x0 % 2;
499 cas_col = tilec->resolutions[l - i].y0 % 2;
503 bj = (int*)opj_malloc(rh * sizeof(int));
504 for (j = 0; j < rw; j++) {
506 for (k = 0; k < rh; k++) {
509 dwt_encode_1_real(bj, dn, sn, cas_col);
510 dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col);
516 bj = (int*)opj_malloc(rw * sizeof(int));
517 for (j = 0; j < rh; j++) {
519 for (k = 0; k < rw; k++) {
522 dwt_encode_1_real(bj, dn, sn, cas_row);
523 dwt_deinterleave_h(bj, aj, dn, sn, cas_row);
531 /* Get gain of 9-7 wavelet transform. */
533 int dwt_getgain_real(int orient)
540 /* Get norm of 9-7 wavelet. */
542 double dwt_getnorm_real(int level, int orient)
544 return dwt_norms_real[orient][level];
547 void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec)
549 int numbands, bandno;
550 numbands = 3 * tccp->numresolutions - 2;
551 for (bandno = 0; bandno < numbands; bandno++) {
553 int resno, level, orient, gain;
555 resno = (bandno == 0) ? 0 : ((bandno - 1) / 3 + 1);
556 orient = (bandno == 0) ? 0 : ((bandno - 1) % 3 + 1);
557 level = tccp->numresolutions - 1 - resno;
558 gain = (tccp->qmfbid == 0) ? 0 : ((orient == 0) ? 0 : (((orient == 1) ||
559 (orient == 2)) ? 1 : 2));
560 if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) {
563 double norm = dwt_norms_real[orient][level];
564 stepsize = (1 << (gain)) / norm;
566 dwt_encode_stepsize((int) floor(stepsize * 8192.0), prec + gain,
567 &tccp->stepsizes[bandno]);
573 /* Determine maximum computed resolution level for inverse wavelet transform */
575 static int dwt_decode_max_resolution(opj_tcd_resolution_t* restrict r, int i)
581 if (mr < (w = r->x1 - r->x0)) {
584 if (mr < (w = r->y1 - r->y0)) {
593 /* Inverse wavelet transform in 2-D. */
595 static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int numres,
601 opj_tcd_resolution_t* tr = tilec->resolutions;
603 int rw = tr->x1 - tr->x0; /* width of the resolution level computed */
604 int rh = tr->y1 - tr->y0; /* height of the resolution level computed */
606 int w = tilec->x1 - tilec->x0;
608 h.mem = (int*)opj_aligned_malloc(dwt_decode_max_resolution(tr,
609 numres) * sizeof(int));
613 int * restrict tiledp = tilec->data;
620 rw = tr->x1 - tr->x0;
621 rh = tr->y1 - tr->y0;
626 for (j = 0; j < rh; ++j) {
627 dwt_interleave_h(&h, &tiledp[j * w]);
629 memcpy(&tiledp[j * w], h.mem, rw * sizeof(int));
635 for (j = 0; j < rw; ++j) {
637 dwt_interleave_v(&v, &tiledp[j], w);
639 for (k = 0; k < rh; ++k) {
640 tiledp[k * w + j] = v.mem[k];
644 opj_aligned_free(h.mem);
647 static void v4dwt_interleave_h(v4dwt_t* restrict w, float* restrict a, int x,
650 float* restrict bi = (float*)(w->wavelet + w->cas);
653 for (k = 0; k < 2; ++k) {
654 if (count + 3 * x < size && ((size_t) a & 0x0f) == 0 &&
655 ((size_t) bi & 0x0f) == 0 && (x & 0x0f) == 0) {
657 for (i = 0; i < count; ++i) {
661 bi[i * 8 + 1] = a[j];
663 bi[i * 8 + 2] = a[j];
665 bi[i * 8 + 3] = a[j];
669 for (i = 0; i < count; ++i) {
676 bi[i * 8 + 1] = a[j];
681 bi[i * 8 + 2] = a[j];
686 bi[i * 8 + 3] = a[j];
689 bi = (float*)(w->wavelet + 1 - w->cas);
696 static void v4dwt_interleave_v(v4dwt_t* restrict v, float* restrict a, int x)
698 v4* restrict bi = v->wavelet + v->cas;
700 for (i = 0; i < v->sn; ++i) {
701 memcpy(&bi[i * 2], &a[i * x], 4 * sizeof(float));
704 bi = v->wavelet + 1 - v->cas;
705 for (i = 0; i < v->dn; ++i) {
706 memcpy(&bi[i * 2], &a[i * x], 4 * sizeof(float));
712 static void v4dwt_decode_step1_sse(v4* w, int count, const __m128 c)
714 __m128* restrict vw = (__m128*) w;
716 /* 4x unrolled loop */
717 for (i = 0; i < count >> 2; ++i) {
718 *vw = _mm_mul_ps(*vw, c);
720 *vw = _mm_mul_ps(*vw, c);
722 *vw = _mm_mul_ps(*vw, c);
724 *vw = _mm_mul_ps(*vw, c);
728 for (i = 0; i < count; ++i) {
729 *vw = _mm_mul_ps(*vw, c);
734 static void v4dwt_decode_step2_sse(v4* l, v4* w, int k, int m, __m128 c)
736 __m128* restrict vl = (__m128*) l;
737 __m128* restrict vw = (__m128*) w;
739 __m128 tmp1, tmp2, tmp3;
741 for (i = 0; i < m; ++i) {
744 vw[-1] = _mm_add_ps(tmp2, _mm_mul_ps(_mm_add_ps(tmp1, tmp3), c));
752 c = _mm_add_ps(c, c);
753 c = _mm_mul_ps(c, vl[0]);
756 vw[-1] = _mm_add_ps(tmp, c);
763 static void v4dwt_decode_step1(v4* w, int count, const float c)
765 float* restrict fw = (float*) w;
767 for (i = 0; i < count; ++i) {
768 float tmp1 = fw[i * 8 ];
769 float tmp2 = fw[i * 8 + 1];
770 float tmp3 = fw[i * 8 + 2];
771 float tmp4 = fw[i * 8 + 3];
772 fw[i * 8 ] = tmp1 * c;
773 fw[i * 8 + 1] = tmp2 * c;
774 fw[i * 8 + 2] = tmp3 * c;
775 fw[i * 8 + 3] = tmp4 * c;
779 static void v4dwt_decode_step2(v4* l, v4* w, int k, int m, float c)
781 float* restrict fl = (float*) l;
782 float* restrict fw = (float*) w;
784 for (i = 0; i < m; ++i) {
785 float tmp1_1 = fl[0];
786 float tmp1_2 = fl[1];
787 float tmp1_3 = fl[2];
788 float tmp1_4 = fl[3];
789 float tmp2_1 = fw[-4];
790 float tmp2_2 = fw[-3];
791 float tmp2_3 = fw[-2];
792 float tmp2_4 = fw[-1];
793 float tmp3_1 = fw[0];
794 float tmp3_2 = fw[1];
795 float tmp3_3 = fw[2];
796 float tmp3_4 = fw[3];
797 fw[-4] = tmp2_1 + ((tmp1_1 + tmp3_1) * c);
798 fw[-3] = tmp2_2 + ((tmp1_2 + tmp3_2) * c);
799 fw[-2] = tmp2_3 + ((tmp1_3 + tmp3_3) * c);
800 fw[-1] = tmp2_4 + ((tmp1_4 + tmp3_4) * c);
831 /* Inverse 9-7 wavelet transform in 1-D. */
833 static void v4dwt_decode(v4dwt_t* restrict dwt)
837 if (!((dwt->dn > 0) || (dwt->sn > 1))) {
843 if (!((dwt->sn > 0) || (dwt->dn > 1))) {
850 v4dwt_decode_step1_sse(dwt->wavelet + a, dwt->sn, _mm_set1_ps(K));
851 v4dwt_decode_step1_sse(dwt->wavelet + b, dwt->dn, _mm_set1_ps(c13318));
852 v4dwt_decode_step2_sse(dwt->wavelet + b, dwt->wavelet + a + 1, dwt->sn,
853 int_min(dwt->sn, dwt->dn - a), _mm_set1_ps(dwt_delta));
854 v4dwt_decode_step2_sse(dwt->wavelet + a, dwt->wavelet + b + 1, dwt->dn,
855 int_min(dwt->dn, dwt->sn - b), _mm_set1_ps(dwt_gamma));
856 v4dwt_decode_step2_sse(dwt->wavelet + b, dwt->wavelet + a + 1, dwt->sn,
857 int_min(dwt->sn, dwt->dn - a), _mm_set1_ps(dwt_beta));
858 v4dwt_decode_step2_sse(dwt->wavelet + a, dwt->wavelet + b + 1, dwt->dn,
859 int_min(dwt->dn, dwt->sn - b), _mm_set1_ps(dwt_alpha));
861 v4dwt_decode_step1(dwt->wavelet + a, dwt->sn, K);
862 v4dwt_decode_step1(dwt->wavelet + b, dwt->dn, c13318);
863 v4dwt_decode_step2(dwt->wavelet + b, dwt->wavelet + a + 1, dwt->sn,
864 int_min(dwt->sn, dwt->dn - a), dwt_delta);
865 v4dwt_decode_step2(dwt->wavelet + a, dwt->wavelet + b + 1, dwt->dn,
866 int_min(dwt->dn, dwt->sn - b), dwt_gamma);
867 v4dwt_decode_step2(dwt->wavelet + b, dwt->wavelet + a + 1, dwt->sn,
868 int_min(dwt->sn, dwt->dn - a), dwt_beta);
869 v4dwt_decode_step2(dwt->wavelet + a, dwt->wavelet + b + 1, dwt->dn,
870 int_min(dwt->dn, dwt->sn - b), dwt_alpha);
875 /* Inverse 9-7 wavelet transform in 2-D. */
877 void dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, int numres)
882 opj_tcd_resolution_t* res = tilec->resolutions;
884 int rw = res->x1 - res->x0; /* width of the resolution level computed */
885 int rh = res->y1 - res->y0; /* height of the resolution level computed */
887 int w = tilec->x1 - tilec->x0;
889 h.wavelet = (v4*) opj_aligned_malloc((dwt_decode_max_resolution(res,
890 numres) + 5) * sizeof(v4));
891 v.wavelet = h.wavelet;
894 float * restrict aj = (float*) tilec->data;
895 int bufsize = (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0);
903 rw = res->x1 - res->x0; /* width of the resolution level computed */
904 rh = res->y1 - res->y0; /* height of the resolution level computed */
909 for (j = rh; j > 3; j -= 4) {
911 v4dwt_interleave_h(&h, aj, w, bufsize);
913 for (k = rw; --k >= 0;) {
914 aj[k ] = h.wavelet[k].f[0];
915 aj[k + w ] = h.wavelet[k].f[1];
916 aj[k + w * 2] = h.wavelet[k].f[2];
917 aj[k + w * 3] = h.wavelet[k].f[3];
925 v4dwt_interleave_h(&h, aj, w, bufsize);
927 for (k = rw; --k >= 0;) {
930 aj[k + w * 2] = h.wavelet[k].f[2];
932 aj[k + w ] = h.wavelet[k].f[1];
934 aj[k ] = h.wavelet[k].f[0];
942 aj = (float*) tilec->data;
943 for (j = rw; j > 3; j -= 4) {
945 v4dwt_interleave_v(&v, aj, w);
947 for (k = 0; k < rh; ++k) {
948 memcpy(&aj[k * w], &v.wavelet[k], 4 * sizeof(float));
955 v4dwt_interleave_v(&v, aj, w);
957 for (k = 0; k < rh; ++k) {
958 memcpy(&aj[k * w], &v.wavelet[k], j * sizeof(float));
963 opj_aligned_free(h.wavelet);