return l;
}
-void encode_stepsize(int stepsize, int numbps, int *expn, int *mant)
+void encode_stepsize(float stepsize, int numbps, int *expn, int *mant)
{
- int p, n;
- p = floorlog2(stepsize) - 13;
- n = 11 - floorlog2(stepsize);
- *mant = (n < 0 ? stepsize >> -n : stepsize << n) & 0x7ff;
+ int p, n, stepsizeTMP;
+ stepsizeTMP=(int) floor(stepsize * 8192.0);
+ p = floorlog2(stepsizeTMP) - 13;
+ n = 11 - floorlog2(stepsizeTMP);
+ *mant = (n < 0 ? stepsizeTMP >> -n : stepsizeTMP << n) & 0x7ff;
*expn = numbps - p;
}
int numbands, bandno;
numbands = 3 * tccp->numresolutions - 2;
for (bandno = 0; bandno < numbands; bandno++) {
- double stepsize;
+ float stepsize;
int resno, level, orient, gain;
resno = bandno == 0 ? 0 : (bandno - 1) / 3 + 1;
double norm = dwt_norms_97[orient][level];
stepsize = (1 << (gain + 1)) / norm;
}
- encode_stepsize((int) floor(stepsize * 8192.0), prec + gain,
+ encode_stepsize(stepsize, prec + gain,
&tccp->stepsizes[bandno].expn,
&tccp->stepsizes[bandno].mant);
}
}
} /* VSC and BYPASS by Antonin */
-double t1_getwmsedec(int nmsedec, int compno, int level, int orient, int bpno, int qmfbid, double stepsize, int numcomps) //mod fixed_quality
+double t1_getwmsedec(int nmsedec, int compno, int level, int orient, int bpno, int qmfbid, float stepsize, int numcomps) //mod fixed_quality
{
double w1, w2, wmsedec;
if (qmfbid == 1) {
return wmsedec;
}
-void t1_encode_cblk(tcd_cblk_t * cblk, int orient, int compno, int level, int qmfbid, double stepsize, int cblksty, int numcomps, tcd_tile_t * tile) //mod fixed_quality
+void t1_encode_cblk(tcd_cblk_t * cblk, int orient, int compno, int level, int qmfbid, float stepsize, int cblksty, int numcomps, tcd_tile_t * tile) //mod fixed_quality
{
int i, j;
int w, h;
else
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:
- t1_dec_sigpass(w, h, bpno, orient, type, cblksty);
+ t1_dec_sigpass(w, h, bpno+1, orient, type, cblksty);
break;
case 1:
- t1_dec_refpass(w, h, bpno, type, cblksty);
+ t1_dec_refpass(w, h, bpno+1, type, cblksty);
break;
case 2:
- t1_dec_clnpass(w, h, bpno, orient, cblksty);
+ t1_dec_clnpass(w, h, bpno+1, orient, cblksty);
break;
}
tilec->
x0)],
8192 * 8192 /
- band->stepsize) >> (13 - T1_NMSEDEC_FRACBITS);
+ ((int) floor(band->stepsize * 8192))) >> (13 - T1_NMSEDEC_FRACBITS);
}
}
}
if (tcp->tccps[compno].qmfbid == 1) {
for (j = 0; j < cblk->y1 - cblk->y0; j++) {
for (i = 0; i < cblk->x1 - cblk->x0; i++) {
- tilec->data[x + i +
- (y + j) * (tilec->x1 -
- tilec->x0)] = t1_data[j][i];
+ int tmp=t1_data[j][i];
+ if (tmp>>1==0) tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)] = 0;
+ else tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)] = tmp<0?((tmp>>1) | 0x80000000)+1:(tmp>>1);
}
}
} else { /* if (tcp->tccps[compno].qmfbid == 0) */
for (j = 0; j < cblk->y1 - cblk->y0; j++) {
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;
+ float tmp=t1_data[j][i] * band->stepsize * 4096.0;
+ int tmp2;
+ if (t1_data[j][i]>>1 == 0) {
+ tilec->data[x + i + (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] << 12, band->stepsize); //Mod Antonin : quantizbug1 (before : << 13)
+ tmp2=((int) (floor(fabs(tmp)))) + ((int) floor(fabs(tmp*2))%2);
+ tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)] = ((tmp<0)?-tmp2:tmp2);
}
}
}
tcd_band_t *band = &res->bands[bandno];
fprintf(stdout, " band {\n");
fprintf(stdout,
- " x0=%d, y0=%d, x1=%d, y1=%d, stepsize=%d, numbps=%d\n",
+ " x0=%d, y0=%d, x1=%d, y1=%d, stepsize=%f, numbps=%d\n",
band->x0, band->y0, band->x1, band->y1,
band->stepsize, band->numbps);
for (precno = 0; precno < res->pw * res->ph; precno++) {
tccp->qmfbid ==
0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno);
numbps = img->comps[compno].prec + gain;
- band->stepsize =
- (int) floor((1.0 + ss->mant / 2048.0) *
- pow(2.0, numbps - ss->expn) * 8192.0);
+ band->stepsize = (1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn);
band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */
band->precincts =
tccp->qmfbid ==
0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno);
numbps = img->comps[compno].prec + gain;
- band->stepsize =
- (int) floor((1.0 + ss->mant / 2048.0) *
- pow(2.0, numbps - ss->expn) * 8192.0);
+ band->stepsize = (1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn);
band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */
for (precno = 0; precno < res->pw * res->ph; precno++) {
ss = &tccp->stepsizes[resno ==
0 ? 0 : 3 * (resno - 1) + bandno + 1];
- gain =
+ gain =
tccp->qmfbid ==
0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno);
numbps = img->comps[compno].prec + gain;
- band->stepsize =
- (int) floor((1.0 + ss->mant / 2048.0) *
- pow(2.0, numbps - ss->expn) * 8192.0);
+ band->stepsize = (1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn);
band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */
band->precincts =
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
}
}
}
for (i = res->x0; i < res->x1; i++) {
int v;
-
- double tmp =
- (double) tilec->data[i - res->x0 + (j - res->y0) * tw];
+ float tmp = (tilec->data[i - res->x0 + (j - res->y0) * tw])/8192.0;
+ int tmp2;
+
if (tcd_tcp->tccps[compno].qmfbid == 1) {
- v = (int) tmp;
+ v = tilec->data[i - res->x0 + (j - res->y0) * tw];
} else {
-
- //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
- }
+ tmp2=((int) (floor(fabs(tmp)))) + ((int) floor(fabs(tmp*2))%2);
+ v = ((tmp<0)?-tmp2:tmp2);
+ }
+
v += adjust;
tcd_img->comps[compno].data[(i - offset_x) +
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 */
int bandno;
tcd_precinct_t *precincts; /* precinct information */
int numbps;
- int stepsize;
+ float stepsize;
} tcd_band_t;
typedef struct {