summaryrefslogtreecommitdiff
path: root/libtiff/tif_luv.c
diff options
context:
space:
mode:
authorjoris <joris>2007-04-11 02:41:22 +0000
committerjoris <joris>2007-04-11 02:41:22 +0000
commit206d2b8f46fcb35a84f1233cbb42219299820c06 (patch)
treef98dd41eadb0d6d0dfaf18507d162458badaff7a /libtiff/tif_luv.c
parenta8d938080b680c7e849e85bd355db48d3894c065 (diff)
downloadlibtiff-206d2b8f46fcb35a84f1233cbb42219299820c06.tar.gz
BigTIFF upgrade in progress - widespread temp mess - does not compile now
Diffstat (limited to 'libtiff/tif_luv.c')
-rw-r--r--libtiff/tif_luv.c416
1 files changed, 220 insertions, 196 deletions
diff --git a/libtiff/tif_luv.c b/libtiff/tif_luv.c
index 915fc16a..acadf892 100644
--- a/libtiff/tif_luv.c
+++ b/libtiff/tif_luv.c
@@ -1,4 +1,4 @@
-/* $Id: tif_luv.c,v 1.21 2007-04-07 15:14:30 dron Exp $ */
+/* $Id: tif_luv.c,v 1.22 2007-04-11 02:41:22 joris Exp $ */
/*
* Copyright (c) 1997 Greg Ward Larson
@@ -155,40 +155,44 @@
* State block for each open TIFF
* file using LogLuv compression/decompression.
*/
-typedef struct logLuvState LogLuvState;
+typedef struct logLuvState LogLuvState;
struct logLuvState {
- int user_datafmt; /* user data format */
- int encode_meth; /* encoding method */
- int pixel_size; /* bytes per pixel */
+ int user_datafmt; /* user data format */
+ int encode_meth; /* encoding method */
+ int pixel_size; /* bytes per pixel */
- tidata_t* tbuf; /* translation buffer */
- int tbuflen; /* buffer length */
- void (*tfunc)(LogLuvState*, tidata_t, int);
+ uint8* tbuf; /* translation buffer */
+ tmsize_t tbuflen; /* buffer length */
+ void (*tfunc)(LogLuvState*, uint8*, tmsize_t);
- TIFFVSetMethod vgetparent; /* super-class method */
- TIFFVSetMethod vsetparent; /* super-class method */
+ TIFFVSetMethod vgetparent; /* super-class method */
+ TIFFVSetMethod vsetparent; /* super-class method */
};
-#define DecoderState(tif) ((LogLuvState*) (tif)->tif_data)
-#define EncoderState(tif) ((LogLuvState*) (tif)->tif_data)
+#define DecoderState(tif) ((LogLuvState*) (tif)->tif_data)
+#define EncoderState(tif) ((LogLuvState*) (tif)->tif_data)
-#define SGILOGDATAFMT_UNKNOWN -1
+#define SGILOGDATAFMT_UNKNOWN -1
-#define MINRUN 4 /* minimum run length */
+#define MINRUN 4 /* minimum run length */
/*
* Decode a string of 16-bit gray pixels.
*/
static int
-LogL16Decode(TIFF* tif, tidata_t op, tsize_t occ, uint16 s)
+LogL16Decode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
{
+ static const char module[] = "LogL16Decode";
LogLuvState* sp = DecoderState(tif);
- int shft, i, npixels;
+ int shft;
+ tmsize_t i;
+ tmsize_t npixels;
unsigned char* bp;
int16* tp;
int16 b;
- int cc, rc;
+ tmsize_t cc;
+ int rc;
assert(s == 0);
assert(sp != NULL);
@@ -201,15 +205,15 @@ LogL16Decode(TIFF* tif, tidata_t op, tsize_t occ, uint16 s)
assert(sp->tbuflen >= npixels);
tp = (int16*) sp->tbuf;
}
- _TIFFmemset((tdata_t) tp, 0, npixels*sizeof (tp[0]));
+ _TIFFmemset((void*) tp, 0, npixels*sizeof (tp[0]));
bp = (unsigned char*) tif->tif_rawcp;
- cc = tif->tif_rawcc; ddd
- /* get each byte string */
+ cc = tif->tif_rawcc;
+ /* get each byte string */
for (shft = 2*8; (shft -= 8) >= 0; ) {
for (i = 0; i < npixels && cc > 0; )
if (*bp >= 128) { /* run */
- rc = *bp++ + (2-128);
+ rc = *bp++ + (2-128); /* TODO: potential input buffer overrun when decoding corrupt or truncated data */
b = (int16)(*bp++ << shft);
cc -= 2;
while (rc-- && i < npixels)
@@ -220,17 +224,17 @@ LogL16Decode(TIFF* tif, tidata_t op, tsize_t occ, uint16 s)
tp[i++] |= (int16)*bp++ << shft;
}
if (i != npixels) {
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
- "LogL16Decode: Not enough data at row %d (short %d pixels)",
- tif->tif_row, npixels - i);
- tif->tif_rawcp = (tidata_t) bp;
- tif->tif_rawcc = cc; ddd
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Not enough data at row %lud (short %llud pixels)",
+ (unsigned long) tif->tif_row, (unsigned long long) (npixels - i));
+ tif->tif_rawcp = (uint8*) bp;
+ tif->tif_rawcc = cc;
return (0);
}
}
(*sp->tfunc)(sp, op, npixels);
- tif->tif_rawcp = (tidata_t) bp;
- tif->tif_rawcc = cc; ddd
+ tif->tif_rawcp = (uint8*) bp;
+ tif->tif_rawcc = cc;
return (1);
}
@@ -238,10 +242,13 @@ LogL16Decode(TIFF* tif, tidata_t op, tsize_t occ, uint16 s)
* Decode a string of 24-bit pixels.
*/
static int
-LogLuvDecode24(TIFF* tif, tidata_t op, tsize_t occ, uint16 s)
+LogLuvDecode24(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
{
+ static const char module[] = "LogLuvDecode24";
LogLuvState* sp = DecoderState(tif);
- int cc, i, npixels;
+ tmsize_t cc;
+ tmsize_t i;
+ tmsize_t npixels;
unsigned char* bp;
uint32* tp;
@@ -256,20 +263,20 @@ LogLuvDecode24(TIFF* tif, tidata_t op, tsize_t occ, uint16 s)
assert(sp->tbuflen >= npixels);
tp = (uint32 *) sp->tbuf;
}
- /* copy to array of uint32 */
+ /* copy to array of uint32 */
bp = (unsigned char*) tif->tif_rawcp;
- cc = tif->tif_rawcc; ddd
+ cc = tif->tif_rawcc;
for (i = 0; i < npixels && cc > 0; i++) {
tp[i] = bp[0] << 16 | bp[1] << 8 | bp[2];
bp += 3;
cc -= 3;
}
- tif->tif_rawcp = (tidata_t) bp;
- tif->tif_rawcc = cc; ddd
+ tif->tif_rawcp = (uint8*) bp;
+ tif->tif_rawcc = cc;
if (i != npixels) {
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
- "LogLuvDecode24: Not enough data at row %d (short %d pixels)",
- tif->tif_row, npixels - i);
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Not enough data at row %lud (short %llud pixels)",
+ (unsigned long) tif->tif_row, (unsigned long long) (npixels - i));
return (0);
}
(*sp->tfunc)(sp, op, npixels);
@@ -280,14 +287,18 @@ LogLuvDecode24(TIFF* tif, tidata_t op, tsize_t occ, uint16 s)
* Decode a string of 32-bit pixels.
*/
static int
-LogLuvDecode32(TIFF* tif, tidata_t op, tsize_t occ, uint16 s)
+LogLuvDecode32(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
{
+ static const char module[] = "LogLuvDecode32";
LogLuvState* sp;
- int shft, i, npixels;
+ int shft;
+ tmsize_t i;
+ tmsize_t npixels;
unsigned char* bp;
uint32* tp;
uint32 b;
- int cc, rc;
+ tmsize_t cc;
+ int rc;
assert(s == 0);
sp = DecoderState(tif);
@@ -301,17 +312,17 @@ LogLuvDecode32(TIFF* tif, tidata_t op, tsize_t occ, uint16 s)
assert(sp->tbuflen >= npixels);
tp = (uint32*) sp->tbuf;
}
- _TIFFmemset((tdata_t) tp, 0, npixels*sizeof (tp[0]));
+ _TIFFmemset((void*) tp, 0, npixels*sizeof (tp[0]));
bp = (unsigned char*) tif->tif_rawcp;
- cc = tif->tif_rawcc; ddd
- /* get each byte string */
+ cc = tif->tif_rawcc;
+ /* get each byte string */
for (shft = 4*8; (shft -= 8) >= 0; ) {
for (i = 0; i < npixels && cc > 0; )
if (*bp >= 128) { /* run */
rc = *bp++ + (2-128);
b = (uint32)*bp++ << shft;
- cc -= 2;
+ cc -= 2; /* TODO: potential input buffer overrun when decoding corrupt or truncated data */
while (rc-- && i < npixels)
tp[i++] |= b;
} else { /* non-run */
@@ -320,17 +331,17 @@ LogLuvDecode32(TIFF* tif, tidata_t op, tsize_t occ, uint16 s)
tp[i++] |= (uint32)*bp++ << shft;
}
if (i != npixels) {
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
- "LogLuvDecode32: Not enough data at row %d (short %d pixels)",
- tif->tif_row, npixels - i);
- tif->tif_rawcp = (tidata_t) bp;
- tif->tif_rawcc = cc; ddd
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Not enough data at row %lud (short %llud pixels)",
+ (unsigned long) tif->tif_row, (unsigned long long) (npixels - i));
+ tif->tif_rawcp = (uint8*) bp;
+ tif->tif_rawcc = cc;
return (0);
}
}
(*sp->tfunc)(sp, op, npixels);
- tif->tif_rawcp = (tidata_t) bp;
- tif->tif_rawcc = cc; ddd
+ tif->tif_rawcp = (uint8*) bp;
+ tif->tif_rawcc = cc;
return (1);
}
@@ -340,12 +351,12 @@ LogLuvDecode32(TIFF* tif, tidata_t op, tsize_t occ, uint16 s)
* is row by row.
*/
static int
-LogLuvDecodeStrip(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
+LogLuvDecodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
{
- tsize_t rowlen = TIFFScanlineSize(tif); ddd
+ tmsize_t rowlen = TIFFScanlineSize(tif);
assert(cc%rowlen == 0);
- while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s)) ddd
+ while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s))
bp += rowlen, cc -= rowlen;
return (cc == 0);
}
@@ -356,12 +367,12 @@ LogLuvDecodeStrip(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
* is row by row.
*/
static int
-LogLuvDecodeTile(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
+LogLuvDecodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
{
- tsize_t rowlen = TIFFTileRowSize(tif); ddd
+ tmsize_t rowlen = TIFFTileRowSize(tif);
assert(cc%rowlen == 0);
- while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s)) ddd
+ while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s))
bp += rowlen, cc -= rowlen;
return (cc == 0);
}
@@ -370,14 +381,19 @@ LogLuvDecodeTile(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
* Encode a row of 16-bit pixels.
*/
static int
-LogL16Encode(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
+LogL16Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
{
LogLuvState* sp = EncoderState(tif);
- int shft, i, j, npixels;
- tidata_t op;
+ int shft;
+ tmsize_t i;
+ tmsize_t j;
+ tmsize_t npixels;
+ uint8* op;
int16* tp;
int16 b;
- int occ, rc=0, mask, beg;
+ tmsize_t occ;
+ int rc=0, mask;
+ tmsize_t beg;
assert(s == 0);
assert(sp != NULL);
@@ -390,25 +406,25 @@ LogL16Encode(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
assert(sp->tbuflen >= npixels);
(*sp->tfunc)(sp, bp, npixels);
}
- /* compress each byte string */
+ /* compress each byte string */
op = tif->tif_rawcp;
- occ = tif->tif_rawdatasize - tif->tif_rawcc; ddd
+ occ = tif->tif_rawdatasize - tif->tif_rawcc;
for (shft = 2*8; (shft -= 8) >= 0; )
for (i = 0; i < npixels; i += rc) {
if (occ < 4) {
tif->tif_rawcp = op;
- tif->tif_rawcc = tif->tif_rawdatasize - occ; ddd
+ tif->tif_rawcc = tif->tif_rawdatasize - occ;
if (!TIFFFlushData1(tif))
return (-1);
op = tif->tif_rawcp;
- occ = tif->tif_rawdatasize - tif->tif_rawcc; ddd
+ occ = tif->tif_rawdatasize - tif->tif_rawcc;
}
mask = 0xff << shft; /* find next run */
for (beg = i; beg < npixels; beg += rc) {
b = (int16) (tp[beg] & mask);
rc = 1;
while (rc < 127+2 && beg+rc < npixels &&
- (tp[beg+rc] & mask) == b)
+ (tp[beg+rc] & mask) == b)
rc++;
if (rc >= MINRUN)
break; /* long enough */
@@ -417,39 +433,39 @@ LogL16Encode(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
b = (int16) (tp[i] & mask);/*check short run */
j = i+1;
while ((tp[j++] & mask) == b)
- if (j == beg) {
- *op++ = (tidataval_t)(128-2+j-i);
- *op++ = (tidataval_t) (b >> shft);
- occ -= 2;
- i = beg;
- break;
- }
+ if (j == beg) {
+ *op++ = (uint8)(128-2+j-i);
+ *op++ = (uint8)(b >> shft);
+ occ -= 2;
+ i = beg;
+ break;
+ }
}
while (i < beg) { /* write out non-run */
if ((j = beg-i) > 127) j = 127;
if (occ < j+3) {
- tif->tif_rawcp = op;
- tif->tif_rawcc = tif->tif_rawdatasize - occ; ddd
- if (!TIFFFlushData1(tif))
- return (-1);
- op = tif->tif_rawcp;
- occ = tif->tif_rawdatasize - tif->tif_rawcc; ddd
+ tif->tif_rawcp = op;
+ tif->tif_rawcc = tif->tif_rawdatasize - occ;
+ if (!TIFFFlushData1(tif))
+ return (-1);
+ op = tif->tif_rawcp;
+ occ = tif->tif_rawdatasize - tif->tif_rawcc;
}
- *op++ = (tidataval_t) j; occ--;
+ *op++ = (uint8) j; occ--;
while (j--) {
- *op++ = (tidataval_t) (tp[i++] >> shft & 0xff);
+ *op++ = (uint8) (tp[i++] >> shft & 0xff);
occ--;
}
}
if (rc >= MINRUN) { /* write out run */
- *op++ = (tidataval_t) (128-2+rc);
- *op++ = (tidataval_t) (tp[beg] >> shft & 0xff);
+ *op++ = (uint8) (128-2+rc);
+ *op++ = (uint8) (tp[beg] >> shft & 0xff);
occ -= 2;
} else
rc = 0;
}
tif->tif_rawcp = op;
- tif->tif_rawcc = tif->tif_rawdatasize - occ; ddd
+ tif->tif_rawcc = tif->tif_rawdatasize - occ;
return (0);
}
@@ -458,11 +474,13 @@ LogL16Encode(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
* Encode a row of 24-bit pixels.
*/
static int
-LogLuvEncode24(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
+LogLuvEncode24(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
{
LogLuvState* sp = EncoderState(tif);
- int i, npixels, occ;
- tidata_t op;
+ tmsize_t i;
+ tmsize_t npixels;
+ tmsize_t occ;
+ uint8* op;
uint32* tp;
assert(s == 0);
@@ -476,25 +494,25 @@ LogLuvEncode24(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
assert(sp->tbuflen >= npixels);
(*sp->tfunc)(sp, bp, npixels);
}
- /* write out encoded pixels */
+ /* write out encoded pixels */
op = tif->tif_rawcp;
- occ = tif->tif_rawdatasize - tif->tif_rawcc; ddd
+ occ = tif->tif_rawdatasize - tif->tif_rawcc;
for (i = npixels; i--; ) {
if (occ < 3) {
tif->tif_rawcp = op;
- tif->tif_rawcc = tif->tif_rawdatasize - occ; ddd
+ tif->tif_rawcc = tif->tif_rawdatasize - occ;
if (!TIFFFlushData1(tif))
return (-1);
op = tif->tif_rawcp;
- occ = tif->tif_rawdatasize - tif->tif_rawcc; ddd
+ occ = tif->tif_rawdatasize - tif->tif_rawcc;
}
- *op++ = (tidataval_t)(*tp >> 16);
- *op++ = (tidataval_t)(*tp >> 8 & 0xff);
- *op++ = (tidataval_t)(*tp++ & 0xff);
+ *op++ = (uint8)(*tp >> 16);
+ *op++ = (uint8)(*tp >> 8 & 0xff);
+ *op++ = (uint8)(*tp++ & 0xff);
occ -= 3;
}
tif->tif_rawcp = op;
- tif->tif_rawcc = tif->tif_rawdatasize - occ; ddd
+ tif->tif_rawcc = tif->tif_rawdatasize - occ;
return (0);
}
@@ -503,14 +521,19 @@ LogLuvEncode24(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
* Encode a row of 32-bit pixels.
*/
static int
-LogLuvEncode32(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
+LogLuvEncode32(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
{
LogLuvState* sp = EncoderState(tif);
- int shft, i, j, npixels;
- tidata_t op;
+ int shft;
+ tmsize_t i;
+ tmsize_t j;
+ tmsize_t npixels;
+ uint8* op;
uint32* tp;
uint32 b;
- int occ, rc=0, mask, beg;
+ tmsize_t occ;
+ int rc=0, mask;
+ tmsize_t beg;
assert(s == 0);
assert(sp != NULL);
@@ -524,18 +547,18 @@ LogLuvEncode32(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
assert(sp->tbuflen >= npixels);
(*sp->tfunc)(sp, bp, npixels);
}
- /* compress each byte string */
+ /* compress each byte string */
op = tif->tif_rawcp;
- occ = tif->tif_rawdatasize - tif->tif_rawcc; ddd
+ occ = tif->tif_rawdatasize - tif->tif_rawcc;
for (shft = 4*8; (shft -= 8) >= 0; )
for (i = 0; i < npixels; i += rc) {
if (occ < 4) {
tif->tif_rawcp = op;
- tif->tif_rawcc = tif->tif_rawdatasize - occ; ddd
+ tif->tif_rawcc = tif->tif_rawdatasize - occ;
if (!TIFFFlushData1(tif))
return (-1);
op = tif->tif_rawcp;
- occ = tif->tif_rawdatasize - tif->tif_rawcc; ddd
+ occ = tif->tif_rawdatasize - tif->tif_rawcc;
}
mask = 0xff << shft; /* find next run */
for (beg = i; beg < npixels; beg += rc) {
@@ -552,8 +575,8 @@ LogLuvEncode32(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
j = i+1;
while ((tp[j++] & mask) == b)
if (j == beg) {
- *op++ = (tidataval_t)(128-2+j-i);
- *op++ = (tidataval_t)(b >> shft);
+ *op++ = (uint8)(128-2+j-i);
+ *op++ = (uint8)(b >> shft);
occ -= 2;
i = beg;
break;
@@ -563,27 +586,27 @@ LogLuvEncode32(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
if ((j = beg-i) > 127) j = 127;
if (occ < j+3) {
tif->tif_rawcp = op;
- tif->tif_rawcc = tif->tif_rawdatasize - occ; ddd
+ tif->tif_rawcc = tif->tif_rawdatasize - occ;
if (!TIFFFlushData1(tif))
return (-1);
op = tif->tif_rawcp;
- occ = tif->tif_rawdatasize - tif->tif_rawcc; ddd
+ occ = tif->tif_rawdatasize - tif->tif_rawcc;
}
- *op++ = (tidataval_t) j; occ--;
+ *op++ = (uint8) j; occ--;
while (j--) {
- *op++ = (tidataval_t)(tp[i++] >> shft & 0xff);
+ *op++ = (uint8)(tp[i++] >> shft & 0xff);
occ--;
}
}
if (rc >= MINRUN) { /* write out run */
- *op++ = (tidataval_t) (128-2+rc);
- *op++ = (tidataval_t)(tp[beg] >> shft & 0xff);
+ *op++ = (uint8) (128-2+rc);
+ *op++ = (uint8)(tp[beg] >> shft & 0xff);
occ -= 2;
} else
rc = 0;
}
tif->tif_rawcp = op;
- tif->tif_rawcc = tif->tif_rawdatasize - occ; ddd
+ tif->tif_rawcc = tif->tif_rawdatasize - occ;
return (0);
}
@@ -593,12 +616,12 @@ LogLuvEncode32(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
* avoid encoding runs across row boundaries.
*/
static int
-LogLuvEncodeStrip(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
+LogLuvEncodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
{
- tsize_t rowlen = TIFFScanlineSize(tif); ddd
+ tmsize_t rowlen = TIFFScanlineSize(tif);
assert(cc%rowlen == 0);
- while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 0) ddd
+ while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 0)
bp += rowlen, cc -= rowlen;
return (cc == 0);
}
@@ -608,12 +631,12 @@ LogLuvEncodeStrip(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
* avoid encoding runs across row boundaries.
*/
static int
-LogLuvEncodeTile(TIFF* tif, tidata_t bp, tsize_t cc, uint16 s)
+LogLuvEncodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
{
- tsize_t rowlen = TIFFTileRowSize(tif); ddd
+ tmsize_t rowlen = TIFFTileRowSize(tif);
assert(cc%rowlen == 0);
- while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 0) ddd
+ while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 0)
bp += rowlen, cc -= rowlen;
return (cc == 0);
}
@@ -676,7 +699,7 @@ LogL16fromY(double Y, int em) /* get 16-bit LogL from Y */
}
static void
-L16toY(LogLuvState* sp, tidata_t op, int n)
+L16toY(LogLuvState* sp, uint8* op, tmsize_t n)
{
int16* l16 = (int16*) sp->tbuf;
float* yp = (float*) op;
@@ -686,7 +709,7 @@ L16toY(LogLuvState* sp, tidata_t op, int n)
}
static void
-L16toGry(LogLuvState* sp, tidata_t op, int n)
+L16toGry(LogLuvState* sp, uint8* op, tmsize_t n)
{
int16* l16 = (int16*) sp->tbuf;
uint8* gp = (uint8*) op;
@@ -698,7 +721,7 @@ L16toGry(LogLuvState* sp, tidata_t op, int n)
}
static void
-L16fromY(LogLuvState* sp, tidata_t op, int n)
+L16fromY(LogLuvState* sp, uint8* op, tmsize_t n)
{
int16* l16 = (int16*) sp->tbuf;
float* yp = (float*) op;
@@ -760,7 +783,7 @@ oog_encode(double u, double v) /* encode out-of-gamut chroma */
static int oog_table[NANGLES];
static int initialized = 0;
register int i;
-
+
if (!initialized) { /* set up perimeter table */
double eps[NANGLES], ua, va, ang, epsa;
int ui, vi, ustep;
@@ -774,7 +797,7 @@ oog_encode(double u, double v) /* encode out-of-gamut chroma */
for (ui = uv_row[vi].nus-1; ui >= 0; ui -= ustep) {
ua = uv_row[vi].ustart + (ui+.5)*UV_SQSIZ;
ang = uv2ang(ua, va);
- i = (int) ang;
+ i = (int) ang;
epsa = fabs(ang - (i+.5));
if (epsa < eps[i]) {
oog_table[i] = uv_row[vi].ncum + ui;
@@ -916,9 +939,9 @@ LogLuv24fromXYZ(float XYZ[3], int em)
}
static void
-Luv24toXYZ(LogLuvState* sp, tidata_t op, int n)
+Luv24toXYZ(LogLuvState* sp, uint8* op, tmsize_t n)
{
- uint32* luv = (uint32*) sp->tbuf;
+ uint32* luv = (uint32*) sp->tbuf;
float* xyz = (float*) op;
while (n-- > 0) {
@@ -929,9 +952,9 @@ Luv24toXYZ(LogLuvState* sp, tidata_t op, int n)
}
static void
-Luv24toLuv48(LogLuvState* sp, tidata_t op, int n)
+Luv24toLuv48(LogLuvState* sp, uint8* op, tmsize_t n)
{
- uint32* luv = (uint32*) sp->tbuf;
+ uint32* luv = (uint32*) sp->tbuf;
int16* luv3 = (int16*) op;
while (n-- > 0) {
@@ -949,9 +972,9 @@ Luv24toLuv48(LogLuvState* sp, tidata_t op, int n)
}
static void
-Luv24toRGB(LogLuvState* sp, tidata_t op, int n)
+Luv24toRGB(LogLuvState* sp, uint8* op, tmsize_t n)
{
- uint32* luv = (uint32*) sp->tbuf;
+ uint32* luv = (uint32*) sp->tbuf;
uint8* rgb = (uint8*) op;
while (n-- > 0) {
@@ -964,9 +987,9 @@ Luv24toRGB(LogLuvState* sp, tidata_t op, int n)
}
static void
-Luv24fromXYZ(LogLuvState* sp, tidata_t op, int n)
+Luv24fromXYZ(LogLuvState* sp, uint8* op, tmsize_t n)
{
- uint32* luv = (uint32*) sp->tbuf;
+ uint32* luv = (uint32*) sp->tbuf;
float* xyz = (float*) op;
while (n-- > 0) {
@@ -976,9 +999,9 @@ Luv24fromXYZ(LogLuvState* sp, tidata_t op, int n)
}
static void
-Luv24fromLuv48(LogLuvState* sp, tidata_t op, int n)
+Luv24fromLuv48(LogLuvState* sp, uint8* op, tmsize_t n)
{
- uint32* luv = (uint32*) sp->tbuf;
+ uint32* luv = (uint32*) sp->tbuf;
int16* luv3 = (int16*) op;
while (n-- > 0) {
@@ -1057,9 +1080,9 @@ LogLuv32fromXYZ(float XYZ[3], int em)
}
static void
-Luv32toXYZ(LogLuvState* sp, tidata_t op, int n)
+Luv32toXYZ(LogLuvState* sp, uint8* op, tmsize_t n)
{
- uint32* luv = (uint32*) sp->tbuf;
+ uint32* luv = (uint32*) sp->tbuf;
float* xyz = (float*) op;
while (n-- > 0) {
@@ -1069,9 +1092,9 @@ Luv32toXYZ(LogLuvState* sp, tidata_t op, int n)
}
static void
-Luv32toLuv48(LogLuvState* sp, tidata_t op, int n)
+Luv32toLuv48(LogLuvState* sp, uint8* op, tmsize_t n)
{
- uint32* luv = (uint32*) sp->tbuf;
+ uint32* luv = (uint32*) sp->tbuf;
int16* luv3 = (int16*) op;
while (n-- > 0) {
@@ -1087,9 +1110,9 @@ Luv32toLuv48(LogLuvState* sp, tidata_t op, int n)
}
static void
-Luv32toRGB(LogLuvState* sp, tidata_t op, int n)
+Luv32toRGB(LogLuvState* sp, uint8* op, tmsize_t n)
{
- uint32* luv = (uint32*) sp->tbuf;
+ uint32* luv = (uint32*) sp->tbuf;
uint8* rgb = (uint8*) op;
while (n-- > 0) {
@@ -1102,9 +1125,9 @@ Luv32toRGB(LogLuvState* sp, tidata_t op, int n)
}
static void
-Luv32fromXYZ(LogLuvState* sp, tidata_t op, int n)
+Luv32fromXYZ(LogLuvState* sp, uint8* op, tmsize_t n)
{
- uint32* luv = (uint32*) sp->tbuf;
+ uint32* luv = (uint32*) sp->tbuf;
float* xyz = (float*) op;
while (n-- > 0) {
@@ -1114,7 +1137,7 @@ Luv32fromXYZ(LogLuvState* sp, tidata_t op, int n)
}
static void
-Luv32fromLuv48(LogLuvState* sp, tidata_t op, int n)
+Luv32fromLuv48(LogLuvState* sp, uint8* op, tmsize_t n)
{
uint32* luv = (uint32*) sp->tbuf;
int16* luv3 = (int16*) op;
@@ -1137,7 +1160,7 @@ Luv32fromLuv48(LogLuvState* sp, tidata_t op, int n)
}
static void
-_logLuvNop(LogLuvState* sp, tidata_t op, int n)
+_logLuvNop(LogLuvState* sp, uint8* op, tmsize_t n)
{
(void) sp; (void) op; (void) n;
}
@@ -1161,10 +1184,10 @@ LogL16GuessDataFmt(TIFFDirectory *td)
return (SGILOGDATAFMT_UNKNOWN);
}
-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;
@@ -1175,9 +1198,9 @@ multiply(size_t m1, size_t m2)
static int
LogL16InitState(TIFF* tif)
{
+ static const char module[] = "LogL16InitState";
TIFFDirectory *td = &tif->tif_dir;
LogLuvState* sp = DecoderState(tif);
- static const char module[] = "LogL16InitState";
assert(sp != NULL);
assert(td->td_photometric == PHOTOMETRIC_LOGL);
@@ -1196,15 +1219,14 @@ LogL16InitState(TIFF* tif)
sp->pixel_size = sizeof (uint8);
break;
default:
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
+ TIFFErrorExt(tif->tif_clientdata, module,
"No support for converting user data format to LogL");
return (0);
}
- sp->tbuflen = multiply(td->td_imagewidth, td->td_rowsperstrip);
- if (multiply(sp->tbuflen, sizeof (int16)) == 0 ||
- (sp->tbuf = (tidata_t*) _TIFFmalloc(sp->tbuflen * sizeof (int16))) == NULL) {
- TIFFErrorExt(tif->tif_clientdata, module, "%s: No space for SGILog translation buffer",
- tif->tif_name);
+ sp->tbuflen = multiply_ms(td->td_imagewidth, td->td_rowsperstrip);
+ if (multiply_ms(sp->tbuflen, sizeof (int16)) == 0 ||
+ (sp->tbuf = (uint8*) _TIFFmalloc(sp->tbuflen * sizeof (int16))) == NULL) {
+ TIFFErrorExt(tif->tif_clientdata, module, "No space for SGILog translation buffer");
return (0);
}
return (1);
@@ -1265,9 +1287,9 @@ LogLuvGuessDataFmt(TIFFDirectory *td)
static int
LogLuvInitState(TIFF* tif)
{
+ static const char module[] = "LogLuvInitState";
TIFFDirectory* td = &tif->tif_dir;
LogLuvState* sp = DecoderState(tif);
- static const char module[] = "LogLuvInitState";
assert(sp != NULL);
assert(td->td_photometric == PHOTOMETRIC_LOGLUV);
@@ -1294,15 +1316,14 @@ LogLuvInitState(TIFF* tif)
sp->pixel_size = 3*sizeof (uint8);
break;
default:
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
+ TIFFErrorExt(tif->tif_clientdata, module,
"No support for converting user data format to LogLuv");
return (0);
}
- sp->tbuflen = multiply(td->td_imagewidth, td->td_rowsperstrip);
- if (multiply(sp->tbuflen, sizeof (uint32)) == 0 ||
- (sp->tbuf = (tidata_t*) _TIFFmalloc(sp->tbuflen * sizeof (uint32))) == NULL) {
- TIFFErrorExt(tif->tif_clientdata, module, "%s: No space for SGILog translation buffer",
- tif->tif_name);
+ sp->tbuflen = multiply_ms(td->td_imagewidth, td->td_rowsperstrip);
+ if (multiply_ms(sp->tbuflen, sizeof (uint32)) == 0 ||
+ (sp->tbuf = (uint8*) _TIFFmalloc(sp->tbuflen * sizeof (uint32))) == NULL) {
+ TIFFErrorExt(tif->tif_clientdata, module, "No space for SGILog translation buffer");
return (0);
}
return (1);
@@ -1311,29 +1332,30 @@ LogLuvInitState(TIFF* tif)
static int
LogLuvSetupDecode(TIFF* tif)
{
+ static const char module[] = "LogLuvSetupDecode";
LogLuvState* sp = DecoderState(tif);
TIFFDirectory* td = &tif->tif_dir;
- tif->tif_postdecode = _TIFFNoPostDecode;
+ tif->tif_postdecode = _TIFFNoPostDecode;
switch (td->td_photometric) {
case PHOTOMETRIC_LOGLUV:
if (!LogLuvInitState(tif))
break;
if (td->td_compression == COMPRESSION_SGILOG24) {
- tif->tif_decoderow = LogLuvDecode24; ddd
+ tif->tif_decoderow = LogLuvDecode24;
switch (sp->user_datafmt) {
case SGILOGDATAFMT_FLOAT:
- sp->tfunc = Luv24toXYZ;
+ sp->tfunc = Luv24toXYZ;
break;
case SGILOGDATAFMT_16BIT:
- sp->tfunc = Luv24toLuv48;
+ sp->tfunc = Luv24toLuv48;
break;
case SGILOGDATAFMT_8BIT:
sp->tfunc = Luv24toRGB;
break;
}
} else {
- tif->tif_decoderow = LogLuvDecode32; ddd
+ tif->tif_decoderow = LogLuvDecode32;
switch (sp->user_datafmt) {
case SGILOGDATAFMT_FLOAT:
sp->tfunc = Luv32toXYZ;
@@ -1350,7 +1372,7 @@ LogLuvSetupDecode(TIFF* tif)
case PHOTOMETRIC_LOGL:
if (!LogL16InitState(tif))
break;
- tif->tif_decoderow = LogL16Decode; ddd
+ tif->tif_decoderow = LogL16Decode;
switch (sp->user_datafmt) {
case SGILOGDATAFMT_FLOAT:
sp->tfunc = L16toY;
@@ -1361,8 +1383,8 @@ LogLuvSetupDecode(TIFF* tif)
}
return (1);
default:
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
- "Inappropriate photometric interpretation %d for SGILog compression; %s",
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Inappropriate photometric interpretation %d for SGILog compression; %s",
td->td_photometric, "must be either LogLUV or LogL");
break;
}
@@ -1372,6 +1394,7 @@ LogLuvSetupDecode(TIFF* tif)
static int
LogLuvSetupEncode(TIFF* tif)
{
+ static const char module[] = "LogLuvSetupEncode";
LogLuvState* sp = EncoderState(tif);
TIFFDirectory* td = &tif->tif_dir;
@@ -1380,13 +1403,13 @@ LogLuvSetupEncode(TIFF* tif)
if (!LogLuvInitState(tif))
break;
if (td->td_compression == COMPRESSION_SGILOG24) {
- tif->tif_encoderow = LogLuvEncode24; ddd
+ tif->tif_encoderow = LogLuvEncode24;
switch (sp->user_datafmt) {
case SGILOGDATAFMT_FLOAT:
sp->tfunc = Luv24fromXYZ;
break;
case SGILOGDATAFMT_16BIT:
- sp->tfunc = Luv24fromLuv48;
+ sp->tfunc = Luv24fromLuv48;
break;
case SGILOGDATAFMT_RAW:
break;
@@ -1394,13 +1417,13 @@ LogLuvSetupEncode(TIFF* tif)
goto notsupported;
}
} else {
- tif->tif_encoderow = LogLuvEncode32; ddd
+ tif->tif_encoderow = LogLuvEncode32;
switch (sp->user_datafmt) {
case SGILOGDATAFMT_FLOAT:
- sp->tfunc = Luv32fromXYZ;
+ sp->tfunc = Luv32fromXYZ;
break;
case SGILOGDATAFMT_16BIT:
- sp->tfunc = Luv32fromLuv48;
+ sp->tfunc = Luv32fromLuv48;
break;
case SGILOGDATAFMT_RAW:
break;
@@ -1412,7 +1435,7 @@ LogLuvSetupEncode(TIFF* tif)
case PHOTOMETRIC_LOGL:
if (!LogL16InitState(tif))
break;
- tif->tif_encoderow = LogL16Encode; ddd
+ tif->tif_encoderow = LogL16Encode;
switch (sp->user_datafmt) {
case SGILOGDATAFMT_FLOAT:
sp->tfunc = L16fromY;
@@ -1424,14 +1447,14 @@ LogLuvSetupEncode(TIFF* tif)
}
break;
default:
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
- "Inappropriate photometric interpretation %d for SGILog compression; %s",
- td->td_photometric, "must be either LogLUV or LogL");
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Inappropriate photometric interpretation %d for SGILog compression; %s",
+ td->td_photometric, "must be either LogLUV or LogL");
break;
}
return (1);
notsupported:
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
+ TIFFErrorExt(tif->tif_clientdata, module,
"SGILog compression supported only for %s, or raw data",
td->td_photometric == PHOTOMETRIC_LOGL ? "Y, L" : "XYZ, Luv");
return (0);
@@ -1474,8 +1497,9 @@ LogLuvCleanup(TIFF* tif)
}
static int
-LogLuvVSetField(TIFF* tif, ttag_t tag, va_list ap)
+LogLuvVSetField(TIFF* tif, uint32 tag, va_list ap)
{
+ static const char module[] = "LogLuvVSetField";
LogLuvState* sp = DecoderState(tif);
int bps, fmt;
@@ -1513,16 +1537,16 @@ LogLuvVSetField(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; ddd
- tif->tif_scanlinesize = TIFFScanlineSize(tif); ddd
+ tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tmsize_t) -1;
+ tif->tif_scanlinesize = TIFFScanlineSize(tif);
return (1);
case TIFFTAG_SGILOGENCODE:
sp->encode_meth = va_arg(ap, int);
if (sp->encode_meth != SGILOGENCODE_NODITHER &&
- sp->encode_meth != SGILOGENCODE_RANDITHER) {
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
- "Unknown encoding %d for LogLuv compression",
- sp->encode_meth);
+ sp->encode_meth != SGILOGENCODE_RANDITHER) {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Unknown encoding %d for LogLuv compression",
+ sp->encode_meth);
return (0);
}
return (1);
@@ -1532,7 +1556,7 @@ LogLuvVSetField(TIFF* tif, ttag_t tag, va_list ap)
}
static int
-LogLuvVGetField(TIFF* tif, ttag_t tag, va_list ap)
+LogLuvVGetField(TIFF* tif, uint32 tag, va_list ap)
{
LogLuvState *sp = (LogLuvState *)tif->tif_data;
@@ -1564,23 +1588,23 @@ TIFFInitSGILog(TIFF* tif, int scheme)
* Merge codec-specific tag information.
*/
if (!_TIFFMergeFieldInfo(tif, LogLuvFieldInfo,
- TIFFArrayCount(LogLuvFieldInfo))) {
+ TIFFArrayCount(LogLuvFieldInfo))) {
TIFFErrorExt(tif->tif_clientdata, module,
- "Merging SGILog codec-specific tags failed");
+ "Merging SGILog codec-specific tags failed");
return 0;
}
/*
* Allocate state block so tag methods have storage to record values.
*/
- tif->tif_data = (tidata_t) _TIFFmalloc(sizeof (LogLuvState));
+ tif->tif_data = (uint8*) _TIFFmalloc(sizeof (LogLuvState));
if (tif->tif_data == NULL)
goto bad;
sp = (LogLuvState*) tif->tif_data;
- _TIFFmemset((tdata_t)sp, 0, sizeof (*sp));
+ _TIFFmemset((void*)sp, 0, sizeof (*sp));
sp->user_datafmt = SGILOGDATAFMT_UNKNOWN;
sp->encode_meth = (scheme == COMPRESSION_SGILOG24) ?
- SGILOGENCODE_RANDITHER : SGILOGENCODE_NODITHER;
+ SGILOGENCODE_RANDITHER : SGILOGENCODE_NODITHER;
sp->tfunc = _logLuvNop;
/*
@@ -1589,15 +1613,15 @@ TIFFInitSGILog(TIFF* tif, int scheme)
* in at setup time.
*/
tif->tif_setupdecode = LogLuvSetupDecode;
- tif->tif_decodestrip = LogLuvDecodeStrip; ddd
- tif->tif_decodetile = LogLuvDecodeTile; ddd
+ tif->tif_decodestrip = LogLuvDecodeStrip;
+ tif->tif_decodetile = LogLuvDecodeTile;
tif->tif_setupencode = LogLuvSetupEncode;
- tif->tif_encodestrip = LogLuvEncodeStrip; ddd
- tif->tif_encodetile = LogLuvEncodeTile; ddd
+ tif->tif_encodestrip = LogLuvEncodeStrip;
+ tif->tif_encodetile = LogLuvEncodeTile;
tif->tif_close = LogLuvClose;
tif->tif_cleanup = LogLuvCleanup;
- /*
+ /*
* Override parent get/set field methods.
*/
sp->vgetparent = tif->tif_tagmethods.vgetfield;