| 1 |
TIFFReadRGBAImage |
| 2 |
================= |
| 3 |
|
| 4 |
Synopsis |
| 5 |
-------- |
| 6 |
|
| 7 |
.. highlight:: c |
| 8 |
|
| 9 |
:: |
| 10 |
|
| 11 |
#include <tiffio.h> |
| 12 |
|
| 13 |
.. c:macro:: TIFFGetR(abgr) |
| 14 |
|
| 15 |
:c:expr:`((abgr) & 0xff)` |
| 16 |
|
| 17 |
.. c:macro:: TIFFGetG(abgr) |
| 18 |
|
| 19 |
:c:expr:`(((abgr) >> 8) & 0xff)` |
| 20 |
|
| 21 |
.. c:macro:: TIFFGetB(abgr) |
| 22 |
|
| 23 |
:c:expr:`(((abgr) >> 16) & 0xff)` |
| 24 |
|
| 25 |
.. c:macro:: TIFFGetA(abgr) |
| 26 |
|
| 27 |
:c:expr:`(((abgr) >> 24) & 0xff)` |
| 28 |
|
| 29 |
.. c:function:: int TIFFReadRGBAImage(TIFF* tif, uint32_t width, uint32_t height, uint32_t* raster, int stopOnError) |
| 30 |
|
| 31 |
.. c:function:: int TIFFReadRGBAImageOriented(TIFF* tif, uint32_t width, uint32_t height, uint32_t * raster, int orientation, int stopOnError) |
| 32 |
|
| 33 |
Description |
| 34 |
----------- |
| 35 |
|
| 36 |
:c:func:`TIFFReadRGBAImage` reads a strip- or tile-based image into memory, |
| 37 |
storing the result in the user supplied *raster*. |
| 38 |
The raster is assumed to be an array of *width* × *height* 32-bit entries, |
| 39 |
where *width* must be less than or equal to the width of the image |
| 40 |
(*height* may be any non-zero size). |
| 41 |
If the raster dimensions are smaller than the image, the image data is |
| 42 |
cropped to the raster bounds. |
| 43 |
If the raster height is greater than that of the image, then the image data |
| 44 |
are placed in the lower part of the raster. |
| 45 |
(Note that the raster is assume to be organized such that the pixel |
| 46 |
at location (*x*, *y*) is *raster* [ *y* × *width* + *x* ]; |
| 47 |
with the raster origin in the lower-left hand corner.) |
| 48 |
|
| 49 |
:c:func:`TIFFReadRGBAImageOriented` works like :c:func:`TIFFReadRGBAImage` |
| 50 |
except that the user can specify the raster origin position with the |
| 51 |
*orientation* parameter. Four orientations are supported: |
| 52 |
|
| 53 |
* :c:macro:`ORIENTATION_TOPLEFT`: origin in top-left corner, |
| 54 |
* :c:macro:`ORIENTATION_TOPRIGHT`: origin in top-right corner, |
| 55 |
* :c:macro:`ORIENTATION_BOTLEFT`: origin in bottom-left corner |
| 56 |
* :c:macro:`ORIENTATION_BOTRIGHT`: origin in bottom-right corner. |
| 57 |
|
| 58 |
If you choose :c:macro:`ORIENTATION_BOTLEFT`, the result will be the same |
| 59 |
as returned by the :c:func:`TIFFReadRGBAImage`. |
| 60 |
|
| 61 |
Raster pixels are 8-bit packed red, green, blue, alpha samples. |
| 62 |
The macros :c:macro:`TIFFGetR`, :c:macro:`TIFFGetG`, :c:macro:`TIFFGetB`, |
| 63 |
and :c:macro:`TIFFGetA` should be used to access individual samples. |
| 64 |
Images without Associated Alpha matting information have a constant |
| 65 |
Alpha of 1.0 (255). |
| 66 |
|
| 67 |
:c:func:`TIFFReadRGBAImage` converts non-8-bit images by scaling sample |
| 68 |
values. Palette, grayscale, bilevel, CMYK, and YCbCr images are |
| 69 |
converted to RGB transparently. |
| 70 |
Raster pixels are returned uncorrected by any colorimetry information |
| 71 |
present in the directory. |
| 72 |
|
| 73 |
The parameter *stopOnError* specifies how to act if an error is |
| 74 |
encountered while reading the image. If *stopOnError* is non-zero, then |
| 75 |
an error will terminate the operation; otherwise :c:func:`TIFFReadRGBAImage` |
| 76 |
will continue processing data until all the possible data in the |
| 77 |
image have been requested. |
| 78 |
|
| 79 |
Notes |
| 80 |
----- |
| 81 |
|
| 82 |
In C++ the *stopOnError* parameter defaults to 0. |
| 83 |
|
| 84 |
``SamplesPerPixel`` must be either 1, 2, 4, 8, or 16 bits. |
| 85 |
Colorimetric samples/pixel must be either 1, 3, or 4 (i.e. |
| 86 |
``SamplesPerPixel`` minus ``ExtraSamples``). |
| 87 |
|
| 88 |
Palettte image colormaps that appear to be incorrectly written |
| 89 |
as 8-bit values are automatically scaled to 16-bits. |
| 90 |
|
| 91 |
:c:func:`IFFReadRGBAImage` is just a wrapper around the more general |
| 92 |
:doc:`TIFFRGBAImage` facilities. |
| 93 |
|
| 94 |
Return values |
| 95 |
------------- |
| 96 |
|
| 97 |
1 is returned if the image was successfully read and converted. |
| 98 |
Otherwise, 0 is returned if an error was encountered and |
| 99 |
*stopOnError* is zero. |
| 100 |
|
| 101 |
.. TODO: Specify, what the return value is if an error occurs and stopOnError was non-zero. |
| 102 |
|
| 103 |
Diagnostics |
| 104 |
----------- |
| 105 |
|
| 106 |
All error messages are directed to the :c:func:`TIFFErrorExtR` routine. |
| 107 |
|
| 108 |
``"Sorry, can not handle %d-bit pictures"``: |
| 109 |
|
| 110 |
The image had ``BitsPerSample`` other than 1, 2, 4, 8, or 16. |
| 111 |
|
| 112 |
``"Sorry, can not handle %d-channel images"``: |
| 113 |
|
| 114 |
The image had ``SamplesPerPixel`` other than 1, 3, or 4. |
| 115 |
|
| 116 |
``Missing needed "PhotometricInterpretation" tag``: |
| 117 |
|
| 118 |
The image did not have a tag that describes how to display |
| 119 |
the data. |
| 120 |
|
| 121 |
``No "PhotometricInterpretation" tag, assuming RGB``: |
| 122 |
|
| 123 |
The image was missing a tag that describes how to display it, |
| 124 |
but because it has 3 or 4 samples/pixel, it is assumed to be |
| 125 |
RGB. |
| 126 |
|
| 127 |
``No "PhotometricInterpretation" tag, assuming min-is-black``: |
| 128 |
|
| 129 |
The image was missing a tag that describes how to display it, |
| 130 |
but because it has 1 sample/pixel, it is assumed to be a grayscale |
| 131 |
or bilevel image. |
| 132 |
|
| 133 |
``"No space for photometric conversion table"``: |
| 134 |
|
| 135 |
There was insufficient memory for a table used to convert |
| 136 |
image samples to 8-bit RGB. |
| 137 |
|
| 138 |
``Missing required "Colormap" tag``: |
| 139 |
|
| 140 |
A Palette image did not have a required ``Colormap`` tag. |
| 141 |
|
| 142 |
``"No space for tile buffer"``: |
| 143 |
|
| 144 |
There was insufficient memory to allocate an i/o buffer. |
| 145 |
|
| 146 |
``"No space for strip buffer"``: |
| 147 |
|
| 148 |
There was insufficient memory to allocate an i/o buffer. |
| 149 |
|
| 150 |
``"Can not handle format"``: |
| 151 |
|
| 152 |
The image has a format (combination of ``BitsPerSample``, |
| 153 |
``SamplesPerPixel``, and ``PhotometricInterpretation``) |
| 154 |
that :c:func:`TIFFReadRGBAImage` can not handle. |
| 155 |
|
| 156 |
``"No space for B&W mapping table"``: |
| 157 |
|
| 158 |
There was insufficient memory to allocate a table used to map |
| 159 |
grayscale data to RGB. |
| 160 |
|
| 161 |
``"No space for Palette mapping table"``: |
| 162 |
|
| 163 |
There was insufficient memory to allocate a table used to map |
| 164 |
data to 8-bit RGB. |
| 165 |
|
| 166 |
See also |
| 167 |
-------- |
| 168 |
|
| 169 |
:doc:`TIFFOpen` (3tiff), |
| 170 |
:doc:`TIFFRGBAImage` (3tiff), |
| 171 |
:doc:`TIFFReadRGBAStrip` (3tiff), |
| 172 |
:doc:`TIFFReadRGBATile` (3tiff), |
| 173 |
:doc:`libtiff` (3tiff) |