]> git.saurik.com Git - wxWidgets.git/blobdiff - src/tiff/tools/tiffgt.c
fix wxCHECK_MSG() return value
[wxWidgets.git] / src / tiff / tools / tiffgt.c
index 835295a0f74610939511b6f626101a83cee8da22..45022166dce31d2b57bf41684f5532e8d2e27c57 100644 (file)
@@ -40,6 +40,7 @@
 #endif
 
 #include "tiffio.h"
+#include "tiffiop.h"
 
 #ifndef HAVE_GETOPT
 extern int getopt(int, char**, char*);
@@ -204,7 +205,7 @@ initImage(void)
         if (photo != (uint16) -1)
                 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photo);
         if (!TIFFRGBAImageBegin(&img, tif, stoponerr, title)) {
-                TIFFError(filelist[fileindex], title);
+                TIFFError(filelist[fileindex], "%s", title);
                 TIFFClose(tif);
                 tif = NULL;
                 return -1;
@@ -224,21 +225,24 @@ initImage(void)
                 w = xmax;
         }
 
-        if (w != width || h != height) {
-            if (raster != NULL)
-                _TIFFfree(raster), raster = NULL;
-            raster = (uint32*) _TIFFmalloc(img.width * img.height * sizeof (uint32));
-            if (raster == NULL) {
-                width = height = 0;
-                TIFFError(filelist[fileindex], "No space for raster buffer");
-                cleanup_and_exit();
-            }
-            width = w;
-            height = h;
-        }
-        TIFFRGBAImageGet(&img, raster, img.width, img.height);
+       if (w != width || h != height) {
+               uint32 rastersize =
+                       _TIFFMultiply32(tif, img.width, img.height, "allocating raster buffer");
+               if (raster != NULL)
+                       _TIFFfree(raster), raster = NULL;
+               raster = (uint32*) _TIFFCheckMalloc(tif, rastersize, sizeof (uint32),
+                                                   "allocating raster buffer");
+               if (raster == NULL) {
+                       width = height = 0;
+                       TIFFError(filelist[fileindex], "No space for raster buffer");
+                       cleanup_and_exit();
+               }
+               width = w;
+               height = h;
+       }
+       TIFFRGBAImageGet(&img, raster, img.width, img.height);
 #if HOST_BIGENDIAN
-        TIFFSwabArrayOfLong(raster,img.width*img.height);
+       TIFFSwabArrayOfLong(raster,img.width*img.height);
 #endif
        return 0;
 }
@@ -453,3 +457,10 @@ photoArg(const char* arg)
 }
 
 /* vim: set ts=8 sts=8 sw=8 noet: */
+/*
+ * Local Variables:
+ * mode: c
+ * c-basic-offset: 8
+ * fill-column: 78
+ * End:
+ */