diff options
| author | Francois-Olivier Devaux <fodevaux@users.noreply.github.com> | 2004-11-15 12:41:35 +0000 |
|---|---|---|
| committer | Francois-Olivier Devaux <fodevaux@users.noreply.github.com> | 2004-11-15 12:41:35 +0000 |
| commit | 1bdb07cefed67bb661f835d5165eb931c583c02d (patch) | |
| tree | 84844be57eb29e550e3a53ff938b8b148954cbc0 /codec | |
| parent | 0a879e22071bfdf39dcf2cb611db9cb364e62a04 (diff) | |
fprintf correctly redirected to stderr or stdout
Diffstat (limited to 'codec')
| -rw-r--r-- | codec/convert.c | 25 | ||||
| -rw-r--r-- | codec/image_to_j2k.c | 292 |
2 files changed, 169 insertions, 148 deletions
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"); - - - 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"); - - printf("-q : different psnr for successive layers (-q 30,40,50) \n "); - - printf(" (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"); - - printf("MaxDisto\n"); - - printf("TotalDisto\n\n"); + fprintf(stdout,"HELP\n----\n\n"); + fprintf(stdout,"- the -h option displays this help information on screen\n\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"); + + fprintf(stdout,"-q : different psnr for successive layers (-q 30,40,50) \n "); + + fprintf(stdout," (options -r and -q cannot be used together)\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"); + + fprintf(stdout,"MaxDisto\n"); + + fprintf(stdout,"TotalDisto\n\n"); } int give_progression(char progression[4]) |
