* Quantization bug fixed when using 9x7 DWT (comment keyword : quantizbug1)

* Multiplication bug fixed when dividing by 8192 (comment keyword : multbug1)
This commit is contained in:
Antonin Descampe 2004-07-13 09:17:17 +00:00
parent f50f66c0c9
commit bc563fc5ba
5 changed files with 48 additions and 10 deletions

View File

@ -67,7 +67,7 @@ static int *b = NULL;
static int lastSizeOfB = 0;
/* <summary> */
/* Claning memory. */
/* Cleaning memory. */
/* </summary> */
void dwt_clean()

View File

@ -25,6 +25,7 @@
*/
#include "fix.h"
#include <math.h> //Add Antonin : multbug1
#ifdef WIN32
#define int64 __int64
@ -35,7 +36,19 @@
/*
* Multiply two fixed-precision rational numbers.
*/
//int fix_mul(int a, int b)
//{
// return (int) ((int64) a * (int64) b >> 13);
//}
//Mod Antonin : multbug1
int fix_mul(int a, int b)
{
return (int) ((int64) a * (int64) b >> 13);
double tmp= (double) ((int64) a * (int64) b);
int64 v = (int64) ((fabs(tmp/8192.0)>=floor(fabs(tmp/8192.0))+0.5)?fabs(tmp/8192.0)+1.0:fabs(tmp/8192.0));
v = (tmp<0)?-v:v;
return (int) v;
}
//doM

View File

@ -92,7 +92,7 @@ static int t1_lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
static int t1_lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
static int t1_lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
static int t1_data[T1_MAXCBLKH][T1_MAXCBLKH];
static int t1_data[T1_MAXCBLKH][T1_MAXCBLKW];
static int t1_flags[T1_MAXCBLKH + 2][T1_MAXCBLKH + 2];
int t1_getctxno_zc(int f, int orient)
@ -187,6 +187,7 @@ void t1_enc_sigpass_step(int *fp, int *dp, int orient, int bpno, int one,
}
}
void t1_dec_sigpass_step(int *fp, int *dp, int orient, int oneplushalf,
char type, int vsc)
{
@ -247,7 +248,9 @@ void t1_dec_sigpass(int w, int h, int bpno, int orient, char type,
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC)
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_dec_sigpass_step(&t1_flags[1 + j][1 + i],
&t1_data[j][i], orient, oneplushalf,
&t1_data[j][i],
orient,
oneplushalf,
type, vsc);
}
}
@ -275,6 +278,7 @@ void t1_enc_refpass_step(int *fp, int *dp, int bpno, int one, int *nmsedec,
}
}
void t1_dec_refpass_step(int *fp, int *dp, int poshalf, int neghalf,
char type, int vsc)
{
@ -326,7 +330,10 @@ void t1_dec_refpass(int w, int h, int bpno, char type, int cblksty)
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC)
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_dec_refpass_step(&t1_flags[1 + j][1 + i],
&t1_data[j][i], poshalf, neghalf, type, vsc);
&t1_data[j][i],
poshalf,
neghalf,
type, vsc);
}
}
}
@ -358,6 +365,7 @@ void t1_enc_clnpass_step(int *fp, int *dp, int orient, int bpno, int one,
*fp &= ~T1_VISIT;
}
void t1_dec_clnpass_step(int *fp, int *dp, int orient, int oneplushalf,
int partial, int vsc)
{
@ -495,7 +503,9 @@ void t1_dec_clnpass(int w, int h, int bpno, int orient, int cblksty)
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC)
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_dec_clnpass_step(&t1_flags[1 + j][1 + i],
&t1_data[j][i], orient, oneplushalf,
&t1_data[j][i],
orient,
oneplushalf,
agg && (j == k + runlen), vsc);
}
}
@ -692,6 +702,8 @@ void t1_decode_cblk(tcd_cblk_t * cblk, int orient, int roishift,
mqc_init_dec(seg->data, seg->len);
/* dda */
if (bpno==0) cblk->lastbp=1; // Add Antonin : quantizbug1
for (passno = 0; passno < seg->numpasses; passno++) {
switch (passtype) {
case 0:
@ -865,13 +877,18 @@ void t1_decode_cblks(tcd_tile_t * tile, j2k_tcp_t * tcp)
for (i = 0; i < cblk->x1 - cblk->x0; i++) {
if (t1_data[j][i] == 0) {
tilec->data[x + i +
(y + j) * (tilec->x1 - tilec->x0)] = 0;
(y + j) * (tilec->x1 - tilec->x0)] = 0;
} else {
// Add antonin : quantizbug1
t1_data[j][i]<<=1;
//if (cblk->lastbp)
t1_data[j][i]+=t1_data[j][i]>0?1:-1;
// ddA
tilec->data[x + i +
(y + j) * (tilec->x1 -
tilec->
x0)] =
fix_mul(t1_data[j][i] << 13, band->stepsize);
fix_mul(t1_data[j][i] << 12, band->stepsize); //Mod Antonin : quantizbug1 (before : << 13)
}
}
}

View File

@ -774,6 +774,8 @@ void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
cblk->y0 = int_max(cblkystart, prc->y0);
cblk->x1 = int_min(cblkxend, prc->x1);
cblk->y1 = int_min(cblkyend, prc->y1);
cblk->lastbp = 0; // Add Antonin : quantizbug1
}
}
}
@ -1523,10 +1525,15 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
for (i = res->x0; i < res->x1; i++) {
int v;
double tmp= (double) tilec->data[i - res->x0 + (j - res->y0) * tw];
if (tcd_tcp->tccps[compno].qmfbid == 1) {
v = tilec->data[i - res->x0 + (j - res->y0) * tw];
v = (int) tmp;
} else {
v = tilec->data[i - res->x0 + (j - res->y0) * tw] >> 13;
//v = (int) tmp >> 13;
//Mod antonin : multbug1
v = (int) ((fabs(tmp/8192.0)>=floor(fabs(tmp/8192.0))+0.5)?fabs(tmp/8192.0)+1.0:fabs(tmp/8192.0));
v = (tmp<0)?-v:v;
//doM
}
v += adjust;

View File

@ -57,6 +57,7 @@ typedef struct {
typedef struct {
int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
int numbps;
int lastbp; /* Add antonin : quantizbug1 */
int numlenbits;
int len; /* length */
int numpasses; /* number of pass already done for the code-blocks */