Several bugs fixed when dealing with pgx-files with more than 8 bpp and the fixed_quality feature.

This commit is contained in:
Antonin Descampe 2005-07-18 15:21:56 +00:00
parent 32ba9920db
commit de75303c38
3 changed files with 21 additions and 29 deletions

View File

@ -665,7 +665,7 @@ int main(int argc, char **argv)
/* if no rate entered, lossless by default */ /* if no rate entered, lossless by default */
if (tcp_init->numlayers == 0) { if (tcp_init->numlayers == 0) {
tcp_init->rates[tcp_init->numlayers] = 0; //MOD antonin : losslessbug tcp_init->rates[0] = 0; //MOD antonin : losslessbug
tcp_init->numlayers++; tcp_init->numlayers++;
cp.disto_alloc = 1; cp.disto_alloc = 1;
} }

View File

@ -366,25 +366,24 @@ int main(int argc, char **argv)
img.comps[0].factor); img.comps[0].factor);
fprintf(fdest, "P6\n# %d %d %d %d %d\n%d %d\n%d\n", fprintf(fdest, "P6\n%d %d\n%d\n", wrr, hrr, max);
cp.tcps[cp.tileno[0]].tccps[0].numresolutions, w, h,
img.comps[0].x0, img.comps[0].y0, wrr, hrr, max);
adjust = img.comps[0].prec > 8 ? img.comps[0].prec - 8 : 0; adjust = img.comps[0].prec > 8 ? img.comps[0].prec - 8 : 0;
for (i = 0; i < wrr * hrr; i++) { for (i = 0; i < wrr * hrr; i++) {
char r, g, b; int r, g, b;
unsigned char rc,gc,bc;
r = img.comps[0].data[i / wrr * wr + i % wrr]; r = img.comps[0].data[i / wrr * wr + i % wrr];
r += (img.comps[0].sgnd ? 1 << (img.comps[0].prec - 1) : 0); r += (img.comps[0].sgnd ? 1 << (img.comps[0].prec - 1) : 0);
r = r >> adjust; rc = (unsigned char) ((r >> adjust)+((r >> (adjust-1))%2));
g = img.comps[1].data[i / wrr * wr + i % wrr]; g = img.comps[1].data[i / wrr * wr + i % wrr];
g += (img.comps[1].sgnd ? 1 << (img.comps[1].prec - 1) : 0); g += (img.comps[1].sgnd ? 1 << (img.comps[1].prec - 1) : 0);
g = g >> adjust; gc = (unsigned char) ((g >> adjust)+((g >> (adjust-1))%2));
b = img.comps[2].data[i / wrr * wr + i % wrr]; b = img.comps[2].data[i / wrr * wr + i % wrr];
b += (img.comps[2].sgnd ? 1 << (img.comps[2].prec - 1) : 0); b += (img.comps[2].sgnd ? 1 << (img.comps[2].prec - 1) : 0);
b = b >> adjust; bc = (unsigned char) ((b >> adjust)+((b >> (adjust-1))%2));
fprintf(fdest, "%c%c%c", r, g, b); fprintf(fdest, "%c%c%c", rc, gc, bc);
} }
free(img.comps[0].data); free(img.comps[0].data);
free(img.comps[1].data); free(img.comps[1].data);
@ -438,19 +437,17 @@ int main(int argc, char **argv)
img.comps[compno].dy), img.comps[compno].dy),
img.comps[compno].factor); img.comps[compno].factor);
fprintf(fdest, "P5\n# %d %d %d %d %d\n%d %d\n%d\n", fprintf(fdest, "P5\n%d %d\n%d\n", wrr, hrr, max);
cp.tcps[cp.tileno[0]].tccps[compno].
numresolutions, w, h, img.comps[compno].x0,
img.comps[compno].y0, wrr, hrr, max);
adjust = adjust =
img.comps[compno].prec > 8 ? img.comps[compno].prec - 8 : 0; img.comps[compno].prec > 8 ? img.comps[compno].prec - 8 : 0;
for (i = 0; i < wrr * hrr; i++) { for (i = 0; i < wrr * hrr; i++) {
char l; int l;
unsigned char lc;
l = img.comps[compno].data[i / wrr * wr + i % wrr]; l = img.comps[compno].data[i / wrr * wr + i % wrr];
l += (img.comps[compno]. l += (img.comps[compno].
sgnd ? 1 << (img.comps[compno].prec - 1) : 0); sgnd ? 1 << (img.comps[compno].prec - 1) : 0);
l = l >> adjust; lc = (unsigned char) ((l >> adjust)+((l >> (adjust-1))%2));
fprintf(fdest, "%c", l); fprintf(fdest, "%c", lc);
} }
fclose(fdest); fclose(fdest);
free(img.comps[compno].data); free(img.comps[compno].data);
@ -476,12 +473,11 @@ int main(int argc, char **argv)
tmp--; tmp--;
} }
*tmp='\0'; *tmp='\0';
//if (img.numcomps > 1)
if (img.numcomps > 1)
sprintf(name, "%s-%d.pgx", outfile, compno); sprintf(name, "%s-%d.pgx", outfile, compno);
else
//else sprintf(name, "%s.pgx", outfile);
//sprintf(name, "%s.pgx", outfile);
fdest = fopen(name, "wb"); fdest = fopen(name, "wb");
if (!fdest) { if (!fdest) {

View File

@ -1076,11 +1076,7 @@ void tcd_rateallocate(unsigned char *dest, int len, info_image * info_IM)
} /* precno */ } /* precno */
} /* bandno */ } /* bandno */
} /* resno */ } /* resno */
maxSE += (((double)(1 << tcd_img->comps[compno].prec) - 1.0) * ((double)(1 << tcd_img->comps[compno].prec) -1.0)) * ((double)(tilec->nbpix));
maxSE +=
(double) (((1 << tcd_img->comps[compno].prec) -
1) * ((1 << tcd_img->comps[compno].prec) -
1)) * (tilec->nbpix);
} /* compno */ } /* compno */
/* add antonin index */ /* add antonin index */
@ -1104,7 +1100,7 @@ void tcd_rateallocate(unsigned char *dest, int len, info_image * info_IM)
distotarget = tcd_tile->distotile - ((K * maxSE) / pow(10, tcd_tcp->distoratio[layno] / 10)); // add fixed_quality distotarget = tcd_tile->distotile - ((K * maxSE) / pow(10, tcd_tcp->distoratio[layno] / 10)); // add fixed_quality
if (tcd_tcp->rates[layno]) { if ((tcd_tcp->rates[layno]) || (tcd_cp->disto_alloc==0)) {
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
volatile double thresh = (lo + hi) / 2; volatile double thresh = (lo + hi) / 2;
int l = 0; int l = 0;