libtiff¶
Synopsis¶
#include <tiffio.h>
cc file.c -ltiff
Description¶
libtiff is a library for reading and writing data files encoded with the "Tag Image File" format, Revision 6.0 (or revision 5.0 or revision 4.0). This file format is suitable for archiving multi-color and monochromatic image data.
The library supports several compression algorithms, as indicated by the
Compression
field, including:
no compression (1),
CCITT 1D Huffman compression (2),
CCITT Group 3 Facsimile compression (3),
CCITT Group 4 Facsimile compression (4),
Lempel-Ziv & Welch compression (5),
baseline JPEG compression (7),
word-aligned 1D Huffman compression (32771),
PackBits compression (32773).
In addition, several nonstandard compression algorithms are supported: the
4-bit compression algorithm used by the
ThunderScan program (32809) (decompression only),
NeXT's 2-bit compression algorithm (32766) (decompression only),
an experimental LZ-style algorithm known as Deflate (32946),
and an experimental CIE LogLuv compression scheme designed
for images with high dynamic range (32845 for LogL and 32845 for LogLuv).
Directory information may be in either little- or big-endian byte order; byte
swapping is automatically done by the library. Data bit ordering may be either
Most Significant Bit (MSB
) to Least Significant Bit (LSB
) or
LSB to MSB.
Finally, the library does not support files in which the
BitsPerSample
,
Compression
,
MinSampleValue
,
or
MaxSampleValue
fields are defined differently on a per-sample basis
(in Rev. 6.0 the
Compression
tag is not defined on a per-sample basis, so this is immaterial).
Data types¶
The library makes extensive use of C typedefs to promote portability. Two sets of typedefs are used, one for communication with clients of the library and one for internal data structures and parsing of the TIFF format. The following typedefs are exposed to users either through function definitions or through parameters passed through the varargs interfaces.
typedef uint32_t ttag_t; // directory tag
typedef uint32_t tdir_t; // directory index
typedef uint16_t tsample_t; // sample number
typedef uint32_t tstrip_t; // strip number
typedef uint32_t ttile_t; // tile number
typedef int64_t tmsize_t; // signed size type (int32_t on 32-bit platforms)
typedef tmsize_t tsize_t; // i/o size in bytes
typedef void* tdata_t; // image data ref
typedef void* thandle_t; // client data handle
typedef uint64_t toff_t; // file offset
Note that
tstrip_t
,
ttile_t
,
and
tsize_t
are constrained to be no more than 32-bit quantities by 32-bit fields they are
stored in in the
TIFF
image.
Likewise
tsample_t
is limited by the 16-bit field used to store the
SamplesPerPixel
tag.
tdir_t
constrains the maximum number of
IFDs
that may appear in an image and may be an arbitrary size (w/o penalty).
Starting with libtiff 4.5.0, tdir_t is a 32-bit unsigned integer. Previously,
it was a 16-bit unsigned integer.
ttag_t
must be either int, unsigned int, pointer, or double because the library uses
a varargs interface and
C restricts the type of the parameter before an ellipsis to be a promoted type.
toff_t
is defined as uint64_t
because TIFF file offsets are (unsigned) 32-bit
quantities, and BigTIFF file offsets are unsigned 64-bit quantities.
A signed value is used because some interfaces return -1 on
error. Finally, note that user-specified data references are passed as opaque
handles and only cast at the lowest layers where their type is presumed.
List of routines¶
The following routines are part of the library. Consult specific manual pages for details on their operation; on most systems doing man function-name will work.
Name |
Description |
---|---|
provides read/write access to the TIFFTagMethods within the TIFF structure to application code without giving access to the private TIFF structure |
|
writes the current state of the directory |
|
very x,y,z,sample is within image |
|
initialize CIE L*a*b* 1976 to RGB conversion state |
|
perform CIE L*a*b* 1976 to CIE XYZ conversion |
|
auxiliary function to free the TIFF structure |
|
return open file's clientdata handle, which represents
the file descriptor used within |
|
open a file for reading or writing |
|
open a file for reading or writing with options, such as re-entrant error and warning handlers may be passed |
|
close a previously opened TIFF file |
|
return strip containing y,sample |
|
return tile containing x,y,z,sample |
|
setup for a custom directory in a open TIFF file |
|
setup for a directory in a open TIFF file |
|
setup for a EXIF custom directory in a open TIFF file within a TIFF tag |
|
setup for a GPS custom directory in a open TIFF file within a TIFF tag |
|
return index of current directory |
|
return file offset of the current directory (instead of an index) |
|
return index of current scanline |
|
return index of current strip |
|
return index of current tile |
|
return the size of TIFF data types |
|
return number of rows for a reasonable-sized strip according to the current settings of the ImageWidth, BitsPerSample and SamplesPerPixel, tags and any compression-specific requirements |
|
return pixel width and height of a reasonable-sized tile; suitable for setting up the TileWidth and TileLength tags |
|
is an advanced writing function to control when/where the [Strip/Tile][Offsets/ByteCounts] arrays are written into the file, and must be used in a particular sequence together with TIFFForceStrileArrayWriting() (see description) |
|
library-wide error handling function printing to |
|
user-specific library-wide error handling function that can be passed
a file handle, which is set to the open TIFF file within |
|
user-specific re-entrant library error handling function, to which its TIFF structure is passed containing the pointer to a user-specific data object |
|
open a file for reading or writing |
|
open a file for reading or writing with options, such as re-entrant error and warning handlers may be passed |
|
get data type from field information |
|
returns if field was unknown to |
|
get field name from field information |
|
get whether to pass a value count to Get/SetField |
|
get number of values to be read from field |
|
returns size of |
|
return data size in bytes of the field data type used for |
|
get tag value from field information |
|
get field information given field name |
|
get field information given tag |
|
get number of values to be written to field |
|
return name of open file |
|
return open file descriptor |
|
find standard codec for the specific scheme |
|
get field information given tag and data type |
|
flush all pending writes |
|
flush pending data writes |
|
is an advanced writing function that writes the [Strip/Tile][Offsets/ByteCounts] arrays at the end of the file (see description) |
|
release storage associated with a directory |
|
return bit reversal table |
|
returns a pointer to the data of the named entry in the clientinfo-list |
|
returns a pointer to file close method |
|
gets list of configured codecs, both built-in and registered by user |
|
return tag value in current directory |
|
return tag value in current directory with default value set if the value is not already set and a default is defined |
|
returns a pointer to memory mapping method |
|
return open file mode |
|
returns a pointer to file read method |
|
returns a pointer to file seek method |
|
returns a pointer to file size requesting method |
|
return value of the TileByteCounts/StripByteCounts array for the specified tile/strile |
|
same as TIFFGetStrileByteCount() and additionally provides an error return |
|
return value of the TileOffsets/StripOffsets array for the specified tile/strile |
|
same as TIFFGetStrileOffset() and additionally provides an error return |
|
return number of entries in the custom tag list |
|
return tag number of the (n.th - 1) entry within the custom tag list |
|
returns a pointer to memory unmapping method |
|
return library version string |
|
returns a pointer to file write method |
|
returns a non-zero value if the file is BigEndian and zero if the file is LittleEndian |
|
returns a non-zero value if the file is in BigTIFF style |
|
return true if image data is byte-swapped |
|
check, whether we have working codec |
|
return true if image data is being returned with bit 0 as the most significant bit |
|
return true if image data is tiled |
|
returns a non-zero value if image data returned through the read interface Routines is being up-sampled |
|
returns a non-zero value if the current directory is the last directory in the file; otherwise zero is returned |
|
adds application defined TIFF tags to the list of known |
|
return number of directories in a file |
|
return number of strips in an image |
|
return number of tiles in an image |
|
open a file for reading or writing |
|
open a file for reading or writing with options, such as re-entrant error and warning handlers may be passed |
|
opens a TIFF file with a Unicode filename, for read/writing |
|
opens a TIFF file with a Unicode filename, for read/writing with options, such as re-entrant error and warning handlers may be passed |
|
allocates memory for |
|
releases the allocated memory for |
|
limits the maximum single memory allocation within |
|
limits the maximum cumulated memory allocation within |
|
setup of a user-specific and per-TIFF handle (re-entrant) error handler |
|
setup of a user-specific and per-TIFF handle (re-entrant) warning handler |
|
print description of the current directory |
|
returns the size in bytes of a complete decoded and packed raster scanline |
|
return size as |
|
return number of bytes in a raw strip |
|
return number of bytes in a raw strip as |
|
specify i/o buffer for reading |
|
read the custom directory from the given offset and set the context of the TIFF-handle tif to that custom directory |
|
read the next directory |
|
read and decode a strip of data |
|
read and decode a tile of data |
|
read the EXIF directory from the given offset and set the context of the TIFF-handle tif to that EXIF directory |
|
replaces the use of |
|
read the GPS directory from the given offset and set the context of the TIFF-handle tif to that GPS directory |
|
read a raw strip of data |
|
read a raw tile of data |
|
read an image into a fixed format raster |
|
works like |
|
reads a single strip of a strip-based image into memory, storing the result in the user supplied RGBA raster |
|
same as |
|
reads a single tile of a tile-based image into memory, storing the result in the user supplied RGBA raster |
|
same as |
|
read and decode a row of data |
|
read and decode a tile of data |
|
override standard codec for the specific scheme |
|
reverse bits in an array of bytes |
|
operates similarly to |
|
setup decoder state for TIFFRGBAImageGet |
|
release TIFFRGBAImage decoder state |
|
read and decode an image |
|
is image readable by TIFFRGBAImageGet |
|
return size of a scanline |
|
return size of a scanline as |
|
set open file's clientdata (file descriptor/handle), and return previous value |
|
adds or replaces an entry in the clientinfo-list |
|
set compression scheme |
|
set the current directory |
|
set error handler function |
|
set error handler function with a file handle as parameter |
|
set a tag's value in the current directory |
|
sets the file name in the TIFF-structure and returns the old file name |
|
overwrites a copy of the open file's I/O descriptor, and return previous value (refer to detailed description) |
|
sets the |
|
set the current directory |
|
is used to register the merge function for user defined tags as an
extender callback with |
|
setup or reset strip parameters and strip array memory |
|
set warning handler function |
|
set warning handler function with a file handle as parameter |
|
set current write offset |
|
return size of a strip |
|
return equivalent size for a strip of data as |
|
swap bytes of an array of doubles |
|
swap bytes of an array of floats |
|
swap bytes of an array of longs |
|
swap bytes of an array of uint64_t |
|
swap bytes of an array of shorts |
|
swap the first and third byte of each triple within an array of bytes |
|
swap bytes of double |
|
swap bytes of float |
|
swap bytes of long |
|
swap bytes of long long (uint64_t) |
|
swap bytes of short |
|
return size of a row in a tile |
|
return size of a row in a tile as |
|
return size of a tile |
|
return size of a tile as |
|
unlink the specified directory from the directory chain |
|
unregisters the codec |
|
clear the contents of the field in the internal structure |
|
return tag value in current directory |
|
return tag value in current directory |
|
set a tag's value in the current directory |
|
return number of bytes in a strip |
|
return number of bytes in a strip with nrows rows of data as |
|
returns the number of bytes in a row-aligned tile with nrows of data |
|
returns the number of bytes in a row-aligned tile with nrows of data
a |
|
library-wide warning handling function printing to |
|
user-specific library-wide warning handling function that can be passed
a file handle, which is set to the open TIFF file within |
|
user-specific re-entrant library warning handling function, to which its TIFF structure is passed containing the pointer to a user-specific data object |
|
sets up the data buffer used to write raw (encoded) data to a file |
|
verify file is writable and that the directory information is setup properly |
|
write the current custom directory (also EXIF or GPS) to file |
|
write the current directory |
|
compress and write a strip of data |
|
compress and write a tile of data |
|
write a raw strip of data |
|
write a raw tile of data |
|
write a scanline of data |
|
compress and write a tile of data |
|
perform CIE XYZ to RGB conversion |
|
perform YCbCr to RGB conversion |
|
initialize YCbCr to RGB conversion state |
Name |
Description |
---|---|
checking for integer overflow before dynamically allocate memory buffer |
|
checking for integer overflow before dynamically reallocate memory buffer |
|
clamps double values into the range of |
|
free memory buffer |
|
return a pointer to the |
|
return a pointer to the |
|
dynamically allocate memory buffer |
|
compare contents of the memory buffers |
|
copy contents of the one buffer to another |
|
fill memory buffer with a constant byte |
|
checks for an integer overflow of the multiplication result of uint32_t and return the multiplication result or 0 if an overflow would happen |
|
checks for an integer overflow of the multiplication result of uint64_t and return the multiplication result or 0 if an overflow would happen |
|
dynamically reallocate memory buffer |
|
Rewrite a field in the directory on disk without regard to updating the TIFF directory structure in memory |
Tag usage¶
For a table of TIFF tags recognized by the library refer to LibTIFF Coverage of the TIFF 6.0 Specification.
Diagnostics¶
All error messages are directed through the TIFFErrorExtR()
routine.
By default messages are directed to stderr
in the form:
module: message\n
.
Warning messages are likewise directed through the
TIFFWarningExtR()
routine.
See also¶
fax2tiff, pal2rgb, ppm2tiff, rgb2ycbcr, raw2tiff, tiff2bw, tiffdither, tiffdump, tiffcp, tiffcmp, tiffgt, tiffinfo, tiffmedian, tiffsplit,
"Tag Image File Format Specification *Revision 6.0*", an Aldus Technical Memorandum.
"The Spirit of TIFF Class F" , an appendix to the TIFF 5.0 specification prepared by Cygnet Technologies.
Bugs¶
The library does not support multi-sample images where some samples have different bits/sample.
The library does not support random access to compressed data that is organized with more than one row per tile or strip.