From c58ef8cff423af0a581ad551107cbcd7d59c2332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Wed, 13 Feb 2019 11:55:19 +0200 Subject: [PATCH] Set TIFFTAG_SAMPLEFORMAT in imagetotif --- src/bin/jp2/converttif.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/bin/jp2/converttif.c b/src/bin/jp2/converttif.c index 6714d69c..4663e306 100644 --- a/src/bin/jp2/converttif.c +++ b/src/bin/jp2/converttif.c @@ -570,7 +570,7 @@ int imagetotif(opj_image_t * image, const char *outfile) tdata_t buf; uint32 width, height; uint16 bps, tiPhoto; - int adjust, sgnd; + int sgnd; int64_t strip_size, rowStride, TIFF_MAX; OPJ_UINT32 i, numcomps; OPJ_INT32* buffer32s = NULL; @@ -687,7 +687,6 @@ int imagetotif(opj_image_t * image, const char *outfile) break; } sgnd = (int)image->comps[0].sgnd; - adjust = sgnd ? (int)(1 << (image->comps[0].prec - 1)) : 0; width = (uint32)image->comps[0].w; height = (uint32)image->comps[0].h; @@ -699,6 +698,11 @@ int imagetotif(opj_image_t * image, const char *outfile) TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, tiPhoto); TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1); + if (sgnd) { + TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_INT); + } else { + TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT); + } if (sizeof(tsize_t) == 4) { TIFF_MAX = INT_MAX; } else { @@ -733,7 +737,7 @@ int imagetotif(opj_image_t * image, const char *outfile) } for (i = 0; i < image->comps[0].h; ++i) { - cvtPxToCx(planes, buffer32s, (OPJ_SIZE_T)width, adjust); + cvtPxToCx(planes, buffer32s, (OPJ_SIZE_T)width, 0); cvt32sToTif(buffer32s, (OPJ_BYTE *)buf, (OPJ_SIZE_T)width * numcomps); (void)TIFFWriteEncodedStrip(tif, i, (void*)buf, (tsize_t)strip_size); planes[0] += width; @@ -1505,4 +1509,3 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) return image; }/* tiftoimage() */ -