opj_compress: improve help message regarding new IMF switch
[openjpeg.git] / src / bin / jp2 / converttif.c
index 080b470fa444b8f2cbcc92476c0bf139f9b7053a..6714d69c72996c3814058027391dbfc341e8f514 100644 (file)
@@ -568,7 +568,8 @@ int imagetotif(opj_image_t * image, const char *outfile)
 {
     TIFF *tif;
     tdata_t buf;
-    uint32 width, height, bps, tiPhoto;
+    uint32 width, height;
+    uint16 bps, tiPhoto;
     int adjust, sgnd;
     int64_t strip_size, rowStride, TIFF_MAX;
     OPJ_UINT32 i, numcomps;
@@ -577,7 +578,7 @@ int imagetotif(opj_image_t * image, const char *outfile)
     convert_32s_PXCX cvtPxToCx = NULL;
     convert_32sXXx_C1R cvt32sToTif = NULL;
 
-    bps = (uint32)image->comps[0].prec;
+    bps = (uint16)image->comps[0].prec;
     planes[0] = image->comps[0].data;
 
     numcomps = image->numcomps;
@@ -692,7 +693,7 @@ int imagetotif(opj_image_t * image, const char *outfile)
 
     TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);
     TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height);
-    TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (uint32)numcomps);
+    TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (uint16)numcomps);
     TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps);
     TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
     TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
@@ -724,8 +725,7 @@ int imagetotif(opj_image_t * image, const char *outfile)
         TIFFClose(tif);
         return 1;
     }
-    buffer32s = (OPJ_INT32 *)malloc((OPJ_SIZE_T)(width * numcomps * sizeof(
-                                        OPJ_INT32)));
+    buffer32s = (OPJ_INT32 *)malloc(sizeof(OPJ_INT32) * width * numcomps);
     if (buffer32s == NULL) {
         _TIFFfree(buf);
         TIFFClose(tif);
@@ -1253,8 +1253,8 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
     OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_UNKNOWN;
     opj_image_cmptparm_t cmptparm[4]; /* RGBA */
     opj_image_t *image = NULL;
-    int has_alpha = 0;
-    uint32 tiBps, tiPhoto, tiSf, tiSpp, tiPC, tiWidth, tiHeight;
+    uint16 tiBps, tiPhoto, tiSf, tiSpp, tiPC;
+    uint32 tiWidth, tiHeight;
     OPJ_BOOL is_cinema = OPJ_IS_CINEMA(parameters->rsiz);
     convert_XXx32s_C1R cvtTifTo32s = NULL;
     convert_32s_CXPX cvtCxToPx = NULL;
@@ -1281,7 +1281,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
     h = (int)tiHeight;
 
     if (tiSpp == 0 || tiSpp > 4) { /* should be 1 ... 4 */
-        fprintf(stderr, "tiftoimage: Bad value for samples per pixel == %hu.\n"
+        fprintf(stderr, "tiftoimage: Bad value for samples per pixel == %d.\n"
                 "\tAborting.\n", tiSpp);
         TIFFClose(tif);
         return NULL;
@@ -1355,34 +1355,6 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
         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));
 
@@ -1396,11 +1368,10 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
         is_cinema = 0U;
     }
 
+    numcomps = tiSpp;
     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;
     }
 
@@ -1475,8 +1446,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
     }
 
     rowStride = (int64_t)((tiWidth * tiSpp * tiBps + 7U) / 8U);
-    buffer32s = (OPJ_INT32 *)malloc((OPJ_SIZE_T)(tiWidth * tiSpp * sizeof(
-                                        OPJ_INT32)));
+    buffer32s = (OPJ_INT32 *)malloc(sizeof(OPJ_INT32) * tiWidth * tiSpp);
     if (buffer32s == NULL) {
         _TIFFfree(buf);
         TIFFClose(tif);