31#ifdef PIXARLOG_SUPPORT
109#define CODE_MASK 0x7ff
140#define REPEAT(n, op) \
172 memcpy(&v, cp,
sizeof(v));
189 memcpy(cp, &v,
sizeof(v));
206 memcpy(&v, cp,
sizeof(v));
223 memcpy(cp, &v,
sizeof(v));
249 uint8_t *op,
float *ToLinearF)
251 unsigned int cr, cg, cb, ca, mask;
252 float t0, t1, t2, t3;
259 t0 = ToLinearF[cr = (wp[0] & mask)];
260 t1 = ToLinearF[cg = (wp[1] & mask)];
261 t2 = ToLinearF[cb = (wp[2] & mask)];
269 op += 3 *
sizeof(float);
271 t0 = ToLinearF[(cr += wp[0]) & mask];
272 t1 = ToLinearF[(cg += wp[1]) & mask];
273 t2 = ToLinearF[(cb += wp[2]) & mask];
279 else if (stride == 4)
281 t0 = ToLinearF[cr = (wp[0] & mask)];
282 t1 = ToLinearF[cg = (wp[1] & mask)];
283 t2 = ToLinearF[cb = (wp[2] & mask)];
284 t3 = ToLinearF[ca = (wp[3] & mask)];
293 op += 4 *
sizeof(float);
295 t0 = ToLinearF[(cr += wp[0]) & mask];
296 t1 = ToLinearF[(cg += wp[1]) & mask];
297 t2 = ToLinearF[(cb += wp[2]) & mask];
298 t3 = ToLinearF[(ca += wp[3]) & mask];
309 wp++; op +=
sizeof(float))
313 REPEAT(stride, *wp = (uint16_t)(*wp + wp[-stride]);
315 ToLinearF[*wp & mask]);
316 wp++; op +=
sizeof(float))
347 uint8_t *op,
float *ToLinearF)
349 unsigned int cr, cg, cb, ca, mask;
350 float t0, t1, t2, t3;
352#define SCALE12 2048.0f
353#define CLAMP12(t) (((t) < 3071) ? (int16_t)(uint16_t)(t) : (int16_t)3071)
360 t0 = ToLinearF[cr = (wp[0] & mask)] *
SCALE12;
361 t1 = ToLinearF[cg = (wp[1] & mask)] *
SCALE12;
362 t2 = ToLinearF[cb = (wp[2] & mask)] *
SCALE12;
372 op += 3 *
sizeof(uint16_t);
374 t0 = ToLinearF[(cr += wp[0]) & mask] *
SCALE12;
375 t1 = ToLinearF[(cg += wp[1]) & mask] *
SCALE12;
376 t2 = ToLinearF[(cb += wp[2]) & mask] *
SCALE12;
384 else if (stride == 4)
386 t0 = ToLinearF[cr = (wp[0] & mask)] *
SCALE12;
387 t1 = ToLinearF[cg = (wp[1] & mask)] *
SCALE12;
388 t2 = ToLinearF[cb = (wp[2] & mask)] *
SCALE12;
389 t3 = ToLinearF[ca = (wp[3] & mask)] *
SCALE12;
401 op += 4 *
sizeof(uint16_t);
403 t0 = ToLinearF[(cr += wp[0]) & mask] *
SCALE12;
404 t1 = ToLinearF[(cg += wp[1]) & mask] *
SCALE12;
405 t2 = ToLinearF[(cb += wp[2]) & mask] *
SCALE12;
406 t3 = ToLinearF[(ca += wp[3]) & mask] *
SCALE12;
420 wp++; op +=
sizeof(uint16_t))
425 stride, *wp = (uint16_t)(*wp + wp[-stride]);
426 t0 = ToLinearF[*wp & mask] *
SCALE12;
428 wp++; op +=
sizeof(uint16_t))
459 uint8_t *op, uint16_t *ToLinear16)
461 unsigned int cr, cg, cb, ca, mask;
470 ToLinear16[cg = (wp[1] & mask)]);
472 ToLinear16[cb = (wp[2] & mask)]);
477 op += 3 *
sizeof(uint16_t);
480 op, ToLinear16[(cr += wp[0]) & mask]);
482 op +
sizeof(uint16_t), ToLinear16[(cg += wp[1]) & mask]);
484 op + 2 *
sizeof(uint16_t),
485 ToLinear16[(cb += wp[2]) & mask]);
488 else if (stride == 4)
492 ToLinear16[cg = (wp[1] & mask)]);
494 ToLinear16[cb = (wp[2] & mask)]);
496 ToLinear16[ca = (wp[3] & mask)]);
501 op += 4 *
sizeof(uint16_t);
504 op, ToLinear16[(cr += wp[0]) & mask]);
506 op +
sizeof(uint16_t), ToLinear16[(cg += wp[1]) & mask]);
508 op + 2 *
sizeof(uint16_t),
509 ToLinear16[(cb += wp[2]) & mask]);
511 op + 3 *
sizeof(uint16_t),
512 ToLinear16[(ca += wp[3]) & mask]);
519 wp++; op +=
sizeof(uint16_t))
524 stride, *wp = (uint16_t)(*wp + wp[-stride]);
526 wp++; op +=
sizeof(uint16_t))
563 unsigned int cr, cg, cb, ca, mask;
580 op += 3 *
sizeof(uint16_t);
583 op, (uint16_t)((cr += wp[0]) & mask));
585 op +
sizeof(uint16_t), (uint16_t)((cg += wp[1]) & mask));
587 op + 2 *
sizeof(uint16_t),
588 (uint16_t)((cb += wp[2]) & mask));
591 else if (stride == 4)
605 op += 4 *
sizeof(uint16_t);
608 op, (uint16_t)((cr += wp[0]) & mask));
610 op +
sizeof(uint16_t), (uint16_t)((cg += wp[1]) & mask));
612 op + 2 *
sizeof(uint16_t),
613 (uint16_t)((cb += wp[2]) & mask));
615 op + 3 *
sizeof(uint16_t),
616 (uint16_t)((ca += wp[3]) & mask));
623 wp++; op +=
sizeof(uint16_t))
628 stride, *wp = (uint16_t)(*wp + wp[-stride]);
630 wp++; op +=
sizeof(uint16_t))
660 unsigned char *op,
unsigned char *ToLinear8)
662 unsigned int cr, cg, cb, ca, mask;
669 op[0] = ToLinear8[cr = (wp[0] & mask)];
670 op[1] = ToLinear8[cg = (wp[1] & mask)];
671 op[2] = ToLinear8[cb = (wp[2] & mask)];
678 op[0] = ToLinear8[(cr += wp[0]) & mask];
679 op[1] = ToLinear8[(cg += wp[1]) & mask];
680 op[2] = ToLinear8[(cb += wp[2]) & mask];
683 else if (stride == 4)
685 op[0] = ToLinear8[cr = (wp[0] & mask)];
686 op[1] = ToLinear8[cg = (wp[1] & mask)];
687 op[2] = ToLinear8[cb = (wp[2] & mask)];
688 op[3] = ToLinear8[ca = (wp[3] & mask)];
695 op[0] = ToLinear8[(cr += wp[0]) & mask];
696 op[1] = ToLinear8[(cg += wp[1]) & mask];
697 op[2] = ToLinear8[(cb += wp[2]) & mask];
698 op[3] = ToLinear8[(ca += wp[3]) & mask];
703 REPEAT(stride, *op = ToLinear8[*wp & mask]; wp++; op++)
707 REPEAT(stride, *wp = (uint16_t)(*wp + wp[-stride]);
708 *op = ToLinear8[*wp & mask]; wp++; op++)
741 unsigned char *ToLinear8)
743 unsigned int cr, cg, cb, ca, mask;
744 unsigned char t0, t1, t2, t3;
752 t1 = ToLinear8[cb = (wp[2] & mask)];
753 t2 = ToLinear8[cg = (wp[1] & mask)];
754 t3 = ToLinear8[cr = (wp[0] & mask)];
765 t1 = ToLinear8[(cb += wp[2]) & mask];
766 t2 = ToLinear8[(cg += wp[1]) & mask];
767 t3 = ToLinear8[(cr += wp[0]) & mask];
773 else if (stride == 4)
775 t0 = ToLinear8[ca = (wp[3] & mask)];
776 t1 = ToLinear8[cb = (wp[2] & mask)];
777 t2 = ToLinear8[cg = (wp[1] & mask)];
778 t3 = ToLinear8[cr = (wp[0] & mask)];
789 t0 = ToLinear8[(ca += wp[3]) & mask];
790 t1 = ToLinear8[(cb += wp[2]) & mask];
791 t2 = ToLinear8[(cg += wp[1]) & mask];
792 t3 = ToLinear8[(cr += wp[0]) & mask];
801 REPEAT(stride, *op = ToLinear8[*wp & mask]; wp++; op++)
805 REPEAT(stride, *wp = (uint16_t)(*wp + wp[-stride]);
806 *op = ToLinear8[*wp & mask]; wp++; op++)
848#define PLSTATE_INIT 1
906 double b, c, linstep, v;
908 uint16_t *ToLinear16;
909 unsigned char *ToLinear8;
915 nlin = (int)(1. / c);
918 linstep = b * c * exp(1.);
920 LogK1 = (float)(1. / c);
921 LogK2 = (float)(1. / b);
922 lt2size = (int)(2. / linstep) + 1;
924 tif, (
tmsize_t)((size_t)lt2size *
sizeof(uint16_t)));
925 From14 = (uint16_t *)
_TIFFmallocExt(tif, 16384 *
sizeof(uint16_t));
931 if (FromLT2 == NULL || From14 == NULL || From8 == NULL ||
932 ToLinearF == NULL || ToLinear16 == NULL || ToLinear8 == NULL)
957 for (i = 0; i < nlin; i++)
960 ToLinearF[j++] = (float)v;
963 for (i = nlin; i <
TSIZE; i++)
964 ToLinearF[j++] = (
float)(b * exp(c * i));
966 ToLinearF[2048] = ToLinearF[2047];
970 v = (double)ToLinearF[i] * 65535.0 + 0.5;
971 ToLinear16[i] = (v > 65535.0) ? 65535 : (uint16_t)v;
972 v = (double)ToLinearF[i] * 255.0 + 0.5;
973 ToLinear8[i] = (v > 255.0) ? 255 : (
unsigned char)v;
977 for (i = 0; i < lt2size; i++)
979 if ((i * linstep) * (i * linstep) >
980 (
double)ToLinearF[j] * (double)ToLinearF[j + 1])
982 FromLT2[i] = (uint16_t)j;
991 for (i = 0; i < 16384; i++)
993 while ((i / 16383.) * (i / 16383.) >
994 (
double)ToLinearF[j] * (double)ToLinearF[j + 1])
996 From14[i] = (uint16_t)j;
1000 for (i = 0; i < 256; i++)
1002 while ((i / 255.) * (i / 255.) >
1003 (
double)ToLinearF[j] * (double)ToLinearF[j + 1])
1005 From8[i] = (uint16_t)j;
1008 Fltsize = (float)(lt2size / 2);
1020#define PixarLogDecoderState(tif) ((PixarLogState *)(tif)->tif_data)
1021#define PixarLogEncoderState(tif) ((PixarLogState *)(tif)->tif_data)
1026#define PIXARLOGDATAFMT_UNKNOWN -1
1111 assert(m1 >= 0 && m2 >= 0);
1113 if (m1 == 0 || m2 == 0)
1156 static const char module[] = "PixarLogSetupDecode";
1160 uint32_t segment_width, segment_height;
1172 segment_width = td->td_tilewidth;
1173 segment_height = td->td_tilelength;
1177 segment_width = td->td_imagewidth;
1178 segment_height = td->td_rowsperstrip;
1179 if (segment_height > td->td_imagelength)
1180 segment_height = td->td_imagelength;
1196 tbuf_size =
multiply_ms(tif, module, tbuf_size, segment_height);
1207 if (sp->
tbuf == NULL)
1218 "PixarLog compression can't handle bits depth/data "
1219 "format combination (depth: %" PRIu16
")",
1220 td->td_bitspersample);
1224 if (inflateInit(&sp->
stream) != Z_OK)
1258 static const char module[] = "PixarLogPreDecode";
1264 assert(
sizeof(sp->stream.avail_in) == 4);
1268 sp->stream.avail_in = (uInt)tif->
tif_rawcc;
1271 TIFFErrorExtR(tif, module,
"ZLib cannot deal with buffers this size");
1274 return (inflateReset(&sp->stream) == Z_OK);
1304 static const char module[] = "PixarLogDecode";
1312 uint8_t *op_start = op;
1317 nsamples = (
tmsize_t)((uint64_t)occ /
1333 "%" PRIu16
" bit input not supported in PixarLog",
1334 td->td_bitspersample);
1335 memset(op, 0, (
size_t)occ);
1339 row_width =
isTiled(tif) ? td->td_tilewidth : td->td_imagewidth;
1357 "Output buffer too small for PixarLog ABGR data");
1358 memset(op, 0, (
size_t)occ);
1370 "Fractional scanline not supported for PixarLog ABGR data");
1371 memset(op, 0, (
size_t)occ);
1380 max_rows = occ / required;
1381 max_nsamples = max_rows * llen;
1383 if (nsamples > max_nsamples)
1386 "Output buffer too small for PixarLog ABGR data");
1387 memset(op, 0, (
size_t)occ);
1398 sp->
stream.next_out = (
unsigned char *)sp->
tbuf;
1399 assert(
sizeof(sp->
stream.avail_out) == 4);
1403 sp->
stream.avail_out = (uInt)((
unsigned long)nsamples *
sizeof(uint16_t));
1404 if (sp->
stream.avail_out != (
unsigned long)nsamples *
sizeof(uint16_t))
1406 TIFFErrorExtR(tif, module,
"ZLib cannot deal with buffers this size");
1407 memset(op, 0, (
size_t)occ);
1413 TIFFErrorExtR(tif, module,
"sp->stream.avail_out > sp->tbuf_size");
1414 memset(op, 0, (
size_t)occ);
1419 int state = inflate(&sp->
stream, Z_PARTIAL_FLUSH);
1420 if (state == Z_STREAM_END)
1424 if (state == Z_DATA_ERROR)
1427 "Decoding error at scanline %" PRIu32
", %s",
1430 memset(op, 0, (
size_t)occ);
1437 memset(op, 0, (
size_t)occ);
1440 }
while (sp->
stream.avail_out > 0);
1443 if (sp->
stream.avail_out != 0)
1446 "Not enough data at scanline %" PRIu32
1447 " (short %u bytes)",
1449 memset(op, 0, (
size_t)occ);
1466 if (nsamples % llen)
1470 " is not a multiple of sample count, "
1473 nsamples -= nsamples % llen;
1476 for (i = 0; i < nsamples; i += llen, up += llen)
1482 op += (
unsigned long)llen *
sizeof(
float);
1487 op += (
unsigned long)llen *
sizeof(uint16_t);
1491 op += (
unsigned long)llen *
sizeof(int16_t);
1495 op += (
unsigned long)llen *
sizeof(uint16_t);
1500 op += (
unsigned long)llen *
sizeof(
unsigned char);
1509 op += (
unsigned long)row_width * 4;
1511 op += (
unsigned long)llen *
sizeof(
unsigned char);
1514 TIFFErrorExtR(tif, module,
"Unsupported bits/sample: %" PRIu16,
1515 td->td_bitspersample);
1516 memset(op, 0, (
size_t)occ);
1522 if (op - op_start < occ)
1523 memset(op, 0, (
size_t)(occ - (op - op_start)));
1545 static const char module[] = "PixarLogSetupEncode";
1564 "PixarLog compression can't handle %" PRIu16
1565 " bit linear encodings",
1566 td->td_bitspersample);
1602 static const char module[] = "PixarLogPreEncode";
1608 assert(
sizeof(sp->stream.avail_out) == 4);
1615 TIFFErrorExtR(tif, module,
"ZLib cannot deal with buffers this size");
1618 return (deflateReset(&sp->stream) == Z_OK);
1646 uint16_t *wp, uint16_t *FromLT2)
1648 int32_t r1, g1, b1, a1, r2, g2, b2, a2, mask;
1652 ((v < (float)0.) ? 0 \
1653 : (v < (float)2.) ? FromLT2[(int)(v * fltsize)] \
1654 : (v > (float)24.2) \
1656 : (double)LogK1 * log((double)v * (double)LogK2) + 0.5)
1664 g2 = wp[1] = (uint16_t)
CLAMP(
1666 b2 = wp[2] = (uint16_t)
CLAMP(
1673 ip += 3 *
sizeof(float);
1675 wp[0] = (uint16_t)((r1 - r2) & mask);
1677 g1 = (int32_t)
CLAMP(
1679 wp[1] = (uint16_t)((g1 - g2) & mask);
1681 b1 = (int32_t)
CLAMP(
1683 wp[2] = (uint16_t)((b1 - b2) & mask);
1687 else if (stride == 4)
1690 g2 = wp[1] = (uint16_t)
CLAMP(
1692 b2 = wp[2] = (uint16_t)
CLAMP(
1694 a2 = wp[3] = (uint16_t)
CLAMP(
1701 ip += 4 *
sizeof(float);
1703 wp[0] = (uint16_t)((r1 - r2) & mask);
1705 g1 = (int32_t)
CLAMP(
1707 wp[1] = (uint16_t)((g1 - g2) & mask);
1709 b1 = (int32_t)
CLAMP(
1711 wp[2] = (uint16_t)((b1 - b2) & mask);
1713 a1 = (int32_t)
CLAMP(
1715 wp[3] = (uint16_t)((a1 - a2) & mask);
1723 wp++; ip +=
sizeof(float))
1730 (uint16_t)(((int32_t)
CLAMP(
1738 wp++; ip +=
sizeof(float))
1769 unsigned short *wp, uint16_t *From14)
1771 int r1, g1, b1, a1, r2, g2, b2, a2, mask;
1775#define CLAMP(v) From14[(v) >> 2]
1792 ip += 3 *
sizeof(uint16_t);
1794 wp[0] = (uint16_t)((r1 - r2) & mask);
1798 wp[1] = (uint16_t)((g1 - g2) & mask);
1802 wp[2] = (uint16_t)((b1 - b2) & mask);
1806 else if (stride == 4)
1820 ip += 4 *
sizeof(uint16_t);
1822 wp[0] = (uint16_t)((r1 - r2) & mask);
1826 wp[1] = (uint16_t)((g1 - g2) & mask);
1830 wp[2] = (uint16_t)((b1 - b2) & mask);
1834 wp[3] = (uint16_t)((a1 - a2) & mask);
1841 wp++; ip +=
sizeof(uint16_t))
1853 wp++; ip +=
sizeof(uint16_t))
1879 unsigned short *wp, uint16_t *From8)
1881 int r1, g1, b1, a1, r2, g2, b2, a2, mask;
1884#define CLAMP(v) (From8[(v)])
1891 r2 = wp[0] =
CLAMP(ip[0]);
1892 g2 = wp[1] =
CLAMP(ip[1]);
1893 b2 = wp[2] =
CLAMP(ip[2]);
1899 wp[3] = (uint16_t)((r1 - r2) & mask);
1902 wp[4] = (uint16_t)((g1 - g2) & mask);
1905 wp[5] = (uint16_t)((b1 - b2) & mask);
1911 else if (stride == 4)
1913 r2 = wp[0] =
CLAMP(ip[0]);
1914 g2 = wp[1] =
CLAMP(ip[1]);
1915 b2 = wp[2] =
CLAMP(ip[2]);
1916 a2 = wp[3] =
CLAMP(ip[3]);
1922 wp[4] = (uint16_t)((r1 - r2) & mask);
1925 wp[5] = (uint16_t)((g1 - g2) & mask);
1928 wp[6] = (uint16_t)((b1 - b2) & mask);
1931 wp[7] = (uint16_t)((a1 - a2) & mask);
1944 wp[0] = (uint16_t)((
CLAMP(ip[0]) -
CLAMP(ip[-stride])) &
1988 static const char module[] = "PixarLogEncode";
2016 "%" PRIu16
" bit input not supported in PixarLog",
2017 td->td_bitspersample);
2023 (
isTiled(tif) ? td->td_tilewidth : td->td_imagewidth);
2025 if (llen == 0 || n % llen != 0)
2027 TIFFErrorExtR(tif, module,
"Fractional scanline cannot be written");
2030 if ((uint64_t)(n / llen) >
2031 (
isTiled(tif) ? td->td_tilelength : td->td_rowsperstrip))
2033 TIFFErrorExtR(tif, module,
"Too many input bytes provided");
2039 tif, sp->
tbuf, n,
sizeof(uint16_t),
"PixarLog encoding");
2040 if (new_tbuf == NULL)
2042 sp->
tbuf = new_tbuf;
2046 for (i = 0, up = sp->
tbuf; i < n; i += llen, up += llen)
2052 bp += (
unsigned long)llen *
sizeof(
float);
2056 bp += (
unsigned long)llen *
sizeof(uint16_t);
2061 bp += (
unsigned long)llen *
sizeof(
unsigned char);
2065 "%" PRIu16
" bit input not supported in PixarLog",
2066 td->td_bitspersample);
2071 sp->
stream.next_in = (
unsigned char *)sp->
tbuf;
2072 assert(
sizeof(sp->
stream.avail_in) == 4);
2076 sp->
stream.avail_in = (uInt)((
unsigned long)n *
sizeof(uint16_t));
2077 if ((sp->
stream.avail_in /
sizeof(uint16_t)) != (
unsigned long)n)
2079 TIFFErrorExtR(tif, module,
"ZLib cannot deal with buffers this size");
2085 if (deflate(&sp->
stream, Z_NO_FLUSH) != Z_OK)
2091 if (sp->
stream.avail_out == 0)
2102 }
while (sp->
stream.avail_in > 0);
2126 static const char module[] = "PixarLogPostEncode";
2130 sp->stream.avail_in = 0;
2134 state = deflate(&sp->stream, Z_FINISH);
2146 sp->stream.avail_out =
2154 sp->stream.msg ? sp->stream.msg :
"(null)");
2157 }
while (state != Z_STREAM_END);
2208 for (
int i = 0; i < 3; i++)
2306 static const char module[] = "PixarLogVSetField";
2313 sp->quality = (int)va_arg(ap,
int);
2316 if (deflateParams(&sp->stream, sp->quality,
2317 Z_DEFAULT_STRATEGY) != Z_OK)
2320 sp->stream.msg ? sp->stream.msg :
"(null)");
2326 sp->user_datafmt = (int)va_arg(ap,
int);
2332 switch (sp->user_datafmt)
2368 result = (*sp->vsetparent)(tif, tag, ap);
2395 *va_arg(ap,
int *) = sp->
quality;
2433 const uint64_t MAX_DEFLATE_RATIO = 1032;
2436 return MAX_DEFLATE_RATIO * (uint64_t)4;
2441 static const char module[] = "TIFFInitPixarLog";
2454 "Merging PixarLog codec-specific tags failed");
2466 sp->stream.data_type = Z_BINARY;
2495 sp->quality = Z_DEFAULT_COMPRESSION;
2509 "Failed to allocate memory for PixarLog tables");
2515 TIFFErrorExtR(tif, module,
"No space for PixarLog state block");
tmsize_t _TIFFMultiplySSize(TIFF *tif, tmsize_t first, tmsize_t second, const char *where)
Check and multiply two signed-size operands.
void _TIFFSetDefaultCompressionState(TIFF *tif)
Install fallback codec callbacks and reset raw-access flags.
#define TIFF_SSIZE_FORMAT
Provide the printf conversion fragment for tmsize_t, without a percent sign.
#define FIELD_TRANSFERFUNCTION
Index the transfer function presence bit; not an on-disk tag number.
int _TIFFMergeFields(TIFF *tif, const TIFFField info[], uint32_t n)
Merge borrowed field definitions into the lookup table.
#define FIELD_SMAXSAMPLEVALUE
Index the per-sample maximum presence bit; not an on-disk tag number.
#define FIELD_COLORMAP
Index the colormap presence bit; not an on-disk tag number.
#define FIELD_SMINSAMPLEVALUE
Index the per-sample minimum presence bit; not an on-disk tag number.
#define FIELD_PSEUDO
Share bit zero with FIELD_IGNORE for pseudo-tags.
#define TIFFClrFieldBit(tif, field)
Clear a directory presence bit.
@ TIFF_SETGET_INT
Promoted int scalar representation.
void _TIFFNoPostDecode(TIFF *tif, uint8_t *buf, tmsize_t cc)
Leave decoded bytes unchanged.
int TIFFFlushData1(TIFF *tif)
Append buffered encoded bytes without invoking postencode recursively.
void _TIFFfreeExt(TIFF *tif, void *p)
Release a handle-aware allocation and its payload charge.
void * _TIFFmallocExt(TIFF *tif, tmsize_t s)
Allocate uninitialised bytes under a handle's allocation policy.
void * _TIFFCheckRealloc(TIFF *tif, void *buffer, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Resize a checked array with an allocation-failure diagnostic.
static void PixarLogStore16NativeUnaligned(uint8_t *cp, uint16_t v)
Write one unaligned native-order sixteen-bit sample.
static float PixarLogLoadFloatNativeUnaligned(const uint8_t *cp)
Read one unaligned native-order float.
static void horizontalAccumulate11(uint16_t *wp, tmsize_t n, int stride, uint8_t *op)
Accumulate PixarLog prediction into raw eleven-bit code words in native uint16_t slots.
#define TSIZE
Count the 2048 eleven-bit code values.
#define TSIZEP1
Include one repeated endpoint in decode tables.
static const TIFFField pixarlogFields[]
Define PixarLog format and quality pseudo-tags.
static void horizontalDifferenceF(const uint8_t *ip, tmsize_t n, int stride, uint16_t *wp, uint16_t *FromLT2)
Compand finite native float32 samples and difference eleven-bit codes.
static void horizontalDifference16(const uint8_t *ip, tmsize_t n, int stride, unsigned short *wp, uint16_t *From14)
Compand native unsigned sixteen-bit samples and difference eleven-bit codes.
static int PixarLogMakeTables(TIFF *tif, PixarLogState *sp)
Build linear/log companding tables for PixarLog sample formats.
#define ONE
Select code 1250 for linear value one.
static tmsize_t add_ms(tmsize_t m1, tmsize_t m2)
Add positive buffer extents with signed overflow rejection.
#define SCALE12
Scale PICIO output by 2048.
static int PixarLogPreEncode(TIFF *tif, uint16_t s)
Reset PixarLog deflation with the current raw output buffer.
static int PixarLogSetupDecode(TIFF *tif)
Allocate companded row storage and initialise PixarLog inflation.
static uint64_t PixarLogGetMaxCompressionRatio(TIFF *tif)
Report a conservative PixarLog expansion allocation heuristic.
static int PixarLogGuessDataFmt(TIFFDirectory *td)
Infer the PixarLog user format from depth and sample format.
static void horizontalAccumulate12(uint16_t *wp, tmsize_t n, int stride, uint8_t *op, float *ToLinearF)
Accumulate PixarLog prediction into twelve-bit PICIO values scaled by 2048 and capped at 3071.
static int PixarLogEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
Compand and difference complete input rows then deflate their codes.
static int PixarLogPostEncode(TIFF *tif)
Finish PixarLog deflation and flush encoded output.
int TIFFInitPixarLog(TIFF *tif, int scheme)
Install PixarLog codec state methods and companding tables.
static void horizontalDifference8(unsigned char *ip, tmsize_t n, int stride, unsigned short *wp, uint16_t *From8)
Compand unsigned eight-bit samples and difference eleven-bit codes.
static void horizontalAccumulate8(uint16_t *wp, tmsize_t n, int stride, unsigned char *op, unsigned char *ToLinear8)
Accumulate PixarLog prediction into clipped unsigned eight-bit linear samples.
static void PixarLogCleanup(TIFF *tif)
Restore PixarLog method chains and release companding storage.
#define CLAMP12(t)
Cap positive PICIO output at 3071.
#define RATIO
Choose the nominal log-region step ratio.
static void PixarLogClose(TIFF *tif)
Present initialised PixarLog directory metadata as unsigned eight-bit samples.
static void horizontalAccumulate16(uint16_t *wp, tmsize_t n, int stride, uint8_t *op, uint16_t *ToLinear16)
Accumulate PixarLog prediction into clipped unsigned sixteen-bit linear samples.
#define PixarLogDecoderState(tif)
Borrow the handle-owned PixarLog decoder state.
#define PIXARLOGDATAFMT_UNKNOWN
Mark an application format not yet inferred or selected.
static void horizontalAccumulate8abgr(uint16_t *wp, tmsize_t n, int stride, unsigned char *op, unsigned char *ToLinear8)
Accumulate PixarLog prediction into eight-bit ABGR bytes.
static int PixarLogVSetField(TIFF *tif, uint32_t tag, va_list ap)
Set PixarLog quality or user data format and update directory sizes.
static int PixarLogSetupEncode(TIFF *tif)
Allocate PixarLog code staging and initialise zlib deflation.
#define CODE_MASK
Mask accumulated codes to eleven bits.
#define PixarLogEncoderState(tif)
Borrow the handle-owned PixarLog encoder state.
static float LogK1
Scale logarithmic float companding.
static float Fltsize
Scale low-range float lookup indices.
#define CLAMP(v)
Map one float sixteen-bit or byte input to a companded code in its enclosing converter.
static void PixarLogStoreFloatNativeUnaligned(uint8_t *cp, float v)
Write one unaligned native-order float.
static void horizontalAccumulateF(uint16_t *wp, tmsize_t n, int stride, uint8_t *op, float *ToLinearF)
Accumulate PixarLog prediction into float32 linear samples.
#define PLSTATE_INIT
Mark dependency stream initialised.
static float LogK2
Normalise logarithmic float companding.
#define REPEAT(n, op)
Repeat a statement n times, and at least once.
static uint16_t PixarLogLoad16NativeUnaligned(const uint8_t *cp)
Read one unaligned native-order sixteen-bit sample.
static int PixarLogPreDecode(TIFF *tif, uint16_t s)
Reset PixarLog inflation over the current raw strile.
static int PixarLogVGetField(TIFF *tif, uint32_t tag, va_list ap)
Retrieve PixarLog quality or format or delegate another query.
static int PixarLogDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
Inflate companded samples and convert complete PixarLog output rows.
static int PixarLogFixupTags(TIFF *tif)
Accept PixarLog tag fixup without changes.
static tmsize_t multiply_ms(TIFF *tif, const char *module, tmsize_t m1, tmsize_t m2)
Multiply positive buffer extents with signed-size checking.
int TIFFPredictorCleanup(TIFF *tif)
Restore saved Predictor tag print and setup hooks.
int TIFFPredictorInit(TIFF *tif)
Install Predictor tag and setup hooks around a codec.
#define isTiled(tif)
Test whether a handle uses tiled storage.
#define FALSE
Represent the legacy internal false value.
#define TIFF_SWAB
Request swapping multibyte file values to or from host order.
#define TIFFArrayCount(a)
Compute the element count of an actual array.
void TIFFSwabArrayOfShort(uint16_t *wp, tmsize_t n)
Reverse the byte order of each array element.
#define TIFF_ANY
Match any data type when searching for a field descriptor.
void TIFFWarningExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a warning diagnostic to the configured handlers.
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a error diagnostic to the configured handlers.
tmsize_t TIFFTileSize(TIFF *tif)
Compute the decoded-size estimate for the configured tile height.
tmsize_t TIFFScanlineSize(TIFF *tif)
Compute the current scanline I/O byte estimate.
void _TIFFmemset(void *p, int v, tmsize_t c)
Fill a byte range with one repeated byte.
int TIFFSetField(TIFF *tif, uint32_t tag,...)
Set a tag value in the current in-memory directory.
int(* TIFFVSetMethod)(TIFF *tif, uint32_t tag, va_list ap)
Implement a handle's variadic tag setter.
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
#define TIFF_TMSIZE_T_MAX
Define the largest positive size representable by tmsize_t.
Own PixarLog companding tables predictor prefix and zlib progress.
uint16_t * From14
Owned Ext 16384-entry lookup for input shifted right two bits.
unsigned char * ToLinear8
Owned Ext clipped eight-bit decode table.
TIFFPredictorState predict
Predictor prefix, first in codec allocation.
TIFFVSetMethod vgetparent
Borrowed parent getter stored under the declared compatible method typedef.
uint16_t stride
Samples per interleaved pixel or one for separate data.
uint16_t * FromLT2
Owned Ext low-range float-to-code mapping.
z_stream stream
Zlib stream whose internal allocation ends during cleanup.
TIFFVSetMethod vsetparent
Borrowed parent setter restored during cleanup.
int user_datafmt
Cached application-facing format, initially UNKNOWN.
uint16_t * ToLinear16
Owned Ext clipped sixteen-bit decode table.
uint16_t * tbuf
Owned Ext aligned uint16_t code staging, released by cleanup.
uint16_t * From8
Owned Ext 256-entry byte-to-code lookup.
tmsize_t tbuf_size
Byte capacity of tbuf; set by decode setup and grown on demand by the encoder.
int quality
Cached zlib quality, applied at setup or active parameter update.
int state
PLSTATE_INIT after dependency setup.
float * ToLinearF
Owned Ext float decode table, TSIZEP1 entries.
Store the current directory values and image traversal state.
uint32_t td_colormap_alloc
Number of entries allocated in each ColorMap plane, zero when none is installed.
tmsize_t td_tilesize
Cached decoded tile size in bytes; minus one when invalidated.
tmsize_t td_scanlinesize
Cached decoded scanline size in bytes; zero when not computed.
double * td_sminsamplevalue
Owned SamplesPerPixel-length array of minimum values, or NULL.
uint16_t td_bitspersample
Bits in each sample.
uint32_t td_row
Current scanline index; UINT32_MAX before traversal starts.
uint16_t * td_transferfunction[3]
Up to three owned gamma curves of td_transferfunction_count entries each.
uint32_t td_colormap_count
Number of entries in each ColorMap plane that the directory uses, zero when none is installed.
double * td_smaxsamplevalue
Owned SamplesPerPixel-length array of maximum values, or NULL.
uint16_t * td_colormap[3]
Three owned palette planes of td_colormap_alloc entries each, or NULL slots; presence is FIELD_COLORM...
uint16_t td_sampleformat
SAMPLEFORMAT_* interpretation of samples.
uint32_t td_transferfunction_count
Number of entries in each installed TransferFunction curve, zero when none is installed; the only rec...
Prefix codec state with Predictor method chains and row geometry.
TIFFVGetMethod vgetfield
Variadic tag-query implementation for the handle.
TIFFVSetMethod vsetfield
Variadic tag-setting implementation for the handle.
Describe a field's file type and internal argument contract.
Hold private state for one open TIFF library instance.
TIFFCodeMethod tif_encodestrip
Codec callback encoding strip data.
TIFFCodeMethod tif_encodetile
Codec callback encoding tile data.
TIFFTagMethods tif_tagmethods
Inline table of directory field and print callbacks.
TIFFPreMethod tif_preencode
Codec callback preparing a row, strip, or tile encode.
TIFFBoolMethod tif_fixuptags
Codec callback for directory-dependent tag corrections.
tmsize_t tif_rawcc
Raw-buffer byte count interpreted according to read/write state.
TIFFPreMethod tif_predecode
Codec callback preparing a row, strip, or tile decode.
TIFFCodeMethod tif_decodestrip
Codec callback decoding strip data.
TIFFGetMaxCompressionRatioMethod tif_getmaxcompressionratio
Codec callback returning its maximum compression ratio.
TIFFPostMethod tif_postdecode
Callback transforming decoded data, for example by byte swapping.
TIFFCodeMethod tif_decoderow
Codec callback decoding a scanline.
TIFFBoolMethod tif_setupencode
Codec setup callback run before preencode.
TIFFDirectory tif_dir
Inline representation of the current image directory.
TIFFBoolMethod tif_postencode
Codec callback completing buffered encoding.
TIFFCodeMethod tif_encoderow
Codec callback encoding a scanline.
TIFFVoidMethod tif_close
Codec close callback; distinct from the client I/O close callback.
TIFFVoidMethod tif_cleanup
Codec callback releasing codec-private state.
uint8_t * tif_data
Codec-private storage; allocation and cleanup follow the selected codec.
uint8_t * tif_rawcp
Borrowed current-position pointer into the raw buffer.
TIFFBoolMethod tif_setupdecode
Codec setup callback run before predecode.
uint8_t * tif_rawdata
Raw buffer; ownership/mapping follow TIFF_MYBUFFER and TIFF_BUFFERMMAP.
tmsize_t tif_rawdatasize
Raw-buffer capacity in bytes; kept in step with tif_rawdata, including zero whenever tif_rawdata is N...
uint32_t tif_flags
Bitmask combining the TIFF_* handle-state flags declared below.
TIFFCodeMethod tif_decodetile
Codec callback decoding tile data.
int tif_mode
Current access mode using the O_* constants.
Define the predictor prefix and method-chain contracts.
Declare private library state, callbacks, and implementation helpers.