fprintf correctly redirected to stderr or stdout

This commit is contained in:
Francois-Olivier Devaux
2004-11-15 12:41:35 +00:00
parent 0a879e2207
commit 1bdb07cefe
7 changed files with 508 additions and 358 deletions

View File

@@ -105,79 +105,79 @@ void j2k_clean()
void j2k_dump_image(j2k_image_t * img)
{
int compno;
fprintf(stderr, "image {\n");
fprintf(stderr, " x0=%d, y0=%d, x1=%d, y1=%d\n", img->x0, img->y0,
fprintf(stdout, "image {\n");
fprintf(stdout, " x0=%d, y0=%d, x1=%d, y1=%d\n", img->x0, img->y0,
img->x1, img->y1);
fprintf(stderr, " numcomps=%d\n", img->numcomps);
fprintf(stdout, " numcomps=%d\n", img->numcomps);
for (compno = 0; compno < img->numcomps; compno++) {
j2k_comp_t *comp = &img->comps[compno];
fprintf(stderr, " comp %d {\n", compno);
fprintf(stderr, " dx=%d, dy=%d\n", comp->dx, comp->dy);
fprintf(stderr, " prec=%d\n", comp->prec);
fprintf(stderr, " sgnd=%d\n", comp->sgnd);
fprintf(stderr, " }\n");
fprintf(stdout, " comp %d {\n", compno);
fprintf(stdout, " dx=%d, dy=%d\n", comp->dx, comp->dy);
fprintf(stdout, " prec=%d\n", comp->prec);
fprintf(stdout, " sgnd=%d\n", comp->sgnd);
fprintf(stdout, " }\n");
}
fprintf(stderr, "}\n");
fprintf(stdout, "}\n");
}
void j2k_dump_cp(j2k_image_t * img, j2k_cp_t * cp)
{
int tileno, compno, layno, bandno, resno, numbands;
fprintf(stderr, "coding parameters {\n");
fprintf(stderr, " tx0=%d, ty0=%d\n", cp->tx0, cp->ty0);
fprintf(stderr, " tdx=%d, tdy=%d\n", cp->tdx, cp->tdy);
fprintf(stderr, " tw=%d, th=%d\n", cp->tw, cp->th);
fprintf(stdout, "coding parameters {\n");
fprintf(stdout, " tx0=%d, ty0=%d\n", cp->tx0, cp->ty0);
fprintf(stdout, " tdx=%d, tdy=%d\n", cp->tdx, cp->tdy);
fprintf(stdout, " tw=%d, th=%d\n", cp->tw, cp->th);
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
j2k_tcp_t *tcp = &cp->tcps[tileno];
fprintf(stderr, " tile %d {\n", tileno);
fprintf(stderr, " csty=%x\n", tcp->csty);
fprintf(stderr, " prg=%d\n", tcp->prg);
fprintf(stderr, " numlayers=%d\n", tcp->numlayers);
fprintf(stderr, " mct=%d\n", tcp->mct);
fprintf(stderr, " rates=");
fprintf(stdout, " tile %d {\n", tileno);
fprintf(stdout, " csty=%x\n", tcp->csty);
fprintf(stdout, " prg=%d\n", tcp->prg);
fprintf(stdout, " numlayers=%d\n", tcp->numlayers);
fprintf(stdout, " mct=%d\n", tcp->mct);
fprintf(stdout, " rates=");
for (layno = 0; layno < tcp->numlayers; layno++) {
fprintf(stderr, "%d ", tcp->rates[layno]);
fprintf(stdout, "%d ", tcp->rates[layno]);
}
fprintf(stderr, "\n");
fprintf(stdout, "\n");
for (compno = 0; compno < img->numcomps; compno++) {
j2k_tccp_t *tccp = &tcp->tccps[compno];
fprintf(stderr, " comp %d {\n", compno);
fprintf(stderr, " csty=%x\n", tccp->csty);
fprintf(stderr, " numresolutions=%d\n", tccp->numresolutions);
fprintf(stderr, " cblkw=%d\n", tccp->cblkw);
fprintf(stderr, " cblkh=%d\n", tccp->cblkh);
fprintf(stderr, " cblksty=%x\n", tccp->cblksty);
fprintf(stderr, " qmfbid=%d\n", tccp->qmfbid);
fprintf(stderr, " qntsty=%d\n", tccp->qntsty);
fprintf(stderr, " numgbits=%d\n", tccp->numgbits);
fprintf(stderr, " roishift=%d\n", tccp->roishift);
fprintf(stderr, " stepsizes=");
fprintf(stdout, " comp %d {\n", compno);
fprintf(stdout, " csty=%x\n", tccp->csty);
fprintf(stdout, " numresolutions=%d\n", tccp->numresolutions);
fprintf(stdout, " cblkw=%d\n", tccp->cblkw);
fprintf(stdout, " cblkh=%d\n", tccp->cblkh);
fprintf(stdout, " cblksty=%x\n", tccp->cblksty);
fprintf(stdout, " qmfbid=%d\n", tccp->qmfbid);
fprintf(stdout, " qntsty=%d\n", tccp->qntsty);
fprintf(stdout, " numgbits=%d\n", tccp->numgbits);
fprintf(stdout, " roishift=%d\n", tccp->roishift);
fprintf(stdout, " stepsizes=");
numbands =
tccp->qntsty ==
J2K_CCP_QNTSTY_SIQNT ? 1 : tccp->numresolutions * 3 - 2;
for (bandno = 0; bandno < numbands; bandno++) {
fprintf(stderr, "(%d,%d) ", tccp->stepsizes[bandno].mant,
fprintf(stdout, "(%d,%d) ", tccp->stepsizes[bandno].mant,
tccp->stepsizes[bandno].expn);
}
fprintf(stderr, "\n");
fprintf(stdout, "\n");
if (tccp->csty & J2K_CCP_CSTY_PRT) {
fprintf(stderr, " prcw=");
fprintf(stdout, " prcw=");
for (resno = 0; resno < tccp->numresolutions; resno++) {
fprintf(stderr, "%d ", tccp->prcw[resno]);
fprintf(stdout, "%d ", tccp->prcw[resno]);
}
fprintf(stderr, "\n");
fprintf(stderr, " prch=");
fprintf(stdout, "\n");
fprintf(stdout, " prch=");
for (resno = 0; resno < tccp->numresolutions; resno++) {
fprintf(stderr, "%d ", tccp->prch[resno]);
fprintf(stdout, "%d ", tccp->prch[resno]);
}
fprintf(stderr, "\n");
fprintf(stdout, "\n");
}
fprintf(stderr, " }\n");
fprintf(stdout, " }\n");
}
fprintf(stderr, " }\n");
fprintf(stdout, " }\n");
}
fprintf(stderr, "}\n");
fprintf(stdout, "}\n");
}
void j2k_write_soc()
@@ -1044,7 +1044,7 @@ j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *output,
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
fprintf(stderr, "Tile number %d / %d ", tileno + 1, cp->tw * cp->th);
fprintf(stdout, "Tile number %d / %d ", tileno + 1, cp->tw * cp->th);
if (cp->intermed_file == 1) {
/* new dest for each tile */
@@ -1459,6 +1459,7 @@ j2k_decode(unsigned char *src, int len, j2k_image_t * img, j2k_cp_t * cp)
for (;;) {
j2k_dec_mstabent_t *e;
int id = cio_read(2);
if (id >> 8 != 0xff) {
@@ -1475,6 +1476,7 @@ j2k_decode(unsigned char *src, int len, j2k_image_t * img, j2k_cp_t * cp)
(*e->handler) ();
}
if (j2k_state == J2K_STATE_NEOC)
break; /* RAJOUTE */
}
@@ -1564,24 +1566,44 @@ j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t * img,
return 0;
}
void j2k_dec_release()
{
int i=0;
//tcd_dec_release();
if (j2k_tile_len!=NULL) free(j2k_tile_len);
if (j2k_tile_data!=NULL) free(j2k_tile_data);
if (j2k_default_tcp.ppt_data!=NULL) free(j2k_default_tcp.ppt_data);
if (j2k_default_tcp.tccps!=NULL) free(j2k_default_tcp.tccps);
for (i=0;i<j2k_cp->tw*j2k_cp->th;i++) {
if (j2k_cp->tcps[i].ppt_data!=NULL) free(j2k_cp->tcps[i].ppt_data);
if (j2k_cp->tcps[i].tccps!=NULL) free(j2k_cp->tcps[i].tccps);
}
if (j2k_cp->ppm_data!=NULL) free(j2k_cp->ppm_data);
if (j2k_cp->tcps!=NULL) free(j2k_cp->tcps);
if (j2k_img->comps!=NULL) free(j2k_img->comps);
if (j2k_cp->tileno!=NULL) free(j2k_cp->tileno);
}
#ifdef WIN32

View File

@@ -188,6 +188,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)
{
@@ -249,7 +250,9 @@ void t1_dec_sigpass(int w, int h, int bpno, int orient, char type,
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_dec_sigpass_step(&t1_flags[1 + j][1 + i],
&t1_data[j][i],
orient,
oneplushalf,
type, vsc);
}
@@ -279,6 +282,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)
{
@@ -331,8 +335,11 @@ void t1_dec_refpass(int w, int h, int bpno, char type, int cblksty)
&& (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);
}
}
@@ -366,6 +373,8 @@ void t1_enc_clnpass_step(int *fp, int *dp, int orient, int bpno, int one,
}
void t1_dec_clnpass_step(int *fp, int *dp, int orient, int oneplushalf,
int partial, int vsc)
{
@@ -504,7 +513,9 @@ void t1_dec_clnpass(int w, int h, int bpno, int orient, int cblksty)
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_dec_clnpass_step(&t1_flags[1 + j][1 + i],
&t1_data[j][i],
orient,
oneplushalf,
agg && (j == k + runlen), vsc);
}
@@ -699,7 +710,9 @@ void t1_decode_cblk(tcd_cblk_t * cblk, int orient, int roishift,
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++) {
@@ -717,9 +730,13 @@ void t1_decode_cblk(tcd_cblk_t * cblk, int orient, int roishift,
if ((cblksty & J2K_CCP_CBLKSTY_RESET) && type == T1_TYPE_MQ) {
mqc_resetstates();
mqc_setstate(T1_CTXNO_UNI, 0, 46);
mqc_setstate(T1_CTXNO_AGG, 0, 3);
mqc_setstate(T1_CTXNO_ZC, 0, 4);
}
if (++passtype == 3) {
@@ -881,10 +898,15 @@ void t1_decode_cblks(tcd_tile_t * tile, j2k_tcp_t * tcp)
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 -
@@ -1061,7 +1083,7 @@ void t1_init_luts()
t1_lut_spb[i] = t1_init_spb(i << 4);
}
/* FIXME FIXME FIXME */
/* printf("nmsedec luts:\n"); */
/* fprintf(stdout,"nmsedec luts:\n"); */
for (i = 0; i < (1 << T1_NMSEDEC_BITS); i++) {
t = i / pow(2, T1_NMSEDEC_FRACBITS);
u = t;

View File

@@ -303,6 +303,7 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
tcd_tilecomp_t *tilec = &tile->comps[compno];
tcd_resolution_t *res = &tilec->resolutions[resno];
unsigned char *c = src;
unsigned char *hd = NULL;
int present;
@@ -310,10 +311,15 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
for (bandno = 0; bandno < res->numbands; bandno++) {
tcd_band_t *band = &res->bands[bandno];
tcd_precinct_t *prc = &band->precincts[precno];
//Add Antonin : sizebug1
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
//ddA
tgt_reset(prc->incltree);
tgt_reset(prc->imsbtree);
@@ -323,15 +329,25 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
}
}
}
// SOP markers
if (tcp->csty & J2K_CP_CSTY_SOP) {
if ((*c) != 0xff || (*(c + 1) != 0x91)) {
printf("Warning : expected SOP marker\n");
fprintf(stderr,"Warning : expected SOP marker\n");
} else {
c += 6;
}
//TODO : check the Nsop value
}
/* When the marker PPT/PPM is used the packet header are store in PPT/PPM marker
@@ -339,6 +355,7 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
step 1: Read packet header in the saved structure
step 2: Return to codestream for decoding */
if (cp->ppm == 1) { /* PPM */
hd = cp->ppm_data;
bio_init_dec(hd, cp->ppm_len); //Mod Antonin : ppmbug1
@@ -346,47 +363,69 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
hd = tcp->ppt_data;
bio_init_dec(hd, tcp->ppt_len); //Mod Antonin : ppmbug1
} else { /* Normal Case */
hd = c;
bio_init_dec(hd, src+len-hd);
}
present = bio_read(1);
if (!present) {
bio_inalign();
hd += bio_numbytes();
// EPH markers
if (tcp->csty & J2K_CP_CSTY_EPH) {
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
printf("Error : expected EPH marker\n");
} else {
hd += 2;
}
}
if (cp->ppm == 1) { /* PPM case */
cp->ppm_len+=cp->ppm_data-hd;
cp->ppm_data = hd;
return c - src;
}
if (tcp->ppt == 1) { /* PPT case */
tcp->ppt_len+=tcp->ppt_data-hd;
tcp->ppt_data = hd;
return c - src;
}
return hd - src;
}
for (bandno = 0; bandno < res->numbands; bandno++) {
tcd_band_t *band = &res->bands[bandno];
tcd_precinct_t *prc = &band->precincts[precno];
//Add Antonin : sizebug1
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
//ddA
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
int included, increment, n;
tcd_cblk_t *cblk = &prc->cblks[cblkno];
@@ -444,33 +483,50 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
hd += bio_numbytes();
// EPH markers
if (tcp->csty & J2K_CP_CSTY_EPH) {
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
printf("Error : expected EPH marker\n");
fprintf(stderr,"Error : expected EPH marker\n");
} else {
hd += 2;
}
}
if (cp->ppm==1) {
cp->ppm_len+=cp->ppm_data-hd;
cp->ppm_data = hd;
} else if (tcp->ppt == 1) {
tcp->ppt_len+=tcp->ppt_data-hd;
tcp->ppt_data = hd;
} else {
c=hd;
}
for (bandno = 0; bandno < res->numbands; bandno++) {
tcd_band_t *band = &res->bands[bandno];
tcd_precinct_t *prc = &band->precincts[precno];
//Add Antonin : sizebug1
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
//ddA
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
tcd_cblk_t *cblk = &prc->cblks[cblkno];
tcd_seg_t *seg;
@@ -478,6 +534,7 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
continue;
if (!cblk->numsegs) {
seg = &cblk->segs[0];
cblk->numsegs++;
cblk->len = 0;
} else {

View File

@@ -61,61 +61,61 @@ extern jmp_buf j2k_error;
void tcd_dump(tcd_image_t * img, int curtileno)
{
int tileno, compno, resno, bandno, precno, cblkno;
fprintf(stderr, "image {\n");
fprintf(stderr, " tw=%d, th=%d x0=%d x1=%d y0=%d y1=%d\n", img->tw,
fprintf(stdout, "image {\n");
fprintf(stdout, " tw=%d, th=%d x0=%d x1=%d y0=%d y1=%d\n", img->tw,
img->th, tcd_img->x0, tcd_img->x1, tcd_img->y0, tcd_img->y1);
for (tileno = 0; tileno < img->th * img->tw; tileno++) {
tcd_tile_t *tile = &tcd_image.tiles[tileno];
fprintf(stderr, " tile {\n");
fprintf(stderr, " x0=%d, y0=%d, x1=%d, y1=%d, numcomps=%d\n",
fprintf(stdout, " tile {\n");
fprintf(stdout, " x0=%d, y0=%d, x1=%d, y1=%d, numcomps=%d\n",
tile->x0, tile->y0, tile->x1, tile->y1, tile->numcomps);
for (compno = 0; compno < tile->numcomps; compno++) {
tcd_tilecomp_t *tilec = &tile->comps[compno];
fprintf(stderr, " tilec {\n");
fprintf(stderr,
fprintf(stdout, " tilec {\n");
fprintf(stdout,
" x0=%d, y0=%d, x1=%d, y1=%d, numresolutions=%d\n",
tilec->x0, tilec->y0, tilec->x1, tilec->y1,
tilec->numresolutions);
for (resno = 0; resno < tilec->numresolutions; resno++) {
tcd_resolution_t *res = &tilec->resolutions[resno];
fprintf(stderr, "\n res {\n");
fprintf(stderr,
fprintf(stdout, "\n res {\n");
fprintf(stdout,
" x0=%d, y0=%d, x1=%d, y1=%d, pw=%d, ph=%d, numbands=%d\n",
res->x0, res->y0, res->x1, res->y1, res->pw, res->ph,
res->numbands);
for (bandno = 0; bandno < res->numbands; bandno++) {
tcd_band_t *band = &res->bands[bandno];
fprintf(stderr, " band {\n");
fprintf(stderr,
fprintf(stdout, " band {\n");
fprintf(stdout,
" x0=%d, y0=%d, x1=%d, y1=%d, stepsize=%d, numbps=%d\n",
band->x0, band->y0, band->x1, band->y1,
band->stepsize, band->numbps);
for (precno = 0; precno < res->pw * res->ph; precno++) {
tcd_precinct_t *prec = &band->precincts[precno];
fprintf(stderr, " prec {\n");
fprintf(stderr,
fprintf(stdout, " prec {\n");
fprintf(stdout,
" x0=%d, y0=%d, x1=%d, y1=%d, cw=%d, ch=%d\n",
prec->x0, prec->y0, prec->x1, prec->y1,
prec->cw, prec->ch);
for (cblkno = 0; cblkno < prec->cw * prec->ch; cblkno++) {
tcd_cblk_t *cblk = &prec->cblks[cblkno];
fprintf(stderr, " cblk {\n");
fprintf(stderr,
fprintf(stdout, " cblk {\n");
fprintf(stdout,
" x0=%d, y0=%d, x1=%d, y1=%d\n",
cblk->x0, cblk->y0, cblk->x1, cblk->y1);
fprintf(stderr, " }\n");
fprintf(stdout, " }\n");
}
fprintf(stderr, " }\n");
fprintf(stdout, " }\n");
}
fprintf(stderr, " }\n");
fprintf(stdout, " }\n");
}
fprintf(stderr, " }\n");
fprintf(stdout, " }\n");
}
fprintf(stderr, " }\n");
fprintf(stdout, " }\n");
}
fprintf(stderr, " }\n");
fprintf(stdout, " }\n");
}
fprintf(stderr, "}\n");
fprintf(stdout, "}\n");
}
void tcd_malloc_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
@@ -1294,7 +1294,7 @@ tcd_encode_tile_pxm(int tileno, unsigned char *dest, int len,
/*---------------CLEAN-------------------*/
time7 = clock() - time7;
printf("total: %ld.%.3ld s\n", time7 / CLOCKS_PER_SEC,
fprintf(stdout,"total: %ld.%.3ld s\n", time7 / CLOCKS_PER_SEC,
(time7 % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
/* cleaning memory */
@@ -1461,7 +1461,7 @@ tcd_encode_tile_pgx(int tileno, unsigned char *dest, int len,
/*---------------CLEAN-------------------*/
time = clock() - time;
printf("total: %ld.%.3ld s\n", time / CLOCKS_PER_SEC,
fprintf(stdout,"total: %ld.%.3ld s\n", time / CLOCKS_PER_SEC,
(time % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
for (compno = 0; compno < tile->numcomps; compno++) {
@@ -1488,7 +1488,7 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
time = clock();
fprintf(stderr, "tile decoding time %d/%d: ", tileno + 1,
fprintf(stdout, "tile decoding time %d/%d: ", tileno + 1,
tcd_cp->tw * tcd_cp->th);
/*--------------TIER2------------------*/
@@ -1611,10 +1611,11 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
}
time = clock() - time;
fprintf(stderr, "total: %ld.%.3ld s\n", time / CLOCKS_PER_SEC,
fprintf(stdout, "total: %ld.%.3ld s\n", time / CLOCKS_PER_SEC,
(time % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
for (compno = 0; compno < tile->numcomps; compno++) {
free(tcd_image.tiles[tileno].comps[compno].data);
}
@@ -1626,29 +1627,56 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
return l;
}
void tcd_dec_release()
{
int tileno,compno,resno,bandno,precno;
for (tileno=0;tileno<tcd_image.tw*tcd_image.th;tileno++) {
tcd_tile_t tile=tcd_image.tiles[tileno];
for (compno=0;compno<tile.numcomps;compno++) {
tcd_tilecomp_t tilec=tile.comps[compno];
for (resno=0;resno<tilec.numresolutions;resno++) {
tcd_resolution_t res=tilec.resolutions[resno];
for (bandno=0;bandno<res.numbands;bandno++) {
tcd_band_t band=res.bands[bandno];
for (precno=0;precno<res.ph*res.pw;precno++) {
tcd_precinct_t prec=band.precincts[precno];
if (prec.cblks!=NULL) free(prec.cblks);
if (prec.imsbtree!=NULL) free(prec.imsbtree);
if (prec.incltree!=NULL) free(prec.incltree);
}
if (band.precincts!=NULL) free(band.precincts);
}
}
if (tilec.resolutions!=NULL) free(tilec.resolutions);
}
if (tile.comps!=NULL) free(tile.comps);
}
if (tcd_image.tiles!=NULL) free(tcd_image.tiles);
}