Blame man/TIFFRGBAImage.3tiff

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