summaryrefslogtreecommitdiff
path: root/codec
diff options
context:
space:
mode:
authorParvatha Elangovan <p.elangovan@intopix.com>2007-02-28 15:31:56 +0000
committerParvatha Elangovan <p.elangovan@intopix.com>2007-02-28 15:31:56 +0000
commit192e46c32f7baededf8df7b1777f8c5409110e8a (patch)
tree6c02f445207de1af38390a47a7ec9f7aab1a1ea3 /codec
parente5c5d1064ec154ebcf7d976b1070dd0da3d95ee4 (diff)
Enabled compression of TIF image format to j2k by tifftoimage() and decompression of codestream to TIF image format using imagetotif(). Modifications in image_to_j2k.c, j2k_to_image.c, convert.c, convert.h
Diffstat (limited to 'codec')
-rw-r--r--codec/convert.c356
-rw-r--r--codec/convert.h3
-rw-r--r--codec/image_to_j2k.c35
-rw-r--r--codec/j2k_to_image.c58
4 files changed, 425 insertions, 27 deletions
diff --git a/codec/convert.c b/codec/convert.c
index 5c84cbdb..3ff6eb88 100644
--- a/codec/convert.c
+++ b/codec/convert.c
@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <string.h>
#include "openjpeg.h"
+#include "../libs/libtiff/tiffio.h"
/*
* Get logarithm of an integer and round downwards.
@@ -1063,4 +1064,359 @@ int imagetopnm(opj_image_t * image, const char *outfile) {
return 0;
}
+/* -->> -->> -->> -->>
+
+ TIFF IMAGE FORMAT
+
+ <<-- <<-- <<-- <<-- */
+
+typedef struct tiff_infoheader{
+ DWORD tiWidth; // Width of Image in pixel
+ DWORD tiHeight; // Height of Image in pixel
+ DWORD tiPhoto; // Photometric
+ WORD tiBps; // Bits per sample
+ WORD tiSf; // Sample Format
+ WORD tiSpp; // Sample per pixel 1-bilevel,gray scale , 2- RGB
+ WORD tiPC; // Planar config (1-Interleaved, 2-Planarcomp)
+}tiff_infoheader_t;
+
+int imagetotif(opj_image_t * image, const char *outfile) {
+ int width, height;
+ int bps,index;
+ TIFF *tif;
+ tdata_t buf;
+ tstrip_t strip;
+ tsize_t strip_size;
+ if (image->numcomps == 3 && image->comps[0].dx == image->comps[1].dx
+ && image->comps[1].dx == image->comps[2].dx
+ && image->comps[0].dy == image->comps[1].dy
+ && image->comps[1].dy == image->comps[2].dy
+ && image->comps[0].prec == image->comps[1].prec
+ && image->comps[1].prec == image->comps[2].prec) {
+
+ /* -->> -->> -->>
+ RGB color
+ <<-- <<-- <<-- */
+
+ tif = TIFFOpen(outfile, "wb");
+ if (!tif) {
+ fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile);
+ return 1;
+ }
+
+ width = image->comps[0].w;
+ height= image->comps[0].h;
+ bps = image->comps[0].prec;
+ /* Set tags */
+ TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);
+ TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height);
+ TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
+ TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps);
+ TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
+ TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
+ TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
+ TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1);
+
+ /* Get a buffer for the data */
+ buf = _TIFFmalloc(TIFFStripSize(tif));
+ index=0;
+ strip_size=0;
+ strip_size=TIFFStripSize(tif);
+ for (strip = 0; strip < TIFFNumberOfStrips(tif); strip++) {
+ unsigned char *dat8;
+ 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++;
+ }
+ }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;
+ }
+ }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++;
+ }
+ }else{
+ fprintf(stderr,"Bits=%d, Only 8,12,16 bits implemented\n",image->comps[0].prec);
+ fprintf(stderr,"Aborting\n");
+ return 1;
+ }
+ TIFFWriteEncodedStrip(tif, strip, buf, strip_size);
+ }
+ _TIFFfree(buf);
+ TIFFClose(tif);
+ }else if (image->numcomps == 1){
+ /* -->> -->> -->>
+ Black and White
+ <<-- <<-- <<-- */
+
+ tif = TIFFOpen(outfile, "wb");
+ if (!tif) {
+ fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile);
+ return 1;
+ }
+
+ width = image->comps[0].w;
+ height= image->comps[0].h;
+ bps = image->comps[0].prec;
+
+ /* Set tags */
+ TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);
+ TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height);
+ TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
+ TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps);
+ TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
+ TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
+ TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
+ TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1);
+
+ /* Get a buffer for the data */
+ buf = _TIFFmalloc(TIFFStripSize(tif));
+ index = 0;
+ strip_size = 0;
+ strip_size = TIFFStripSize(tif);
+ for (strip = 0; strip < TIFFNumberOfStrips(tif); strip++) {
+ unsigned char *dat8;
+ int i;
+ dat8 = buf;
+ if (image->comps[0].prec == 8){
+ for (i=0; i<TIFFStripSize(tif); i+=1) { // 8 bits per pixel
+ dat8[i+0] = image->comps[0].data[index] ;
+ index++;
+ }
+ }else if (image->comps[0].prec == 12){
+ for (i = 0; i<TIFFStripSize(tif); i+=3) { // 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[0].data[index+1]>>8)& 0x0f);
+ dat8[i+2] = (image->comps[0].data[index+1]);
+ index+=2;
+ }
+ }else if (image->comps[0].prec == 16){
+ for (i=0; i<TIFFStripSize(tif); i+=2) { // 16 bits per pixel
+ dat8[i+0] = image->comps[0].data[index];
+ dat8[i+1] = (image->comps[0].data[index]>> 8);
+ index++;
+ }
+ }else{
+ fprintf(stderr,"Bits=%d, Only 8,12,16 bits implemented\n",image->comps[0].prec);
+ fprintf(stderr,"Aborting\n");
+ return 1;
+ }
+ TIFFWriteEncodedStrip(tif, strip, buf, strip_size);
+ }
+ _TIFFfree(buf);
+ TIFFClose(tif);
+ }else{
+ fprintf(stderr,"False color format. Only RGB & Grayscale has been implemented\n");
+ fprintf(stderr,"Aborting\n");
+ return 1;
+ }
+ return 0;
+}
+
+opj_image_t* tiftoimage(char *filename, opj_cparameters_t *parameters)
+{
+ int subsampling_dx = parameters->subsampling_dx;
+ int subsampling_dy = parameters->subsampling_dy;
+ TIFF *tif;
+ tiff_infoheader_t Info;
+ tdata_t buf;
+ tstrip_t strip;
+ tsize_t strip_size;
+ int j, numcomps, w, h,index;
+ OPJ_COLOR_SPACE color_space;
+ opj_image_cmptparm_t cmptparm[3];
+ opj_image_t * image = NULL;
+
+ tif = TIFFOpen(filename, "r");
+
+ if (!tif) {
+ fprintf(stderr, "Failed to open %s for reading\n", filename);
+ return 0;
+ }
+
+ TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &Info.tiWidth);
+ TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &Info.tiHeight);
+ TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &Info.tiBps);
+ TIFFGetField(tif, TIFFTAG_SAMPLEFORMAT, &Info.tiSf);
+ TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &Info.tiSpp);
+ Info.tiPhoto = 0;
+ TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &Info.tiPhoto);
+ TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &Info.tiPC);
+ w= Info.tiWidth;
+ h= Info.tiHeight;
+
+ if (Info.tiPhoto == 2) {
+ /* -->> -->> -->>
+ RGB color
+ <<-- <<-- <<-- */
+
+ numcomps = 3;
+ color_space = CLRSPC_SRGB;
+ /* initialize image components*/
+ memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t));
+ for(j = 0; j < numcomps; j++) {
+ cmptparm[j].prec = Info.tiBps;
+ cmptparm[j].bpp = Info.tiBps;
+ cmptparm[j].sgnd = 0;
+ cmptparm[j].dx = subsampling_dx;
+ cmptparm[j].dy = subsampling_dy;
+ cmptparm[j].w = w;
+ cmptparm[j].h = h;
+ }
+ /* create the image*/
+ image = opj_image_create(numcomps, &cmptparm[0], color_space);
+ if(!image) {
+ TIFFClose(tif);
+ return NULL;
+ }
+
+ /* set image offset and reference grid */
+ image->x0 = parameters->image_offset_x0;
+ image->y0 = parameters->image_offset_y0;
+ image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w - 1) * subsampling_dx + 1;
+ image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h - 1) * subsampling_dy + 1;
+
+ buf = _TIFFmalloc(TIFFStripSize(tif));
+ strip_size=0;
+ strip_size=TIFFStripSize(tif);
+ index = 0;
+ /* Read the Image components*/
+ for (strip = 0; strip < TIFFNumberOfStrips(tif); strip++) {
+ unsigned char *dat8;
+ int i, ssize;
+ ssize = TIFFReadEncodedStrip(tif, strip, buf, strip_size);
+ dat8 = buf;
+
+ 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;
+ }
+ }
+ 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++;
+ }
+ }
+ 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++;
+ }
+ }
+ else{
+ fprintf(stderr,"Bits=%d, Only 8,12,16 bits implemented\n",Info.tiBps);
+ fprintf(stderr,"Aborting\n");
+ return NULL;
+ }
+ }
+
+ _TIFFfree(buf);
+ TIFFClose(tif);
+ }else if(Info.tiPhoto == 1) {
+ /* -->> -->> -->>
+ Black and White
+ <<-- <<-- <<-- */
+
+ numcomps = 1;
+ color_space = CLRSPC_GRAY;
+ /* initialize image components*/
+ memset(&cmptparm[0], 0, sizeof(opj_image_cmptparm_t));
+ cmptparm[0].prec = Info.tiBps;
+ cmptparm[0].bpp = Info.tiBps;
+ cmptparm[0].sgnd = 0;
+ cmptparm[0].dx = subsampling_dx;
+ cmptparm[0].dy = subsampling_dy;
+ cmptparm[0].w = w;
+ cmptparm[0].h = h;
+
+ /* create the image*/
+ image = opj_image_create(numcomps, &cmptparm[0], color_space);
+ if(!image) {
+ TIFFClose(tif);
+ return NULL;
+ }
+ /* set image offset and reference grid */
+ image->x0 = parameters->image_offset_x0;
+ image->y0 = parameters->image_offset_y0;
+ image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w - 1) * subsampling_dx + 1;
+ image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h - 1) * subsampling_dy + 1;
+
+ buf = _TIFFmalloc(TIFFStripSize(tif));
+ strip_size = 0;
+ strip_size = TIFFStripSize(tif);
+ index = 0;
+ /* Read the Image components*/
+ for (strip = 0; strip < TIFFNumberOfStrips(tif); strip++) {
+ unsigned char *dat8;
+ int i, ssize;
+ ssize = TIFFReadEncodedStrip(tif, strip, buf, strip_size);
+ dat8 = buf;
+
+ if (Info.tiBps==12){
+ for (i=0; i<ssize; i+=3) { /* 12 bits per pixel*/
+ image->comps[0].data[index] = ( dat8[i+0]<<4 ) |(dat8[i+1]>>4) ;
+ image->comps[0].data[index] = ((dat8[i+1]& 0x0f)<< 8) | dat8[i+2];
+ index+=2;
+ }
+ }
+ else if( Info.tiBps==16){
+ for (i=0; i<ssize; i+=2) { /* 16 bits per pixel */
+ image->comps[0].data[index] = ( dat8[i+1] << 8 ) | dat8[i+0];
+ index++;
+ }
+ }
+ else if ( Info.tiBps==8){
+ for (i=0; i<ssize; i+=1) { /* 8 bits per pixel */
+ image->comps[0].data[index] = dat8[i+0];
+ index++;
+ }
+ }
+ else{
+ fprintf(stderr,"Bits=%d, Only 8,12,16 bits implemented\n",Info.tiBps);
+ fprintf(stderr,"Aborting\n");
+ return NULL;
+ }
+ }
+
+ _TIFFfree(buf);
+ TIFFClose(tif);
+ }else{
+ fprintf(stderr,"False color format. Only RGB & Grayscale has been implemented\n");
+ fprintf(stderr,"Aborting\n");
+ return NULL;
+ }
+ return image;
+}
diff --git a/codec/convert.h b/codec/convert.h
index 95c3b357..68aed4b3 100644
--- a/codec/convert.h
+++ b/codec/convert.h
@@ -35,6 +35,9 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters);
int imagetobmp(opj_image_t *image, const char *outfile);
+/* TIFF to image conversion*/
+opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters);
+int imagetotif(opj_image_t *image, const char *outfile);
/**
Load a single image component encoded in PGX file format
@param filename Name of the PGX file to load
diff --git a/codec/image_to_j2k.c b/codec/image_to_j2k.c
index 71e3dd6a..28208c5c 100644
--- a/codec/image_to_j2k.c
+++ b/codec/image_to_j2k.c
@@ -52,6 +52,7 @@
#define PGX_DFMT 11
#define BMP_DFMT 12
#define YUV_DFMT 13
+#define TIF_DFMT 14
/* ----------------------------------------------------------------------- */
@@ -356,10 +357,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", "j2k", "jp2"
+ "pgx", "pnm", "pgm", "ppm", "bmp","tif", "j2k", "jp2"
};
static const int format[] = {
- PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, J2K_CFMT, JP2_CFMT
+ PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT,TIF_DFMT, J2K_CFMT, JP2_CFMT
};
char * ext = strrchr(filename, '.');
if (ext == NULL)
@@ -443,11 +444,12 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,i
case PGX_DFMT:
case PXM_DFMT:
case BMP_DFMT:
+ case TIF_DFMT:
break;
default:
fprintf(stderr,
"!! Unrecognized format for infile : %s "
- "[accept only *.pnm, *.pgm, *.ppm, *.pgx or *.bmp] !!\n\n",
+ "[accept only *.pnm, *.pgm, *.ppm, *.pgx, *.bmp or *.tif] !!\n\n",
infile);
return 1;
}
@@ -1145,8 +1147,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,i
}
/* check for possible errors */
- if(img_fol->set_imgdir==1){
- if(!(parameters->infile[0]==0)){
+ if(img_fol->set_imgdir == 1){
+ if(!(parameters->infile[0] == 0)){
fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n");
return 1;
}
@@ -1234,7 +1236,6 @@ int main(int argc, char **argv) {
opj_image_t *image = NULL;
int i,num_images;
int imageno;
- char process_file = 1;
dircnt_t *dirptr;
/*
@@ -1319,7 +1320,9 @@ int main(int argc, char **argv) {
break;
case BMP_DFMT:
break;
-
+ case TIF_DFMT:
+ break;
+
default:
fprintf(stderr,"skipping file...\n");
continue;
@@ -1332,15 +1335,15 @@ int main(int argc, char **argv) {
case PGX_DFMT:
image = pgxtoimage(parameters.infile, &parameters);
if (!image) {
- fprintf(stderr, " unable to load pgx file\n");
- return 1;
+ fprintf(stderr, "Unable to load pgx file\n");
+ return 1;
}
break;
case PXM_DFMT:
image = pnmtoimage(parameters.infile, &parameters);
if (!image) {
- fprintf(stderr, " not a pnm file\n");
+ fprintf(stderr, "Unable to load pnm file\n");
return 1;
}
break;
@@ -1348,11 +1351,19 @@ int main(int argc, char **argv) {
case BMP_DFMT:
image = bmptoimage(parameters.infile, &parameters);
if (!image) {
- fprintf(stderr, " not a bmp file\n");
+ fprintf(stderr, "Unable to load bmp file\n");
return 1;
}
break;
- }
+
+ case TIF_DFMT:
+ image = tiftoimage(parameters.infile, &parameters);
+ if (!image) {
+ fprintf(stderr, "Unable to load tiff file\n");
+ return 1;
+ }
+ break;
+ }
/* encode the destination image */
/* ---------------------------- */
diff --git a/codec/j2k_to_image.c b/codec/j2k_to_image.c
index 91651de9..223f44ee 100644
--- a/codec/j2k_to_image.c
+++ b/codec/j2k_to_image.c
@@ -52,6 +52,7 @@
#define PGX_DFMT 11
#define BMP_DFMT 12
#define YUV_DFMT 13
+#define TIF_DFMT 14
/* ----------------------------------------------------------------------- */
@@ -179,8 +180,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", "j2k", "jp2", "jpt" };
- static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT };
+ 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 };
char * ext = strrchr(filename, '.');
if (ext == NULL)
return -1;
@@ -200,7 +201,7 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN];
strcpy(image_filename,dirptr->filename[imageno]);
- fprintf(stderr,"Imageno=%d %s\n",imageno,image_filename);
+ fprintf(stderr,"File Number %d \"%s\"\n",imageno,image_filename);
parameters->decod_format = get_file_format(image_filename);
if (parameters->decod_format == -1)
return 1;
@@ -271,6 +272,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
case PGX_DFMT:
case PXM_DFMT:
case BMP_DFMT:
+ case TIF_DFMT:
break;
default:
fprintf(stderr, "Unknown output format image %s [only *.pnm, *.pgm, *.ppm, *.pgx or *.bmp]!! \n", outfile);
@@ -299,6 +301,9 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
case BMP_DFMT:
img_fol->out_format = "bmp";
break;
+ case TIF_DFMT:
+ img_fol->out_format = "tif";
+ break;
default:
fprintf(stderr, "Unknown output format image %s [only *.pnm, *.pgm, *.ppm, *.pgx or *.bmp]!! \n");
return 1;
@@ -484,7 +489,6 @@ int main(int argc, char **argv) {
int num_images;
int i,imageno;
dircnt_t *dirptr;
- char process_file = 1;
opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */
opj_cio_t *cio = NULL;
@@ -657,7 +661,7 @@ int main(int argc, char **argv) {
break;
default:
- fprintf(stderr, "False input image format skipping file..\n");
+ fprintf(stderr, "skipping file..\n");
continue;
}
@@ -667,26 +671,50 @@ int main(int argc, char **argv) {
/* create output image */
/* ------------------- */
- switch (parameters.cod_format) {
+ switch (parameters.cod_format) {
case PXM_DFMT: /* PNM PGM PPM */
- imagetopnm(image, parameters.outfile);
+ if (imagetopnm(image, parameters.outfile)) {
+ fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
+ }
+ else {
+ fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
+ }
break;
case PGX_DFMT: /* PGX */
- imagetopgx(image, parameters.outfile);
+ if(imagetopgx(image, parameters.outfile)){
+ fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
+ }
+ else {
+ fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
+ }
break;
case BMP_DFMT: /* BMP */
- imagetobmp(image, parameters.outfile);
- break;
+ if(imagetobmp(image, parameters.outfile)){
+ fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
+ }
+ else {
+ fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
+ break;
- /* free remaining structures */
- if(dinfo) {
- opj_destroy_decompress(dinfo);
+ case TIF_DFMT: /* TIFF */
+ if(imagetotif(image, parameters.outfile)){
+ fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
}
- /* free image data structure */
- opj_image_destroy(image);
+ else {
+ fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
+ }
+ break;
+ }
+
+ /* free remaining structures */
+ if(dinfo) {
+ opj_destroy_decompress(dinfo);
+ }
+ /* free image data structure */
+ opj_image_destroy(image);
}
return 0;