225#define DecoderState(tif) ((LogLuvState *)(tif)->tif_data)
226#define EncoderState(tif) ((LogLuvState *)(tif)->tif_data)
228#define SGILOGDATAFMT_UNKNOWN -1
297 " bytes is too small for SGILog encoding",
337 static const char module[] = "LogL16Decode";
352 npixels = occ / sp->pixel_size;
354 if (sp->tbuflen < npixels)
361 tp = (int16_t *)sp->tbuf;
367 for (shft = 8; shft >= 0; shft -= 8)
369 for (i = 0; i < npixels && cc > 0;)
375 rc = *bp++ + (2 - 128);
376 b = (int16_t)(*bp++ << shft);
378 while (rc-- && i < npixels)
384 while (--cc && rc-- && i < npixels)
385 tp[i++] |= (int16_t)(*bp++ << shft);
393 "Not enough data at row %" PRIu32
404 (*sp->tfunc)(sp, op, npixels);
439 static const char module[] = "LogLuvDecode24";
451 npixels = occ / sp->pixel_size;
453 if (sp->tbuflen < npixels)
460 tp = (uint32_t *)sp->tbuf;
464 for (i = 0; i < npixels && cc >= 3; i++)
466 tp[i] = (uint32_t)bp[0] << 16 | (uint32_t)bp[1] << 8 | bp[2];
477 "Not enough data at row %" PRIu32
485 (*sp->tfunc)(sp, op, npixels);
518 static const char module[] = "LogLuvDecode32";
534 npixels = occ / sp->pixel_size;
536 if (sp->tbuflen < npixels)
543 tp = (uint32_t *)sp->tbuf;
549 for (shft = 24; shft >= 0; shft -= 8)
551 for (i = 0; i < npixels && cc > 0;)
557 rc = *bp++ + (2 - 128);
558 b = (uint32_t)*bp++ << shft;
560 while (rc-- && i < npixels)
566 while (--cc && rc-- && i < npixels)
567 tp[i++] |= (uint32_t)*bp++ << shft;
575 "Not enough data at row %" PRIu32
586 (*sp->tfunc)(sp, op, npixels);
630 if (cc % rowlen != 0)
635 "Fractional scanline cannot be read");
690 if (cc % rowlen != 0)
695 "Fractional scanline cannot be read");
741 static const char module[] = "LogL16Encode";
757 npixels = cc / sp->pixel_size;
759 tp = (int16_t *)sp->tbuf;
760 if (sp->tbuflen < npixels)
768 (*sp->tfunc)(sp, bp, npixels);
772 for (shft = 8; shft >= 0; shft -= 8)
774 for (i = 0; i < npixels; i += rc)
779 for (beg = i; beg < npixels; beg += rc)
781 b = (int16_t)(tp[beg] & mask);
783 while (rc < 127 + 2 && beg + rc < npixels &&
784 (tp[beg + rc] & mask) == b)
789 if (beg - i > 1 && beg - i <
MINRUN)
791 b = (int16_t)(tp[i] & mask);
793 while ((tp[j++] & mask) == b)
798 *op++ = (uint8_t)(128 - 2 + j - i);
799 *op++ = (uint8_t)(b >> shft);
807 if ((j = beg - i) > 127)
817 *op++ = (uint8_t)(tp[i++] >> shft & 0xff);
825 *op++ = (uint8_t)(128 - 2 + rc);
826 *op++ = (uint8_t)(tp[beg] >> shft & 0xff);
868 static const char module[] = "LogLuvEncode24";
879 npixels = cc / sp->pixel_size;
881 tp = (uint32_t *)sp->tbuf;
882 if (sp->tbuflen < npixels)
890 (*sp->tfunc)(sp, bp, npixels);
894 for (i = npixels; i--;)
900 *op++ = (uint8_t)(*tp >> 16);
901 *op++ = (uint8_t)(*tp >> 8 & 0xff);
902 *op++ = (uint8_t)(*tp++ & 0xff);
940 static const char module[] = "LogLuvEncode32";
957 npixels = cc / sp->pixel_size;
959 tp = (uint32_t *)sp->tbuf;
960 if (sp->tbuflen < npixels)
968 (*sp->tfunc)(sp, bp, npixels);
972 for (shft = 24; shft >= 0; shft -= 8)
974 const uint32_t mask = 0xffU << shft;
975 for (i = 0; i < npixels; i += rc)
979 for (beg = i; beg < npixels; beg += rc)
983 while (rc < 127 + 2 && beg + rc < npixels &&
984 (tp[beg + rc] & mask) == b)
989 if (beg - i > 1 && beg - i <
MINRUN)
993 while ((tp[j++] & mask) == b)
998 *op++ = (uint8_t)(128 - 2 + j - i);
999 *op++ = (uint8_t)(b >> shft);
1007 if ((j = beg - i) > 127)
1017 *op++ = (uint8_t)(tp[i++] >> shft & 0xff);
1025 *op++ = (uint8_t)(128 - 2 + rc);
1026 *op++ = (uint8_t)(tp[beg] >> shft & 0xff);
1070 if (cc % rowlen != 0)
1073 "Fractional scanline cannot be written");
1076 while (cc && (*tif->
tif_encoderow)(tif, bp, rowlen, s) == 1)
1115 if (cc % rowlen != 0)
1118 "Fractional scanline cannot be written");
1121 while (cc && (*tif->
tif_encoderow)(tif, bp, rowlen, s) == 1)
1136#define U_NEU 0.210526316
1137#define V_NEU 0.473684211
1142#define M_LN2 0.69314718055994530942
1145#define M_PI 3.14159265358979323846
1148#define TIFF_RAND_MAX 32767
1165 static uint32_t nCounter = 0;
1167 nCounter = (uint32_t)(time(NULL) & UINT32_MAX);
1169 uint32_t nCounterLocal =
1170 (uint32_t)(((uint64_t)(nCounter) * 1103515245U + 12345U) & UINT32_MAX);
1171 nCounter = nCounterLocal;
1201 int Le = p16 & 0x7fff;
1206 Y = exp(
M_LN2 / 256. * (Le + .5) -
M_LN2 * 64.);
1207 return (!(p16 & 0x8000) ? Y : -Y);
1215 if (Y >= 1.8371976e19)
1217 if (Y <= -1.8371976e19)
1219 if (Y > 5.4136769e-20)
1221 if (Y < -5.4136769e-20)
1222 return (~0x7fff |
tiff_itrunc(256. * (log2(-Y) + 64.), em));
1248 memcpy(&v, cp,
sizeof(v));
1265 memcpy(cp, &v,
sizeof(v));
1283 memcpy(&v, cp,
sizeof(v));
1301 memcpy(cp, &v,
sizeof(v));
1319 memcpy(&v, cp,
sizeof(v));
1337 memcpy(cp, &v,
sizeof(v));
1358 int16_t *l16 = (int16_t *)sp->
tbuf;
1363 op +=
sizeof(int16_t);
1385 int16_t *l16 = (int16_t *)sp->
tbuf;
1390 op +=
sizeof(int16_t);
1412 uint32_t *luv = (uint32_t *)sp->
tbuf;
1417 op +=
sizeof(uint32_t);
1439 uint32_t *luv = (uint32_t *)sp->
tbuf;
1444 op +=
sizeof(uint32_t);
1466 int16_t *l16 = (int16_t *)sp->
tbuf;
1471 op +=
sizeof(float);
1492 int16_t *l16 = (int16_t *)sp->
tbuf;
1493 uint8_t *gp = (uint8_t *)op;
1498 *gp++ = (uint8_t)((Y <= 0.) ? 0
1500 : (int)(256. * sqrt(Y)));
1524 int16_t *l16 = (int16_t *)sp->
tbuf;
1530 op +=
sizeof(float);
1541 r = 2.690 * (double)xyz[0] + -1.276 * (
double)xyz[1] +
1542 -0.414 * (double)xyz[2];
1543 g = -1.022 * (double)xyz[0] + 1.978 * (
double)xyz[1] +
1544 0.044 * (double)xyz[2];
1545 b = 0.061 * (double)xyz[0] + -0.224 * (
double)xyz[1] +
1546 1.163 * (double)xyz[2];
1549 rgb[0] = (uint8_t)((r <= 0.) ? 0 : (r >= 1.) ? 255 : (int)(256. * sqrt(r)));
1550 rgb[1] = (uint8_t)((g <= 0.) ? 0 : (g >= 1.) ? 255 : (int)(256. * sqrt(g)));
1551 rgb[2] = (uint8_t)((b <= 0.) ? 0 : (b >= 1.) ? 255 : (int)(256. * sqrt(b)));
1561 return (exp(
M_LN2 / 64. * (p10 + .5) -
M_LN2 * 12.));
1571 else if (Y <= .00024283)
1578#define uv2ang(u, v) \
1579 ((NANGLES * .499999999 / M_PI) * atan2((v) - V_NEU, (u) - U_NEU) + \
1598 static int oog_table[
NANGLES];
1599 static int initialized = 0;
1604 double eps[
NANGLES], ua, va, ang, epsa;
1611 ustep =
uv_row[vi].nus - 1;
1612 if (vi ==
UV_NVS - 1 || vi == 0 || ustep <= 0)
1614 for (ui =
uv_row[vi].
nus - 1; ui >= 0; ui -= ustep)
1617 ((
double)ui + .5) * (
double)
UV_SQSIZ;
1620 epsa = fabs(ang - (i + .5));
1623 oog_table[i] =
uv_row[vi].ncum + ui;
1632 for (i1 = 1; i1 <
NANGLES / 2; i1++)
1633 if (eps[(i + i1) %
NANGLES] < 1.5)
1635 for (i2 = 1; i2 <
NANGLES / 2; i2++)
1639 oog_table[i] = oog_table[(i + i1) %
NANGLES];
1646 return (oog_table[i]);
1661 if (isnan(u) || isnan(v))
1688 unsigned int upper, lower;
1696 while (upper - lower > 1)
1698 vi = (lower + upper) >> 1;
1699 ui = c -
uv_row[vi].ncum;
1711 ui = c -
uv_row[vi].ncum;
1723 double L, u, v, s, x, y;
1728 XYZ[0] = XYZ[1] = XYZ[2] = 0.;
1738 s = 1. / (6. * u - 16. * v + 12.);
1742 XYZ[0] = (float)(x / y * L);
1744 XYZ[2] = (float)((1. - x - y) / y * L);
1757 s = (double)XYZ[0] + 15. * (
double)XYZ[1] + 3. * (double)XYZ[2];
1765 u = 4. * (double)XYZ[0] / s;
1766 v = 9. * (double)XYZ[1] / s;
1772 return (uint32_t)Le << 14 | (uint32_t)Ce;
1793 uint32_t *luv = (uint32_t *)sp->
tbuf;
1802 op += 3 *
sizeof(float);
1826 uint32_t *luv = (uint32_t *)sp->
tbuf;
1835 luv0 = (int16_t)((*luv >> 12 & 0xffd) + 13314);
1836 if (
uv_decode(&u, &v, *luv & 0x3fff) < 0)
1841 luv1 = (int16_t)(u * (1 << 15));
1842 luv2 = (int16_t)(v * (1 << 15));
1846 op += 3 *
sizeof(int16_t);
1869 uint32_t *luv = (uint32_t *)sp->
tbuf;
1870 uint8_t *rgb = (uint8_t *)op;
1904 uint32_t *luv = (uint32_t *)sp->
tbuf;
1913 op += 3 *
sizeof(float);
1940 uint32_t *luv = (uint32_t *)sp->
tbuf;
1951 else if (luv0 >= (1 << 12) + 3314)
1954 Le = (luv0 - 3314) >> 2;
1958 Ce =
uv_encode((luv1 + .5) / (1 << 15), (luv2 + .5) / (1 << 15),
1962 *luv++ = (uint32_t)Le << 14 | (uint32_t)Ce;
1963 op += 3 *
sizeof(int16_t);
1972 double L, u, v, s, x, y;
1977 XYZ[0] = XYZ[1] = XYZ[2] = 0.;
1981 u = 1. /
UVSCALE * ((p >> 8 & 0xff) + .5);
1982 v = 1. /
UVSCALE * ((p & 0xff) + .5);
1983 s = 1. / (6. * u - 16. * v + 12.);
1987 XYZ[0] = (float)(x / y * L);
1989 XYZ[2] = (float)((1. - x - y) / y * L);
1997 unsigned int Le, ue, ve;
2000 Le = (
unsigned int)
LogL16fromY((
double)XYZ[1], em);
2002 s = (double)XYZ[0] + 15. * (
double)XYZ[1] + 3. * (double)XYZ[2];
2010 u = 4. * (double)XYZ[0] / s;
2011 v = 9. * (double)XYZ[1] / s;
2026 return (Le << 16 | ue << 8 | ve);
2047 uint32_t *luv = (uint32_t *)sp->
tbuf;
2056 op += 3 *
sizeof(float);
2079 uint32_t *luv = (uint32_t *)sp->
tbuf;
2084 int16_t luv0 = (int16_t)(*luv >> 16);
2088 u = 1. /
UVSCALE * ((*luv >> 8 & 0xff) + .5);
2089 v = 1. /
UVSCALE * ((*luv & 0xff) + .5);
2090 luv1 = (int16_t)(u * (1 << 15));
2091 luv2 = (int16_t)(v * (1 << 15));
2095 op += 3 *
sizeof(int16_t);
2118 uint32_t *luv = (uint32_t *)sp->
tbuf;
2119 uint8_t *rgb = (uint8_t *)op;
2152 uint32_t *luv = (uint32_t *)sp->
tbuf;
2161 op += 3 *
sizeof(float);
2187 uint32_t *luv = (uint32_t *)sp->
tbuf;
2197 *luv++ = (uint32_t)luv0 << 16 |
2198 ((uint32_t)luv1 * (uint32_t)(
UVSCALE + .5) >> 7 & 0xff00) |
2199 ((uint32_t)luv2 * (uint32_t)(
UVSCALE + .5) >> 15 & 0xff);
2200 op += 3 *
sizeof(int16_t);
2209 *luv++ = (uint32_t)luv0 << 16 |
2217 op += 3 *
sizeof(int16_t);
2255#define PACK(s, b, f) (((b) << 6) | ((s) << 3) | (f))
2313 static const char module[] = "LogL16InitState";
2320 if (td->td_samplesperpixel != 1)
2323 "Sorry, can not handle LogL image with %s=%" PRIu16,
2324 "Samples/pixel", td->td_samplesperpixel);
2344 "No support for converting user data format to LogL");
2349 multiply_ms(tif, module, td->td_tilewidth, td->td_tilelength);
2350 else if (td->td_rowsperstrip < td->td_imagelength)
2352 multiply_ms(tif, module, td->td_imagewidth, td->td_rowsperstrip);
2355 multiply_ms(tif, module, td->td_imagewidth, td->td_imagelength);
2364 TIFFErrorExtR(tif, module,
"No space for SGILog translation buffer");
2390#define PACK(a, b) (((a) << 3) | (b))
2454 static const char module[] = "LogLuvInitState";
2465 "SGILog compression cannot handle non-contiguous data");
2487 "No support for converting user data format to LogLuv");
2492 multiply_ms(tif, module, td->td_tilewidth, td->td_tilelength);
2493 else if (td->td_rowsperstrip < td->td_imagelength)
2495 multiply_ms(tif, module, td->td_imagewidth, td->td_rowsperstrip);
2498 multiply_ms(tif, module, td->td_imagewidth, td->td_imagelength);
2508 TIFFErrorExtR(tif, module,
"No space for SGILog translation buffer");
2548 static const char module[] = "LogLuvSetupDecode";
2561 switch (sp->user_datafmt)
2579 switch (sp->user_datafmt)
2599 switch (sp->user_datafmt)
2613 "Inappropriate photometric interpretation %" PRIu16
2614 " for SGILog compression; %s",
2638 static const char module[] = "LogLuvSetupEncode";
2650 switch (sp->user_datafmt)
2667 switch (sp->user_datafmt)
2686 switch (sp->user_datafmt)
2699 "Inappropriate photometric interpretation %" PRIu16
2700 " for SGILog compression; %s",
2704 sp->encoder_state = 1;
2708 "SGILog compression supported only for %s, or raw data",
2749 uint16_t new_bps = 16;
2760 for (
int i = 0; i < 3; i++)
2838 static const char module[] = "LogLuvVSetField";
2840 int bps, fmt, old_datafmt;
2845 old_datafmt = sp->user_datafmt;
2846 sp->user_datafmt = (int)va_arg(ap,
int);
2853 switch (sp->user_datafmt)
2876 "Unknown data format %d for LogLuv compression",
2903 if (sp->user_datafmt != old_datafmt &&
2923 sp->encode_meth = (int)va_arg(ap,
int);
2928 "Unknown encoding %d for LogLuv compression",
2934 return (*sp->vsetparent)(tif, tag, ap);
2983 static const char module[] = "TIFFInitSGILog";
2993 TIFFErrorExtR(tif, module,
"Merging SGILog codec-specific tags failed");
3035 TIFFErrorExtR(tif, module,
"%s: No space for LogLuv 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 NOSTRIP
Represent the absence of a current strip with UINT32_MAX.
#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 NOTILE
Represent the absence of a current tile with UINT32_MAX.
#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.
#define U_NEU
Select neutral u-prime chromaticity.
static int LogLuvInitState(TIFF *tif)
Validate contiguous LogLuv format and allocate packed translation pixels.
static int LogLuvDecode32(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
Decode four compressed colour byte planes and translate one row.
static int LogLuvVSetField(TIFF *tif, uint32_t tag, va_list ap)
Set SGILog user format or dithering and update representation metadata.
static const TIFFField LogLuvFields[]
Define SGILog user format and encoding-method pseudo-tags.
static void LuvRawFromRaw(LogLuvState *sp, uint8_t *op, tmsize_t n)
Copy native caller LogLuv words into staging.
void(* tfunc)(LogLuvState *, uint8_t *, tmsize_t)
Translate pixels between caller bytes and packed codec staging.
static void Luv32fromXYZ(LogLuvState *sp, uint8_t *op, tmsize_t n)
Quantise native float XYZ triplets into LogLuv32 staging.
#define UVSCALE
Scale uniform eight-bit chromaticity for LogLuv32.
static int LogLuvSetupEncode(TIFF *tif)
Select SGILog row encoding and input conversion.
static void LogLuvClose(TIFF *tif)
Normalise encoded SGILog directory sample metadata before writing.
#define EncoderState(tif)
Borrow handle-owned SGILog encode state.
#define TIFF_RAND_MAX
Limit SGILog pseudo-random output to fifteen bits.
static void Luv24toLuv48(LogLuvState *sp, uint8_t *op, tmsize_t n)
Convert staged LogLuv24 codes to native signed Luv triplets.
static void Luv32fromLuv48(LogLuvState *sp, uint8_t *op, tmsize_t n)
Quantise native signed Luv triplets into LogLuv32 staging.
#define PACK(s, b, f)
Combine directory format fields for a local inference switch.
static void L16toL16(LogLuvState *sp, uint8_t *op, tmsize_t n)
Copy encoded luminance words from staging to native caller bytes.
static void LogLuvCleanup(TIFF *tif)
Restore SGILog tag methods and release translation/codec state.
static int LogLuvFits(TIFF *tif, const char *module, const uint8_t *op, tmsize_t need)
Verify that need bytes fit before the raw buffer end.
static int LogL16GuessDataFmt(TIFFDirectory *td)
Infer grayscale SGILog input format from directory fields.
static int LogLuvDecodeStrip(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
Decode complete SGILog strip rows through the selected row callback.
#define SGILOGDATAFMT_UNKNOWN
Mark a user representation not yet inferred.
#define V_NEU
Select neutral v-prime chromaticity.
static int LogL16InitState(TIFF *tif)
Validate grayscale SGILog format and allocate translation pixels.
static int LogLuvReserve(TIFF *tif, uint8_t **opp, tmsize_t *occ, tmsize_t need)
Flush the raw data buffer when fewer than need bytes remain.
#define NANGLES
Partition the gamut perimeter into one hundred hue angles.
#define DecoderState(tif)
Borrow handle-owned SGILog decode state.
static uint32_t _TIFFRand(void)
Advance the shared SGILog pseudo-random dither generator.
#define MINRUN
Choose four pixels as the minimum byte-plane run.
static int LogLuvDecode24(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
Decode three stored bytes per packed colour pixel and translate one row.
static void _logLuvNop(LogLuvState *sp, uint8_t *op, tmsize_t n)
Perform no SGILog pixel translation.
static void LuvRawToRaw(LogLuvState *sp, uint8_t *op, tmsize_t n)
Copy packed LogLuv words from staging to native caller bytes.
static void L16toGry(LogLuvState *sp, uint8_t *op, tmsize_t n)
Convert staged LogL16 values to clipped gamma-two grayscale bytes.
static void Luv24toXYZ(LogLuvState *sp, uint8_t *op, tmsize_t n)
Convert staged LogLuv24 codes to native float XYZ triplets.
static int LogLuvVGetField(TIFF *tif, uint32_t tag, va_list ap)
Retrieve SGILog user format or delegate another tag query.
static int LogLuvGuessDataFmt(TIFFDirectory *td)
Infer colour SGILog input format from directory fields.
static void L16fromY(LogLuvState *sp, uint8_t *op, tmsize_t n)
Quantise native float luminance into staged LogL16 codes.
static float LogLuvLoadFloatNativeUnaligned(const uint8_t *cp)
Read one native-order float through unaligned bytes.
static void LogLuvStore16NativeUnaligned(uint8_t *cp, int16_t v)
Write one native-order signed sixteen-bit value through unaligned bytes.
#define M_LN2
Supply the natural logarithm of two when absent.
static int oog_encode(double u, double v)
Map out-of-gamut chromaticity to a hue-matched boundary bin.
static int LogLuvDecodeTile(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
Decode complete SGILog tile rows through the selected row callback.
static void Luv32toXYZ(LogLuvState *sp, uint8_t *op, tmsize_t n)
Convert staged LogLuv32 codes to native float XYZ triplets.
static void L16fromL16(LogLuvState *sp, uint8_t *op, tmsize_t n)
Copy native caller luminance words into staging.
static void Luv32toRGB(LogLuvState *sp, uint8_t *op, tmsize_t n)
Convert staged LogLuv32 codes to clipped gamma-two RGB bytes.
static void Luv32toLuv48(LogLuvState *sp, uint8_t *op, tmsize_t n)
Convert staged LogLuv32 codes to native signed Luv triplets.
static void Luv24fromXYZ(LogLuvState *sp, uint8_t *op, tmsize_t n)
Quantise native float XYZ triplets into LogLuv24 staging.
static int16_t LogLuvLoad16NativeUnaligned(const uint8_t *cp)
Read one native-order signed sixteen-bit value through unaligned bytes.
static void Luv24toRGB(LogLuvState *sp, uint8_t *op, tmsize_t n)
Convert staged LogLuv24 codes to clipped gamma-two RGB bytes.
static int LogLuvEncode24(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
Translate one input row and emit three-byte packed colour pixels.
static int LogLuvEncodeTile(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
Encode complete SGILog tile rows through the selected row callback.
static int tiff_itrunc(double x, int m)
Quantise a finite value with optional shared random dithering.
static int LogL16Encode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
Translate one input row and emit luminance byte-plane runs.
static uint32_t LogLuvLoad32NativeUnaligned(const uint8_t *cp)
Read one native-order unsigned thirty-two-bit value through unaligned bytes.
static void LogLuvStore32NativeUnaligned(uint8_t *cp, uint32_t v)
Write one native-order unsigned thirty-two-bit value through unaligned bytes.
#define uv2ang(u, v)
Map finite chromaticity to a bounded hue lookup angle.
static int LogLuvSetupDecode(TIFF *tif)
Select SGILog row decoding and application-format conversion.
static const struct @4 uv_row[UV_NVS]
Map each v-prime row to its u-prime start and bin index interval.
static void Luv24fromLuv48(LogLuvState *sp, uint8_t *op, tmsize_t n)
Quantise native signed Luv triplets into LogLuv24 staging.
static int LogLuvEncode32(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
Translate one input row and emit colour byte-plane runs.
static void LogLuvStoreFloatNativeUnaligned(uint8_t *cp, float v)
Write one native-order float through unaligned bytes.
static void L16toY(LogLuvState *sp, uint8_t *op, tmsize_t n)
Convert staged LogL16 values to native float luminance.
int TIFFInitSGILog(TIFF *tif, int scheme)
Allocate SGILog codec state and install row dispatch and tag hooks.
static int LogLuvFixupTags(TIFF *tif)
Accept SGILog tag fixup without changes.
static int LogLuvEncodeStrip(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
Encode complete SGILog strip rows through the selected row callback.
static int LogL16Decode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
Decode two compressed luminance byte planes and translate one row.
static tmsize_t multiply_ms(TIFF *tif, const char *module, tmsize_t m1, tmsize_t m2)
Multiply translation-buffer extents with signed-size checking.
#define isTiled(tif)
Test whether a handle uses tiled storage.
#define TIFF_CODERSETUP
Mark completed codec setup.
#define TRUE
Represent the legacy internal true value.
#define FALSE
Represent the legacy internal false value.
#define TIFFArrayCount(a)
Compute the element count of an actual array.
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.
tmsize_t TIFFTileRowSize(TIFF *tif)
Compute the packed byte count of one tile row.
int LogL10fromY(double Y, int em)
Encode linear luminance as a 10-bit logarithmic value.
int uv_decode(double *up, double *vp, int c)
Decode a quantised chromaticity index to a bin-centre pair.
void LogLuv32toXYZ(uint32_t p, float *XYZ)
Decode one packed 32-bit LogLuv pixel to linear XYZ.
double LogL10toY(int p10)
Decode 10-bit logarithmic luminance to a linear value.
int LogL16fromY(double Y, int em)
Encode linear luminance as a 16-bit logarithmic value.
void XYZtoRGB24(float *xyz, uint8_t *rgb)
Convert a linear XYZ triplet to display RGB bytes.
void LogLuv24toXYZ(uint32_t p, float *XYZ)
Decode one packed 24-bit LogLuv pixel to linear XYZ.
uint32_t LogLuv32fromXYZ(float *XYZ, int em)
Encode linear XYZ as one packed 32-bit LogLuv pixel.
uint32_t LogLuv24fromXYZ(float *XYZ, int em)
Encode linear XYZ as one packed 24-bit LogLuv pixel.
double LogL16toY(int p16)
Decode 16-bit logarithmic luminance to a linear value.
int uv_encode(double u, double v, int em)
Encode chromaticity using the irregular LogLuv quantisation table.
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.
@ TIFF_SHORT
Unsigned 16-bit integer.
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.
uint16_t td_compression
COMPRESSION_* codec identifier.
uint16_t td_photometric
PHOTOMETRIC_* interpretation.
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.
uint16_t td_samplesperpixel
Samples per pixel, including extra samples.
uint32_t td_curtile
Current tile index, or NOTILE.
uint32_t td_transferfunction_count
Number of entries in each installed TransferFunction curve, zero when none is installed; the only rec...
uint32_t td_curstrip
Current strip index, or NOSTRIP.
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.
Own SGILog translation pixels and selected format conversion.
int encode_meth
Cached no-dither/random-dither mode; invalid attempts can remain after rejection.
int encoder_state
One after successful encoder setup, controlling close-time metadata changes.
TIFFVSetMethod vsetparent
Borrowed saved parent setter restored during cleanup.
int user_datafmt
Cached application format, initially UNKNOWN; rejected assignments can remain cached.
uint8_t * tbuf
Owned Ext aligned translation storage, released during cleanup.
tmsize_t tbuflen
Translation capacity in pixels, not bytes.
int pixel_size
Positive bytes per application-facing pixel after setup.
TIFFVSetMethod vgetparent
Borrowed saved parent getter under the declared compatible method type.
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.
TIFFBoolMethod tif_fixuptags
Codec callback for directory-dependent tag corrections.
tmsize_t tif_rawcc
Raw-buffer byte count interpreted according to read/write state.
TIFFCodeMethod tif_decodestrip
Codec callback decoding strip data.
TIFFPostMethod tif_postdecode
Callback transforming decoded data, for example by byte swapping.
char * tif_name
Current filename pointer; may refer to inline or client-supplied storage.
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.
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.
Declare private library state, callbacks, and implementation helpers.
Preserve the historical LogLuv chromaticity-bin table.
#define UV_VSTART
Locate the lower v-prime edge of the first row.
short ncum
Count all bins preceding this row.
short nus
Count horizontal bins in this chromaticity row.
#define UV_NVS
Count the 163 v-prime rows.
#define UV_NDIVS
Count all 16289 chromaticity bins.
#define UV_SQSIZ
Set the chromaticity bin side length.
float ustart
Lower u-prime boundary of this row.