diff --git a/codec/convert.c b/codec/convert.c index 8be7c220..d72f4377 100644 --- a/codec/convert.c +++ b/codec/convert.c @@ -1048,3 +1048,5 @@ int imagetopnm(opj_image_t * image, char *outfile) { return 0; } + + diff --git a/codec/image_to_j2k.c b/codec/image_to_j2k.c index 77bb3362..4a28ba07 100644 --- a/codec/image_to_j2k.c +++ b/codec/image_to_j2k.c @@ -201,8 +201,12 @@ OPJ_PROG_ORDER give_progression(char progression[4]) { int get_file_format(char *filename) { unsigned int i; - static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp", "j2k", "jp2" }; - static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, J2K_CFMT, JP2_CFMT }; + static const char *extension[] = { + "pgx", "pnm", "pgm", "ppm", "bmp", "j2k", "jp2" + }; + static const int format[] = { + PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, J2K_CFMT, JP2_CFMT + }; char * ext = strrchr(filename, '.') + 1; for(i = 0; i < sizeof(format)/sizeof(*format); i++) { if(strnicmp(ext, extension[i], 3) == 0) { @@ -213,7 +217,7 @@ int get_file_format(char *filename) { return -1; } -/* ------------------------------------------------------------------------------------ */ +/* -------------------------------------------------------------------------*/ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) { int i, j; @@ -235,15 +239,16 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) case BMP_DFMT: break; default: - fprintf(stderr, - "!! Unrecognized format for infile : %s [accept only *.pnm, *.pgm, *.ppm, *.pgx or *.bmp] !!\n\n", + fprintf(stderr, + "!! Unrecognized format for infile : %s " + "[accept only *.pnm, *.pgm, *.ppm, *.pgx or *.bmp] !!\n\n", infile); return 1; } strncpy(parameters->infile, infile, MAX_PATH); } break; - + /* ----------------------------------------------------- */ case 'o': /* output file */ @@ -263,7 +268,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) break; /* ----------------------------------------------------- */ - + case 'r': /* rates rates/distorsion */ { char *s = optarg; @@ -279,9 +284,9 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) parameters->cp_disto_alloc = 1; } break; - + /* ----------------------------------------------------- */ - + case 'q': /* add fixed_quality */ { char *s = optarg; @@ -297,7 +302,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) parameters->cp_fixed_quality = 1; } break; - + /* dda */ /* ----------------------------------------------------- */ @@ -345,7 +350,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) parameters->cp_fixed_alloc = 1; } break; - + /* ----------------------------------------------------- */ case 't': /* tiles */ @@ -354,15 +359,15 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) parameters->tile_size_on = true; } break; - + /* ----------------------------------------------------- */ - + case 'n': /* resolution */ { sscanf(optarg, "%d", ¶meters->numresolution); } break; - + /* ----------------------------------------------------- */ case 'c': /* precinct dimension */ { @@ -372,7 +377,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) char *s = optarg; do { sep = 0; - sscanf(s, "[%d,%d]%c", ¶meters->prcw_init[res_spec], ¶meters->prch_init[res_spec], &sep); + sscanf(s, "[%d,%d]%c", ¶meters->prcw_init[res_spec], + ¶meters->prch_init[res_spec], &sep); parameters->csty |= 0x01; res_spec++; s = strpbrk(s, "]") + 2; @@ -381,9 +387,9 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) parameters->res_spec = res_spec; } break; - + /* ----------------------------------------------------- */ - + case 'b': /* code-block dimension */ { int cblockw_init = 0, cblockh_init = 0; @@ -391,16 +397,17 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024 || cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) { fprintf(stderr, - "!! Size of code_block error (option -b) !!\n\nRestriction :\n * width*height<=4096\n * 4<=width,height<= 1024\n\n"); + "!! Size of code_block error (option -b) !!\n\nRestriction :\n" + " * width*height<=4096\n * 4<=width,height<= 1024\n\n"); return 1; } parameters->cblockw_init = cblockw_init; parameters->cblockh_init = cblockh_init; } break; - + /* ----------------------------------------------------- */ - + case 'x': /* creation of index file */ { char *index = optarg; @@ -408,9 +415,9 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) parameters->index_on = 1; } break; - + /* ----------------------------------------------------- */ - + case 'p': /* progression order */ { char progression[4]; @@ -418,40 +425,44 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) strncpy(progression, optarg, 4); parameters->prog_order = give_progression(progression); if (parameters->prog_order == -1) { - fprintf(stderr, "Unrecognized progression order [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n"); + fprintf(stderr, "Unrecognized progression order " + "[LRCP, RLCP, RPCL, PCRL, CPRL] !!\n"); return 1; } } break; - + /* ----------------------------------------------------- */ - + case 's': /* subsampling factor */ { - if (sscanf(optarg, "%d,%d", ¶meters->subsampling_dx, ¶meters->subsampling_dy) != 2) { + if (sscanf(optarg, "%d,%d", ¶meters->subsampling_dx, + ¶meters->subsampling_dy) != 2) { fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n"); return 1; } } break; - + /* ----------------------------------------------------- */ - + case 'd': /* coordonnate of the reference grid */ { - if (sscanf(optarg, "%d,%d", ¶meters->image_offset_x0, ¶meters->image_offset_y0) != 2) { - fprintf(stderr, "-d 'coordonnate of the reference grid' argument error !! [-d x0,y0]\n"); + if (sscanf(optarg, "%d,%d", ¶meters->image_offset_x0, + ¶meters->image_offset_y0) != 2) { + fprintf(stderr, "-d 'coordonnate of the reference grid' argument " + "error !! [-d x0,y0]\n"); return 1; } } break; - + /* ----------------------------------------------------- */ - + case 'h': /* display an help description */ encode_help_display(); return 1; - + /* ----------------------------------------------------- */ case 'P': /* POC */ @@ -465,7 +476,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) fprintf(stderr, "/----------------------------------\\\n"); fprintf(stderr, "| POC option not fully tested !! |\n"); fprintf(stderr, "\\----------------------------------/\n"); - + while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%s", &POC[numpocs].tile, &POC[numpocs].resno0, &POC[numpocs].compno0, &POC[numpocs].layno1, &POC[numpocs].resno1, @@ -484,25 +495,25 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) parameters->numpocs = numpocs; } break; - + /* ------------------------------------------------------ */ - + case 'S': /* SOP marker */ { parameters->csty |= 0x02; } break; - + /* ------------------------------------------------------ */ - + case 'E': /* EPH marker */ { parameters->csty |= 0x04; } break; - + /* ------------------------------------------------------ */ - + case 'M': /* Mode switch pas tous au point !! */ { int value = 0; @@ -515,20 +526,21 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) } } break; - + /* ------------------------------------------------------ */ - + case 'R': /* ROI */ { - if (sscanf(optarg, "OI:c=%d,U=%d", ¶meters->roi_compno, ¶meters->roi_shift) != 2) { + if (sscanf(optarg, "OI:c=%d,U=%d", ¶meters->roi_compno, + ¶meters->roi_shift) != 2) { fprintf(stderr, "ROI error !! [-ROI:c='compno',U='shift']\n"); return 1; } } break; - + /* ------------------------------------------------------ */ - + case 'T': /* Tile offset */ { if (sscanf(optarg, "%d,%d", ¶meters->cp_tx0, ¶meters->cp_ty0) != 2) { @@ -537,9 +549,9 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) } } break; - + /* ------------------------------------------------------ */ - + case 'C': /* add a comment */ { parameters->cp_comment = (char*)malloc(strlen(optarg) + 1); @@ -548,17 +560,17 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) } } break; - + /* ------------------------------------------------------ */ - + case 'I': /* reversible or not */ { parameters->irreversible = 1; } break; - + /* ------------------------------------------------------ */ - + default: fprintf(stderr, "ERROR -> this option is not valid \"-%c %s\"\n", c, optarg); return 1; @@ -635,9 +647,9 @@ int main(int argc, char **argv) { opj_event_mgr_t event_mgr; /* event manager */ opj_image_t *image = NULL; - /* + /* configure the event callbacks (not required) - setting of each callback is optionnal + setting of each callback is optionnal */ memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); event_mgr.error_handler = error_callback; @@ -669,7 +681,7 @@ int main(int argc, char **argv) { return 1; } break; - + case PXM_DFMT: image = pnmtoimage(parameters.infile, ¶meters); if (!image) { @@ -699,9 +711,9 @@ int main(int argc, char **argv) { opj_cinfo_t* cinfo = opj_create_compress(CODEC_J2K); /* catch events using our callbacks and give a local context */ - opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr); + opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr); - /* setup the encoder parameters using the current image and using user parameters */ + /* setup the encoder parameters using the current image and user parameters */ opj_setup_encoder(cinfo, ¶meters, image); /* open a byte stream for writing */ diff --git a/codec/j2k_to_image.c b/codec/j2k_to_image.c index 4541badd..c9747bbc 100644 --- a/codec/j2k_to_image.c +++ b/codec/j2k_to_image.c @@ -223,7 +223,7 @@ int main(int argc, char **argv) { opj_event_mgr_t event_mgr; /* event manager */ opj_image_t *image = NULL; FILE *fsrc = NULL; - unsigned char *src = NULL; + unsigned char *src = NULL; int file_length; opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */ @@ -242,21 +242,21 @@ int main(int argc, char **argv) { if(parse_cmdline_decoder(argc, argv, ¶meters) == 1) { return 0; } - + /* read the input file and put it in memory */ /* ---------------------------------------- */ fsrc = fopen(parameters.infile, "rb"); if (!fsrc) { fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile); return 1; - } + } fseek(fsrc, 0, SEEK_END); file_length = ftell(fsrc); fseek(fsrc, 0, SEEK_SET); src = (unsigned char *) malloc(file_length); fread(src, 1, file_length, fsrc); fclose(fsrc); - + /* decode the code-stream */ /* ---------------------- */ @@ -267,9 +267,9 @@ int main(int argc, char **argv) { /* get a decoder handle */ dinfo = opj_create_decompress(CODEC_J2K); - + /* catch events using our callbacks and give a local context */ - opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); + opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); /* setup the decoder decoding parameters using user parameters */ opj_setup_decoder(dinfo, ¶meters); @@ -285,7 +285,7 @@ int main(int argc, char **argv) { opj_cio_close(cio); return 1; } - + /* close the byte stream */ opj_cio_close(cio); } @@ -297,11 +297,11 @@ int main(int argc, char **argv) { /* get a decoder handle */ dinfo = opj_create_decompress(CODEC_JP2); - - /* catch events using our callbacks and give a local context */ - opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); - /* setup the decoder decoding parameters using the current image and using user parameters */ + /* catch events using our callbacks and give a local context */ + opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); + + /* setup the decoder decoding parameters using the current image and user parameters */ opj_setup_decoder(dinfo, ¶meters); /* open a byte stream */ @@ -328,9 +328,9 @@ int main(int argc, char **argv) { /* get a decoder handle */ dinfo = opj_create_decompress(CODEC_JPT); - + /* catch events using our callbacks and give a local context */ - opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); + opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); /* setup the decoder decoding parameters using user parameters */ opj_setup_decoder(dinfo, ¶meters); @@ -341,11 +341,11 @@ int main(int argc, char **argv) { /* decode the stream and fill the image structure */ image = opj_decode(dinfo, cio); if(!image) { - fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); + fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); opj_destroy_decompress(dinfo); opj_cio_close(cio); return 1; - } + } /* close the byte stream */ opj_cio_close(cio); @@ -356,7 +356,7 @@ int main(int argc, char **argv) { fprintf(stderr, "ERROR -> j2k_to_image : Unknown input image format\n"); return 1; } - + /* free the memory containing the code-stream */ free(src); src = NULL; @@ -368,11 +368,11 @@ int main(int argc, char **argv) { case PXM_DFMT: /* PNM PGM PPM */ imagetopnm(image, parameters.outfile); break; - + case PGX_DFMT: /* PGX */ imagetopgx(image, parameters.outfile); break; - + case BMP_DFMT: /* BMP */ imagetobmp(image, parameters.outfile); break; @@ -385,7 +385,7 @@ int main(int argc, char **argv) { /* free image data structure */ opj_image_destroy(image); - + return 0; }