Blame man/TIFFRGBAImage.3tiff

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