Blame man/TIFFRGBAImage.3tiff

Packit Service 2594b8
.\" $Id: TIFFRGBAImage.3tiff,v 1.3 2016-09-25 20:05:49 bfriesen Exp $
Packit Service 2594b8
.\"
Packit Service 2594b8
.\" Copyright (c) 1991-1997 Sam Leffler
Packit Service 2594b8
.\" Copyright (c) 1991-1997 Silicon Graphics, Inc.
Packit Service 2594b8
.\"
Packit Service 2594b8
.\" Permission to use, copy, modify, distribute, and sell this software and 
Packit Service 2594b8
.\" its documentation for any purpose is hereby granted without fee, provided
Packit Service 2594b8
.\" that (i) the above copyright notices and this permission notice appear in
Packit Service 2594b8
.\" all copies of the software and related documentation, and (ii) the names of
Packit Service 2594b8
.\" Sam Leffler and Silicon Graphics may not be used in any advertising or
Packit Service 2594b8
.\" publicity relating to the software without the specific, prior written
Packit Service 2594b8
.\" permission of Sam Leffler and Silicon Graphics.
Packit Service 2594b8
.\" 
Packit Service 2594b8
.\" THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
Packit Service 2594b8
.\" EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
Packit Service 2594b8
.\" WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
Packit Service 2594b8
.\" 
Packit Service 2594b8
.\" IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
Packit Service 2594b8
.\" ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
Packit Service 2594b8
.\" OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
Packit Service 2594b8
.\" WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
Packit Service 2594b8
.\" LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
Packit Service 2594b8
.\" OF THIS SOFTWARE.
Packit Service 2594b8
.\"
Packit Service 2594b8
.if n .po 0
Packit Service 2594b8
.TH TIFFRGBAImage 3TIFF "October 29, 2004" "libtiff"
Packit Service 2594b8
.SH NAME
Packit Service 2594b8
TIFFRGBAImageOK, TIFFRGBAImageBegin, TIFFRGBAImageGet, TIFFRGBAImageEnd
Packit Service 2594b8
\- read and decode an image into a raster
Packit Service 2594b8
.SH SYNOPSIS
Packit Service 2594b8
.B "#include <tiffio.h>"
Packit Service 2594b8
.sp
Packit Service 2594b8
.B "typedef unsigned char TIFFRGBValue;"
Packit Service 2594b8
.B "typedef struct _TIFFRGBAImage TIFFRGBAImage;"
Packit Service 2594b8
.sp
Packit Service 2594b8
.BI "int TIFFRGBAImageOK(TIFF *" tif ", char " emsg[1024] ")"
Packit Service 2594b8
.br
Packit Service 2594b8
.BI "int TIFFRGBAImageBegin(TIFFRGBAImage *" img ", TIFF* " tif ", int " stopOnError ", char " emsg[1024] ")"
Packit Service 2594b8
.br
Packit Service 2594b8
.BI "int TIFFRGBAImageGet(TIFFRGBAImage *" img ", uint32* " raster ", uint32 " width " , uint32 " height ")"
Packit Service 2594b8
.br
Packit Service 2594b8
.BI "void TIFFRGBAImageEnd(TIFFRGBAImage *" img ")"
Packit Service 2594b8
.br
Packit Service 2594b8
.SH DESCRIPTION
Packit Service 2594b8
The routines described here provide a high-level interface
Packit Service 2594b8
through which
Packit Service 2594b8
.SM TIFF
Packit Service 2594b8
images may be read into memory.
Packit Service 2594b8
Images may be strip- or tile-based and have a variety of different
Packit Service 2594b8
characteristics: bits/sample, samples/pixel, photometric, etc.
Packit Service 2594b8
Decoding state is encapsulated in a
Packit Service 2594b8
.I TIFFRGBAImage
Packit Service 2594b8
structure making it possible to capture state for multiple images
Packit Service 2594b8
and quickly switch between them.
Packit Service 2594b8
The target raster format can be customized to a particular application's
Packit Service 2594b8
needs by installing custom routines that manipulate image data
Packit Service 2594b8
according to application requirements.
Packit Service 2594b8
.PP
Packit Service 2594b8
The default usage for these routines is: check if an image can
Packit Service 2594b8
be processed using
Packit Service 2594b8
.IR TIFFRGBAImageOK ,
Packit Service 2594b8
construct a decoder state block using
Packit Service 2594b8
.IR TIFFRGBAImageBegin ,
Packit Service 2594b8
read and decode an image into a target raster using
Packit Service 2594b8
.IR TIFFRGBAImageGet ,
Packit Service 2594b8
and then
Packit Service 2594b8
release resources using
Packit Service 2594b8
.IR TIFFRGBAImageEnd .
Packit Service 2594b8
.I TIFFRGBAImageGet
Packit Service 2594b8
can be called multiple times to decode an image using different
Packit Service 2594b8
state parameters.
Packit Service 2594b8
If multiple images are to be displayed and there is not enough
Packit Service 2594b8
space for each of the decoded rasters, multiple state blocks can
Packit Service 2594b8
be managed and then calls can be made to
Packit Service 2594b8
.I TIFFRGBAImageGet
Packit Service 2594b8
as needed to display an image.
Packit Service 2594b8
.PP
Packit Service 2594b8
The generated raster is assumed to be an array of
Packit Service 2594b8
.I width
Packit Service 2594b8
times
Packit Service 2594b8
.I height
Packit Service 2594b8
32-bit entries, where
Packit Service 2594b8
.I width
Packit Service 2594b8
must be less than or equal to the width of the image (\c
Packit Service 2594b8
.I height
Packit Service 2594b8
may be any non-zero size).
Packit Service 2594b8
If the raster dimensions are smaller than the image, the image data
Packit Service 2594b8
is cropped to the raster bounds.
Packit Service 2594b8
If the raster height is greater than that of the image, then the
Packit Service 2594b8
image data are placed in the lower part of the raster.
Packit Service 2594b8
(Note that the raster is assume to be organized such that the pixel
Packit Service 2594b8
at location (\fIx\fP,\fIy\fP) is \fIraster\fP[\fIy\fP*\fIwidth\fP+\fIx\fP];
Packit Service 2594b8
with the raster origin in the 
Packit Service 2594b8
.B lower-left
Packit Service 2594b8
hand corner.)
Packit Service 2594b8
.PP
Packit Service 2594b8
Raster pixels are 8-bit packed red, green, blue, alpha samples.
Packit Service 2594b8
The macros
Packit Service 2594b8
.IR TIFFGetR ,
Packit Service 2594b8
.IR TIFFGetG ,
Packit Service 2594b8
.IR TIFFGetB ,
Packit Service 2594b8
and
Packit Service 2594b8
.I TIFFGetA
Packit Service 2594b8
should be used to access individual samples.
Packit Service 2594b8
Images without Associated Alpha matting information have a constant
Packit Service 2594b8
Alpha of 1.0 (255).
Packit Service 2594b8
.PP
Packit Service 2594b8
.I TIFFRGBAImageGet
Packit Service 2594b8
converts non-8-bit images by scaling sample values.
Packit Service 2594b8
Palette, grayscale, bilevel, 
Packit Service 2594b8
.SM CMYK\c
Packit Service 2594b8
, and YCbCr images are converted to
Packit Service 2594b8
.SM RGB
Packit Service 2594b8
transparently.
Packit Service 2594b8
Raster pixels are returned uncorrected by any colorimetry information
Packit Service 2594b8
present in the directory.
Packit Service 2594b8
.PP
Packit Service 2594b8
The parameter
Packit Service 2594b8
.I stopOnError
Packit Service 2594b8
specifies how to act if an error is encountered while reading
Packit Service 2594b8
the image.
Packit Service 2594b8
If
Packit Service 2594b8
.I stopOnError
Packit Service 2594b8
is non-zero, then an error will terminate the operation; otherwise
Packit Service 2594b8
.I TIFFRGBAImageGet
Packit Service 2594b8
will continue processing data until all the possible data in the
Packit Service 2594b8
image have been requested.
Packit Service 2594b8
.SH "ALTERNATE RASTER FORMATS"
Packit Service 2594b8
To use the core support for reading and processing 
Packit Service 2594b8
.SM TIFF
Packit Service 2594b8
images, but write the resulting raster data in a different format
Packit Service 2594b8
one need only override the ``\fIput methods\fP'' used to store raster data.
Packit Service 2594b8
These methods are are defined in the
Packit Service 2594b8
.I TIFFRGBAImage
Packit Service 2594b8
structure and initially setup by
Packit Service 2594b8
.I TIFFRGBAImageBegin
Packit Service 2594b8
to point to routines that pack raster data in the default
Packit Service 2594b8
.SM ABGR
Packit Service 2594b8
pixel format.
Packit Service 2594b8
Two different routines are used according to the physical organization
Packit Service 2594b8
of the image data in the file: 
Packit Service 2594b8
.IR PlanarConfiguration =1
Packit Service 2594b8
(packed samples),
Packit Service 2594b8
and 
Packit Service 2594b8
.IR PlanarConfiguration =2
Packit Service 2594b8
(separated samples).
Packit Service 2594b8
Note that this mechanism can be used to transform the data before
Packit Service 2594b8
storing it in the raster.
Packit Service 2594b8
For example one can convert data
Packit Service 2594b8
to colormap indices for display on a colormap display.
Packit Service 2594b8
.SH "SIMULTANEOUS RASTER STORE AND DISPLAY"
Packit Service 2594b8
It is simple to display an image as it is being read into memory
Packit Service 2594b8
by overriding the put methods as described above for supporting
Packit Service 2594b8
alternate raster formats.
Packit Service 2594b8
Simply keep a reference to the default put methods setup by
Packit Service 2594b8
.I TIFFRGBAImageBegin
Packit Service 2594b8
and then invoke them before or after each display operation.
Packit Service 2594b8
For example, the
Packit Service 2594b8
.IR tiffgt (1)
Packit Service 2594b8
utility uses the following put method to update the display as
Packit Service 2594b8
the raster is being filled:
Packit Service 2594b8
.sp
Packit Service 2594b8
.nf
Packit Service 2594b8
.ft C
Packit Service 2594b8
static void
Packit Service 2594b8
putContigAndDraw(TIFFRGBAImage* img, uint32* raster,
Packit Service 2594b8
    uint32 x, uint32 y, uint32 w, uint32 h,
Packit Service 2594b8
    int32 fromskew, int32 toskew,
Packit Service 2594b8
    unsigned char* cp)
