Debian Codegraph @

texk/xdvipsk/thirdparty/libtiff/doc/functions/TIFFRGBAImage.rst

raw
1 TIFFRGBAImage
2 =============
3
4 Synopsis
5 --------
6
7 .. highlight:: c
8
9 ::
10
11 #include <tiffio.h>
12
13 .. c:type:: unsigned char TIFFRGBValue
14
15 .. c:type:: struct _TIFFRGBAImage TIFFRGBAImage
16
17 .. c:function:: int TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
18
19 .. c:function:: int TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stopOnError, char emsg[1024])
20
21 .. c:function:: int TIFFRGBAImageGet(TIFFRGBAImage* img, uint32_t* raster, uint32_t width, uint32_t height)
22
23 .. c:function:: void TIFFRGBAImageEnd(TIFFRGBAImage* img)
24
25 Description
26 -----------
27
28 The routines described here provide a high-level interface through which
29 TIFF images may be read into memory.
30 Images may be strip- or tile-based and have a variety of different
31 characteristics: bits/sample, samples/pixel, photometric, etc.
32 Decoding state is encapsulated in a :c:type:`TIFFRGBAImage`
33 structure making it possible to capture state for multiple images
34 and quickly switch between them.
35 The target raster format can be customized to a particular application's
36 needs by installing custom routines that manipulate image data
37 according to application requirements.
38
39 The default usage for these routines is:
40
41 * check if an image can be processed using :c:func:`TIFFRGBAImageOK`
42 * construct a decoder state block using :c:func:`TIFFRGBAImageBegin`
43 * read and decode an image into a target raster using
44 :c:func:`TIFFRGBAImageGet`, and then
45 * release resources using :c:func:`TIFFRGBAImageEnd`
46
47 :c:func:`TIFFRGBAImageGet` can be called multiple times to decode an
48 image using different state parameters.
49 If multiple images are to be displayed and there is not enough
50 space for each of the decoded rasters, multiple state blocks can
51 be managed and then calls can be made to :c:func:`TIFFRGBAImageGet`
52 as needed to display an image.
53
54 The generated raster is assumed to be an array of
55 *width* × *height*
56 32-bit entries, where *width* must be less than or equal to the width of
57 the image (*height* may be any non-zero size).
58 If the raster dimensions are smaller than the image, the image data
59 is cropped to the raster bounds.
60 If the raster height is greater than that of the image, then the
61 image data are placed in the lower part of the raster.
62 (Note that the raster is assume to be organized such that the pixel
63 at location (*x*, *y*) is *raster* [ *y* × *width* + *x* ];
64 with the raster origin in the *lower-left hand corner*.)
65
66 Raster pixels are 8-bit packed red, green, blue, alpha samples.
67 The macros :c:macro:`TIFFGetR`, :c:macro:`TIFFGetG`, :c:macro:`TIFFGetB`,
68 and :c:macro:`TIFFGetA` should be used to access individual samples.
69 Images without Associated Alpha matting information have a constant
70 Alpha of 1.0 (255).
71
72 :c:func:`TIFFRGBAImageGet` converts non-8-bit images by scaling sample
73 values. Palette, grayscale, bilevel, CMYK, and YCbCr images are
74 converted to RGB transparently.
75 Raster pixels are returned uncorrected by any colorimetry information
76 present in the directory.
77
78 The parameter *stopOnError* specifies how to act if an error is
79 encountered while reading the image. If *stopOnError* is non-zero,
80 then an error will terminate the operation; otherwise
81 :c:func:`TIFFRGBAImageGet` will continue processing data until all the
82 possible data in the image have been requested.
83
84 Alternate raster formats
85 ------------------------
86
87 To use the core support for reading and processing TIFF images, but
88 write the resulting raster data in a different format one need only
89 override the "put methods" used to store raster data.
90 These methods are are defined in the :c:type:`TIFFRGBAImage`
91 structure and initially setup by :c:func:`TIFFRGBAImageBegin`
92 to point to routines that pack raster data in the default
93 ABGR pixel format.
94 Two different routines are used according to the physical organization
95 of the image data in the file:
96 ``PlanarConfiguration`` = 1 (packed samples), and
97 ``PlanarConfiguration`` = 2 (separated samples).
98 Note that this mechanism can be used to transform the data before
99 storing it in the raster.
100 For example one can convert data to colormap indices for display on a
101 colormap display.
102
103 Simultaneous raster store and display
104 -------------------------------------
105
106 It is simple to display an image as it is being read into memory
107 by overriding the put methods as described above for supporting
108 alternate raster formats.
109 Simply keep a reference to the default put methods setup by
110 :c:func:`TIFFRGBAImageBegin` and then invoke them before or after
111 each display operation. For example, the
112 :doc:`/tools/tiffgt` utility uses the following put method to
113 update the display as the raster is being filled:
114
115 ::
116
117 static void
118 putContigAndDraw(TIFFRGBAImage* img, uint32_t* raster,
119 uint32_t x, uint32_t y, uint32_t w, uint32_t h,
120 int32_t fromskew, int32_t toskew,
121 unsigned char* cp)
122 {
123 (*putContig)(img, raster, x, y, w, h, fromskew, toskew, cp);
124 if (x+w == width) {
125 w = width;
126 if (img->orientation == ORIENTATION_TOPLEFT)
127 lrectwrite(0, y-(h-1), w-1, y, raster-x-(h-1)*w);
128 else
129 lrectwrite(0, y, w-1, y+h-1, raster);
130 }
131 }
132
133 (the original routine provided by the library is saved in the
134 variable :c:var:`putContig`.)
135
136 Supporting additional TIFF formats
137 ----------------------------------
138
139 The :c:func:`TIFFRGBAImage` routines support the most commonly
140 encountered flavors of TIFF. It is possible to extend this support by
141 overriding the "get method" invoked by :c:func:`TIFFRGBAImageGet`
142 to read TIFF image data.
143 Details of doing this are a bit involved, it is best to make a copy
144 of an existing get method and modify it to suit the needs of an
145 application.
146
147 Notes
148 -----
149
150 Samples must be either 1, 2, 4, 8, or 16 bits.
151 Colorimetric samples/pixel must be either 1, 3, or 4 (i.e.
152 ``SamplesPerPixel`` -``ExtraSamples``).
153
154 Palette image colormaps that appear to be incorrectly written
155 as 8-bit values are automatically scaled to 16-bits.
156
157 Return values
158 -------------
159
160 All routines return 1 if the operation was successful.
161 Otherwise, 0 is returned if an error was encountered and
162 *stopOnError* is zero.
163
164 Diagnostics
165 -----------
166
167 All error messages are directed to the :c:func:`TIFFErrorExtR` routine.
168
169 ``"Sorry, can not handle %d-bit pictures"``:
170
171 The image had ``BitsPerSample`` other than 1, 2, 4, 8, or 16.
172
173 ``"Sorry, can not handle %d-channel images"``:
174
175 The image had ``SamplesPerPixel`` other than 1, 3, or 4.
176
177 ``Missing needed "PhotometricInterpretation" tag``:
178
179 The image did not have a tag that describes how to display
180 the data.
181
182 ``No "PhotometricInterpretation" tag, assuming RGB``:
183
184 The image was missing a tag that describes how to display it,
185 but because it has 3 or 4 samples/pixel, it is assumed to be
186 RGB.
187
188 ``No "PhotometricInterpretation" tag, assuming min-is-black``:
189
190 The image was missing a tag that describes how to display it,
191 but because it has 1 sample/pixel, it is assumed to be a grayscale
192 or bilevel image.
193
194 ``"No space for photometric conversion table"``:
195
196 There was insufficient memory for a table used to convert
197 image samples to 8-bit RGB.
198
199 ``Missing required "Colormap" tag``:
200
201 A Palette image did not have a required ``Colormap`` tag.
202
203 ``"No space for tile buffer"``:
204
205 There was insufficient memory to allocate an i/o buffer.
206
207 ``"No space for strip buffer"``:
208
209 There was insufficient memory to allocate an i/o buffer.
210
211 ``"Can not handle format"``:
212
213 The image has a format (combination of ``BitsPerSample``,
214 ``SamplesPerPixel`` and ``PhotometricInterpretation``)
215 that can not be handled.
216
217 ``"No space for B&W mapping table"``:
218
219 There was insufficient memory to allocate a table used to map
220 grayscale data to RGB.
221
222 ``"No space for Palette mapping table"``:
223
224 There was insufficient memory to allocate a table used to map
225 data to 8-bit RGB.
226
227 See also
228 --------
229
230 :doc:`TIFFOpen` (3tiff),
231 :doc:`TIFFReadRGBAImage` (3tiff),
232 :doc:`TIFFReadRGBAStrip` (3tiff),
233 :doc:`TIFFReadRGBATile` (3tiff),
234 :doc:`libtiff` (3tiff)