-static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
- img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) {
- int i, j, totlen, c;
- opj_option_t long_option[]={
- {"cinema2K",REQ_ARG, NULL ,'w'},
- {"cinema4K",NO_ARG, NULL ,'y'},
- {"ImgDir",REQ_ARG, NULL ,'z'},
- {"TP",REQ_ARG, NULL ,'u'},
- {"SOP",NO_ARG, NULL ,'S'},
- {"EPH",NO_ARG, NULL ,'E'},
- {"OutFor",REQ_ARG, NULL ,'O'},
- {"POC",REQ_ARG, NULL ,'P'},
- {"ROI",REQ_ARG, NULL ,'R'},
- {"jpip",NO_ARG, NULL, 'J'}
- };
-
- /* parse the command line */
- const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:J"
-#ifdef USE_JPWL
- "W:"
-#endif /* USE_JPWL */
- "h";
-
- totlen=sizeof(long_option);
- img_fol->set_out_format=0;
- raw_cp->rawWidth = 0;
-
- do{
- c = opj_getopt_long(argc, argv, optlist,long_option,totlen);
- if (c == -1)
- break;
- switch (c) {
- case 'i': /* input file */
- {
- char *infile = opj_optarg;
- parameters->decod_format = get_file_format(infile);
- switch(parameters->decod_format) {
- case PGX_DFMT:
- case PXM_DFMT:
- case BMP_DFMT:
- case TIF_DFMT:
- case RAW_DFMT:
- case RAWL_DFMT:
- case TGA_DFMT:
- case PNG_DFMT:
- break;
- default:
- fprintf(stderr,
- "!! Unrecognized format for infile : %s "
- "[accept only *.pnm, *.pgm, *.ppm, *.pgx, *png, *.bmp, *.tif, *.raw or *.tga] !!\n\n",
- infile);
- return 1;
- }
- strncpy(parameters->infile, infile, sizeof(parameters->infile)-1);
- }
- break;
-
- /* ----------------------------------------------------- */
-
- case 'o': /* output file */
- {
- char *outfile = opj_optarg;
- parameters->cod_format = get_file_format(outfile);
- switch(parameters->cod_format) {
- case J2K_CFMT:
- case JP2_CFMT:
- break;
- default:
- fprintf(stderr, "Unknown output format image %s [only *.j2k, *.j2c or *.jp2]!! \n", outfile);
- return 1;
- }
- strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1);
- }
- break;
-
- /* ----------------------------------------------------- */
- case 'O': /* output format */
- {
- char outformat[50];
- char *of = opj_optarg;
- sprintf(outformat,".%s",of);
- img_fol->set_out_format = 1;
- parameters->cod_format = get_file_format(outformat);
- switch(parameters->cod_format) {
- case J2K_CFMT:
- case JP2_CFMT:
- img_fol->out_format = opj_optarg;
- break;
- default:
- fprintf(stderr, "Unknown output format image [only j2k, j2c, jp2]!! \n");
- return 1;
- }
- }
- break;
-
-
- /* ----------------------------------------------------- */
-
-
- case 'r': /* rates rates/distorsion */
- {
- char *s = opj_optarg;
- parameters->tcp_numlayers = 0;
- while (sscanf(s, "%f", ¶meters->tcp_rates[parameters->tcp_numlayers]) == 1) {
- parameters->tcp_numlayers++;
- while (*s && *s != ',') {
- s++;
- }
- if (!*s)
- break;
- s++;
- }
- parameters->cp_disto_alloc = 1;
- }
- break;
-
- /* ----------------------------------------------------- */
-
-
- case 'F': /* Raw image format parameters */
- {
- char signo;
- char *s = opj_optarg;
- if (sscanf(s, "%d,%d,%d,%d,%c", &raw_cp->rawWidth, &raw_cp->rawHeight, &raw_cp->rawComp, &raw_cp->rawBitDepth, &signo) == 5) {
- if (signo == 's') {
- raw_cp->rawSigned = OPJ_TRUE;
- fprintf(stdout,"\nRaw file parameters: %d,%d,%d,%d Signed\n", raw_cp->rawWidth, raw_cp->rawHeight, raw_cp->rawComp, raw_cp->rawBitDepth);
- }
- else if (signo == 'u') {
- raw_cp->rawSigned = OPJ_FALSE;
- fprintf(stdout,"\nRaw file parameters: %d,%d,%d,%d Unsigned\n", raw_cp->rawWidth, raw_cp->rawHeight, raw_cp->rawComp, raw_cp->rawBitDepth);
- }
- else {
- fprintf(stderr,"\nError: invalid raw image parameters: Unknown sign of raw file\n");
- fprintf(stderr,"Please use the Format option -F:\n");
- fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n");
- fprintf(stderr,"Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n");
- fprintf(stderr,"Aborting\n");
- }
- }
- else {
- fprintf(stderr,"\nError: invalid raw image parameters\n");
- fprintf(stderr,"Please use the Format option -F:\n");
- fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n");
- fprintf(stderr,"Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n");
- fprintf(stderr,"Aborting\n");
- return 1;
- }
- }
- break;
-
- /* ----------------------------------------------------- */
-
- case 'q': /* add fixed_quality */
- {
- char *s = opj_optarg;
- while (sscanf(s, "%f", ¶meters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
- parameters->tcp_numlayers++;
- while (*s && *s != ',') {
- s++;
- }
- if (!*s)
- break;
- s++;
- }
- parameters->cp_fixed_quality = 1;
- }
- break;
-
- /* dda */
- /* ----------------------------------------------------- */
-
- case 'f': /* mod fixed_quality (before : -q) */
- {
- int *row = NULL, *col = NULL;
- int numlayers = 0, numresolution = 0, matrix_width = 0;
-
- char *s = opj_optarg;
- sscanf(s, "%d", &numlayers);
- s++;
- if (numlayers > 9)
- s++;
-
- parameters->tcp_numlayers = numlayers;
- numresolution = parameters->numresolution;
- matrix_width = numresolution * 3;
- parameters->cp_matrice = (int *) malloc(numlayers * matrix_width * sizeof(int));
- s = s + 2;
-
- for (i = 0; i < numlayers; i++) {
- row = ¶meters->cp_matrice[i * matrix_width];
- col = row;
- parameters->tcp_rates[i] = 1;
- sscanf(s, "%d,", &col[0]);
- s += 2;
- if (col[0] > 9)
- s++;
- col[1] = 0;
- col[2] = 0;
- for (j = 1; j < numresolution; j++) {
- col += 3;
- sscanf(s, "%d,%d,%d", &col[0], &col[1], &col[2]);
- s += 6;
- if (col[0] > 9)
- s++;
- if (col[1] > 9)
- s++;
- if (col[2] > 9)
- s++;
- }
- if (i < numlayers - 1)
- s++;
- }
- parameters->cp_fixed_alloc = 1;
- }
- break;
-
- /* ----------------------------------------------------- */
-
- case 't': /* tiles */
- {
- sscanf(opj_optarg, "%d,%d", ¶meters->cp_tdx, ¶meters->cp_tdy);
- parameters->tile_size_on = OPJ_TRUE;
- }
- break;
-
- /* ----------------------------------------------------- */
-
- case 'n': /* resolution */
- {
- sscanf(opj_optarg, "%d", ¶meters->numresolution);
- }
- break;
-
- /* ----------------------------------------------------- */
- case 'c': /* precinct dimension */
- {
- char sep;
- int res_spec = 0;
-
- char *s = opj_optarg;
- do {
- sep = 0;
- 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;
- }
- while (sep == ',');
- parameters->res_spec = res_spec;
- }
- break;
-
- /* ----------------------------------------------------- */
-
- case 'b': /* code-block dimension */
- {
- int cblockw_init = 0, cblockh_init = 0;
- sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
- 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");
- return 1;
- }
- parameters->cblockw_init = cblockw_init;
- parameters->cblockh_init = cblockh_init;
- }
- break;
-
- /* ----------------------------------------------------- */
-
- case 'x': /* creation of index file */
- {
- char *index = opj_optarg;
- strncpy(indexfilename, index, OPJ_PATH_LEN);
- }
- break;
-
- /* ----------------------------------------------------- */
-
- case 'p': /* progression order */
- {
- char progression[4];
-
- strncpy(progression, opj_optarg, 4);
- parameters->prog_order = give_progression(progression);
- if (parameters->prog_order == -1) {
- fprintf(stderr, "Unrecognized progression order "
- "[LRCP, RLCP, RPCL, PCRL, CPRL] !!\n");
- return 1;
- }
- }
- break;
-
- /* ----------------------------------------------------- */
-
- case 's': /* subsampling factor */
- {
- if (sscanf(opj_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(opj_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 */
- {
- int numpocs = 0; /* number of progression order change (POC) default 0 */
- opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
-
- char *s = opj_optarg;
- POC = parameters->POC;
-
- while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%4s", &POC[numpocs].tile,
- &POC[numpocs].resno0, &POC[numpocs].compno0,
- &POC[numpocs].layno1, &POC[numpocs].resno1,
- &POC[numpocs].compno1, POC[numpocs].progorder) == 7) {
- POC[numpocs].prg1 = give_progression(POC[numpocs].progorder);
- numpocs++;
- while (*s && *s != '/') {
- s++;
- }
- if (!*s) {
- break;
- }
- s++;
- }
- 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;
- if (sscanf(opj_optarg, "%d", &value) == 1) {
- for (i = 0; i <= 5; i++) {
- int cache = value & (1 << i);
- if (cache)
- parameters->mode |= (1 << i);
- }
- }
- }
- break;
-
- /* ------------------------------------------------------ */
-
- case 'R': /* ROI */
- {
- if (sscanf(opj_optarg, "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(opj_optarg, "%d,%d", ¶meters->cp_tx0, ¶meters->cp_ty0) != 2) {
- fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
- return 1;
- }
- }
- break;
-
- /* ------------------------------------------------------ */
-
- case 'C': /* add a comment */
- {
- parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
- if(parameters->cp_comment) {
- strcpy(parameters->cp_comment, opj_optarg);
- }
- }
- break;
-
-
- /* ------------------------------------------------------ */
-
- case 'I': /* reversible or not */
- {
- parameters->irreversible = 1;
- }
- break;
-
- /* ------------------------------------------------------ */
-
- case 'u': /* Tile part generation*/
- {
- parameters->tp_flag = opj_optarg[0];
- parameters->tp_on = 1;
- }
- break;
-
- /* ------------------------------------------------------ */
-
- case 'z': /* Image Directory path */
- {
- img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
- strcpy(img_fol->imgdirpath,opj_optarg);
- img_fol->set_imgdir=1;
- }
- break;
-
- /* ------------------------------------------------------ */
-
- case 'w': /* Digital Cinema 2K profile compliance*/
- {
- int fps=0;
- sscanf(opj_optarg,"%d",&fps);
- if(fps == 24){
- parameters->cp_cinema = CINEMA2K_24;
- }else if(fps == 48 ){
- parameters->cp_cinema = CINEMA2K_48;
- }else {
- fprintf(stderr,"Incorrect value!! must be 24 or 48\n");
- return 1;
- }
- fprintf(stdout,"CINEMA 2K compliant codestream\n");
- parameters->cp_rsiz = CINEMA2K;
-
- }
- break;
-
- /* ------------------------------------------------------ */
-
- case 'y': /* Digital Cinema 4K profile compliance*/
- {
- parameters->cp_cinema = CINEMA4K_24;
- fprintf(stdout,"CINEMA 4K compliant codestream\n");
- parameters->cp_rsiz = CINEMA4K;
- }
- break;
-
- /* ------------------------------------------------------ */
- case 'm': /* mct input file */
- {
- char *lFilename = opj_optarg;
- char *lMatrix;
- char *lCurrentPtr ;
- float *lCurrentDoublePtr;
- float *lSpace;
- int *l_int_ptr;
- int lNbComp = 0, lTotalComp, lMctComp, i, lStrLen;
-
- /* Open file */
- FILE * lFile = fopen(lFilename,"r");
- if (lFile == NULL) {
- return 1;
- }
-
- /* Set size of file and read its content*/
- fseek(lFile,0,SEEK_END);
- lStrLen = ftell(lFile);
- fseek(lFile,0,SEEK_SET);
- lMatrix = (char *) malloc(lStrLen + 1);
- fread(lMatrix, lStrLen, 1, lFile);
- fclose(lFile);
-
- lMatrix[lStrLen] = 0;
- lCurrentPtr = lMatrix;
-
- /* replace ',' by 0 */
- while (*lCurrentPtr != 0 ) {
- if (*lCurrentPtr == ' ') {
- *lCurrentPtr = 0;
- ++lNbComp;
- }
- ++lCurrentPtr;
- }
- ++lNbComp;
- lCurrentPtr = lMatrix;
-
- lNbComp = (int) (sqrt(4*lNbComp + 1)/2. - 0.5);
- lMctComp = lNbComp * lNbComp;
- lTotalComp = lMctComp + lNbComp;
- lSpace = (float *) malloc(lTotalComp * sizeof(float));
- lCurrentDoublePtr = lSpace;
- for (i=0;i<lMctComp;++i) {
- lStrLen = strlen(lCurrentPtr) + 1;
- *lCurrentDoublePtr++ = (float) atof(lCurrentPtr);
- lCurrentPtr += lStrLen;
- }
-
- l_int_ptr = (int*) lCurrentDoublePtr;
- for (i=0;i<lNbComp;++i) {
- lStrLen = strlen(lCurrentPtr) + 1;
- *l_int_ptr++ = atoi(lCurrentPtr);
- lCurrentPtr += lStrLen;
- }
-
- /* TODO should not be here ! */
- opj_set_MCT(parameters, lSpace, (int *)(lSpace + lMctComp), lNbComp);
-
- /* Free memory*/
- free(lSpace);
- free(lMatrix);
- }
- break;
-
-
- /* ------------------------------------------------------ */
-
-/* UniPG>> */
+ strncpy(progression, opj_optarg, 4);
+ parameters->prog_order = give_progression(progression);
+ if (parameters->prog_order == -1) {
+ fprintf(stderr, "Unrecognized progression order "
+ "[LRCP, RLCP, RPCL, PCRL, CPRL] !!\n");
+ return 1;
+ }
+ }
+ break;
+
+ /* ----------------------------------------------------- */
+
+ case 's': { /* subsampling factor */
+ if (sscanf(opj_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(opj_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 */
+ int numpocs = 0; /* number of progression order change (POC) default 0 */
+ opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
+
+ char *s = opj_optarg;
+ POC = parameters->POC;
+
+ while (sscanf(s, "T%u=%u,%u,%u,%u,%u,%4s", &POC[numpocs].tile,
+ &POC[numpocs].resno0, &POC[numpocs].compno0,
+ &POC[numpocs].layno1, &POC[numpocs].resno1,
+ &POC[numpocs].compno1, POC[numpocs].progorder) == 7) {
+ POC[numpocs].prg1 = give_progression(POC[numpocs].progorder);
+ numpocs++;
+ while (*s && *s != '/') {
+ s++;
+ }
+ if (!*s) {
+ break;
+ }
+ s++;
+ }
+ parameters->numpocs = (OPJ_UINT32)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;
+ if (sscanf(opj_optarg, "%d", &value) == 1) {
+ for (i = 0; i <= 5; i++) {
+ int cache = value & (1 << i);
+ if (cache) {
+ parameters->mode |= (1 << i);
+ }
+ }
+ }
+ }
+ break;
+
+ /* ------------------------------------------------------ */
+
+ case 'R': { /* ROI */
+ if (sscanf(opj_optarg, "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(opj_optarg, "%d,%d", ¶meters->cp_tx0,
+ ¶meters->cp_ty0) != 2) {
+ fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
+ return 1;
+ }
+ }
+ break;
+
+ /* ------------------------------------------------------ */
+
+ case 'C': { /* add a comment */
+ parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
+ if (parameters->cp_comment) {
+ strcpy(parameters->cp_comment, opj_optarg);
+ }
+ }
+ break;
+
+
+ /* ------------------------------------------------------ */
+
+ case 'I': { /* reversible or not */
+ parameters->irreversible = 1;
+ }
+ break;
+
+ /* ------------------------------------------------------ */
+
+ case 'u': { /* Tile part generation*/
+ parameters->tp_flag = opj_optarg[0];
+ parameters->tp_on = 1;
+ }
+ break;
+
+ /* ------------------------------------------------------ */
+
+ case 'z': { /* Image Directory path */
+ img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
+ if (img_fol->imgdirpath == NULL) {
+ return 1;
+ }
+ strcpy(img_fol->imgdirpath, opj_optarg);
+ img_fol->set_imgdir = 1;
+ }
+ break;
+
+ /* ------------------------------------------------------ */
+
+ case 'w': { /* Digital Cinema 2K profile compliance*/
+ int fps = 0;
+ sscanf(opj_optarg, "%d", &fps);
+ if (fps == 24) {
+ parameters->rsiz = OPJ_PROFILE_CINEMA_2K;
+ parameters->max_comp_size = OPJ_CINEMA_24_COMP;
+ parameters->max_cs_size = OPJ_CINEMA_24_CS;
+ } else if (fps == 48) {
+ parameters->rsiz = OPJ_PROFILE_CINEMA_2K;
+ parameters->max_comp_size = OPJ_CINEMA_48_COMP;
+ parameters->max_cs_size = OPJ_CINEMA_48_CS;
+ } else {
+ fprintf(stderr, "Incorrect value!! must be 24 or 48\n");
+ return 1;
+ }
+ fprintf(stdout, "CINEMA 2K profile activated\n"
+ "Other options specified could be overridden\n");
+
+ }
+ break;
+
+ /* ------------------------------------------------------ */
+
+ case 'y': { /* Digital Cinema 4K profile compliance*/
+ parameters->rsiz = OPJ_PROFILE_CINEMA_4K;
+ fprintf(stdout, "CINEMA 4K profile activated\n"
+ "Other options specified could be overridden\n");
+ }
+ break;
+
+ /* ------------------------------------------------------ */
+
+ case 'Z': { /* IMF profile*/
+ int mainlevel = 0;
+ int sublevel = 0;
+ int profile = 0;
+ int framerate = 0;
+ const char* msg =
+ "Wrong value for -IMF. Should be "
+ "<PROFILE>[,mainlevel=X][,sublevel=Y][,framerate=FPS] where <PROFILE> is one "
+ "of 2K/4K/8K/2K_R/4K_R/8K_R.\n";
+ char* comma;
+
+ comma = strstr(opj_optarg, ",mainlevel=");
+ if (comma && sscanf(comma + 1, "mainlevel=%d", &mainlevel) != 1) {
+ fprintf(stderr, "%s", msg);
+ return 1;
+ }
+
+ comma = strstr(opj_optarg, ",sublevel=");
+ if (comma && sscanf(comma + 1, "sublevel=%d", &sublevel) != 1) {
+ fprintf(stderr, "%s", msg);
+ return 1;
+ }
+
+ comma = strstr(opj_optarg, ",framerate=");
+ if (comma && sscanf(comma + 1, "framerate=%d", &framerate) != 1) {
+ fprintf(stderr, "%s", msg);
+ return 1;
+ }
+
+ comma = strchr(opj_optarg, ',');
+ if (comma != NULL) {
+ *comma = 0;
+ }
+
+ if (strcmp(opj_optarg, "2K") == 0) {
+ profile = OPJ_PROFILE_IMF_2K;
+ } else if (strcmp(opj_optarg, "4K") == 0) {
+ profile = OPJ_PROFILE_IMF_4K;
+ } else if (strcmp(opj_optarg, "8K") == 0) {
+ profile = OPJ_PROFILE_IMF_8K;
+ } else if (strcmp(opj_optarg, "2K_R") == 0) {
+ profile = OPJ_PROFILE_IMF_2K_R;
+ } else if (strcmp(opj_optarg, "4K_R") == 0) {
+ profile = OPJ_PROFILE_IMF_4K_R;
+ } else if (strcmp(opj_optarg, "8K_R") == 0) {
+ profile = OPJ_PROFILE_IMF_8K_R;
+ } else {
+ fprintf(stderr, "%s", msg);
+ return 1;
+ }
+
+ if (!(mainlevel >= 0 && mainlevel <= 15)) {
+ /* Voluntarily rough validation. More fine grained done in library */
+ fprintf(stderr, "Invalid mainlevel value.\n");
+ return 1;
+ }
+ if (!(sublevel >= 0 && sublevel <= 15)) {
+ /* Voluntarily rough validation. More fine grained done in library */
+ fprintf(stderr, "Invalid sublevel value.\n");
+ return 1;
+ }
+ parameters->rsiz = (OPJ_UINT16)(profile | (sublevel << 4) | mainlevel);
+
+ fprintf(stdout, "IMF profile activated\n"
+ "Other options specified could be overridden\n");
+
+ if (pOutFramerate) {
+ *pOutFramerate = framerate;
+ }
+ if (framerate > 0 && sublevel > 0 && sublevel <= 9) {
+ const int limitMBitsSec[] = {
+ 0,
+ OPJ_IMF_SUBLEVEL_1_MBITSSEC,
+ OPJ_IMF_SUBLEVEL_2_MBITSSEC,
+ OPJ_IMF_SUBLEVEL_3_MBITSSEC,
+ OPJ_IMF_SUBLEVEL_4_MBITSSEC,
+ OPJ_IMF_SUBLEVEL_5_MBITSSEC,
+ OPJ_IMF_SUBLEVEL_6_MBITSSEC,
+ OPJ_IMF_SUBLEVEL_7_MBITSSEC,
+ OPJ_IMF_SUBLEVEL_8_MBITSSEC,
+ OPJ_IMF_SUBLEVEL_9_MBITSSEC
+ };
+ parameters->max_cs_size = limitMBitsSec[sublevel] * (1000 * 1000 / 8) /
+ framerate;
+ fprintf(stdout, "Setting max codestream size to %d bytes.\n",
+ parameters->max_cs_size);
+ }
+ }
+ break;
+
+ /* ------------------------------------------------------ */
+
+ case 'Y': { /* Shall we do an MCT ? 0:no_mct;1:rgb->ycc;2:custom mct (-m option required)*/
+ int mct_mode = 0;
+ sscanf(opj_optarg, "%d", &mct_mode);
+ if (mct_mode < 0 || mct_mode > 2) {
+ fprintf(stderr,
+ "MCT incorrect value!! Current accepted values are 0, 1 or 2.\n");
+ return 1;
+ }
+ parameters->tcp_mct = (char) mct_mode;
+ }
+ break;
+
+ /* ------------------------------------------------------ */
+
+
+ case 'm': { /* mct input file */
+ char *lFilename = opj_optarg;
+ char *lMatrix;
+ char *lCurrentPtr ;
+ float *lCurrentDoublePtr;
+ float *lSpace;
+ int *l_int_ptr;
+ int lNbComp = 0, lTotalComp, lMctComp, i2;
+ size_t lStrLen, lStrFread;
+
+ /* Open file */
+ FILE * lFile = fopen(lFilename, "r");
+ if (lFile == NULL) {
+ return 1;
+ }
+
+ /* Set size of file and read its content*/
+ fseek(lFile, 0, SEEK_END);
+ lStrLen = (size_t)ftell(lFile);
+ fseek(lFile, 0, SEEK_SET);
+ lMatrix = (char *) malloc(lStrLen + 1);
+ if (lMatrix == NULL) {
+ fclose(lFile);
+ return 1;
+ }
+ lStrFread = fread(lMatrix, 1, lStrLen, lFile);
+ fclose(lFile);
+ if (lStrLen != lStrFread) {
+ free(lMatrix);
+ return 1;
+ }
+
+ lMatrix[lStrLen] = 0;
+ lCurrentPtr = lMatrix;
+
+ /* replace ',' by 0 */
+ while (*lCurrentPtr != 0) {
+ if (*lCurrentPtr == ' ') {
+ *lCurrentPtr = 0;
+ ++lNbComp;
+ }
+ ++lCurrentPtr;
+ }
+ ++lNbComp;
+ lCurrentPtr = lMatrix;
+
+ lNbComp = (int)(sqrt(4 * lNbComp + 1) / 2. - 0.5);
+ lMctComp = lNbComp * lNbComp;
+ lTotalComp = lMctComp + lNbComp;
+ lSpace = (float *) malloc((size_t)lTotalComp * sizeof(float));
+ if (lSpace == NULL) {
+ free(lMatrix);
+ return 1;
+ }
+ lCurrentDoublePtr = lSpace;
+ for (i2 = 0; i2 < lMctComp; ++i2) {
+ lStrLen = strlen(lCurrentPtr) + 1;
+ *lCurrentDoublePtr++ = (float) atof(lCurrentPtr);
+ lCurrentPtr += lStrLen;
+ }
+
+ l_int_ptr = (int*) lCurrentDoublePtr;
+ for (i2 = 0; i2 < lNbComp; ++i2) {
+ lStrLen = strlen(lCurrentPtr) + 1;
+ *l_int_ptr++ = atoi(lCurrentPtr);
+ lCurrentPtr += lStrLen;
+ }
+
+ /* TODO should not be here ! */
+ opj_set_MCT(parameters, lSpace, (int *)(lSpace + lMctComp),
+ (OPJ_UINT32)lNbComp);
+
+ /* Free memory*/
+ free(lSpace);
+ free(lMatrix);
+ }
+ break;
+
+
+ /* ------------------------------------------------------ */
+
+ /* UniPG>> */