+
+ for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
+ int start_pos, end_ph_pos, end_pos;
+ double disto = 0;
+ int max_numdecompos = 0;
+ pack_nb = 0;
+
+ for (compno = 0; compno < cstr_info->numcomps; compno++) {
+ if (max_numdecompos < cstr_info->numdecompos[compno])
+ max_numdecompos = cstr_info->numdecompos[compno];
+ }
+
+ fprintf(stream, "\nTILE %d DETAILS\n", tileno);
+ fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n");
+ for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++)
+ fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\n",
+ tilepartno, tileno,
+ cstr_info->tile[tileno].tp[tilepartno].tp_start_pack,
+ cstr_info->tile[tileno].tp[tilepartno].tp_numpacks,
+ cstr_info->tile[tileno].tp[tilepartno].tp_start_pos,
+ cstr_info->tile[tileno].tp[tilepartno].tp_end_header,
+ cstr_info->tile[tileno].tp[tilepartno].tp_end_pos
+ );
+ if (cstr_info->prog == LRCP) { /* LRCP */
+ fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos disto\n");
+
+ for (layno = 0; layno < cstr_info->numlayers; layno++) {
+ for (resno = 0; resno < max_numdecompos + 1; resno++) {
+ for (compno = 0; compno < cstr_info->numcomps; compno++) {
+ int prec_max;
+ if (resno > cstr_info->numdecompos[compno])
+ break;
+ prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
+ for (precno = 0; precno < prec_max; precno++) {
+ start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
+ end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
+ end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
+ disto = cstr_info->tile[tileno].packet[pack_nb].disto;
+ fprintf(stream, "%4d %6d %7d %5d %6d %6d %6d %6d %7d %8e\n",
+ pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos, disto);
+ total_disto += disto;
+ pack_nb++;
+ }
+ }
+ }
+ }
+ } /* LRCP */
+ else if (cstr_info->prog == RLCP) { /* RLCP */
+
+ fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos disto\n");
+
+ for (resno = 0; resno < max_numdecompos + 1; resno++) {
+ for (layno = 0; layno < cstr_info->numlayers; layno++) {
+ for (compno = 0; compno < cstr_info->numcomps; compno++) {
+ int prec_max;
+ if (resno > cstr_info->numdecompos[compno])
+ break;
+ prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
+ for (precno = 0; precno < prec_max; precno++) {
+ start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
+ end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
+ end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
+ disto = cstr_info->tile[tileno].packet[pack_nb].disto;
+ fprintf(stream, "%4d %6d %5d %7d %6d %6d %9d %9d %7d %8e\n",
+ pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos, disto);
+ total_disto += disto;
+ pack_nb++;
+ }
+ }
+ }
+ }
+ } /* RLCP */
+ else if (cstr_info->prog == RPCL) { /* RPCL */
+
+ fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos disto\n");
+
+ for (resno = 0; resno < max_numdecompos + 1; resno++) {
+ /* I suppose components have same XRsiz, YRsiz */
+ int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
+ int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
+ int x1 = x0 + cstr_info->tile_x;
+ int y1 = y0 + cstr_info->tile_y;
+ for (compno = 0; compno < cstr_info->numcomps; compno++) {
+ int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
+ if (resno > cstr_info->numdecompos[compno])
+ break;
+ for (precno = 0; precno < prec_max; precno++) {
+ int pcnx = cstr_info->tile[tileno].pw[resno];
+ int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );
+ int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );
+ int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
+ int precno_y = (int) floor( (float)precno/(float)pcnx );
+ for(y = y0; y < y1; y++) {
+ if (precno_y*pcy == y ) {
+ for (x = x0; x < x1; x++) {
+ if (precno_x*pcx == x ) {
+ for (layno = 0; layno < cstr_info->numlayers; layno++) {
+ start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
+ end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
+ end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
+ disto = cstr_info->tile[tileno].packet[pack_nb].disto;
+ fprintf(stream, "%4d %6d %5d %6d %6d %7d %9d %9d %7d %8e\n",
+ pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos, disto);
+ total_disto += disto;
+ pack_nb++;
+ }
+ }
+ }/* x = x0..x1 */
+ }
+ } /* y = y0..y1 */
+ } /* precno */
+ } /* compno */
+ } /* resno */
+ } /* RPCL */
+ else if (cstr_info->prog == PCRL) { /* PCRL */
+ /* I suppose components have same XRsiz, YRsiz */
+ int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
+ int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
+ int x1 = x0 + cstr_info->tile_x;
+ int y1 = y0 + cstr_info->tile_y;
+
+ fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos disto\n");
+
+ for (compno = 0; compno < cstr_info->numcomps; compno++) {
+ for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) {
+ int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
+ for (precno = 0; precno < prec_max; precno++) {
+ int pcnx = cstr_info->tile[tileno].pw[resno];
+ int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );
+ int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );
+ int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
+ int precno_y = (int) floor( (float)precno/(float)pcnx );
+ for(y = y0; y < y1; y++) {
+ if (precno_y*pcy == y ) {
+ for (x = x0; x < x1; x++) {
+ if (precno_x*pcx == x ) {
+ for (layno = 0; layno < cstr_info->numlayers; layno++) {
+ start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
+ end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
+ end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
+ disto = cstr_info->tile[tileno].packet[pack_nb].disto;
+ fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %7d %8e\n",
+ pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos, disto);
+ total_disto += disto;
+ pack_nb++;
+ }
+ }
+ }/* x = x0..x1 */
+ }
+ } /* y = y0..y1 */
+ } /* precno */
+ } /* resno */
+ } /* compno */
+ } /* PCRL */
+ else { /* CPRL */
+
+ fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos disto\n");
+
+ for (compno = 0; compno < cstr_info->numcomps; compno++) {
+ /* I suppose components have same XRsiz, YRsiz */
+ int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
+ int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
+ int x1 = x0 + cstr_info->tile_x;
+ int y1 = y0 + cstr_info->tile_y;
+
+ for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) {
+ int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
+ for (precno = 0; precno < prec_max; precno++) {
+ int pcnx = cstr_info->tile[tileno].pw[resno];
+ int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );
+ int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );
+ int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
+ int precno_y = (int) floor( (float)precno/(float)pcnx );
+ for(y = y0; y < y1; y++) {
+ if (precno_y*pcy == y ) {
+ for (x = x0; x < x1; x++) {
+ if (precno_x*pcx == x ) {
+ for (layno = 0; layno < cstr_info->numlayers; layno++) {
+ start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
+ end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
+ end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
+ disto = cstr_info->tile[tileno].packet[pack_nb].disto;
+ fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %7d %8e\n",
+ pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos, disto);
+ total_disto += disto;
+ pack_nb++;
+ }
+ }
+ }/* x = x0..x1 */
+ }
+ } /* y = y0..y1 */
+ } /* precno */
+ } /* resno */
+ } /* compno */
+ } /* CPRL */
+ } /* tileno */
+
+ fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
+ fprintf(stream, "%.8e\n", total_disto); /* SE totale */
+/* UniPG>> */
+ /* print the markers' list */
+ fprintf(stream, "\nMARKER LIST\n");
+ fprintf(stream, "%d\n", cstr_info->marknum);
+ fprintf(stream, "type\tstart_pos length\n");
+ for (x = 0; x < cstr_info->marknum; x++)
+ fprintf(stream, "%X\t%9d %9d\n", cstr_info->marker[x].type, cstr_info->marker[x].pos, cstr_info->marker[x].len);
+/* <<UniPG */
+ fclose(stream);
+
+ fprintf(stderr,"Generated index file %s\n", index);
+
+ return 0;
+}
+
+/* ------------------------------------------------------------------------------------ */
+
+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;
+ option_t long_option[]={
+ {"cinema2K",REQ_ARG, NULL ,'w'},
+ {"cinema4K",NO_ARG, NULL ,'y'},
+ {"ImgDir",REQ_ARG, NULL ,'z'},
+ {"TP",REQ_ARG, NULL ,'v'},
+ {"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'},
+ };
+
+ /* parse the command line */
+ const char optlist[] = "i:o:hr:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:"
+#ifdef USE_JPWL
+ "W:"
+#endif /* USE_JPWL */
+ ;
+
+ totlen=sizeof(long_option);
+ img_fol->set_out_format=0;
+ raw_cp->rawWidth = 0;
+
+ while (1) {
+ int c = getopt_long(argc, argv, optlist,long_option,totlen);
+ if (c == -1)
+ break;
+ switch (c) {
+ case 'i': /* input file */
+ {
+ char *infile = 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 TGA_DFMT:
+ break;
+ default:
+ fprintf(stderr,
+ "!! Unrecognized format for infile : %s "
+ "[accept only *.pnm, *.pgm, *.ppm, *.pgx, *.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 = 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 = 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 = optarg;
+ break;
+ default:
+ fprintf(stderr, "Unknown output format image [only j2k, j2c, jp2]!! \n");
+ return 1;
+ }
+ }
+ break;
+
+
+ /* ----------------------------------------------------- */
+
+
+ case 'r': /* rates rates/distorsion */
+ {
+ char *s = optarg;
+ 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 = 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 = 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 = 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 = 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 = 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(optarg, "%d,%d", ¶meters->cp_tdx, ¶meters->cp_tdy);
+ parameters->tile_size_on = true;
+ }
+ break;
+
+ /* ----------------------------------------------------- */
+
+ case 'n': /* resolution */
+ {
+ sscanf(optarg, "%d", ¶meters->numresolution);
+ }
+ break;
+
+ /* ----------------------------------------------------- */
+ case 'c': /* precinct dimension */
+ {
+ char sep;
+ int res_spec = 0;
+
+ char *s = 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(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 = optarg;
+ strncpy(indexfilename, index, OPJ_PATH_LEN);
+ }
+ break;
+
+ /* ----------------------------------------------------- */
+
+ case 'p': /* progression order */
+ {
+ char progression[4];
+
+ 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");
+ return 1;
+ }
+ }
+ break;
+
+ /* ----------------------------------------------------- */
+
+ case 's': /* subsampling factor */
+ {
+ 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");
+ 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 = 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(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(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(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(optarg) + 1);
+ if(parameters->cp_comment) {
+ strcpy(parameters->cp_comment, optarg);
+ }
+ }
+ break;
+
+
+ /* ------------------------------------------------------ */
+
+ case 'I': /* reversible or not */
+ {
+ parameters->irreversible = 1;
+ }
+ break;
+
+ /* ------------------------------------------------------ */
+
+ case 'v': /* Tile part generation*/
+ {
+ parameters->tp_flag = optarg[0];
+ parameters->tp_on = 1;
+ }
+ break;
+
+ /* ------------------------------------------------------ */
+
+ case 'z': /* Image Directory path */
+ {
+ img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);
+ strcpy(img_fol->imgdirpath,optarg);
+ img_fol->set_imgdir=1;
+ }
+ break;
+
+ /* ------------------------------------------------------ */
+
+ case 'w': /* Digital Cinema 2K profile compliance*/
+ {
+ int fps=0;
+ sscanf(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;
+
+ /* ------------------------------------------------------ */
+
+/* UniPG>> */
+#ifdef USE_JPWL
+ /* ------------------------------------------------------ */
+
+ case 'W': /* JPWL capabilities switched on */
+ {
+ char *token = NULL;
+ int hprot, pprot, sens, addr, size, range;
+
+ /* we need to enable indexing */
+ if (!indexfilename) {
+ strncpy(indexfilename, JPWL_PRIVATEINDEX_NAME, OPJ_PATH_LEN);
+ }
+
+ /* search for different protection methods */
+
+ /* break the option in comma points and parse the result */
+ token = strtok(optarg, ",");
+ while(token != NULL) {
+
+ /* search header error protection method */
+ if (*token == 'h') {
+
+ static int tile = 0, tilespec = 0, lasttileno = 0;
+
+ hprot = 1; /* predefined method */
+
+ if(sscanf(token, "h=%d", &hprot) == 1) {
+ /* Main header, specified */
+ if (!((hprot == 0) || (hprot == 1) || (hprot == 16) || (hprot == 32) ||
+ ((hprot >= 37) && (hprot <= 128)))) {
+ fprintf(stderr, "ERROR -> invalid main header protection method h = %d\n", hprot);
+ return 1;
+ }
+ parameters->jpwl_hprot_MH = hprot;
+
+ } else if(sscanf(token, "h%d=%d", &tile, &hprot) == 2) {
+ /* Tile part header, specified */
+ if (!((hprot == 0) || (hprot == 1) || (hprot == 16) || (hprot == 32) ||
+ ((hprot >= 37) && (hprot <= 128)))) {
+ fprintf(stderr, "ERROR -> invalid tile part header protection method h = %d\n", hprot);
+ return 1;
+ }
+ if (tile < 0) {
+ fprintf(stderr, "ERROR -> invalid tile part number on protection method t = %d\n", tile);
+ return 1;
+ }
+ if (tilespec < JPWL_MAX_NO_TILESPECS) {
+ parameters->jpwl_hprot_TPH_tileno[tilespec] = lasttileno = tile;
+ parameters->jpwl_hprot_TPH[tilespec++] = hprot;
+ }
+
+ } else if(sscanf(token, "h%d", &tile) == 1) {
+ /* Tile part header, unspecified */
+ if (tile < 0) {
+ fprintf(stderr, "ERROR -> invalid tile part number on protection method t = %d\n", tile);
+ return 1;
+ }
+ if (tilespec < JPWL_MAX_NO_TILESPECS) {
+ parameters->jpwl_hprot_TPH_tileno[tilespec] = lasttileno = tile;
+ parameters->jpwl_hprot_TPH[tilespec++] = hprot;
+ }
+
+
+ } else if (!strcmp(token, "h")) {
+ /* Main header, unspecified */
+ parameters->jpwl_hprot_MH = hprot;
+
+ } else {
+ fprintf(stderr, "ERROR -> invalid protection method selection = %s\n", token);
+ return 1;
+ };
+
+ }
+
+ /* search packet error protection method */
+ if (*token == 'p') {
+
+ static int pack = 0, tile = 0, packspec = 0, lastpackno = 0;
+
+ pprot = 1; /* predefined method */
+
+ if (sscanf(token, "p=%d", &pprot) == 1) {
+ /* Method for all tiles and all packets */
+ if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) ||
+ ((pprot >= 37) && (pprot <= 128)))) {
+ fprintf(stderr, "ERROR -> invalid default packet protection method p = %d\n", pprot);
+ return 1;
+ }
+ parameters->jpwl_pprot_tileno[0] = 0;
+ parameters->jpwl_pprot_packno[0] = 0;
+ parameters->jpwl_pprot[0] = pprot;
+
+ } else if (sscanf(token, "p%d=%d", &tile, &pprot) == 2) {
+ /* method specified from that tile on */
+ if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) ||
+ ((pprot >= 37) && (pprot <= 128)))) {
+ fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot);
+ return 1;
+ }
+ if (tile < 0) {
+ fprintf(stderr, "ERROR -> invalid tile part number on protection method p = %d\n", tile);
+ return 1;
+ }
+ if (packspec < JPWL_MAX_NO_PACKSPECS) {
+ parameters->jpwl_pprot_tileno[packspec] = tile;
+ parameters->jpwl_pprot_packno[packspec] = 0;
+ parameters->jpwl_pprot[packspec++] = pprot;
+ }
+
+ } else if (sscanf(token, "p%d:%d=%d", &tile, &pack, &pprot) == 3) {
+ /* method fully specified from that tile and that packet on */
+ if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) ||
+ ((pprot >= 37) && (pprot <= 128)))) {
+ fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot);
+ return 1;
+ }
+ if (tile < 0) {
+ fprintf(stderr, "ERROR -> invalid tile part number on protection method p = %d\n", tile);
+ return 1;
+ }
+ if (pack < 0) {
+ fprintf(stderr, "ERROR -> invalid packet number on protection method p = %d\n", pack);
+ return 1;
+ }
+ if (packspec < JPWL_MAX_NO_PACKSPECS) {
+ parameters->jpwl_pprot_tileno[packspec] = tile;
+ parameters->jpwl_pprot_packno[packspec] = pack;
+ parameters->jpwl_pprot[packspec++] = pprot;
+ }
+
+ } else if (sscanf(token, "p%d:%d", &tile, &pack) == 2) {
+ /* default method from that tile and that packet on */
+ if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) ||
+ ((pprot >= 37) && (pprot <= 128)))) {
+ fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot);
+ return 1;
+ }
+ if (tile < 0) {
+ fprintf(stderr, "ERROR -> invalid tile part number on protection method p = %d\n", tile);
+ return 1;
+ }
+ if (pack < 0) {
+ fprintf(stderr, "ERROR -> invalid packet number on protection method p = %d\n", pack);
+ return 1;
+ }
+ if (packspec < JPWL_MAX_NO_PACKSPECS) {
+ parameters->jpwl_pprot_tileno[packspec] = tile;
+ parameters->jpwl_pprot_packno[packspec] = pack;
+ parameters->jpwl_pprot[packspec++] = pprot;
+ }
+
+ } else if (sscanf(token, "p%d", &tile) == 1) {
+ /* default from a tile on */
+ if (tile < 0) {
+ fprintf(stderr, "ERROR -> invalid tile part number on protection method p = %d\n", tile);
+ return 1;
+ }
+ if (packspec < JPWL_MAX_NO_PACKSPECS) {
+ parameters->jpwl_pprot_tileno[packspec] = tile;
+ parameters->jpwl_pprot_packno[packspec] = 0;
+ parameters->jpwl_pprot[packspec++] = pprot;
+ }
+
+
+ } else if (!strcmp(token, "p")) {
+ /* all default */
+ parameters->jpwl_pprot_tileno[0] = 0;
+ parameters->jpwl_pprot_packno[0] = 0;
+ parameters->jpwl_pprot[0] = pprot;
+
+ } else {
+ fprintf(stderr, "ERROR -> invalid protection method selection = %s\n", token);
+ return 1;
+ };
+
+ }
+
+ /* search sensitivity method */
+ if (*token == 's') {
+
+ static int tile = 0, tilespec = 0, lasttileno = 0;
+
+ sens = 0; /* predefined: relative error */
+
+ if(sscanf(token, "s=%d", &sens) == 1) {
+ /* Main header, specified */
+ if ((sens < -1) || (sens > 7)) {
+ fprintf(stderr, "ERROR -> invalid main header sensitivity method s = %d\n", sens);
+ return 1;
+ }
+ parameters->jpwl_sens_MH = sens;
+
+ } else if(sscanf(token, "s%d=%d", &tile, &sens) == 2) {
+ /* Tile part header, specified */
+ if ((sens < -1) || (sens > 7)) {
+ fprintf(stderr, "ERROR -> invalid tile part header sensitivity method s = %d\n", sens);
+ return 1;
+ }
+ if (tile < 0) {
+ fprintf(stderr, "ERROR -> invalid tile part number on sensitivity method t = %d\n", tile);
+ return 1;
+ }
+ if (tilespec < JPWL_MAX_NO_TILESPECS) {
+ parameters->jpwl_sens_TPH_tileno[tilespec] = lasttileno = tile;
+ parameters->jpwl_sens_TPH[tilespec++] = sens;
+ }
+
+ } else if(sscanf(token, "s%d", &tile) == 1) {
+ /* Tile part header, unspecified */
+ if (tile < 0) {
+ fprintf(stderr, "ERROR -> invalid tile part number on sensitivity method t = %d\n", tile);
+ return 1;
+ }
+ if (tilespec < JPWL_MAX_NO_TILESPECS) {
+ parameters->jpwl_sens_TPH_tileno[tilespec] = lasttileno = tile;
+ parameters->jpwl_sens_TPH[tilespec++] = hprot;
+ }
+
+ } else if (!strcmp(token, "s")) {
+ /* Main header, unspecified */
+ parameters->jpwl_sens_MH = sens;
+
+ } else {
+ fprintf(stderr, "ERROR -> invalid sensitivity method selection = %s\n", token);
+ return 1;
+ };
+
+ parameters->jpwl_sens_size = 2; /* 2 bytes for default size */
+ }
+
+ /* search addressing size */
+ if (*token == 'a') {
+
+ static int tile = 0, tilespec = 0, lasttileno = 0;
+
+ addr = 0; /* predefined: auto */
+
+ if(sscanf(token, "a=%d", &addr) == 1) {
+ /* Specified */
+ if ((addr != 0) && (addr != 2) && (addr != 4)) {
+ fprintf(stderr, "ERROR -> invalid addressing size a = %d\n", addr);
+ return 1;
+ }
+ parameters->jpwl_sens_addr = addr;
+
+ } else if (!strcmp(token, "a")) {
+ /* default */
+ parameters->jpwl_sens_addr = addr; /* auto for default size */
+
+ } else {
+ fprintf(stderr, "ERROR -> invalid addressing selection = %s\n", token);
+ return 1;
+ };
+
+ }
+
+ /* search sensitivity size */
+ if (*token == 'z') {
+
+ static int tile = 0, tilespec = 0, lasttileno = 0;
+
+ size = 1; /* predefined: 1 byte */
+
+ if(sscanf(token, "z=%d", &size) == 1) {
+ /* Specified */
+ if ((size != 0) && (size != 1) && (size != 2)) {
+ fprintf(stderr, "ERROR -> invalid sensitivity size z = %d\n", size);
+ return 1;
+ }
+ parameters->jpwl_sens_size = size;
+
+ } else if (!strcmp(token, "a")) {
+ /* default */
+ parameters->jpwl_sens_size = size; /* 1 for default size */
+
+ } else {
+ fprintf(stderr, "ERROR -> invalid size selection = %s\n", token);
+ return 1;
+ };
+
+ }
+
+ /* search range method */
+ if (*token == 'g') {
+
+ static int tile = 0, tilespec = 0, lasttileno = 0;
+
+ range = 0; /* predefined: 0 (packet) */
+
+ if(sscanf(token, "g=%d", &range) == 1) {
+ /* Specified */
+ if ((range < 0) || (range > 3)) {
+ fprintf(stderr, "ERROR -> invalid sensitivity range method g = %d\n", range);
+ return 1;
+ }
+ parameters->jpwl_sens_range = range;
+
+ } else if (!strcmp(token, "g")) {
+ /* default */
+ parameters->jpwl_sens_range = range;
+
+ } else {
+ fprintf(stderr, "ERROR -> invalid range selection = %s\n", token);
+ return 1;
+ };
+
+ }
+
+ /* next token or bust */
+ token = strtok(NULL, ",");
+ };
+
+
+ /* some info */
+ fprintf(stdout, "Info: JPWL capabilities enabled\n");
+ parameters->jpwl_epc_on = true;
+
+ }
+ break;
+#endif /* USE_JPWL */
+/* <<UniPG */
+
+ /* ------------------------------------------------------ */
+
+ default:
+ fprintf(stderr, "ERROR -> Command line not valid\n");
+ return 1;
+ }