Packit Service 2594b8
{
Packit Service 2594b8
    (*putContig)(img, raster, x, y, w, h, fromskew, toskew, cp);
Packit Service 2594b8
    if (x+w == width) {
Packit Service 2594b8
	w = width;
Packit Service 2594b8
	if (img->orientation == ORIENTATION_TOPLEFT)
Packit Service 2594b8
	    lrectwrite(0, y-(h-1), w-1, y, raster-x-(h-1)*w);
Packit Service 2594b8
	else
Packit Service 2594b8
	    lrectwrite(0, y, w-1, y+h-1, raster);
Packit Service 2594b8
    }
Packit Service 2594b8
}
Packit Service 2594b8
.ft R
Packit Service 2594b8
.fi
Packit Service 2594b8
.sp
Packit Service 2594b8
(the original routine provided by the library is saved in the
Packit Service 2594b8
variable 
Packit Service 2594b8
.IR putContig .)
Packit Service 2594b8
.SH "SUPPORTING ADDITIONAL TIFF FORMATS"
Packit Service 2594b8
The
Packit Service 2594b8
.I TIFFRGBAImage
Packit Service 2594b8
routines support the most commonly encountered flavors of
Packit Service 2594b8
.SM TIFF.
Packit Service 2594b8
It is possible to extend this support by overriding the ``\fIget method\fP''
Packit Service 2594b8
invoked by
Packit Service 2594b8
.I TIFFRGBAImageGet
Packit Service 2594b8
to read 
Packit Service 2594b8
.SM TIFF
Packit Service 2594b8
image data.
Packit Service 2594b8
Details of doing this are a bit involved, it is best to make a copy
Packit Service 2594b8
of an existing get method and modify it to suit the needs of an
Packit Service 2594b8
application.
Packit Service 2594b8
.SH NOTES
Packit Service 2594b8
Samples must be either 1, 2, 4, 8, or 16 bits.
Packit Service 2594b8
Colorimetric samples/pixel must be either 1, 3, or 4 (i.e.
Packit Service 2594b8
.I SamplesPerPixel
Packit Service 2594b8
minus
Packit Service 2594b8
.IR ExtraSamples ).
Packit Service 2594b8
.PP
Packit Service 2594b8
Palette image colormaps that appear to be incorrectly written
Packit Service 2594b8
as 8-bit values are automatically scaled to 16-bits.
Packit Service 2594b8
.SH "RETURN VALUES"
Packit Service 2594b8
All routines return
Packit Service 2594b8
1 if the operation was successful.
Packit Service 2594b8
Otherwise, 0 is returned if an error was encountered and
Packit Service 2594b8
.I stopOnError
Packit Service 2594b8
is zero.
Packit Service 2594b8
.SH DIAGNOSTICS
Packit Service 2594b8
All error messages are directed to the
Packit Service 2594b8
.IR TIFFError (3TIFF)
Packit Service 2594b8
routine.
Packit Service 2594b8
.PP
Packit Service 2594b8
.BR "Sorry, can not handle %d-bit pictures" .
Packit Service 2594b8
The image had
Packit Service 2594b8
.I BitsPerSample
Packit Service 2594b8
other than 1, 2, 4, 8, or 16.
Packit Service 2594b8
.PP
Packit Service 2594b8
.BR "Sorry, can not handle %d-channel images" .
Packit Service 2594b8
The image had
Packit Service 2594b8
.I SamplesPerPixel
Packit Service 2594b8
other than 1, 3, or 4.
Packit Service 2594b8
.PP
Packit Service 2594b8
\fBMissing needed "PhotometricInterpretation" tag\fP.
Packit Service 2594b8
The image did not have a tag that describes how to display
Packit Service 2594b8
the data.
Packit Service 2594b8
.PP
Packit Service 2594b8
\fBNo "PhotometricInterpretation" tag, assuming RGB\fP.
Packit Service 2594b8
The image was missing a tag that describes how to display it,
Packit Service 2594b8
but because it has 3 or 4 samples/pixel, it is assumed to be
Packit Service 2594b8
.SM RGB.
Packit Service 2594b8
.PP
Packit Service 2594b8
\fBNo "PhotometricInterpretation" tag, assuming min-is-black\fP.
Packit Service 2594b8
The image was missing a tag that describes how to display it,
Packit Service 2594b8
but because it has 1 sample/pixel, it is assumed to be a grayscale
Packit Service 2594b8
or bilevel image.
Packit Service 2594b8
.PP
Packit Service 2594b8
.BR "No space for photometric conversion table" .
Packit Service 2594b8
There was insufficient memory for a table used to convert
Packit Service 2594b8
image samples to 8-bit
Packit Service 2594b8
.SM RGB.
Packit Service 2594b8
.PP
Packit Service 2594b8
\fBMissing required "Colormap" tag\fP.
Packit Service 2594b8
A Palette image did not have a required
Packit Service 2594b8
.I Colormap
Packit Service 2594b8
tag.
Packit Service 2594b8
.PP
Packit Service 2594b8
.BR "No space for tile buffer" .
Packit Service 2594b8
There was insufficient memory to allocate an i/o buffer.
Packit Service 2594b8
.PP
Packit Service 2594b8
.BR "No space for strip buffer" .
Packit Service 2594b8
There was insufficient memory to allocate an i/o buffer.
Packit Service 2594b8
.PP
Packit Service 2594b8
.BR "Can not handle format" .
Packit Service 2594b8
The image has a format (combination of
Packit Service 2594b8
.IR BitsPerSample ,
Packit Service 2594b8
.IR SamplesPerPixel ,
Packit Service 2594b8
and
Packit Service 2594b8
.IR PhotometricInterpretation )
Packit Service 2594b8
that can not be handled.
Packit Service 2594b8
.PP
Packit Service 2594b8
.BR "No space for B&W mapping table" .
Packit Service 2594b8
There was insufficient memory to allocate a table used to map
Packit Service 2594b8
grayscale data to
Packit Service 2594b8
.SM RGB.
Packit Service 2594b8
.PP
Packit Service 2594b8
.BR "No space for Palette mapping table" .
Packit Service 2594b8
There was insufficient memory to allocate a table used to map
Packit Service 2594b8
data to 8-bit
Packit Service 2594b8
.SM RGB.
Packit Service 2594b8
.SH "SEE ALSO"
Packit Service 2594b8
.BR TIFFOpen (3TIFF),
Packit Service 2594b8
.BR TIFFReadRGBAImage (3TIFF),
Packit Service 2594b8
.BR TIFFReadRGBAImageOriented (3TIFF),
Packit Service 2594b8
.BR TIFFReadRGBAStrip (3TIFF),
Packit Service 2594b8
.BR TIFFReadRGBATile (3TIFF),
Packit Service 2594b8
.BR libtiff (3TIFF)
Packit Service 2594b8
.PP
Packit Service 2594b8
Libtiff library home page:
Packit Service 2594b8
.BR http://www.simplesystems.org/libtiff/