summaryrefslogtreecommitdiff
path: root/src/3rdparty/libtiff/libtiff/tif_pixarlog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/libtiff/libtiff/tif_pixarlog.c')
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_pixarlog.c284
1 files changed, 173 insertions, 111 deletions
diff --git a/src/3rdparty/libtiff/libtiff/tif_pixarlog.c b/src/3rdparty/libtiff/libtiff/tif_pixarlog.c
index 5ad84f8b80..e583117048 100644
--- a/src/3rdparty/libtiff/libtiff/tif_pixarlog.c
+++ b/src/3rdparty/libtiff/libtiff/tif_pixarlog.c
@@ -1,4 +1,4 @@
-/* $Id: tif_pixarlog.c,v 1.15.2.3 2009-01-01 00:10:43 bfriesen Exp $ */
+/* $Id: tif_pixarlog.c,v 1.38 2012-06-21 01:01:53 fwarmerdam Exp $ */
/*
* Copyright (c) 1996-1997 Sam Leffler
@@ -83,7 +83,10 @@
* The codec also handle byte swapping the encoded values as necessary
* since the library does not have the information necessary
* to know the bit depth of the raw unencoded buffer.
- *
+ *
+ * NOTE: This decoder does not appear to update tif_rawcp, and tif_rawcc.
+ * This can cause problems with the implementation of CHUNKY_STRIP_READ_SUPPORT
+ * as noted in http://trac.osgeo.org/gdal/ticket/3894. FrankW - Jan'11
*/
#include "tif_predict.h"
@@ -108,7 +111,7 @@ static float LogK1, LogK2;
#define REPEAT(n, op) { int i; i=n; do { i--; op; } while (i>0); }
static void
-horizontalAccumulateF(uint16 *wp, int n, int stride, float *op,
+horizontalAccumulateF(uint16 *wp, int n, int stride, float *op,
float *ToLinearF)
{
register unsigned int cr, cg, cb, ca, mask;
@@ -117,9 +120,9 @@ horizontalAccumulateF(uint16 *wp, int n, int stride, float *op,
if (n >= stride) {
mask = CODE_MASK;
if (stride == 3) {
- t0 = ToLinearF[cr = wp[0]];
- t1 = ToLinearF[cg = wp[1]];
- t2 = ToLinearF[cb = wp[2]];
+ t0 = ToLinearF[cr = (wp[0] & mask)];
+ t1 = ToLinearF[cg = (wp[1] & mask)];
+ t2 = ToLinearF[cb = (wp[2] & mask)];
op[0] = t0;
op[1] = t1;
op[2] = t2;
@@ -136,10 +139,10 @@ horizontalAccumulateF(uint16 *wp, int n, int stride, float *op,
op[2] = t2;
}
} else if (stride == 4) {
- t0 = ToLinearF[cr = wp[0]];
- t1 = ToLinearF[cg = wp[1]];
- t2 = ToLinearF[cb = wp[2]];
- t3 = ToLinearF[ca = wp[3]];
+ t0 = ToLinearF[cr = (wp[0] & mask)];
+ t1 = ToLinearF[cg = (wp[1] & mask)];
+ t2 = ToLinearF[cb = (wp[2] & mask)];
+ t3 = ToLinearF[ca = (wp[3] & mask)];
op[0] = t0;
op[1] = t1;
op[2] = t2;
@@ -183,9 +186,9 @@ horizontalAccumulate12(uint16 *wp, int n, int stride, int16 *op,
if (n >= stride) {
mask = CODE_MASK;
if (stride == 3) {
- t0 = ToLinearF[cr = wp[0]] * SCALE12;
- t1 = ToLinearF[cg = wp[1]] * SCALE12;
- t2 = ToLinearF[cb = wp[2]] * SCALE12;
+ t0 = ToLinearF[cr = (wp[0] & mask)] * SCALE12;
+ t1 = ToLinearF[cg = (wp[1] & mask)] * SCALE12;
+ t2 = ToLinearF[cb = (wp[2] & mask)] * SCALE12;
op[0] = CLAMP12(t0);
op[1] = CLAMP12(t1);
op[2] = CLAMP12(t2);
@@ -202,10 +205,10 @@ horizontalAccumulate12(uint16 *wp, int n, int stride, int16 *op,
op[2] = CLAMP12(t2);
}
} else if (stride == 4) {
- t0 = ToLinearF[cr = wp[0]] * SCALE12;
- t1 = ToLinearF[cg = wp[1]] * SCALE12;
- t2 = ToLinearF[cb = wp[2]] * SCALE12;
- t3 = ToLinearF[ca = wp[3]] * SCALE12;
+ t0 = ToLinearF[cr = (wp[0] & mask)] * SCALE12;
+ t1 = ToLinearF[cg = (wp[1] & mask)] * SCALE12;
+ t2 = ToLinearF[cb = (wp[2] & mask)] * SCALE12;
+ t3 = ToLinearF[ca = (wp[3] & mask)] * SCALE12;
op[0] = CLAMP12(t0);
op[1] = CLAMP12(t1);
op[2] = CLAMP12(t2);
@@ -247,9 +250,9 @@ horizontalAccumulate16(uint16 *wp, int n, int stride, uint16 *op,
if (n >= stride) {
mask = CODE_MASK;
if (stride == 3) {
- op[0] = ToLinear16[cr = wp[0]];
- op[1] = ToLinear16[cg = wp[1]];
- op[2] = ToLinear16[cb = wp[2]];
+ op[0] = ToLinear16[cr = (wp[0] & mask)];
+ op[1] = ToLinear16[cg = (wp[1] & mask)];
+ op[2] = ToLinear16[cb = (wp[2] & mask)];
n -= 3;
while (n > 0) {
wp += 3;
@@ -260,10 +263,10 @@ horizontalAccumulate16(uint16 *wp, int n, int stride, uint16 *op,
op[2] = ToLinear16[(cb += wp[2]) & mask];
}
} else if (stride == 4) {
- op[0] = ToLinear16[cr = wp[0]];
- op[1] = ToLinear16[cg = wp[1]];
- op[2] = ToLinear16[cb = wp[2]];
- op[3] = ToLinear16[ca = wp[3]];
+ op[0] = ToLinear16[cr = (wp[0] & mask)];
+ op[1] = ToLinear16[cg = (wp[1] & mask)];
+ op[2] = ToLinear16[cb = (wp[2] & mask)];
+ op[3] = ToLinear16[ca = (wp[3] & mask)];
n -= 4;
while (n > 0) {
wp += 4;
@@ -342,9 +345,9 @@ horizontalAccumulate8(uint16 *wp, int n, int stride, unsigned char *op,
if (n >= stride) {
mask = CODE_MASK;
if (stride == 3) {
- op[0] = ToLinear8[cr = wp[0]];
- op[1] = ToLinear8[cg = wp[1]];
- op[2] = ToLinear8[cb = wp[2]];
+ op[0] = ToLinear8[cr = (wp[0] & mask)];
+ op[1] = ToLinear8[cg = (wp[1] & mask)];
+ op[2] = ToLinear8[cb = (wp[2] & mask)];
n -= 3;
while (n > 0) {
n -= 3;
@@ -355,10 +358,10 @@ horizontalAccumulate8(uint16 *wp, int n, int stride, unsigned char *op,
op[2] = ToLinear8[(cb += wp[2]) & mask];
}
} else if (stride == 4) {
- op[0] = ToLinear8[cr = wp[0]];
- op[1] = ToLinear8[cg = wp[1]];
- op[2] = ToLinear8[cb = wp[2]];
- op[3] = ToLinear8[ca = wp[3]];
+ op[0] = ToLinear8[cr = (wp[0] & mask)];
+ op[1] = ToLinear8[cg = (wp[1] & mask)];
+ op[2] = ToLinear8[cb = (wp[2] & mask)];
+ op[3] = ToLinear8[ca = (wp[3] & mask)];
n -= 4;
while (n > 0) {
n -= 4;
@@ -393,9 +396,9 @@ horizontalAccumulate8abgr(uint16 *wp, int n, int stride, unsigned char *op,
mask = CODE_MASK;
if (stride == 3) {
op[0] = 0;
- t1 = ToLinear8[cb = wp[2]];
- t2 = ToLinear8[cg = wp[1]];
- t3 = ToLinear8[cr = wp[0]];
+ t1 = ToLinear8[cb = (wp[2] & mask)];
+ t2 = ToLinear8[cg = (wp[1] & mask)];
+ t3 = ToLinear8[cr = (wp[0] & mask)];
op[1] = t1;
op[2] = t2;
op[3] = t3;
@@ -413,10 +416,10 @@ horizontalAccumulate8abgr(uint16 *wp, int n, int stride, unsigned char *op,
op[3] = t3;
}
} else if (stride == 4) {
- t0 = ToLinear8[ca = wp[3]];
- t1 = ToLinear8[cb = wp[2]];
- t2 = ToLinear8[cg = wp[1]];
- t3 = ToLinear8[cr = wp[0]];
+ t0 = ToLinear8[ca = (wp[3] & mask)];
+ t1 = ToLinear8[cb = (wp[2] & mask)];
+ t2 = ToLinear8[cg = (wp[1] & mask)];
+ t3 = ToLinear8[cr = (wp[0] & mask)];
op[0] = t0;
op[1] = t1;
op[2] = t2;
@@ -587,11 +590,11 @@ PixarLogMakeTables(PixarLogState *sp)
return 1;
}
-#define DecoderState(tif) ((PixarLogState*) (tif)->tif_data)
-#define EncoderState(tif) ((PixarLogState*) (tif)->tif_data)
+#define DecoderState(tif) ((PixarLogState*) (tif)->tif_data)
+#define EncoderState(tif) ((PixarLogState*) (tif)->tif_data)
-static int PixarLogEncode(TIFF*, tidata_t, tsize_t, tsample_t);
-static int PixarLogDecode(TIFF*, tidata_t, tsize_t, tsample_t);
+static int PixarLogEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s);
+static int PixarLogDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s);
#define PIXARLOGDATAFMT_UNKNOWN -1
@@ -630,10 +633,10 @@ PixarLogGuessDataFmt(TIFFDirectory *td)
return guess;
}
-static uint32
-multiply(size_t m1, size_t m2)
+static tmsize_t
+multiply_ms(tmsize_t m1, tmsize_t m2)
{
- uint32 bytes = m1 * m2;
+ tmsize_t bytes = m1 * m2;
if (m1 && bytes / m1 != m2)
bytes = 0;
@@ -642,28 +645,35 @@ multiply(size_t m1, size_t m2)
}
static int
+PixarLogFixupTags(TIFF* tif)
+{
+ (void) tif;
+ return (1);
+}
+
+static int
PixarLogSetupDecode(TIFF* tif)
{
+ static const char module[] = "PixarLogSetupDecode";
TIFFDirectory *td = &tif->tif_dir;
PixarLogState* sp = DecoderState(tif);
- tsize_t tbuf_size;
- static const char module[] = "PixarLogSetupDecode";
+ tmsize_t tbuf_size;
assert(sp != NULL);
/* Make sure no byte swapping happens on the data
* after decompression. */
- tif->tif_postdecode = _TIFFNoPostDecode;
+ tif->tif_postdecode = _TIFFNoPostDecode;
/* for some reason, we can't do this in TIFFInitPixarLog */
sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ?
td->td_samplesperpixel : 1);
- tbuf_size = multiply(multiply(multiply(sp->stride, td->td_imagewidth),
+ tbuf_size = multiply_ms(multiply_ms(multiply_ms(sp->stride, td->td_imagewidth),
td->td_rowsperstrip), sizeof(uint16));
if (tbuf_size == 0)
- return (0);
- sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size);
+ return (0); /* TODO: this is an error return without error report through TIFFErrorExt */
+ sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size+sizeof(uint16)*sp->stride);
if (sp->tbuf == NULL)
return (0);
if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN)
@@ -676,7 +686,7 @@ PixarLogSetupDecode(TIFF* tif)
}
if (inflateInit(&sp->stream) != Z_OK) {
- TIFFErrorExt(tif->tif_clientdata, module, "%s: %s", tif->tif_name, sp->stream.msg);
+ TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg);
return (0);
} else {
sp->state |= PLSTATE_INIT;
@@ -688,24 +698,36 @@ PixarLogSetupDecode(TIFF* tif)
* Setup state for decoding a strip.
*/
static int
-PixarLogPreDecode(TIFF* tif, tsample_t s)
+PixarLogPreDecode(TIFF* tif, uint16 s)
{
+ static const char module[] = "PixarLogPreDecode";
PixarLogState* sp = DecoderState(tif);
(void) s;
assert(sp != NULL);
sp->stream.next_in = tif->tif_rawdata;
- sp->stream.avail_in = tif->tif_rawcc;
+ assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised,
+ we need to simplify this code to reflect a ZLib that is likely updated
+ to deal with 8byte memory sizes, though this code will respond
+ apropriately even before we simplify it */
+ sp->stream.avail_in = (uInt) tif->tif_rawcc;
+ if ((tmsize_t)sp->stream.avail_in != tif->tif_rawcc)
+ {
+ TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size");
+ return (0);
+ }
return (inflateReset(&sp->stream) == Z_OK);
}
static int
-PixarLogDecode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
+PixarLogDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
{
+ static const char module[] = "PixarLogDecode";
TIFFDirectory *td = &tif->tif_dir;
PixarLogState* sp = DecoderState(tif);
- static const char module[] = "PixarLogDecode";
- int i, nsamples, llen;
+ tmsize_t i;
+ tmsize_t nsamples;
+ int llen;
uint16 *up;
switch (sp->user_datafmt) {
@@ -722,7 +744,7 @@ PixarLogDecode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
nsamples = occ;
break;
default:
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
+ TIFFErrorExt(tif->tif_clientdata, module,
"%d bit input not supported in PixarLog",
td->td_bitspersample);
return 0;
@@ -733,7 +755,16 @@ PixarLogDecode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
(void) s;
assert(sp != NULL);
sp->stream.next_out = (unsigned char *) sp->tbuf;
- sp->stream.avail_out = nsamples * sizeof(uint16);
+ assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised,
+ we need to simplify this code to reflect a ZLib that is likely updated
+ to deal with 8byte memory sizes, though this code will respond
+ apropriately even before we simplify it */
+ sp->stream.avail_out = (uInt) (nsamples * sizeof(uint16));
+ if (sp->stream.avail_out != nsamples * sizeof(uint16))
+ {
+ TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size");
+ return (0);
+ }
do {
int state = inflate(&sp->stream, Z_PARTIAL_FLUSH);
if (state == Z_STREAM_END) {
@@ -741,15 +772,15 @@ PixarLogDecode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
}
if (state == Z_DATA_ERROR) {
TIFFErrorExt(tif->tif_clientdata, module,
- "%s: Decoding error at scanline %d, %s",
- tif->tif_name, tif->tif_row, sp->stream.msg);
+ "Decoding error at scanline %lu, %s",
+ (unsigned long) tif->tif_row, sp->stream.msg);
if (inflateSync(&sp->stream) != Z_OK)
return (0);
continue;
}
if (state != Z_OK) {
- TIFFErrorExt(tif->tif_clientdata, module, "%s: zlib error: %s",
- tif->tif_name, sp->stream.msg);
+ TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s",
+ sp->stream.msg);
return (0);
}
} while (sp->stream.avail_out > 0);
@@ -757,8 +788,8 @@ PixarLogDecode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
/* hopefully, we got all the bytes we needed */
if (sp->stream.avail_out != 0) {
TIFFErrorExt(tif->tif_clientdata, module,
- "%s: Not enough data at scanline %d (short %d bytes)",
- tif->tif_name, tif->tif_row, sp->stream.avail_out);
+ "Not enough data at scanline %lu (short " TIFF_UINT64_FORMAT " bytes)",
+ (unsigned long) tif->tif_row, (TIFF_UINT64_T) sp->stream.avail_out);
return (0);
}
@@ -767,15 +798,15 @@ PixarLogDecode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
if (tif->tif_flags & TIFF_SWAB)
TIFFSwabArrayOfShort(up, nsamples);
- /*
+ /*
* if llen is not an exact multiple of nsamples, the decode operation
* may overflow the output buffer, so truncate it enough to prevent
* that but still salvage as much data as possible.
*/
if (nsamples % llen) {
TIFFWarningExt(tif->tif_clientdata, module,
- "%s: stride %d is not a multiple of sample count, "
- "%d, data truncated.", tif->tif_name, llen, nsamples);
+ "stride %lu is not a multiple of sample count, "
+ "%lu, data truncated.", (unsigned long) llen, (unsigned long) nsamples);
nsamples -= nsamples % llen;
}
@@ -812,8 +843,8 @@ PixarLogDecode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
op += llen * sizeof(unsigned char);
break;
default:
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
- "PixarLogDecode: unsupported bits/sample: %d",
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Unsupported bits/sample: %d",
td->td_bitspersample);
return (0);
}
@@ -825,10 +856,10 @@ PixarLogDecode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
static int
PixarLogSetupEncode(TIFF* tif)
{
+ static const char module[] = "PixarLogSetupEncode";
TIFFDirectory *td = &tif->tif_dir;
PixarLogState* sp = EncoderState(tif);
- tsize_t tbuf_size;
- static const char module[] = "PixarLogSetupEncode";
+ tmsize_t tbuf_size;
assert(sp != NULL);
@@ -836,10 +867,10 @@ PixarLogSetupEncode(TIFF* tif)
sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ?
td->td_samplesperpixel : 1);
- tbuf_size = multiply(multiply(multiply(sp->stride, td->td_imagewidth),
+ tbuf_size = multiply_ms(multiply_ms(multiply_ms(sp->stride, td->td_imagewidth),
td->td_rowsperstrip), sizeof(uint16));
if (tbuf_size == 0)
- return (0);
+ return (0); /* TODO: this is an error return without error report through TIFFErrorExt */
sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size);
if (sp->tbuf == NULL)
return (0);
@@ -851,7 +882,7 @@ PixarLogSetupEncode(TIFF* tif)
}
if (deflateInit(&sp->stream, sp->quality) != Z_OK) {
- TIFFErrorExt(tif->tif_clientdata, module, "%s: %s", tif->tif_name, sp->stream.msg);
+ TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg);
return (0);
} else {
sp->state |= PLSTATE_INIT;
@@ -863,21 +894,30 @@ PixarLogSetupEncode(TIFF* tif)
* Reset encoding state at the start of a strip.
*/
static int
-PixarLogPreEncode(TIFF* tif, tsample_t s)
+PixarLogPreEncode(TIFF* tif, uint16 s)
{
+ static const char module[] = "PixarLogPreEncode";
PixarLogState *sp = EncoderState(tif);
(void) s;
assert(sp != NULL);
sp->stream.next_out = tif->tif_rawdata;
+ assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised,
+ we need to simplify this code to reflect a ZLib that is likely updated
+ to deal with 8byte memory sizes, though this code will respond
+ apropriately even before we simplify it */
sp->stream.avail_out = tif->tif_rawdatasize;
+ if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize)
+ {
+ TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size");
+ return (0);
+ }
return (deflateReset(&sp->stream) == Z_OK);
}
static void
horizontalDifferenceF(float *ip, int n, int stride, uint16 *wp, uint16 *FromLT2)
{
-
int32 r1, g1, b1, a1, r2, g2, b2, a2, mask;
float fltsize = Fltsize;
@@ -1042,12 +1082,14 @@ horizontalDifference8(unsigned char *ip, int n, int stride,
* Encode a chunk of pixels.
*/
static int
-PixarLogEncode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
+PixarLogEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
{
+ static const char module[] = "PixarLogEncode";
TIFFDirectory *td = &tif->tif_dir;
PixarLogState *sp = EncoderState(tif);
- static const char module[] = "PixarLogEncode";
- int i, n, llen;
+ tmsize_t i;
+ tmsize_t n;
+ int llen;
unsigned short * up;
(void) s;
@@ -1066,7 +1108,7 @@ PixarLogEncode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
n = cc;
break;
default:
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
+ TIFFErrorExt(tif->tif_clientdata, module,
"%d bit input not supported in PixarLog",
td->td_bitspersample);
return 0;
@@ -1092,7 +1134,7 @@ PixarLogEncode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
bp += llen * sizeof(unsigned char);
break;
default:
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
+ TIFFErrorExt(tif->tif_clientdata, module,
"%d bit input not supported in PixarLog",
td->td_bitspersample);
return 0;
@@ -1100,19 +1142,29 @@ PixarLogEncode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
}
sp->stream.next_in = (unsigned char *) sp->tbuf;
- sp->stream.avail_in = n * sizeof(uint16);
+ assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised,
+ we need to simplify this code to reflect a ZLib that is likely updated
+ to deal with 8byte memory sizes, though this code will respond
+ apropriately even before we simplify it */
+ sp->stream.avail_in = (uInt) (n * sizeof(uint16));
+ if ((sp->stream.avail_in / sizeof(uint16)) != (uInt) n)
+ {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "ZLib cannot deal with buffers this size");
+ return (0);
+ }
do {
if (deflate(&sp->stream, Z_NO_FLUSH) != Z_OK) {
- TIFFErrorExt(tif->tif_clientdata, module, "%s: Encoder error: %s",
- tif->tif_name, sp->stream.msg);
+ TIFFErrorExt(tif->tif_clientdata, module, "Encoder error: %s",
+ sp->stream.msg);
return (0);
}
if (sp->stream.avail_out == 0) {
tif->tif_rawcc = tif->tif_rawdatasize;
TIFFFlushData1(tif);
sp->stream.next_out = tif->tif_rawdata;
- sp->stream.avail_out = tif->tif_rawdatasize;
+ sp->stream.avail_out = (uInt) tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in PixarLogPreEncode */
}
} while (sp->stream.avail_in > 0);
return (1);
@@ -1126,8 +1178,8 @@ PixarLogEncode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
static int
PixarLogPostEncode(TIFF* tif)
{
- PixarLogState *sp = EncoderState(tif);
static const char module[] = "PixarLogPostEncode";
+ PixarLogState *sp = EncoderState(tif);
int state;
sp->stream.avail_in = 0;
@@ -1137,17 +1189,17 @@ PixarLogPostEncode(TIFF* tif)
switch (state) {
case Z_STREAM_END:
case Z_OK:
- if (sp->stream.avail_out != (uint32)tif->tif_rawdatasize) {
+ if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) {
tif->tif_rawcc =
tif->tif_rawdatasize - sp->stream.avail_out;
TIFFFlushData1(tif);
sp->stream.next_out = tif->tif_rawdata;
- sp->stream.avail_out = tif->tif_rawdatasize;
+ sp->stream.avail_out = (uInt) tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in PixarLogPreEncode */
}
break;
default:
- TIFFErrorExt(tif->tif_clientdata, module, "%s: zlib error: %s",
- tif->tif_name, sp->stream.msg);
+ TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s",
+ sp->stream.msg);
return (0);
}
} while (state != Z_STREAM_END);
@@ -1159,9 +1211,11 @@ PixarLogClose(TIFF* tif)
{
TIFFDirectory *td = &tif->tif_dir;
- /* In a really sneaky maneuver, on close, we covertly modify both
- * bitspersample and sampleformat in the directory to indicate
- * 8-bit linear. This way, the decode "just works" even for
+ /* In a really sneaky (and really incorrect, and untruthfull, and
+ * troublesome, and error-prone) maneuver that completely goes against
+ * the spirit of TIFF, and breaks TIFF, on close, we covertly
+ * modify both bitspersample and sampleformat in the directory to
+ * indicate 8-bit linear. This way, the decode "just works" even for
* readers that don't know about PixarLog, or how to set
* the PIXARLOGDATFMT pseudo-tag.
*/
@@ -1202,26 +1256,26 @@ PixarLogCleanup(TIFF* tif)
}
static int
-PixarLogVSetField(TIFF* tif, ttag_t tag, va_list ap)
+PixarLogVSetField(TIFF* tif, uint32 tag, va_list ap)
{
+ static const char module[] = "PixarLogVSetField";
PixarLogState *sp = (PixarLogState *)tif->tif_data;
int result;
- static const char module[] = "PixarLogVSetField";
switch (tag) {
case TIFFTAG_PIXARLOGQUALITY:
- sp->quality = va_arg(ap, int);
+ sp->quality = (int) va_arg(ap, int);
if (tif->tif_mode != O_RDONLY && (sp->state&PLSTATE_INIT)) {
if (deflateParams(&sp->stream,
sp->quality, Z_DEFAULT_STRATEGY) != Z_OK) {
- TIFFErrorExt(tif->tif_clientdata, module, "%s: zlib error: %s",
- tif->tif_name, sp->stream.msg);
+ TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s",
+ sp->stream.msg);
return (0);
}
}
return (1);
case TIFFTAG_PIXARLOGDATAFMT:
- sp->user_datafmt = va_arg(ap, int);
+ sp->user_datafmt = (int) va_arg(ap, int);
/* Tweak the TIFF header so that the rest of libtiff knows what
* size of data will be passed between app and library, and
* assume that the app knows what it is doing and is not
@@ -1253,7 +1307,7 @@ PixarLogVSetField(TIFF* tif, ttag_t tag, va_list ap)
/*
* Must recalculate sizes should bits/sample change.
*/
- tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tsize_t) -1;
+ tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tmsize_t)(-1);
tif->tif_scanlinesize = TIFFScanlineSize(tif);
result = 1; /* NB: pseudo tag */
break;
@@ -1264,7 +1318,7 @@ PixarLogVSetField(TIFF* tif, ttag_t tag, va_list ap)
}
static int
-PixarLogVGetField(TIFF* tif, ttag_t tag, va_list ap)
+PixarLogVGetField(TIFF* tif, uint32 tag, va_list ap)
{
PixarLogState *sp = (PixarLogState *)tif->tif_data;
@@ -1281,9 +1335,9 @@ PixarLogVGetField(TIFF* tif, ttag_t tag, va_list ap)
return (1);
}
-static const TIFFFieldInfo pixarlogFieldInfo[] = {
- {TIFFTAG_PIXARLOGDATAFMT,0,0,TIFF_ANY, FIELD_PSEUDO,FALSE,FALSE,""},
- {TIFFTAG_PIXARLOGQUALITY,0,0,TIFF_ANY, FIELD_PSEUDO,FALSE,FALSE,""}
+static const TIFFField pixarlogFields[] = {
+ {TIFFTAG_PIXARLOGDATAFMT, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "", NULL},
+ {TIFFTAG_PIXARLOGQUALITY, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "", NULL}
};
int
@@ -1298,8 +1352,8 @@ TIFFInitPixarLog(TIFF* tif, int scheme)
/*
* Merge codec-specific tag information.
*/
- if (!_TIFFMergeFieldInfo(tif, pixarlogFieldInfo,
- TIFFArrayCount(pixarlogFieldInfo))) {
+ if (!_TIFFMergeFields(tif, pixarlogFields,
+ TIFFArrayCount(pixarlogFields))) {
TIFFErrorExt(tif->tif_clientdata, module,
"Merging PixarLog codec-specific tags failed");
return 0;
@@ -1308,7 +1362,7 @@ TIFFInitPixarLog(TIFF* tif, int scheme)
/*
* Allocate state block so tag methods have storage to record values.
*/
- tif->tif_data = (tidata_t) _TIFFmalloc(sizeof (PixarLogState));
+ tif->tif_data = (uint8*) _TIFFmalloc(sizeof (PixarLogState));
if (tif->tif_data == NULL)
goto bad;
sp = (PixarLogState*) tif->tif_data;
@@ -1319,17 +1373,18 @@ TIFFInitPixarLog(TIFF* tif, int scheme)
/*
* Install codec methods.
*/
+ tif->tif_fixuptags = PixarLogFixupTags;
tif->tif_setupdecode = PixarLogSetupDecode;
tif->tif_predecode = PixarLogPreDecode;
tif->tif_decoderow = PixarLogDecode;
- tif->tif_decodestrip = PixarLogDecode;
+ tif->tif_decodestrip = PixarLogDecode;
tif->tif_decodetile = PixarLogDecode;
tif->tif_setupencode = PixarLogSetupEncode;
tif->tif_preencode = PixarLogPreEncode;
tif->tif_postencode = PixarLogPostEncode;
- tif->tif_encoderow = PixarLogEncode;
+ tif->tif_encoderow = PixarLogEncode;
tif->tif_encodestrip = PixarLogEncode;
- tif->tif_encodetile = PixarLogEncode;
+ tif->tif_encodetile = PixarLogEncode;
tif->tif_close = PixarLogClose;
tif->tif_cleanup = PixarLogCleanup;
@@ -1362,3 +1417,10 @@ bad:
#endif /* PIXARLOG_SUPPORT */
/* vim: set ts=8 sts=8 sw=8 noet: */
+/*
+ * Local Variables:
+ * mode: c
+ * c-basic-offset: 8
+ * fill-column: 78
+ * End:
+ */