* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
- * Copyright (c) 2005, Herve Drolon, FreeImage Team
+ * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006-2007, Parvatha Elangovan
* All rights reserved.
*
#define TIF_DFMT 14
#define RAW_DFMT 15
#define TGA_DFMT 16
-
+#define PNG_DFMT 17
/* ----------------------------------------------------------------------- */
#define CINEMA_24_CS 1302083 /*Codestream length for 24fps*/
#define CINEMA_48_CS 651041 /*Codestream length for 48fps*/
fprintf(stdout,"-h : display the help information \n ");
fprintf(stdout,"\n");
fprintf(stdout,"-cinema2K : Digital Cinema 2K profile compliant codestream for 2K resolution.(-cinema2k 24 or 48) \n");
- fprintf(stdout," Need to specify the frames per second for a 2K resolution. Only 24 or 48 fps is allowed\n");
+ fprintf(stdout," Need to specify the frames per second for a 2K resolution. Only 24 or 48 fps is allowed\n");
fprintf(stdout,"\n");
fprintf(stdout,"-cinema4K : Digital Cinema 4K profile compliant codestream for 4K resolution \n");
- fprintf(stdout," Frames per second not required. Default value is 24fps\n");
+ fprintf(stdout," Frames per second not required. Default value is 24fps\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");
int get_num_images(char *imgdirpath){
DIR *dir;
- struct dirent* content;
+ struct dirent* content;
int num_images = 0;
/*Reading the input images from given input directory*/
int load_images(dircnt_t *dirptr, char *imgdirpath){
DIR *dir;
- struct dirent* content;
+ struct dirent* content;
int i = 0;
/*Reading the input images from given input directory*/
strcpy(dirptr->filename[i],content->d_name);
i++;
}
- return 0;
+ return 0;
}
int get_file_format(char *filename) {
unsigned int i;
static const char *extension[] = {
- "pgx", "pnm", "pgm", "ppm", "bmp", "tif", "raw", "tga", "j2k", "jp2", "j2c"
+ "pgx", "pnm", "pgm", "ppm", "bmp", "tif", "raw", "tga", "png", "j2k", "jp2", "j2c", "jpc"
};
static const int format[] = {
- PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, J2K_CFMT, JP2_CFMT, J2K_CFMT
+ PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, J2K_CFMT, J2K_CFMT
};
char * ext = strrchr(filename, '.');
if (ext == NULL)
}
static int initialise_4K_poc(opj_poc_t *POC, int numres){
- POC[0].tile = 1;
- POC[0].resno0 = 0;
+ POC[0].tile = 1;
+ POC[0].resno0 = 0;
POC[0].compno0 = 0;
POC[0].layno1 = 1;
POC[0].resno1 = numres-1;
POC[0].compno1 = 3;
POC[0].prg1 = CPRL;
POC[1].tile = 1;
- POC[1].resno0 = numres-1;
+ POC[1].resno0 = numres-1;
POC[1].compno0 = 0;
POC[1].layno1 = 1;
POC[1].resno1 = numres;
parameters->tile_size_on = false;
parameters->cp_tdx=1;
parameters->cp_tdy=1;
-
+
/*Tile part*/
parameters->tp_flag = 'C';
parameters->tp_on = 1;
parameters->image_offset_y0 = 0;
/*Codeblock size= 32*32*/
- parameters->cblockw_init = 32;
+ parameters->cblockw_init = 32;
parameters->cblockh_init = 32;
parameters->csty |= 0x01;
void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_fol_t *img_fol){
int i;
float temp_rate;
- opj_poc_t *POC = NULL;
switch (parameters->cp_cinema){
case CINEMA2K_24:
parameters->cp_rsiz = STD_RSIZ;
}
break;
-
+
case CINEMA4K_24:
if(parameters->numresolution < 1){
parameters->numresolution = 1;
parameters->numresolution = 7;
}
if (!((image->comps[0].w == 4096) | (image->comps[0].h == 2160))){
- fprintf(stdout,"Image coordinates %d x %d is not 4K compliant.\nJPEG Digital Cinema Profile-4"
+ fprintf(stdout,"Image coordinates %d x %d is not 4K compliant.\nJPEG Digital Cinema Profile-4"
"(4K profile) compliance requires that at least one of coordinates match 4096 x 2160\n",
image->comps[0].w,image->comps[0].h);
parameters->cp_rsiz = STD_RSIZ;
}
parameters->numpocs = initialise_4K_poc(parameters->POC,parameters->numresolution);
break;
+ default :
+ break;
}
switch (parameters->cp_cinema){
for(i=0 ; i<parameters->tcp_numlayers ; i++){
temp_rate = 0 ;
if (img_fol->rates[i]== 0){
- parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
+ parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
}else{
- temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
+ temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
if (temp_rate > CINEMA_24_CS ){
- parameters->tcp_rates[i]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
+ parameters->tcp_rates[i]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
}else{
parameters->tcp_rates[i]= img_fol->rates[i];
}
parameters->max_comp_size = COMP_24_CS;
break;
-
+
case CINEMA2K_48:
for(i=0 ; i<parameters->tcp_numlayers ; i++){
temp_rate = 0 ;
if (img_fol->rates[i]== 0){
- parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
+ parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
}else{
- temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
+ temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
if (temp_rate > CINEMA_48_CS ){
- parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
+ parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
}else{
parameters->tcp_rates[i]= img_fol->rates[i];
}
parameters->max_comp_size = COMP_48_CS;
break;
+ default:
+ break;
}
parameters->cp_disto_alloc = 1;
}
case TIF_DFMT:
case RAW_DFMT:
case TGA_DFMT:
+ case PNG_DFMT:
break;
default:
fprintf(stderr,
"!! Unrecognized format for infile : %s "
- "[accept only *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga] !!\n\n",
+ "[accept only *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga] !!\n\n",
infile);
return 1;
}
/* ----------------------------------------------------- */
-
+
case 'F': /* Raw image format parameters */
{
char signo;
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");
break;
/* ------------------------------------------------------ */
-
+
case 'v': /* Tile part generation*/
{
parameters->tp_flag = optarg[0];
parameters->tp_on = 1;
}
- break;
+ break;
/* ------------------------------------------------------ */
-
+
case 'z': /* Image Directory path */
{
img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);
break;
/* ------------------------------------------------------ */
-
+
case 'w': /* Digital Cinema 2K profile compliance*/
{
int fps=0;
}
fprintf(stdout,"CINEMA 2K compliant codestream\n");
parameters->cp_rsiz = CINEMA2K;
-
+
}
break;
-
+
/* ------------------------------------------------------ */
-
+
case 'y': /* Digital Cinema 4K profile compliance*/
{
parameters->cp_cinema = CINEMA4K_24;
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 || !strcmp(indexfilename, "")) {
+ if (!indexfilename || !*indexfilename) {
strncpy(indexfilename, JPWL_PRIVATEINDEX_NAME, OPJ_PATH_LEN);
}
/* search packet error protection method */
if (*token == 'p') {
- static int pack = 0, tile = 0, packspec = 0/*, lastpackno = 0*/;
+ static int pack = 0, tile = 0, packspec = 0;
pprot = 1; /* predefined method */
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 */
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 */
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) */
fprintf(stderr, "ERROR -> invalid range selection = %s\n", token);
return 1;
};
-
+
}
/* next token or bust */
if(parse_cmdline_encoder(argc, argv, ¶meters,&img_fol, &raw_cp, indexfilename) == 1) {
return 1;
}
-
+
if (parameters.cp_cinema){
img_fol.rates = (float*)malloc(parameters.tcp_numlayers * sizeof(float));
for(i=0; i< parameters.tcp_numlayers; i++){
img_fol.rates[i] = parameters.tcp_rates[i];
}
cinema_parameters(¶meters);
- }
+ }
/* Create comment for codestream */
if(parameters.cp_comment == NULL) {
for(imageno=0;imageno<num_images;imageno++) {
image = NULL;
fprintf(stderr,"\n");
-
+
if(img_fol.set_imgdir==1){
if (get_next_file(imageno, dirptr,&img_fol, ¶meters)) {
fprintf(stderr,"skipping file...\n");
break;
case TGA_DFMT:
break;
+ case PNG_DFMT:
+ break;
default:
fprintf(stderr,"skipping file...\n");
- continue;
+ continue;
}
/* decode the source image */
image = pgxtoimage(parameters.infile, ¶meters);
if (!image) {
fprintf(stderr, "Unable to load pgx file\n");
- return 1;
+ return 1;
}
break;
return 1;
}
break;
-
+
case TIF_DFMT:
image = tiftoimage(parameters.infile, ¶meters);
if (!image) {
return 1;
}
break;
+
+ case PNG_DFMT:
+ image = pngtoimage(parameters.infile, ¶meters);
+ if (!image) {
+ fprintf(stderr, "Unable to load png file\n");
+ return 1;
+ }
+ break;
}
/* Decide if MCT should be used */
parameters.tcp_mct = image->numcomps == 3 ? 1 : 0;
opj_cinfo_t* 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);
+ opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
/* setup the encoder parameters using the current image and using user parameters */
opj_setup_encoder(cinfo, ¶meters, image);
fprintf(stderr,"Generated outfile %s\n",parameters.outfile);
/* close and free the byte stream */
opj_cio_close(cio);
-
+
/* Write the index to disk */
if (*indexfilename) {
bSuccess = write_index_file(&cstr_info, indexfilename);
if (*indexfilename)
opj_destroy_cstr_info(&cstr_info);
}
-
+
/* free image data */
opj_image_destroy(image);
}