3 * Copyright (c) 1996-1997 Sam Leffler
4 * Copyright (c) 1996 Pixar
6 * Permission to use, copy, modify, distribute, and sell this software and
7 * its documentation for any purpose is hereby granted without fee, provided
8 * that (i) the above copyright notices and this permission notice appear in
9 * all copies of the software and related documentation, and (ii) the names of
10 * Pixar, Sam Leffler and Silicon Graphics may not be used in any advertising or
11 * publicity relating to the software without the specific, prior written
12 * permission of Pixar, Sam Leffler and Silicon Graphics.
14 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
16 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18 * IN NO EVENT SHALL PIXAR, SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
19 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
20 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
21 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
22 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
27 #ifdef PIXARLOG_SUPPORT
31 * PixarLog Compression Support
33 * Contributed by Dan McCoy.
35 * PixarLog film support uses the TIFF library to store companded
36 * 11 bit values into a tiff file, which are compressed using the
39 * The codec can take as input and produce as output 32-bit IEEE float values
40 * as well as 16-bit or 8-bit unsigned integer values.
42 * On writing any of the above are converted into the internal
43 * 11-bit log format. In the case of 8 and 16 bit values, the
44 * input is assumed to be unsigned linear color values that represent
45 * the range 0-1. In the case of IEEE values, the 0-1 range is assumed to
46 * be the normal linear color range, in addition over 1 values are
47 * accepted up to a value of about 25.0 to encode "hot" hightlights and such.
48 * The encoding is lossless for 8-bit values, slightly lossy for the
49 * other bit depths. The actual color precision should be better
50 * than the human eye can perceive with extra room to allow for
51 * error introduced by further image computation. As with any quantized
52 * color format, it is possible to perform image calculations which
53 * expose the quantization error. This format should certainly be less
54 * susceptable to such errors than standard 8-bit encodings, but more
55 * susceptable than straight 16-bit or 32-bit encodings.
57 * On reading the internal format is converted to the desired output format.
58 * The program can request which format it desires by setting the internal
59 * pseudo tag TIFFTAG_PIXARLOGDATAFMT to one of these possible values:
60 * PIXARLOGDATAFMT_FLOAT = provide IEEE float values.
61 * PIXARLOGDATAFMT_16BIT = provide unsigned 16-bit integer values
62 * PIXARLOGDATAFMT_8BIT = provide unsigned 8-bit integer values
64 * alternately PIXARLOGDATAFMT_8BITABGR provides unsigned 8-bit integer
65 * values with the difference that if there are exactly three or four channels
66 * (rgb or rgba) it swaps the channel order (bgr or abgr).
68 * PIXARLOGDATAFMT_11BITLOG provides the internal encoding directly
69 * packed in 16-bit values. However no tools are supplied for interpreting
72 * "hot" (over 1.0) areas written in floating point get clamped to
73 * 1.0 in the integer data types.
75 * When the file is closed after writing, the bit depth and sample format
76 * are set always to appear as if 8-bit data has been written into it.
77 * That way a naive program unaware of the particulars of the encoding
78 * gets the format it is most likely able to handle.
80 * The codec does it's own horizontal differencing step on the coded
81 * values so the libraries predictor stuff should be turned off.
82 * The codec also handle byte swapping the encoded values as necessary
83 * since the library does not have the information necessary
84 * to know the bit depth of the raw unencoded buffer.
86 * NOTE: This decoder does not appear to update tif_rawcp, and tif_rawcc.
87 * This can cause problems with the implementation of CHUNKY_STRIP_READ_SUPPORT
88 * as noted in http://trac.osgeo.org/gdal/ticket/3894. FrankW - Jan'11
91 #include "tif_predict.h"
98 /* Tables for converting to/from 11 bit coded values */
100 #define TSIZE 2048 /* decode table size (11-bit tokens) */
101 #define TSIZEP1 2049 /* Plus one for slop */
102 #define ONE 1250 /* token value of 1.0 exactly */
103 #define RATIO 1.004 /* nominal ratio for log part */
105 #define CODE_MASK 0x7ff /* 11 bits. */
107 static float Fltsize
;
108 static float LogK1
, LogK2
;
110 #define REPEAT(n, op) { int i; i=n; do { i--; op; } while (i>0); }
113 horizontalAccumulateF(uint16
*wp
, int n
, int stride
, float *op
,
116 register unsigned int cr
, cg
, cb
, ca
, mask
;
117 register float t0
, t1
, t2
, t3
;
122 t0
= ToLinearF
[cr
= (wp
[0] & mask
)];
123 t1
= ToLinearF
[cg
= (wp
[1] & mask
)];
124 t2
= ToLinearF
[cb
= (wp
[2] & mask
)];
133 t0
= ToLinearF
[(cr
+= wp
[0]) & mask
];
134 t1
= ToLinearF
[(cg
+= wp
[1]) & mask
];
135 t2
= ToLinearF
[(cb
+= wp
[2]) & mask
];
140 } else if (stride
== 4) {
141 t0
= ToLinearF
[cr
= (wp
[0] & mask
)];
142 t1
= ToLinearF
[cg
= (wp
[1] & mask
)];
143 t2
= ToLinearF
[cb
= (wp
[2] & mask
)];
144 t3
= ToLinearF
[ca
= (wp
[3] & mask
)];
154 t0
= ToLinearF
[(cr
+= wp
[0]) & mask
];
155 t1
= ToLinearF
[(cg
+= wp
[1]) & mask
];
156 t2
= ToLinearF
[(cb
+= wp
[2]) & mask
];
157 t3
= ToLinearF
[(ca
+= wp
[3]) & mask
];
164 REPEAT(stride
, *op
= ToLinearF
[*wp
&mask
]; wp
++; op
++)
168 wp
[stride
] += *wp
; *op
= ToLinearF
[*wp
&mask
]; wp
++; op
++)
176 horizontalAccumulate12(uint16
*wp
, int n
, int stride
, int16
*op
,
179 register unsigned int cr
, cg
, cb
, ca
, mask
;
180 register float t0
, t1
, t2
, t3
;
182 #define SCALE12 2048.0F
183 #define CLAMP12(t) (((t) < 3071) ? (uint16) (t) : 3071)
188 t0
= ToLinearF
[cr
= (wp
[0] & mask
)] * SCALE12
;
189 t1
= ToLinearF
[cg
= (wp
[1] & mask
)] * SCALE12
;
190 t2
= ToLinearF
[cb
= (wp
[2] & mask
)] * SCALE12
;
199 t0
= ToLinearF
[(cr
+= wp
[0]) & mask
] * SCALE12
;
200 t1
= ToLinearF
[(cg
+= wp
[1]) & mask
] * SCALE12
;
201 t2
= ToLinearF
[(cb
+= wp
[2]) & mask
] * SCALE12
;
206 } else if (stride
== 4) {
207 t0
= ToLinearF
[cr
= (wp
[0] & mask
)] * SCALE12
;
208 t1
= ToLinearF
[cg
= (wp
[1] & mask
)] * SCALE12
;
209 t2
= ToLinearF
[cb
= (wp
[2] & mask
)] * SCALE12
;
210 t3
= ToLinearF
[ca
= (wp
[3] & mask
)] * SCALE12
;
220 t0
= ToLinearF
[(cr
+= wp
[0]) & mask
] * SCALE12
;
221 t1
= ToLinearF
[(cg
+= wp
[1]) & mask
] * SCALE12
;
222 t2
= ToLinearF
[(cb
+= wp
[2]) & mask
] * SCALE12
;
223 t3
= ToLinearF
[(ca
+= wp
[3]) & mask
] * SCALE12
;
230 REPEAT(stride
, t0
= ToLinearF
[*wp
&mask
] * SCALE12
;
231 *op
= CLAMP12(t0
); wp
++; op
++)
235 wp
[stride
] += *wp
; t0
= ToLinearF
[wp
[stride
]&mask
]*SCALE12
;
236 *op
= CLAMP12(t0
); wp
++; op
++)
244 horizontalAccumulate16(uint16
*wp
, int n
, int stride
, uint16
*op
,
247 register unsigned int cr
, cg
, cb
, ca
, mask
;
252 op
[0] = ToLinear16
[cr
= (wp
[0] & mask
)];
253 op
[1] = ToLinear16
[cg
= (wp
[1] & mask
)];
254 op
[2] = ToLinear16
[cb
= (wp
[2] & mask
)];
260 op
[0] = ToLinear16
[(cr
+= wp
[0]) & mask
];
261 op
[1] = ToLinear16
[(cg
+= wp
[1]) & mask
];
262 op
[2] = ToLinear16
[(cb
+= wp
[2]) & mask
];
264 } else if (stride
== 4) {
265 op
[0] = ToLinear16
[cr
= (wp
[0] & mask
)];
266 op
[1] = ToLinear16
[cg
= (wp
[1] & mask
)];
267 op
[2] = ToLinear16
[cb
= (wp
[2] & mask
)];
268 op
[3] = ToLinear16
[ca
= (wp
[3] & mask
)];
274 op
[0] = ToLinear16
[(cr
+= wp
[0]) & mask
];
275 op
[1] = ToLinear16
[(cg
+= wp
[1]) & mask
];
276 op
[2] = ToLinear16
[(cb
+= wp
[2]) & mask
];
277 op
[3] = ToLinear16
[(ca
+= wp
[3]) & mask
];
280 REPEAT(stride
, *op
= ToLinear16
[*wp
&mask
]; wp
++; op
++)
284 wp
[stride
] += *wp
; *op
= ToLinear16
[*wp
&mask
]; wp
++; op
++)
292 * Returns the log encoded 11-bit values with the horizontal
293 * differencing undone.
296 horizontalAccumulate11(uint16
*wp
, int n
, int stride
, uint16
*op
)
298 register unsigned int cr
, cg
, cb
, ca
, mask
;
303 op
[0] = cr
= wp
[0]; op
[1] = cg
= wp
[1]; op
[2] = cb
= wp
[2];
309 op
[0] = (cr
+= wp
[0]) & mask
;
310 op
[1] = (cg
+= wp
[1]) & mask
;
311 op
[2] = (cb
+= wp
[2]) & mask
;
313 } else if (stride
== 4) {
314 op
[0] = cr
= wp
[0]; op
[1] = cg
= wp
[1];
315 op
[2] = cb
= wp
[2]; op
[3] = ca
= wp
[3];
321 op
[0] = (cr
+= wp
[0]) & mask
;
322 op
[1] = (cg
+= wp
[1]) & mask
;
323 op
[2] = (cb
+= wp
[2]) & mask
;
324 op
[3] = (ca
+= wp
[3]) & mask
;
327 REPEAT(stride
, *op
= *wp
&mask
; wp
++; op
++)
331 wp
[stride
] += *wp
; *op
= *wp
&mask
; wp
++; op
++)
339 horizontalAccumulate8(uint16
*wp
, int n
, int stride
, unsigned char *op
,
340 unsigned char *ToLinear8
)
342 register unsigned int cr
, cg
, cb
, ca
, mask
;
347 op
[0] = ToLinear8
[cr
= (wp
[0] & mask
)];
348 op
[1] = ToLinear8
[cg
= (wp
[1] & mask
)];
349 op
[2] = ToLinear8
[cb
= (wp
[2] & mask
)];
355 op
[0] = ToLinear8
[(cr
+= wp
[0]) & mask
];
356 op
[1] = ToLinear8
[(cg
+= wp
[1]) & mask
];
357 op
[2] = ToLinear8
[(cb
+= wp
[2]) & mask
];
359 } else if (stride
== 4) {
360 op
[0] = ToLinear8
[cr
= (wp
[0] & mask
)];
361 op
[1] = ToLinear8
[cg
= (wp
[1] & mask
)];
362 op
[2] = ToLinear8
[cb
= (wp
[2] & mask
)];
363 op
[3] = ToLinear8
[ca
= (wp
[3] & mask
)];
369 op
[0] = ToLinear8
[(cr
+= wp
[0]) & mask
];
370 op
[1] = ToLinear8
[(cg
+= wp
[1]) & mask
];
371 op
[2] = ToLinear8
[(cb
+= wp
[2]) & mask
];
372 op
[3] = ToLinear8
[(ca
+= wp
[3]) & mask
];
375 REPEAT(stride
, *op
= ToLinear8
[*wp
&mask
]; wp
++; op
++)
379 wp
[stride
] += *wp
; *op
= ToLinear8
[*wp
&mask
]; wp
++; op
++)
388 horizontalAccumulate8abgr(uint16
*wp
, int n
, int stride
, unsigned char *op
,
389 unsigned char *ToLinear8
)
391 register unsigned int cr
, cg
, cb
, ca
, mask
;
392 register unsigned char t0
, t1
, t2
, t3
;
398 t1
= ToLinear8
[cb
= (wp
[2] & mask
)];
399 t2
= ToLinear8
[cg
= (wp
[1] & mask
)];
400 t3
= ToLinear8
[cr
= (wp
[0] & mask
)];
410 t1
= ToLinear8
[(cb
+= wp
[2]) & mask
];
411 t2
= ToLinear8
[(cg
+= wp
[1]) & mask
];
412 t3
= ToLinear8
[(cr
+= wp
[0]) & mask
];
417 } else if (stride
== 4) {
418 t0
= ToLinear8
[ca
= (wp
[3] & mask
)];
419 t1
= ToLinear8
[cb
= (wp
[2] & mask
)];
420 t2
= ToLinear8
[cg
= (wp
[1] & mask
)];
421 t3
= ToLinear8
[cr
= (wp
[0] & mask
)];
431 t0
= ToLinear8
[(ca
+= wp
[3]) & mask
];
432 t1
= ToLinear8
[(cb
+= wp
[2]) & mask
];
433 t2
= ToLinear8
[(cg
+= wp
[1]) & mask
];
434 t3
= ToLinear8
[(cr
+= wp
[0]) & mask
];
441 REPEAT(stride
, *op
= ToLinear8
[*wp
&mask
]; wp
++; op
++)
445 wp
[stride
] += *wp
; *op
= ToLinear8
[*wp
&mask
]; wp
++; op
++)
453 * State block for each open TIFF
454 * file using PixarLog compression/decompression.
457 TIFFPredictorState predict
;
464 #define PLSTATE_INIT 1
466 TIFFVSetMethod vgetparent
; /* super-class method */
467 TIFFVSetMethod vsetparent
; /* super-class method */
471 unsigned char *ToLinear8
;
473 uint16
*From14
; /* Really for 16-bit data, but we shift down 2 */
479 PixarLogMakeTables(PixarLogState
*sp
)
483 * We make several tables here to convert between various external
484 * representations (float, 16-bit, and 8-bit) and the internal
485 * 11-bit companded representation. The 11-bit representation has two
486 * distinct regions. A linear bottom end up through .018316 in steps
487 * of about .000073, and a region of constant ratio up to about 25.
488 * These floating point numbers are stored in the main table ToLinearF.
489 * All other tables are derived from this one. The tables (and the
490 * ratios) are continuous at the internal seam.
495 double b
, c
, linstep
, v
;
498 unsigned char *ToLinear8
;
500 uint16
*From14
; /* Really for 16-bit data, but we shift down 2 */
504 nlin
= (int)(1./c
); /* nlin must be an integer */
506 b
= exp(-c
*ONE
); /* multiplicative scale factor [b*exp(c*ONE) = 1] */
507 linstep
= b
*c
*exp(1.);
509 LogK1
= (float)(1./c
); /* if (v >= 2) token = k1*log(v*k2) */
510 LogK2
= (float)(1./b
);
511 lt2size
= (int)(2./linstep
) + 1;
512 FromLT2
= (uint16
*)_TIFFmalloc(lt2size
*sizeof(uint16
));
513 From14
= (uint16
*)_TIFFmalloc(16384*sizeof(uint16
));
514 From8
= (uint16
*)_TIFFmalloc(256*sizeof(uint16
));
515 ToLinearF
= (float *)_TIFFmalloc(TSIZEP1
* sizeof(float));
516 ToLinear16
= (uint16
*)_TIFFmalloc(TSIZEP1
* sizeof(uint16
));
517 ToLinear8
= (unsigned char *)_TIFFmalloc(TSIZEP1
* sizeof(unsigned char));
518 if (FromLT2
== NULL
|| From14
== NULL
|| From8
== NULL
||
519 ToLinearF
== NULL
|| ToLinear16
== NULL
|| ToLinear8
== NULL
) {
520 if (FromLT2
) _TIFFfree(FromLT2
);
521 if (From14
) _TIFFfree(From14
);
522 if (From8
) _TIFFfree(From8
);
523 if (ToLinearF
) _TIFFfree(ToLinearF
);
524 if (ToLinear16
) _TIFFfree(ToLinear16
);
525 if (ToLinear8
) _TIFFfree(ToLinear8
);
529 sp
->ToLinearF
= NULL
;
530 sp
->ToLinear16
= NULL
;
531 sp
->ToLinear8
= NULL
;
537 for (i
= 0; i
< nlin
; i
++) {
539 ToLinearF
[j
++] = (float)v
;
542 for (i
= nlin
; i
< TSIZE
; i
++)
543 ToLinearF
[j
++] = (float)(b
*exp(c
*i
));
545 ToLinearF
[2048] = ToLinearF
[2047];
547 for (i
= 0; i
< TSIZEP1
; i
++) {
548 v
= ToLinearF
[i
]*65535.0 + 0.5;
549 ToLinear16
[i
] = (v
> 65535.0) ? 65535 : (uint16
)v
;
550 v
= ToLinearF
[i
]*255.0 + 0.5;
551 ToLinear8
[i
] = (v
> 255.0) ? 255 : (unsigned char)v
;
555 for (i
= 0; i
< lt2size
; i
++) {
556 if ((i
*linstep
)*(i
*linstep
) > ToLinearF
[j
]*ToLinearF
[j
+1])
562 * Since we lose info anyway on 16-bit data, we set up a 14-bit
563 * table and shift 16-bit values down two bits on input.
564 * saves a little table space.
567 for (i
= 0; i
< 16384; i
++) {
568 while ((i
/16383.)*(i
/16383.) > ToLinearF
[j
]*ToLinearF
[j
+1])
574 for (i
= 0; i
< 256; i
++) {
575 while ((i
/255.)*(i
/255.) > ToLinearF
[j
]*ToLinearF
[j
+1])
580 Fltsize
= (float)(lt2size
/2);
582 sp
->ToLinearF
= ToLinearF
;
583 sp
->ToLinear16
= ToLinear16
;
584 sp
->ToLinear8
= ToLinear8
;
585 sp
->FromLT2
= FromLT2
;
592 #define DecoderState(tif) ((PixarLogState*) (tif)->tif_data)
593 #define EncoderState(tif) ((PixarLogState*) (tif)->tif_data)
595 static int PixarLogEncode(TIFF
* tif
, uint8
* bp
, tmsize_t cc
, uint16 s
);
596 static int PixarLogDecode(TIFF
* tif
, uint8
* op
, tmsize_t occ
, uint16 s
);
598 #define PIXARLOGDATAFMT_UNKNOWN -1
601 PixarLogGuessDataFmt(TIFFDirectory
*td
)
603 int guess
= PIXARLOGDATAFMT_UNKNOWN
;
604 int format
= td
->td_sampleformat
;
606 /* If the user didn't tell us his datafmt,
607 * take our best guess from the bitspersample.
609 switch (td
->td_bitspersample
) {
611 if (format
== SAMPLEFORMAT_IEEEFP
)
612 guess
= PIXARLOGDATAFMT_FLOAT
;
615 if (format
== SAMPLEFORMAT_VOID
|| format
== SAMPLEFORMAT_UINT
)
616 guess
= PIXARLOGDATAFMT_16BIT
;
619 if (format
== SAMPLEFORMAT_VOID
|| format
== SAMPLEFORMAT_INT
)
620 guess
= PIXARLOGDATAFMT_12BITPICIO
;
623 if (format
== SAMPLEFORMAT_VOID
|| format
== SAMPLEFORMAT_UINT
)
624 guess
= PIXARLOGDATAFMT_11BITLOG
;
627 if (format
== SAMPLEFORMAT_VOID
|| format
== SAMPLEFORMAT_UINT
)
628 guess
= PIXARLOGDATAFMT_8BIT
;
636 multiply_ms(tmsize_t m1
, tmsize_t m2
)
638 tmsize_t bytes
= m1
* m2
;
640 if (m1
&& bytes
/ m1
!= m2
)
647 PixarLogFixupTags(TIFF
* tif
)
654 PixarLogSetupDecode(TIFF
* tif
)
656 static const char module[] = "PixarLogSetupDecode";
657 TIFFDirectory
*td
= &tif
->tif_dir
;
658 PixarLogState
* sp
= DecoderState(tif
);
663 /* Make sure no byte swapping happens on the data
664 * after decompression. */
665 tif
->tif_postdecode
= _TIFFNoPostDecode
;
667 /* for some reason, we can't do this in TIFFInitPixarLog */
669 sp
->stride
= (td
->td_planarconfig
== PLANARCONFIG_CONTIG
?
670 td
->td_samplesperpixel
: 1);
671 tbuf_size
= multiply_ms(multiply_ms(multiply_ms(sp
->stride
, td
->td_imagewidth
),
672 td
->td_rowsperstrip
), sizeof(uint16
));
674 return (0); /* TODO: this is an error return without error report through TIFFErrorExt */
675 sp
->tbuf
= (uint16
*) _TIFFmalloc(tbuf_size
+sizeof(uint16
)*sp
->stride
);
676 if (sp
->tbuf
== NULL
)
678 if (sp
->user_datafmt
== PIXARLOGDATAFMT_UNKNOWN
)
679 sp
->user_datafmt
= PixarLogGuessDataFmt(td
);
680 if (sp
->user_datafmt
== PIXARLOGDATAFMT_UNKNOWN
) {
681 TIFFErrorExt(tif
->tif_clientdata
, module,
682 "PixarLog compression can't handle bits depth/data format combination (depth: %d)",
683 td
->td_bitspersample
);
687 if (inflateInit(&sp
->stream
) != Z_OK
) {
688 TIFFErrorExt(tif
->tif_clientdata
, module, "%s", sp
->stream
.msg
);
691 sp
->state
|= PLSTATE_INIT
;
697 * Setup state for decoding a strip.
700 PixarLogPreDecode(TIFF
* tif
, uint16 s
)
702 static const char module[] = "PixarLogPreDecode";
703 PixarLogState
* sp
= DecoderState(tif
);
707 sp
->stream
.next_in
= tif
->tif_rawdata
;
708 assert(sizeof(sp
->stream
.avail_in
)==4); /* if this assert gets raised,
709 we need to simplify this code to reflect a ZLib that is likely updated
710 to deal with 8byte memory sizes, though this code will respond
711 apropriately even before we simplify it */
712 sp
->stream
.avail_in
= (uInt
) tif
->tif_rawcc
;
713 if ((tmsize_t
)sp
->stream
.avail_in
!= tif
->tif_rawcc
)
715 TIFFErrorExt(tif
->tif_clientdata
, module, "ZLib cannot deal with buffers this size");
718 return (inflateReset(&sp
->stream
) == Z_OK
);
722 PixarLogDecode(TIFF
* tif
, uint8
* op
, tmsize_t occ
, uint16 s
)
724 static const char module[] = "PixarLogDecode";
725 TIFFDirectory
*td
= &tif
->tif_dir
;
726 PixarLogState
* sp
= DecoderState(tif
);
732 switch (sp
->user_datafmt
) {
733 case PIXARLOGDATAFMT_FLOAT
:
734 nsamples
= occ
/ sizeof(float); /* XXX float == 32 bits */
736 case PIXARLOGDATAFMT_16BIT
:
737 case PIXARLOGDATAFMT_12BITPICIO
:
738 case PIXARLOGDATAFMT_11BITLOG
:
739 nsamples
= occ
/ sizeof(uint16
); /* XXX uint16 == 16 bits */
741 case PIXARLOGDATAFMT_8BIT
:
742 case PIXARLOGDATAFMT_8BITABGR
:
746 TIFFErrorExt(tif
->tif_clientdata
, module,
747 "%d bit input not supported in PixarLog",
748 td
->td_bitspersample
);
752 llen
= sp
->stride
* td
->td_imagewidth
;
756 sp
->stream
.next_out
= (unsigned char *) sp
->tbuf
;
757 assert(sizeof(sp
->stream
.avail_out
)==4); /* if this assert gets raised,
758 we need to simplify this code to reflect a ZLib that is likely updated
759 to deal with 8byte memory sizes, though this code will respond
760 apropriately even before we simplify it */
761 sp
->stream
.avail_out
= (uInt
) (nsamples
* sizeof(uint16
));
762 if (sp
->stream
.avail_out
!= nsamples
* sizeof(uint16
))
764 TIFFErrorExt(tif
->tif_clientdata
, module, "ZLib cannot deal with buffers this size");
768 int state
= inflate(&sp
->stream
, Z_PARTIAL_FLUSH
);
769 if (state
== Z_STREAM_END
) {
772 if (state
== Z_DATA_ERROR
) {
773 TIFFErrorExt(tif
->tif_clientdata
, module,
774 "Decoding error at scanline %lu, %s",
775 (unsigned long) tif
->tif_row
, sp
->stream
.msg
);
776 if (inflateSync(&sp
->stream
) != Z_OK
)
781 TIFFErrorExt(tif
->tif_clientdata
, module, "ZLib error: %s",
785 } while (sp
->stream
.avail_out
> 0);
787 /* hopefully, we got all the bytes we needed */
788 if (sp
->stream
.avail_out
!= 0) {
789 TIFFErrorExt(tif
->tif_clientdata
, module,
790 "Not enough data at scanline %lu (short " TIFF_UINT64_FORMAT
" bytes)",
791 (unsigned long) tif
->tif_row
, (TIFF_UINT64_T
) sp
->stream
.avail_out
);
796 /* Swap bytes in the data if from a different endian machine. */
797 if (tif
->tif_flags
& TIFF_SWAB
)
798 TIFFSwabArrayOfShort(up
, nsamples
);
801 * if llen is not an exact multiple of nsamples, the decode operation
802 * may overflow the output buffer, so truncate it enough to prevent
803 * that but still salvage as much data as possible.
805 if (nsamples
% llen
) {
806 TIFFWarningExt(tif
->tif_clientdata
, module,
807 "stride %lu is not a multiple of sample count, "
808 "%lu, data truncated.", (unsigned long) llen
, (unsigned long) nsamples
);
809 nsamples
-= nsamples
% llen
;
812 for (i
= 0; i
< nsamples
; i
+= llen
, up
+= llen
) {
813 switch (sp
->user_datafmt
) {
814 case PIXARLOGDATAFMT_FLOAT
:
815 horizontalAccumulateF(up
, llen
, sp
->stride
,
816 (float *)op
, sp
->ToLinearF
);
817 op
+= llen
* sizeof(float);
819 case PIXARLOGDATAFMT_16BIT
:
820 horizontalAccumulate16(up
, llen
, sp
->stride
,
821 (uint16
*)op
, sp
->ToLinear16
);
822 op
+= llen
* sizeof(uint16
);
824 case PIXARLOGDATAFMT_12BITPICIO
:
825 horizontalAccumulate12(up
, llen
, sp
->stride
,
826 (int16
*)op
, sp
->ToLinearF
);
827 op
+= llen
* sizeof(int16
);
829 case PIXARLOGDATAFMT_11BITLOG
:
830 horizontalAccumulate11(up
, llen
, sp
->stride
,
832 op
+= llen
* sizeof(uint16
);
834 case PIXARLOGDATAFMT_8BIT
:
835 horizontalAccumulate8(up
, llen
, sp
->stride
,
836 (unsigned char *)op
, sp
->ToLinear8
);
837 op
+= llen
* sizeof(unsigned char);
839 case PIXARLOGDATAFMT_8BITABGR
:
840 horizontalAccumulate8abgr(up
, llen
, sp
->stride
,
841 (unsigned char *)op
, sp
->ToLinear8
);
842 op
+= llen
* sizeof(unsigned char);
845 TIFFErrorExt(tif
->tif_clientdata
, module,
846 "Unsupported bits/sample: %d",
847 td
->td_bitspersample
);
856 PixarLogSetupEncode(TIFF
* tif
)
858 static const char module[] = "PixarLogSetupEncode";
859 TIFFDirectory
*td
= &tif
->tif_dir
;
860 PixarLogState
* sp
= EncoderState(tif
);
865 /* for some reason, we can't do this in TIFFInitPixarLog */
867 sp
->stride
= (td
->td_planarconfig
== PLANARCONFIG_CONTIG
?
868 td
->td_samplesperpixel
: 1);
869 tbuf_size
= multiply_ms(multiply_ms(multiply_ms(sp
->stride
, td
->td_imagewidth
),
870 td
->td_rowsperstrip
), sizeof(uint16
));
872 return (0); /* TODO: this is an error return without error report through TIFFErrorExt */
873 sp
->tbuf
= (uint16
*) _TIFFmalloc(tbuf_size
);
874 if (sp
->tbuf
== NULL
)
876 if (sp
->user_datafmt
== PIXARLOGDATAFMT_UNKNOWN
)
877 sp
->user_datafmt
= PixarLogGuessDataFmt(td
);
878 if (sp
->user_datafmt
== PIXARLOGDATAFMT_UNKNOWN
) {
879 TIFFErrorExt(tif
->tif_clientdata
, module, "PixarLog compression can't handle %d bit linear encodings", td
->td_bitspersample
);
883 if (deflateInit(&sp
->stream
, sp
->quality
) != Z_OK
) {
884 TIFFErrorExt(tif
->tif_clientdata
, module, "%s", sp
->stream
.msg
);
887 sp
->state
|= PLSTATE_INIT
;
893 * Reset encoding state at the start of a strip.
896 PixarLogPreEncode(TIFF
* tif
, uint16 s
)
898 static const char module[] = "PixarLogPreEncode";
899 PixarLogState
*sp
= EncoderState(tif
);
903 sp
->stream
.next_out
= tif
->tif_rawdata
;
904 assert(sizeof(sp
->stream
.avail_out
)==4); /* if this assert gets raised,
905 we need to simplify this code to reflect a ZLib that is likely updated
906 to deal with 8byte memory sizes, though this code will respond
907 apropriately even before we simplify it */
908 sp
->stream
.avail_out
= tif
->tif_rawdatasize
;
909 if ((tmsize_t
)sp
->stream
.avail_out
!= tif
->tif_rawdatasize
)
911 TIFFErrorExt(tif
->tif_clientdata
, module, "ZLib cannot deal with buffers this size");
914 return (deflateReset(&sp
->stream
) == Z_OK
);
918 horizontalDifferenceF(float *ip
, int n
, int stride
, uint16
*wp
, uint16
*FromLT2
)
920 int32 r1
, g1
, b1
, a1
, r2
, g2
, b2
, a2
, mask
;
921 float fltsize
= Fltsize
;
923 #define CLAMP(v) ( (v<(float)0.) ? 0 \
924 : (v<(float)2.) ? FromLT2[(int)(v*fltsize)] \
925 : (v>(float)24.2) ? 2047 \
926 : LogK1*log(v*LogK2) + 0.5 )
931 r2
= wp
[0] = (uint16
) CLAMP(ip
[0]);
932 g2
= wp
[1] = (uint16
) CLAMP(ip
[1]);
933 b2
= wp
[2] = (uint16
) CLAMP(ip
[2]);
939 r1
= (int32
) CLAMP(ip
[0]); wp
[0] = (r1
-r2
) & mask
; r2
= r1
;
940 g1
= (int32
) CLAMP(ip
[1]); wp
[1] = (g1
-g2
) & mask
; g2
= g1
;
941 b1
= (int32
) CLAMP(ip
[2]); wp
[2] = (b1
-b2
) & mask
; b2
= b1
;
943 } else if (stride
== 4) {
944 r2
= wp
[0] = (uint16
) CLAMP(ip
[0]);
945 g2
= wp
[1] = (uint16
) CLAMP(ip
[1]);
946 b2
= wp
[2] = (uint16
) CLAMP(ip
[2]);
947 a2
= wp
[3] = (uint16
) CLAMP(ip
[3]);
953 r1
= (int32
) CLAMP(ip
[0]); wp
[0] = (r1
-r2
) & mask
; r2
= r1
;
954 g1
= (int32
) CLAMP(ip
[1]); wp
[1] = (g1
-g2
) & mask
; g2
= g1
;
955 b1
= (int32
) CLAMP(ip
[2]); wp
[2] = (b1
-b2
) & mask
; b2
= b1
;
956 a1
= (int32
) CLAMP(ip
[3]); wp
[3] = (a1
-a2
) & mask
; a2
= a1
;
959 ip
+= n
- 1; /* point to last one */
960 wp
+= n
- 1; /* point to last one */
963 REPEAT(stride
, wp
[0] = (uint16
) CLAMP(ip
[0]);
969 REPEAT(stride
, wp
[0] = (uint16
) CLAMP(ip
[0]); wp
--; ip
--)
975 horizontalDifference16(unsigned short *ip
, int n
, int stride
,
976 unsigned short *wp
, uint16
*From14
)
978 register int r1
, g1
, b1
, a1
, r2
, g2
, b2
, a2
, mask
;
980 /* assumption is unsigned pixel values */
982 #define CLAMP(v) From14[(v) >> 2]
987 r2
= wp
[0] = CLAMP(ip
[0]); g2
= wp
[1] = CLAMP(ip
[1]);
988 b2
= wp
[2] = CLAMP(ip
[2]);
994 r1
= CLAMP(ip
[0]); wp
[0] = (r1
-r2
) & mask
; r2
= r1
;
995 g1
= CLAMP(ip
[1]); wp
[1] = (g1
-g2
) & mask
; g2
= g1
;
996 b1
= CLAMP(ip
[2]); wp
[2] = (b1
-b2
) & mask
; b2
= b1
;
998 } else if (stride
== 4) {
999 r2
= wp
[0] = CLAMP(ip
[0]); g2
= wp
[1] = CLAMP(ip
[1]);
1000 b2
= wp
[2] = CLAMP(ip
[2]); a2
= wp
[3] = CLAMP(ip
[3]);
1006 r1
= CLAMP(ip
[0]); wp
[0] = (r1
-r2
) & mask
; r2
= r1
;
1007 g1
= CLAMP(ip
[1]); wp
[1] = (g1
-g2
) & mask
; g2
= g1
;
1008 b1
= CLAMP(ip
[2]); wp
[2] = (b1
-b2
) & mask
; b2
= b1
;
1009 a1
= CLAMP(ip
[3]); wp
[3] = (a1
-a2
) & mask
; a2
= a1
;
1012 ip
+= n
- 1; /* point to last one */
1013 wp
+= n
- 1; /* point to last one */
1016 REPEAT(stride
, wp
[0] = CLAMP(ip
[0]);
1017 wp
[stride
] -= wp
[0];
1022 REPEAT(stride
, wp
[0] = CLAMP(ip
[0]); wp
--; ip
--)
1029 horizontalDifference8(unsigned char *ip
, int n
, int stride
,
1030 unsigned short *wp
, uint16
*From8
)
1032 register int r1
, g1
, b1
, a1
, r2
, g2
, b2
, a2
, mask
;
1035 #define CLAMP(v) (From8[(v)])
1040 r2
= wp
[0] = CLAMP(ip
[0]); g2
= wp
[1] = CLAMP(ip
[1]);
1041 b2
= wp
[2] = CLAMP(ip
[2]);
1045 r1
= CLAMP(ip
[3]); wp
[3] = (r1
-r2
) & mask
; r2
= r1
;
1046 g1
= CLAMP(ip
[4]); wp
[4] = (g1
-g2
) & mask
; g2
= g1
;
1047 b1
= CLAMP(ip
[5]); wp
[5] = (b1
-b2
) & mask
; b2
= b1
;
1051 } else if (stride
== 4) {
1052 r2
= wp
[0] = CLAMP(ip
[0]); g2
= wp
[1] = CLAMP(ip
[1]);
1053 b2
= wp
[2] = CLAMP(ip
[2]); a2
= wp
[3] = CLAMP(ip
[3]);
1057 r1
= CLAMP(ip
[4]); wp
[4] = (r1
-r2
) & mask
; r2
= r1
;
1058 g1
= CLAMP(ip
[5]); wp
[5] = (g1
-g2
) & mask
; g2
= g1
;
1059 b1
= CLAMP(ip
[6]); wp
[6] = (b1
-b2
) & mask
; b2
= b1
;
1060 a1
= CLAMP(ip
[7]); wp
[7] = (a1
-a2
) & mask
; a2
= a1
;
1065 wp
+= n
+ stride
- 1; /* point to last one */
1066 ip
+= n
+ stride
- 1; /* point to last one */
1069 REPEAT(stride
, wp
[0] = CLAMP(ip
[0]);
1070 wp
[stride
] -= wp
[0];
1075 REPEAT(stride
, wp
[0] = CLAMP(ip
[0]); wp
--; ip
--)
1081 * Encode a chunk of pixels.
1084 PixarLogEncode(TIFF
* tif
, uint8
* bp
, tmsize_t cc
, uint16 s
)
1086 static const char module[] = "PixarLogEncode";
1087 TIFFDirectory
*td
= &tif
->tif_dir
;
1088 PixarLogState
*sp
= EncoderState(tif
);
1092 unsigned short * up
;
1096 switch (sp
->user_datafmt
) {
1097 case PIXARLOGDATAFMT_FLOAT
:
1098 n
= cc
/ sizeof(float); /* XXX float == 32 bits */
1100 case PIXARLOGDATAFMT_16BIT
:
1101 case PIXARLOGDATAFMT_12BITPICIO
:
1102 case PIXARLOGDATAFMT_11BITLOG
:
1103 n
= cc
/ sizeof(uint16
); /* XXX uint16 == 16 bits */
1105 case PIXARLOGDATAFMT_8BIT
:
1106 case PIXARLOGDATAFMT_8BITABGR
:
1110 TIFFErrorExt(tif
->tif_clientdata
, module,
1111 "%d bit input not supported in PixarLog",
1112 td
->td_bitspersample
);
1116 llen
= sp
->stride
* td
->td_imagewidth
;
1118 for (i
= 0, up
= sp
->tbuf
; i
< n
; i
+= llen
, up
+= llen
) {
1119 switch (sp
->user_datafmt
) {
1120 case PIXARLOGDATAFMT_FLOAT
:
1121 horizontalDifferenceF((float *)bp
, llen
,
1122 sp
->stride
, up
, sp
->FromLT2
);
1123 bp
+= llen
* sizeof(float);
1125 case PIXARLOGDATAFMT_16BIT
:
1126 horizontalDifference16((uint16
*)bp
, llen
,
1127 sp
->stride
, up
, sp
->From14
);
1128 bp
+= llen
* sizeof(uint16
);
1130 case PIXARLOGDATAFMT_8BIT
:
1131 horizontalDifference8((unsigned char *)bp
, llen
,
1132 sp
->stride
, up
, sp
->From8
);
1133 bp
+= llen
* sizeof(unsigned char);
1136 TIFFErrorExt(tif
->tif_clientdata
, module,
1137 "%d bit input not supported in PixarLog",
1138 td
->td_bitspersample
);
1143 sp
->stream
.next_in
= (unsigned char *) sp
->tbuf
;
1144 assert(sizeof(sp
->stream
.avail_in
)==4); /* if this assert gets raised,
1145 we need to simplify this code to reflect a ZLib that is likely updated
1146 to deal with 8byte memory sizes, though this code will respond
1147 apropriately even before we simplify it */
1148 sp
->stream
.avail_in
= (uInt
) (n
* sizeof(uint16
));
1149 if ((sp
->stream
.avail_in
/ sizeof(uint16
)) != (uInt
) n
)
1151 TIFFErrorExt(tif
->tif_clientdata
, module,
1152 "ZLib cannot deal with buffers this size");
1157 if (deflate(&sp
->stream
, Z_NO_FLUSH
) != Z_OK
) {
1158 TIFFErrorExt(tif
->tif_clientdata
, module, "Encoder error: %s",
1162 if (sp
->stream
.avail_out
== 0) {
1163 tif
->tif_rawcc
= tif
->tif_rawdatasize
;
1164 TIFFFlushData1(tif
);
1165 sp
->stream
.next_out
= tif
->tif_rawdata
;
1166 sp
->stream
.avail_out
= (uInt
) tif
->tif_rawdatasize
; /* this is a safe typecast, as check is made already in PixarLogPreEncode */
1168 } while (sp
->stream
.avail_in
> 0);
1173 * Finish off an encoded strip by flushing the last
1174 * string and tacking on an End Of Information code.
1178 PixarLogPostEncode(TIFF
* tif
)
1180 static const char module[] = "PixarLogPostEncode";
1181 PixarLogState
*sp
= EncoderState(tif
);
1184 sp
->stream
.avail_in
= 0;
1187 state
= deflate(&sp
->stream
, Z_FINISH
);
1191 if ((tmsize_t
)sp
->stream
.avail_out
!= tif
->tif_rawdatasize
) {
1193 tif
->tif_rawdatasize
- sp
->stream
.avail_out
;
1194 TIFFFlushData1(tif
);
1195 sp
->stream
.next_out
= tif
->tif_rawdata
;
1196 sp
->stream
.avail_out
= (uInt
) tif
->tif_rawdatasize
; /* this is a safe typecast, as check is made already in PixarLogPreEncode */
1200 TIFFErrorExt(tif
->tif_clientdata
, module, "ZLib error: %s",
1204 } while (state
!= Z_STREAM_END
);
1209 PixarLogClose(TIFF
* tif
)
1211 TIFFDirectory
*td
= &tif
->tif_dir
;
1213 /* In a really sneaky (and really incorrect, and untruthfull, and
1214 * troublesome, and error-prone) maneuver that completely goes against
1215 * the spirit of TIFF, and breaks TIFF, on close, we covertly
1216 * modify both bitspersample and sampleformat in the directory to
1217 * indicate 8-bit linear. This way, the decode "just works" even for
1218 * readers that don't know about PixarLog, or how to set
1219 * the PIXARLOGDATFMT pseudo-tag.
1221 td
->td_bitspersample
= 8;
1222 td
->td_sampleformat
= SAMPLEFORMAT_UINT
;
1226 PixarLogCleanup(TIFF
* tif
)
1228 PixarLogState
* sp
= (PixarLogState
*) tif
->tif_data
;
1232 (void)TIFFPredictorCleanup(tif
);
1234 tif
->tif_tagmethods
.vgetfield
= sp
->vgetparent
;
1235 tif
->tif_tagmethods
.vsetfield
= sp
->vsetparent
;
1237 if (sp
->FromLT2
) _TIFFfree(sp
->FromLT2
);
1238 if (sp
->From14
) _TIFFfree(sp
->From14
);
1239 if (sp
->From8
) _TIFFfree(sp
->From8
);
1240 if (sp
->ToLinearF
) _TIFFfree(sp
->ToLinearF
);
1241 if (sp
->ToLinear16
) _TIFFfree(sp
->ToLinear16
);
1242 if (sp
->ToLinear8
) _TIFFfree(sp
->ToLinear8
);
1243 if (sp
->state
&PLSTATE_INIT
) {
1244 if (tif
->tif_mode
== O_RDONLY
)
1245 inflateEnd(&sp
->stream
);
1247 deflateEnd(&sp
->stream
);
1250 _TIFFfree(sp
->tbuf
);
1252 tif
->tif_data
= NULL
;
1254 _TIFFSetDefaultCompressionState(tif
);
1258 PixarLogVSetField(TIFF
* tif
, uint32 tag
, va_list ap
)
1260 static const char module[] = "PixarLogVSetField";
1261 PixarLogState
*sp
= (PixarLogState
*)tif
->tif_data
;
1265 case TIFFTAG_PIXARLOGQUALITY
:
1266 sp
->quality
= (int) va_arg(ap
, int);
1267 if (tif
->tif_mode
!= O_RDONLY
&& (sp
->state
&PLSTATE_INIT
)) {
1268 if (deflateParams(&sp
->stream
,
1269 sp
->quality
, Z_DEFAULT_STRATEGY
) != Z_OK
) {
1270 TIFFErrorExt(tif
->tif_clientdata
, module, "ZLib error: %s",
1276 case TIFFTAG_PIXARLOGDATAFMT
:
1277 sp
->user_datafmt
= (int) va_arg(ap
, int);
1278 /* Tweak the TIFF header so that the rest of libtiff knows what
1279 * size of data will be passed between app and library, and
1280 * assume that the app knows what it is doing and is not
1281 * confused by these header manipulations...
1283 switch (sp
->user_datafmt
) {
1284 case PIXARLOGDATAFMT_8BIT
:
1285 case PIXARLOGDATAFMT_8BITABGR
:
1286 TIFFSetField(tif
, TIFFTAG_BITSPERSAMPLE
, 8);
1287 TIFFSetField(tif
, TIFFTAG_SAMPLEFORMAT
, SAMPLEFORMAT_UINT
);
1289 case PIXARLOGDATAFMT_11BITLOG
:
1290 TIFFSetField(tif
, TIFFTAG_BITSPERSAMPLE
, 16);
1291 TIFFSetField(tif
, TIFFTAG_SAMPLEFORMAT
, SAMPLEFORMAT_UINT
);
1293 case PIXARLOGDATAFMT_12BITPICIO
:
1294 TIFFSetField(tif
, TIFFTAG_BITSPERSAMPLE
, 16);
1295 TIFFSetField(tif
, TIFFTAG_SAMPLEFORMAT
, SAMPLEFORMAT_INT
);
1297 case PIXARLOGDATAFMT_16BIT
:
1298 TIFFSetField(tif
, TIFFTAG_BITSPERSAMPLE
, 16);
1299 TIFFSetField(tif
, TIFFTAG_SAMPLEFORMAT
, SAMPLEFORMAT_UINT
);
1301 case PIXARLOGDATAFMT_FLOAT
:
1302 TIFFSetField(tif
, TIFFTAG_BITSPERSAMPLE
, 32);
1303 TIFFSetField(tif
, TIFFTAG_SAMPLEFORMAT
, SAMPLEFORMAT_IEEEFP
);
1307 * Must recalculate sizes should bits/sample change.
1309 tif
->tif_tilesize
= isTiled(tif
) ? TIFFTileSize(tif
) : (tmsize_t
)(-1);
1310 tif
->tif_scanlinesize
= TIFFScanlineSize(tif
);
1311 result
= 1; /* NB: pseudo tag */
1314 result
= (*sp
->vsetparent
)(tif
, tag
, ap
);
1320 PixarLogVGetField(TIFF
* tif
, uint32 tag
, va_list ap
)
1322 PixarLogState
*sp
= (PixarLogState
*)tif
->tif_data
;
1325 case TIFFTAG_PIXARLOGQUALITY
:
1326 *va_arg(ap
, int*) = sp
->quality
;
1328 case TIFFTAG_PIXARLOGDATAFMT
:
1329 *va_arg(ap
, int*) = sp
->user_datafmt
;
1332 return (*sp
->vgetparent
)(tif
, tag
, ap
);
1337 static const TIFFField pixarlogFields
[] = {
1338 {TIFFTAG_PIXARLOGDATAFMT
, 0, 0, TIFF_ANY
, 0, TIFF_SETGET_INT
, TIFF_SETGET_UNDEFINED
, FIELD_PSEUDO
, FALSE
, FALSE
, "", NULL
},
1339 {TIFFTAG_PIXARLOGQUALITY
, 0, 0, TIFF_ANY
, 0, TIFF_SETGET_INT
, TIFF_SETGET_UNDEFINED
, FIELD_PSEUDO
, FALSE
, FALSE
, "", NULL
}
1343 TIFFInitPixarLog(TIFF
* tif
, int scheme
)
1345 static const char module[] = "TIFFInitPixarLog";
1349 assert(scheme
== COMPRESSION_PIXARLOG
);
1352 * Merge codec-specific tag information.
1354 if (!_TIFFMergeFields(tif
, pixarlogFields
,
1355 TIFFArrayCount(pixarlogFields
))) {
1356 TIFFErrorExt(tif
->tif_clientdata
, module,
1357 "Merging PixarLog codec-specific tags failed");
1362 * Allocate state block so tag methods have storage to record values.
1364 tif
->tif_data
= (uint8
*) _TIFFmalloc(sizeof (PixarLogState
));
1365 if (tif
->tif_data
== NULL
)
1367 sp
= (PixarLogState
*) tif
->tif_data
;
1368 _TIFFmemset(sp
, 0, sizeof (*sp
));
1369 sp
->stream
.data_type
= Z_BINARY
;
1370 sp
->user_datafmt
= PIXARLOGDATAFMT_UNKNOWN
;
1373 * Install codec methods.
1375 tif
->tif_fixuptags
= PixarLogFixupTags
;
1376 tif
->tif_setupdecode
= PixarLogSetupDecode
;
1377 tif
->tif_predecode
= PixarLogPreDecode
;
1378 tif
->tif_decoderow
= PixarLogDecode
;
1379 tif
->tif_decodestrip
= PixarLogDecode
;
1380 tif
->tif_decodetile
= PixarLogDecode
;
1381 tif
->tif_setupencode
= PixarLogSetupEncode
;
1382 tif
->tif_preencode
= PixarLogPreEncode
;
1383 tif
->tif_postencode
= PixarLogPostEncode
;
1384 tif
->tif_encoderow
= PixarLogEncode
;
1385 tif
->tif_encodestrip
= PixarLogEncode
;
1386 tif
->tif_encodetile
= PixarLogEncode
;
1387 tif
->tif_close
= PixarLogClose
;
1388 tif
->tif_cleanup
= PixarLogCleanup
;
1390 /* Override SetField so we can handle our private pseudo-tag */
1391 sp
->vgetparent
= tif
->tif_tagmethods
.vgetfield
;
1392 tif
->tif_tagmethods
.vgetfield
= PixarLogVGetField
; /* hook for codec tags */
1393 sp
->vsetparent
= tif
->tif_tagmethods
.vsetfield
;
1394 tif
->tif_tagmethods
.vsetfield
= PixarLogVSetField
; /* hook for codec tags */
1396 /* Default values for codec-specific fields */
1397 sp
->quality
= Z_DEFAULT_COMPRESSION
; /* default comp. level */
1400 /* we don't wish to use the predictor,
1401 * the default is none, which predictor value 1
1403 (void) TIFFPredictorInit(tif
);
1406 * build the companding tables
1408 PixarLogMakeTables(sp
);
1412 TIFFErrorExt(tif
->tif_clientdata
, module,
1413 "No space for PixarLog state block");
1416 #endif /* PIXARLOG_SUPPORT */
1418 /* vim: set ts=8 sts=8 sw=8 noet: */