1
/* $Header: /cvsroot/osrs/libtiff/libtiff/tif_aux.c,v 1.6 2003/12/06 15:55:41 dron Exp $ */
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.
33
#include "tif_predict.h"
37
TIFFDefaultTransferFunction(TIFFDirectory* td)
39
uint16 **tf = td->td_transferfunction;
42
tf[0] = tf[1] = tf[2] = 0;
43
if (td->td_bitspersample >= sizeof(tsize_t) * 8 - 2)
46
n = 1<<td->td_bitspersample;
47
nbytes = n * sizeof (uint16);
48
if (!(tf[0] = (uint16 *)_TIFFmalloc(nbytes)))
51
for (i = 1; i < n; i++) {
52
double t = (double)i/((double) n-1.);
53
tf[0][i] = (uint16)floor(65535.*pow(t, 2.2) + .5);
56
if (td->td_samplesperpixel - td->td_extrasamples > 1) {
57
if (!(tf[1] = (uint16 *)_TIFFmalloc(nbytes)))
59
_TIFFmemcpy(tf[1], tf[0], nbytes);
60
if (!(tf[2] = (uint16 *)_TIFFmalloc(nbytes)))
62
_TIFFmemcpy(tf[2], tf[0], nbytes);
73
tf[0] = tf[1] = tf[2] = 0;
78
TIFFDefaultRefBlackWhite(TIFFDirectory* td)
82
if (!(td->td_refblackwhite = (float *)_TIFFmalloc(6*sizeof (float))))
84
for (i = 0; i < 3; i++) {
85
td->td_refblackwhite[2*i+0] = 0;
86
td->td_refblackwhite[2*i+1] = (float)((1L<<td->td_bitspersample)-1L);
92
* Like TIFFGetField, but return any default
93
* value if the tag is not present in the directory.
95
* NB: We use the value in the directory, rather than
96
* explcit values so that defaults exist only one
97
* place in the library -- in TIFFDefaultDirectory.
100
TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap)
102
TIFFDirectory *td = &tif->tif_dir;
104
if (TIFFVGetField(tif, tag, ap))
107
case TIFFTAG_SUBFILETYPE:
108
*va_arg(ap, uint32 *) = td->td_subfiletype;
110
case TIFFTAG_BITSPERSAMPLE:
111
*va_arg(ap, uint16 *) = td->td_bitspersample;
113
case TIFFTAG_THRESHHOLDING:
114
*va_arg(ap, uint16 *) = td->td_threshholding;
116
case TIFFTAG_FILLORDER:
117
*va_arg(ap, uint16 *) = td->td_fillorder;
119
case TIFFTAG_ORIENTATION:
120
*va_arg(ap, uint16 *) = td->td_orientation;
122
case TIFFTAG_SAMPLESPERPIXEL:
123
*va_arg(ap, uint16 *) = td->td_samplesperpixel;
125
case TIFFTAG_ROWSPERSTRIP:
126
*va_arg(ap, uint32 *) = td->td_rowsperstrip;
128
case TIFFTAG_MINSAMPLEVALUE:
129
*va_arg(ap, uint16 *) = td->td_minsamplevalue;
131
case TIFFTAG_MAXSAMPLEVALUE:
132
*va_arg(ap, uint16 *) = td->td_maxsamplevalue;
134
case TIFFTAG_PLANARCONFIG:
135
*va_arg(ap, uint16 *) = td->td_planarconfig;
137
case TIFFTAG_RESOLUTIONUNIT:
138
*va_arg(ap, uint16 *) = td->td_resolutionunit;
140
case TIFFTAG_PREDICTOR:
142
TIFFPredictorState* sp = (TIFFPredictorState*) tif->tif_data;
143
*va_arg(ap, uint16*) = (uint16) sp->predictor;
146
case TIFFTAG_DOTRANGE:
147
*va_arg(ap, uint16 *) = 0;
148
*va_arg(ap, uint16 *) = (1<<td->td_bitspersample)-1;
151
*va_arg(ap, uint16 *) = td->td_inkset;
153
case TIFFTAG_NUMBEROFINKS:
154
*va_arg(ap, uint16 *) = td->td_ninks;
156
case TIFFTAG_EXTRASAMPLES:
157
*va_arg(ap, uint16 *) = td->td_extrasamples;
158
*va_arg(ap, uint16 **) = td->td_sampleinfo;
160
case TIFFTAG_MATTEING:
161
*va_arg(ap, uint16 *) =
162
(td->td_extrasamples == 1 &&
163
td->td_sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA);
165
case TIFFTAG_TILEDEPTH:
166
*va_arg(ap, uint32 *) = td->td_tiledepth;
168
case TIFFTAG_DATATYPE:
169
*va_arg(ap, uint16 *) = td->td_sampleformat-1;
171
case TIFFTAG_SAMPLEFORMAT:
172
*va_arg(ap, uint16 *) = td->td_sampleformat;
174
case TIFFTAG_IMAGEDEPTH:
175
*va_arg(ap, uint32 *) = td->td_imagedepth;
177
case TIFFTAG_YCBCRCOEFFICIENTS:
178
if (!td->td_ycbcrcoeffs) {
179
td->td_ycbcrcoeffs = (float *)
180
_TIFFmalloc(3*sizeof (float));
181
if (!td->td_ycbcrcoeffs)
183
/* defaults are from CCIR Recommendation 601-1 */
184
td->td_ycbcrcoeffs[0] = 0.299f;
185
td->td_ycbcrcoeffs[1] = 0.587f;
186
td->td_ycbcrcoeffs[2] = 0.114f;
188
*va_arg(ap, float **) = td->td_ycbcrcoeffs;
190
case TIFFTAG_YCBCRSUBSAMPLING:
191
*va_arg(ap, uint16 *) = td->td_ycbcrsubsampling[0];
192
*va_arg(ap, uint16 *) = td->td_ycbcrsubsampling[1];
194
case TIFFTAG_YCBCRPOSITIONING:
195
*va_arg(ap, uint16 *) = td->td_ycbcrpositioning;
197
case TIFFTAG_WHITEPOINT:
198
if (!td->td_whitepoint) {
199
td->td_whitepoint = (float *)
200
_TIFFmalloc(2 * sizeof (float));
201
if (!td->td_whitepoint)
203
/* TIFF 6.0 specification says that it is no default
204
value for the WhitePoint, but AdobePhotoshop TIFF
205
Technical Note tells that it should be CIE D50. */
206
td->td_whitepoint[0] =
207
D50_X0 / (D50_X0 + D50_Y0 + D50_Z0);
208
td->td_whitepoint[1] =
209
D50_Y0 / (D50_X0 + D50_Y0 + D50_Z0);
211
*va_arg(ap, float **) = td->td_whitepoint;
213
case TIFFTAG_TRANSFERFUNCTION:
214
if (!td->td_transferfunction[0] &&
215
!TIFFDefaultTransferFunction(td)) {
216
TIFFError(tif->tif_name, "No space for \"TransferFunction\" tag");
219
*va_arg(ap, uint16 **) = td->td_transferfunction[0];
220
if (td->td_samplesperpixel - td->td_extrasamples > 1) {
221
*va_arg(ap, uint16 **) = td->td_transferfunction[1];
222
*va_arg(ap, uint16 **) = td->td_transferfunction[2];
225
case TIFFTAG_REFERENCEBLACKWHITE:
226
if (!td->td_refblackwhite && !TIFFDefaultRefBlackWhite(td))
228
*va_arg(ap, float **) = td->td_refblackwhite;
235
* Like TIFFGetField, but return any default
236
* value if the tag is not present in the directory.
239
TIFFGetFieldDefaulted(TIFF* tif, ttag_t tag, ...)
245
ok = TIFFVGetFieldDefaulted(tif, tag, ap);