*/
#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;
npixels += n;
if (npixels < maxpixels) {
for (; n > 0; n -= 2)
- *op++ = (tidataval_t) lastpixel;
+ *op++ = (uint8) lastpixel;
}
if (n == -1)
*--op &= 0xf0;
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;
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:
+ */