158typedef struct logLuvState LogLuvState;
175#define DecoderState(tif) ((LogLuvState *)(tif)->tif_data)
176#define EncoderState(tif) ((LogLuvState *)(tif)->tif_data)
178#define SGILOGDATAFMT_UNKNOWN -1
187 static const char module[] =
"LogL16Decode";
188 LogLuvState *
sp = DecoderState(tif);
202 npixels = occ /
sp->pixel_size;
208 if (
sp->tbuflen < npixels)
220 for (shft = 8; shft >= 0; shft -= 8)
222 for (
i = 0; i < npixels && cc > 0;)
228 rc = *bp++ + (2 - 128);
231 while (rc-- &&
i < npixels)
237 while (--
cc && rc-- &&
i < npixels)
244 "Not enough data at row %" PRIu32
252 (*
sp->tfunc)(
sp,
op, npixels);
263 static const char module[] =
"LogLuvDecode24";
264 LogLuvState *
sp = DecoderState(tif);
275 npixels = occ /
sp->pixel_size;
281 if (
sp->tbuflen < npixels)
291 for (
i = 0; i < npixels && cc >= 3;
i++)
293 tp[
i] = bp[0] << 16 | bp[1] << 8 | bp[2];
302 "Not enough data at row %" PRIu32
307 (*
sp->tfunc)(
sp,
op, npixels);
316 static const char module[] =
"LogLuvDecode32";
329 sp = DecoderState(tif);
332 npixels = occ /
sp->pixel_size;
338 if (
sp->tbuflen < npixels)
350 for (shft = 24; shft >= 0; shft -= 8)
352 for (
i = 0; i < npixels && cc > 0;)
358 rc = *bp++ + (2 - 128);
361 while (rc-- &&
i < npixels)
367 while (--
cc && rc-- &&
i < npixels)
374 "Not enough data at row %" PRIu32
382 (*
sp->tfunc)(
sp,
op, npixels);
435 static const char module[] =
"LogL16Encode";
436 LogLuvState *
sp = EncoderState(tif);
451 npixels =
cc /
sp->pixel_size;
458 if (
sp->tbuflen < npixels)
463 (*
sp->tfunc)(
sp, bp, npixels);
468 for (shft = 8; shft >= 0; shft -= 8)
470 for (
i = 0;
i < npixels;
i += rc)
482 for (beg =
i; beg < npixels; beg += rc)
486 while (rc < 127 + 2 && beg + rc < npixels &&
492 if (beg -
i > 1 && beg -
i < MINRUN)
508 if ((
j = beg -
i) > 127)
548 static const char module[] =
"LogLuvEncode24";
549 LogLuvState *
sp = EncoderState(tif);
559 npixels =
cc /
sp->pixel_size;
566 if (
sp->tbuflen < npixels)
571 (*
sp->tfunc)(
sp, bp, npixels);
576 for (
i = npixels;
i--;)
603 static const char module[] =
"LogLuvEncode32";
604 LogLuvState *
sp = EncoderState(tif);
620 npixels =
cc /
sp->pixel_size;
627 if (
sp->tbuflen < npixels)
632 (*
sp->tfunc)(
sp, bp, npixels);
637 for (shft = 24; shft >= 0; shft -= 8)
640 for (
i = 0;
i < npixels;
i += rc)
651 for (beg =
i; beg < npixels; beg += rc)
655 while (rc < 127 + 2 && beg + rc < npixels &&
661 if (beg -
i > 1 && beg -
i < MINRUN)
677 if ((
j = beg -
i) > 127)
759#define U_NEU 0.210526316
760#define V_NEU 0.473684211
765#define M_LN2 0.69314718055994530942
768#define M_PI 3.14159265358979323846
771#define log2(x) ((1. / M_LN2) * log(x))
773#define exp2(x) exp(M_LN2 *(x))
775#define TIFF_RAND_MAX 32767
786 nCounter = nCounterLocal;
787 return (nCounterLocal / 65536U) % (TIFF_RAND_MAX + 1);
790static int tiff_itrunc(
double x,
int m)
794 return (
int)(
x + _TIFFRand() * (1. / TIFF_RAND_MAX) - .5);
803 int Le = p16 & 0x7fff;
809 return (!(p16 & 0x8000) ?
Y : -
Y);
818 if (
Y >= 1.8371976e19)
820 if (
Y <= -1.8371976e19)
822 if (
Y > 5.4136769e-20)
823 return tiff_itrunc(256. * (
log2(
Y) + 64.), em);
824 if (
Y < -5.4136769e-20)
825 return (~0x7fff | tiff_itrunc(256. * (
log2(-
Y) + 64.), em));
832 float *yp = (
float *)
op;
848 : (
int)(256. *
sqrt(
Y)));
855 float *yp = (
float *)
op;
869 r = 2.690 * xyz[0] + -1.276 * xyz[1] + -0.414 * xyz[2];
870 g = -1.022 * xyz[0] + 1.978 * xyz[1] + 0.044 * xyz[2];
871 b = 0.061 * xyz[0] + -0.224 * xyz[1] + 1.163 * xyz[2];
898 else if (
Y <= .00024283)
901 return tiff_itrunc(64. * (
log2(
Y) + 12.), em);
905#define uv2ang(u, v) \
906 ((NANGLES * .499999999 / M_PI) * atan2((v)-V_NEU, (u)-U_NEU) + .5 * NANGLES)
908static int oog_encode(
double u,
double v)
910 static int oog_table[NANGLES];
916 double eps[NANGLES], ua, va, ang, epsa;
918 for (
i = NANGLES;
i--;)
924 if (
vi ==
UV_NVS - 1 ||
vi == 0 || ustep <= 0)
929 ang = uv2ang(ua, va);
931 epsa =
fabs(ang - (
i + .5));
939 for (
i = NANGLES;
i--;)
943 for (i1 = 1; i1 < NANGLES / 2; i1++)
944 if (
eps[(
i + i1) % NANGLES] < 1.5)
946 for (i2 = 1; i2 < NANGLES / 2; i2++)
947 if (
eps[(
i + NANGLES - i2) % NANGLES] < 1.5)
950 oog_table[
i] = oog_table[(
i + i1) % NANGLES];
952 oog_table[
i] = oog_table[(
i + NANGLES - i2) % NANGLES];
957 return (oog_table[
i]);
973 if (
u !=
u ||
v !=
v)
980 return oog_encode(
u,
v);
983 return oog_encode(
u,
v);
985 return oog_encode(
u,
v);
988 return oog_encode(
u,
v);
999 unsigned int upper, lower;
1007 while (upper - lower > 1)
1009 vi = (lower + upper) >> 1;
1040 XYZ[0] = XYZ[1] = XYZ[2] = 0.;
1050 s = 1. / (6. *
u - 16. *
v + 12.);
1070 s = XYZ[0] + 15. * XYZ[1] + 3. * XYZ[2];
1078 u = 4. * XYZ[0] /
s;
1079 v = 9. * XYZ[1] /
s;
1085 return (Le << 14 | Ce);
1091 float *xyz = (
float *)
op;
1110 *luv3++ = (
int16_t)((*luv >> 12 & 0xffd) + 13314);
1116 *luv3++ = (
int16_t)(
u * (1L << 15));
1117 *luv3++ = (
int16_t)(
v * (1L << 15));
1140 float *xyz = (
float *)
op;
1160 else if (luv3[0] >= (1 << 12) + 3314)
1163 Le = (luv3[0] - 3314) >> 2;
1165 Le = tiff_itrunc(.25 * (luv3[0] - 3314.),
sp->encode_meth);
1167 Ce =
uv_encode((luv3[1] + .5) / (1 << 15), (luv3[2] + .5) / (1 << 15),
1187 XYZ[0] = XYZ[1] = XYZ[2] = 0.;
1191 u = 1. /
UVSCALE * ((
p >> 8 & 0xff) + .5);
1193 s = 1. / (6. *
u - 16. *
v + 12.);
1208 unsigned int Le, ue,
ve;
1213 s = XYZ[0] + 15. * XYZ[1] + 3. * XYZ[2];
1221 u = 4. * XYZ[0] /
s;
1222 v = 9. * XYZ[1] /
s;
1237 return (Le << 16 | ue << 8 |
ve);
1243 float *xyz = (
float *)
op;
1261 *luv3++ = (
int16_t)(*luv >> 16);
1262 u = 1. /
UVSCALE * ((*luv >> 8 & 0xff) + .5);
1263 v = 1. /
UVSCALE * ((*luv & 0xff) + .5);
1264 *luv3++ = (
int16_t)(
u * (1L << 15));
1265 *luv3++ = (
int16_t)(
v * (1L << 15));
1288 float *xyz = (
float *)
op;
1317 (tiff_itrunc(luv3[1] * (
UVSCALE / (1 << 15)),
sp->encode_meth)
1320 (tiff_itrunc(luv3[2] * (
UVSCALE / (1 << 15)),
sp->encode_meth) &
1335#define PACK(s, b, f) (((b) << 6) | ((s) << 3) | (f))
1350 return (SGILOGDATAFMT_UNKNOWN);
1358static int LogL16InitState(
TIFF *tif)
1360 static const char module[] =
"LogL16InitState";
1362 LogLuvState *
sp = DecoderState(tif);
1370 "Sorry, can not handle LogL image with %s=%" PRIu16,
1376 if (
sp->user_datafmt == SGILOGDATAFMT_UNKNOWN)
1377 sp->user_datafmt = LogL16GuessDataFmt(td);
1378 switch (
sp->user_datafmt)
1381 sp->pixel_size =
sizeof(
float);
1391 "No support for converting user data format to LogL");
1400 if (multiply_ms(
sp->tbuflen,
sizeof(
int16_t)) == 0 ||
1418#define PACK(a, b) (((a) << 3) | (b))
1439 guess = SGILOGDATAFMT_UNKNOWN;
1450 guess = SGILOGDATAFMT_UNKNOWN;
1454 guess = SGILOGDATAFMT_UNKNOWN;
1457 guess = SGILOGDATAFMT_UNKNOWN;
1463static int LogLuvInitState(
TIFF *tif)
1465 static const char module[] =
"LogLuvInitState";
1467 LogLuvState *
sp = DecoderState(tif);
1476 "SGILog compression cannot handle non-contiguous data");
1479 if (
sp->user_datafmt == SGILOGDATAFMT_UNKNOWN)
1480 sp->user_datafmt = LogLuvGuessDataFmt(td);
1481 switch (
sp->user_datafmt)
1484 sp->pixel_size = 3 *
sizeof(
float);
1498 "No support for converting user data format to LogLuv");
1507 if (multiply_ms(
sp->tbuflen,
sizeof(
uint32_t)) == 0 ||
1517static int LogLuvFixupTags(
TIFF *tif)
1523static int LogLuvSetupDecode(
TIFF *tif)
1525 static const char module[] =
"LogLuvSetupDecode";
1526 LogLuvState *
sp = DecoderState(tif);
1533 if (!LogLuvInitState(tif))
1538 switch (
sp->user_datafmt)
1541 sp->tfunc = Luv24toXYZ;
1544 sp->tfunc = Luv24toLuv48;
1547 sp->tfunc = Luv24toRGB;
1554 switch (
sp->user_datafmt)
1557 sp->tfunc = Luv32toXYZ;
1560 sp->tfunc = Luv32toLuv48;
1563 sp->tfunc = Luv32toRGB;
1569 if (!LogL16InitState(tif))
1572 switch (
sp->user_datafmt)
1578 sp->tfunc = L16toGry;
1584 "Inappropriate photometric interpretation %" PRIu16
1585 " for SGILog compression; %s",
1592static int LogLuvSetupEncode(
TIFF *tif)
1594 static const char module[] =
"LogLuvSetupEncode";
1595 LogLuvState *
sp = EncoderState(tif);
1601 if (!LogLuvInitState(tif))
1606 switch (
sp->user_datafmt)
1609 sp->tfunc = Luv24fromXYZ;
1612 sp->tfunc = Luv24fromLuv48;
1623 switch (
sp->user_datafmt)
1626 sp->tfunc = Luv32fromXYZ;
1629 sp->tfunc = Luv32fromLuv48;
1639 if (!LogL16InitState(tif))
1642 switch (
sp->user_datafmt)
1645 sp->tfunc = L16fromY;
1655 "Inappropriate photometric interpretation %" PRIu16
1656 " for SGILog compression; %s",
1660 sp->encoder_state = 1;
1664 "SGILog compression supported only for %s, or raw data",
1669static void LogLuvClose(
TIFF *tif)
1671 LogLuvState *
sp = (LogLuvState *)tif->
tif_data;
1683 if (
sp->encoder_state)
1694static void LogLuvCleanup(
TIFF *tif)
1696 LogLuvState *
sp = (LogLuvState *)tif->
tif_data;
1713 static const char module[] =
"LogLuvVSetField";
1714 LogLuvState *
sp = DecoderState(tif);
1727 switch (
sp->user_datafmt)
1749 "Unknown data format %d for LogLuv compression",
1767 "Unknown encoding %d for LogLuv compression",
1773 return (*
sp->vsetparent)(tif,
tag,
ap);
1779 LogLuvState *
sp = (LogLuvState *)tif->
tif_data;
1787 return (*
sp->vgetparent)(tif,
tag,
ap);
1791static const TIFFField LogLuvFields[] = {
1799 static const char module[] =
"TIFFInitSGILog";
1821 sp->user_datafmt = SGILOGDATAFMT_UNKNOWN;
1824 sp->tfunc = _logLuvNop;
_ACRTIMP double __cdecl sqrt(double)
_ACRTIMP double __cdecl fabs(double)
_ACRTIMP double __cdecl log2(double)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
for(i=0;i< ARRAY_SIZE(offsets);i++)
GLint GLint GLint GLint GLint x
GLint GLint GLint GLint GLint GLint y
GLdouble GLdouble GLdouble r
GLboolean GLboolean GLboolean b
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
struct msdos_volume_info vi
static float(__cdecl *square_half_float)(float x
static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
uint16_t td_bitspersample
uint16_t td_samplesperpixel
TIFFCodeMethod tif_encodestrip
TIFFCodeMethod tif_encodetile
TIFFTagMethods tif_tagmethods
tmsize_t tif_scanlinesize
TIFFBoolMethod tif_fixuptags
TIFFCodeMethod tif_decodestrip
TIFFPostMethod tif_postdecode
TIFFCodeMethod tif_decoderow
TIFFBoolMethod tif_setupencode
TIFFCodeMethod tif_encoderow
TIFFVoidMethod tif_cleanup
TIFFBoolMethod tif_setupdecode
TIFFCodeMethod tif_decodetile
tmsize_t _TIFFMultiplySSize(TIFF *tif, tmsize_t first, tmsize_t second, const char *where)
void _TIFFSetDefaultCompressionState(TIFF *tif)
#define TIFF_SSIZE_FORMAT
int TIFFSetField(TIFF *tif, uint32_t tag,...)
int _TIFFMergeFields(TIFF *tif, const TIFFField info[], uint32_t n)
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
void _TIFFfreeExt(TIFF *tif, void *p)
void * _TIFFmallocExt(TIFF *tif, tmsize_t s)
void _TIFFNoPostDecode(TIFF *tif, uint8_t *buf, tmsize_t cc)
tmsize_t TIFFScanlineSize(TIFF *tif)
tmsize_t TIFFTileSize(TIFF *tif)
tmsize_t TIFFTileRowSize(TIFF *tif)
void _TIFFmemset(void *p, int v, tmsize_t c)
int TIFFFlushData1(TIFF *tif)
#define SGILOGDATAFMT_RAW
#define TIFFTAG_BITSPERSAMPLE
#define TIFFTAG_SGILOGENCODE
#define TIFFTAG_SAMPLESPERPIXEL
#define COMPRESSION_SGILOG
#define SAMPLEFORMAT_UINT
#define SGILOGENCODE_RANDITHER
#define PHOTOMETRIC_LOGLUV
#define SAMPLEFORMAT_IEEEFP
#define SGILOGDATAFMT_8BIT
#define SGILOGDATAFMT_FLOAT
#define TIFFTAG_SGILOGDATAFMT
#define COMPRESSION_SGILOG24
#define SGILOGENCODE_NODITHER
#define TIFFTAG_SAMPLEFORMAT
#define SAMPLEFORMAT_VOID
#define SGILOGDATAFMT_16BIT
#define PLANARCONFIG_CONTIG
int LogL16fromY(double, int)
void LogLuv32toXYZ(uint32_t, float *)
void LogLuv24toXYZ(uint32_t, float *)
int(* TIFFVSetMethod)(TIFF *, uint32_t, va_list)
void XYZtoRGB24(float *, uint8_t *)
int uv_decode(double *, double *, int)
int uv_encode(double, double, int)
uint32_t LogLuv32fromXYZ(float *, int)
uint32_t LogLuv24fromXYZ(float *, int)
int LogL10fromY(double, int)
#define TIFFArrayCount(a)
static const struct @3703 uv_row[UV_NVS]
_In_ ULONG _In_ ULONG rgb
void int int ULONGLONG int va_list * ap