Accepting "j2c" as format for Encoding and Decoding. Modification in image_to_j2k.c.

Modified imagetotif() to read images with signed data. Modification in convert.c.
This commit is contained in:
Parvatha Elangovan 2007-04-10 16:23:48 +00:00
parent 0930d9886b
commit dbd132dca8
5 changed files with 115 additions and 59 deletions

View File

@ -5,6 +5,10 @@ What's New for OpenJPEG
! : changed
+ : added
April 10,2007
+ [Parvatha] Accepting "j2c" as format for Encoding and Decoding. Modification in image_to_j2k.c.
* [Parvatha] Modified imagetotif() to read images with signed data. Modification in convert.c.
April 5, 2007
! [FOD] fix.h optimized. Thanks a lot to Dzonatas <dzonatas at dzonux.net> !
! [FOD] dwt.c optimized. Thanks a lot to Dzonatas <dzonatas at dzonux.net> !

View File

@ -1082,7 +1082,7 @@ typedef struct tiff_infoheader{
}tiff_infoheader_t;
int imagetotif(opj_image_t * image, const char *outfile) {
int width, height;
int width, height, imgsize;
int bps,index;
TIFF *tif;
tdata_t buf;
@ -1107,7 +1107,8 @@ int imagetotif(opj_image_t * image, const char *outfile) {
}
width = image->comps[0].w;
height= image->comps[0].h;
height = image->comps[0].h;
imgsize = image->comps[0].w * image->comps[0].h ;
bps = image->comps[0].prec;
/* Set tags */
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);
@ -1129,34 +1130,74 @@ int imagetotif(opj_image_t * image, const char *outfile) {
int i;
dat8 = buf;
if (image->comps[0].prec == 8){
for (i=0; i<TIFFStripSize(tif); i+=3) { // 8 bits per pixel
dat8[i+0] = image->comps[0].data[index] ; // R
dat8[i+1] = image->comps[1].data[index] ; // G
dat8[i+2] = image->comps[2].data[index] ; // B
index++;
for (i=0; i < strip_size; i+=3) { // 8 bits per pixel
int r = 0,g = 0,b = 0;
if(index < imgsize){
r = image->comps[0].data[index];
r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
g = image->comps[1].data[index];
g += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
b = image->comps[2].data[index];
b += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
dat8[i+0] = r ; // R
dat8[i+1] = g ; // G
dat8[i+2] = b ; // B
index++;
}else
break;
}
}else if (image->comps[0].prec == 12){
for (i=0; i<TIFFStripSize(tif); i+=9) { // 12 bits per pixel
dat8[i+0] = (image->comps[0].data[index]>>8)<<4 | (image->comps[0].data[index]>>4);
dat8[i+1] = (image->comps[0].data[index]<<4)|((image->comps[1].data[index]>>8)& 0x0f);
dat8[i+2] = (image->comps[1].data[index]);
dat8[i+3] = (image->comps[2].data[index]>>8)<<4 | (image->comps[2].data[index]>>4);
dat8[i+4] = (image->comps[2].data[index]<<4)|((image->comps[1].data[index+1]>>8)& 0x0f);
dat8[i+5] = (image->comps[0].data[index+1]);
dat8[i+6] = (image->comps[1].data[index+1]>>8)<<4 | (image->comps[1].data[index+1]>>4);
dat8[i+7] = (image->comps[1].data[index+1]<<4)|((image->comps[2].data[index+1]>>8)& 0x0f);
dat8[i+8] = (image->comps[2].data[index+1]);
index+=2;
for (i=0; i<strip_size; i+=9) { // 12 bits per pixel
int r = 0,g = 0,b = 0;
int r1 = 0,g1 = 0,b1 = 0;
if(index < imgsize){
r = image->comps[0].data[index];
r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
g = image->comps[1].data[index];
g += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
b = image->comps[2].data[index];
b += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
r1 = image->comps[0].data[index+1];
r1 += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
g1 = image->comps[1].data[index+1];
g1 += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
b1 = image->comps[2].data[index+1];
b1 += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
dat8[i+0] = (r >> 4);
dat8[i+1] = ((r & 0x0f) << 4 )|((g >> 8)& 0x0f);
dat8[i+2] = g ;
dat8[i+3] = (b >> 4);
dat8[i+4] = ((b & 0x0f) << 4 )|((r1 >> 8)& 0x0f);
dat8[i+5] = (r1);
dat8[i+6] = (g1 >> 4);
dat8[i+7] = ((g1 & 0x0f)<< 4 )|((b1 >> 8)& 0x0f);
dat8[i+8] = (b1);
index+=2;
}else
break;
}
}else if (image->comps[0].prec == 16){
for (i=0; i<TIFFStripSize(tif); i+=6) { // 16 bits per pixel
dat8[i+0] = image->comps[0].data[index];//LSB
dat8[i+1] = (image->comps[0].data[index]>> 8);//MSB
dat8[i+2] = image->comps[1].data[index];
dat8[i+3] = (image->comps[1].data[index]>> 8);
dat8[i+4] = image->comps[2].data[index];
dat8[i+5] = (image->comps[2].data[index]>> 8);
index++;
for (i=0; i<strip_size; i+=6) { // 16 bits per pixel
int r = 0,g = 0,b = 0;
if(index < imgsize){
r = image->comps[0].data[index];
r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
g = image->comps[1].data[index];
g += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
b = image->comps[2].data[index];
b += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
dat8[i+0] = r;//LSB
dat8[i+1] = (r >> 8);//MSB
dat8[i+2] = g;
dat8[i+3] = (g >> 8);
dat8[i+4] = b;
dat8[i+5] = (b >> 8);
index++;
}else
break;
}
}else{
fprintf(stderr,"Bits=%d, Only 8,12,16 bits implemented\n",image->comps[0].prec);
@ -1249,6 +1290,7 @@ opj_image_t* tiftoimage(char *filename, opj_cparameters_t *parameters)
OPJ_COLOR_SPACE color_space;
opj_image_cmptparm_t cmptparm[3];
opj_image_t * image = NULL;
int imgsize;
tif = TIFFOpen(filename, "r");
@ -1303,6 +1345,7 @@ opj_image_t* tiftoimage(char *filename, opj_cparameters_t *parameters)
strip_size=0;
strip_size=TIFFStripSize(tif);
index = 0;
imgsize = image->comps[0].w * image->comps[0].h ;
/* Read the Image components*/
for (strip = 0; strip < TIFFNumberOfStrips(tif); strip++) {
unsigned char *dat8;
@ -1312,29 +1355,38 @@ opj_image_t* tiftoimage(char *filename, opj_cparameters_t *parameters)
if (Info.tiBps==12){
for (i=0; i<ssize; i+=9) { /*12 bits per pixel*/
image->comps[0].data[index] = ( dat8[i+0]<<4 ) |(dat8[i+1]>>4);
image->comps[1].data[index] = ((dat8[i+1]& 0x0f)<< 8) | dat8[i+2];
image->comps[2].data[index] = ( dat8[i+3]<<4) |(dat8[i+4]>>4);
image->comps[0].data[index+1] = ((dat8[i+4]& 0x0f)<< 8) | dat8[i+5];
image->comps[1].data[index+1] = ( dat8[i+6] <<4) |(dat8[i+7]>>4);
image->comps[2].data[index+1] = ((dat8[i+7]& 0x0f)<< 8) | dat8[i+8];
index+=2;
if(index < datasize){
image->comps[0].data[index] = ( dat8[i+0]<<4 ) |(dat8[i+1]>>4);
image->comps[1].data[index] = ((dat8[i+1]& 0x0f)<< 8) | dat8[i+2];
image->comps[2].data[index] = ( dat8[i+3]<<4) |(dat8[i+4]>>4);
image->comps[0].data[index+1] = ((dat8[i+4]& 0x0f)<< 8) | dat8[i+5];
image->comps[1].data[index+1] = ( dat8[i+6] <<4) |(dat8[i+7]>>4);
image->comps[2].data[index+1] = ((dat8[i+7]& 0x0f)<< 8) | dat8[i+8];
index+=2;
}else
break;
}
}
else if( Info.tiBps==16){
for (i=0; i<ssize; i+=6) { /* 16 bits per pixel */
image->comps[0].data[index] = ( dat8[i+1] << 8 ) | dat8[i+0]; // R
image->comps[1].data[index] = ( dat8[i+3] << 8 ) | dat8[i+2]; // G
image->comps[2].data[index] = ( dat8[i+5] << 8 ) | dat8[i+4]; // B
index++;
if(index < datasize){
image->comps[0].data[index] = ( dat8[i+1] << 8 ) | dat8[i+0]; // R
image->comps[1].data[index] = ( dat8[i+3] << 8 ) | dat8[i+2]; // G
image->comps[2].data[index] = ( dat8[i+5] << 8 ) | dat8[i+4]; // B
index++;
}else
break;
}
}
else if ( Info.tiBps==8){
for (i=0; i<ssize; i+=3) { /* 8 bits per pixel */
image->comps[0].data[index] = dat8[i+0]; // R
image->comps[1].data[index] = dat8[i+1]; // G
image->comps[2].data[index] = dat8[i+2]; // B
index++;
if(index < datasize){
image->comps[0].data[index] = dat8[i+0]; // R
image->comps[1].data[index] = dat8[i+1]; // G
image->comps[2].data[index] = dat8[i+2]; // B
index++;
}else
break;
}
}
else{

View File

@ -375,10 +375,10 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){
int get_file_format(char *filename) {
unsigned int i;
static const char *extension[] = {
"pgx", "pnm", "pgm", "ppm", "bmp","tif", "j2k", "jp2"
"pgx", "pnm", "pgm", "ppm", "bmp","tif", "j2k", "jp2", "j2c"
};
static const int format[] = {
PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT,TIF_DFMT, J2K_CFMT, JP2_CFMT
PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT,TIF_DFMT, J2K_CFMT, JP2_CFMT, J2K_CFMT
};
char * ext = strrchr(filename, '.');
if (ext == NULL)
@ -478,7 +478,7 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image){
if(parameters->numresolution > 6){
parameters->numresolution = 6;
}
if (!((image->comps[0].w == 2048) & (image->comps[0].h == 1080))){
if (!((image->comps[0].w == 2048) | (image->comps[0].h == 1080))){
fprintf(stdout,"Image coordinates %d x %d is not 2K compliant.\nDCI 2K compliance requires that atleast one of coordinates match 2048 x 1080\n",image->comps[0].w,image->comps[0].h);
parameters->cp_rsiz = STD_RSIZ;
}
@ -490,7 +490,7 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image){
}else if(parameters->numresolution > 7){
parameters->numresolution = 7;
}
if (!((image->comps[0].w == 4096) & (image->comps[0].h == 2160))){
if (!((image->comps[0].w == 4096) | (image->comps[0].h == 2160))){
fprintf(stdout,"Image coordinates %d x %d is not 4K compliant.\nDCI 4K compliance requires that atleast one of coordinates match 4096 x 2160\n",image->comps[0].w,image->comps[0].h);
parameters->cp_rsiz = STD_RSIZ;
}
@ -619,15 +619,13 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,i
img_fol->set_out_format = 1;
parameters->cod_format = get_file_format(outformat);
switch(parameters->cod_format) {
case J2K_CFMT:
img_fol->out_format = "j2k";
break;
case JP2_CFMT:
img_fol->out_format = "jp2";
break;
default:
fprintf(stderr, "Unknown output format image [only j2k, jp2]!! \n");
return 1;
case J2K_CFMT:
case JP2_CFMT:
img_fol->out_format = optarg;
break;
default:
fprintf(stderr, "Unknown output format image [only j2k, jp2]!! \n");
return 1;
}
}
break;

View File

@ -181,8 +181,8 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){
int get_file_format(char *filename) {
unsigned int i;
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "j2k", "jp2", "jpt" };
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT };
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "j2k", "jp2", "jpt", "j2c" };
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT };
char * ext = strrchr(filename, '.');
if (ext == NULL)
return -1;

View File

@ -603,9 +603,11 @@ int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlaye
}
}
if (e == -999) break;
if (comp_len > cp->max_comp_size){
e = -999;
break;
if (cp->max_comp_size){
if (comp_len > cp->max_comp_size){
e = -999;
break;
}
}
}
if (e == -999) break;