diff --git a/codec/convert.c b/codec/convert.c index 9e5973ac..373faa12 100644 --- a/codec/convert.c +++ b/codec/convert.c @@ -96,7 +96,7 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, File_h.bfType = (getc(IN) << 8) + File_h.bfType; if (File_h.bfType != 19778) { - printf("Error, not a BMP file!\n"); + fprintf(stderr,"Error, not a BMP file!\n"); return 0; } else { /* FILE HEADER */ @@ -458,7 +458,7 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, not_end_file = 0; break; case 2: - printf("No Delta supported\n"); + fprintf(stderr,"No Delta supported\n"); return 1; break; default: @@ -557,8 +557,10 @@ int pgxtoimage(char *filename, j2k_image_t * img, int tdy, int w, h, prec; int i, compno, bandno; char str[256]; + char endian1,endian2,sign; char signtmp[32]; + char temp[32]; int bigendian; j2k_comp_t *comp; @@ -572,35 +574,54 @@ int pgxtoimage(char *filename, j2k_image_t * img, int tdy, int max = 0; int Y1; + comp = &img->comps[compno]; sprintf(str, "%s", filename); + f = fopen(str, "rb"); if (!f) { fprintf(stderr, "Failed to open %s for reading !\n", str); return 0; } + + fseek(f, 0, SEEK_SET); + fscanf(f, "PG%[ \t]%c%c%[ \t+-]%d%[ \t]%d%[ \t]%d",temp,&endian1,&endian2,signtmp,&prec,temp,&w,temp,&h); + + i=0; + sign='+'; + while (signtmp[i]!='\0') { + if (signtmp[i]=='-') sign='-'; + i++; + } + + fgetc(f); if (endian1=='M' && endian2=='L') bigendian = 1; else if (endian2=='M' && endian1=='L') bigendian = 0; + else { + fprintf(stderr, "Bad pgx header, please check input file\n", str); + return 0; + } + if (compno == 0) { img->x0 = Dim[0]; img->y0 = Dim[1]; diff --git a/codec/image_to_j2k.c b/codec/image_to_j2k.c index ed9ec0ce..922182bd 100644 --- a/codec/image_to_j2k.c +++ b/codec/image_to_j2k.c @@ -56,152 +56,152 @@ void help_display() { - printf("HELP\n----\n\n"); - printf("- the -h option displays this help information on screen\n\n"); + fprintf(stdout,"HELP\n----\n\n"); + fprintf(stdout,"- the -h option displays this help information on screen\n\n"); - printf("List of parameters for the coder JPEG 2000:\n"); - printf("\n"); - printf("REMARKS:\n"); - printf("---------\n"); - printf("\n"); - printf - ("The markers written to the main_header are : SOC SIZ COD QCD COM.\n"); - printf - ("COD and QCD never appear in the tile_header.\n"); - printf("\n"); - printf - ("- This coder can encode a mega image, a test was made on a 24000x24000 pixels \n"); - printf - ("color image. You need enough disk space memory (twice the original) to encode \n"); - printf - ("the image,i.e. for a 1.5 GB image you need a minimum of 3GB of disk memory)\n"); - printf("\n"); - printf("By default:\n"); - printf("------------\n"); - printf("\n"); - printf(" * Lossless\n"); - printf(" * 1 tile\n"); - printf(" * Size of precinct : 2^15 x 2^15 (means 1 precinct)\n"); - printf(" * Size of code-block : 64 x 64\n"); - printf(" * Number of resolutions: 6\n"); - printf(" * No SOP marker in the codestream\n"); - printf(" * No EPH marker in the codestream\n"); - printf(" * No sub-sampling in x or y direction\n"); - printf(" * No mode switch activated\n"); - printf(" * Progression order: LRCP\n"); - printf(" * No index file\n"); - printf(" * No ROI upshifted\n"); - printf(" * No offset of the origin of the image\n"); - printf(" * No offset of the origin of the tiles\n"); - printf(" * Reversible DWT 5-3\n"); - printf("\n"); - printf("Parameters:\n"); - printf("------------\n"); - printf("\n"); - printf - ("Required Parameters (except with -h):\n"); - printf("\n"); - printf - ("-i : source file (-i source.pnm also *.pgm, *.ppm) \n"); - printf("\n"); - printf - ("-o : destination file (-o dest.j2k or .jp2) \n"); - printf("\n"); - printf - ("Optional Parameters:\n"); - printf("\n"); - printf("-h : display the help information \n "); - printf("\n"); - printf("-r : different compression ratios for successive layers (-r 20,10,5)\n "); - printf(" - The rate specified for each quality level is the desired \n"); - printf(" compression factor.\n"); - printf(" Example: -r 20,10,1 means quality 1: compress 20x, \n"); - printf(" quality 2: compress 10x and quality 3: compress lossless\n"); - printf("\n"); - printf(" (options -r and -q cannot be used together)\n "); - printf("\n"); + fprintf(stdout,"List of parameters for the coder JPEG 2000:\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"REMARKS:\n"); + fprintf(stdout,"---------\n"); + fprintf(stdout,"\n"); + fprintf + (stdout,"The markers written to the main_header are : SOC SIZ COD QCD COM.\n"); + fprintf + (stdout,"COD and QCD never appear in the tile_header.\n"); + fprintf(stdout,"\n"); + fprintf + (stdout,"- This coder can encode a mega image, a test was made on a 24000x24000 pixels \n"); + fprintf + (stdout,"color image. You need enough disk space memory (twice the original) to encode \n"); + fprintf + (stdout,"the image,i.e. for a 1.5 GB image you need a minimum of 3GB of disk memory)\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"By default:\n"); + fprintf(stdout,"------------\n"); + fprintf(stdout,"\n"); + fprintf(stdout," * Lossless\n"); + fprintf(stdout," * 1 tile\n"); + fprintf(stdout," * Size of precinct : 2^15 x 2^15 (means 1 precinct)\n"); + fprintf(stdout," * Size of code-block : 64 x 64\n"); + fprintf(stdout," * Number of resolutions: 6\n"); + fprintf(stdout," * No SOP marker in the codestream\n"); + fprintf(stdout," * No EPH marker in the codestream\n"); + fprintf(stdout," * No sub-sampling in x or y direction\n"); + fprintf(stdout," * No mode switch activated\n"); + fprintf(stdout," * Progression order: LRCP\n"); + fprintf(stdout," * No index file\n"); + fprintf(stdout," * No ROI upshifted\n"); + fprintf(stdout," * No offset of the origin of the image\n"); + fprintf(stdout," * No offset of the origin of the tiles\n"); + fprintf(stdout," * Reversible DWT 5-3\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"Parameters:\n"); + fprintf(stdout,"------------\n"); + fprintf(stdout,"\n"); + fprintf + (stdout,"Required Parameters (except with -h):\n"); + fprintf(stdout,"\n"); + fprintf + (stdout,"-i : source file (-i source.pnm also *.pgm, *.ppm) \n"); + fprintf(stdout,"\n"); + fprintf + (stdout,"-o : destination file (-o dest.j2k or .jp2) \n"); + fprintf(stdout,"\n"); + fprintf + (stdout,"Optional Parameters:\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-h : display the help information \n "); + fprintf(stdout,"\n"); + fprintf(stdout,"-r : different compression ratios for successive layers (-r 20,10,5)\n "); + fprintf(stdout," - The rate specified for each quality level is the desired \n"); + fprintf(stdout," compression factor.\n"); + fprintf(stdout," Example: -r 20,10,1 means quality 1: compress 20x, \n"); + fprintf(stdout," quality 2: compress 10x and quality 3: compress lossless\n"); + fprintf(stdout,"\n"); + fprintf(stdout," (options -r and -q cannot be used together)\n "); + fprintf(stdout,"\n"); - printf("-q : different psnr for successive layers (-q 30,40,50) \n "); + fprintf(stdout,"-q : different psnr for successive layers (-q 30,40,50) \n "); - printf(" (options -r and -q cannot be used together)\n "); + fprintf(stdout," (options -r and -q cannot be used together)\n "); - printf("\n"); - printf("-n : number of resolutions (-n 3) \n"); - printf("\n"); - printf("-b : size of code block (-b 32,32) \n"); - printf("\n"); - printf("-c : size of precinct (-c 128,128) \n"); - printf("\n"); - printf("-t : size of tile (-t 512,512) \n"); - printf("\n"); - printf - ("-p : progression order (-p LRCP) [LRCP, RLCP, RPCL, PCRL, CPRL] \n"); - printf("\n"); - printf - ("-s : subsampling factor (-s 2,2) [-s X,Y] \n"); - printf(" Remark: subsampling bigger than 2 can produce error\n"); - printf("\n"); - printf - ("-SOP : write SOP marker before each packet \n"); - printf("\n"); - printf - ("-EPH : write EPH marker after each header packet \n"); - printf("\n"); - printf - ("-M : mode switch (-M 3) [1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL)\n"); - printf - (" 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)] \n"); - printf - (" Indicate multiple modes by adding their values. \n"); - printf - (" ex: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n"); - printf("\n"); - printf - ("-x : create an index file *.Idx (-x index_name.Idx) \n"); - printf("\n"); - printf - ("-ROI : c=%%d,U=%%d : quantization indices upshifted \n"); - printf - (" for component c=%%d [%%d = 0,1,2]\n"); - printf - (" with a value of U=%%d [0 <= %%d <= 37] (i.e. -ROI:c=0,U=25) \n"); - printf("\n"); - printf - ("-d : offset of the origin of the image (-d 150,300) \n"); - printf("\n"); - printf - ("-T : offset of the origin of the tiles (-T 100,75) \n"); - printf("\n"); - printf("-I : use the irreversible DWT 9-7 (-I) \n"); - printf("\n"); - printf("IMPORTANT:\n"); - printf("-----------\n"); - printf("\n"); - printf("The index file has the structure below:\n"); - printf("---------------------------------------\n"); - printf("\n"); - printf("Image_height Image_width\n"); - printf("progression order\n"); - printf("Tiles_size_X Tiles_size_Y\n"); - printf("Components_nb\n"); - printf("Layers_nb\n"); - printf("decomposition_levels\n"); - printf("[Precincts_size_X_res_Nr Precincts_size_Y_res_Nr]...\n"); - printf(" [Precincts_size_X_res_0 Precincts_size_Y_res_0]\n"); - printf("Main_header_end_position\n"); - printf("Codestream_size\n"); - printf("Tile_0 start_pos end_Theader end_pos TotalDisto NumPix MaxMSE\n"); - printf("Tile_1 '' '' '' '' '' ''\n"); - printf("...\n"); - printf("Tile_Nt '' '' '' '' '' ''\n"); - printf("Tpacket_0 Tile layer res. comp. prec. start_pos end_pos disto\n"); - printf("...\n"); - printf("Tpacket_Np '' '' '' '' '' '' '' ''\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-n : number of resolutions (-n 3) \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-b : size of code block (-b 32,32) \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-c : size of precinct (-c 128,128) \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-t : size of tile (-t 512,512) \n"); + fprintf(stdout,"\n"); + fprintf + (stdout,"-p : progression order (-p LRCP) [LRCP, RLCP, RPCL, PCRL, CPRL] \n"); + fprintf(stdout,"\n"); + fprintf + (stdout,"-s : subsampling factor (-s 2,2) [-s X,Y] \n"); + fprintf(stdout," Remark: subsampling bigger than 2 can produce error\n"); + fprintf(stdout,"\n"); + fprintf + (stdout,"-SOP : write SOP marker before each packet \n"); + fprintf(stdout,"\n"); + fprintf + (stdout,"-EPH : write EPH marker after each header packet \n"); + fprintf(stdout,"\n"); + fprintf + (stdout,"-M : mode switch (-M 3) [1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL)\n"); + fprintf + (stdout," 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)] \n"); + fprintf + (stdout," Indicate multiple modes by adding their values. \n"); + fprintf + (stdout," ex: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n"); + fprintf(stdout,"\n"); + fprintf + (stdout,"-x : create an index file *.Idx (-x index_name.Idx) \n"); + fprintf(stdout,"\n"); + fprintf + (stdout,"-ROI : c=%%d,U=%%d : quantization indices upshifted \n"); + fprintf + (stdout," for component c=%%d [%%d = 0,1,2]\n"); + fprintf + (stdout," with a value of U=%%d [0 <= %%d <= 37] (i.e. -ROI:c=0,U=25) \n"); + fprintf(stdout,"\n"); + fprintf + (stdout,"-d : offset of the origin of the image (-d 150,300) \n"); + fprintf(stdout,"\n"); + fprintf + (stdout,"-T : offset of the origin of the tiles (-T 100,75) \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-I : use the irreversible DWT 9-7 (-I) \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"IMPORTANT:\n"); + fprintf(stdout,"-----------\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"The index file has the structure below:\n"); + fprintf(stdout,"---------------------------------------\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"Image_height Image_width\n"); + fprintf(stdout,"progression order\n"); + fprintf(stdout,"Tiles_size_X Tiles_size_Y\n"); + fprintf(stdout,"Components_nb\n"); + fprintf(stdout,"Layers_nb\n"); + fprintf(stdout,"decomposition_levels\n"); + fprintf(stdout,"[Precincts_size_X_res_Nr Precincts_size_Y_res_Nr]...\n"); + fprintf(stdout," [Precincts_size_X_res_0 Precincts_size_Y_res_0]\n"); + fprintf(stdout,"Main_header_end_position\n"); + fprintf(stdout,"Codestream_size\n"); + fprintf(stdout,"Tile_0 start_pos end_Theader end_pos TotalDisto NumPix MaxMSE\n"); + fprintf(stdout,"Tile_1 '' '' '' '' '' ''\n"); + fprintf(stdout,"...\n"); + fprintf(stdout,"Tile_Nt '' '' '' '' '' ''\n"); + fprintf(stdout,"Tpacket_0 Tile layer res. comp. prec. start_pos end_pos disto\n"); + fprintf(stdout,"...\n"); + fprintf(stdout,"Tpacket_Np '' '' '' '' '' '' '' ''\n"); - printf("MaxDisto\n"); + fprintf(stdout,"MaxDisto\n"); - printf("TotalDisto\n\n"); + fprintf(stdout,"TotalDisto\n\n"); } int give_progression(char progression[4]) diff --git a/libopenjpeg/j2k.c b/libopenjpeg/j2k.c index 6c611adf..5611a892 100644 --- a/libopenjpeg/j2k.c +++ b/libopenjpeg/j2k.c @@ -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;itw*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 diff --git a/libopenjpeg/t1.c b/libopenjpeg/t1.c index 4df64799..be79c436 100644 --- a/libopenjpeg/t1.c +++ b/libopenjpeg/t1.c @@ -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; diff --git a/libopenjpeg/t2.c b/libopenjpeg/t2.c index 9ccc64c3..092b509c 100644 --- a/libopenjpeg/t2.c +++ b/libopenjpeg/t2.c @@ -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 { diff --git a/libopenjpeg/tcd.c b/libopenjpeg/tcd.c index ff9e0c95..225f75a0 100644 --- a/libopenjpeg/tcd.c +++ b/libopenjpeg/tcd.c @@ -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