summaryrefslogtreecommitdiff
path: root/src/3rdparty/libtiff/libtiff/tif_thunder.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/libtiff/libtiff/tif_thunder.c')
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_thunder.c91
1 files changed, 70 insertions, 21 deletions
diff --git a/src/3rdparty/libtiff/libtiff/tif_thunder.c b/src/3rdparty/libtiff/libtiff/tif_thunder.c
index 94496eccb1..390891c98b 100644
--- a/src/3rdparty/libtiff/libtiff/tif_thunder.c
+++ b/src/3rdparty/libtiff/libtiff/tif_thunder.c
@@ -1,4 +1,4 @@
-/* $Id: tif_thunder.c,v 1.5 2005/12/21 12:23:13 joris Exp $ */
+/* $Id: tif_thunder.c,v 1.12 2011-04-02 20:54:09 bfriesen Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
@@ -25,6 +25,7 @@
*/
#include "tiffiop.h"
+#include <assert.h>
#ifdef THUNDER_SUPPORT
/*
* TIFF Library.
@@ -55,21 +56,42 @@
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:
+ */