Blame man/TIFFRGBAImage.3tiff

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