4 * Copyright (c) 1991-1997 Sam Leffler
5 * Copyright (c) 1991-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 and Silicon Graphics may not be used in any advertising or
12 * publicity relating to the software without the specific, prior written
13 * permission of Sam Leffler 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 OR SILICON GRAPHICS BE LIABLE FOR
20 * 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
30 * Auxiliary Support Routines.
34 #ifdef COLORIMETRY_SUPPORT
38 TIFFDefaultTransferFunction(TIFFDirectory
* td
)
40 uint16
**tf
= td
->td_transferfunction
;
41 long i
, n
= 1<<td
->td_bitspersample
;
43 tf
[0] = (uint16
*)_TIFFmalloc(n
* sizeof (uint16
));
45 for (i
= 1; i
< n
; i
++) {
46 double t
= (double)i
/((double) n
-1.);
47 tf
[0][i
] = (uint16
)floor(65535.*pow(t
, 2.2) + .5);
49 if (td
->td_samplesperpixel
- td
->td_extrasamples
> 1) {
50 tf
[1] = (uint16
*)_TIFFmalloc(n
* sizeof (uint16
));
51 _TIFFmemcpy(tf
[1], tf
[0], n
* sizeof (uint16
));
52 tf
[2] = (uint16
*)_TIFFmalloc(n
* sizeof (uint16
));
53 _TIFFmemcpy(tf
[2], tf
[0], n
* sizeof (uint16
));
58 TIFFDefaultRefBlackWhite(TIFFDirectory
* td
)
62 td
->td_refblackwhite
= (float *)_TIFFmalloc(6*sizeof (float));
63 for (i
= 0; i
< 3; i
++) {
64 td
->td_refblackwhite
[2*i
+0] = 0;
65 td
->td_refblackwhite
[2*i
+1] = (float)((1L<<td
->td_bitspersample
)-1L);
71 * Like TIFFGetField, but return any default
72 * value if the tag is not present in the directory.
74 * NB: We use the value in the directory, rather than
75 * explcit values so that defaults exist only one
76 * place in the library -- in TIFFDefaultDirectory.
79 TIFFVGetFieldDefaulted(TIFF
* tif
, ttag_t tag
, va_list ap
)
81 TIFFDirectory
*td
= &tif
->tif_dir
;
83 if (TIFFVGetField(tif
, tag
, ap
))
86 case TIFFTAG_SUBFILETYPE
:
87 *va_arg(ap
, uint32
*) = td
->td_subfiletype
;
89 case TIFFTAG_BITSPERSAMPLE
:
90 *va_arg(ap
, uint16
*) = td
->td_bitspersample
;
92 case TIFFTAG_THRESHHOLDING
:
93 *va_arg(ap
, uint16
*) = td
->td_threshholding
;
95 case TIFFTAG_FILLORDER
:
96 *va_arg(ap
, uint16
*) = td
->td_fillorder
;
98 case TIFFTAG_ORIENTATION
:
99 *va_arg(ap
, uint16
*) = td
->td_orientation
;
101 case TIFFTAG_SAMPLESPERPIXEL
:
102 *va_arg(ap
, uint16
*) = td
->td_samplesperpixel
;
104 case TIFFTAG_ROWSPERSTRIP
:
105 *va_arg(ap
, uint32
*) = td
->td_rowsperstrip
;
107 case TIFFTAG_MINSAMPLEVALUE
:
108 *va_arg(ap
, uint16
*) = td
->td_minsamplevalue
;
110 case TIFFTAG_MAXSAMPLEVALUE
:
111 *va_arg(ap
, uint16
*) = td
->td_maxsamplevalue
;
113 case TIFFTAG_PLANARCONFIG
:
114 *va_arg(ap
, uint16
*) = td
->td_planarconfig
;
116 case TIFFTAG_RESOLUTIONUNIT
:
117 *va_arg(ap
, uint16
*) = td
->td_resolutionunit
;
120 case TIFFTAG_DOTRANGE
:
121 *va_arg(ap
, uint16
*) = 0;
122 *va_arg(ap
, uint16
*) = (1<<td
->td_bitspersample
)-1;
125 *va_arg(ap
, uint16
*) = td
->td_inkset
;
127 case TIFFTAG_NUMBEROFINKS
:
128 *va_arg(ap
, uint16
*) = td
->td_ninks
;
131 case TIFFTAG_EXTRASAMPLES
:
132 *va_arg(ap
, uint16
*) = td
->td_extrasamples
;
133 *va_arg(ap
, uint16
**) = td
->td_sampleinfo
;
135 case TIFFTAG_MATTEING
:
136 *va_arg(ap
, uint16
*) =
137 (td
->td_extrasamples
== 1 &&
138 td
->td_sampleinfo
[0] == EXTRASAMPLE_ASSOCALPHA
);
140 case TIFFTAG_TILEDEPTH
:
141 *va_arg(ap
, uint32
*) = td
->td_tiledepth
;
143 case TIFFTAG_DATATYPE
:
144 *va_arg(ap
, uint16
*) = td
->td_sampleformat
-1;
146 case TIFFTAG_IMAGEDEPTH
:
147 *va_arg(ap
, uint32
*) = td
->td_imagedepth
;
150 case TIFFTAG_YCBCRCOEFFICIENTS
:
151 if (!td
->td_ycbcrcoeffs
) {
152 td
->td_ycbcrcoeffs
= (float *)
153 _TIFFmalloc(3*sizeof (float));
154 /* defaults are from CCIR Recommendation 601-1 */
155 td
->td_ycbcrcoeffs
[0] = 0.299f
;
156 td
->td_ycbcrcoeffs
[1] = 0.587f
;
157 td
->td_ycbcrcoeffs
[2] = 0.114f
;
159 *va_arg(ap
, float **) = td
->td_ycbcrcoeffs
;
161 case TIFFTAG_YCBCRSUBSAMPLING
:
162 *va_arg(ap
, uint16
*) = td
->td_ycbcrsubsampling
[0];
163 *va_arg(ap
, uint16
*) = td
->td_ycbcrsubsampling
[1];
165 case TIFFTAG_YCBCRPOSITIONING
:
166 *va_arg(ap
, uint16
*) = td
->td_ycbcrpositioning
;
169 #ifdef COLORIMETRY_SUPPORT
170 case TIFFTAG_TRANSFERFUNCTION
:
171 if (!td
->td_transferfunction
[0])
172 TIFFDefaultTransferFunction(td
);
173 *va_arg(ap
, uint16
**) = td
->td_transferfunction
[0];
174 if (td
->td_samplesperpixel
- td
->td_extrasamples
> 1) {
175 *va_arg(ap
, uint16
**) = td
->td_transferfunction
[1];
176 *va_arg(ap
, uint16
**) = td
->td_transferfunction
[2];
179 case TIFFTAG_REFERENCEBLACKWHITE
:
180 if (!td
->td_refblackwhite
)
181 TIFFDefaultRefBlackWhite(td
);
182 *va_arg(ap
, float **) = td
->td_refblackwhite
;
190 * Like TIFFGetField, but return any default
191 * value if the tag is not present in the directory.
194 TIFFGetFieldDefaulted(TIFF
* tif
, ttag_t tag
, ...)
200 ok
= TIFFVGetFieldDefaulted(tif
, tag
, ap
);