From dbd132dca8f87a75c5d5addb1e6324da7c089c09 Mon Sep 17 00:00:00 2001
From: Parvatha Elangovan
Date: Tue, 10 Apr 2007 16:23:48 +0000
Subject: [PATCH] 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.
---
ChangeLog | 4 ++
codec/convert.c | 134 ++++++++++++++++++++++++++++++-------------
codec/image_to_j2k.c | 24 ++++----
codec/j2k_to_image.c | 4 +-
libopenjpeg/t2.c | 8 ++-
5 files changed, 115 insertions(+), 59 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c304f9b4..3ded1a3c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 !
! [FOD] dwt.c optimized. Thanks a lot to Dzonatas !
diff --git a/codec/convert.c b/codec/convert.c
index 999b41ca..4ffa1ef0 100644
--- a/codec/convert.c
+++ b/codec/convert.c
@@ -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; icomps[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; icomps[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; icomps[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; icomps[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; icomps[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; icomps[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; icomps[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; icomps[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{
diff --git a/codec/image_to_j2k.c b/codec/image_to_j2k.c
index b5e056df..60581f51 100644
--- a/codec/image_to_j2k.c
+++ b/codec/image_to_j2k.c
@@ -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;
diff --git a/codec/j2k_to_image.c b/codec/j2k_to_image.c
index bdf6de74..1cf9dbcc 100644
--- a/codec/j2k_to_image.c
+++ b/codec/j2k_to_image.c
@@ -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;
diff --git a/libopenjpeg/t2.c b/libopenjpeg/t2.c
index 995b85ce..dc8e24ed 100644
--- a/libopenjpeg/t2.c
+++ b/libopenjpeg/t2.c
@@ -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;