* input is assumed to be unsigned linear color values that represent
* the range 0-1. In the case of IEEE values, the 0-1 range is assumed to
* be the normal linear color range, in addition over 1 values are
- * accepted up to a value of about 25.0 to encode "hot" hightlights and such.
+ * accepted up to a value of about 25.0 to encode "hot" highlights and such.
* The encoding is lossless for 8-bit values, slightly lossy for the
* other bit depths. The actual color precision should be better
* than the human eye can perceive with extra room to allow for
*
*/
-/* Watcom C++ (or its make utility) doesn't like long filenames */
-#ifdef __WATCOMC__
-#include "tif_pred.h"
-#else
#include "tif_predict.h"
-#endif
-
#include "zlib.h"
-#include "zutil.h"
#include <stdio.h>
#include <assert.h>
int nlin, lt2size;
int i, j;
- double b, c, linstep, max;
- double k, v, dv, r, lr2, r2;
+ double b, c, linstep, v;
float *ToLinearF;
uint16 *ToLinear16;
unsigned char *ToLinear8;
uint16 *From8;
c = log(RATIO);
- nlin = 1./c; /* nlin must be an integer */
+ nlin = (int)1./c; /* nlin must be an integer */
c = 1./nlin;
b = exp(-c*ONE); /* multiplicative scale factor [b*exp(c*ONE) = 1] */
linstep = b*c*exp(1.);
LogK1 = 1./c; /* if (v >= 2) token = k1*log(v*k2) */
LogK2 = 1./b;
- lt2size = (2./linstep)+1;
+ lt2size = (int)(2./linstep) + 1;
FromLT2 = (uint16 *)_TIFFmalloc(lt2size*sizeof(uint16));
From14 = (uint16 *)_TIFFmalloc(16384*sizeof(uint16));
From8 = (uint16 *)_TIFFmalloc(256*sizeof(uint16));
for (i = 0; i < TSIZEP1; i++) {
v = ToLinearF[i]*65535.0 + 0.5;
- ToLinear16[i] = (v > 65535.0) ? 65535 : v;
+ ToLinear16[i] = (v > 65535.0) ? 65535 : (uint16)v;
v = ToLinearF[i]*255.0 + 0.5;
- ToLinear8[i] = (v > 255.0) ? 255 : v;
+ ToLinear8[i] = (v > 255.0) ? 255 : (unsigned char)v;
}
j = 0;
return guess;
}
+static uint32
+multiply(size_t m1, size_t m2)
+{
+ uint32 bytes = m1 * m2;
+
+ if (m1 && bytes / m1 != m2)
+ bytes = 0;
+
+ return bytes;
+}
+
static int
PixarLogSetupDecode(TIFF* tif)
{
TIFFDirectory *td = &tif->tif_dir;
PixarLogState* sp = DecoderState(tif);
+ tsize_t tbuf_size;
static const char module[] = "PixarLogSetupDecode";
assert(sp != NULL);
sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ?
td->td_samplesperpixel : 1);
- sp->tbuf = (uint16 *) _TIFFmalloc(sp->stride *
- td->td_imagewidth * td->td_rowsperstrip * sizeof(uint16));
+ tbuf_size = multiply(multiply(multiply(sp->stride, td->td_imagewidth),
+ td->td_rowsperstrip), sizeof(uint16));
+ if (tbuf_size == 0)
+ return (0);
+ sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size);
+ if (sp->tbuf == NULL)
+ return (0);
if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN)
sp->user_datafmt = PixarLogGuessDataFmt(td);
if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) {
static int
PixarLogPreDecode(TIFF* tif, tsample_t s)
{
- TIFFDirectory *td = &tif->tif_dir;
PixarLogState* sp = DecoderState(tif);
(void) s;
{
TIFFDirectory *td = &tif->tif_dir;
PixarLogState* sp = EncoderState(tif);
+ tsize_t tbuf_size;
static const char module[] = "PixarLogSetupEncode";
assert(sp != NULL);
sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ?
td->td_samplesperpixel : 1);
- sp->tbuf = (uint16 *) _TIFFmalloc(sp->stride *
- td->td_imagewidth * td->td_rowsperstrip * sizeof(uint16));
+ tbuf_size = multiply(multiply(multiply(sp->stride, td->td_imagewidth),
+ td->td_rowsperstrip), sizeof(uint16));
+ if (tbuf_size == 0)
+ return (0);
+ sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size);
+ if (sp->tbuf == NULL)
+ return (0);
if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN)
sp->user_datafmt = PixarLogGuessDataFmt(td);
if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) {
static int
PixarLogPreEncode(TIFF* tif, tsample_t s)
{
- TIFFDirectory *td = &tif->tif_dir;
PixarLogState *sp = EncoderState(tif);
(void) s;
/* Override SetField so we can handle our private pseudo-tag */
_TIFFMergeFieldInfo(tif, pixarlogFieldInfo, N(pixarlogFieldInfo));
- sp->vgetparent = tif->tif_vgetfield;
- tif->tif_vgetfield = PixarLogVGetField; /* hook for codec tags */
- sp->vsetparent = tif->tif_vsetfield;
- tif->tif_vsetfield = PixarLogVSetField; /* hook for codec tags */
+ sp->vgetparent = tif->tif_tagmethods.vgetfield;
+ tif->tif_tagmethods.vgetfield = PixarLogVGetField; /* hook for codec tags */
+ sp->vsetparent = tif->tif_tagmethods.vsetfield;
+ tif->tif_tagmethods.vsetfield = PixarLogVSetField; /* hook for codec tags */
/* Default values for codec-specific fields */
sp->quality = Z_DEFAULT_COMPRESSION; /* default comp. level */