2003-11-27 11:10:17 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2001-2002, David Janssens
|
2004-02-13 10:47:40 +01:00
|
|
|
* Copyright (c) 2002-2004, Yannick Verschueren
|
|
|
|
* Copyright (c) 2002-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
2005-09-21 15:00:51 +02:00
|
|
|
* Copyright (c) 2005, Reiner Wahler
|
2003-11-27 11:10:17 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
/*
|
|
|
|
* NOTE:
|
|
|
|
* This is a modified version of the openjpeg dwt.c file.
|
|
|
|
* Average speed improvement compared to the original file (measured on
|
|
|
|
* my own machine, a P4 running at 3.0 GHz):
|
|
|
|
* 5x3 wavelets about 2 times faster
|
|
|
|
* 9x7 wavelets about 3 times faster
|
|
|
|
* for both, encoding and decoding.
|
|
|
|
*
|
|
|
|
* The better performance is caused by doing the 1-dimensional DWT
|
|
|
|
* within a temporary buffer where the data can be accessed sequential
|
|
|
|
* for both directions, horizontal and vertical. The 2d vertical DWT was
|
|
|
|
* the major bottleneck in the former version.
|
|
|
|
*
|
|
|
|
* I have also removed the "Add Patrick" part because it is not longer
|
|
|
|
* needed.
|
|
|
|
*
|
|
|
|
* 6/6/2005
|
|
|
|
* -Ive (aka Reiner Wahler)
|
|
|
|
* mail: ive@lilysoft.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-11-27 11:10:17 +01:00
|
|
|
#include "dwt.h"
|
|
|
|
#include "int.h"
|
|
|
|
#include "fix.h"
|
|
|
|
#include "tcd.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
#define S(i) a[(i)*2]
|
|
|
|
#define D(i) a[(1+(i)*2)]
|
2003-11-27 11:10:17 +01:00
|
|
|
#define S_(i) ((i)<0?S(0):((i)>=sn?S(sn-1):S(i)))
|
|
|
|
#define D_(i) ((i)<0?D(0):((i)>=dn?D(dn-1):D(i)))
|
|
|
|
/* new */
|
|
|
|
#define SS_(i) ((i)<0?S(0):((i)>=dn?S(dn-1):S(i)))
|
|
|
|
#define DD_(i) ((i)<0?D(0):((i)>=sn?D(sn-1):D(i)))
|
|
|
|
|
2004-02-13 10:47:40 +01:00
|
|
|
/* <summary> */
|
|
|
|
/* This table contains the norms of the 5-3 wavelets for different bands. */
|
|
|
|
/* </summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
double dwt_norms[4][10] = {
|
2004-04-29 15:27:24 +02:00
|
|
|
{1.000, 1.500, 2.750, 5.375, 10.68, 21.34, 42.67, 85.33, 170.7, 341.3},
|
|
|
|
{1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9},
|
|
|
|
{1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9},
|
|
|
|
{.7186, .9218, 1.586, 3.043, 6.019, 12.01, 24.00, 47.97, 95.93}
|
2003-11-27 11:10:17 +01:00
|
|
|
};
|
|
|
|
|
2004-02-13 10:47:40 +01:00
|
|
|
/* <summary> */
|
|
|
|
/* This table contains the norms of the 9-7 wavelets for different bands. */
|
|
|
|
/* </summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
double dwt_norms_real[4][10] = {
|
2004-04-29 15:27:24 +02:00
|
|
|
{1.000, 1.965, 4.177, 8.403, 16.90, 33.84, 67.69, 135.3, 270.6, 540.9},
|
|
|
|
{2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0},
|
|
|
|
{2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0},
|
|
|
|
{2.080, 3.865, 8.307, 17.18, 34.71, 69.59, 139.3, 278.6, 557.2}
|
2003-11-27 11:10:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
/* <summary> */
|
|
|
|
/* Forward lazy transform (horizontal). */
|
|
|
|
/* </summary> */
|
|
|
|
void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas) {
|
|
|
|
int i;
|
|
|
|
for (i=0; i<sn; i++) b[i]=a[2*i+cas];
|
|
|
|
for (i=0; i<dn; i++) b[sn+i]=a[(2*i+1-cas)];
|
2003-11-27 11:10:17 +01:00
|
|
|
}
|
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
/* <summary> */
|
|
|
|
/* Forward lazy transform (vertical). */
|
|
|
|
/* </summary> */
|
|
|
|
void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas) {
|
|
|
|
int i;
|
|
|
|
for (i=0; i<sn; i++) b[i*x]=a[2*i+cas];
|
|
|
|
for (i=0; i<dn; i++) b[(sn+i)*x]=a[(2*i+1-cas)];
|
2003-11-27 11:10:17 +01:00
|
|
|
}
|
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
/* <summary> */
|
|
|
|
/* Inverse lazy transform (horizontal). */
|
|
|
|
/* </summary> */
|
|
|
|
void dwt_interleave_h(int *a, int *b, int dn, int sn, int cas) {
|
|
|
|
int i;
|
2005-11-01 11:15:34 +01:00
|
|
|
/* for (i=0; i<sn; i++) b[2*i+cas]=a[i];*/
|
|
|
|
/* for (i=0; i<dn; i++) b[2*i+1-cas]=a[(sn+i)];*/
|
2005-09-21 15:00:51 +02:00
|
|
|
int* ai;
|
|
|
|
int* bi;
|
|
|
|
ai=a;
|
|
|
|
bi=b+cas;
|
|
|
|
for (i=0; i<sn; i++) {
|
|
|
|
*bi = *ai; bi+=2; ai++;
|
|
|
|
}
|
|
|
|
ai=a+sn;
|
|
|
|
bi=b+1-cas;
|
|
|
|
for (i=0; i<dn; i++) {
|
|
|
|
*bi = *ai; bi+=2; ai++;
|
|
|
|
}
|
|
|
|
}
|
2004-04-29 15:27:24 +02:00
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
/* <summary> */
|
|
|
|
/* Inverse lazy transform (vertical). */
|
|
|
|
/* </summary> */
|
|
|
|
void dwt_interleave_v(int *a, int *b, int dn, int sn, int x, int cas) {
|
|
|
|
int i;
|
2005-11-01 11:15:34 +01:00
|
|
|
/* for (i=0; i<sn; i++) b[2*i+cas]=a[i*x];*/
|
|
|
|
/* for (i=0; i<dn; i++) b[2*i+1-cas]=a[(sn+i)*x];*/
|
2005-09-21 15:00:51 +02:00
|
|
|
int* ai;
|
|
|
|
int* bi;
|
|
|
|
ai=a;
|
|
|
|
bi=b+cas;
|
|
|
|
for (i=0; i<sn; i++) {
|
|
|
|
*bi = *ai; bi+=2; ai+=x;
|
|
|
|
}
|
|
|
|
ai=a+(sn*x);
|
|
|
|
bi=b+1-cas;
|
|
|
|
for (i=0; i<dn; i++) {
|
|
|
|
*bi = *ai; bi+=2; ai+=x;
|
|
|
|
}
|
2003-11-27 11:10:17 +01:00
|
|
|
}
|
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
|
2004-02-13 10:47:40 +01:00
|
|
|
/* <summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
/* Forward 5-3 wavelet tranform in 1-D. */
|
2004-02-13 10:47:40 +01:00
|
|
|
/* </summary> */
|
2005-09-21 15:00:51 +02:00
|
|
|
void dwt_encode_1(int *a, int dn, int sn, int cas)
|
2003-11-27 11:10:17 +01:00
|
|
|
{
|
2005-09-21 15:00:51 +02:00
|
|
|
int i;
|
2004-04-29 15:27:24 +02:00
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
if (!cas) {
|
|
|
|
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
|
|
|
for (i = 0; i < dn; i++) D(i) -= (S_(i) + S_(i + 1)) >> 1;
|
|
|
|
for (i = 0; i < sn; i++) S(i) += (D_(i - 1) + D_(i) + 2) >> 2;
|
2004-04-29 15:10:05 +02:00
|
|
|
}
|
2004-04-29 15:27:24 +02:00
|
|
|
} else {
|
2005-09-21 15:00:51 +02:00
|
|
|
if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */
|
|
|
|
S(0) *= 2;
|
|
|
|
else {
|
|
|
|
for (i = 0; i < dn; i++) S(i) -= (DD_(i) + DD_(i - 1)) >> 1;
|
|
|
|
for (i = 0; i < sn; i++) D(i) += (SS_(i) + SS_(i + 1) + 2) >> 2;
|
2004-04-29 15:27:24 +02:00
|
|
|
}
|
2005-09-21 15:00:51 +02:00
|
|
|
|
2004-04-29 15:27:24 +02:00
|
|
|
}
|
2003-11-27 11:10:17 +01:00
|
|
|
}
|
|
|
|
|
2004-02-13 10:47:40 +01:00
|
|
|
/* <summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
/* Inverse 5-3 wavelet tranform in 1-D. */
|
2005-09-21 15:00:51 +02:00
|
|
|
/* </summary> */
|
|
|
|
void dwt_decode_1(int *a, int dn, int sn, int cas)
|
2003-11-27 11:10:17 +01:00
|
|
|
{
|
2005-09-21 15:00:51 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!cas) {
|
|
|
|
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
|
|
|
for (i = 0; i < sn; i++) S(i) -= (D_(i - 1) + D_(i) + 2) >> 2;
|
|
|
|
for (i = 0; i < dn; i++) D(i) += (S_(i) + S_(i + 1)) >> 1;
|
2004-04-29 15:27:24 +02:00
|
|
|
}
|
|
|
|
} else {
|
2005-09-21 15:00:51 +02:00
|
|
|
if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */
|
|
|
|
S(0) /= 2;
|
|
|
|
else {
|
|
|
|
for (i = 0; i < sn; i++) D(i) -= (SS_(i) + SS_(i + 1) + 2) >> 2;
|
|
|
|
for (i = 0; i < dn; i++) S(i) += (DD_(i) + DD_(i - 1)) >> 1;
|
2004-04-29 15:10:05 +02:00
|
|
|
}
|
2004-04-29 15:27:24 +02:00
|
|
|
}
|
2003-11-27 11:10:17 +01:00
|
|
|
}
|
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
|
2004-02-13 10:47:40 +01:00
|
|
|
/* <summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
/* Forward 5-3 wavelet tranform in 2-D. */
|
2004-02-13 10:47:40 +01:00
|
|
|
/* </summary> */
|
2005-09-21 15:00:51 +02:00
|
|
|
void dwt_encode(tcd_tilecomp_t * tilec)
|
2003-11-27 11:10:17 +01:00
|
|
|
{
|
2005-09-21 15:00:51 +02:00
|
|
|
int i, j, k;
|
|
|
|
int* a;
|
|
|
|
int* aj;
|
|
|
|
int* bj;
|
|
|
|
int w, l;
|
|
|
|
|
|
|
|
w = tilec->x1-tilec->x0;
|
|
|
|
l = tilec->numresolutions-1;
|
|
|
|
a = tilec->data;
|
2004-04-29 15:27:24 +02:00
|
|
|
|
|
|
|
for (i = 0; i < l; i++) {
|
2005-09-21 15:00:51 +02:00
|
|
|
int rw; /* width of the resolution level computed */
|
|
|
|
int rh; /* heigth of the resolution level computed */
|
|
|
|
int rw1; /* width of the resolution level once lower than computed one */
|
|
|
|
int rh1; /* height of the resolution level once lower than computed one */
|
|
|
|
int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
|
|
|
int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
|
|
|
int dn, sn;
|
|
|
|
|
2004-04-29 15:27:24 +02:00
|
|
|
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
|
|
|
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
2005-09-21 15:00:51 +02:00
|
|
|
rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
|
|
|
rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
2004-04-29 15:27:24 +02:00
|
|
|
|
|
|
|
cas_row = tilec->resolutions[l - i].x0 % 2;
|
|
|
|
cas_col = tilec->resolutions[l - i].y0 % 2;
|
|
|
|
|
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
sn = rh1;
|
|
|
|
dn = rh - rh1;
|
|
|
|
bj=(int*)malloc(rh*sizeof(int));
|
|
|
|
for (j=0; j<rw; j++) {
|
|
|
|
aj=a+j;
|
|
|
|
for (k=0; k<rh; k++) bj[k]=aj[k*w];
|
|
|
|
dwt_encode_1(bj, dn, sn, cas_col);
|
|
|
|
dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col);
|
|
|
|
}
|
|
|
|
free(bj);
|
|
|
|
|
|
|
|
sn = rw1;
|
|
|
|
dn = rw - rw1;
|
|
|
|
bj=(int*)malloc(rw*sizeof(int));
|
|
|
|
for (j=0; j<rh; j++) {
|
|
|
|
aj=a+j*w;
|
|
|
|
for (k=0; k<rw; k++) bj[k]=aj[k];
|
|
|
|
dwt_encode_1(bj, dn, sn, cas_row);
|
|
|
|
dwt_deinterleave_h(bj, aj, dn, sn, cas_row);
|
|
|
|
}
|
|
|
|
free(bj);
|
|
|
|
}
|
2003-11-27 11:10:17 +01:00
|
|
|
}
|
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
|
2004-02-13 10:47:40 +01:00
|
|
|
/* <summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
/* Inverse 5-3 wavelet tranform in 2-D. */
|
2004-02-13 10:47:40 +01:00
|
|
|
/* </summary> */
|
2005-09-21 15:00:51 +02:00
|
|
|
void dwt_decode(tcd_tilecomp_t * tilec, int stop)
|
2003-11-27 11:10:17 +01:00
|
|
|
{
|
2005-09-21 15:00:51 +02:00
|
|
|
int i, j, k;
|
|
|
|
int* a;
|
|
|
|
int* aj;
|
|
|
|
int* bj;
|
|
|
|
int w, l;
|
|
|
|
|
|
|
|
w = tilec->x1-tilec->x0;
|
|
|
|
l = tilec->numresolutions-1;
|
|
|
|
a = tilec->data;
|
2004-04-29 15:27:24 +02:00
|
|
|
|
|
|
|
for (i = l - 1; i >= stop; i--) {
|
2005-09-21 15:00:51 +02:00
|
|
|
int rw; /* width of the resolution level computed */
|
|
|
|
int rh; /* heigth of the resolution level computed */
|
|
|
|
int rw1; /* width of the resolution level once lower than computed one */
|
|
|
|
int rh1; /* height of the resolution level once lower than computed one */
|
|
|
|
int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
|
|
|
int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
|
|
|
int dn, sn;
|
2004-04-29 15:27:24 +02:00
|
|
|
|
|
|
|
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
|
|
|
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
2005-09-21 15:00:51 +02:00
|
|
|
rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
|
|
|
rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
2004-04-29 15:27:24 +02:00
|
|
|
|
|
|
|
cas_row = tilec->resolutions[l - i].x0 % 2;
|
|
|
|
cas_col = tilec->resolutions[l - i].y0 % 2;
|
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
sn = rw1;
|
|
|
|
dn = rw - rw1;
|
|
|
|
bj=(int*)malloc(rw*sizeof(int));
|
|
|
|
for (j = 0; j < rh; j++) {
|
|
|
|
aj = a+j*w;
|
|
|
|
dwt_interleave_h(aj, bj, dn, sn, cas_row);
|
|
|
|
dwt_decode_1(bj, dn, sn, cas_row);
|
|
|
|
for (k = 0; k < rw; k++) aj[k] = bj[k];
|
|
|
|
}
|
|
|
|
free(bj);
|
|
|
|
|
|
|
|
sn = rh1;
|
|
|
|
dn = rh - rh1;
|
|
|
|
bj=(int*)malloc(rh*sizeof(int));
|
|
|
|
for (j = 0; j < rw; j++) {
|
|
|
|
aj = a+j;
|
|
|
|
dwt_interleave_v(aj, bj, dn, sn, w, cas_col);
|
|
|
|
dwt_decode_1(bj, dn, sn, cas_col);
|
|
|
|
for (k = 0; k < rh; k++) aj[k * w] = bj[k];
|
|
|
|
}
|
|
|
|
free(bj);
|
|
|
|
|
2004-04-29 15:27:24 +02:00
|
|
|
}
|
2003-11-27 11:10:17 +01:00
|
|
|
}
|
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
|
2004-02-13 10:47:40 +01:00
|
|
|
/* <summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
/* Get gain of 5-3 wavelet transform. */
|
2004-02-13 10:47:40 +01:00
|
|
|
/* </summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
int dwt_getgain(int orient)
|
|
|
|
{
|
2004-04-29 15:27:24 +02:00
|
|
|
if (orient == 0)
|
|
|
|
return 0;
|
|
|
|
if (orient == 1 || orient == 2)
|
|
|
|
return 1;
|
|
|
|
return 2;
|
2003-11-27 11:10:17 +01:00
|
|
|
}
|
|
|
|
|
2004-02-13 10:47:40 +01:00
|
|
|
/* <summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
/* Get norm of 5-3 wavelet. */
|
2004-02-13 10:47:40 +01:00
|
|
|
/* </summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
double dwt_getnorm(int level, int orient)
|
|
|
|
{
|
2004-04-29 15:27:24 +02:00
|
|
|
return dwt_norms[orient][level];
|
2003-11-27 11:10:17 +01:00
|
|
|
}
|
|
|
|
|
2004-02-13 10:47:40 +01:00
|
|
|
/* <summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
/* Forward 9-7 wavelet transform in 1-D. */
|
2004-02-13 10:47:40 +01:00
|
|
|
/* </summary> */
|
2005-09-21 15:00:51 +02:00
|
|
|
void dwt_encode_1_real(int *a, int dn, int sn, int cas)
|
2003-11-27 11:10:17 +01:00
|
|
|
{
|
2005-09-21 15:00:51 +02:00
|
|
|
int i;
|
|
|
|
if (!cas) {
|
|
|
|
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < dn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
D(i) -= fix_mul(S_(i) + S_(i + 1), 12993);
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < sn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
S(i) -= fix_mul(D_(i - 1) + D_(i), 434);
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < dn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
D(i) += fix_mul(S_(i) + S_(i + 1), 7233);
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < sn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
S(i) += fix_mul(D_(i - 1) + D_(i), 3633);
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < dn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
D(i) = fix_mul(D(i), 5038); /*5038 */
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < sn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
S(i) = fix_mul(S(i), 6659); /*6660 */
|
2004-04-29 15:27:24 +02:00
|
|
|
}
|
|
|
|
} else {
|
2005-09-21 15:00:51 +02:00
|
|
|
if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < dn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
S(i) -= fix_mul(DD_(i) + DD_(i - 1), 12993);
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < sn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
D(i) -= fix_mul(SS_(i) + SS_(i + 1), 434);
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < dn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
S(i) += fix_mul(DD_(i) + DD_(i - 1), 7233);
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < sn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
D(i) += fix_mul(SS_(i) + SS_(i + 1), 3633);
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < dn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
S(i) = fix_mul(S(i), 5038); /*5038 */
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < sn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
D(i) = fix_mul(D(i), 6659); /*6660 */
|
2004-04-29 15:10:05 +02:00
|
|
|
}
|
2004-04-29 15:27:24 +02:00
|
|
|
}
|
2003-11-27 11:10:17 +01:00
|
|
|
}
|
|
|
|
|
2004-02-13 10:47:40 +01:00
|
|
|
/* <summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
/* Inverse 9-7 wavelet transform in 1-D. */
|
2004-02-13 10:47:40 +01:00
|
|
|
/* </summary> */
|
2005-09-21 15:00:51 +02:00
|
|
|
void dwt_decode_1_real(int *a, int dn, int sn, int cas)
|
2003-11-27 11:10:17 +01:00
|
|
|
{
|
2005-09-21 15:00:51 +02:00
|
|
|
int i;
|
|
|
|
if (!cas) {
|
|
|
|
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < sn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
S(i) = fix_mul(S(i), 10078); /* 10076 */
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < dn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
D(i) = fix_mul(D(i), 13318); /* 13320 */
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < sn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
S(i) -= fix_mul(D_(i - 1) + D_(i), 3633);
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < dn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
D(i) -= fix_mul(S_(i) + S_(i + 1), 7233);
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < sn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
S(i) += fix_mul(D_(i - 1) + D_(i), 434);
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < dn; i++)
|
2005-10-27 09:51:11 +02:00
|
|
|
D(i) += fix_mul(S_(i) + S_(i + 1), 12994); /* 12993 */
|
2004-04-29 15:10:05 +02:00
|
|
|
}
|
2004-04-29 15:27:24 +02:00
|
|
|
} else {
|
2005-09-21 15:00:51 +02:00
|
|
|
if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < sn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
D(i) = fix_mul(D(i), 10078); /* 10076 */
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < dn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
S(i) = fix_mul(S(i), 13318); /* 13320 */
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < sn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
D(i) -= fix_mul(SS_(i) + SS_(i + 1), 3633);
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < dn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
S(i) -= fix_mul(DD_(i) + DD_(i - 1), 7233);
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < sn; i++)
|
2005-09-21 15:00:51 +02:00
|
|
|
D(i) += fix_mul(SS_(i) + SS_(i + 1), 434);
|
2004-04-29 15:27:24 +02:00
|
|
|
for (i = 0; i < dn; i++)
|
2005-10-27 09:51:11 +02:00
|
|
|
S(i) += fix_mul(DD_(i) + DD_(i - 1), 12994); /* 12993 */
|
2004-04-29 15:27:24 +02:00
|
|
|
}
|
|
|
|
}
|
2003-11-27 11:10:17 +01:00
|
|
|
}
|
|
|
|
|
2004-02-13 10:47:40 +01:00
|
|
|
/* <summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
/* Forward 9-7 wavelet transform in 2-D. */
|
2004-02-13 10:47:40 +01:00
|
|
|
/* </summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
void dwt_encode_real(tcd_tilecomp_t * tilec)
|
2003-11-27 11:10:17 +01:00
|
|
|
{
|
2005-09-21 15:00:51 +02:00
|
|
|
int i, j, k;
|
|
|
|
int* a;
|
|
|
|
int* aj;
|
|
|
|
int* bj;
|
|
|
|
int w, l;
|
|
|
|
|
|
|
|
w = tilec->x1-tilec->x0;
|
|
|
|
l = tilec->numresolutions-1;
|
|
|
|
a = tilec->data;
|
2004-04-29 15:27:24 +02:00
|
|
|
|
|
|
|
for (i = 0; i < l; i++) {
|
2005-09-21 15:00:51 +02:00
|
|
|
int rw; /* width of the resolution level computed */
|
|
|
|
int rh; /* heigth of the resolution level computed */
|
|
|
|
int rw1; /* width of the resolution level once lower than computed one */
|
|
|
|
int rh1; /* height of the resolution level once lower than computed one */
|
|
|
|
int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
|
|
|
int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
|
|
|
int dn, sn;
|
|
|
|
|
2004-04-29 15:27:24 +02:00
|
|
|
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
|
|
|
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
2005-09-21 15:00:51 +02:00
|
|
|
rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
|
|
|
rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
2004-04-29 15:27:24 +02:00
|
|
|
|
|
|
|
cas_row = tilec->resolutions[l - i].x0 % 2;
|
|
|
|
cas_col = tilec->resolutions[l - i].y0 % 2;
|
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
sn = rh1;
|
|
|
|
dn = rh - rh1;
|
|
|
|
bj=(int*)malloc(rh*sizeof(int));
|
|
|
|
for (j = 0; j < rw; j++) {
|
|
|
|
aj = a + j;
|
|
|
|
for (k = 0; k < rh; k++) bj[k] = aj[k*w];
|
|
|
|
dwt_encode_1_real(bj, dn, sn, cas_col);
|
|
|
|
dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col);
|
|
|
|
}
|
|
|
|
free(bj);
|
|
|
|
|
|
|
|
sn = rw1;
|
|
|
|
dn = rw - rw1;
|
|
|
|
bj=(int*)malloc(rw*sizeof(int));
|
|
|
|
for (j = 0; j < rh; j++) {
|
|
|
|
aj = a + j * w;
|
|
|
|
for (k = 0; k < rw; k++) bj[k] = aj[k];
|
|
|
|
dwt_encode_1_real(bj, dn, sn, cas_row);
|
|
|
|
dwt_deinterleave_h(bj, aj, dn, sn, cas_row);
|
|
|
|
}
|
|
|
|
free(bj);
|
2004-04-29 15:27:24 +02:00
|
|
|
}
|
2003-11-27 11:10:17 +01:00
|
|
|
}
|
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
|
2004-02-13 10:47:40 +01:00
|
|
|
/* <summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
/* Inverse 9-7 wavelet transform in 2-D. */
|
2004-02-13 10:47:40 +01:00
|
|
|
/* </summary> */
|
2005-09-21 15:00:51 +02:00
|
|
|
void dwt_decode_real(tcd_tilecomp_t * tilec, int stop)
|
2003-11-27 11:10:17 +01:00
|
|
|
{
|
2004-04-29 15:27:24 +02:00
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
int i, j, k;
|
|
|
|
int* a;
|
|
|
|
int* aj;
|
|
|
|
int* bj;
|
|
|
|
int w, l;
|
|
|
|
|
|
|
|
w = tilec->x1-tilec->x0;
|
|
|
|
l = tilec->numresolutions-1;
|
|
|
|
a = tilec->data;
|
|
|
|
|
|
|
|
for (i = l-1; i >= stop; i--) {
|
|
|
|
int rw; /* width of the resolution level computed */
|
|
|
|
int rh; /* heigth of the resolution level computed */
|
|
|
|
int rw1; /* width of the resolution level once lower than computed one */
|
|
|
|
int rh1; /* height of the resolution level once lower than computed one */
|
|
|
|
int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
|
|
|
int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
|
|
|
int dn, sn;
|
2004-04-29 15:27:24 +02:00
|
|
|
|
|
|
|
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
|
|
|
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
2005-09-21 15:00:51 +02:00
|
|
|
rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
|
|
|
rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
|
|
|
|
|
|
|
cas_col = tilec->resolutions[l - i].x0 % 2; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
|
|
|
cas_row = tilec->resolutions[l - i].y0 % 2; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
|
|
|
|
|
|
|
sn = rw1;
|
|
|
|
dn = rw-rw1;
|
|
|
|
bj = (int*)malloc(rw * sizeof(int));
|
|
|
|
for (j = 0; j < rh; j++) {
|
|
|
|
aj = a+j*w;
|
|
|
|
dwt_interleave_h(aj, bj, dn, sn, cas_col);
|
|
|
|
dwt_decode_1_real(bj, dn, sn, cas_col);
|
|
|
|
for (k = 0; k < rw; k++) aj[k] = bj[k];
|
|
|
|
}
|
|
|
|
free(bj);
|
|
|
|
|
|
|
|
sn = rh1;
|
|
|
|
dn = rh-rh1;
|
|
|
|
bj = (int*)malloc(rh * sizeof(int));
|
|
|
|
for (j=0; j<rw; j++) {
|
|
|
|
aj = a+j;
|
|
|
|
dwt_interleave_v(aj, bj, dn, sn, w, cas_row);
|
|
|
|
dwt_decode_1_real(bj, dn, sn, cas_row);
|
|
|
|
for (k = 0; k < rh; k++) aj[k * w] = bj[k];
|
|
|
|
}
|
|
|
|
free(bj);
|
2004-04-29 15:27:24 +02:00
|
|
|
}
|
2003-11-27 11:10:17 +01:00
|
|
|
}
|
|
|
|
|
2005-09-21 15:00:51 +02:00
|
|
|
|
2004-02-13 10:47:40 +01:00
|
|
|
/* <summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
/* Get gain of 9-7 wavelet transform. */
|
2004-02-13 10:47:40 +01:00
|
|
|
/* </summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
int dwt_getgain_real(int orient)
|
|
|
|
{
|
2005-11-01 11:15:34 +01:00
|
|
|
(void)orient;
|
2004-04-29 15:27:24 +02:00
|
|
|
return 0;
|
2003-11-27 11:10:17 +01:00
|
|
|
}
|
|
|
|
|
2004-02-13 10:47:40 +01:00
|
|
|
/* <summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
/* Get norm of 9-7 wavelet. */
|
2004-02-13 10:47:40 +01:00
|
|
|
/* </summary> */
|
2003-11-27 11:10:17 +01:00
|
|
|
double dwt_getnorm_real(int level, int orient)
|
|
|
|
{
|
2004-04-29 15:27:24 +02:00
|
|
|
return dwt_norms_real[orient][level];
|
2003-11-27 11:10:17 +01:00
|
|
|
}
|