#include "opj_config.h"
#include "openjpeg.h"
-#include "getopt.h"
+#include "opj_getopt.h"
#include "convert.h"
#include "index.h"
float *rates;
}img_fol_t;
-void encode_help_display() {
+void encode_help_display(void) {
fprintf(stdout,"HELP for image_to_j2k\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
fprintf(stdout," -F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n");
fprintf(stdout," Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n");
fprintf(stdout,"\n");
+ fprintf(stdout,"-jpip : write jpip codestream index box in JP2 output file\n");
+ fprintf(stdout," NOTICE: currently supports only RPCL order\n");
+ fprintf(stdout,"\n");
/* UniPG>> */
#ifdef USE_JPWL
fprintf(stdout,"-W : adoption of JPWL (Part 11) capabilities (-W params)\n");
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[]={
+ 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'},
{"OutFor",REQ_ARG, NULL ,'O'},
{"POC",REQ_ARG, NULL ,'P'},
{"ROI",REQ_ARG, NULL ,'R'},
+ {"jpip",NO_ARG, NULL, 'J'}
};
/* parse the command line */
img_fol->set_out_format=0;
raw_cp->rawWidth = 0;
- while (1) {
- int c = getopt_long(argc, argv, optlist,long_option,totlen);
+ do{
+ c = opj_getopt_long(argc, argv, optlist,long_option,totlen);
if (c == -1)
break;
switch (c) {
case 'i': /* input file */
{
- char *infile = optarg;
+ char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
case PGX_DFMT:
case 'o': /* output file */
{
- char *outfile = optarg;
+ char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
case J2K_CFMT:
case 'O': /* output format */
{
char outformat[50];
- char *of = optarg;
+ 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 = optarg;
+ img_fol->out_format = opj_optarg;
break;
default:
fprintf(stderr, "Unknown output format image [only j2k, j2c, jp2]!! \n");
case 'r': /* rates rates/distorsion */
{
- char *s = optarg;
+ char *s = opj_optarg;
parameters->tcp_numlayers = 0;
while (sscanf(s, "%f", ¶meters->tcp_rates[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++;
case 'F': /* Raw image format parameters */
{
char signo;
- char *s = optarg;
+ 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;
case 'q': /* add fixed_quality */
{
- char *s = optarg;
+ char *s = opj_optarg;
while (sscanf(s, "%f", ¶meters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++;
while (*s && *s != ',') {
int *row = NULL, *col = NULL;
int numlayers = 0, numresolution = 0, matrix_width = 0;
- char *s = optarg;
+ char *s = opj_optarg;
sscanf(s, "%d", &numlayers);
s++;
if (numlayers > 9)
case 't': /* tiles */
{
- sscanf(optarg, "%d,%d", ¶meters->cp_tdx, ¶meters->cp_tdy);
+ sscanf(opj_optarg, "%d,%d", ¶meters->cp_tdx, ¶meters->cp_tdy);
parameters->tile_size_on = OPJ_TRUE;
}
break;
case 'n': /* resolution */
{
- sscanf(optarg, "%d", ¶meters->numresolution);
+ sscanf(opj_optarg, "%d", ¶meters->numresolution);
}
break;
char sep;
int res_spec = 0;
- char *s = optarg;
+ char *s = opj_optarg;
do {
sep = 0;
sscanf(s, "[%d,%d]%c", ¶meters->prcw_init[res_spec],
case 'b': /* code-block dimension */
{
int cblockw_init = 0, cblockh_init = 0;
- sscanf(optarg, "%d,%d", &cblockw_init, &cblockh_init);
+ 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,
case 'x': /* creation of index file */
{
- char *index = optarg;
+ char *index = opj_optarg;
strncpy(indexfilename, index, OPJ_PATH_LEN);
}
break;
{
char progression[4];
- strncpy(progression, optarg, 4);
+ strncpy(progression, opj_optarg, 4);
parameters->prog_order = give_progression(progression);
if (parameters->prog_order == -1) {
fprintf(stderr, "Unrecognized progression order "
case 's': /* subsampling factor */
{
- if (sscanf(optarg, "%d,%d", ¶meters->subsampling_dx,
+ 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;
case 'd': /* coordonnate of the reference grid */
{
- if (sscanf(optarg, "%d,%d", ¶meters->image_offset_x0,
+ 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");
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;
+ char *s = opj_optarg;
POC = parameters->POC;
while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%4s", &POC[numpocs].tile,
case 'M': /* Mode switch pas tous au point !! */
{
int value = 0;
- if (sscanf(optarg, "%d", &value) == 1) {
+ if (sscanf(opj_optarg, "%d", &value) == 1) {
for (i = 0; i <= 5; i++) {
int cache = value & (1 << i);
if (cache)
case 'R': /* ROI */
{
- if (sscanf(optarg, "c=%d,U=%d", ¶meters->roi_compno,
+ 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;
case 'T': /* Tile offset */
{
- if (sscanf(optarg, "%d,%d", ¶meters->cp_tx0, ¶meters->cp_ty0) != 2) {
+ 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;
}
case 'C': /* add a comment */
{
- parameters->cp_comment = (char*)malloc(strlen(optarg) + 1);
+ parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
if(parameters->cp_comment) {
- strcpy(parameters->cp_comment, optarg);
+ strcpy(parameters->cp_comment, opj_optarg);
}
}
break;
case 'v': /* Tile part generation*/
{
- parameters->tp_flag = optarg[0];
+ parameters->tp_flag = opj_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->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(optarg,"%d",&fps);
+ sscanf(opj_optarg,"%d",&fps);
if(fps == 24){
parameters->cp_cinema = CINEMA2K_24;
}else if(fps == 48 ){
/* search for different protection methods */
/* break the option in comma points and parse the result */
- token = strtok(optarg, ",");
+ token = strtok(opj_optarg, ",");
while(token != NULL) {
/* search header error protection method */
break;
#endif /* USE_JPWL */
/* <<UniPG */
-
+/* ------------------------------------------------------ */
+
+ case 'J': /* jpip on */
+ {
+ parameters->jpip_on = OPJ_TRUE;
+ }
+ break;
/* ------------------------------------------------------ */
+
default:
fprintf(stderr, "ERROR -> Command line not valid\n");
return 1;
}
- }
+ }while(c != -1);
/* check for possible errors */
if (parameters->cp_cinema){
/* encode the image */
if (*indexfilename) // If need to extract codestream information
- bSuccess = opj_encode_with_info(cinfo, cio, image, &cstr_info);
+ bSuccess = opj_encode_with_info(cinfo, cio, image, &cstr_info);
else
bSuccess = opj_encode(cinfo, cio, image, NULL);
if (!bSuccess) {
int codestream_length;
opj_cio_t *cio = NULL;
FILE *f = NULL;
+ opj_cinfo_t *cinfo = NULL;
- /* get a JP2 compressor handle */
- opj_cinfo_t* cinfo = opj_create_compress(CODEC_JP2);
+ /* get a JP2 compressor handle */
+ cinfo = opj_create_compress(CODEC_JP2);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
/* encode the image */
- if (*indexfilename) // If need to extract codestream information
- bSuccess = opj_encode_with_info(cinfo, cio, image, &cstr_info);
+ if (*indexfilename || parameters.jpip_on) // If need to extract codestream information
+ bSuccess = opj_encode_with_info(cinfo, cio, image, &cstr_info);
else
bSuccess = opj_encode(cinfo, cio, image, NULL);
if (!bSuccess) {