From ac9fb5a302c3f53d7bbce8e62c142ce275f8027d Mon Sep 17 00:00:00 2001 From: mayeut Date: Tue, 14 Jul 2015 23:51:02 +0200 Subject: [PATCH 01/10] Update tiftoimage to support more input TIF formats Update uclouvain/openjpeg#322 Update uclouvain/openjpeg#264 --- src/bin/jp2/CMakeLists.txt | 4 + src/bin/jp2/convert.c | 764 +--------------------------- src/bin/jp2/converttif.c | 984 +++++++++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 1 + 4 files changed, 990 insertions(+), 763 deletions(-) create mode 100644 src/bin/jp2/converttif.c diff --git a/src/bin/jp2/CMakeLists.txt b/src/bin/jp2/CMakeLists.txt index 4cf4aecf..95d1430d 100644 --- a/src/bin/jp2/CMakeLists.txt +++ b/src/bin/jp2/CMakeLists.txt @@ -8,6 +8,10 @@ set(common_SRCS ${OPENJPEG_SOURCE_DIR}/src/bin/common/color.c ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c ) + +if(OPJ_HAVE_LIBTIFF) + list(APPEND common_SRCS converttif.c) +endif() # Headers file are located here: include_directories( diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 5cde4fbd..bb8cfdac 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -149,6 +149,7 @@ void scale_component(opj_image_comp_t* component, OPJ_UINT32 precision) l_data[i] >>= shift; } } + component->bpp = precision; component->prec = precision; } @@ -1582,769 +1583,6 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0; return 0; }/* imagetopnm() */ -#ifdef OPJ_HAVE_LIBTIFF -/* -->> -->> -->> -->> - - TIFF IMAGE FORMAT - - <<-- <<-- <<-- <<-- */ - -int imagetotif(opj_image_t * image, const char *outfile) -{ - int width, height, imgsize; - int bps,index,adjust, sgnd; - int ushift, dshift, has_alpha, force16; - TIFF *tif; - tdata_t buf; - tstrip_t strip; - tsize_t strip_size; - - ushift = dshift = force16 = has_alpha = 0; - bps = (int)image->comps[0].prec; - - if(bps > 8 && bps < 16) - { - ushift = 16 - bps; dshift = bps - ushift; - bps = 16; force16 = 1; - } - - if(bps != 8 && bps != 16) - { - fprintf(stderr,"imagetotif: Bits=%d, Only 8 and 16 bits implemented\n", - bps); - fprintf(stderr,"\tAborting\n"); - return 1; - } - tif = TIFFOpen(outfile, "wb"); - - if (!tif) - { - fprintf(stderr, "imagetotif:failed to open %s for writing\n", outfile); - return 1; - } - sgnd = (int)image->comps[0].sgnd; - adjust = sgnd ? 1 << (image->comps[0].prec - 1) : 0; - - 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) - { - has_alpha = (image->numcomps == 4); - - width = (int)image->comps[0].w; - height = (int)image->comps[0].h; - imgsize = width * height ; - - TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width); - TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height); - TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3 + has_alpha); - 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); - strip_size = TIFFStripSize(tif); - buf = _TIFFmalloc(strip_size); - index=0; - - for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) - { - unsigned char *dat8; - tsize_t i, ssize, last_i = 0; - int step, restx; - ssize = TIFFStripSize(tif); - dat8 = (unsigned char*)buf; - - if(bps == 8) - { - step = 3 + has_alpha; - restx = step - 1; - - for(i=0; i < ssize - restx; i += step) - { - int r, g, b, a = 0; - - if(index < imgsize) - { - r = image->comps[0].data[index]; - g = image->comps[1].data[index]; - b = image->comps[2].data[index]; - if(has_alpha) a = image->comps[3].data[index]; - - if(sgnd) - { - r += adjust; - g += adjust; - b += adjust; - if(has_alpha) a += adjust; - } - if(r > 255) r = 255; else if(r < 0) r = 0; - dat8[i+0] = (unsigned char)r ; - if(g > 255) g = 255; else if(g < 0) g = 0; - dat8[i+1] = (unsigned char)g ; - if(b > 255) b = 255; else if(b < 0) b = 0; - dat8[i+2] = (unsigned char)b ; - if(has_alpha) - { - if(a > 255) a = 255; else if(a < 0) a = 0; - dat8[i+3] = (unsigned char)a; - } - - index++; - last_i = i + step; - } - else - break; - }/*for(i = 0;)*/ - - if(last_i < ssize) - { - for(i = last_i; i < ssize; i += step) - { - int r, g, b, a = 0; - - if(index < imgsize) - { - r = image->comps[0].data[index]; - g = image->comps[1].data[index]; - b = image->comps[2].data[index]; - if(has_alpha) a = image->comps[3].data[index]; - - if(sgnd) - { - r += adjust; - g += adjust; - b += adjust; - if(has_alpha) a += adjust; - } - if(r > 255) r = 255; else if(r < 0) r = 0; - if(g > 255) g = 255; else if(g < 0) g = 0; - if(b > 255) b = 255; else if(b < 0) b = 0; - - dat8[i+0] = (unsigned char)r ; - if(i+1 < ssize) dat8[i+1] = (unsigned char)g ; else break; - if(i+2 < ssize) dat8[i+2] = (unsigned char)b ; else break; - if(has_alpha) - { - if(a > 255) a = 255; else if(a < 0) a = 0; - - if(i+3 < ssize) dat8[i+3] = (unsigned char)a ; else break; - } - index++; - } - else - break; - }/*for(i)*/ - }/*if(last_i < ssize)*/ - - } /*if(bps == 8)*/ - else - if(bps == 16) - { - step = 6 + has_alpha + has_alpha; - restx = step - 1; - - for(i = 0; i < ssize - restx ; i += step) - { - int r, g, b, a = 0; - - if(index < imgsize) - { - r = image->comps[0].data[index]; - g = image->comps[1].data[index]; - b = image->comps[2].data[index]; - if(has_alpha) a = image->comps[3].data[index]; - - if(sgnd) - { - r += adjust; - g += adjust; - b += adjust; - if(has_alpha) a += adjust; - } - if(force16) - { - r = (r<>dshift); - g = (g<>dshift); - b = (b<>dshift); - if(has_alpha) a = (a<>dshift); - } - if(r > 65535) r = 65535; else if(r < 0) r = 0; - if(g > 65535) g = 65535; else if(g < 0) g = 0; - if(b > 65535) b = 65535; else if(b < 0) b = 0; - - dat8[i+0] = (unsigned char)r;/*LSB*/ - dat8[i+1] = (unsigned char)(r >> 8);/*MSB*/ - dat8[i+2] = (unsigned char)g; - dat8[i+3] = (unsigned char)(g >> 8); - dat8[i+4] = (unsigned char)b; - dat8[i+5] = (unsigned char)(b >> 8); - if(has_alpha) - { - if(a > 65535) a = 65535; else if(a < 0) a = 0; - dat8[i+6] = (unsigned char)a; - dat8[i+7] = (unsigned char)(a >> 8); - } - index++; - last_i = i + step; - } - else - break; - }/*for(i = 0;)*/ - - if(last_i < ssize) - { - for(i = last_i ; i < ssize ; i += step) - { - int r, g, b, a = 0; - - if(index < imgsize) - { - r = image->comps[0].data[index]; - g = image->comps[1].data[index]; - b = image->comps[2].data[index]; - if(has_alpha) a = image->comps[3].data[index]; - - if(sgnd) - { - r += adjust; - g += adjust; - b += adjust; - if(has_alpha) a += adjust; - } - if(force16) - { - r = (r<>dshift); - g = (g<>dshift); - b = (b<>dshift); - if(has_alpha) a = (a<>dshift); - } - if(r > 65535) r = 65535; else if(r < 0) r = 0; - if(g > 65535) g = 65535; else if(g < 0) g = 0; - if(b > 65535) b = 65535; else if(b < 0) b = 0; - - dat8[i+0] = (unsigned char) r;/*LSB*/ - if(i+1 < ssize) dat8[i+1] = (unsigned char)(r >> 8);else break;/*MSB*/ - if(i+2 < ssize) dat8[i+2] = (unsigned char) g; else break; - if(i+3 < ssize) dat8[i+3] = (unsigned char)(g >> 8);else break; - if(i+4 < ssize) dat8[i+4] = (unsigned char) b; else break; - if(i+5 < ssize) dat8[i+5] = (unsigned char)(b >> 8);else break; - - if(has_alpha) - { - if(a > 65535) a = 65535; else if(a < 0) a = 0; - if(i+6 < ssize) dat8[i+6] = (unsigned char)a; else break; - if(i+7 < ssize) dat8[i+7] = (unsigned char)(a >> 8); else break; - } - index++; - } - else - break; - }/*for(i)*/ - }/*if(last_i < ssize)*/ - - }/*if(bps == 16)*/ - (void)TIFFWriteEncodedStrip(tif, strip, (void*)buf, strip_size); - }/*for(strip = 0; )*/ - - _TIFFfree((void*)buf); - TIFFClose(tif); - - return 0; - }/*RGB(A)*/ - - if(image->numcomps == 1 /* GRAY */ - || ( image->numcomps == 2 /* GRAY_ALPHA */ - && image->comps[0].dx == image->comps[1].dx - && image->comps[0].dy == image->comps[1].dy - && image->comps[0].prec == image->comps[1].prec)) - { - int step; - - has_alpha = (image->numcomps == 2); - - width = (int)image->comps[0].w; - height = (int)image->comps[0].h; - imgsize = width * height; - - /* Set tags */ - TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width); - TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height); - TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1 + has_alpha); - 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 */ - strip_size = TIFFStripSize(tif); - buf = _TIFFmalloc(strip_size); - index = 0; - - for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) - { - unsigned char *dat8; - tsize_t i, ssize = TIFFStripSize(tif); - dat8 = (unsigned char*)buf; - - if(bps == 8) - { - step = 1 + has_alpha; - - for(i=0; i < ssize; i += step) - { - if(index < imgsize) - { - int r, a = 0; - - r = image->comps[0].data[index]; - if(has_alpha) a = image->comps[1].data[index]; - - if(sgnd) - { - r += adjust; - if(has_alpha) a += adjust; - } - if(r > 255) r = 255; else if(r < 0) r = 0; - dat8[i+0] = (unsigned char)r; - - if(has_alpha) - { - if(a > 255) a = 255; else if(a < 0) a = 0; - dat8[i+1] = (unsigned char)a; - } - index++; - } - else - break; - }/*for(i )*/ - }/*if(bps == 8*/ - else - if(bps == 16) - { - step = 2 + has_alpha + has_alpha; - - for(i=0; i < ssize; i += step) - { - if(index < imgsize) - { - int r, a = 0; - - r = image->comps[0].data[index]; - if(has_alpha) a = image->comps[1].data[index]; - - if(sgnd) - { - r += adjust; - if(has_alpha) a += adjust; - } - if(force16) - { - r = (r<>dshift); - if(has_alpha) a = (a<>dshift); - } - if(r > 65535) r = 65535; else if(r < 0) r = 0; - dat8[i+0] = (unsigned char)r;/*LSB*/ - dat8[i+1] = (unsigned char)(r >> 8);/*MSB*/ - if(has_alpha) - { - if(a > 65535) a = 65535; else if(a < 0) a = 0; - dat8[i+2] = (unsigned char)a; - dat8[i+3] = (unsigned char)(a >> 8); - } - index++; - }/*if(index < imgsize)*/ - else - break; - }/*for(i )*/ - } - (void)TIFFWriteEncodedStrip(tif, strip, (void*)buf, strip_size); - }/*for(strip*/ - - _TIFFfree(buf); - TIFFClose(tif); - - return 0; - } - - TIFFClose(tif); - - fprintf(stderr,"imagetotif: Bad color format.\n" - "\tOnly RGB(A) and GRAY(A) has been implemented\n"); - fprintf(stderr,"\tFOUND: numcomps(%d)\n\tAborting\n", - image->numcomps); - - return 1; -}/* imagetotif() */ - -/* - * libtiff/tif_getimage.c : 1,2,4,8,16 bitspersample accepted - * CINEMA : 12 bit precision -*/ -opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) -{ - int subsampling_dx = parameters->subsampling_dx; - int subsampling_dy = parameters->subsampling_dy; - TIFF *tif; - 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[4]; /* RGBA */ - opj_image_t *image = NULL; - int imgsize = 0; - int has_alpha = 0; - unsigned short tiBps, tiPhoto, tiSf, tiSpp, tiPC; - unsigned int tiWidth, tiHeight; - OPJ_BOOL is_cinema = OPJ_IS_CINEMA(parameters->rsiz); - - tif = TIFFOpen(filename, "r"); - - if(!tif) - { - fprintf(stderr, "tiftoimage:Failed to open %s for reading\n", filename); - return 0; - } - tiBps = tiPhoto = tiSf = tiSpp = tiPC = 0; - tiWidth = tiHeight = 0; - - TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &tiWidth); - TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &tiHeight); - TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &tiBps); - TIFFGetField(tif, TIFFTAG_SAMPLEFORMAT, &tiSf); - TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &tiSpp); - TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &tiPhoto); - TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &tiPC); - w= (int)tiWidth; - h= (int)tiHeight; - - if(tiBps != 8 && tiBps != 16 && tiBps != 12) tiBps = 0; - if(tiPhoto != 1 && tiPhoto != 2) tiPhoto = 0; - - if( !tiBps || !tiPhoto) - { - if( !tiBps) - fprintf(stderr,"tiftoimage: Bits=%d, Only 8 and 16 bits" - " implemented\n",tiBps); - else - if( !tiPhoto) - fprintf(stderr,"tiftoimage: Bad color format %d.\n\tOnly RGB(A)" - " and GRAY(A) has been implemented\n",(int) tiPhoto); - - fprintf(stderr,"\tAborting\n"); - TIFFClose(tif); - - return NULL; - } - - {/* From: tiff-4.0.x/libtiff/tif_getimage.c : */ - uint16* sampleinfo; - uint16 extrasamples; - - TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, - &extrasamples, &sampleinfo); - - if(extrasamples >= 1) - { - switch(sampleinfo[0]) - { - case EXTRASAMPLE_UNSPECIFIED: - /* Workaround for some images without correct info about alpha channel -*/ - if(tiSpp > 3) - has_alpha = 1; - break; - - case EXTRASAMPLE_ASSOCALPHA: /* data pre-multiplied */ - case EXTRASAMPLE_UNASSALPHA: /* data not pre-multiplied */ - has_alpha = 1; - break; - } - } - else /* extrasamples == 0 */ - if(tiSpp == 4 || tiSpp == 2) has_alpha = 1; - } - - /* initialize image components -*/ - memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t)); - - if ((tiPhoto == PHOTOMETRIC_RGB) && (is_cinema)) { - fprintf(stdout,"WARNING:\n" - "Input image bitdepth is %d bits\n" - "TIF conversion has automatically rescaled to 12-bits\n" - "to comply with cinema profiles.\n", - tiBps); - } - - if(tiPhoto == PHOTOMETRIC_RGB) /* RGB(A) */ - { - numcomps = 3 + has_alpha; - color_space = OPJ_CLRSPC_SRGB; - - /*#define USETILEMODE*/ - for(j = 0; j < numcomps; j++) - { - if(is_cinema) - { - cmptparm[j].prec = 12; - cmptparm[j].bpp = 12; - } - else - { - cmptparm[j].prec = tiBps; - cmptparm[j].bpp = tiBps; - } - cmptparm[j].dx = (OPJ_UINT32)subsampling_dx; - cmptparm[j].dy = (OPJ_UINT32)subsampling_dy; - cmptparm[j].w = (OPJ_UINT32)w; - cmptparm[j].h = (OPJ_UINT32)h; -#ifdef USETILEMODE - cmptparm[j].x0 = 0; - cmptparm[j].y0 = 0; -#endif - } - -#ifdef USETILEMODE - image = opj_image_tile_create(numcomps,&cmptparm[0],color_space); -#else - image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space); -#endif - - if(!image) - { - TIFFClose(tif); - return NULL; - } - /* set image offset and reference grid -*/ - image->x0 = (OPJ_UINT32)parameters->image_offset_x0; - image->y0 = (OPJ_UINT32)parameters->image_offset_y0; - image->x1 = !image->x0 ? (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1 : - image->x0 + (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1; - image->y1 = !image->y0 ? (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1 : - image->y0 + (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1; - - buf = _TIFFmalloc(TIFFStripSize(tif)); - - strip_size=TIFFStripSize(tif); - index = 0; - imgsize = (int)(image->comps[0].w * image->comps[0].h); - /* Read the Image components -*/ - for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) - { - unsigned char *dat8; - int step; - tsize_t i, ssize; - ssize = TIFFReadEncodedStrip(tif, strip, buf, strip_size); - dat8 = (unsigned char*)buf; - - if(tiBps == 16) - { - step = 6 + has_alpha + has_alpha; - - for(i = 0; i < ssize; i += step) - { - if(index < imgsize) - { - 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 */ - if(has_alpha) - image->comps[3].data[index] = ( dat8[i+7] << 8 ) | dat8[i+6]; - - if(is_cinema) - { - /* Rounding 16 to 12 bits -*/ - image->comps[0].data[index] = - (image->comps[0].data[index] + 0x08) >> 4 ; - image->comps[1].data[index] = - (image->comps[1].data[index] + 0x08) >> 4 ; - image->comps[2].data[index] = - (image->comps[2].data[index] + 0x08) >> 4 ; - if(has_alpha) - image->comps[3].data[index] = - (image->comps[3].data[index] + 0x08) >> 4 ; - } - index++; - } - else - break; - }/*for(i = 0)*/ - }/*if(tiBps == 16)*/ - else - if(tiBps == 8) - { - step = 3 + has_alpha; - - for(i = 0; i < ssize; i += step) - { - if(index < imgsize) - { -#ifndef USETILEMODE - 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 */ - if(has_alpha) - image->comps[3].data[index] = dat8[i+3]; -#endif - - if(is_cinema) - { - /* Rounding 8 to 12 bits -*/ -#ifndef USETILEMODE - image->comps[0].data[index] = image->comps[0].data[index] << 4 ; - image->comps[1].data[index] = image->comps[1].data[index] << 4 ; - image->comps[2].data[index] = image->comps[2].data[index] << 4 ; - if(has_alpha) - image->comps[3].data[index] = image->comps[3].data[index] << 4 ; -#endif - } - index++; - }/*if(index*/ - else - break; - }/*for(i )*/ - }/*if( tiBps == 8)*/ - else - if(tiBps == 12)/* CINEMA file */ - { - step = 9; - - for(i = 0; i < ssize; i += step) - { - if((index < imgsize)&&(index+1 < imgsize)) - { - 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; - }/*for(i )*/ - } - }/*for(strip = 0; )*/ - - _TIFFfree(buf); - TIFFClose(tif); - - return image; - }/*RGB(A)*/ - - if(tiPhoto == PHOTOMETRIC_MINISBLACK) /* GRAY(A) */ - { - numcomps = 1 + has_alpha; - color_space = OPJ_CLRSPC_GRAY; - - for(j = 0; j < numcomps; ++j) - { - cmptparm[j].prec = tiBps; - cmptparm[j].bpp = tiBps; - cmptparm[j].dx = (OPJ_UINT32)subsampling_dx; - cmptparm[j].dy = (OPJ_UINT32)subsampling_dy; - cmptparm[j].w = (OPJ_UINT32)w; - cmptparm[j].h = (OPJ_UINT32)h; - } -#ifdef USETILEMODE - image = opj_image_tile_create(numcomps,&cmptparm[0],color_space); -#else - image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space); -#endif - - if(!image) - { - TIFFClose(tif); - return NULL; - } - /* set image offset and reference grid -*/ - image->x0 = (OPJ_UINT32)parameters->image_offset_x0; - image->y0 = (OPJ_UINT32)parameters->image_offset_y0; - image->x1 = !image->x0 ? (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1 : - image->x0 + (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1; - image->y1 = !image->y0 ? (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1 : - image->y0 + (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1; - - buf = _TIFFmalloc(TIFFStripSize(tif)); - - strip_size = TIFFStripSize(tif); - index = 0; - imgsize = (int)(image->comps[0].w * image->comps[0].h); - /* Read the Image components -*/ - for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) - { - unsigned char *dat8; - tsize_t i, ssize; - int step; - - ssize = TIFFReadEncodedStrip(tif, strip, buf, strip_size); - dat8 = (unsigned char*)buf; - - if(tiBps == 16) - { - step = 2 + has_alpha + has_alpha; - - for(i = 0; i < ssize; i += step) - { - if(index < imgsize) - { - image->comps[0].data[index] = ( dat8[i+1] << 8 ) | dat8[i+0]; - if(has_alpha) - image->comps[1].data[index] = ( dat8[i+3] << 8 ) | dat8[i+2]; - index++; - } - else - break; - }/*for(i )*/ - } - else - if(tiBps == 8) - { - step = 1 + has_alpha; - - for(i = 0; i < ssize; i += step) - { - if(index < imgsize) - { - image->comps[0].data[index] = dat8[i+0]; - if(has_alpha) - image->comps[1].data[index] = dat8[i+1]; - index++; - } - else - break; - }/*for(i )*/ - } - }/*for(strip = 0;*/ - - _TIFFfree(buf); - TIFFClose(tif); - - }/*GRAY(A)*/ - - return image; - -}/* tiftoimage() */ - -#endif /* OPJ_HAVE_LIBTIFF */ - /* -->> -->> -->> -->> RAW IMAGE FORMAT diff --git a/src/bin/jp2/converttif.c b/src/bin/jp2/converttif.c new file mode 100644 index 00000000..85fc2b97 --- /dev/null +++ b/src/bin/jp2/converttif.c @@ -0,0 +1,984 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2014, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux + * Copyright (c) 2003-2014, Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2006-2007, Parvatha Elangovan + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include "opj_apps_config.h" + +#include +#include +#include +#include + +#ifndef OPJ_HAVE_LIBTIFF +# error OPJ_HAVE_LIBTIFF_NOT_DEFINED +#endif /* OPJ_HAVE_LIBTIFF */ + +#include +#include "openjpeg.h" +#include "convert.h" + +/* -->> -->> -->> -->> + + TIFF IMAGE FORMAT + + <<-- <<-- <<-- <<-- */ + +int imagetotif(opj_image_t * image, const char *outfile) +{ + int width, height, imgsize; + int bps,index,adjust, sgnd; + int ushift, dshift, has_alpha, force16; + TIFF *tif; + tdata_t buf; + tstrip_t strip; + tsize_t strip_size; + + ushift = dshift = force16 = has_alpha = 0; + bps = (int)image->comps[0].prec; + + if(bps > 8 && bps < 16) + { + ushift = 16 - bps; dshift = bps - ushift; + bps = 16; force16 = 1; + } + + if(bps != 8 && bps != 16) + { + fprintf(stderr,"imagetotif: Bits=%d, Only 8 and 16 bits implemented\n", + bps); + fprintf(stderr,"\tAborting\n"); + return 1; + } + tif = TIFFOpen(outfile, "wb"); + + if (!tif) + { + fprintf(stderr, "imagetotif:failed to open %s for writing\n", outfile); + return 1; + } + sgnd = (int)image->comps[0].sgnd; + adjust = sgnd ? 1 << (image->comps[0].prec - 1) : 0; + + 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) + { + has_alpha = (image->numcomps == 4); + + width = (int)image->comps[0].w; + height = (int)image->comps[0].h; + imgsize = width * height ; + + TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width); + TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height); + TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3 + has_alpha); + 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); + strip_size = TIFFStripSize(tif); + buf = _TIFFmalloc(strip_size); + index=0; + + for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) + { + unsigned char *dat8; + tsize_t i, ssize, last_i = 0; + int step, restx; + ssize = TIFFStripSize(tif); + dat8 = (unsigned char*)buf; + + if(bps == 8) + { + step = 3 + has_alpha; + restx = step - 1; + + for(i=0; i < ssize - restx; i += step) + { + int r, g, b, a = 0; + + if(index < imgsize) + { + r = image->comps[0].data[index]; + g = image->comps[1].data[index]; + b = image->comps[2].data[index]; + if(has_alpha) a = image->comps[3].data[index]; + + if(sgnd) + { + r += adjust; + g += adjust; + b += adjust; + if(has_alpha) a += adjust; + } + if(r > 255) r = 255; else if(r < 0) r = 0; + dat8[i+0] = (unsigned char)r ; + if(g > 255) g = 255; else if(g < 0) g = 0; + dat8[i+1] = (unsigned char)g ; + if(b > 255) b = 255; else if(b < 0) b = 0; + dat8[i+2] = (unsigned char)b ; + if(has_alpha) + { + if(a > 255) a = 255; else if(a < 0) a = 0; + dat8[i+3] = (unsigned char)a; + } + + index++; + last_i = i + step; + } + else + break; + }/*for(i = 0;)*/ + + if(last_i < ssize) + { + for(i = last_i; i < ssize; i += step) + { + int r, g, b, a = 0; + + if(index < imgsize) + { + r = image->comps[0].data[index]; + g = image->comps[1].data[index]; + b = image->comps[2].data[index]; + if(has_alpha) a = image->comps[3].data[index]; + + if(sgnd) + { + r += adjust; + g += adjust; + b += adjust; + if(has_alpha) a += adjust; + } + if(r > 255) r = 255; else if(r < 0) r = 0; + if(g > 255) g = 255; else if(g < 0) g = 0; + if(b > 255) b = 255; else if(b < 0) b = 0; + + dat8[i+0] = (unsigned char)r ; + if(i+1 < ssize) dat8[i+1] = (unsigned char)g ; else break; + if(i+2 < ssize) dat8[i+2] = (unsigned char)b ; else break; + if(has_alpha) + { + if(a > 255) a = 255; else if(a < 0) a = 0; + + if(i+3 < ssize) dat8[i+3] = (unsigned char)a ; else break; + } + index++; + } + else + break; + }/*for(i)*/ + }/*if(last_i < ssize)*/ + + } /*if(bps == 8)*/ + else + if(bps == 16) + { + step = 6 + has_alpha + has_alpha; + restx = step - 1; + + for(i = 0; i < ssize - restx ; i += step) + { + int r, g, b, a = 0; + + if(index < imgsize) + { + r = image->comps[0].data[index]; + g = image->comps[1].data[index]; + b = image->comps[2].data[index]; + if(has_alpha) a = image->comps[3].data[index]; + + if(sgnd) + { + r += adjust; + g += adjust; + b += adjust; + if(has_alpha) a += adjust; + } + if(force16) + { + r = (r<>dshift); + g = (g<>dshift); + b = (b<>dshift); + if(has_alpha) a = (a<>dshift); + } + if(r > 65535) r = 65535; else if(r < 0) r = 0; + if(g > 65535) g = 65535; else if(g < 0) g = 0; + if(b > 65535) b = 65535; else if(b < 0) b = 0; + + dat8[i+0] = (unsigned char)r;/*LSB*/ + dat8[i+1] = (unsigned char)(r >> 8);/*MSB*/ + dat8[i+2] = (unsigned char)g; + dat8[i+3] = (unsigned char)(g >> 8); + dat8[i+4] = (unsigned char)b; + dat8[i+5] = (unsigned char)(b >> 8); + if(has_alpha) + { + if(a > 65535) a = 65535; else if(a < 0) a = 0; + dat8[i+6] = (unsigned char)a; + dat8[i+7] = (unsigned char)(a >> 8); + } + index++; + last_i = i + step; + } + else + break; + }/*for(i = 0;)*/ + + if(last_i < ssize) + { + for(i = last_i ; i < ssize ; i += step) + { + int r, g, b, a = 0; + + if(index < imgsize) + { + r = image->comps[0].data[index]; + g = image->comps[1].data[index]; + b = image->comps[2].data[index]; + if(has_alpha) a = image->comps[3].data[index]; + + if(sgnd) + { + r += adjust; + g += adjust; + b += adjust; + if(has_alpha) a += adjust; + } + if(force16) + { + r = (r<>dshift); + g = (g<>dshift); + b = (b<>dshift); + if(has_alpha) a = (a<>dshift); + } + if(r > 65535) r = 65535; else if(r < 0) r = 0; + if(g > 65535) g = 65535; else if(g < 0) g = 0; + if(b > 65535) b = 65535; else if(b < 0) b = 0; + + dat8[i+0] = (unsigned char) r;/*LSB*/ + if(i+1 < ssize) dat8[i+1] = (unsigned char)(r >> 8);else break;/*MSB*/ + if(i+2 < ssize) dat8[i+2] = (unsigned char) g; else break; + if(i+3 < ssize) dat8[i+3] = (unsigned char)(g >> 8);else break; + if(i+4 < ssize) dat8[i+4] = (unsigned char) b; else break; + if(i+5 < ssize) dat8[i+5] = (unsigned char)(b >> 8);else break; + + if(has_alpha) + { + if(a > 65535) a = 65535; else if(a < 0) a = 0; + if(i+6 < ssize) dat8[i+6] = (unsigned char)a; else break; + if(i+7 < ssize) dat8[i+7] = (unsigned char)(a >> 8); else break; + } + index++; + } + else + break; + }/*for(i)*/ + }/*if(last_i < ssize)*/ + + }/*if(bps == 16)*/ + (void)TIFFWriteEncodedStrip(tif, strip, (void*)buf, strip_size); + }/*for(strip = 0; )*/ + + _TIFFfree((void*)buf); + TIFFClose(tif); + + return 0; + }/*RGB(A)*/ + + if(image->numcomps == 1 /* GRAY */ + || ( image->numcomps == 2 /* GRAY_ALPHA */ + && image->comps[0].dx == image->comps[1].dx + && image->comps[0].dy == image->comps[1].dy + && image->comps[0].prec == image->comps[1].prec)) + { + int step; + + has_alpha = (image->numcomps == 2); + + width = (int)image->comps[0].w; + height = (int)image->comps[0].h; + imgsize = width * height; + + /* Set tags */ + TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width); + TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height); + TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1 + has_alpha); + 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 */ + strip_size = TIFFStripSize(tif); + buf = _TIFFmalloc(strip_size); + index = 0; + + for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) + { + unsigned char *dat8; + tsize_t i, ssize = TIFFStripSize(tif); + dat8 = (unsigned char*)buf; + + if(bps == 8) + { + step = 1 + has_alpha; + + for(i=0; i < ssize; i += step) + { + if(index < imgsize) + { + int r, a = 0; + + r = image->comps[0].data[index]; + if(has_alpha) a = image->comps[1].data[index]; + + if(sgnd) + { + r += adjust; + if(has_alpha) a += adjust; + } + if(r > 255) r = 255; else if(r < 0) r = 0; + dat8[i+0] = (unsigned char)r; + + if(has_alpha) + { + if(a > 255) a = 255; else if(a < 0) a = 0; + dat8[i+1] = (unsigned char)a; + } + index++; + } + else + break; + }/*for(i )*/ + }/*if(bps == 8*/ + else + if(bps == 16) + { + step = 2 + has_alpha + has_alpha; + + for(i=0; i < ssize; i += step) + { + if(index < imgsize) + { + int r, a = 0; + + r = image->comps[0].data[index]; + if(has_alpha) a = image->comps[1].data[index]; + + if(sgnd) + { + r += adjust; + if(has_alpha) a += adjust; + } + if(force16) + { + r = (r<>dshift); + if(has_alpha) a = (a<>dshift); + } + if(r > 65535) r = 65535; else if(r < 0) r = 0; + dat8[i+0] = (unsigned char)r;/*LSB*/ + dat8[i+1] = (unsigned char)(r >> 8);/*MSB*/ + if(has_alpha) + { + if(a > 65535) a = 65535; else if(a < 0) a = 0; + dat8[i+2] = (unsigned char)a; + dat8[i+3] = (unsigned char)(a >> 8); + } + index++; + }/*if(index < imgsize)*/ + else + break; + }/*for(i )*/ + } + (void)TIFFWriteEncodedStrip(tif, strip, (void*)buf, strip_size); + }/*for(strip*/ + + _TIFFfree(buf); + TIFFClose(tif); + + return 0; + } + + TIFFClose(tif); + + fprintf(stderr,"imagetotif: Bad color format.\n" + "\tOnly RGB(A) and GRAY(A) has been implemented\n"); + fprintf(stderr,"\tFOUND: numcomps(%d)\n\tAborting\n", + image->numcomps); + + return 1; +}/* imagetotif() */ + +typedef void (* tif_Xto32s)(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length); + +static void tif_1uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)8U); i+=8U) { + OPJ_UINT8 val = *pSrc++; + pDst[i+0] = val >> 7; + pDst[i+1] = (val >> 6) & 0x1U; + pDst[i+2] = (val >> 5) & 0x1U; + pDst[i+3] = (val >> 4) & 0x1U; + pDst[i+4] = (val >> 3) & 0x1U; + pDst[i+5] = (val >> 2) & 0x1U; + pDst[i+6] = (val >> 1) & 0x1U; + pDst[i+7] = val & 0x1U; + } + if (length & 7U) { + OPJ_UINT8 val = *pSrc++; + length = length & 7U; + pDst[i+0] = val >> 7; + + if (length > 1U) { + pDst[i+1] = (val >> 6) & 0x1U; + if (length > 2U) { + pDst[i+2] = (val >> 5) & 0x1U; + if (length > 3U) { + pDst[i+3] = (val >> 4) & 0x1U; + if (length > 4U) { + pDst[i+4] = (val >> 3) & 0x1U; + if (length > 5U) { + pDst[i+5] = (val >> 2) & 0x1U; + if (length > 6U) { + pDst[i+6] = (val >> 1) & 0x1U; + } + } + } + } + } + } + } +} +static void tif_2uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)4U); i+=4U) { + OPJ_UINT8 val = *pSrc++; + pDst[i+0] = val >> 6; + pDst[i+1] = (val >> 4) & 0x3U; + pDst[i+2] = (val >> 2) & 0x3U; + pDst[i+3] = val & 0x3U; + } + if (length & 3U) { + OPJ_UINT8 val = *pSrc++; + length = length & 3U; + pDst[i+0] = val >> 6; + + if (length > 1U) { + pDst[i+1] = (val >> 4) & 0x3U; + if (length > 2U) { + pDst[i+2] = (val >> 2) & 0x3U; + + } + } + } +} +static void tif_4uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)2U); i+=2U) { + OPJ_UINT8 val = *pSrc++; + pDst[i+0] = val >> 4; + pDst[i+1] = val & 0xFU; + } + if (length & 1U) { + OPJ_UINT8 val = *pSrc++; + pDst[i+0] = val >> 4; + } +} +static void tif_6uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)4U); i+=4U) { + OPJ_UINT8 val0 = *pSrc++; + OPJ_UINT8 val1 = *pSrc++; + OPJ_UINT8 val2 = *pSrc++; + pDst[i+0] = val0 >> 2; + pDst[i+1] = ((val0 & 0x3U) << 4) | (val1 >> 4); + pDst[i+2] = ((val1 & 0xFU) << 2) | (val2 >> 6); + pDst[i+3] = val2 & 0x3FU; + + } + if (length & 3U) { + OPJ_UINT8 val0 = *pSrc++; + length = length & 3U; + pDst[i+0] = val0 >> 2; + + if (length > 1U) { + OPJ_UINT8 val1 = *pSrc++; + pDst[i+1] = ((val0 & 0x3U) << 4) | (val1 >> 4); + if (length > 2U) { + OPJ_UINT8 val2 = *pSrc++; + pDst[i+2] = ((val1 & 0xFU) << 2) | (val2 >> 6); + } + } + } +} +static void tif_8uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < length; ++i) { + pDst[i] = pSrc[i]; + } +} +static void tif_10uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)4U); i+=4U) { + OPJ_INT32 val0 = *pSrc++; + OPJ_INT32 val1 = *pSrc++; + OPJ_INT32 val2 = *pSrc++; + OPJ_INT32 val3 = *pSrc++; + OPJ_INT32 val4 = *pSrc++; + + pDst[i+0] = (val0 << 2) | (val1 >> 6); + pDst[i+1] = ((val1 & 0x3FU) << 4) | (val2 >> 4); + pDst[i+2] = ((val2 & 0xFU) << 6) | (val3 >> 2); + pDst[i+3] = ((val3 & 0x3U) << 8) | val4; + + } + if (length & 3U) { + OPJ_INT32 val0 = *pSrc++; + OPJ_INT32 val1 = *pSrc++; + length = length & 3U; + pDst[i+0] = (val0 << 2) | (val1 >> 6); + + if (length > 1U) { + OPJ_INT32 val2 = *pSrc++; + pDst[i+1] = ((val1 & 0x3FU) << 4) | (val2 >> 4); + if (length > 2U) { + OPJ_INT32 val3 = *pSrc++; + pDst[i+2] = ((val2 & 0xFU) << 6) | (val3 >> 2); + } + } + } +} +static void tif_12uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)2U); i+=2U) { + OPJ_INT32 val0 = *pSrc++; + OPJ_INT32 val1 = *pSrc++; + OPJ_INT32 val2 = *pSrc++; + + pDst[i+0] = (val0 << 4) | (val1 >> 4); + pDst[i+1] = ((val1 & 0xFU) << 8) | val2; + } + if (length & 1U) { + OPJ_INT32 val0 = *pSrc++; + OPJ_INT32 val1 = *pSrc++; + pDst[i+0] = (val0 << 4) | (val1 >> 4); + } +} +static void tif_14uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)4U); i+=4U) { + OPJ_INT32 val0 = *pSrc++; + OPJ_INT32 val1 = *pSrc++; + OPJ_INT32 val2 = *pSrc++; + OPJ_INT32 val3 = *pSrc++; + OPJ_INT32 val4 = *pSrc++; + OPJ_INT32 val5 = *pSrc++; + OPJ_INT32 val6 = *pSrc++; + + pDst[i+0] = (val0 << 6) | (val1 >> 2); + pDst[i+1] = ((val1 & 0x3U) << 12) | (val2 << 4) | (val3 >> 4); + pDst[i+2] = ((val3 & 0xFU) << 10) | (val4 << 2) | (val5 >> 6); + pDst[i+3] = ((val5 & 0x3FU) << 8) | val6; + + } + if (length & 3U) { + OPJ_INT32 val0 = *pSrc++; + OPJ_INT32 val1 = *pSrc++; + length = length & 3U; + pDst[i+0] = (val0 << 6) | (val1 >> 2); + + if (length > 1U) { + OPJ_INT32 val2 = *pSrc++; + OPJ_INT32 val3 = *pSrc++; + pDst[i+1] = ((val1 & 0x3U) << 12) | (val2 << 4) | (val3 >> 4); + if (length > 2U) { + OPJ_INT32 val4 = *pSrc++; + OPJ_INT32 val5 = *pSrc++; + pDst[i+2] = ((val3 & 0xFU) << 10) | (val4 << 2) | (val5 >> 6); + } + } + } +} +#if 0 +static void tif_16uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < length; i++) { + OPJ_INT32 val0 = *pSrc++; + OPJ_INT32 val1 = *pSrc++; +#ifdef OPJ_BIG_ENDIAN + pDst[i] = (val0 << 8) | val1; +#else + pDst[i] = (val1 << 8) | val0; +#endif + } +} +#else +/* seems that libtiff decodes this to machine endianness */ +static void tif_16uto32s(const OPJ_UINT16* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < length; i++) { + pDst[i] = pSrc[i]; + } +} +#endif + +typedef void (* convert_32s_CXPX)(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, OPJ_SIZE_T length); +static void convert_32s_C1P1(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, OPJ_SIZE_T length) +{ + memcpy(pDst[0], pSrc, length * sizeof(OPJ_INT32)); +} +static void convert_32s_C2P2(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + OPJ_INT32* pDst0 = pDst[0]; + OPJ_INT32* pDst1 = pDst[1]; + + for (i = 0; i < length; i++) { + pDst0[i] = pSrc[2*i+0]; + pDst1[i] = pSrc[2*i+1]; + } +} +static void convert_32s_C3P3(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + OPJ_INT32* pDst0 = pDst[0]; + OPJ_INT32* pDst1 = pDst[1]; + OPJ_INT32* pDst2 = pDst[2]; + + for (i = 0; i < length; i++) { + pDst0[i] = pSrc[3*i+0]; + pDst1[i] = pSrc[3*i+1]; + pDst2[i] = pSrc[3*i+2]; + } +} +static void convert_32s_C4P4(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + OPJ_INT32* pDst0 = pDst[0]; + OPJ_INT32* pDst1 = pDst[1]; + OPJ_INT32* pDst2 = pDst[2]; + OPJ_INT32* pDst3 = pDst[3]; + + for (i = 0; i < length; i++) { + pDst0[i] = pSrc[4*i+0]; + pDst1[i] = pSrc[4*i+1]; + pDst2[i] = pSrc[4*i+2]; + pDst3[i] = pSrc[4*i+3]; + } +} + + +/* + * libtiff/tif_getimage.c : 1,2,4,8,16 bitspersample accepted + * CINEMA : 12 bit precision + */ +opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) +{ + int subsampling_dx = parameters->subsampling_dx; + int subsampling_dy = parameters->subsampling_dy; + TIFF *tif; + tdata_t buf; + tstrip_t strip; + tsize_t strip_size; + int j, currentPlane, numcomps = 0, w, h; + OPJ_COLOR_SPACE color_space; + opj_image_cmptparm_t cmptparm[4]; /* RGBA */ + opj_image_t *image = NULL; + int has_alpha = 0; + unsigned short tiBps, tiPhoto, tiSf, tiSpp, tiPC; + unsigned int tiWidth, tiHeight; + OPJ_BOOL is_cinema = OPJ_IS_CINEMA(parameters->rsiz); + tif_Xto32s cvtTifTo32s = NULL; + convert_32s_CXPX cvtCxToPx = NULL; + OPJ_INT32* buffer32s = NULL; + OPJ_INT32* planes[4]; + OPJ_SIZE_T rowStride; + + tif = TIFFOpen(filename, "r"); + + if(!tif) + { + fprintf(stderr, "tiftoimage:Failed to open %s for reading\n", filename); + return 0; + } + tiBps = tiPhoto = tiSf = tiSpp = tiPC = 0; + tiWidth = tiHeight = 0; + + TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &tiWidth); + TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &tiHeight); + TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &tiBps); + TIFFGetField(tif, TIFFTAG_SAMPLEFORMAT, &tiSf); + TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &tiSpp); + TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &tiPhoto); + TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &tiPC); + w= (int)tiWidth; + h= (int)tiHeight; + + if((tiBps > 16U) || ((tiBps != 1U) && (tiBps & 1U))) tiBps = 0U; + if(tiPhoto != PHOTOMETRIC_MINISBLACK && tiPhoto != PHOTOMETRIC_RGB) tiPhoto = 0; + + if( !tiBps || !tiPhoto) + { + if( !tiBps) + fprintf(stderr,"tiftoimage: Bits=%d, Only 1, 2, 4, 6, 8, 10, 12, 14 and 16 bits implemented\n",tiBps); + else + if( !tiPhoto) + fprintf(stderr,"tiftoimage: Bad color format %d.\n\tOnly RGB(A)" + " and GRAY(A) has been implemented\n",(int) tiPhoto); + + fprintf(stderr,"\tAborting\n"); + TIFFClose(tif); + return NULL; + } + + switch (tiBps) { + case 1: + cvtTifTo32s = tif_1uto32s; + break; + case 2: + cvtTifTo32s = tif_2uto32s; + break; + case 4: + cvtTifTo32s = tif_4uto32s; + break; + case 6: + cvtTifTo32s = tif_6uto32s; + break; + case 8: + cvtTifTo32s = tif_8uto32s; + break; + case 10: + cvtTifTo32s = tif_10uto32s; + break; + case 12: + cvtTifTo32s = tif_12uto32s; + break; + case 14: + cvtTifTo32s = tif_14uto32s; + break; + case 16: + cvtTifTo32s = (tif_Xto32s)tif_16uto32s; + break; + default: + /* never here */ + break; + } + + {/* From: tiff-4.0.x/libtiff/tif_getimage.c : */ + uint16* sampleinfo; + uint16 extrasamples; + + TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, + &extrasamples, &sampleinfo); + + if(extrasamples >= 1) + { + switch(sampleinfo[0]) + { + case EXTRASAMPLE_UNSPECIFIED: + /* Workaround for some images without correct info about alpha channel + */ + if(tiSpp > 3) + has_alpha = 1; + break; + + case EXTRASAMPLE_ASSOCALPHA: /* data pre-multiplied */ + case EXTRASAMPLE_UNASSALPHA: /* data not pre-multiplied */ + has_alpha = 1; + break; + } + } + else /* extrasamples == 0 */ + if(tiSpp == 4 || tiSpp == 2) has_alpha = 1; + } + + /* initialize image components + */ + memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t)); + + if ((tiPhoto == PHOTOMETRIC_RGB) && (is_cinema) && (tiBps != 12U)) { + fprintf(stdout,"WARNING:\n" + "Input image bitdepth is %d bits\n" + "TIF conversion has automatically rescaled to 12-bits\n" + "to comply with cinema profiles.\n", + tiBps); + } else { + is_cinema = 0U; + } + + if(tiPhoto == PHOTOMETRIC_RGB) /* RGB(A) */ + { + numcomps = 3 + has_alpha; + color_space = OPJ_CLRSPC_SRGB; + } + else if (tiPhoto == PHOTOMETRIC_MINISBLACK) /* GRAY(A) */ + { + numcomps = 1 + has_alpha; + color_space = OPJ_CLRSPC_GRAY; + } + + switch (numcomps) { + case 1: + cvtCxToPx = convert_32s_C1P1; + break; + case 2: + cvtCxToPx = convert_32s_C2P2; + break; + case 3: + cvtCxToPx = convert_32s_C3P3; + break; + case 4: + cvtCxToPx = convert_32s_C4P4; + break; + default: + /* never here */ + break; + } + if (tiPC == PLANARCONFIG_SEPARATE) { + cvtCxToPx = convert_32s_C1P1; /* override */ + tiSpp = 1U; /* consider only one sample per plane */ + } + + for(j = 0; j < numcomps; j++) + { + cmptparm[j].prec = tiBps; + cmptparm[j].bpp = tiBps; + cmptparm[j].dx = (OPJ_UINT32)subsampling_dx; + cmptparm[j].dy = (OPJ_UINT32)subsampling_dy; + cmptparm[j].w = (OPJ_UINT32)w; + cmptparm[j].h = (OPJ_UINT32)h; + } + + image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space); + if(!image) + { + TIFFClose(tif); + return NULL; + } + /* set image offset and reference grid */ + image->x0 = (OPJ_UINT32)parameters->image_offset_x0; + image->y0 = (OPJ_UINT32)parameters->image_offset_y0; + image->x1 = !image->x0 ? (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1 : + image->x0 + (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1; + image->y1 = !image->y0 ? (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1 : + image->y0 + (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1; + + for(j = 0; j < numcomps; j++) + { + planes[j] = image->comps[j].data; + if (has_alpha) { + planes[j] = image->comps[j].data; + } + } + + strip_size = TIFFStripSize(tif); + + buf = _TIFFmalloc(strip_size); + if (buf == NULL) { + TIFFClose(tif); + opj_image_destroy(image); + return NULL; + } + rowStride = ((OPJ_SIZE_T)w * tiSpp * tiBps + 7U) / 8U; + buffer32s = malloc((OPJ_SIZE_T)w * tiSpp * sizeof(OPJ_INT32)); + if (buffer32s == NULL) { + _TIFFfree(buf); + TIFFClose(tif); + opj_image_destroy(image); + return NULL; + } + + strip = 0; + currentPlane = 0; + do + { + planes[0] = image->comps[currentPlane].data; /* to manage planar data */ + h= (int)tiHeight; + /* Read the Image components */ + for(; (h > 0) && (strip < TIFFNumberOfStrips(tif)); strip++) + { + const OPJ_UINT8 *dat8; + tsize_t ssize; + + ssize = TIFFReadEncodedStrip(tif, strip, buf, strip_size); + dat8 = (const OPJ_UINT8*)buf; + + while (ssize >= rowStride) { + cvtTifTo32s(dat8, buffer32s, w * tiSpp); + cvtCxToPx(buffer32s, planes, w); + planes[0] += w; + planes[1] += w; + planes[2] += w; + planes[3] += w; + dat8 += rowStride; + ssize -= rowStride; + h--; + } + } + currentPlane++; + } while ((tiPC == PLANARCONFIG_SEPARATE) && (currentPlane < numcomps)); + + free(buffer32s); + _TIFFfree(buf); + TIFFClose(tif); + + if (is_cinema) { + for (j=0; j < numcomps; ++j) { + scale_component(&(image->comps[j]), 12); + } + + } + return image; + +}/* tiftoimage() */ + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 64f63e83..ee39de8e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,6 +13,7 @@ include_directories( # First thing define the common source: set(compare_images_SRCS compare_images.c ${OPENJPEG_SOURCE_DIR}/src/bin/jp2/convert.c + ${OPENJPEG_SOURCE_DIR}/src/bin/jp2/converttif.c ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c ) From 8f798864a9a01a3aa3f3219c7f0f6d98afd482ba Mon Sep 17 00:00:00 2001 From: mayeut Date: Thu, 16 Jul 2015 00:26:02 +0200 Subject: [PATCH 02/10] Update imagetotif to support more output TIF formats Update uclouvain/openjpeg#322 Update uclouvain/openjpeg#264 --- src/bin/jp2/converttif.c | 794 +++++++++++++++++++++------------------ 1 file changed, 426 insertions(+), 368 deletions(-) diff --git a/src/bin/jp2/converttif.c b/src/bin/jp2/converttif.c index 85fc2b97..471f01ff 100644 --- a/src/bin/jp2/converttif.c +++ b/src/bin/jp2/converttif.c @@ -55,398 +55,460 @@ TIFF IMAGE FORMAT <<-- <<-- <<-- <<-- */ +typedef void (* tif_32stoX)(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length); + +static void tif_32sto1u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)8U); i+=8U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3]; + OPJ_UINT32 src4 = (OPJ_UINT32)pSrc[i+4]; + OPJ_UINT32 src5 = (OPJ_UINT32)pSrc[i+5]; + OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i+6]; + OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i+7]; + + *pDst++ = (src0 << 7) | (src1 << 6) | (src2 << 5) | (src3 << 4) | (src4 << 3) | (src5 << 2) | (src6 << 1) | src7; + } + + if (length & 7U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = 0U; + OPJ_UINT32 src2 = 0U; + OPJ_UINT32 src3 = 0U; + OPJ_UINT32 src4 = 0U; + OPJ_UINT32 src5 = 0U; + OPJ_UINT32 src6 = 0U; + length = length & 7U; + + if (length > 1U) { + src1 = (OPJ_UINT32)pSrc[i+1]; + if (length > 2U) { + src2 = (OPJ_UINT32)pSrc[i+2]; + if (length > 3U) { + src3 = (OPJ_UINT32)pSrc[i+3]; + if (length > 4U) { + src4 = (OPJ_UINT32)pSrc[i+4]; + if (length > 5U) { + src5 = (OPJ_UINT32)pSrc[i+5]; + if (length > 6U) { + src6 = (OPJ_UINT32)pSrc[i+6]; + } + } + } + } + } + } + *pDst++ = (src0 << 7) | (src1 << 6) | (src2 << 5) | (src3 << 4) | (src4 << 3) | (src5 << 2) | (src6 << 1); + } +} + +static void tif_32sto2u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)4U); i+=4U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3]; + + *pDst++ = (src0 << 6) | (src1 << 4) | (src2 << 2) | src3; + } + + if (length & 3U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = 0U; + OPJ_UINT32 src2 = 0U; + length = length & 3U; + + if (length > 1U) { + src1 = (OPJ_UINT32)pSrc[i+1]; + if (length > 2U) { + src2 = (OPJ_UINT32)pSrc[i+2]; + } + } + *pDst++ = (src0 << 6) | (src1 << 4) | (src2 << 2); + } +} + +static void tif_32sto4u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)2U); i+=2U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1]; + + *pDst++ = (src0 << 4) | src1; + } + + if (length & 1U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + *pDst++ = (src0 << 4); + } +} + +static void tif_32sto6u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)4U); i+=4U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3]; + + *pDst++ = (src0 << 2) | (src1 >> 4); + *pDst++ = ((src1 & 0xFU) << 4) | (src2 >> 2); + *pDst++ = ((src2 & 0x3U) << 6) | src3; + } + + if (length & 3U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = 0U; + OPJ_UINT32 src2 = 0U; + length = length & 3U; + + if (length > 1U) { + src1 = (OPJ_UINT32)pSrc[i+1]; + if (length > 2U) { + src2 = (OPJ_UINT32)pSrc[i+2]; + } + } + *pDst++ = (src0 << 2) | (src1 >> 4); + if (length > 1U) { + *pDst++ = ((src1 & 0xFU) << 4) | (src2 >> 2); + if (length > 2U) { + *pDst++ = ((src2 & 0x3U) << 6); + } + } + } +} +static void tif_32sto8u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < length; ++i) { + pDst[i] = (OPJ_BYTE)pSrc[i]; + } +} +static void tif_32sto10u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)4U); i+=4U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3]; + + *pDst++ = src0 >> 2; + *pDst++ = ((src0 & 0x3U) << 6) | (src1 >> 4); + *pDst++ = ((src1 & 0xFU) << 4) | (src2 >> 6); + *pDst++ = ((src2 & 0x3FU) << 2) | (src3 >> 8); + *pDst++ = src3; + } + + if (length & 3U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = 0U; + OPJ_UINT32 src2 = 0U; + length = length & 3U; + + if (length > 1U) { + src1 = (OPJ_UINT32)pSrc[i+1]; + if (length > 2U) { + src2 = (OPJ_UINT32)pSrc[i+2]; + } + } + *pDst++ = src0 >> 2; + *pDst++ = ((src0 & 0x3U) << 6) | (src1 >> 4); + if (length > 1U) { + *pDst++ = ((src1 & 0xFU) << 4) | (src2 >> 6); + if (length > 2U) { + *pDst++ = ((src2 & 0x3FU) << 2); + } + } + } +} +static void tif_32sto12u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)2U); i+=2U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1]; + + *pDst++ = src0 >> 4; + *pDst++ = ((src0 & 0xFU) << 4) | (src1 >> 8); + *pDst++ = src1; + } + + if (length & 1U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + *pDst++ = src0 >> 4; + *pDst++ = ((src0 & 0xFU) << 4); + } +} +static void tif_32sto14u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)4U); i+=4U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3]; + + *pDst++ = src0 >> 6; + *pDst++ = ((src0 & 0x3FU) << 2) | (src1 >> 12); + *pDst++ = src1 >> 4; + *pDst++ = ((src1 & 0xFU) << 4) | (src2 >> 10); + *pDst++ = src2 >> 2; + *pDst++ = ((src2 & 0x3U) << 6) | (src3 >> 8); + *pDst++ = src3; + } + + if (length & 3U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = 0U; + OPJ_UINT32 src2 = 0U; + length = length & 3U; + + if (length > 1U) { + src1 = (OPJ_UINT32)pSrc[i+1]; + if (length > 2U) { + src2 = (OPJ_UINT32)pSrc[i+2]; + } + } + *pDst++ = src0 >> 6; + *pDst++ = ((src0 & 0x3FU) << 2) | (src1 >> 12); + if (length > 1U) { + *pDst++ = src1 >> 4; + *pDst++ = ((src1 & 0xFU) << 4) | (src2 >> 10); + if (length > 2U) { + *pDst++ = src2 >> 2; + *pDst++ = ((src2 & 0x3U) << 6); + } + } + } +} +static void tif_32sto16u(const OPJ_INT32* pSrc, OPJ_UINT16* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < length; ++i) { + pDst[i] = (OPJ_UINT16)pSrc[i]; + } +} + +typedef void (* convert_32s_PXCX)(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length, OPJ_INT32 adjust); +static void convert_32s_P1C1(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length, OPJ_INT32 adjust) +{ + OPJ_SIZE_T i; + const OPJ_INT32* pSrc0 = pSrc[0]; + + for (i = 0; i < length; i++) { + pDst[i] = pSrc0[i] + adjust; + } +} +static void convert_32s_P2C2(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length, OPJ_INT32 adjust) +{ + OPJ_SIZE_T i; + const OPJ_INT32* pSrc0 = pSrc[0]; + const OPJ_INT32* pSrc1 = pSrc[1]; + + for (i = 0; i < length; i++) { + pDst[2*i+0] = pSrc0[i] + adjust; + pDst[2*i+1] = pSrc1[i] + adjust; + } +} +static void convert_32s_P3C3(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length, OPJ_INT32 adjust) +{ + OPJ_SIZE_T i; + const OPJ_INT32* pSrc0 = pSrc[0]; + const OPJ_INT32* pSrc1 = pSrc[1]; + const OPJ_INT32* pSrc2 = pSrc[2]; + + for (i = 0; i < length; i++) { + pDst[3*i+0] = pSrc0[i] + adjust; + pDst[3*i+1] = pSrc1[i] + adjust; + pDst[3*i+2] = pSrc2[i] + adjust; + } +} +static void convert_32s_P4C4(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length, OPJ_INT32 adjust) +{ + OPJ_SIZE_T i; + const OPJ_INT32* pSrc0 = pSrc[0]; + const OPJ_INT32* pSrc1 = pSrc[1]; + const OPJ_INT32* pSrc2 = pSrc[2]; + const OPJ_INT32* pSrc3 = pSrc[3]; + + for (i = 0; i < length; i++) { + pDst[4*i+0] = pSrc0[i] + adjust; + pDst[4*i+1] = pSrc1[i] + adjust; + pDst[4*i+2] = pSrc2[i] + adjust; + pDst[4*i+3] = pSrc3[i] + adjust; + } +} int imagetotif(opj_image_t * image, const char *outfile) { - int width, height, imgsize; - int bps,index,adjust, sgnd; - int ushift, dshift, has_alpha, force16; + int width, height; + int bps,adjust, sgnd; + int has_alpha; + int tiPhoto; TIFF *tif; tdata_t buf; - tstrip_t strip; tsize_t strip_size; + OPJ_UINT32 i, numcomps; + OPJ_SIZE_T rowStride; + OPJ_INT32* buffer32s = NULL; + OPJ_INT32 const* planes[4]; + convert_32s_PXCX cvtPxToCx = NULL; + tif_32stoX cvt32sToTif = NULL; - ushift = dshift = force16 = has_alpha = 0; + has_alpha = 0; bps = (int)image->comps[0].prec; + planes[0] = image->comps[0].data; - if(bps > 8 && bps < 16) - { - ushift = 16 - bps; dshift = bps - ushift; - bps = 16; force16 = 1; + numcomps = image->numcomps; + + if (numcomps > 2U) { + tiPhoto = PHOTOMETRIC_RGB; + if (numcomps > 4U) { + numcomps = 4U; + } + } else { + tiPhoto = PHOTOMETRIC_MINISBLACK; + } + for (i = 1U; i < numcomps; ++i) { + if (image->comps[0].dx != image->comps[i].dx) { + break; + } + if (image->comps[0].dy != image->comps[i].dy) { + break; + } + if (image->comps[0].prec != image->comps[i].prec) { + break; + } + if (image->comps[0].sgnd != image->comps[i].sgnd) { + break; + } + planes[i] = image->comps[i].data; + } + if (i != numcomps) { + fprintf(stderr,"imagetotif: All components shall have the same subsampling, same bit depth.\n"); + fprintf(stderr,"\tAborting\n"); + return 1; } - if(bps != 8 && bps != 16) + if((bps > 16) || ((bps != 1) && (bps & 1))) bps = 0; + if(bps == 0) { - fprintf(stderr,"imagetotif: Bits=%d, Only 8 and 16 bits implemented\n", - bps); + fprintf(stderr,"imagetotif: Bits=%d, Only 1, 2, 4, 6, 8, 10, 12, 14 and 16 bits implemented\n",bps); fprintf(stderr,"\tAborting\n"); return 1; } tif = TIFFOpen(outfile, "wb"); - if (!tif) { fprintf(stderr, "imagetotif:failed to open %s for writing\n", outfile); return 1; } + for (i = 0U; i < numcomps; ++i) { + clip_component(&(image->comps[i]), image->comps[0].prec); + } + switch (numcomps) { + case 1: + cvtPxToCx = convert_32s_P1C1; + break; + case 2: + cvtPxToCx = convert_32s_P2C2; + break; + case 3: + cvtPxToCx = convert_32s_P3C3; + break; + case 4: + cvtPxToCx = convert_32s_P4C4; + break; + default: + /* never here */ + break; + } + switch (bps) { + case 1: + cvt32sToTif = tif_32sto1u; + break; + case 2: + cvt32sToTif = tif_32sto2u; + break; + case 4: + cvt32sToTif = tif_32sto4u; + break; + case 6: + cvt32sToTif = tif_32sto6u; + break; + case 8: + cvt32sToTif = tif_32sto8u; + break; + case 10: + cvt32sToTif = tif_32sto10u; + break; + case 12: + cvt32sToTif = tif_32sto12u; + break; + case 14: + cvt32sToTif = tif_32sto14u; + break; + case 16: + cvt32sToTif = (tif_32stoX)tif_32sto16u; + break; + default: + /* never here */ + break; + } sgnd = (int)image->comps[0].sgnd; adjust = sgnd ? 1 << (image->comps[0].prec - 1) : 0; + width = (int)image->comps[0].w; + height = (int)image->comps[0].h; - 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) - { - has_alpha = (image->numcomps == 4); - - width = (int)image->comps[0].w; - height = (int)image->comps[0].h; - imgsize = width * height ; - - TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width); - TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height); - TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3 + has_alpha); - 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); - strip_size = TIFFStripSize(tif); - buf = _TIFFmalloc(strip_size); - index=0; - - for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) - { - unsigned char *dat8; - tsize_t i, ssize, last_i = 0; - int step, restx; - ssize = TIFFStripSize(tif); - dat8 = (unsigned char*)buf; - - if(bps == 8) - { - step = 3 + has_alpha; - restx = step - 1; - - for(i=0; i < ssize - restx; i += step) - { - int r, g, b, a = 0; - - if(index < imgsize) - { - r = image->comps[0].data[index]; - g = image->comps[1].data[index]; - b = image->comps[2].data[index]; - if(has_alpha) a = image->comps[3].data[index]; - - if(sgnd) - { - r += adjust; - g += adjust; - b += adjust; - if(has_alpha) a += adjust; - } - if(r > 255) r = 255; else if(r < 0) r = 0; - dat8[i+0] = (unsigned char)r ; - if(g > 255) g = 255; else if(g < 0) g = 0; - dat8[i+1] = (unsigned char)g ; - if(b > 255) b = 255; else if(b < 0) b = 0; - dat8[i+2] = (unsigned char)b ; - if(has_alpha) - { - if(a > 255) a = 255; else if(a < 0) a = 0; - dat8[i+3] = (unsigned char)a; - } - - index++; - last_i = i + step; - } - else - break; - }/*for(i = 0;)*/ - - if(last_i < ssize) - { - for(i = last_i; i < ssize; i += step) - { - int r, g, b, a = 0; - - if(index < imgsize) - { - r = image->comps[0].data[index]; - g = image->comps[1].data[index]; - b = image->comps[2].data[index]; - if(has_alpha) a = image->comps[3].data[index]; - - if(sgnd) - { - r += adjust; - g += adjust; - b += adjust; - if(has_alpha) a += adjust; - } - if(r > 255) r = 255; else if(r < 0) r = 0; - if(g > 255) g = 255; else if(g < 0) g = 0; - if(b > 255) b = 255; else if(b < 0) b = 0; - - dat8[i+0] = (unsigned char)r ; - if(i+1 < ssize) dat8[i+1] = (unsigned char)g ; else break; - if(i+2 < ssize) dat8[i+2] = (unsigned char)b ; else break; - if(has_alpha) - { - if(a > 255) a = 255; else if(a < 0) a = 0; - - if(i+3 < ssize) dat8[i+3] = (unsigned char)a ; else break; - } - index++; - } - else - break; - }/*for(i)*/ - }/*if(last_i < ssize)*/ - - } /*if(bps == 8)*/ - else - if(bps == 16) - { - step = 6 + has_alpha + has_alpha; - restx = step - 1; - - for(i = 0; i < ssize - restx ; i += step) - { - int r, g, b, a = 0; - - if(index < imgsize) - { - r = image->comps[0].data[index]; - g = image->comps[1].data[index]; - b = image->comps[2].data[index]; - if(has_alpha) a = image->comps[3].data[index]; - - if(sgnd) - { - r += adjust; - g += adjust; - b += adjust; - if(has_alpha) a += adjust; - } - if(force16) - { - r = (r<>dshift); - g = (g<>dshift); - b = (b<>dshift); - if(has_alpha) a = (a<>dshift); - } - if(r > 65535) r = 65535; else if(r < 0) r = 0; - if(g > 65535) g = 65535; else if(g < 0) g = 0; - if(b > 65535) b = 65535; else if(b < 0) b = 0; - - dat8[i+0] = (unsigned char)r;/*LSB*/ - dat8[i+1] = (unsigned char)(r >> 8);/*MSB*/ - dat8[i+2] = (unsigned char)g; - dat8[i+3] = (unsigned char)(g >> 8); - dat8[i+4] = (unsigned char)b; - dat8[i+5] = (unsigned char)(b >> 8); - if(has_alpha) - { - if(a > 65535) a = 65535; else if(a < 0) a = 0; - dat8[i+6] = (unsigned char)a; - dat8[i+7] = (unsigned char)(a >> 8); - } - index++; - last_i = i + step; - } - else - break; - }/*for(i = 0;)*/ - - if(last_i < ssize) - { - for(i = last_i ; i < ssize ; i += step) - { - int r, g, b, a = 0; - - if(index < imgsize) - { - r = image->comps[0].data[index]; - g = image->comps[1].data[index]; - b = image->comps[2].data[index]; - if(has_alpha) a = image->comps[3].data[index]; - - if(sgnd) - { - r += adjust; - g += adjust; - b += adjust; - if(has_alpha) a += adjust; - } - if(force16) - { - r = (r<>dshift); - g = (g<>dshift); - b = (b<>dshift); - if(has_alpha) a = (a<>dshift); - } - if(r > 65535) r = 65535; else if(r < 0) r = 0; - if(g > 65535) g = 65535; else if(g < 0) g = 0; - if(b > 65535) b = 65535; else if(b < 0) b = 0; - - dat8[i+0] = (unsigned char) r;/*LSB*/ - if(i+1 < ssize) dat8[i+1] = (unsigned char)(r >> 8);else break;/*MSB*/ - if(i+2 < ssize) dat8[i+2] = (unsigned char) g; else break; - if(i+3 < ssize) dat8[i+3] = (unsigned char)(g >> 8);else break; - if(i+4 < ssize) dat8[i+4] = (unsigned char) b; else break; - if(i+5 < ssize) dat8[i+5] = (unsigned char)(b >> 8);else break; - - if(has_alpha) - { - if(a > 65535) a = 65535; else if(a < 0) a = 0; - if(i+6 < ssize) dat8[i+6] = (unsigned char)a; else break; - if(i+7 < ssize) dat8[i+7] = (unsigned char)(a >> 8); else break; - } - index++; - } - else - break; - }/*for(i)*/ - }/*if(last_i < ssize)*/ - - }/*if(bps == 16)*/ - (void)TIFFWriteEncodedStrip(tif, strip, (void*)buf, strip_size); - }/*for(strip = 0; )*/ - - _TIFFfree((void*)buf); + TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width); + TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height); + TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, numcomps); + TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps); + TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); + TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); + TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, tiPhoto); + TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1); + strip_size = TIFFStripSize(tif); + rowStride = ((OPJ_SIZE_T)width * numcomps * bps + 7U) / 8U; + if (rowStride != (OPJ_SIZE_T)strip_size) { + fprintf(stderr, "Invalid TIFF strip size\n"); TIFFClose(tif); - - return 0; - }/*RGB(A)*/ - - if(image->numcomps == 1 /* GRAY */ - || ( image->numcomps == 2 /* GRAY_ALPHA */ - && image->comps[0].dx == image->comps[1].dx - && image->comps[0].dy == image->comps[1].dy - && image->comps[0].prec == image->comps[1].prec)) - { - int step; - - has_alpha = (image->numcomps == 2); - - width = (int)image->comps[0].w; - height = (int)image->comps[0].h; - imgsize = width * height; - - /* Set tags */ - TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width); - TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height); - TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1 + has_alpha); - 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 */ - strip_size = TIFFStripSize(tif); - buf = _TIFFmalloc(strip_size); - index = 0; - - for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) - { - unsigned char *dat8; - tsize_t i, ssize = TIFFStripSize(tif); - dat8 = (unsigned char*)buf; - - if(bps == 8) - { - step = 1 + has_alpha; - - for(i=0; i < ssize; i += step) - { - if(index < imgsize) - { - int r, a = 0; - - r = image->comps[0].data[index]; - if(has_alpha) a = image->comps[1].data[index]; - - if(sgnd) - { - r += adjust; - if(has_alpha) a += adjust; - } - if(r > 255) r = 255; else if(r < 0) r = 0; - dat8[i+0] = (unsigned char)r; - - if(has_alpha) - { - if(a > 255) a = 255; else if(a < 0) a = 0; - dat8[i+1] = (unsigned char)a; - } - index++; - } - else - break; - }/*for(i )*/ - }/*if(bps == 8*/ - else - if(bps == 16) - { - step = 2 + has_alpha + has_alpha; - - for(i=0; i < ssize; i += step) - { - if(index < imgsize) - { - int r, a = 0; - - r = image->comps[0].data[index]; - if(has_alpha) a = image->comps[1].data[index]; - - if(sgnd) - { - r += adjust; - if(has_alpha) a += adjust; - } - if(force16) - { - r = (r<>dshift); - if(has_alpha) a = (a<>dshift); - } - if(r > 65535) r = 65535; else if(r < 0) r = 0; - dat8[i+0] = (unsigned char)r;/*LSB*/ - dat8[i+1] = (unsigned char)(r >> 8);/*MSB*/ - if(has_alpha) - { - if(a > 65535) a = 65535; else if(a < 0) a = 0; - dat8[i+2] = (unsigned char)a; - dat8[i+3] = (unsigned char)(a >> 8); - } - index++; - }/*if(index < imgsize)*/ - else - break; - }/*for(i )*/ - } - (void)TIFFWriteEncodedStrip(tif, strip, (void*)buf, strip_size); - }/*for(strip*/ - + return 1; + } + buf = _TIFFmalloc(strip_size); + if (buf == NULL) { + TIFFClose(tif); + return 1; + } + buffer32s = malloc((OPJ_SIZE_T)width * numcomps * sizeof(OPJ_INT32)); + if (buffer32s == NULL) { _TIFFfree(buf); TIFFClose(tif); - - return 0; + return 1; } + for (i = 0; i < image->comps[0].h; ++i) { + cvtPxToCx(planes, buffer32s, width, adjust); + cvt32sToTif(buffer32s, buf, width * numcomps); + (void)TIFFWriteEncodedStrip(tif, i, (void*)buf, strip_size); + planes[0] += width; + planes[1] += width; + planes[2] += width; + planes[3] += width; + } + _TIFFfree((void*)buf); TIFFClose(tif); - - fprintf(stderr,"imagetotif: Bad color format.\n" - "\tOnly RGB(A) and GRAY(A) has been implemented\n"); - fprintf(stderr,"\tFOUND: numcomps(%d)\n\tAborting\n", - image->numcomps); - - return 1; + free(buffer32s); + + return 0; }/* imagetotif() */ typedef void (* tif_Xto32s)(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length); @@ -842,8 +904,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) if(tiSpp == 4 || tiSpp == 2) has_alpha = 1; } - /* initialize image components - */ + /* initialize image components */ memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t)); if ((tiPhoto == PHOTOMETRIC_RGB) && (is_cinema) && (tiBps != 12U)) { @@ -880,7 +941,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) case 4: cvtCxToPx = convert_32s_C4P4; break; - default: + default: /* never here */ break; } @@ -916,9 +977,6 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) for(j = 0; j < numcomps; j++) { planes[j] = image->comps[j].data; - if (has_alpha) { - planes[j] = image->comps[j].data; - } } strip_size = TIFFStripSize(tif); From 635a358962ce2eefe9750399d9c212d1fff65afc Mon Sep 17 00:00:00 2001 From: mayeut Date: Thu, 16 Jul 2015 06:51:21 +0200 Subject: [PATCH 03/10] Fix build warnings in converttif.c --- src/bin/jp2/converttif.c | 281 +++++++++++++++++++-------------------- 1 file changed, 140 insertions(+), 141 deletions(-) diff --git a/src/bin/jp2/converttif.c b/src/bin/jp2/converttif.c index 471f01ff..21bb11f8 100644 --- a/src/bin/jp2/converttif.c +++ b/src/bin/jp2/converttif.c @@ -12,6 +12,7 @@ * Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2006-2007, Parvatha Elangovan + * Copyright (c) 2015, Matthieu Darbois * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -70,7 +71,7 @@ static void tif_32sto1u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i+6]; OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i+7]; - *pDst++ = (src0 << 7) | (src1 << 6) | (src2 << 5) | (src3 << 4) | (src4 << 3) | (src5 << 2) | (src6 << 1) | src7; + *pDst++ = (OPJ_BYTE)((src0 << 7) | (src1 << 6) | (src2 << 5) | (src3 << 4) | (src4 << 3) | (src5 << 2) | (src6 << 1) | src7); } if (length & 7U) { @@ -101,7 +102,7 @@ static void tif_32sto1u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length } } } - *pDst++ = (src0 << 7) | (src1 << 6) | (src2 << 5) | (src3 << 4) | (src4 << 3) | (src5 << 2) | (src6 << 1); + *pDst++ = (OPJ_BYTE)((src0 << 7) | (src1 << 6) | (src2 << 5) | (src3 << 4) | (src4 << 3) | (src5 << 2) | (src6 << 1)); } } @@ -114,7 +115,7 @@ static void tif_32sto2u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2]; OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3]; - *pDst++ = (src0 << 6) | (src1 << 4) | (src2 << 2) | src3; + *pDst++ = (OPJ_BYTE)((src0 << 6) | (src1 << 4) | (src2 << 2) | src3); } if (length & 3U) { @@ -129,7 +130,7 @@ static void tif_32sto2u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length src2 = (OPJ_UINT32)pSrc[i+2]; } } - *pDst++ = (src0 << 6) | (src1 << 4) | (src2 << 2); + *pDst++ = (OPJ_BYTE)((src0 << 6) | (src1 << 4) | (src2 << 2)); } } @@ -140,12 +141,12 @@ static void tif_32sto4u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1]; - *pDst++ = (src0 << 4) | src1; + *pDst++ = (OPJ_BYTE)((src0 << 4) | src1); } if (length & 1U) { OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; - *pDst++ = (src0 << 4); + *pDst++ = (OPJ_BYTE)((src0 << 4)); } } @@ -158,9 +159,9 @@ static void tif_32sto6u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2]; OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3]; - *pDst++ = (src0 << 2) | (src1 >> 4); - *pDst++ = ((src1 & 0xFU) << 4) | (src2 >> 2); - *pDst++ = ((src2 & 0x3U) << 6) | src3; + *pDst++ = (OPJ_BYTE)((src0 << 2) | (src1 >> 4)); + *pDst++ = (OPJ_BYTE)(((src1 & 0xFU) << 4) | (src2 >> 2)); + *pDst++ = (OPJ_BYTE)(((src2 & 0x3U) << 6) | src3); } if (length & 3U) { @@ -175,11 +176,11 @@ static void tif_32sto6u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length src2 = (OPJ_UINT32)pSrc[i+2]; } } - *pDst++ = (src0 << 2) | (src1 >> 4); + *pDst++ = (OPJ_BYTE)((src0 << 2) | (src1 >> 4)); if (length > 1U) { - *pDst++ = ((src1 & 0xFU) << 4) | (src2 >> 2); + *pDst++ = (OPJ_BYTE)(((src1 & 0xFU) << 4) | (src2 >> 2)); if (length > 2U) { - *pDst++ = ((src2 & 0x3U) << 6); + *pDst++ = (OPJ_BYTE)(((src2 & 0x3U) << 6)); } } } @@ -200,11 +201,11 @@ static void tif_32sto10u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T lengt OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2]; OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3]; - *pDst++ = src0 >> 2; - *pDst++ = ((src0 & 0x3U) << 6) | (src1 >> 4); - *pDst++ = ((src1 & 0xFU) << 4) | (src2 >> 6); - *pDst++ = ((src2 & 0x3FU) << 2) | (src3 >> 8); - *pDst++ = src3; + *pDst++ = (OPJ_BYTE)(src0 >> 2); + *pDst++ = (OPJ_BYTE)(((src0 & 0x3U) << 6) | (src1 >> 4)); + *pDst++ = (OPJ_BYTE)(((src1 & 0xFU) << 4) | (src2 >> 6)); + *pDst++ = (OPJ_BYTE)(((src2 & 0x3FU) << 2) | (src3 >> 8)); + *pDst++ = (OPJ_BYTE)(src3); } if (length & 3U) { @@ -219,12 +220,12 @@ static void tif_32sto10u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T lengt src2 = (OPJ_UINT32)pSrc[i+2]; } } - *pDst++ = src0 >> 2; - *pDst++ = ((src0 & 0x3U) << 6) | (src1 >> 4); + *pDst++ = (OPJ_BYTE)(src0 >> 2); + *pDst++ = (OPJ_BYTE)(((src0 & 0x3U) << 6) | (src1 >> 4)); if (length > 1U) { - *pDst++ = ((src1 & 0xFU) << 4) | (src2 >> 6); + *pDst++ = (OPJ_BYTE)(((src1 & 0xFU) << 4) | (src2 >> 6)); if (length > 2U) { - *pDst++ = ((src2 & 0x3FU) << 2); + *pDst++ = (OPJ_BYTE)(((src2 & 0x3FU) << 2)); } } } @@ -236,15 +237,15 @@ static void tif_32sto12u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T lengt OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1]; - *pDst++ = src0 >> 4; - *pDst++ = ((src0 & 0xFU) << 4) | (src1 >> 8); - *pDst++ = src1; + *pDst++ = (OPJ_BYTE)(src0 >> 4); + *pDst++ = (OPJ_BYTE)(((src0 & 0xFU) << 4) | (src1 >> 8)); + *pDst++ = (OPJ_BYTE)(src1); } if (length & 1U) { OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; - *pDst++ = src0 >> 4; - *pDst++ = ((src0 & 0xFU) << 4); + *pDst++ = (OPJ_BYTE)(src0 >> 4); + *pDst++ = (OPJ_BYTE)(((src0 & 0xFU) << 4)); } } static void tif_32sto14u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) @@ -256,13 +257,13 @@ static void tif_32sto14u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T lengt OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2]; OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3]; - *pDst++ = src0 >> 6; - *pDst++ = ((src0 & 0x3FU) << 2) | (src1 >> 12); - *pDst++ = src1 >> 4; - *pDst++ = ((src1 & 0xFU) << 4) | (src2 >> 10); - *pDst++ = src2 >> 2; - *pDst++ = ((src2 & 0x3U) << 6) | (src3 >> 8); - *pDst++ = src3; + *pDst++ = (OPJ_BYTE)(src0 >> 6); + *pDst++ = (OPJ_BYTE)(((src0 & 0x3FU) << 2) | (src1 >> 12)); + *pDst++ = (OPJ_BYTE)(src1 >> 4); + *pDst++ = (OPJ_BYTE)(((src1 & 0xFU) << 4) | (src2 >> 10)); + *pDst++ = (OPJ_BYTE)(src2 >> 2); + *pDst++ = (OPJ_BYTE)(((src2 & 0x3U) << 6) | (src3 >> 8)); + *pDst++ = (OPJ_BYTE)(src3); } if (length & 3U) { @@ -277,14 +278,14 @@ static void tif_32sto14u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T lengt src2 = (OPJ_UINT32)pSrc[i+2]; } } - *pDst++ = src0 >> 6; - *pDst++ = ((src0 & 0x3FU) << 2) | (src1 >> 12); + *pDst++ = (OPJ_BYTE)(src0 >> 6); + *pDst++ = (OPJ_BYTE)(((src0 & 0x3FU) << 2) | (src1 >> 12)); if (length > 1U) { - *pDst++ = src1 >> 4; - *pDst++ = ((src1 & 0xFU) << 4) | (src2 >> 10); + *pDst++ = (OPJ_BYTE)(src1 >> 4); + *pDst++ = (OPJ_BYTE)(((src1 & 0xFU) << 4) | (src2 >> 10)); if (length > 2U) { - *pDst++ = src2 >> 2; - *pDst++ = ((src2 & 0x3U) << 6); + *pDst++ = (OPJ_BYTE)(src2 >> 2); + *pDst++ = (OPJ_BYTE)(((src2 & 0x3U) << 6)); } } } @@ -351,7 +352,6 @@ int imagetotif(opj_image_t * image, const char *outfile) { int width, height; int bps,adjust, sgnd; - int has_alpha; int tiPhoto; TIFF *tif; tdata_t buf; @@ -362,8 +362,7 @@ int imagetotif(opj_image_t * image, const char *outfile) OPJ_INT32 const* planes[4]; convert_32s_PXCX cvtPxToCx = NULL; tif_32stoX cvt32sToTif = NULL; - - has_alpha = 0; + bps = (int)image->comps[0].prec; planes[0] = image->comps[0].data; @@ -477,7 +476,7 @@ int imagetotif(opj_image_t * image, const char *outfile) TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, tiPhoto); TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1); strip_size = TIFFStripSize(tif); - rowStride = ((OPJ_SIZE_T)width * numcomps * bps + 7U) / 8U; + rowStride = ((OPJ_SIZE_T)width * numcomps * (OPJ_SIZE_T)bps + 7U) / 8U; if (rowStride != (OPJ_SIZE_T)strip_size) { fprintf(stderr, "Invalid TIFF strip size\n"); TIFFClose(tif); @@ -496,8 +495,8 @@ int imagetotif(opj_image_t * image, const char *outfile) } for (i = 0; i < image->comps[0].h; ++i) { - cvtPxToCx(planes, buffer32s, width, adjust); - cvt32sToTif(buffer32s, buf, width * numcomps); + cvtPxToCx(planes, buffer32s, (OPJ_SIZE_T)width, adjust); + cvt32sToTif(buffer32s, buf, (OPJ_SIZE_T)width * numcomps); (void)TIFFWriteEncodedStrip(tif, i, (void*)buf, strip_size); planes[0] += width; planes[1] += width; @@ -517,33 +516,33 @@ static void tif_1uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length { OPJ_SIZE_T i; for (i = 0; i < (length & -(OPJ_SIZE_T)8U); i+=8U) { - OPJ_UINT8 val = *pSrc++; - pDst[i+0] = val >> 7; - pDst[i+1] = (val >> 6) & 0x1U; - pDst[i+2] = (val >> 5) & 0x1U; - pDst[i+3] = (val >> 4) & 0x1U; - pDst[i+4] = (val >> 3) & 0x1U; - pDst[i+5] = (val >> 2) & 0x1U; - pDst[i+6] = (val >> 1) & 0x1U; - pDst[i+7] = val & 0x1U; + OPJ_UINT32 val = *pSrc++; + pDst[i+0] = (OPJ_INT32)( val >> 7); + pDst[i+1] = (OPJ_INT32)((val >> 6) & 0x1U); + pDst[i+2] = (OPJ_INT32)((val >> 5) & 0x1U); + pDst[i+3] = (OPJ_INT32)((val >> 4) & 0x1U); + pDst[i+4] = (OPJ_INT32)((val >> 3) & 0x1U); + pDst[i+5] = (OPJ_INT32)((val >> 2) & 0x1U); + pDst[i+6] = (OPJ_INT32)((val >> 1) & 0x1U); + pDst[i+7] = (OPJ_INT32)(val & 0x1U); } if (length & 7U) { - OPJ_UINT8 val = *pSrc++; + OPJ_UINT32 val = *pSrc++; length = length & 7U; - pDst[i+0] = val >> 7; + pDst[i+0] = (OPJ_INT32)(val >> 7); if (length > 1U) { - pDst[i+1] = (val >> 6) & 0x1U; + pDst[i+1] = (OPJ_INT32)((val >> 6) & 0x1U); if (length > 2U) { - pDst[i+2] = (val >> 5) & 0x1U; + pDst[i+2] = (OPJ_INT32)((val >> 5) & 0x1U); if (length > 3U) { - pDst[i+3] = (val >> 4) & 0x1U; + pDst[i+3] = (OPJ_INT32)((val >> 4) & 0x1U); if (length > 4U) { - pDst[i+4] = (val >> 3) & 0x1U; + pDst[i+4] = (OPJ_INT32)((val >> 3) & 0x1U); if (length > 5U) { - pDst[i+5] = (val >> 2) & 0x1U; + pDst[i+5] = (OPJ_INT32)((val >> 2) & 0x1U); if (length > 6U) { - pDst[i+6] = (val >> 1) & 0x1U; + pDst[i+6] = (OPJ_INT32)((val >> 1) & 0x1U); } } } @@ -556,21 +555,21 @@ static void tif_2uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length { OPJ_SIZE_T i; for (i = 0; i < (length & -(OPJ_SIZE_T)4U); i+=4U) { - OPJ_UINT8 val = *pSrc++; - pDst[i+0] = val >> 6; - pDst[i+1] = (val >> 4) & 0x3U; - pDst[i+2] = (val >> 2) & 0x3U; - pDst[i+3] = val & 0x3U; + OPJ_UINT32 val = *pSrc++; + pDst[i+0] = (OPJ_INT32)( val >> 6); + pDst[i+1] = (OPJ_INT32)((val >> 4) & 0x3U); + pDst[i+2] = (OPJ_INT32)((val >> 2) & 0x3U); + pDst[i+3] = (OPJ_INT32)(val & 0x3U); } if (length & 3U) { - OPJ_UINT8 val = *pSrc++; + OPJ_UINT32 val = *pSrc++; length = length & 3U; - pDst[i+0] = val >> 6; + pDst[i+0] = (OPJ_INT32)(val >> 6); if (length > 1U) { - pDst[i+1] = (val >> 4) & 0x3U; + pDst[i+1] = (OPJ_INT32)((val >> 4) & 0x3U); if (length > 2U) { - pDst[i+2] = (val >> 2) & 0x3U; + pDst[i+2] = (OPJ_INT32)((val >> 2) & 0x3U); } } @@ -580,39 +579,39 @@ static void tif_4uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length { OPJ_SIZE_T i; for (i = 0; i < (length & -(OPJ_SIZE_T)2U); i+=2U) { - OPJ_UINT8 val = *pSrc++; - pDst[i+0] = val >> 4; - pDst[i+1] = val & 0xFU; + OPJ_UINT32 val = *pSrc++; + pDst[i+0] = (OPJ_INT32)(val >> 4); + pDst[i+1] = (OPJ_INT32)(val & 0xFU); } if (length & 1U) { OPJ_UINT8 val = *pSrc++; - pDst[i+0] = val >> 4; + pDst[i+0] = (OPJ_INT32)(val >> 4); } } static void tif_6uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) { OPJ_SIZE_T i; for (i = 0; i < (length & -(OPJ_SIZE_T)4U); i+=4U) { - OPJ_UINT8 val0 = *pSrc++; - OPJ_UINT8 val1 = *pSrc++; - OPJ_UINT8 val2 = *pSrc++; - pDst[i+0] = val0 >> 2; - pDst[i+1] = ((val0 & 0x3U) << 4) | (val1 >> 4); - pDst[i+2] = ((val1 & 0xFU) << 2) | (val2 >> 6); - pDst[i+3] = val2 & 0x3FU; + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + pDst[i+0] = (OPJ_INT32)(val0 >> 2); + pDst[i+1] = (OPJ_INT32)(((val0 & 0x3U) << 4) | (val1 >> 4)); + pDst[i+2] = (OPJ_INT32)(((val1 & 0xFU) << 2) | (val2 >> 6)); + pDst[i+3] = (OPJ_INT32)(val2 & 0x3FU); } if (length & 3U) { - OPJ_UINT8 val0 = *pSrc++; + OPJ_UINT32 val0 = *pSrc++; length = length & 3U; - pDst[i+0] = val0 >> 2; + pDst[i+0] = (OPJ_INT32)(val0 >> 2); if (length > 1U) { - OPJ_UINT8 val1 = *pSrc++; - pDst[i+1] = ((val0 & 0x3U) << 4) | (val1 >> 4); + OPJ_UINT32 val1 = *pSrc++; + pDst[i+1] = (OPJ_INT32)(((val0 & 0x3U) << 4) | (val1 >> 4)); if (length > 2U) { - OPJ_UINT8 val2 = *pSrc++; - pDst[i+2] = ((val1 & 0xFU) << 2) | (val2 >> 6); + OPJ_UINT32 val2 = *pSrc++; + pDst[i+2] = (OPJ_INT32)(((val1 & 0xFU) << 2) | (val2 >> 6)); } } } @@ -628,30 +627,30 @@ static void tif_10uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T lengt { OPJ_SIZE_T i; for (i = 0; i < (length & -(OPJ_SIZE_T)4U); i+=4U) { - OPJ_INT32 val0 = *pSrc++; - OPJ_INT32 val1 = *pSrc++; - OPJ_INT32 val2 = *pSrc++; - OPJ_INT32 val3 = *pSrc++; - OPJ_INT32 val4 = *pSrc++; + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + OPJ_UINT32 val4 = *pSrc++; - pDst[i+0] = (val0 << 2) | (val1 >> 6); - pDst[i+1] = ((val1 & 0x3FU) << 4) | (val2 >> 4); - pDst[i+2] = ((val2 & 0xFU) << 6) | (val3 >> 2); - pDst[i+3] = ((val3 & 0x3U) << 8) | val4; + pDst[i+0] = (OPJ_INT32)((val0 << 2) | (val1 >> 6)); + pDst[i+1] = (OPJ_INT32)(((val1 & 0x3FU) << 4) | (val2 >> 4)); + pDst[i+2] = (OPJ_INT32)(((val2 & 0xFU) << 6) | (val3 >> 2)); + pDst[i+3] = (OPJ_INT32)(((val3 & 0x3U) << 8) | val4); } if (length & 3U) { - OPJ_INT32 val0 = *pSrc++; - OPJ_INT32 val1 = *pSrc++; + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; length = length & 3U; - pDst[i+0] = (val0 << 2) | (val1 >> 6); + pDst[i+0] = (OPJ_INT32)((val0 << 2) | (val1 >> 6)); if (length > 1U) { - OPJ_INT32 val2 = *pSrc++; - pDst[i+1] = ((val1 & 0x3FU) << 4) | (val2 >> 4); + OPJ_UINT32 val2 = *pSrc++; + pDst[i+1] = (OPJ_INT32)(((val1 & 0x3FU) << 4) | (val2 >> 4)); if (length > 2U) { - OPJ_INT32 val3 = *pSrc++; - pDst[i+2] = ((val2 & 0xFU) << 6) | (val3 >> 2); + OPJ_UINT32 val3 = *pSrc++; + pDst[i+2] = (OPJ_INT32)(((val2 & 0xFU) << 6) | (val3 >> 2)); } } } @@ -660,51 +659,51 @@ static void tif_12uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T lengt { OPJ_SIZE_T i; for (i = 0; i < (length & -(OPJ_SIZE_T)2U); i+=2U) { - OPJ_INT32 val0 = *pSrc++; - OPJ_INT32 val1 = *pSrc++; - OPJ_INT32 val2 = *pSrc++; + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; - pDst[i+0] = (val0 << 4) | (val1 >> 4); - pDst[i+1] = ((val1 & 0xFU) << 8) | val2; + pDst[i+0] = (OPJ_INT32)((val0 << 4) | (val1 >> 4)); + pDst[i+1] = (OPJ_INT32)(((val1 & 0xFU) << 8) | val2); } if (length & 1U) { - OPJ_INT32 val0 = *pSrc++; - OPJ_INT32 val1 = *pSrc++; - pDst[i+0] = (val0 << 4) | (val1 >> 4); + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + pDst[i+0] = (OPJ_INT32)((val0 << 4) | (val1 >> 4)); } } static void tif_14uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) { OPJ_SIZE_T i; for (i = 0; i < (length & -(OPJ_SIZE_T)4U); i+=4U) { - OPJ_INT32 val0 = *pSrc++; - OPJ_INT32 val1 = *pSrc++; - OPJ_INT32 val2 = *pSrc++; - OPJ_INT32 val3 = *pSrc++; - OPJ_INT32 val4 = *pSrc++; - OPJ_INT32 val5 = *pSrc++; - OPJ_INT32 val6 = *pSrc++; + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + OPJ_UINT32 val4 = *pSrc++; + OPJ_UINT32 val5 = *pSrc++; + OPJ_UINT32 val6 = *pSrc++; - pDst[i+0] = (val0 << 6) | (val1 >> 2); - pDst[i+1] = ((val1 & 0x3U) << 12) | (val2 << 4) | (val3 >> 4); - pDst[i+2] = ((val3 & 0xFU) << 10) | (val4 << 2) | (val5 >> 6); - pDst[i+3] = ((val5 & 0x3FU) << 8) | val6; + pDst[i+0] = (OPJ_INT32)((val0 << 6) | (val1 >> 2)); + pDst[i+1] = (OPJ_INT32)(((val1 & 0x3U) << 12) | (val2 << 4) | (val3 >> 4)); + pDst[i+2] = (OPJ_INT32)(((val3 & 0xFU) << 10) | (val4 << 2) | (val5 >> 6)); + pDst[i+3] = (OPJ_INT32)(((val5 & 0x3FU) << 8) | val6); } if (length & 3U) { - OPJ_INT32 val0 = *pSrc++; - OPJ_INT32 val1 = *pSrc++; + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; length = length & 3U; - pDst[i+0] = (val0 << 6) | (val1 >> 2); + pDst[i+0] = (OPJ_INT32)((val0 << 6) | (val1 >> 2)); if (length > 1U) { - OPJ_INT32 val2 = *pSrc++; - OPJ_INT32 val3 = *pSrc++; - pDst[i+1] = ((val1 & 0x3U) << 12) | (val2 << 4) | (val3 >> 4); + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + pDst[i+1] = (OPJ_INT32)(((val1 & 0x3U) << 12) | (val2 << 4) | (val3 >> 4)); if (length > 2U) { - OPJ_INT32 val4 = *pSrc++; - OPJ_INT32 val5 = *pSrc++; - pDst[i+2] = ((val3 & 0xFU) << 10) | (val4 << 2) | (val5 >> 6); + OPJ_UINT32 val4 = *pSrc++; + OPJ_UINT32 val5 = *pSrc++; + pDst[i+2] = (OPJ_INT32)(((val3 & 0xFU) << 10) | (val4 << 2) | (val5 >> 6)); } } } @@ -714,12 +713,12 @@ static void tif_16uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T lengt { OPJ_SIZE_T i; for (i = 0; i < length; i++) { - OPJ_INT32 val0 = *pSrc++; - OPJ_INT32 val1 = *pSrc++; + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; #ifdef OPJ_BIG_ENDIAN - pDst[i] = (val0 << 8) | val1; + pDst[i] = (OPJ_INT32)((val0 << 8) | val1); #else - pDst[i] = (val1 << 8) | val0; + pDst[i] = (OPJ_INT32)((val1 << 8) | val0); #endif } } @@ -793,7 +792,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) tstrip_t strip; tsize_t strip_size; int j, currentPlane, numcomps = 0, w, h; - OPJ_COLOR_SPACE color_space; + OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_UNKNOWN; opj_image_cmptparm_t cmptparm[4]; /* RGBA */ opj_image_t *image = NULL; int has_alpha = 0; @@ -1006,14 +1005,14 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) for(; (h > 0) && (strip < TIFFNumberOfStrips(tif)); strip++) { const OPJ_UINT8 *dat8; - tsize_t ssize; + OPJ_SIZE_T ssize; - ssize = TIFFReadEncodedStrip(tif, strip, buf, strip_size); + ssize = (OPJ_SIZE_T)TIFFReadEncodedStrip(tif, strip, buf, strip_size); dat8 = (const OPJ_UINT8*)buf; while (ssize >= rowStride) { - cvtTifTo32s(dat8, buffer32s, w * tiSpp); - cvtCxToPx(buffer32s, planes, w); + cvtTifTo32s(dat8, buffer32s, (OPJ_SIZE_T)w * tiSpp); + cvtCxToPx(buffer32s, planes, (OPJ_SIZE_T)w); planes[0] += w; planes[1] += w; planes[2] += w; From 6b7ad74e26770f92f62e249c15e7c64a4321eb3a Mon Sep 17 00:00:00 2001 From: mayeut Date: Thu, 16 Jul 2015 23:20:50 +0200 Subject: [PATCH 04/10] Add tests for TIFF input Update uclouvain/openjpeg#322 --- tests/nonregression/test_suite.ctest.in | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index eaaa2e04..9dd804a3 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -74,6 +74,31 @@ opj_compress -i @INPUT_NR_PATH@/issue203-33x33-bgrx16.bmp -o @TEMP_PATH@/issue20 opj_compress -i @INPUT_NR_PATH@/issue203-127x64-bgr16.bmp -o @TEMP_PATH@/issue203-127x64-bgr16.bmp.jp2 opj_compress -i @INPUT_NR_PATH@/issue203-127x64-bgrx.bmp -o @TEMP_PATH@/issue203-127x64-bgrx.bmp.jp2 +# issue 322 limited tif support +opj_compress -i @INPUT_NR_PATH@/flower-minisblack-01.tif -o @TEMP_PATH@/flower-minisblack-01.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-minisblack-02.tif -o @TEMP_PATH@/flower-minisblack-02.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-minisblack-04.tif -o @TEMP_PATH@/flower-minisblack-04.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-minisblack-06.tif -o @TEMP_PATH@/flower-minisblack-06.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-minisblack-08.tif -o @TEMP_PATH@/flower-minisblack-08.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-minisblack-10.tif -o @TEMP_PATH@/flower-minisblack-10.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-minisblack-12.tif -o @TEMP_PATH@/flower-minisblack-12.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-minisblack-14.tif -o @TEMP_PATH@/flower-minisblack-14.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-minisblack-16.tif -o @TEMP_PATH@/flower-minisblack-16.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-rgb-contig-02.tif -o @TEMP_PATH@/flower-rgb-contig-02.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-rgb-contig-04.tif -o @TEMP_PATH@/flower-rgb-contig-04.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-rgb-contig-08.tif -o @TEMP_PATH@/flower-rgb-contig-08.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-rgb-contig-10.tif -o @TEMP_PATH@/flower-rgb-contig-10.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-rgb-contig-12.tif -o @TEMP_PATH@/flower-rgb-contig-12.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-rgb-contig-14.tif -o @TEMP_PATH@/flower-rgb-contig-14.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-rgb-contig-16.tif -o @TEMP_PATH@/flower-rgb-contig-16.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-rgb-planar-02.tif -o @TEMP_PATH@/flower-rgb-planar-02.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-rgb-planar-04.tif -o @TEMP_PATH@/flower-rgb-planar-04.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-rgb-planar-08.tif -o @TEMP_PATH@/flower-rgb-planar-08.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-rgb-planar-10.tif -o @TEMP_PATH@/flower-rgb-planar-10.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-rgb-planar-12.tif -o @TEMP_PATH@/flower-rgb-planar-12.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-rgb-planar-14.tif -o @TEMP_PATH@/flower-rgb-planar-14.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-rgb-planar-16.tif -o @TEMP_PATH@/flower-rgb-planar-16.tif.jp2 + # DECODER TEST SUITE opj_decompress -i @INPUT_NR_PATH@/Bretagne2.j2k -o @TEMP_PATH@/Bretagne2.j2k.pgx opj_decompress -i @INPUT_NR_PATH@/_00042.j2k -o @TEMP_PATH@/_00042.j2k.pgx From d1591be3d7f5a95a11b2d5d1647f79d01c8c5bc1 Mon Sep 17 00:00:00 2001 From: mayeut Date: Fri, 17 Jul 2015 23:22:40 +0200 Subject: [PATCH 05/10] Add tests for TIFF output Update uclouvain/openjpeg#322 --- tests/nonregression/checkmd5refs.cmake | 2 +- tests/nonregression/md5refs.txt | 36 +++++++++++++++++++++ tests/nonregression/test_suite.ctest.in | 42 +++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/tests/nonregression/checkmd5refs.cmake b/tests/nonregression/checkmd5refs.cmake index bbc7ac32..40e019b7 100644 --- a/tests/nonregression/checkmd5refs.cmake +++ b/tests/nonregression/checkmd5refs.cmake @@ -32,7 +32,7 @@ get_filename_component(OUTFILENAME_NAME ${OUTFILENAME} NAME) string(FIND ${OUTFILENAME_NAME} "." SHORTEST_EXT_POS REVERSE) string(SUBSTRING ${OUTFILENAME_NAME} 0 ${SHORTEST_EXT_POS} OUTFILENAME_NAME_WE) -file(GLOB globfiles "Temporary/${OUTFILENAME_NAME_WE}*.pgx" "Temporary/${OUTFILENAME_NAME_WE}*.png") +file(GLOB globfiles "Temporary/${OUTFILENAME_NAME_WE}*.pgx" "Temporary/${OUTFILENAME_NAME_WE}*.png" "Temporary/${OUTFILENAME_NAME_WE}*.tif") if(NOT globfiles) message(SEND_ERROR "Could not find output PGX files: ${OUTFILENAME_NAME_WE}") endif() diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index eeb40bcc..3465b099 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -182,3 +182,39 @@ dacaf60e4c430916a8c2a9ebec32e71c issue458.jp2_3.pgx d33fb5dbddb9b9b4438eb51fa27445a3 issue495.jp2_0.pgx 27db8c35e12a5d5eb94d403d2aae2909 issue495.jp2_1.pgx 97da625d2f2d0b75bf891d8083ce8bfb issue495.jp2_2.pgx +86729c5f2b74b2dfd42cb0d8e47aef79 a1_mono_tif-1.tif +fa9b7b896536b25a7a1d8eeeacb59141 a1_mono_tif-10.tif +b0ee13aa90ca4421e09a3b7b41f410c0 a1_mono_tif-12.tif +4699894fedd3758727d8288cd7adb56c a1_mono_tif-14.tif +4ad682c58e63d3223914c10a6656c8ae a1_mono_tif-16.tif +22c2fa09a4d7b9fade6a3cddc6c6a4dc a1_mono_tif-2.tif +996c5e67a663218be90e86bff8ecad89 a1_mono_tif-4.tif +7f451a5ac89915c5cdc023fd8c813a3c a1_mono_tif-6.tif +c3ebfcf478b1c4fc786748813f2b5d53 a1_mono_tif-8.tif +31650ec40241737634179fff6ad306f8 basn4a08_tif-1.tif +abf884080bcfbf58c044a9d86bfa5e5d basn4a08_tif-10.tif +916d97c098d9792993cc91fee4a83f77 basn4a08_tif-12.tif +57643174986481d336db6ddf04b970df basn4a08_tif-14.tif +fb5cf848d63c61dc485c87c9246ee9c7 basn4a08_tif-16.tif +5d7b01d98c82ad563bb28c2d83484a2a basn4a08_tif-2.tif +2401cebbb1d5494fcbe0d899484c342d basn4a08_tif-4.tif +6dbeb5b708bbde76e204c0887da61f6b basn4a08_tif-6.tif +dc40cc1da6de28e7e973c8ba796ca189 basn4a08_tif-8.tif +59e32c45591fd3bb44fe99381a116ba1 basn6a08_tif-1.tif +630e6fb6deba0b3efd93b610561d607a basn6a08_tif-10.tif +765555e75e59de27f7b2177d04f36bc1 basn6a08_tif-12.tif +62384c112d5fe40aefd0a9b0b9a4bcc6 basn6a08_tif-14.tif +d725d41557658a28ab31dff74e2467fa basn6a08_tif-16.tif +96d91df6b10e866ea26ebbf0b8ddc7da basn6a08_tif-2.tif +a324032339808d5fe85d6e354f14c183 basn6a08_tif-4.tif +d60864a6a5c8a49a202d98ae6f5165c7 basn6a08_tif-6.tif +c3e93f61125f82a9832d0b9440468034 basn6a08_tif-8.tif +cfe04d15cf9d615fc36357dcb3b3956b p0_14_tif-1.tif +9ad87e7fddc77ac85e2e92509bee2365 p0_14_tif-10.tif +38e67f9d573e61166761d5eee0104448 p0_14_tif-12.tif +77486f0468694b94290d0b55361498a0 p0_14_tif-14.tif +51be675689949dd08b6ee1427af3eb4a p0_14_tif-16.tif +3e34e94bd8f7380c8d159676fee9ea57 p0_14_tif-2.tif +b6f71c941e3a5b8d2547792ccec58d54 p0_14_tif-4.tif +81fcdd90917efb95aed94c6522d1c188 p0_14_tif-6.tif +6808377b760b4ef3559ba8b14ed9b91a p0_14_tif-8.tif diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 9dd804a3..0a3645eb 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -366,3 +366,45 @@ opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04_6_5.j2k.png - #opj_decompress -i @INPUT_CONF_PATH@/p1_01.j2k -o @TEMP_PATH@/p1_01_3.j2k.png -d 10,150,190,210 #opj_decompress -i @INPUT_CONF_PATH@/p1_01.j2k -o @TEMP_PATH@/p1_01_4.j2k.png -d 100,80,200,150 #opj_decompress -i @INPUT_CONF_PATH@/p1_01.j2k -o @TEMP_PATH@/p1_01_5.j2k.png -d 150,20,200,50 + +# issue 322 limited tif support +# GRAYSCALE +opj_decompress -i @INPUT_CONF_PATH@/a1_mono.j2c -o @TEMP_PATH@/a1_mono_tif-1.tif -p 1S +opj_decompress -i @INPUT_CONF_PATH@/a1_mono.j2c -o @TEMP_PATH@/a1_mono_tif-2.tif -p 2S +opj_decompress -i @INPUT_CONF_PATH@/a1_mono.j2c -o @TEMP_PATH@/a1_mono_tif-4.tif -p 4S +opj_decompress -i @INPUT_CONF_PATH@/a1_mono.j2c -o @TEMP_PATH@/a1_mono_tif-6.tif -p 6S +opj_decompress -i @INPUT_CONF_PATH@/a1_mono.j2c -o @TEMP_PATH@/a1_mono_tif-8.tif -p 8S +opj_decompress -i @INPUT_CONF_PATH@/a1_mono.j2c -o @TEMP_PATH@/a1_mono_tif-10.tif -p 10S +opj_decompress -i @INPUT_CONF_PATH@/a1_mono.j2c -o @TEMP_PATH@/a1_mono_tif-12.tif -p 12S +opj_decompress -i @INPUT_CONF_PATH@/a1_mono.j2c -o @TEMP_PATH@/a1_mono_tif-14.tif -p 14S +opj_decompress -i @INPUT_CONF_PATH@/a1_mono.j2c -o @TEMP_PATH@/a1_mono_tif-16.tif -p 16S +# GRAYSCALE ALPHA +opj_decompress -i @INPUT_NR_PATH@/basn4a08.jp2 -o @TEMP_PATH@/basn4a08_tif-1.tif -p 1S +opj_decompress -i @INPUT_NR_PATH@/basn4a08.jp2 -o @TEMP_PATH@/basn4a08_tif-2.tif -p 2S +opj_decompress -i @INPUT_NR_PATH@/basn4a08.jp2 -o @TEMP_PATH@/basn4a08_tif-4.tif -p 4S +opj_decompress -i @INPUT_NR_PATH@/basn4a08.jp2 -o @TEMP_PATH@/basn4a08_tif-6.tif -p 6S +opj_decompress -i @INPUT_NR_PATH@/basn4a08.jp2 -o @TEMP_PATH@/basn4a08_tif-8.tif -p 8S +opj_decompress -i @INPUT_NR_PATH@/basn4a08.jp2 -o @TEMP_PATH@/basn4a08_tif-10.tif -p 10S +opj_decompress -i @INPUT_NR_PATH@/basn4a08.jp2 -o @TEMP_PATH@/basn4a08_tif-12.tif -p 12S +opj_decompress -i @INPUT_NR_PATH@/basn4a08.jp2 -o @TEMP_PATH@/basn4a08_tif-14.tif -p 14S +opj_decompress -i @INPUT_NR_PATH@/basn4a08.jp2 -o @TEMP_PATH@/basn4a08_tif-16.tif -p 16S +# RGB +opj_decompress -i @INPUT_CONF_PATH@/p0_14.j2k -o @TEMP_PATH@/p0_14_tif-1.tif -p 1S +opj_decompress -i @INPUT_CONF_PATH@/p0_14.j2k -o @TEMP_PATH@/p0_14_tif-2.tif -p 2S +opj_decompress -i @INPUT_CONF_PATH@/p0_14.j2k -o @TEMP_PATH@/p0_14_tif-4.tif -p 4S +opj_decompress -i @INPUT_CONF_PATH@/p0_14.j2k -o @TEMP_PATH@/p0_14_tif-6.tif -p 6S +opj_decompress -i @INPUT_CONF_PATH@/p0_14.j2k -o @TEMP_PATH@/p0_14_tif-8.tif -p 8S +opj_decompress -i @INPUT_CONF_PATH@/p0_14.j2k -o @TEMP_PATH@/p0_14_tif-10.tif -p 10S +opj_decompress -i @INPUT_CONF_PATH@/p0_14.j2k -o @TEMP_PATH@/p0_14_tif-12.tif -p 12S +opj_decompress -i @INPUT_CONF_PATH@/p0_14.j2k -o @TEMP_PATH@/p0_14_tif-14.tif -p 14S +opj_decompress -i @INPUT_CONF_PATH@/p0_14.j2k -o @TEMP_PATH@/p0_14_tif-16.tif -p 16S +# RGBA +opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-1.tif -p 1S +opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-2.tif -p 2S +opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-4.tif -p 4S +opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-6.tif -p 6S +opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-8.tif -p 8S +opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-10.tif -p 10S +opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-12.tif -p 12S +opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-14.tif -p 14S +opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-16.tif -p 16S From 8048bbc7a2c82d8342c3372690ccd3c9a6359425 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 18 Jul 2015 00:07:04 +0200 Subject: [PATCH 06/10] Add tests for TIFF input with Alpha channel Update uclouvain/openjpeg#322 --- src/bin/jp2/converttif.c | 1 + tests/nonregression/test_suite.ctest.in | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/bin/jp2/converttif.c b/src/bin/jp2/converttif.c index 21bb11f8..d93e5f53 100644 --- a/src/bin/jp2/converttif.c +++ b/src/bin/jp2/converttif.c @@ -977,6 +977,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) { planes[j] = image->comps[j].data; } + image->comps[numcomps - 1].alpha = (OPJ_UINT16)(1 - (numcomps & 1)); strip_size = TIFFStripSize(tif); diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 0a3645eb..053d9318 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -98,6 +98,9 @@ opj_compress -i @INPUT_NR_PATH@/flower-rgb-planar-10.tif -o @TEMP_PATH@/flower-r opj_compress -i @INPUT_NR_PATH@/flower-rgb-planar-12.tif -o @TEMP_PATH@/flower-rgb-planar-12.tif.jp2 opj_compress -i @INPUT_NR_PATH@/flower-rgb-planar-14.tif -o @TEMP_PATH@/flower-rgb-planar-14.tif.jp2 opj_compress -i @INPUT_NR_PATH@/flower-rgb-planar-16.tif -o @TEMP_PATH@/flower-rgb-planar-16.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/basn6a08.tif -o @TEMP_PATH@/basn6a08.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/basn4a08.tif -o @TEMP_PATH@/basn4a08.tif.jp2 + # DECODER TEST SUITE opj_decompress -i @INPUT_NR_PATH@/Bretagne2.j2k -o @TEMP_PATH@/Bretagne2.j2k.pgx From b88025b38fbd12e46c5eea436c82c8d861bc0403 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 18 Jul 2015 01:50:17 +0200 Subject: [PATCH 07/10] Add headers to CMake target --- src/bin/jp2/CMakeLists.txt | 4 ++++ src/lib/openjp2/CMakeLists.txt | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/bin/jp2/CMakeLists.txt b/src/bin/jp2/CMakeLists.txt index 95d1430d..857a1d92 100644 --- a/src/bin/jp2/CMakeLists.txt +++ b/src/bin/jp2/CMakeLists.txt @@ -3,10 +3,14 @@ # First thing define the common source: set(common_SRCS convert.c + convert.h convertbmp.c index.c + index.h ${OPENJPEG_SOURCE_DIR}/src/bin/common/color.c + ${OPENJPEG_SOURCE_DIR}/src/bin/common/color.h ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c + ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.h ) if(OPJ_HAVE_LIBTIFF) diff --git a/src/lib/openjp2/CMakeLists.txt b/src/lib/openjp2/CMakeLists.txt index 0795f7c5..414664f9 100644 --- a/src/lib/openjp2/CMakeLists.txt +++ b/src/lib/openjp2/CMakeLists.txt @@ -10,34 +10,60 @@ include_directories( # Defines the source code for the library set(OPENJPEG_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/bio.c + ${CMAKE_CURRENT_SOURCE_DIR}/bio.h ${CMAKE_CURRENT_SOURCE_DIR}/cio.c + ${CMAKE_CURRENT_SOURCE_DIR}/cio.h ${CMAKE_CURRENT_SOURCE_DIR}/dwt.c + ${CMAKE_CURRENT_SOURCE_DIR}/dwt.h ${CMAKE_CURRENT_SOURCE_DIR}/event.c + ${CMAKE_CURRENT_SOURCE_DIR}/event.h ${CMAKE_CURRENT_SOURCE_DIR}/image.c + ${CMAKE_CURRENT_SOURCE_DIR}/image.h ${CMAKE_CURRENT_SOURCE_DIR}/invert.c + ${CMAKE_CURRENT_SOURCE_DIR}/invert.h ${CMAKE_CURRENT_SOURCE_DIR}/j2k.c + ${CMAKE_CURRENT_SOURCE_DIR}/j2k.h ${CMAKE_CURRENT_SOURCE_DIR}/jp2.c + ${CMAKE_CURRENT_SOURCE_DIR}/jp2.h ${CMAKE_CURRENT_SOURCE_DIR}/mct.c + ${CMAKE_CURRENT_SOURCE_DIR}/mct.h ${CMAKE_CURRENT_SOURCE_DIR}/mqc.c + ${CMAKE_CURRENT_SOURCE_DIR}/mqc.h ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.c + ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.h ${CMAKE_CURRENT_SOURCE_DIR}/opj_clock.c + ${CMAKE_CURRENT_SOURCE_DIR}/opj_clock.h ${CMAKE_CURRENT_SOURCE_DIR}/pi.c + ${CMAKE_CURRENT_SOURCE_DIR}/pi.h ${CMAKE_CURRENT_SOURCE_DIR}/raw.c + ${CMAKE_CURRENT_SOURCE_DIR}/raw.h ${CMAKE_CURRENT_SOURCE_DIR}/t1.c + ${CMAKE_CURRENT_SOURCE_DIR}/t1.h ${CMAKE_CURRENT_SOURCE_DIR}/t2.c + ${CMAKE_CURRENT_SOURCE_DIR}/t2.h ${CMAKE_CURRENT_SOURCE_DIR}/tcd.c + ${CMAKE_CURRENT_SOURCE_DIR}/tcd.h ${CMAKE_CURRENT_SOURCE_DIR}/tgt.c + ${CMAKE_CURRENT_SOURCE_DIR}/tgt.h ${CMAKE_CURRENT_SOURCE_DIR}/function_list.c + ${CMAKE_CURRENT_SOURCE_DIR}/function_list.h + ${CMAKE_CURRENT_SOURCE_DIR}/opj_codec.h + ${CMAKE_CURRENT_SOURCE_DIR}/opj_includes.h + ${CMAKE_CURRENT_SOURCE_DIR}/opj_intmath.h + ${CMAKE_CURRENT_SOURCE_DIR}/opj_malloc.h + ${CMAKE_CURRENT_SOURCE_DIR}/opj_stdint.h ) if(BUILD_JPIP) add_definitions(-DUSE_JPIP) set(OPENJPEG_SRCS ${OPENJPEG_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/cidx_manager.c + ${CMAKE_CURRENT_SOURCE_DIR}/cidx_manager.h ${CMAKE_CURRENT_SOURCE_DIR}/phix_manager.c ${CMAKE_CURRENT_SOURCE_DIR}/ppix_manager.c ${CMAKE_CURRENT_SOURCE_DIR}/thix_manager.c ${CMAKE_CURRENT_SOURCE_DIR}/tpix_manager.c + ${CMAKE_CURRENT_SOURCE_DIR}/indexbox_manager.h ) endif() From ae4799ad076837cd83d7f414d8adbbc5bd9107dc Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 18 Jul 2015 02:39:32 +0200 Subject: [PATCH 08/10] Add some missing static Still needs to check j2k.c & jp2.c Update uclouvain/openjpeg#243 --- src/lib/openjp2/bio.c | 8 +++--- src/lib/openjp2/dwt.c | 34 +++++++++++------------ src/lib/openjp2/invert.c | 6 ++-- src/lib/openjp2/mqc.c | 10 +++---- src/lib/openjp2/pi.c | 28 +++++++++---------- src/lib/openjp2/t1.c | 60 ++++++++++++++++++++-------------------- src/lib/openjp2/t2.c | 16 +++++------ src/lib/openjp2/tcd.c | 28 +++++++++---------- 8 files changed, 95 insertions(+), 95 deletions(-) diff --git a/src/lib/openjp2/bio.c b/src/lib/openjp2/bio.c index 3ce64927..e4edb372 100644 --- a/src/lib/openjp2/bio.c +++ b/src/lib/openjp2/bio.c @@ -78,7 +78,7 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio); ========================================================== */ -OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) { +static OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) { bio->buf = (bio->buf << 8) & 0xffff; bio->ct = bio->buf == 0xff00 ? 7 : 8; if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) { @@ -88,7 +88,7 @@ OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) { return OPJ_TRUE; } -OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) { +static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) { bio->buf = (bio->buf << 8) & 0xffff; bio->ct = bio->buf == 0xff00 ? 7 : 8; if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) { @@ -98,7 +98,7 @@ OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) { return OPJ_TRUE; } -void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b) { +static void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b) { if (bio->ct == 0) { opj_bio_byteout(bio); /* MSD: why not check the return value of this function ? */ } @@ -106,7 +106,7 @@ void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b) { bio->buf |= b << bio->ct; } -OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio) { +static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio) { if (bio->ct == 0) { opj_bio_bytein(bio); /* MSD: why not check the return value of this function ? */ } diff --git a/src/lib/openjp2/dwt.c b/src/lib/openjp2/dwt.c index bea45742..4ad99ed9 100644 --- a/src/lib/openjp2/dwt.c +++ b/src/lib/openjp2/dwt.c @@ -193,7 +193,7 @@ static const OPJ_FLOAT64 opj_dwt_norms_real[4][10] = { /* */ /* Forward lazy transform (horizontal). */ /* */ -void opj_dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) { +static void opj_dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) { OPJ_INT32 i; OPJ_INT32 * l_dest = b; OPJ_INT32 * l_src = a+cas; @@ -215,7 +215,7 @@ void opj_dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 /* */ /* Forward lazy transform (vertical). */ /* */ -void opj_dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 x, OPJ_INT32 cas) { +static void opj_dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 x, OPJ_INT32 cas) { OPJ_INT32 i = sn; OPJ_INT32 * l_dest = b; OPJ_INT32 * l_src = a+cas; @@ -240,7 +240,7 @@ void opj_dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 /* */ /* Inverse lazy transform (horizontal). */ /* */ -void opj_dwt_interleave_h(opj_dwt_t* h, OPJ_INT32 *a) { +static void opj_dwt_interleave_h(opj_dwt_t* h, OPJ_INT32 *a) { OPJ_INT32 *ai = a; OPJ_INT32 *bi = h->mem + h->cas; OPJ_INT32 i = h->sn; @@ -260,7 +260,7 @@ void opj_dwt_interleave_h(opj_dwt_t* h, OPJ_INT32 *a) { /* */ /* Inverse lazy transform (vertical). */ /* */ -void opj_dwt_interleave_v(opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x) { +static void opj_dwt_interleave_v(opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x) { OPJ_INT32 *ai = a; OPJ_INT32 *bi = v->mem + v->cas; OPJ_INT32 i = v->sn; @@ -283,7 +283,7 @@ void opj_dwt_interleave_v(opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x) { /* */ /* Forward 5-3 wavelet transform in 1-D. */ /* */ -void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) { +static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) { OPJ_INT32 i; if (!cas) { @@ -304,7 +304,7 @@ void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) { /* */ /* Inverse 5-3 wavelet transform in 1-D. */ /* */ -void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) { +static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) { OPJ_INT32 i; if (!cas) { @@ -325,14 +325,14 @@ void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) /* */ /* Inverse 5-3 wavelet transform in 1-D. */ /* */ -void opj_dwt_decode_1(opj_dwt_t *v) { +static void opj_dwt_decode_1(opj_dwt_t *v) { opj_dwt_decode_1_(v->mem, v->dn, v->sn, v->cas); } /* */ /* Forward 9-7 wavelet transform in 1-D. */ /* */ -void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) { +static void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) { OPJ_INT32 i; if (!cas) { if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ @@ -367,7 +367,7 @@ void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 c } } -void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_stepsize_t *bandno_stepsize) { +static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_stepsize_t *bandno_stepsize) { OPJ_INT32 p, n; p = opj_int_floorlog2(stepsize) - 13; n = 11 - opj_int_floorlog2(stepsize); @@ -385,7 +385,7 @@ void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_stepsize_ /* */ /* Forward 5-3 wavelet transform in 2-D. */ /* */ -INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void (*p_function)(OPJ_INT32 *, OPJ_INT32,OPJ_INT32,OPJ_INT32) ) +static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void (*p_function)(OPJ_INT32 *, OPJ_INT32,OPJ_INT32,OPJ_INT32) ) { OPJ_INT32 i, j, k; OPJ_INT32 *a = 00; @@ -541,7 +541,7 @@ void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec) { /* */ /* Determine maximum computed resolution level for inverse wavelet transform */ /* */ -OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i) { +static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i) { OPJ_UINT32 mr = 0; OPJ_UINT32 w; while( --i ) { @@ -557,7 +557,7 @@ OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i /* */ /* Inverse wavelet transform in 2-D. */ /* */ -OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1DFN dwt_1D) { +static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1DFN dwt_1D) { opj_dwt_t h; opj_dwt_t v; @@ -613,7 +613,7 @@ OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1D return OPJ_TRUE; } -void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restrict a, OPJ_INT32 x, OPJ_INT32 size){ +static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restrict a, OPJ_INT32 x, OPJ_INT32 size){ OPJ_FLOAT32* restrict bi = (OPJ_FLOAT32*) (w->wavelet + w->cas); OPJ_INT32 count = w->sn; OPJ_INT32 i, k; @@ -656,7 +656,7 @@ void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restrict a, OP } } -void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restrict a , OPJ_INT32 x, OPJ_INT32 nb_elts_read){ +static void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restrict a , OPJ_INT32 x, OPJ_INT32 nb_elts_read){ opj_v4_t* restrict bi = v->wavelet + v->cas; OPJ_INT32 i; @@ -674,7 +674,7 @@ void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restrict a , #ifdef __SSE__ -void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m128 c){ +static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m128 c){ __m128* restrict vw = (__m128*) w; OPJ_INT32 i; /* 4x unrolled loop */ @@ -723,7 +723,7 @@ void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32 #else -void opj_v4dwt_decode_step1(opj_v4_t* w, OPJ_INT32 count, const OPJ_FLOAT32 c) +static void opj_v4dwt_decode_step1(opj_v4_t* w, OPJ_INT32 count, const OPJ_FLOAT32 c) { OPJ_FLOAT32* restrict fw = (OPJ_FLOAT32*) w; OPJ_INT32 i; @@ -739,7 +739,7 @@ void opj_v4dwt_decode_step1(opj_v4_t* w, OPJ_INT32 count, const OPJ_FLOAT32 c) } } -void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32 m, OPJ_FLOAT32 c) +static void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32 m, OPJ_FLOAT32 c) { OPJ_FLOAT32* restrict fl = (OPJ_FLOAT32*) l; OPJ_FLOAT32* restrict fw = (OPJ_FLOAT32*) w; diff --git a/src/lib/openjp2/invert.c b/src/lib/openjp2/invert.c index 4c1ee780..dd4998a9 100644 --- a/src/lib/openjp2/invert.c +++ b/src/lib/openjp2/invert.c @@ -103,7 +103,7 @@ OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix, Local functions ========================================================== */ -OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations, +static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations, OPJ_FLOAT32 * p_swap_area, OPJ_UINT32 nb_compo) { @@ -204,7 +204,7 @@ OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations, return OPJ_TRUE; } -void opj_lupSolve (OPJ_FLOAT32 * pResult, +static void opj_lupSolve (OPJ_FLOAT32 * pResult, OPJ_FLOAT32 * pMatrix, OPJ_FLOAT32 * pVector, OPJ_UINT32* pPermutations, @@ -266,7 +266,7 @@ void opj_lupSolve (OPJ_FLOAT32 * pResult, } -void opj_lupInvert (OPJ_FLOAT32 * pSrcMatrix, +static void opj_lupInvert (OPJ_FLOAT32 * pSrcMatrix, OPJ_FLOAT32 * pDestMatrix, OPJ_UINT32 nb_compo, OPJ_UINT32 * pPermutations, diff --git a/src/lib/openjp2/mqc.c b/src/lib/openjp2/mqc.c index 075594b9..7e0f5637 100644 --- a/src/lib/openjp2/mqc.c +++ b/src/lib/openjp2/mqc.c @@ -202,7 +202,7 @@ static opj_mqc_state_t mqc_states[47 * 2] = { ========================================================== */ -void opj_mqc_byteout(opj_mqc_t *mqc) { +static void opj_mqc_byteout(opj_mqc_t *mqc) { if (*mqc->bp == 0xff) { mqc->bp++; *mqc->bp = (OPJ_BYTE)(mqc->c >> 20); @@ -232,7 +232,7 @@ void opj_mqc_byteout(opj_mqc_t *mqc) { } } -void opj_mqc_renorme(opj_mqc_t *mqc) { +static void opj_mqc_renorme(opj_mqc_t *mqc) { do { mqc->a <<= 1; mqc->c <<= 1; @@ -243,7 +243,7 @@ void opj_mqc_renorme(opj_mqc_t *mqc) { } while ((mqc->a & 0x8000) == 0); } -void opj_mqc_codemps(opj_mqc_t *mqc) { +static void opj_mqc_codemps(opj_mqc_t *mqc) { mqc->a -= (*mqc->curctx)->qeval; if ((mqc->a & 0x8000) == 0) { if (mqc->a < (*mqc->curctx)->qeval) { @@ -258,7 +258,7 @@ void opj_mqc_codemps(opj_mqc_t *mqc) { } } -void opj_mqc_codelps(opj_mqc_t *mqc) { +static void opj_mqc_codelps(opj_mqc_t *mqc) { mqc->a -= (*mqc->curctx)->qeval; if (mqc->a < (*mqc->curctx)->qeval) { mqc->c += (*mqc->curctx)->qeval; @@ -269,7 +269,7 @@ void opj_mqc_codelps(opj_mqc_t *mqc) { opj_mqc_renorme(mqc); } -void opj_mqc_setbits(opj_mqc_t *mqc) { +static void opj_mqc_setbits(opj_mqc_t *mqc) { OPJ_UINT32 tempc = mqc->c + mqc->a; mqc->c |= 0xffff; if (mqc->c >= tempc) { diff --git a/src/lib/openjp2/pi.c b/src/lib/openjp2/pi.c index 393a1e55..e32aaeb0 100644 --- a/src/lib/openjp2/pi.c +++ b/src/lib/openjp2/pi.c @@ -214,7 +214,7 @@ static void opj_pi_update_decode_poc ( opj_pi_iterator_t * p_pi, /** * FIXME DOC */ -OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos, +static OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos, opj_cp_t *cp, OPJ_UINT32 tileno, OPJ_UINT32 pino, @@ -230,7 +230,7 @@ OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos, ========================================================== */ -OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi) { +static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; @@ -270,7 +270,7 @@ LABEL_SKIP:; return OPJ_FALSE; } -OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi) { +static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; @@ -309,7 +309,7 @@ LABEL_SKIP:; return OPJ_FALSE; } -OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi) { +static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; @@ -392,7 +392,7 @@ LABEL_SKIP:; return OPJ_FALSE; } -OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) { +static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; @@ -473,7 +473,7 @@ LABEL_SKIP:; return OPJ_FALSE; } -OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) { +static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; @@ -552,7 +552,7 @@ LABEL_SKIP:; return OPJ_FALSE; } -void opj_get_encoding_parameters( const opj_image_t *p_image, +static void opj_get_encoding_parameters( const opj_image_t *p_image, const opj_cp_t *p_cp, OPJ_UINT32 p_tileno, OPJ_INT32 * p_tx0, @@ -666,7 +666,7 @@ void opj_get_encoding_parameters( const opj_image_t *p_image, } -void opj_get_all_encoding_parameters( const opj_image_t *p_image, +static void opj_get_all_encoding_parameters( const opj_image_t *p_image, const opj_cp_t *p_cp, OPJ_UINT32 tileno, OPJ_INT32 * p_tx0, @@ -789,7 +789,7 @@ void opj_get_all_encoding_parameters( const opj_image_t *p_image, } } -opj_pi_iterator_t * opj_pi_create( const opj_image_t *image, +static opj_pi_iterator_t * opj_pi_create( const opj_image_t *image, const opj_cp_t *cp, OPJ_UINT32 tileno ) { @@ -850,7 +850,7 @@ opj_pi_iterator_t * opj_pi_create( const opj_image_t *image, return l_pi; } -void opj_pi_update_encode_poc_and_final ( opj_cp_t *p_cp, +static void opj_pi_update_encode_poc_and_final ( opj_cp_t *p_cp, OPJ_UINT32 p_tileno, OPJ_INT32 p_tx0, OPJ_INT32 p_tx1, @@ -928,7 +928,7 @@ void opj_pi_update_encode_poc_and_final ( opj_cp_t *p_cp, } } -void opj_pi_update_encode_not_poc ( opj_cp_t *p_cp, +static void opj_pi_update_encode_not_poc ( opj_cp_t *p_cp, OPJ_UINT32 p_num_comps, OPJ_UINT32 p_tileno, OPJ_INT32 p_tx0, @@ -983,7 +983,7 @@ void opj_pi_update_encode_not_poc ( opj_cp_t *p_cp, } } -void opj_pi_update_decode_poc (opj_pi_iterator_t * p_pi, +static void opj_pi_update_decode_poc (opj_pi_iterator_t * p_pi, opj_tcp_t * p_tcp, OPJ_UINT32 p_max_precision, OPJ_UINT32 p_max_res) @@ -1025,7 +1025,7 @@ void opj_pi_update_decode_poc (opj_pi_iterator_t * p_pi, } } -void opj_pi_update_decode_not_poc (opj_pi_iterator_t * p_pi, +static void opj_pi_update_decode_not_poc (opj_pi_iterator_t * p_pi, opj_tcp_t * p_tcp, OPJ_UINT32 p_max_precision, OPJ_UINT32 p_max_res) @@ -1062,7 +1062,7 @@ void opj_pi_update_decode_not_poc (opj_pi_iterator_t * p_pi, -OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos, +static OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos, opj_cp_t *cp, OPJ_UINT32 tileno, OPJ_UINT32 pino, diff --git a/src/lib/openjp2/t1.c b/src/lib/openjp2/t1.c index 08883545..108ce78b 100644 --- a/src/lib/openjp2/t1.c +++ b/src/lib/openjp2/t1.c @@ -295,7 +295,7 @@ static OPJ_BOOL opj_t1_decode_cblk( opj_t1_t *t1, OPJ_UINT32 roishift, OPJ_UINT32 cblksty); -OPJ_BOOL opj_t1_allocate_buffers( opj_t1_t *t1, +static OPJ_BOOL opj_t1_allocate_buffers( opj_t1_t *t1, OPJ_UINT32 w, OPJ_UINT32 h); @@ -305,25 +305,25 @@ OPJ_BOOL opj_t1_allocate_buffers( opj_t1_t *t1, /* ----------------------------------------------------------------------- */ -OPJ_BYTE opj_t1_getctxno_zc(OPJ_UINT32 f, OPJ_UINT32 orient) { +static OPJ_BYTE opj_t1_getctxno_zc(OPJ_UINT32 f, OPJ_UINT32 orient) { return lut_ctxno_zc[(orient << 8) | (f & T1_SIG_OTH)]; } -OPJ_BYTE opj_t1_getctxno_sc(OPJ_UINT32 f) { +static OPJ_BYTE opj_t1_getctxno_sc(OPJ_UINT32 f) { return lut_ctxno_sc[(f & (T1_SIG_PRIM | T1_SGN)) >> 4]; } -OPJ_UINT32 opj_t1_getctxno_mag(OPJ_UINT32 f) { +static OPJ_UINT32 opj_t1_getctxno_mag(OPJ_UINT32 f) { OPJ_UINT32 tmp1 = (f & T1_SIG_OTH) ? T1_CTXNO_MAG + 1 : T1_CTXNO_MAG; OPJ_UINT32 tmp2 = (f & T1_REFINE) ? T1_CTXNO_MAG + 2 : tmp1; return (tmp2); } -OPJ_BYTE opj_t1_getspb(OPJ_UINT32 f) { +static OPJ_BYTE opj_t1_getspb(OPJ_UINT32 f) { return lut_spb[(f & (T1_SIG_PRIM | T1_SGN)) >> 4]; } -OPJ_INT16 opj_t1_getnmsedec_sig(OPJ_UINT32 x, OPJ_UINT32 bitpos) { +static OPJ_INT16 opj_t1_getnmsedec_sig(OPJ_UINT32 x, OPJ_UINT32 bitpos) { if (bitpos > 0) { return lut_nmsedec_sig[(x >> (bitpos)) & ((1 << T1_NMSEDEC_BITS) - 1)]; } @@ -331,7 +331,7 @@ OPJ_INT16 opj_t1_getnmsedec_sig(OPJ_UINT32 x, OPJ_UINT32 bitpos) { return lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; } -OPJ_INT16 opj_t1_getnmsedec_ref(OPJ_UINT32 x, OPJ_UINT32 bitpos) { +static OPJ_INT16 opj_t1_getnmsedec_ref(OPJ_UINT32 x, OPJ_UINT32 bitpos) { if (bitpos > 0) { return lut_nmsedec_ref[(x >> (bitpos)) & ((1 << T1_NMSEDEC_BITS) - 1)]; } @@ -339,7 +339,7 @@ OPJ_INT16 opj_t1_getnmsedec_ref(OPJ_UINT32 x, OPJ_UINT32 bitpos) { return lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; } -void opj_t1_updateflags(opj_flag_t *flagsp, OPJ_UINT32 s, OPJ_UINT32 stride) { +static void opj_t1_updateflags(opj_flag_t *flagsp, OPJ_UINT32 s, OPJ_UINT32 stride) { opj_flag_t *np = flagsp - stride; opj_flag_t *sp = flagsp + stride; @@ -363,7 +363,7 @@ void opj_t1_updateflags(opj_flag_t *flagsp, OPJ_UINT32 s, OPJ_UINT32 stride) { sp[1] |= T1_SIG_NW; } -void opj_t1_enc_sigpass_step( opj_t1_t *t1, +static void opj_t1_enc_sigpass_step( opj_t1_t *t1, opj_flag_t *flagsp, OPJ_INT32 *datap, OPJ_UINT32 orient, @@ -427,7 +427,7 @@ static INLINE void opj_t1_dec_sigpass_step_raw( } } -INLINE void opj_t1_dec_sigpass_step_mqc( +static INLINE void opj_t1_dec_sigpass_step_mqc( opj_t1_t *t1, opj_flag_t *flagsp, OPJ_INT32 *datap, @@ -451,7 +451,7 @@ INLINE void opj_t1_dec_sigpass_step_mqc( } } /* VSC and BYPASS by Antonin */ -INLINE void opj_t1_dec_sigpass_step_mqc_vsc( +static INLINE void opj_t1_dec_sigpass_step_mqc_vsc( opj_t1_t *t1, opj_flag_t *flagsp, OPJ_INT32 *datap, @@ -478,7 +478,7 @@ INLINE void opj_t1_dec_sigpass_step_mqc_vsc( -void opj_t1_enc_sigpass(opj_t1_t *t1, +static void opj_t1_enc_sigpass(opj_t1_t *t1, OPJ_INT32 bpno, OPJ_UINT32 orient, OPJ_INT32 *nmsedec, @@ -510,7 +510,7 @@ void opj_t1_enc_sigpass(opj_t1_t *t1, } } -void opj_t1_dec_sigpass_raw( +static void opj_t1_dec_sigpass_raw( opj_t1_t *t1, OPJ_INT32 bpno, OPJ_INT32 orient, @@ -537,7 +537,7 @@ void opj_t1_dec_sigpass_raw( } } /* VSC and BYPASS by Antonin */ -void opj_t1_dec_sigpass_mqc( +static void opj_t1_dec_sigpass_mqc( opj_t1_t *t1, OPJ_INT32 bpno, OPJ_INT32 orient) @@ -580,7 +580,7 @@ void opj_t1_dec_sigpass_mqc( } } /* VSC and BYPASS by Antonin */ -void opj_t1_dec_sigpass_mqc_vsc( +static void opj_t1_dec_sigpass_mqc_vsc( opj_t1_t *t1, OPJ_INT32 bpno, OPJ_INT32 orient) @@ -608,7 +608,7 @@ void opj_t1_dec_sigpass_mqc_vsc( -void opj_t1_enc_refpass_step( opj_t1_t *t1, +static void opj_t1_enc_refpass_step( opj_t1_t *t1, opj_flag_t *flagsp, OPJ_INT32 *datap, OPJ_INT32 bpno, @@ -636,7 +636,7 @@ void opj_t1_enc_refpass_step( opj_t1_t *t1, } } -INLINE void opj_t1_dec_refpass_step_raw( +static INLINE void opj_t1_dec_refpass_step_raw( opj_t1_t *t1, opj_flag_t *flagsp, OPJ_INT32 *datap, @@ -657,7 +657,7 @@ INLINE void opj_t1_dec_refpass_step_raw( } } /* VSC and BYPASS by Antonin */ -INLINE void opj_t1_dec_refpass_step_mqc( +static INLINE void opj_t1_dec_refpass_step_mqc( opj_t1_t *t1, opj_flag_t *flagsp, OPJ_INT32 *datap, @@ -678,7 +678,7 @@ INLINE void opj_t1_dec_refpass_step_mqc( } } /* VSC and BYPASS by Antonin */ -INLINE void opj_t1_dec_refpass_step_mqc_vsc( +static INLINE void opj_t1_dec_refpass_step_mqc_vsc( opj_t1_t *t1, opj_flag_t *flagsp, OPJ_INT32 *datap, @@ -701,7 +701,7 @@ INLINE void opj_t1_dec_refpass_step_mqc_vsc( } /* VSC and BYPASS by Antonin */ -void opj_t1_enc_refpass( +static void opj_t1_enc_refpass( opj_t1_t *t1, OPJ_INT32 bpno, OPJ_INT32 *nmsedec, @@ -731,7 +731,7 @@ void opj_t1_enc_refpass( } } -void opj_t1_dec_refpass_raw( +static void opj_t1_dec_refpass_raw( opj_t1_t *t1, OPJ_INT32 bpno, OPJ_INT32 cblksty) @@ -758,7 +758,7 @@ void opj_t1_dec_refpass_raw( } } /* VSC and BYPASS by Antonin */ -void opj_t1_dec_refpass_mqc( +static void opj_t1_dec_refpass_mqc( opj_t1_t *t1, OPJ_INT32 bpno) { @@ -800,7 +800,7 @@ void opj_t1_dec_refpass_mqc( } } /* VSC and BYPASS by Antonin */ -void opj_t1_dec_refpass_mqc_vsc( +static void opj_t1_dec_refpass_mqc_vsc( opj_t1_t *t1, OPJ_INT32 bpno) { @@ -827,7 +827,7 @@ void opj_t1_dec_refpass_mqc_vsc( } /* VSC and BYPASS by Antonin */ -void opj_t1_enc_clnpass_step( +static void opj_t1_enc_clnpass_step( opj_t1_t *t1, opj_flag_t *flagsp, OPJ_INT32 *datap, @@ -937,7 +937,7 @@ LABEL_PARTIAL: *flagsp &= ~T1_VISIT; } -void opj_t1_enc_clnpass( +static void opj_t1_enc_clnpass( opj_t1_t *t1, OPJ_INT32 bpno, OPJ_UINT32 orient, @@ -1161,7 +1161,7 @@ static OPJ_FLOAT64 opj_t1_getwmsedec( return wmsedec; } -OPJ_BOOL opj_t1_allocate_buffers( +static OPJ_BOOL opj_t1_allocate_buffers( opj_t1_t *t1, OPJ_UINT32 w, OPJ_UINT32 h) @@ -1358,7 +1358,7 @@ OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1, } -OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, +static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, opj_tcd_cblk_dec_t* cblk, OPJ_UINT32 orient, OPJ_UINT32 roishift, @@ -1556,7 +1556,7 @@ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1, } /** mod fixed_quality */ -void opj_t1_encode_cblk(opj_t1_t *t1, +static void opj_t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_enc_t* cblk, OPJ_UINT32 orient, OPJ_UINT32 compno, @@ -1696,7 +1696,7 @@ void opj_t1_encode_cblk(opj_t1_t *t1, } #if 0 -void opj_t1_dec_refpass_step( opj_t1_t *t1, +static void opj_t1_dec_refpass_step( opj_t1_t *t1, opj_flag_t *flagsp, OPJ_INT32 *datap, OPJ_INT32 poshalf, @@ -1728,7 +1728,7 @@ void opj_t1_dec_refpass_step( opj_t1_t *t1, #if 0 -void opj_t1_dec_sigpass_step( opj_t1_t *t1, +static void opj_t1_dec_sigpass_step( opj_t1_t *t1, opj_flag_t *flagsp, OPJ_INT32 *datap, OPJ_UINT32 orient, diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index 6f0ac915..6719ed66 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -158,7 +158,7 @@ static void opj_t2_putcommacode(opj_bio_t *bio, OPJ_INT32 n) { opj_bio_write(bio, 0, 1); } -OPJ_UINT32 opj_t2_getcommacode(opj_bio_t *bio) +static OPJ_UINT32 opj_t2_getcommacode(opj_bio_t *bio) { OPJ_UINT32 n = 0; while (opj_bio_read(bio, 1)) { @@ -167,7 +167,7 @@ OPJ_UINT32 opj_t2_getcommacode(opj_bio_t *bio) return n; } -void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n) { +static void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n) { if (n == 1) { opj_bio_write(bio, 0, 1); } else if (n == 2) { @@ -181,7 +181,7 @@ void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n) { } } -OPJ_UINT32 opj_t2_getnumpasses(opj_bio_t *bio) { +static OPJ_UINT32 opj_t2_getnumpasses(opj_bio_t *bio) { OPJ_UINT32 n; if (!opj_bio_read(bio, 1)) return 1; @@ -511,7 +511,7 @@ void opj_t2_destroy(opj_t2_t *t2) { } } -OPJ_BOOL opj_t2_decode_packet( opj_t2_t* p_t2, +static OPJ_BOOL opj_t2_decode_packet( opj_t2_t* p_t2, opj_tcd_tile_t *p_tile, opj_tcp_t *p_tcp, opj_pi_iterator_t *p_pi, @@ -550,7 +550,7 @@ OPJ_BOOL opj_t2_decode_packet( opj_t2_t* p_t2, return OPJ_TRUE; } -OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, +static OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_iterator_t *pi, @@ -825,7 +825,7 @@ static OPJ_BOOL opj_t2_skip_packet( opj_t2_t* p_t2, } -OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, +static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, opj_tcd_tile_t *p_tile, opj_tcp_t *p_tcp, opj_pi_iterator_t *p_pi, @@ -1094,7 +1094,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, return OPJ_TRUE; } -OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2, +static OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2, opj_tcd_tile_t *p_tile, opj_pi_iterator_t *p_pi, OPJ_BYTE *p_src_data, @@ -1228,7 +1228,7 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2, return OPJ_TRUE; } -OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2, +static OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2, opj_tcd_tile_t *p_tile, opj_pi_iterator_t *p_pi, OPJ_UINT32 * p_data_read, diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index f6231202..e926d4f5 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -1462,7 +1462,7 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd, -void opj_tcd_free_tile(opj_tcd_t *p_tcd) +static void opj_tcd_free_tile(opj_tcd_t *p_tcd) { OPJ_UINT32 compno, resno, bandno, precno; opj_tcd_tile_t *l_tile = 00; @@ -1545,7 +1545,7 @@ void opj_tcd_free_tile(opj_tcd_t *p_tcd) } -OPJ_BOOL opj_tcd_t2_decode (opj_tcd_t *p_tcd, +static OPJ_BOOL opj_tcd_t2_decode (opj_tcd_t *p_tcd, OPJ_BYTE * p_src_data, OPJ_UINT32 * p_data_read, OPJ_UINT32 p_max_src_size, @@ -1577,7 +1577,7 @@ OPJ_BOOL opj_tcd_t2_decode (opj_tcd_t *p_tcd, return OPJ_TRUE; } -OPJ_BOOL opj_tcd_t1_decode ( opj_tcd_t *p_tcd ) +static OPJ_BOOL opj_tcd_t1_decode ( opj_tcd_t *p_tcd ) { OPJ_UINT32 compno; opj_t1_t * l_t1; @@ -1607,7 +1607,7 @@ OPJ_BOOL opj_tcd_t1_decode ( opj_tcd_t *p_tcd ) } -OPJ_BOOL opj_tcd_dwt_decode ( opj_tcd_t *p_tcd ) +static OPJ_BOOL opj_tcd_dwt_decode ( opj_tcd_t *p_tcd ) { OPJ_UINT32 compno; opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles; @@ -1647,7 +1647,7 @@ OPJ_BOOL opj_tcd_dwt_decode ( opj_tcd_t *p_tcd ) return OPJ_TRUE; } -OPJ_BOOL opj_tcd_mct_decode ( opj_tcd_t *p_tcd ) +static OPJ_BOOL opj_tcd_mct_decode ( opj_tcd_t *p_tcd ) { opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles; opj_tcp_t * l_tcp = p_tcd->tcp; @@ -1725,7 +1725,7 @@ OPJ_BOOL opj_tcd_mct_decode ( opj_tcd_t *p_tcd ) } -OPJ_BOOL opj_tcd_dc_level_shift_decode ( opj_tcd_t *p_tcd ) +static OPJ_BOOL opj_tcd_dc_level_shift_decode ( opj_tcd_t *p_tcd ) { OPJ_UINT32 compno; opj_tcd_tilecomp_t * l_tile_comp = 00; @@ -1795,7 +1795,7 @@ OPJ_BOOL opj_tcd_dc_level_shift_decode ( opj_tcd_t *p_tcd ) /** * Deallocates the encoding data of the given precinct. */ -void opj_tcd_code_block_dec_deallocate (opj_tcd_precinct_t * p_precinct) +static void opj_tcd_code_block_dec_deallocate (opj_tcd_precinct_t * p_precinct) { OPJ_UINT32 cblkno , l_nb_code_blocks; @@ -1833,7 +1833,7 @@ void opj_tcd_code_block_dec_deallocate (opj_tcd_precinct_t * p_precinct) /** * Deallocates the encoding data of the given precinct. */ -void opj_tcd_code_block_enc_deallocate (opj_tcd_precinct_t * p_precinct) +static void opj_tcd_code_block_enc_deallocate (opj_tcd_precinct_t * p_precinct) { OPJ_UINT32 cblkno , l_nb_code_blocks; @@ -1894,7 +1894,7 @@ OPJ_UINT32 opj_tcd_get_encoded_tile_size ( opj_tcd_t *p_tcd ) return l_data_size; } -OPJ_BOOL opj_tcd_dc_level_shift_encode ( opj_tcd_t *p_tcd ) +static OPJ_BOOL opj_tcd_dc_level_shift_encode ( opj_tcd_t *p_tcd ) { OPJ_UINT32 compno; opj_tcd_tilecomp_t * l_tile_comp = 00; @@ -1934,7 +1934,7 @@ OPJ_BOOL opj_tcd_dc_level_shift_encode ( opj_tcd_t *p_tcd ) return OPJ_TRUE; } -OPJ_BOOL opj_tcd_mct_encode ( opj_tcd_t *p_tcd ) +static OPJ_BOOL opj_tcd_mct_encode ( opj_tcd_t *p_tcd ) { opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles; opj_tcd_tilecomp_t * l_tile_comp = p_tcd->tcd_image->tiles->comps; @@ -1989,7 +1989,7 @@ OPJ_BOOL opj_tcd_mct_encode ( opj_tcd_t *p_tcd ) return OPJ_TRUE; } -OPJ_BOOL opj_tcd_dwt_encode ( opj_tcd_t *p_tcd ) +static OPJ_BOOL opj_tcd_dwt_encode ( opj_tcd_t *p_tcd ) { opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles; opj_tcd_tilecomp_t * l_tile_comp = p_tcd->tcd_image->tiles->comps; @@ -2015,7 +2015,7 @@ OPJ_BOOL opj_tcd_dwt_encode ( opj_tcd_t *p_tcd ) return OPJ_TRUE; } -OPJ_BOOL opj_tcd_t1_encode ( opj_tcd_t *p_tcd ) +static OPJ_BOOL opj_tcd_t1_encode ( opj_tcd_t *p_tcd ) { opj_t1_t * l_t1; const OPJ_FLOAT64 * l_mct_norms; @@ -2052,7 +2052,7 @@ OPJ_BOOL opj_tcd_t1_encode ( opj_tcd_t *p_tcd ) return OPJ_TRUE; } -OPJ_BOOL opj_tcd_t2_encode (opj_tcd_t *p_tcd, +static OPJ_BOOL opj_tcd_t2_encode (opj_tcd_t *p_tcd, OPJ_BYTE * p_dest_data, OPJ_UINT32 * p_data_written, OPJ_UINT32 p_max_dest_size, @@ -2090,7 +2090,7 @@ OPJ_BOOL opj_tcd_t2_encode (opj_tcd_t *p_tcd, } -OPJ_BOOL opj_tcd_rate_allocate_encode( opj_tcd_t *p_tcd, +static OPJ_BOOL opj_tcd_rate_allocate_encode( opj_tcd_t *p_tcd, OPJ_BYTE * p_dest_data, OPJ_UINT32 p_max_dest_size, opj_codestream_info_t *p_cstr_info ) From 46c1dd22fc6d6a8b8f2b54f9e42e1fe5ba4938a7 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 19 Jul 2015 15:01:12 +0200 Subject: [PATCH 09/10] Correct error message for invalid TIFF input --- src/bin/jp2/converttif.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/bin/jp2/converttif.c b/src/bin/jp2/converttif.c index d93e5f53..e8ff38f3 100644 --- a/src/bin/jp2/converttif.c +++ b/src/bin/jp2/converttif.c @@ -825,18 +825,14 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) w= (int)tiWidth; h= (int)tiHeight; - if((tiBps > 16U) || ((tiBps != 1U) && (tiBps & 1U))) tiBps = 0U; - if(tiPhoto != PHOTOMETRIC_MINISBLACK && tiPhoto != PHOTOMETRIC_RGB) tiPhoto = 0; - - if( !tiBps || !tiPhoto) - { - if( !tiBps) - fprintf(stderr,"tiftoimage: Bits=%d, Only 1, 2, 4, 6, 8, 10, 12, 14 and 16 bits implemented\n",tiBps); - else - if( !tiPhoto) - fprintf(stderr,"tiftoimage: Bad color format %d.\n\tOnly RGB(A)" - " and GRAY(A) has been implemented\n",(int) tiPhoto); - + if((tiBps > 16U) || ((tiBps != 1U) && (tiBps & 1U))) { + fprintf(stderr,"tiftoimage: Bits=%d, Only 1, 2, 4, 6, 8, 10, 12, 14 and 16 bits implemented\n",tiBps); + fprintf(stderr,"\tAborting\n"); + TIFFClose(tif); + return NULL; + } + if(tiPhoto != PHOTOMETRIC_MINISBLACK && tiPhoto != PHOTOMETRIC_RGB) { + fprintf(stderr,"tiftoimage: Bad color format %d.\n\tOnly RGB(A) and GRAY(A) has been implemented\n",(int) tiPhoto); fprintf(stderr,"\tAborting\n"); TIFFClose(tif); return NULL; From 5bb074611aab0df7f62bfd67c1016316138a4122 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 19 Jul 2015 17:42:11 +0200 Subject: [PATCH 10/10] Update PNG support Only input modified for now Update uclouvain/openjpeg#536 Update uclouvain/openjpeg#264 --- src/bin/jp2/CMakeLists.txt | 3 + src/bin/jp2/convert.c | 568 ------------------ src/bin/jp2/convertpng.c | 761 ++++++++++++++++++++++++ tests/nonregression/test_suite.ctest.in | 34 +- 4 files changed, 797 insertions(+), 569 deletions(-) create mode 100644 src/bin/jp2/convertpng.c diff --git a/src/bin/jp2/CMakeLists.txt b/src/bin/jp2/CMakeLists.txt index 857a1d92..7e2476df 100644 --- a/src/bin/jp2/CMakeLists.txt +++ b/src/bin/jp2/CMakeLists.txt @@ -16,6 +16,9 @@ set(common_SRCS if(OPJ_HAVE_LIBTIFF) list(APPEND common_SRCS converttif.c) endif() +if(OPJ_HAVE_LIBPNG) + list(APPEND common_SRCS convertpng.c) +endif() # Headers file are located here: include_directories( diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index bb8cfdac..6f3e0a22 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -42,15 +42,6 @@ #include #include -#ifdef OPJ_HAVE_LIBTIFF -#include -#endif /* OPJ_HAVE_LIBTIFF */ - -#ifdef OPJ_HAVE_LIBPNG -#include -#include -#endif /* OPJ_HAVE_LIBPNG */ - #include "openjpeg.h" #include "convert.h" @@ -1864,562 +1855,3 @@ int imagetorawl(opj_image_t * image, const char *outfile) return imagetoraw_common(image, outfile, OPJ_FALSE); } -#ifdef OPJ_HAVE_LIBPNG - -#define PNG_MAGIC "\x89PNG\x0d\x0a\x1a\x0a" -#define MAGIC_SIZE 8 -/* PNG allows bits per sample: 1, 2, 4, 8, 16 */ - -opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params) -{ - png_structp png; - png_infop info; - double gamma, display_exponent; - int bit_depth, interlace_type,compression_type, filter_type; - int unit; - png_uint_32 resx, resy; - unsigned int i, j; - png_uint_32 width, height; - int color_type, has_alpha, is16; - unsigned char *s; - FILE *reader; - unsigned char **rows; - /* j2k: */ - opj_image_t *image; - opj_image_cmptparm_t cmptparm[4]; - int sub_dx, sub_dy; - unsigned int nr_comp; - int *r, *g, *b, *a = NULL; - unsigned char sigbuf[8]; - - if((reader = fopen(read_idf, "rb")) == NULL) - { - fprintf(stderr,"pngtoimage: can not open %s\n",read_idf); - return NULL; - } - image = NULL; png = NULL; rows = NULL; - - if(fread(sigbuf, 1, MAGIC_SIZE, reader) != MAGIC_SIZE - || memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0) - { - fprintf(stderr,"pngtoimage: %s is no valid PNG file\n",read_idf); - goto fin; - } - /* libpng-VERSION/example.c: - * PC : screen_gamma = 2.2; - * Mac: screen_gamma = 1.7 or 1.0; -*/ - display_exponent = 2.2; - - if((png = png_create_read_struct(PNG_LIBPNG_VER_STRING, - NULL, NULL, NULL)) == NULL) - goto fin; - if((info = png_create_info_struct(png)) == NULL) - goto fin; - - if(setjmp(png_jmpbuf(png))) - goto fin; - - png_init_io(png, reader); - png_set_sig_bytes(png, MAGIC_SIZE); - - png_read_info(png, info); - - if(png_get_IHDR(png, info, &width, &height, - &bit_depth, &color_type, &interlace_type, - &compression_type, &filter_type) == 0) - goto fin; - - /* png_set_expand(): - * expand paletted images to RGB, expand grayscale images of - * less than 8-bit depth to 8-bit depth, and expand tRNS chunks - * to alpha channels. -*/ - if(color_type == PNG_COLOR_TYPE_PALETTE) - png_set_expand(png); - else - if(color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) - png_set_expand(png); - - if(png_get_valid(png, info, PNG_INFO_tRNS)) - png_set_expand(png); - - is16 = (bit_depth == 16); - - /* GRAY => RGB; GRAY_ALPHA => RGBA -*/ - if(color_type == PNG_COLOR_TYPE_GRAY - || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - { - png_set_gray_to_rgb(png); - color_type = - (color_type == PNG_COLOR_TYPE_GRAY? PNG_COLOR_TYPE_RGB: - PNG_COLOR_TYPE_RGB_ALPHA); - } - if( !png_get_gAMA(png, info, &gamma)) - gamma = 0.45455; - - png_set_gamma(png, display_exponent, gamma); - - png_read_update_info(png, info); - - png_get_pHYs(png, info, &resx, &resy, &unit); - - color_type = png_get_color_type(png, info); - - has_alpha = (color_type == PNG_COLOR_TYPE_RGB_ALPHA); - - nr_comp = 3 + (unsigned int)has_alpha; - - bit_depth = png_get_bit_depth(png, info); - - rows = (unsigned char**)calloc(height+1, sizeof(unsigned char*)); - for(i = 0; i < height; ++i) - rows[i] = (unsigned char*)malloc(png_get_rowbytes(png,info)); - - png_read_image(png, rows); - - memset(cmptparm, 0, sizeof(cmptparm)); - - sub_dx = params->subsampling_dx; sub_dy = params->subsampling_dy; - - for(i = 0; i < nr_comp; ++i) - { - cmptparm[i].prec = (OPJ_UINT32)bit_depth; - /* bits_per_pixel: 8 or 16 */ - cmptparm[i].bpp = (OPJ_UINT32)bit_depth; - cmptparm[i].sgnd = 0; - cmptparm[i].dx = (OPJ_UINT32)sub_dx; - cmptparm[i].dy = (OPJ_UINT32)sub_dy; - cmptparm[i].w = (OPJ_UINT32)width; - cmptparm[i].h = (OPJ_UINT32)height; - } - - image = opj_image_create(nr_comp, &cmptparm[0], OPJ_CLRSPC_SRGB); - - if(image == NULL) goto fin; - - image->x0 = (OPJ_UINT32)params->image_offset_x0; - image->y0 = (OPJ_UINT32)params->image_offset_y0; - image->x1 = (OPJ_UINT32)(image->x0 + (width - 1) * (OPJ_UINT32)sub_dx + 1 + image->x0); - image->y1 = (OPJ_UINT32)(image->y0 + (height - 1) * (OPJ_UINT32)sub_dy + 1 + image->y0); - - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; - if(has_alpha) { - a = image->comps[3].data; - image->comps[3].alpha = 1; - } - - for(i = 0; i < height; ++i) - { - s = rows[i]; - - for(j = 0; j < width; ++j) - { - if(is16) - { - *r++ = s[0]<<8|s[1]; s += 2; - - *g++ = s[0]<<8|s[1]; s += 2; - - *b++ = s[0]<<8|s[1]; s += 2; - - if(has_alpha) { *a++ = s[0]<<8|s[1]; s += 2; } - - continue; - } - *r++ = *s++; *g++ = *s++; *b++ = *s++; - - if(has_alpha) *a++ = *s++; - } - } -fin: - if(rows) - { - for(i = 0; i < height; ++i) - free(rows[i]); - free(rows); - } - if(png) - png_destroy_read_struct(&png, &info, NULL); - - fclose(reader); - - return image; - -}/* pngtoimage() */ - -int imagetopng(opj_image_t * image, const char *write_idf) -{ - FILE *writer; - png_structp png; - png_infop info; - int *red, *green, *blue, *alpha; - unsigned char *row_buf, *d; - int has_alpha, width, height, nr_comp, color_type; - int adjustR, adjustG, adjustB, adjustA, x, y, fails; - int prec, ushift, dshift, is16, force16, force8; - unsigned short mask = 0xffff; - png_color_8 sig_bit; - - is16 = force16 = force8 = ushift = dshift = 0; fails = 1; - prec = (int)image->comps[0].prec; - nr_comp = (int)image->numcomps; - - if(prec > 8 && prec < 16) - { - ushift = 16 - prec; dshift = prec - ushift; - prec = 16; force16 = 1; - } - else - if(prec < 8 && nr_comp > 1)/* GRAY_ALPHA, RGB, RGB_ALPHA */ - { - ushift = 8 - prec; dshift = 8 - ushift; - prec = 8; force8 = 1; - } - - if(prec != 1 && prec != 2 && prec != 4 && prec != 8 && prec != 16) - { - fprintf(stderr,"imagetopng: can not create %s" - "\n\twrong bit_depth %d\n", write_idf, prec); - return fails; - } - writer = fopen(write_idf, "wb"); - - if(writer == NULL) return fails; - - info = NULL; has_alpha = 0; - - /* Create and initialize the png_struct with the desired error handler - * functions. If you want to use the default stderr and longjump method, - * you can supply NULL for the last three parameters. We also check that - * the library version is compatible with the one used at compile time, - * in case we are using dynamically linked libraries. REQUIRED. -*/ - png = png_create_write_struct(PNG_LIBPNG_VER_STRING, - NULL, NULL, NULL); - /*png_voidp user_error_ptr, user_error_fn, user_warning_fn); */ - - if(png == NULL) goto fin; - - /* Allocate/initialize the image information data. REQUIRED -*/ - info = png_create_info_struct(png); - - if(info == NULL) goto fin; - - /* Set error handling. REQUIRED if you are not supplying your own - * error handling functions in the png_create_write_struct() call. -*/ - if(setjmp(png_jmpbuf(png))) goto fin; - - /* I/O initialization functions is REQUIRED -*/ - png_init_io(png, writer); - - /* Set the image information here. Width and height are up to 2^31, - * bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on - * the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY, - * PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB, - * or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or - * PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST - * currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. - * REQUIRED - * - * ERRORS: - * - * color_type == PNG_COLOR_TYPE_PALETTE && bit_depth > 8 - * color_type == PNG_COLOR_TYPE_RGB && bit_depth < 8 - * color_type == PNG_COLOR_TYPE_GRAY_ALPHA && bit_depth < 8 - * color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8 - * -*/ - png_set_compression_level(png, Z_BEST_COMPRESSION); - - if(prec == 16) mask = 0xffff; - else - if(prec == 8) mask = 0x00ff; - else - if(prec == 4) mask = 0x000f; - else - if(prec == 2) mask = 0x0003; - else - if(prec == 1) mask = 0x0001; - - if(nr_comp >= 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) - { - int v; - - has_alpha = (nr_comp > 3); - - is16 = (prec == 16); - - width = (int)image->comps[0].w; - height = (int)image->comps[0].h; - - red = image->comps[0].data; - green = image->comps[1].data; - blue = image->comps[2].data; - - sig_bit.red = sig_bit.green = sig_bit.blue = (png_byte)prec; - - if(has_alpha) - { - sig_bit.alpha = (png_byte)prec; - alpha = image->comps[3].data; - color_type = PNG_COLOR_TYPE_RGB_ALPHA; - adjustA = (image->comps[3].sgnd ? 1 << (image->comps[3].prec - 1) : 0); - } - else - { - sig_bit.alpha = 0; alpha = NULL; - color_type = PNG_COLOR_TYPE_RGB; - adjustA = 0; - } - png_set_sBIT(png, info, &sig_bit); - - png_set_IHDR(png, info, (png_uint_32)width, (png_uint_32)height, prec, - color_type, - PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); - - png_set_gamma(png, 2.2, 1./2.2); - png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); - /*=============================*/ - png_write_info(png, info); - /*=============================*/ - if(prec < 8) - { - png_set_packing(png); - } -// printf("%s:%d:sgnd(%d,%d,%d) w(%d) h(%d) alpha(%d)\n",__FILE__,__LINE__, -//image->comps[0].sgnd, -//image->comps[1].sgnd,image->comps[2].sgnd,width,height,has_alpha); - - adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - - row_buf = (unsigned char*)malloc((size_t)width * (size_t)nr_comp * 2); - - for(y = 0; y < height; ++y) - { - d = row_buf; - - for(x = 0; x < width; ++x) - { - if(is16) - { - v = *red + adjustR; ++red; - if(v > 65535) v = 65535; else if(v < 0) v = 0; - - if(force16) { v = (v<>dshift); } - - *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; - - v = *green + adjustG; ++green; - if(v > 65535) v = 65535; else if(v < 0) v = 0; - - if(force16) { v = (v<>dshift); } - - *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; - - v = *blue + adjustB; ++blue; - if(v > 65535) v = 65535; else if(v < 0) v = 0; - - if(force16) { v = (v<>dshift); } - - *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; - - if(has_alpha) - { - v = *alpha + adjustA; ++alpha; - if(v > 65535) v = 65535; else if(v < 0) v = 0; - - if(force16) { v = (v<>dshift); } - - *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; - } - continue; - }/* if(is16) */ - - v = *red + adjustR; ++red; - if(v > 255) v = 255; else if(v < 0) v = 0; - - if(force8) { v = (v<>dshift); } - - *d++ = (unsigned char)(v & mask); - - v = *green + adjustG; ++green; - if(v > 255) v = 255; else if(v < 0) v = 0; - - if(force8) { v = (v<>dshift); } - - *d++ = (unsigned char)(v & mask); - - v = *blue + adjustB; ++blue; - if(v > 255) v = 255; else if(v < 0) v = 0; - - if(force8) { v = (v<>dshift); } - - *d++ = (unsigned char)(v & mask); - - if(has_alpha) - { - v = *alpha + adjustA; ++alpha; - if(v > 255) v = 255; else if(v < 0) v = 0; - - if(force8) { v = (v<>dshift); } - - *d++ = (unsigned char)(v & mask); - } - } /* for(x) */ - - png_write_row(png, row_buf); - - } /* for(y) */ - free(row_buf); - - }/* nr_comp >= 3 */ - else - if(nr_comp == 1 /* GRAY */ - || ( nr_comp == 2 /* GRAY_ALPHA */ - && image->comps[0].dx == image->comps[1].dx - && image->comps[0].dy == image->comps[1].dy - && image->comps[0].prec == image->comps[1].prec)) - { - int v; - - red = image->comps[0].data; - - sig_bit.gray = (png_byte)prec; - sig_bit.red = sig_bit.green = sig_bit.blue = sig_bit.alpha = 0; - alpha = NULL; adjustA = 0; - color_type = PNG_COLOR_TYPE_GRAY; - - if(nr_comp == 2) - { - has_alpha = 1; sig_bit.alpha = (png_byte)prec; - alpha = image->comps[1].data; - color_type = PNG_COLOR_TYPE_GRAY_ALPHA; - adjustA = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - } - width = (int)image->comps[0].w; - height = (int)image->comps[0].h; - - png_set_IHDR(png, info, (png_uint_32)width, (png_uint_32)height, sig_bit.gray, - color_type, - PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); - - png_set_sBIT(png, info, &sig_bit); - - png_set_gamma(png, 2.2, 1./2.2); - png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); - /*=============================*/ - png_write_info(png, info); - /*=============================*/ - adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - - if(prec < 8) - { - png_set_packing(png); - } - - if(prec > 8) - { - row_buf = (unsigned char*) - malloc((size_t)width * (size_t)nr_comp * sizeof(unsigned short)); - - for(y = 0; y < height; ++y) - { - d = row_buf; - - for(x = 0; x < width; ++x) - { - v = *red + adjustR; ++red; - if(v > 65535) v = 65535; else if(v < 0) v = 0; - - if(force16) { v = (v<>dshift); } - - *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; - - if(has_alpha) - { - v = *alpha++; - if(v > 65535) v = 65535; else if(v < 0) v = 0; - - if(force16) { v = (v<>dshift); } - - *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; - } - }/* for(x) */ - png_write_row(png, row_buf); - - } /* for(y) */ - free(row_buf); - } - else /* prec <= 8 */ - { - row_buf = (unsigned char*)calloc((size_t)width, (size_t)nr_comp * 2); - - for(y = 0; y < height; ++y) - { - d = row_buf; - - for(x = 0; x < width; ++x) - { - v = *red + adjustR; ++red; - if(v > 255) v = 255; else if(v < 0) v = 0; - - if(force8) { v = (v<>dshift); } - - *d++ = (unsigned char)(v & mask); - - if(has_alpha) - { - v = *alpha + adjustA; ++alpha; - if(v > 255) v = 255; else if(v < 0) v = 0; - - if(force8) { v = (v<>dshift); } - - *d++ = (unsigned char)(v & mask); - } - }/* for(x) */ - - png_write_row(png, row_buf); - - } /* for(y) */ - free(row_buf); - } - } - else - { - fprintf(stderr,"imagetopng: can not create %s\n",write_idf); - goto fin; - } - png_write_end(png, info); - - fails = 0; - -fin: - - if(png) - { - png_destroy_write_struct(&png, &info); - } - fclose(writer); - - if(fails) remove(write_idf); - - return fails; -}/* imagetopng() */ -#endif /* OPJ_HAVE_LIBPNG */ diff --git a/src/bin/jp2/convertpng.c b/src/bin/jp2/convertpng.c new file mode 100644 index 00000000..ccb1c1f7 --- /dev/null +++ b/src/bin/jp2/convertpng.c @@ -0,0 +1,761 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2014, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux + * Copyright (c) 2003-2014, Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2006-2007, Parvatha Elangovan + * Copyright (c) 2015, Matthieu Darbois + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include "opj_apps_config.h" + +#include +#include +#include +#include + +#include +#include + +#include "openjpeg.h" +#include "convert.h" + +#define PNG_MAGIC "\x89PNG\x0d\x0a\x1a\x0a" +#define MAGIC_SIZE 8 +/* PNG allows bits per sample: 1, 2, 4, 8, 16 */ + +typedef void (* convert_32s_CXPX)(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, OPJ_SIZE_T length); +static void convert_32s_C1P1(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, OPJ_SIZE_T length) +{ + memcpy(pDst[0], pSrc, length * sizeof(OPJ_INT32)); +} +static void convert_32s_C2P2(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + OPJ_INT32* pDst0 = pDst[0]; + OPJ_INT32* pDst1 = pDst[1]; + + for (i = 0; i < length; i++) { + pDst0[i] = pSrc[2*i+0]; + pDst1[i] = pSrc[2*i+1]; + } +} +static void convert_32s_C3P3(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + OPJ_INT32* pDst0 = pDst[0]; + OPJ_INT32* pDst1 = pDst[1]; + OPJ_INT32* pDst2 = pDst[2]; + + for (i = 0; i < length; i++) { + pDst0[i] = pSrc[3*i+0]; + pDst1[i] = pSrc[3*i+1]; + pDst2[i] = pSrc[3*i+2]; + } +} +static void convert_32s_C4P4(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + OPJ_INT32* pDst0 = pDst[0]; + OPJ_INT32* pDst1 = pDst[1]; + OPJ_INT32* pDst2 = pDst[2]; + OPJ_INT32* pDst3 = pDst[3]; + + for (i = 0; i < length; i++) { + pDst0[i] = pSrc[4*i+0]; + pDst1[i] = pSrc[4*i+1]; + pDst2[i] = pSrc[4*i+2]; + pDst3[i] = pSrc[4*i+3]; + } +} + +typedef void (* convert_XXx32s_C1R)(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length); +static void convert_1u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)8U); i+=8U) { + OPJ_UINT32 val = *pSrc++; + pDst[i+0] = (OPJ_INT32)( val >> 7); + pDst[i+1] = (OPJ_INT32)((val >> 6) & 0x1U); + pDst[i+2] = (OPJ_INT32)((val >> 5) & 0x1U); + pDst[i+3] = (OPJ_INT32)((val >> 4) & 0x1U); + pDst[i+4] = (OPJ_INT32)((val >> 3) & 0x1U); + pDst[i+5] = (OPJ_INT32)((val >> 2) & 0x1U); + pDst[i+6] = (OPJ_INT32)((val >> 1) & 0x1U); + pDst[i+7] = (OPJ_INT32)(val & 0x1U); + } + if (length & 7U) { + OPJ_UINT32 val = *pSrc++; + length = length & 7U; + pDst[i+0] = (OPJ_INT32)(val >> 7); + + if (length > 1U) { + pDst[i+1] = (OPJ_INT32)((val >> 6) & 0x1U); + if (length > 2U) { + pDst[i+2] = (OPJ_INT32)((val >> 5) & 0x1U); + if (length > 3U) { + pDst[i+3] = (OPJ_INT32)((val >> 4) & 0x1U); + if (length > 4U) { + pDst[i+4] = (OPJ_INT32)((val >> 3) & 0x1U); + if (length > 5U) { + pDst[i+5] = (OPJ_INT32)((val >> 2) & 0x1U); + if (length > 6U) { + pDst[i+6] = (OPJ_INT32)((val >> 1) & 0x1U); + } + } + } + } + } + } + } +} +static void convert_2u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)4U); i+=4U) { + OPJ_UINT32 val = *pSrc++; + pDst[i+0] = (OPJ_INT32)( val >> 6); + pDst[i+1] = (OPJ_INT32)((val >> 4) & 0x3U); + pDst[i+2] = (OPJ_INT32)((val >> 2) & 0x3U); + pDst[i+3] = (OPJ_INT32)(val & 0x3U); + } + if (length & 3U) { + OPJ_UINT32 val = *pSrc++; + length = length & 3U; + pDst[i+0] = (OPJ_INT32)(val >> 6); + + if (length > 1U) { + pDst[i+1] = (OPJ_INT32)((val >> 4) & 0x3U); + if (length > 2U) { + pDst[i+2] = (OPJ_INT32)((val >> 2) & 0x3U); + + } + } + } +} +static void convert_4u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & -(OPJ_SIZE_T)2U); i+=2U) { + OPJ_UINT32 val = *pSrc++; + pDst[i+0] = (OPJ_INT32)(val >> 4); + pDst[i+1] = (OPJ_INT32)(val & 0xFU); + } + if (length & 1U) { + OPJ_UINT8 val = *pSrc++; + pDst[i+0] = (OPJ_INT32)(val >> 4); + } +} +static void convert_8u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < length; i++) { + pDst[i] = pSrc[i]; + } +} +static void convert_16u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < length; i++) { + OPJ_INT32 val0 = *pSrc++; + OPJ_INT32 val1 = *pSrc++; + pDst[i] = val0 << 8 | val1; + } +} + +opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params) +{ + png_structp png; + png_infop info; + double gamma; + int bit_depth, interlace_type,compression_type, filter_type; + OPJ_UINT32 i; + png_uint_32 width, height; + int color_type; + FILE *reader = NULL; + OPJ_BYTE** rows = NULL; + OPJ_INT32* row32s = NULL; + /* j2k: */ + opj_image_t *image = NULL; + opj_image_cmptparm_t cmptparm[4]; + OPJ_UINT32 nr_comp; + OPJ_BYTE sigbuf[8]; + convert_XXx32s_C1R cvtXXTo32s = NULL; + convert_32s_CXPX cvtCxToPx = NULL; + OPJ_INT32* planes[4]; + + if((reader = fopen(read_idf, "rb")) == NULL) + { + fprintf(stderr,"pngtoimage: can not open %s\n",read_idf); + return NULL; + } + + if(fread(sigbuf, 1, MAGIC_SIZE, reader) != MAGIC_SIZE + || memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0) + { + fprintf(stderr,"pngtoimage: %s is no valid PNG file\n",read_idf); + goto fin; + } + + if((png = png_create_read_struct(PNG_LIBPNG_VER_STRING, + NULL, NULL, NULL)) == NULL) + goto fin; + if((info = png_create_info_struct(png)) == NULL) + goto fin; + + if(setjmp(png_jmpbuf(png))) + goto fin; + + png_init_io(png, reader); + png_set_sig_bytes(png, MAGIC_SIZE); + + png_read_info(png, info); + + if(png_get_IHDR(png, info, &width, &height, + &bit_depth, &color_type, &interlace_type, + &compression_type, &filter_type) == 0) + goto fin; + + /* png_set_expand(): + * expand paletted images to RGB, expand grayscale images of + * less than 8-bit depth to 8-bit depth, and expand tRNS chunks + * to alpha channels. + */ + if(color_type == PNG_COLOR_TYPE_PALETTE) { + png_set_expand(png); + } + + if(png_get_valid(png, info, PNG_INFO_tRNS)) { + png_set_expand(png); + } + /* We might wan't to expand background */ + /* + if(png_get_valid(png, info, PNG_INFO_bKGD)) { + png_color_16p bgnd; + png_get_bKGD(png, info, &bgnd); + png_set_background(png, bgnd, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); + } + */ + + if( !png_get_gAMA(png, info, &gamma)) + gamma = 1.0; + + /* we're not displaying but converting, screen gamma == 1.0 */ + png_set_gamma(png, 1.0, gamma); + + png_read_update_info(png, info); + + color_type = png_get_color_type(png, info); + + switch (color_type) { + case PNG_COLOR_TYPE_GRAY: + nr_comp = 1; + cvtCxToPx = convert_32s_C1P1; + break; + case PNG_COLOR_TYPE_GRAY_ALPHA: + nr_comp = 2; + cvtCxToPx = convert_32s_C2P2; + break; + case PNG_COLOR_TYPE_RGB: + nr_comp = 3; + cvtCxToPx = convert_32s_C3P3; + break; + case PNG_COLOR_TYPE_RGB_ALPHA: + nr_comp = 4; + cvtCxToPx = convert_32s_C4P4; + break; + default: + fprintf(stderr,"pngtoimage: colortype %d is not supported\n", color_type); + goto fin; + } + bit_depth = png_get_bit_depth(png, info); + + switch (bit_depth) { + case 1: + cvtXXTo32s = convert_1u32s_C1R; + break; + case 2: + cvtXXTo32s = convert_2u32s_C1R; + break; + case 4: + cvtXXTo32s = convert_4u32s_C1R; + break; + case 8: + cvtXXTo32s = convert_8u32s_C1R; + break; + case 16: + cvtXXTo32s = convert_16u32s_C1R; + break; + default: + fprintf(stderr,"pngtoimage: bit depth %d is not supported\n", bit_depth); + goto fin; + } + + + rows = (OPJ_BYTE**)calloc(height+1, sizeof(OPJ_BYTE*)); + for(i = 0; i < height; ++i) + rows[i] = (OPJ_BYTE*)malloc(png_get_rowbytes(png,info)); + + png_read_image(png, rows); + + /* Create image */ + memset(cmptparm, 0, sizeof(cmptparm)); + for(i = 0; i < nr_comp; ++i) + { + cmptparm[i].prec = (OPJ_UINT32)bit_depth; + /* bits_per_pixel: 8 or 16 */ + cmptparm[i].bpp = (OPJ_UINT32)bit_depth; + cmptparm[i].sgnd = 0; + cmptparm[i].dx = (OPJ_UINT32)params->subsampling_dx; + cmptparm[i].dy = (OPJ_UINT32)params->subsampling_dy; + cmptparm[i].w = (OPJ_UINT32)width; + cmptparm[i].h = (OPJ_UINT32)height; + } + + image = opj_image_create(nr_comp, &cmptparm[0], (nr_comp > 2U) ? OPJ_CLRSPC_SRGB : OPJ_CLRSPC_GRAY); + if(image == NULL) goto fin; + image->x0 = (OPJ_UINT32)params->image_offset_x0; + image->y0 = (OPJ_UINT32)params->image_offset_y0; + image->x1 = (OPJ_UINT32)(image->x0 + (width - 1) * (OPJ_UINT32)params->subsampling_dx + 1 + image->x0); + image->y1 = (OPJ_UINT32)(image->y0 + (height - 1) * (OPJ_UINT32)params->subsampling_dy + 1 + image->y0); + + row32s = malloc((size_t)width * nr_comp * sizeof(OPJ_INT32)); + if(row32s == NULL) goto fin; + + /* Set alpha channel */ + image->comps[nr_comp-1U].alpha = 1U - (nr_comp & 1U); + + for(i = 0; i < nr_comp; i++) + { + planes[i] = image->comps[i].data; + } + + for(i = 0; i < height; ++i) + { + cvtXXTo32s(rows[i], row32s, (OPJ_SIZE_T)width * nr_comp); + cvtCxToPx(row32s, planes, width); + planes[0] += width; + planes[1] += width; + planes[2] += width; + planes[3] += width; + } +fin: + if(rows) + { + for(i = 0; i < height; ++i) + free(rows[i]); + free(rows); + } + if (row32s) { + free(row32s); + } + if(png) + png_destroy_read_struct(&png, &info, NULL); + + fclose(reader); + + return image; + +}/* pngtoimage() */ + +int imagetopng(opj_image_t * image, const char *write_idf) +{ + FILE *writer; + png_structp png; + png_infop info; + int *red, *green, *blue, *alpha; + unsigned char *row_buf, *d; + int has_alpha, width, height, nr_comp, color_type; + int adjustR, adjustG, adjustB, adjustA, x, y, fails; + int prec, ushift, dshift, is16, force16, force8; + unsigned short mask = 0xffff; + png_color_8 sig_bit; + + is16 = force16 = force8 = ushift = dshift = 0; fails = 1; + prec = (int)image->comps[0].prec; + nr_comp = (int)image->numcomps; + + if(prec > 8 && prec < 16) + { + ushift = 16 - prec; dshift = prec - ushift; + prec = 16; force16 = 1; + } + else + if(prec < 8 && nr_comp > 1)/* GRAY_ALPHA, RGB, RGB_ALPHA */ + { + ushift = 8 - prec; dshift = 8 - ushift; + prec = 8; force8 = 1; + } + + if(prec != 1 && prec != 2 && prec != 4 && prec != 8 && prec != 16) + { + fprintf(stderr,"imagetopng: can not create %s" + "\n\twrong bit_depth %d\n", write_idf, prec); + return fails; + } + writer = fopen(write_idf, "wb"); + + if(writer == NULL) return fails; + + info = NULL; has_alpha = 0; + + /* Create and initialize the png_struct with the desired error handler + * functions. If you want to use the default stderr and longjump method, + * you can supply NULL for the last three parameters. We also check that + * the library version is compatible with the one used at compile time, + * in case we are using dynamically linked libraries. REQUIRED. + */ + png = png_create_write_struct(PNG_LIBPNG_VER_STRING, + NULL, NULL, NULL); + /*png_voidp user_error_ptr, user_error_fn, user_warning_fn); */ + + if(png == NULL) goto fin; + + /* Allocate/initialize the image information data. REQUIRED + */ + info = png_create_info_struct(png); + + if(info == NULL) goto fin; + + /* Set error handling. REQUIRED if you are not supplying your own + * error handling functions in the png_create_write_struct() call. + */ + if(setjmp(png_jmpbuf(png))) goto fin; + + /* I/O initialization functions is REQUIRED + */ + png_init_io(png, writer); + + /* Set the image information here. Width and height are up to 2^31, + * bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on + * the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY, + * PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB, + * or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or + * PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST + * currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. + * REQUIRED + * + * ERRORS: + * + * color_type == PNG_COLOR_TYPE_PALETTE && bit_depth > 8 + * color_type == PNG_COLOR_TYPE_RGB && bit_depth < 8 + * color_type == PNG_COLOR_TYPE_GRAY_ALPHA && bit_depth < 8 + * color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8 + * + */ + png_set_compression_level(png, Z_BEST_COMPRESSION); + + if(prec == 16) mask = 0xffff; + else + if(prec == 8) mask = 0x00ff; + else + if(prec == 4) mask = 0x000f; + else + if(prec == 2) mask = 0x0003; + else + if(prec == 1) mask = 0x0001; + + if(nr_comp >= 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) + { + int v; + + has_alpha = (nr_comp > 3); + + is16 = (prec == 16); + + width = (int)image->comps[0].w; + height = (int)image->comps[0].h; + + red = image->comps[0].data; + green = image->comps[1].data; + blue = image->comps[2].data; + + sig_bit.red = sig_bit.green = sig_bit.blue = (png_byte)prec; + + if(has_alpha) + { + sig_bit.alpha = (png_byte)prec; + alpha = image->comps[3].data; + color_type = PNG_COLOR_TYPE_RGB_ALPHA; + adjustA = (image->comps[3].sgnd ? 1 << (image->comps[3].prec - 1) : 0); + } + else + { + sig_bit.alpha = 0; alpha = NULL; + color_type = PNG_COLOR_TYPE_RGB; + adjustA = 0; + } + png_set_sBIT(png, info, &sig_bit); + + png_set_IHDR(png, info, (png_uint_32)width, (png_uint_32)height, prec, + color_type, + PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + png_set_gamma(png, 2.2, 1./2.2); + png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); + /*=============================*/ + png_write_info(png, info); + /*=============================*/ + if(prec < 8) + { + png_set_packing(png); + } + // printf("%s:%d:sgnd(%d,%d,%d) w(%d) h(%d) alpha(%d)\n",__FILE__,__LINE__, + //image->comps[0].sgnd, + //image->comps[1].sgnd,image->comps[2].sgnd,width,height,has_alpha); + + adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); + adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); + + row_buf = (unsigned char*)malloc((size_t)width * (size_t)nr_comp * 2); + + for(y = 0; y < height; ++y) + { + d = row_buf; + + for(x = 0; x < width; ++x) + { + if(is16) + { + v = *red + adjustR; ++red; + if(v > 65535) v = 65535; else if(v < 0) v = 0; + + if(force16) { v = (v<>dshift); } + + *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; + + v = *green + adjustG; ++green; + if(v > 65535) v = 65535; else if(v < 0) v = 0; + + if(force16) { v = (v<>dshift); } + + *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; + + v = *blue + adjustB; ++blue; + if(v > 65535) v = 65535; else if(v < 0) v = 0; + + if(force16) { v = (v<>dshift); } + + *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; + + if(has_alpha) + { + v = *alpha + adjustA; ++alpha; + if(v > 65535) v = 65535; else if(v < 0) v = 0; + + if(force16) { v = (v<>dshift); } + + *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; + } + continue; + }/* if(is16) */ + + v = *red + adjustR; ++red; + if(v > 255) v = 255; else if(v < 0) v = 0; + + if(force8) { v = (v<>dshift); } + + *d++ = (unsigned char)(v & mask); + + v = *green + adjustG; ++green; + if(v > 255) v = 255; else if(v < 0) v = 0; + + if(force8) { v = (v<>dshift); } + + *d++ = (unsigned char)(v & mask); + + v = *blue + adjustB; ++blue; + if(v > 255) v = 255; else if(v < 0) v = 0; + + if(force8) { v = (v<>dshift); } + + *d++ = (unsigned char)(v & mask); + + if(has_alpha) + { + v = *alpha + adjustA; ++alpha; + if(v > 255) v = 255; else if(v < 0) v = 0; + + if(force8) { v = (v<>dshift); } + + *d++ = (unsigned char)(v & mask); + } + } /* for(x) */ + + png_write_row(png, row_buf); + + } /* for(y) */ + free(row_buf); + + }/* nr_comp >= 3 */ + else + if(nr_comp == 1 /* GRAY */ + || ( nr_comp == 2 /* GRAY_ALPHA */ + && image->comps[0].dx == image->comps[1].dx + && image->comps[0].dy == image->comps[1].dy + && image->comps[0].prec == image->comps[1].prec)) + { + int v; + + red = image->comps[0].data; + + sig_bit.gray = (png_byte)prec; + sig_bit.red = sig_bit.green = sig_bit.blue = sig_bit.alpha = 0; + alpha = NULL; adjustA = 0; + color_type = PNG_COLOR_TYPE_GRAY; + + if(nr_comp == 2) + { + has_alpha = 1; sig_bit.alpha = (png_byte)prec; + alpha = image->comps[1].data; + color_type = PNG_COLOR_TYPE_GRAY_ALPHA; + adjustA = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); + } + width = (int)image->comps[0].w; + height = (int)image->comps[0].h; + + png_set_IHDR(png, info, (png_uint_32)width, (png_uint_32)height, sig_bit.gray, + color_type, + PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + png_set_sBIT(png, info, &sig_bit); + + png_set_gamma(png, 2.2, 1./2.2); + png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); + /*=============================*/ + png_write_info(png, info); + /*=============================*/ + adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + + if(prec < 8) + { + png_set_packing(png); + } + + if(prec > 8) + { + row_buf = (unsigned char*) + malloc((size_t)width * (size_t)nr_comp * sizeof(unsigned short)); + + for(y = 0; y < height; ++y) + { + d = row_buf; + + for(x = 0; x < width; ++x) + { + v = *red + adjustR; ++red; + if(v > 65535) v = 65535; else if(v < 0) v = 0; + + if(force16) { v = (v<>dshift); } + + *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; + + if(has_alpha) + { + v = *alpha++; + if(v > 65535) v = 65535; else if(v < 0) v = 0; + + if(force16) { v = (v<>dshift); } + + *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; + } + }/* for(x) */ + png_write_row(png, row_buf); + + } /* for(y) */ + free(row_buf); + } + else /* prec <= 8 */ + { + row_buf = (unsigned char*)calloc((size_t)width, (size_t)nr_comp * 2); + + for(y = 0; y < height; ++y) + { + d = row_buf; + + for(x = 0; x < width; ++x) + { + v = *red + adjustR; ++red; + if(v > 255) v = 255; else if(v < 0) v = 0; + + if(force8) { v = (v<>dshift); } + + *d++ = (unsigned char)(v & mask); + + if(has_alpha) + { + v = *alpha + adjustA; ++alpha; + if(v > 255) v = 255; else if(v < 0) v = 0; + + if(force8) { v = (v<>dshift); } + + *d++ = (unsigned char)(v & mask); + } + }/* for(x) */ + + png_write_row(png, row_buf); + + } /* for(y) */ + free(row_buf); + } + } + else + { + fprintf(stderr,"imagetopng: can not create %s\n",write_idf); + goto fin; + } + png_write_end(png, info); + + fails = 0; + +fin: + + if(png) + { + png_destroy_write_struct(&png, &info); + } + fclose(writer); + + if(fails) remove(write_idf); + + return fails; +}/* imagetopng() */ + diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 053d9318..b8e63f8b 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -47,7 +47,7 @@ opj_compress -i @INPUT_NR_PATH@/Bretagne2.ppm -o @TEMP_PATH@/Bretagne2_5.j2k -c # issue 316 opj_compress -i @INPUT_NR_PATH@/issue316.png -o @TEMP_PATH@/issue316.png.jp2 # issue 416 (cdef for png with alpha) + issue 436 (MCT norm read buffer overflow for num comp > 3 + Issue 215 number of decomp levels -opj_compress -i @INPUT_NR_PATH@/basn6a08.png -o @TEMP_PATH@/basn6a08.png.jp2 -n 6 +opj_compress -i @INPUT_NR_PATH@/pngsuite/basn6a08.png -o @TEMP_PATH@/basn6a08.png.jp2 -n 6 # issue 203 BMP Files not handled properly opj_compress -i @INPUT_NR_PATH@/issue203-8bpp-width1.bmp -o @TEMP_PATH@/issue203-8bpp-width1.bmp.jp2 opj_compress -i @INPUT_NR_PATH@/issue203-rle8.bmp -o @TEMP_PATH@/issue203-rle8.bmp.jp2 @@ -101,6 +101,38 @@ opj_compress -i @INPUT_NR_PATH@/flower-rgb-planar-16.tif -o @TEMP_PATH@/flower-r opj_compress -i @INPUT_NR_PATH@/basn6a08.tif -o @TEMP_PATH@/basn6a08.tif.jp2 opj_compress -i @INPUT_NR_PATH@/basn4a08.tif -o @TEMP_PATH@/basn4a08.tif.jp2 +# issue 536 (PNG images are always read as RGB(A) images) + issue 264 (convert.c is unmaintainable) +# Test all images from pngsuite +opj_compress -i @INPUT_NR_PATH@/pngsuite/basn0g01.png -o @TEMP_PATH@/basn0g01.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/basn0g02.png -o @TEMP_PATH@/basn0g02.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/basn0g04.png -o @TEMP_PATH@/basn0g04.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/basn0g08.png -o @TEMP_PATH@/basn0g08.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/basn0g16.png -o @TEMP_PATH@/basn0g16.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/basn2c08.png -o @TEMP_PATH@/basn2c08.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/basn2c16.png -o @TEMP_PATH@/basn2c16.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/basn3p01.png -o @TEMP_PATH@/basn3p01.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/basn3p02.png -o @TEMP_PATH@/basn3p02.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/basn3p04.png -o @TEMP_PATH@/basn3p04.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/basn3p08.png -o @TEMP_PATH@/basn3p08.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/basn4a08.png -o @TEMP_PATH@/basn4a08.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/basn4a16.png -o @TEMP_PATH@/basn4a16.png.jp2 +# already done opj_compress -i @INPUT_NR_PATH@/pngsuite/basn6a08.png -o @TEMP_PATH@/basn6a08.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/basn6a16.png -o @TEMP_PATH@/basn6a16.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/ftbbn0g01.png -o @TEMP_PATH@/ftbbn0g01.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/ftbbn0g02.png -o @TEMP_PATH@/ftbbn0g02.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/ftbbn0g04.png -o @TEMP_PATH@/ftbbn0g04.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/ftbbn2c16.png -o @TEMP_PATH@/ftbbn2c16.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/ftbbn3p08.png -o @TEMP_PATH@/ftbbn3p08.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/ftbgn2c16.png -o @TEMP_PATH@/ftbgn2c16.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/ftbgn3p08.png -o @TEMP_PATH@/ftbgn3p08.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/ftbrn2c08.png -o @TEMP_PATH@/ftbrn2c08.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/ftbwn0g16.png -o @TEMP_PATH@/ftbwn0g16.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/ftbwn3p08.png -o @TEMP_PATH@/ftbwn3p08.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/ftbyn3p08.png -o @TEMP_PATH@/ftbyn3p08.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/ftp0n0g08.png -o @TEMP_PATH@/ftp0n0g08.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/ftp0n2c08.png -o @TEMP_PATH@/ftp0n2c08.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/ftp0n3p08.png -o @TEMP_PATH@/ftp0n3p08.png.jp2 +opj_compress -i @INPUT_NR_PATH@/pngsuite/ftp1n3p08.png -o @TEMP_PATH@/ftp1n3p08.png.jp2 # DECODER TEST SUITE opj_decompress -i @INPUT_NR_PATH@/Bretagne2.j2k -o @TEMP_PATH@/Bretagne2.j2k.pgx