]> git.saurik.com Git - wxWidgets.git/blobdiff - src/tiff/libtiff/tif_thunder.c
Merged libtiff 4.0.3 changes into the trunk.
[wxWidgets.git] / src / tiff / libtiff / tif_thunder.c
index bbd8fe2052dd4c051f256428d60ddbc5a4f433b5..d4ca60db7897ca01e81cd2a4d3dc5d2f7ffe6a78 100644 (file)
@@ -25,6 +25,7 @@
  */
 
 #include "tiffiop.h"
+#include <assert.h>
 #ifdef THUNDER_SUPPORT
 /*
  * TIFF Library.
 static const int twobitdeltas[4] = { 0, 1, 0, -1 };
 static const int threebitdeltas[8] = { 0, 1, 2, 3, 0, -3, -2, -1 };
 
-#define        SETPIXEL(op, v) { \
-       lastpixel = (v) & 0xf; \
-       if (npixels++ & 1) \
-           *op++ |= lastpixel; \
-       else \
-           op[0] = (tidataval_t) (lastpixel << 4); \
+#define        SETPIXEL(op, v) {                     \
+       lastpixel = (v) & 0xf;                \
+        if ( npixels < maxpixels )         \
+        {                                     \
+         if (npixels++ & 1)                  \
+           *op++ |= lastpixel;               \
+         else                                \
+           op[0] = (uint8) (lastpixel << 4); \
+        }                                     \
 }
 
 static int
-ThunderDecode(TIFF* tif, tidata_t op, tsize_t maxpixels)
+ThunderSetupDecode(TIFF* tif)
 {
+       static const char module[] = "ThunderSetupDecode";
+
+        if( tif->tif_dir.td_bitspersample != 4 )
+        {
+                TIFFErrorExt(tif->tif_clientdata, module,
+                             "Wrong bitspersample value (%d), Thunder decoder only supports 4bits per sample.",
+                             (int) tif->tif_dir.td_bitspersample );
+                return 0;
+        }
+        
+
+       return (1);
+}
+
+static int
+ThunderDecode(TIFF* tif, uint8* op, tmsize_t maxpixels)
+{
+       static const char module[] = "ThunderDecode";
        register unsigned char *bp;
-       register tsize_t cc;
+       register tmsize_t cc;
        unsigned int lastpixel;
-       tsize_t npixels;
+       tmsize_t npixels;
 
        bp = (unsigned char *)tif->tif_rawcp;
        cc = tif->tif_rawcc;
@@ -93,7 +115,7 @@ ThunderDecode(TIFF* tif, tidata_t op, tsize_t maxpixels)
                        npixels += n;
                        if (npixels < maxpixels) {
                                for (; n > 0; n -= 2)
-                                       *op++ = (tidataval_t) lastpixel;
+                                       *op++ = (uint8) lastpixel;
                        }
                        if (n == -1)
                                *--op &= 0xf0;
@@ -118,25 +140,43 @@ ThunderDecode(TIFF* tif, tidata_t op, tsize_t maxpixels)
                        break;
                }
        }
-       tif->tif_rawcp = (tidata_t) bp;
+       tif->tif_rawcp = (uint8*) bp;
        tif->tif_rawcc = cc;
        if (npixels != maxpixels) {
-               TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
-                   "ThunderDecode: %s data at scanline %ld (%lu != %lu)",
-                   npixels < maxpixels ? "Not enough" : "Too much",
-                   (long) tif->tif_row, (long) npixels, (long) maxpixels);
+#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
+               TIFFErrorExt(tif->tif_clientdata, module,
+                            "%s data at scanline %lu (%I64u != %I64u)",
+                            npixels < maxpixels ? "Not enough" : "Too much",
+                            (unsigned long) tif->tif_row,
+                            (unsigned __int64) npixels,
+                            (unsigned __int64) maxpixels);
+#else
+               TIFFErrorExt(tif->tif_clientdata, module,
+                            "%s data at scanline %lu (%llu != %llu)",
+                            npixels < maxpixels ? "Not enough" : "Too much",
+                            (unsigned long) tif->tif_row,
+                            (unsigned long long) npixels,
+                            (unsigned long long) maxpixels);
+#endif
                return (0);
        }
-       return (1);
+
+        return (1);
 }
 
 static int
-ThunderDecodeRow(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
+ThunderDecodeRow(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s)
 {
-       tidata_t row = buf;
+       static const char module[] = "ThunderDecodeRow";
+       uint8* row = buf;
        
        (void) s;
-       while ((long)occ > 0) {
+       if (occ % tif->tif_scanlinesize)
+       {
+               TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read");
+               return (0);
+       }
+       while (occ > 0) {
                if (!ThunderDecode(tif, row, tif->tif_dir.td_imagewidth))
                        return (0);
                occ -= tif->tif_scanlinesize;
@@ -149,10 +189,19 @@ int
 TIFFInitThunderScan(TIFF* tif, int scheme)
 {
        (void) scheme;
+
+        tif->tif_setupdecode = ThunderSetupDecode;
        tif->tif_decoderow = ThunderDecodeRow;
-       tif->tif_decodestrip = ThunderDecodeRow;
+       tif->tif_decodestrip = ThunderDecodeRow; 
        return (1);
 }
 #endif /* THUNDER_SUPPORT */
 
 /* vim: set ts=8 sts=8 sw=8 noet: */
+/*
+ * Local Variables:
+ * mode: c
+ * c-basic-offset: 8
+ * fill-column: 78
+ * End:
+ */