1 /* $Id: tif_luv.c,v 1.35 2011-04-02 20:54:09 bfriesen Exp $ */
4 * Copyright (c) 1997 Greg Ward Larson
5 * Copyright (c) 1997 Silicon Graphics, Inc.
7 * Permission to use, copy, modify, distribute, and sell this software and
8 * its documentation for any purpose is hereby granted without fee, provided
9 * that (i) the above copyright notices and this permission notice appear in
10 * all copies of the software and related documentation, and (ii) the names of
11 * Sam Leffler, Greg Larson and Silicon Graphics may not be used in any
12 * advertising or publicity relating to the software without the specific,
13 * prior written permission of Sam Leffler, Greg Larson and Silicon Graphics.
15 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19 * IN NO EVENT SHALL SAM LEFFLER, GREG LARSON OR SILICON GRAPHICS BE LIABLE
20 * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 #if (!defined(_FPDFAPI_MINI_) || defined(_TIFF_DECODER_)) && !defined(_USE_ADDIN_) && !defined _FX_NO_ANSIC_ && !defined(_FX_EMB_NOUSE_DECODER_)
32 * LogLuv compression support for high dynamic range images.
34 * Contributed by Greg Larson.
36 * LogLuv image support uses the TIFF library to store 16 or 10-bit
37 * log luminance values with 8 bits each of u and v or a 14-bit index.
39 * The codec can take as input and produce as output 32-bit IEEE float values
40 * as well as 16-bit integer values. A 16-bit luminance is interpreted
41 * as a sign bit followed by a 15-bit integer that is converted
42 * to and from a linear magnitude using the transformation:
44 * L = 2^( (Le+.5)/256 - 64 ) # real from 15-bit
46 * Le = floor( 256*(log2(L) + 64) ) # 15-bit from real
48 * The actual conversion to world luminance units in candelas per sq. meter
49 * requires an additional multiplier, which is stored in the TIFFTAG_STONITS.
50 * This value is usually set such that a reasonable exposure comes from
51 * clamping decoded luminances above 1 to 1 in the displayed image.
53 * The 16-bit values for u and v may be converted to real values by dividing
54 * each by 32768. (This allows for negative values, which aren't useful as
55 * far as we know, but are left in case of future improvements in human
58 * Conversion from (u,v), which is actually the CIE (u',v') system for
59 * you color scientists, is accomplished by the following transformation:
61 * u = 4*x / (-2*x + 12*y + 3)
62 * v = 9*y / (-2*x + 12*y + 3)
64 * x = 9*u / (6*u - 16*v + 12)
65 * y = 4*v / (6*u - 16*v + 12)
67 * This process is greatly simplified by passing 32-bit IEEE floats
68 * for each of three CIE XYZ coordinates. The codec then takes care
69 * of conversion to and from LogLuv, though the application is still
70 * responsible for interpreting the TIFFTAG_STONITS calibration factor.
72 * By definition, a CIE XYZ vector of [1 1 1] corresponds to a neutral white
73 * point of (x,y)=(1/3,1/3). However, most color systems assume some other
74 * white point, such as D65, and an absolute color conversion to XYZ then
75 * to another color space with a different white point may introduce an
76 * unwanted color cast to the image. It is often desirable, therefore, to
77 * perform a white point conversion that maps the input white to [1 1 1]
78 * in XYZ, then record the original white point using the TIFFTAG_WHITEPOINT
79 * tag value. A decoder that demands absolute color calibration may use
80 * this white point tag to get back the original colors, but usually it
81 * will be ignored and the new white point will be used instead that
82 * matches the output color space.
84 * Pixel information is compressed into one of two basic encodings, depending
85 * on the setting of the compression tag, which is one of COMPRESSION_SGILOG
86 * or COMPRESSION_SGILOG24. For COMPRESSION_SGILOG, greyscale data is
92 * COMPRESSION_SGILOG color data is stored as:
95 * |-+---------------|--------+--------|
98 * For the 24-bit COMPRESSION_SGILOG24 color format, the data is stored as:
101 * |----------|--------------|
104 * There is no sign bit in the 24-bit case, and the (u,v) chromaticity is
105 * encoded as an index for optimal color resolution. The 10 log bits are
106 * defined by the following conversions:
108 * L = 2^((Le'+.5)/64 - 12) # real from 10-bit
110 * Le' = floor( 64*(log2(L) + 12) ) # 10-bit from real
112 * The 10 bits of the smaller format may be converted into the 15 bits of
113 * the larger format by multiplying by 4 and adding 13314. Obviously,
114 * a smaller range of magnitudes is covered (about 5 orders of magnitude
115 * instead of 38), and the lack of a sign bit means that negative luminances
116 * are not allowed. (Well, they aren't allowed in the real world, either,
117 * but they are useful for certain types of image processing.)
119 * The desired user format is controlled by the setting the internal
120 * pseudo tag TIFFTAG_SGILOGDATAFMT to one of:
121 * SGILOGDATAFMT_FLOAT = IEEE 32-bit float XYZ values
122 * SGILOGDATAFMT_16BIT = 16-bit integer encodings of logL, u and v
123 * Raw data i/o is also possible using:
124 * SGILOGDATAFMT_RAW = 32-bit unsigned integer with encoded pixel
125 * In addition, the following decoding is provided for ease of display:
126 * SGILOGDATAFMT_8BIT = 8-bit default RGB gamma-corrected values
128 * For grayscale images, we provide the following data formats:
129 * SGILOGDATAFMT_FLOAT = IEEE 32-bit float Y values
130 * SGILOGDATAFMT_16BIT = 16-bit integer w/ encoded luminance
131 * SGILOGDATAFMT_8BIT = 8-bit gray monitor values
133 * Note that the COMPRESSION_SGILOG applies a simple run-length encoding
134 * scheme by separating the logL, u and v bytes for each row and applying
135 * a PackBits type of compression. Since the 24-bit encoding is not
136 * adaptive, the 32-bit color format takes less space in many cases.
138 * Further control is provided over the conversion from higher-resolution
139 * formats to final encoded values through the pseudo tag
140 * TIFFTAG_SGILOGENCODE:
141 * SGILOGENCODE_NODITHER = do not dither encoded values
142 * SGILOGENCODE_RANDITHER = apply random dithering during encoding
144 * The default value of this tag is SGILOGENCODE_NODITHER for
145 * COMPRESSION_SGILOG to maximize run-length encoding and
146 * SGILOGENCODE_RANDITHER for COMPRESSION_SGILOG24 to turn
147 * quantization errors into noise.
155 * State block for each open TIFF
156 * file using LogLuv compression/decompression.
158 typedef struct logLuvState LogLuvState;
161 int user_datafmt; /* user data format */
162 int encode_meth; /* encoding method */
163 int pixel_size; /* bytes per pixel */
165 uint8* tbuf; /* translation buffer */
166 tmsize_t tbuflen; /* buffer length */
167 void (*tfunc)(LogLuvState*, uint8*, tmsize_t);
169 TIFFVSetMethod vgetparent; /* super-class method */
170 TIFFVSetMethod vsetparent; /* super-class method */
173 #define DecoderState(tif) ((LogLuvState*) (tif)->tif_data)
174 #define EncoderState(tif) ((LogLuvState*) (tif)->tif_data)
176 #define SGILOGDATAFMT_UNKNOWN -1
178 #define MINRUN 4 /* minimum run length */
181 * Decode a string of 16-bit gray pixels.
184 LogL16Decode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
186 static const char module[] = "LogL16Decode";
187 LogLuvState* sp = DecoderState(tif);
200 npixels = occ / sp->pixel_size;
202 if (sp->user_datafmt == SGILOGDATAFMT_16BIT)
205 assert(sp->tbuflen >= npixels);
206 tp = (int16*) sp->tbuf;
208 _TIFFmemset((void*) tp, 0, npixels*sizeof (tp[0]));
210 bp = (unsigned char*) tif->tif_rawcp;
212 /* get each byte string */
213 for (shft = 2*8; (shft -= 8) >= 0; ) {
214 for (i = 0; i < npixels && cc > 0; )
215 if (*bp >= 128) { /* run */
216 rc = *bp++ + (2-128); /* TODO: potential input buffer overrun when decoding corrupt or truncated data */
217 b = (int16)(*bp++ << shft);
219 while (rc-- && i < npixels)
221 } else { /* non-run */
222 rc = *bp++; /* nul is noop */
223 while (--cc && rc-- && i < npixels)
224 tp[i++] |= (int16)*bp++ << shft;
227 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
228 TIFFErrorExt(tif->tif_clientdata, module,
229 "Not enough data at row %lu (short %I64d pixels)",
230 (unsigned long) tif->tif_row,
231 (unsigned __int64) (npixels - i));
233 TIFFErrorExt(tif->tif_clientdata, module,
234 "Not enough data at row %lu (short %llu pixels)",
235 (unsigned long) tif->tif_row,
236 (unsigned long long) (npixels - i));
238 tif->tif_rawcp = (uint8*) bp;
243 (*sp->tfunc)(sp, op, npixels);
244 tif->tif_rawcp = (uint8*) bp;
250 * Decode a string of 24-bit pixels.
253 LogLuvDecode24(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
255 static const char module[] = "LogLuvDecode24";
256 LogLuvState* sp = DecoderState(tif);
266 npixels = occ / sp->pixel_size;
268 if (sp->user_datafmt == SGILOGDATAFMT_RAW)
271 assert(sp->tbuflen >= npixels);
272 tp = (uint32 *) sp->tbuf;
274 /* copy to array of uint32 */
275 bp = (unsigned char*) tif->tif_rawcp;
277 for (i = 0; i < npixels && cc > 0; i++) {
278 tp[i] = bp[0] << 16 | bp[1] << 8 | bp[2];
282 tif->tif_rawcp = (uint8*) bp;
285 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
286 TIFFErrorExt(tif->tif_clientdata, module,
287 "Not enough data at row %lu (short %I64d pixels)",
288 (unsigned long) tif->tif_row,
289 (unsigned __int64) (npixels - i));
291 TIFFErrorExt(tif->tif_clientdata, module,
292 "Not enough data at row %lu (short %llu pixels)",
293 (unsigned long) tif->tif_row,
294 (unsigned long long) (npixels - i));
298 (*sp->tfunc)(sp, op, npixels);
303 * Decode a string of 32-bit pixels.
306 LogLuvDecode32(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
308 static const char module[] = "LogLuvDecode32";
320 sp = DecoderState(tif);
323 npixels = occ / sp->pixel_size;
325 if (sp->user_datafmt == SGILOGDATAFMT_RAW)
328 assert(sp->tbuflen >= npixels);
329 tp = (uint32*) sp->tbuf;
331 _TIFFmemset((void*) tp, 0, npixels*sizeof (tp[0]));
333 bp = (unsigned char*) tif->tif_rawcp;
335 /* get each byte string */
336 for (shft = 4*8; (shft -= 8) >= 0; ) {
337 for (i = 0; i < npixels && cc > 0; )
338 if (*bp >= 128) { /* run */
339 rc = *bp++ + (2-128);
340 b = (uint32)*bp++ << shft;
341 cc -= 2; /* TODO: potential input buffer overrun when decoding corrupt or truncated data */
342 while (rc-- && i < npixels)
344 } else { /* non-run */
345 rc = *bp++; /* nul is noop */
346 while (--cc && rc-- && i < npixels)
347 tp[i++] |= (uint32)*bp++ << shft;
350 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
351 TIFFErrorExt(tif->tif_clientdata, module,
352 "Not enough data at row %lu (short %I64d pixels)",
353 (unsigned long) tif->tif_row,
354 (unsigned __int64) (npixels - i));
356 TIFFErrorExt(tif->tif_clientdata, module,
357 "Not enough data at row %lu (short %llu pixels)",
358 (unsigned long) tif->tif_row,
359 (unsigned long long) (npixels - i));
361 tif->tif_rawcp = (uint8*) bp;
366 (*sp->tfunc)(sp, op, npixels);
367 tif->tif_rawcp = (uint8*) bp;
373 * Decode a strip of pixels. We break it into rows to
374 * maintain synchrony with the encode algorithm, which
378 LogLuvDecodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
380 tmsize_t rowlen = TIFFScanlineSize(tif);
382 assert(cc%rowlen == 0);
383 while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s))
384 bp += rowlen, cc -= rowlen;
389 * Decode a tile of pixels. We break it into rows to
390 * maintain synchrony with the encode algorithm, which
394 LogLuvDecodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
396 tmsize_t rowlen = TIFFTileRowSize(tif);
398 assert(cc%rowlen == 0);
399 while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s))
400 bp += rowlen, cc -= rowlen;
405 * Encode a row of 16-bit pixels.
408 LogL16Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
410 LogLuvState* sp = EncoderState(tif);
424 npixels = cc / sp->pixel_size;
426 if (sp->user_datafmt == SGILOGDATAFMT_16BIT)
429 tp = (int16*) sp->tbuf;
430 assert(sp->tbuflen >= npixels);
431 (*sp->tfunc)(sp, bp, npixels);
433 /* compress each byte string */
435 occ = tif->tif_rawdatasize - tif->tif_rawcc;
436 for (shft = 2*8; (shft -= 8) >= 0; )
437 for (i = 0; i < npixels; i += rc) {
440 tif->tif_rawcc = tif->tif_rawdatasize - occ;
441 if (!TIFFFlushData1(tif))
444 occ = tif->tif_rawdatasize - tif->tif_rawcc;
446 mask = 0xff << shft; /* find next run */
447 for (beg = i; beg < npixels; beg += rc) {
448 b = (int16) (tp[beg] & mask);
450 while (rc < 127+2 && beg+rc < npixels &&
451 (tp[beg+rc] & mask) == b)
454 break; /* long enough */
456 if (beg-i > 1 && beg-i < MINRUN) {
457 b = (int16) (tp[i] & mask);/*check short run */
459 while ((tp[j++] & mask) == b)
461 *op++ = (uint8)(128-2+j-i);
462 *op++ = (uint8)(b >> shft);
468 while (i < beg) { /* write out non-run */
469 if ((j = beg-i) > 127) j = 127;
472 tif->tif_rawcc = tif->tif_rawdatasize - occ;
473 if (!TIFFFlushData1(tif))
476 occ = tif->tif_rawdatasize - tif->tif_rawcc;
478 *op++ = (uint8) j; occ--;
480 *op++ = (uint8) (tp[i++] >> shft & 0xff);
484 if (rc >= MINRUN) { /* write out run */
485 *op++ = (uint8) (128-2+rc);
486 *op++ = (uint8) (tp[beg] >> shft & 0xff);
492 tif->tif_rawcc = tif->tif_rawdatasize - occ;
498 * Encode a row of 24-bit pixels.
501 LogLuvEncode24(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
503 LogLuvState* sp = EncoderState(tif);
512 npixels = cc / sp->pixel_size;
514 if (sp->user_datafmt == SGILOGDATAFMT_RAW)
517 tp = (uint32*) sp->tbuf;
518 assert(sp->tbuflen >= npixels);
519 (*sp->tfunc)(sp, bp, npixels);
521 /* write out encoded pixels */
523 occ = tif->tif_rawdatasize - tif->tif_rawcc;
524 for (i = npixels; i--; ) {
527 tif->tif_rawcc = tif->tif_rawdatasize - occ;
528 if (!TIFFFlushData1(tif))
531 occ = tif->tif_rawdatasize - tif->tif_rawcc;
533 *op++ = (uint8)(*tp >> 16);
534 *op++ = (uint8)(*tp >> 8 & 0xff);
535 *op++ = (uint8)(*tp++ & 0xff);
539 tif->tif_rawcc = tif->tif_rawdatasize - occ;
545 * Encode a row of 32-bit pixels.
548 LogLuvEncode32(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
550 LogLuvState* sp = EncoderState(tif);
565 npixels = cc / sp->pixel_size;
567 if (sp->user_datafmt == SGILOGDATAFMT_RAW)
570 tp = (uint32*) sp->tbuf;
571 assert(sp->tbuflen >= npixels);
572 (*sp->tfunc)(sp, bp, npixels);
574 /* compress each byte string */
576 occ = tif->tif_rawdatasize - tif->tif_rawcc;
577 for (shft = 4*8; (shft -= 8) >= 0; )
578 for (i = 0; i < npixels; i += rc) {
581 tif->tif_rawcc = tif->tif_rawdatasize - occ;
582 if (!TIFFFlushData1(tif))
585 occ = tif->tif_rawdatasize - tif->tif_rawcc;
587 mask = 0xff << shft; /* find next run */
588 for (beg = i; beg < npixels; beg += rc) {
591 while (rc < 127+2 && beg+rc < npixels &&
592 (tp[beg+rc] & mask) == b)
595 break; /* long enough */
597 if (beg-i > 1 && beg-i < MINRUN) {
598 b = tp[i] & mask; /* check short run */
600 while ((tp[j++] & mask) == b)
602 *op++ = (uint8)(128-2+j-i);
603 *op++ = (uint8)(b >> shft);
609 while (i < beg) { /* write out non-run */
610 if ((j = beg-i) > 127) j = 127;
613 tif->tif_rawcc = tif->tif_rawdatasize - occ;
614 if (!TIFFFlushData1(tif))
617 occ = tif->tif_rawdatasize - tif->tif_rawcc;
619 *op++ = (uint8) j; occ--;
621 *op++ = (uint8)(tp[i++] >> shft & 0xff);
625 if (rc >= MINRUN) { /* write out run */
626 *op++ = (uint8) (128-2+rc);
627 *op++ = (uint8)(tp[beg] >> shft & 0xff);
633 tif->tif_rawcc = tif->tif_rawdatasize - occ;
639 * Encode a strip of pixels. We break it into rows to
640 * avoid encoding runs across row boundaries.
643 LogLuvEncodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
645 tmsize_t rowlen = TIFFScanlineSize(tif);
647 assert(cc%rowlen == 0);
648 while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1)
649 bp += rowlen, cc -= rowlen;
654 * Encode a tile of pixels. We break it into rows to
655 * avoid encoding runs across row boundaries.
658 LogLuvEncodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
660 tmsize_t rowlen = TIFFTileRowSize(tif);
662 assert(cc%rowlen == 0);
663 while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1)
664 bp += rowlen, cc -= rowlen;
669 * Encode/Decode functions for converting to and from user formats.
675 #define U_NEU 0.210526316
676 #define V_NEU 0.473684211
681 #define M_LN2 0.69314718055994530942
684 #define M_PI 3.14159265358979323846
687 #define log2(x) ((1./M_LN2)*log(x))
689 #define exp2(x) exp(M_LN2*(x))
691 #define itrunc(x,m) ((m)==SGILOGENCODE_NODITHER ? \
693 (int)((x) + rand()*(1./RAND_MAX) - .5))
699 LogL16toY(int p16) /* compute luminance from 16-bit LogL */
701 int Le = p16 & 0x7fff;
706 Y = exp(M_LN2/256.*(Le+.5) - M_LN2*64.);
707 return (!(p16 & 0x8000) ? Y : -Y);
714 LogL16fromY(double Y, int em) /* get 16-bit LogL from Y */
716 if (Y >= 1.8371976e19)
718 if (Y <= -1.8371976e19)
720 if (Y > 5.4136769e-20)
721 return itrunc(256.*(log2(Y) + 64.), em);
722 if (Y < -5.4136769e-20)
723 return (~0x7fff | itrunc(256.*(log2(-Y) + 64.), em));
728 L16toY(LogLuvState* sp, uint8* op, tmsize_t n)
730 int16* l16 = (int16*) sp->tbuf;
731 float* yp = (float*) op;
734 *yp++ = (float)LogL16toY(*l16++);
738 L16toGry(LogLuvState* sp, uint8* op, tmsize_t n)
740 int16* l16 = (int16*) sp->tbuf;
741 uint8* gp = (uint8*) op;
744 double Y = LogL16toY(*l16++);
745 *gp++ = (uint8) ((Y <= 0.) ? 0 : (Y >= 1.) ? 255 : (int)(256.*sqrt(Y)));
750 L16fromY(LogLuvState* sp, uint8* op, tmsize_t n)
752 int16* l16 = (int16*) sp->tbuf;
753 float* yp = (float*) op;
756 *l16++ = (int16) (LogL16fromY(*yp++, sp->encode_meth));
763 XYZtoRGB24(float xyz[3], uint8 rgb[3])
766 /* assume CCIR-709 primaries */
767 r = 2.690*xyz[0] + -1.276*xyz[1] + -0.414*xyz[2];
768 g = -1.022*xyz[0] + 1.978*xyz[1] + 0.044*xyz[2];
769 b = 0.061*xyz[0] + -0.224*xyz[1] + 1.163*xyz[2];
770 /* assume 2.0 gamma for speed */
771 /* could use integer sqrt approx., but this is probably faster */
772 rgb[0] = (uint8)((r<=0.) ? 0 : (r >= 1.) ? 255 : (int)(256.*sqrt(r)));
773 rgb[1] = (uint8)((g<=0.) ? 0 : (g >= 1.) ? 255 : (int)(256.*sqrt(g)));
774 rgb[2] = (uint8)((b<=0.) ? 0 : (b >= 1.) ? 255 : (int)(256.*sqrt(b)));
781 LogL10toY(int p10) /* compute luminance from 10-bit LogL */
785 return (exp(M_LN2/64.*(p10+.5) - M_LN2*12.));
792 LogL10fromY(double Y, int em) /* get 10-bit LogL from Y */
796 else if (Y <= .00024283)
799 return itrunc(64.*(log2(Y) + 12.), em);
803 #define uv2ang(u, v) ( (NANGLES*.499999999/M_PI) \
804 * atan2((v)-V_NEU,(u)-U_NEU) + .5*NANGLES )
807 oog_encode(double u, double v) /* encode out-of-gamut chroma */
809 static int oog_table[NANGLES];
810 static int initialized = 0;
813 if (!initialized) { /* set up perimeter table */
814 double eps[NANGLES], ua, va, ang, epsa;
816 for (i = NANGLES; i--; )
818 for (vi = UV_NVS; vi--; ) {
819 va = UV_VSTART + (vi+.5)*UV_SQSIZ;
820 ustep = uv_row[vi].nus-1;
821 if (vi == UV_NVS-1 || vi == 0 || ustep <= 0)
823 for (ui = uv_row[vi].nus-1; ui >= 0; ui -= ustep) {
824 ua = uv_row[vi].ustart + (ui+.5)*UV_SQSIZ;
825 ang = uv2ang(ua, va);
827 epsa = fabs(ang - (i+.5));
829 oog_table[i] = uv_row[vi].ncum + ui;
834 for (i = NANGLES; i--; ) /* fill any holes */
837 for (i1 = 1; i1 < NANGLES/2; i1++)
838 if (eps[(i+i1)%NANGLES] < 1.5)
840 for (i2 = 1; i2 < NANGLES/2; i2++)
841 if (eps[(i+NANGLES-i2)%NANGLES] < 1.5)
845 oog_table[(i+i1)%NANGLES];
848 oog_table[(i+NANGLES-i2)%NANGLES];
852 i = (int) uv2ang(u, v); /* look up hue angle */
853 return (oog_table[i]);
863 uv_encode(double u, double v, int em) /* encode (u',v') coordinates */
868 return oog_encode(u, v);
869 vi = itrunc((v - UV_VSTART)*(1./UV_SQSIZ), em);
871 return oog_encode(u, v);
872 if (u < uv_row[vi].ustart)
873 return oog_encode(u, v);
874 ui = itrunc((u - uv_row[vi].ustart)*(1./UV_SQSIZ), em);
875 if (ui >= uv_row[vi].nus)
876 return oog_encode(u, v);
878 return (uv_row[vi].ncum + ui);
885 uv_decode(double *up, double *vp, int c) /* decode (u',v') index */
890 if (c < 0 || c >= UV_NDIVS)
892 lower = 0; /* binary search */
894 while (upper - lower > 1) {
895 vi = (lower + upper) >> 1;
896 ui = c - uv_row[vi].ncum;
907 ui = c - uv_row[vi].ncum;
908 *up = uv_row[vi].ustart + (ui+.5)*UV_SQSIZ;
909 *vp = UV_VSTART + (vi+.5)*UV_SQSIZ;
917 LogLuv24toXYZ(uint32 p, float XYZ[3])
920 double L, u, v, s, x, y;
921 /* decode luminance */
922 L = LogL10toY(p>>14 & 0x3ff);
924 XYZ[0] = XYZ[1] = XYZ[2] = 0.;
929 if (uv_decode(&u, &v, Ce) < 0) {
930 u = U_NEU; v = V_NEU;
932 s = 1./(6.*u - 16.*v + 12.);
936 XYZ[0] = (float)(x/y * L);
938 XYZ[2] = (float)((1.-x-y)/y * L);
945 LogLuv24fromXYZ(float XYZ[3], int em)
949 /* encode luminance */
950 Le = LogL10fromY(XYZ[1], em);
952 s = XYZ[0] + 15.*XYZ[1] + 3.*XYZ[2];
953 if (!Le || s <= 0.) {
960 Ce = uv_encode(u, v, em);
961 if (Ce < 0) /* never happens */
962 Ce = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER);
963 /* combine encodings */
964 return (Le << 14 | Ce);
968 Luv24toXYZ(LogLuvState* sp, uint8* op, tmsize_t n)
970 uint32* luv = (uint32*) sp->tbuf;
971 float* xyz = (float*) op;
974 LogLuv24toXYZ(*luv, xyz);
981 Luv24toLuv48(LogLuvState* sp, uint8* op, tmsize_t n)
983 uint32* luv = (uint32*) sp->tbuf;
984 int16* luv3 = (int16*) op;
989 *luv3++ = (int16)((*luv >> 12 & 0xffd) + 13314);
990 if (uv_decode(&u, &v, *luv&0x3fff) < 0) {
994 *luv3++ = (int16)(u * (1L<<15));
995 *luv3++ = (int16)(v * (1L<<15));
1001 Luv24toRGB(LogLuvState* sp, uint8* op, tmsize_t n)
1003 uint32* luv = (uint32*) sp->tbuf;
1004 uint8* rgb = (uint8*) op;
1009 LogLuv24toXYZ(*luv++, xyz);
1010 XYZtoRGB24(xyz, rgb);
1016 Luv24fromXYZ(LogLuvState* sp, uint8* op, tmsize_t n)
1018 uint32* luv = (uint32*) sp->tbuf;
1019 float* xyz = (float*) op;
1022 *luv++ = LogLuv24fromXYZ(xyz, sp->encode_meth);
1028 Luv24fromLuv48(LogLuvState* sp, uint8* op, tmsize_t n)
1030 uint32* luv = (uint32*) sp->tbuf;
1031 int16* luv3 = (int16*) op;
1038 else if (luv3[0] >= (1<<12)+3314)
1040 else if (sp->encode_meth == SGILOGENCODE_NODITHER)
1041 Le = (luv3[0]-3314) >> 2;
1043 Le = itrunc(.25*(luv3[0]-3314.), sp->encode_meth);
1045 Ce = uv_encode((luv3[1]+.5)/(1<<15), (luv3[2]+.5)/(1<<15),
1047 if (Ce < 0) /* never happens */
1048 Ce = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER);
1049 *luv++ = (uint32)Le << 14 | Ce;
1058 LogLuv32toXYZ(uint32 p, float XYZ[3])
1060 double L, u, v, s, x, y;
1061 /* decode luminance */
1062 L = LogL16toY((int)p >> 16);
1064 XYZ[0] = XYZ[1] = XYZ[2] = 0.;
1068 u = 1./UVSCALE * ((p>>8 & 0xff) + .5);
1069 v = 1./UVSCALE * ((p & 0xff) + .5);
1070 s = 1./(6.*u - 16.*v + 12.);
1073 /* convert to XYZ */
1074 XYZ[0] = (float)(x/y * L);
1076 XYZ[2] = (float)((1.-x-y)/y * L);
1083 LogLuv32fromXYZ(float XYZ[3], int em)
1085 unsigned int Le, ue, ve;
1087 /* encode luminance */
1088 Le = (unsigned int)LogL16fromY(XYZ[1], em);
1090 s = XYZ[0] + 15.*XYZ[1] + 3.*XYZ[2];
1091 if (!Le || s <= 0.) {
1098 if (u <= 0.) ue = 0;
1099 else ue = itrunc(UVSCALE*u, em);
1100 if (ue > 255) ue = 255;
1101 if (v <= 0.) ve = 0;
1102 else ve = itrunc(UVSCALE*v, em);
1103 if (ve > 255) ve = 255;
1104 /* combine encodings */
1105 return (Le << 16 | ue << 8 | ve);
1109 Luv32toXYZ(LogLuvState* sp, uint8* op, tmsize_t n)
1111 uint32* luv = (uint32*) sp->tbuf;
1112 float* xyz = (float*) op;
1115 LogLuv32toXYZ(*luv++, xyz);
1121 Luv32toLuv48(LogLuvState* sp, uint8* op, tmsize_t n)
1123 uint32* luv = (uint32*) sp->tbuf;
1124 int16* luv3 = (int16*) op;
1129 *luv3++ = (int16)(*luv >> 16);
1130 u = 1./UVSCALE * ((*luv>>8 & 0xff) + .5);
1131 v = 1./UVSCALE * ((*luv & 0xff) + .5);
1132 *luv3++ = (int16)(u * (1L<<15));
1133 *luv3++ = (int16)(v * (1L<<15));
1139 Luv32toRGB(LogLuvState* sp, uint8* op, tmsize_t n)
1141 uint32* luv = (uint32*) sp->tbuf;
1142 uint8* rgb = (uint8*) op;
1147 LogLuv32toXYZ(*luv++, xyz);
1148 XYZtoRGB24(xyz, rgb);
1154 Luv32fromXYZ(LogLuvState* sp, uint8* op, tmsize_t n)
1156 uint32* luv = (uint32*) sp->tbuf;
1157 float* xyz = (float*) op;
1160 *luv++ = LogLuv32fromXYZ(xyz, sp->encode_meth);
1166 Luv32fromLuv48(LogLuvState* sp, uint8* op, tmsize_t n)
1168 uint32* luv = (uint32*) sp->tbuf;
1169 int16* luv3 = (int16*) op;
1171 if (sp->encode_meth == SGILOGENCODE_NODITHER) {
1173 *luv++ = (uint32)luv3[0] << 16 |
1174 (luv3[1]*(uint32)(UVSCALE+.5) >> 7 & 0xff00) |
1175 (luv3[2]*(uint32)(UVSCALE+.5) >> 15 & 0xff);
1181 *luv++ = (uint32)luv3[0] << 16 |
1182 (itrunc(luv3[1]*(UVSCALE/(1<<15)), sp->encode_meth) << 8 & 0xff00) |
1183 (itrunc(luv3[2]*(UVSCALE/(1<<15)), sp->encode_meth) & 0xff);
1189 _logLuvNop(LogLuvState* sp, uint8* op, tmsize_t n)
1191 (void) sp; (void) op; (void) n;
1195 LogL16GuessDataFmt(TIFFDirectory *td)
1197 #define PACK(s,b,f) (((b)<<6)|((s)<<3)|(f))
1198 switch (PACK(td->td_samplesperpixel, td->td_bitspersample, td->td_sampleformat)) {
1199 case PACK(1, 32, SAMPLEFORMAT_IEEEFP):
1200 return (SGILOGDATAFMT_FLOAT);
1201 case PACK(1, 16, SAMPLEFORMAT_VOID):
1202 case PACK(1, 16, SAMPLEFORMAT_INT):
1203 case PACK(1, 16, SAMPLEFORMAT_UINT):
1204 return (SGILOGDATAFMT_16BIT);
1205 case PACK(1, 8, SAMPLEFORMAT_VOID):
1206 case PACK(1, 8, SAMPLEFORMAT_UINT):
1207 return (SGILOGDATAFMT_8BIT);
1210 return (SGILOGDATAFMT_UNKNOWN);
1214 multiply_ms(tmsize_t m1, tmsize_t m2)
1216 tmsize_t bytes = m1 * m2;
1218 if (m1 && bytes / m1 != m2)
1225 LogL16InitState(TIFF* tif)
1227 static const char module[] = "LogL16InitState";
1228 TIFFDirectory *td = &tif->tif_dir;
1229 LogLuvState* sp = DecoderState(tif);
1232 assert(td->td_photometric == PHOTOMETRIC_LOGL);
1234 /* for some reason, we can't do this in TIFFInitLogL16 */
1235 if (sp->user_datafmt == SGILOGDATAFMT_UNKNOWN)
1236 sp->user_datafmt = LogL16GuessDataFmt(td);
1237 switch (sp->user_datafmt) {
1238 case SGILOGDATAFMT_FLOAT:
1239 sp->pixel_size = sizeof (float);
1241 case SGILOGDATAFMT_16BIT:
1242 sp->pixel_size = sizeof (int16);
1244 case SGILOGDATAFMT_8BIT:
1245 sp->pixel_size = sizeof (uint8);
1248 TIFFErrorExt(tif->tif_clientdata, module,
1249 "No support for converting user data format to LogL");
1253 sp->tbuflen = multiply_ms(td->td_tilewidth, td->td_tilelength);
1255 sp->tbuflen = multiply_ms(td->td_imagewidth, td->td_rowsperstrip);
1256 if (multiply_ms(sp->tbuflen, sizeof (int16)) == 0 ||
1257 (sp->tbuf = (uint8*) _TIFFmalloc(sp->tbuflen * sizeof (int16))) == NULL) {
1258 TIFFErrorExt(tif->tif_clientdata, module, "No space for SGILog translation buffer");
1265 LogLuvGuessDataFmt(TIFFDirectory *td)
1270 * If the user didn't tell us their datafmt,
1271 * take our best guess from the bitspersample.
1273 #define PACK(a,b) (((a)<<3)|(b))
1274 switch (PACK(td->td_bitspersample, td->td_sampleformat)) {
1275 case PACK(32, SAMPLEFORMAT_IEEEFP):
1276 guess = SGILOGDATAFMT_FLOAT;
1278 case PACK(32, SAMPLEFORMAT_VOID):
1279 case PACK(32, SAMPLEFORMAT_UINT):
1280 case PACK(32, SAMPLEFORMAT_INT):
1281 guess = SGILOGDATAFMT_RAW;
1283 case PACK(16, SAMPLEFORMAT_VOID):
1284 case PACK(16, SAMPLEFORMAT_INT):
1285 case PACK(16, SAMPLEFORMAT_UINT):
1286 guess = SGILOGDATAFMT_16BIT;
1288 case PACK( 8, SAMPLEFORMAT_VOID):
1289 case PACK( 8, SAMPLEFORMAT_UINT):
1290 guess = SGILOGDATAFMT_8BIT;
1293 guess = SGILOGDATAFMT_UNKNOWN;
1298 * Double-check samples per pixel.
1300 switch (td->td_samplesperpixel) {
1302 if (guess != SGILOGDATAFMT_RAW)
1303 guess = SGILOGDATAFMT_UNKNOWN;
1306 if (guess == SGILOGDATAFMT_RAW)
1307 guess = SGILOGDATAFMT_UNKNOWN;
1310 guess = SGILOGDATAFMT_UNKNOWN;
1317 LogLuvInitState(TIFF* tif)
1319 static const char module[] = "LogLuvInitState";
1320 TIFFDirectory* td = &tif->tif_dir;
1321 LogLuvState* sp = DecoderState(tif);
1324 assert(td->td_photometric == PHOTOMETRIC_LOGLUV);
1326 /* for some reason, we can't do this in TIFFInitLogLuv */
1327 if (td->td_planarconfig != PLANARCONFIG_CONTIG) {
1328 TIFFErrorExt(tif->tif_clientdata, module,
1329 "SGILog compression cannot handle non-contiguous data");
1332 if (sp->user_datafmt == SGILOGDATAFMT_UNKNOWN)
1333 sp->user_datafmt = LogLuvGuessDataFmt(td);
1334 switch (sp->user_datafmt) {
1335 case SGILOGDATAFMT_FLOAT:
1336 sp->pixel_size = 3*sizeof (float);
1338 case SGILOGDATAFMT_16BIT:
1339 sp->pixel_size = 3*sizeof (int16);
1341 case SGILOGDATAFMT_RAW:
1342 sp->pixel_size = sizeof (uint32);
1344 case SGILOGDATAFMT_8BIT:
1345 sp->pixel_size = 3*sizeof (uint8);
1348 TIFFErrorExt(tif->tif_clientdata, module,
1349 "No support for converting user data format to LogLuv");
1353 sp->tbuflen = multiply_ms(td->td_tilewidth, td->td_tilelength);
1355 sp->tbuflen = multiply_ms(td->td_imagewidth, td->td_rowsperstrip);
1356 if (multiply_ms(sp->tbuflen, sizeof (uint32)) == 0 ||
1357 (sp->tbuf = (uint8*) _TIFFmalloc(sp->tbuflen * sizeof (uint32))) == NULL) {
1358 TIFFErrorExt(tif->tif_clientdata, module, "No space for SGILog translation buffer");
1365 LogLuvFixupTags(TIFF* tif)
1372 LogLuvSetupDecode(TIFF* tif)
1374 static const char module[] = "LogLuvSetupDecode";
1375 LogLuvState* sp = DecoderState(tif);
1376 TIFFDirectory* td = &tif->tif_dir;
1378 tif->tif_postdecode = _TIFFNoPostDecode;
1379 switch (td->td_photometric) {
1380 case PHOTOMETRIC_LOGLUV:
1381 if (!LogLuvInitState(tif))
1383 if (td->td_compression == COMPRESSION_SGILOG24) {
1384 tif->tif_decoderow = LogLuvDecode24;
1385 switch (sp->user_datafmt) {
1386 case SGILOGDATAFMT_FLOAT:
1387 sp->tfunc = Luv24toXYZ;
1389 case SGILOGDATAFMT_16BIT:
1390 sp->tfunc = Luv24toLuv48;
1392 case SGILOGDATAFMT_8BIT:
1393 sp->tfunc = Luv24toRGB;
1397 tif->tif_decoderow = LogLuvDecode32;
1398 switch (sp->user_datafmt) {
1399 case SGILOGDATAFMT_FLOAT:
1400 sp->tfunc = Luv32toXYZ;
1402 case SGILOGDATAFMT_16BIT:
1403 sp->tfunc = Luv32toLuv48;
1405 case SGILOGDATAFMT_8BIT:
1406 sp->tfunc = Luv32toRGB;
1411 case PHOTOMETRIC_LOGL:
1412 if (!LogL16InitState(tif))
1414 tif->tif_decoderow = LogL16Decode;
1415 switch (sp->user_datafmt) {
1416 case SGILOGDATAFMT_FLOAT:
1419 case SGILOGDATAFMT_8BIT:
1420 sp->tfunc = L16toGry;
1425 TIFFErrorExt(tif->tif_clientdata, module,
1426 "Inappropriate photometric interpretation %d for SGILog compression; %s",
1427 td->td_photometric, "must be either LogLUV or LogL");
1434 LogLuvSetupEncode(TIFF* tif)
1436 static const char module[] = "LogLuvSetupEncode";
1437 LogLuvState* sp = EncoderState(tif);
1438 TIFFDirectory* td = &tif->tif_dir;
1440 switch (td->td_photometric) {
1441 case PHOTOMETRIC_LOGLUV:
1442 if (!LogLuvInitState(tif))
1444 if (td->td_compression == COMPRESSION_SGILOG24) {
1445 tif->tif_encoderow = LogLuvEncode24;
1446 switch (sp->user_datafmt) {
1447 case SGILOGDATAFMT_FLOAT:
1448 sp->tfunc = Luv24fromXYZ;
1450 case SGILOGDATAFMT_16BIT:
1451 sp->tfunc = Luv24fromLuv48;
1453 case SGILOGDATAFMT_RAW:
1459 tif->tif_encoderow = LogLuvEncode32;
1460 switch (sp->user_datafmt) {
1461 case SGILOGDATAFMT_FLOAT:
1462 sp->tfunc = Luv32fromXYZ;
1464 case SGILOGDATAFMT_16BIT:
1465 sp->tfunc = Luv32fromLuv48;
1467 case SGILOGDATAFMT_RAW:
1474 case PHOTOMETRIC_LOGL:
1475 if (!LogL16InitState(tif))
1477 tif->tif_encoderow = LogL16Encode;
1478 switch (sp->user_datafmt) {
1479 case SGILOGDATAFMT_FLOAT:
1480 sp->tfunc = L16fromY;
1482 case SGILOGDATAFMT_16BIT:
1489 TIFFErrorExt(tif->tif_clientdata, module,
1490 "Inappropriate photometric interpretation %d for SGILog compression; %s",
1491 td->td_photometric, "must be either LogLUV or LogL");
1496 TIFFErrorExt(tif->tif_clientdata, module,
1497 "SGILog compression supported only for %s, or raw data",
1498 td->td_photometric == PHOTOMETRIC_LOGL ? "Y, L" : "XYZ, Luv");
1503 LogLuvClose(TIFF* tif)
1505 TIFFDirectory *td = &tif->tif_dir;
1508 * For consistency, we always want to write out the same
1509 * bitspersample and sampleformat for our TIFF file,
1510 * regardless of the data format being used by the application.
1511 * Since this routine is called after tags have been set but
1512 * before they have been recorded in the file, we reset them here.
1514 td->td_samplesperpixel =
1515 (td->td_photometric == PHOTOMETRIC_LOGL) ? 1 : 3;
1516 td->td_bitspersample = 16;
1517 td->td_sampleformat = SAMPLEFORMAT_INT;
1521 LogLuvCleanup(TIFF* tif)
1523 LogLuvState* sp = (LogLuvState *)tif->tif_data;
1527 tif->tif_tagmethods.vgetfield = sp->vgetparent;
1528 tif->tif_tagmethods.vsetfield = sp->vsetparent;
1531 _TIFFfree(sp->tbuf);
1533 tif->tif_data = NULL;
1535 _TIFFSetDefaultCompressionState(tif);
1539 LogLuvVSetField(TIFF* tif, uint32 tag, va_list ap)
1541 static const char module[] = "LogLuvVSetField";
1542 LogLuvState* sp = DecoderState(tif);
1546 case TIFFTAG_SGILOGDATAFMT:
1547 sp->user_datafmt = (int) va_arg(ap, int);
1549 * Tweak the TIFF header so that the rest of libtiff knows what
1550 * size of data will be passed between app and library, and
1551 * assume that the app knows what it is doing and is not
1552 * confused by these header manipulations...
1554 switch (sp->user_datafmt) {
1555 case SGILOGDATAFMT_FLOAT:
1556 bps = 32, fmt = SAMPLEFORMAT_IEEEFP;
1558 case SGILOGDATAFMT_16BIT:
1559 bps = 16, fmt = SAMPLEFORMAT_INT;
1561 case SGILOGDATAFMT_RAW:
1562 bps = 32, fmt = SAMPLEFORMAT_UINT;
1563 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
1565 case SGILOGDATAFMT_8BIT:
1566 bps = 8, fmt = SAMPLEFORMAT_UINT;
1569 TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
1570 "Unknown data format %d for LogLuv compression",
1574 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps);
1575 TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, fmt);
1577 * Must recalculate sizes should bits/sample change.
1579 tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tmsize_t) -1;
1580 tif->tif_scanlinesize = TIFFScanlineSize(tif);
1582 case TIFFTAG_SGILOGENCODE:
1583 sp->encode_meth = (int) va_arg(ap, int);
1584 if (sp->encode_meth != SGILOGENCODE_NODITHER &&
1585 sp->encode_meth != SGILOGENCODE_RANDITHER) {
1586 TIFFErrorExt(tif->tif_clientdata, module,
1587 "Unknown encoding %d for LogLuv compression",
1593 return (*sp->vsetparent)(tif, tag, ap);
1598 LogLuvVGetField(TIFF* tif, uint32 tag, va_list ap)
1600 LogLuvState *sp = (LogLuvState *)tif->tif_data;
1603 case TIFFTAG_SGILOGDATAFMT:
1604 *va_arg(ap, int*) = sp->user_datafmt;
1607 return (*sp->vgetparent)(tif, tag, ap);
1611 static const TIFFField LogLuvFields[] = {
1612 { TIFFTAG_SGILOGDATAFMT, 0, 0, TIFF_SHORT, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "SGILogDataFmt", NULL},
1613 { TIFFTAG_SGILOGENCODE, 0, 0, TIFF_SHORT, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "SGILogEncode", NULL}
1617 TIFFInitSGILog(TIFF* tif, int scheme)
1619 static const char module[] = "TIFFInitSGILog";
1622 assert(scheme == COMPRESSION_SGILOG24 || scheme == COMPRESSION_SGILOG);
1625 * Merge codec-specific tag information.
1627 if (!_TIFFMergeFields(tif, LogLuvFields,
1628 TIFFArrayCount(LogLuvFields))) {
1629 TIFFErrorExt(tif->tif_clientdata, module,
1630 "Merging SGILog codec-specific tags failed");
1635 * Allocate state block so tag methods have storage to record values.
1637 tif->tif_data = (uint8*) _TIFFmalloc(sizeof (LogLuvState));
1638 if (tif->tif_data == NULL)
1640 sp = (LogLuvState*) tif->tif_data;
1641 _TIFFmemset((void*)sp, 0, sizeof (*sp));
1642 sp->user_datafmt = SGILOGDATAFMT_UNKNOWN;
1643 sp->encode_meth = (scheme == COMPRESSION_SGILOG24) ?
1644 SGILOGENCODE_RANDITHER : SGILOGENCODE_NODITHER;
1645 sp->tfunc = _logLuvNop;
1648 * Install codec methods.
1649 * NB: tif_decoderow & tif_encoderow are filled
1652 tif->tif_fixuptags = LogLuvFixupTags;
1653 tif->tif_setupdecode = LogLuvSetupDecode;
1654 tif->tif_decodestrip = LogLuvDecodeStrip;
1655 tif->tif_decodetile = LogLuvDecodeTile;
1656 tif->tif_setupencode = LogLuvSetupEncode;
1657 tif->tif_encodestrip = LogLuvEncodeStrip;
1658 tif->tif_encodetile = LogLuvEncodeTile;
1659 tif->tif_close = LogLuvClose;
1660 tif->tif_cleanup = LogLuvCleanup;
1663 * Override parent get/set field methods.
1665 sp->vgetparent = tif->tif_tagmethods.vgetfield;
1666 tif->tif_tagmethods.vgetfield = LogLuvVGetField; /* hook for codec tags */
1667 sp->vsetparent = tif->tif_tagmethods.vsetfield;
1668 tif->tif_tagmethods.vsetfield = LogLuvVSetField; /* hook for codec tags */
1672 TIFFErrorExt(tif->tif_clientdata, module,
1673 "%s: No space for LogLuv state block", tif->tif_name);
1676 #endif /* LOGLUV_SUPPORT */
1678 /* vim: set ts=8 sts=8 sw=8 noet: */