|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<title></title>
|
|
kusano |
7d535a |
Modifying The TIFF Library
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<font face="Arial, Helvetica, Sans"></font>
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Modifying The TIFF Library
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
This chapter provides information about the internal structure of
|
|
kusano |
7d535a |
the library, how to control the configuration when building it, and
|
|
kusano |
7d535a |
how to add new support to the library.
|
|
kusano |
7d535a |
The following sections are found in this chapter:
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Library Configuration
|
|
kusano |
7d535a |
General Portability Comments
|
|
kusano |
7d535a |
Types and Portability
|
|
kusano |
7d535a |
Adding New Tags
|
|
kusano |
7d535a |
Adding New Builtin Codecs
|
|
kusano |
7d535a |
Adding New Codec-private Tags
|
|
kusano |
7d535a |
Other Comments
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Library Configuration
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Information on compiling the library is given
|
|
kusano |
7d535a |
elsewhere in this documentation.
|
|
kusano |
7d535a |
This section describes the low-level mechanisms used to control
|
|
kusano |
7d535a |
the optional parts of the library that are configured at build
|
|
kusano |
7d535a |
time. Control is based on
|
|
kusano |
7d535a |
a collection of C defines that are specified either on the compiler
|
|
kusano |
7d535a |
command line or in a configuration file such as <tt>port.h</tt>
|
|
kusano |
7d535a |
(as generated by the <tt>configure</tt> script for UNIX systems)
|
|
kusano |
7d535a |
or tiffconf.h.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Configuration defines are split into three areas:
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
those that control which compression schemes are
|
|
kusano |
7d535a |
configured as part of the builtin codecs,
|
|
kusano |
7d535a |
those that control support for groups of tags that
|
|
kusano |
7d535a |
are considered optional, and
|
|
kusano |
7d535a |
those that control operating system or machine-specific support.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
If the define <tt>COMPRESSION_SUPPORT</tt> is not defined
|
|
kusano |
7d535a |
then a default set of compression schemes is automatically
|
|
kusano |
7d535a |
configured:
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
CCITT Group 3 and 4 algorithms (compression codes 2, 3, 4, and 32771),
|
|
kusano |
7d535a |
the Macintosh PackBits algorithm (compression 32773),
|
|
kusano |
7d535a |
a 4-bit run-length encoding scheme from ThunderScan (compression 32809),
|
|
kusano |
7d535a |
a 2-bit encoding scheme used by NeXT (compression 32766), and
|
|
kusano |
7d535a |
two experimental schemes intended for images with high dynamic range
|
|
kusano |
7d535a |
(compression 34676 and 34677).
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
To override the default compression behaviour define
|
|
kusano |
7d535a |
<tt>COMPRESSION_SUPPORT</tt> and then one or more additional defines
|
|
kusano |
7d535a |
to enable configuration of the appropriate codecs (see the table
|
|
kusano |
7d535a |
below); e.g.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#define COMPRESSION_SUPPORT
|
|
kusano |
7d535a |
#define CCITT_SUPPORT
|
|
kusano |
7d535a |
#define PACKBITS_SUPPORT
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Several other compression schemes are configured separately from
|
|
kusano |
7d535a |
the default set because they depend on ancillary software
|
|
kusano |
7d535a |
packages that are not distributed with <tt>libtiff</tt>.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Support for JPEG compression is controlled by <tt>JPEG_SUPPORT</tt>.
|
|
kusano |
7d535a |
The JPEG codec that comes with <tt>libtiff</tt> is designed for
|
|
kusano |
7d535a |
use with release 5 or later of the Independent JPEG Group's freely
|
|
kusano |
7d535a |
available software distribution.
|
|
kusano |
7d535a |
This software can be retrieved from the directory
|
|
kusano |
7d535a |
ftp.uu.net:/graphics/jpeg/.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Enabling JPEG support automatically enables support for
|
|
kusano |
7d535a |
the TIFF 6.0 colorimetry and YCbCr-related tags.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Experimental support for the deflate algorithm is controlled by
|
|
kusano |
7d535a |
<tt>DEFLATE_SUPPORT</tt>.
|
|
kusano |
7d535a |
The deflate codec that comes with <tt>libtiff</tt> is designed
|
|
kusano |
7d535a |
for use with version 0.99 or later of the freely available
|
|
kusano |
7d535a |
<tt>libz</tt> library written by Jean-loup Gailly and Mark Adler.
|
|
kusano |
7d535a |
The data format used by this library is described
|
|
kusano |
7d535a |
in the files
|
|
kusano |
7d535a |
zlib-3.1.doc,
|
|
kusano |
7d535a |
and
|
|
kusano |
7d535a |
deflate-1.1.doc,
|
|
kusano |
7d535a |
available in the directory
|
|
kusano |
7d535a |
ftp.uu.net:/pub/archiving/zip/doc.
|
|
kusano |
7d535a |
The library can be retried from the directory
|
|
kusano |
7d535a |
ftp.uu.net:/pub/archiving/zip/zlib/
|
|
kusano |
7d535a |
(or try quest.jpl.nasa.gov:/beta/zlib/).
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
The deflate algorithm is experimental. Do not expect
|
|
kusano |
7d535a |
to exchange files using this compression scheme;
|
|
kusano |
7d535a |
it is included only because the similar, and more common,
|
|
kusano |
7d535a |
LZW algorithm is claimed to be governed by licensing restrictions.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
By default tiffconf.h defines
|
|
kusano |
7d535a |
<tt>COLORIMETRY_SUPPORT</tt>,
|
|
kusano |
7d535a |
<tt>YCBCR_SUPPORT</tt>,
|
|
kusano |
7d535a |
and
|
|
kusano |
7d535a |
<tt>CMYK_SUPPORT</tt>.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
DefineDescription
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>CCITT_SUPPORT</tt>
|
|
kusano |
7d535a |
CCITT Group 3 and 4 algorithms (compression codes 2, 3, 4,
|
|
kusano |
7d535a |
and 32771)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>PACKBITS_SUPPORT</tt>
|
|
kusano |
7d535a |
Macintosh PackBits algorithm (compression 32773)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>LZW_SUPPORT</tt>
|
|
kusano |
7d535a |
Lempel-Ziv & Welch (LZW) algorithm (compression 5)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>THUNDER_SUPPORT</tt>
|
|
kusano |
7d535a |
4-bit
|
|
kusano |
7d535a |
run-length encoding scheme from ThunderScan (compression 32809)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>NEXT_SUPPORT</tt>
|
|
kusano |
7d535a |
2-bit encoding scheme used by NeXT (compression 32766)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>OJPEG_SUPPORT</tt>
|
|
kusano |
7d535a |
obsolete JPEG scheme defined in the 6.0 spec (compression 6)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>JPEG_SUPPORT</tt>
|
|
kusano |
7d535a |
current JPEG scheme defined in TTN2 (compression 7)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>ZIP_SUPPORT</tt>
|
|
kusano |
7d535a |
experimental Deflate scheme (compression 32946)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>PIXARLOG_SUPPORT</tt>
|
|
kusano |
7d535a |
Pixar's compression scheme for high-resolution color images (compression 32909)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>SGILOG_SUPPORT</tt>
|
|
kusano |
7d535a |
SGI's compression scheme for high-resolution color images (compression 34676 and 34677)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>COLORIMETRY_SUPPORT</tt>
|
|
kusano |
7d535a |
support for the TIFF 6.0 colorimetry tags
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>YCBCR_SUPPORT</tt>
|
|
kusano |
7d535a |
support for the TIFF 6.0 YCbCr-related tags
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>CMYK_SUPPORT</tt>
|
|
kusano |
7d535a |
support for the TIFF 6.0 CMYK-related tags
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>ICC_SUPPORT</tt>
|
|
kusano |
7d535a |
support for the ICC Profile tag; see
|
|
kusano |
7d535a |
The ICC Profile Format Specification,
|
|
kusano |
7d535a |
Annex B.3 "Embedding ICC Profiles in TIFF Files";
|
|
kusano |
7d535a |
available at
|
|
kusano |
7d535a |
http://www.color.org
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
General Portability Comments
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
This software is developed on Silicon Graphics UNIX
|
|
kusano |
7d535a |
systems (big-endian, MIPS CPU, 32-bit ints,
|
|
kusano |
7d535a |
IEEE floating point).
|
|
kusano |
7d535a |
The <tt>configure</tt> shell script generates the appropriate
|
|
kusano |
7d535a |
include files and make files for UNIX systems.
|
|
kusano |
7d535a |
Makefiles exist for non-UNIX platforms that the
|
|
kusano |
7d535a |
code runs on -- this work has mostly been done by other people.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
In general, the code is guaranteed to work only on SGI machines.
|
|
kusano |
7d535a |
In practice it is highly portable to any 32-bit or 64-bit system and much
|
|
kusano |
7d535a |
work has been done to insure portability to 16-bit systems.
|
|
kusano |
7d535a |
If you encounter portability problems please return fixes so
|
|
kusano |
7d535a |
that future distributions can be improved.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
The software is written to assume an ANSI C compilation environment.
|
|
kusano |
7d535a |
If your compiler does not support ANSI function prototypes, <tt>const</tt>,
|
|
kusano |
7d535a |
and <tt><stdarg.h></tt> then you will have to make modifications to the
|
|
kusano |
7d535a |
software. In the past I have tried to support compilers without <tt>const</tt>
|
|
kusano |
7d535a |
and systems without <tt><stdarg.h></tt>, but I am
|
|
kusano |
7d535a |
no longer interested in these
|
|
kusano |
7d535a |
antiquated environments. With the general availability of
|
|
kusano |
7d535a |
the freely available GCC compiler, I
|
|
kusano |
7d535a |
see no reason to incorporate modifications to the software for these
|
|
kusano |
7d535a |
purposes.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
An effort has been made to isolate as many of the
|
|
kusano |
7d535a |
operating system-dependencies
|
|
kusano |
7d535a |
as possible in two files: tiffcomp.h and
|
|
kusano |
7d535a |
libtiff/tif_<os>.c. The latter file contains
|
|
kusano |
7d535a |
operating system-specific routines to do I/O and I/O-related operations.
|
|
kusano |
7d535a |
The UNIX (tif_unix.c),
|
|
kusano |
7d535a |
Macintosh (tif_apple.c),
|
|
kusano |
7d535a |
and VMS (tif_vms.c)
|
|
kusano |
7d535a |
code has had the most use;
|
|
kusano |
7d535a |
the MS/DOS support (tif_msdos.c) assumes
|
|
kusano |
7d535a |
some level of UNIX system call emulation (i.e.
|
|
kusano |
7d535a |
<tt>open</tt>,
|
|
kusano |
7d535a |
<tt>read</tt>,
|
|
kusano |
7d535a |
<tt>write</tt>,
|
|
kusano |
7d535a |
<tt>fstat</tt>,
|
|
kusano |
7d535a |
<tt>malloc</tt>,
|
|
kusano |
7d535a |
<tt>free</tt>).
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Native CPU byte order is determined on the fly by
|
|
kusano |
7d535a |
the library and does not need to be specified.
|
|
kusano |
7d535a |
The <tt>HOST_FILLORDER</tt> and <tt>HOST_BIGENDIAN</tt>
|
|
kusano |
7d535a |
definitions are not currently used, but may be employed by
|
|
kusano |
7d535a |
codecs for optimization purposes.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
The following defines control general portability:
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>BSDTYPES</tt>
|
|
kusano |
7d535a |
Define this if your system does NOT define the
|
|
kusano |
7d535a |
usual BSD typedefs: <tt>u_char</tt>,
|
|
kusano |
7d535a |
<tt>u_short</tt>, <tt>u_int</tt>, <tt>u_long</tt>.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>HAVE_IEEEFP</tt>
|
|
kusano |
7d535a |
Define this as 0 or 1 according to the floating point
|
|
kusano |
7d535a |
format suported by the machine. If your machine does
|
|
kusano |
7d535a |
not support IEEE floating point then you will need to
|
|
kusano |
7d535a |
add support to tif_machdep.c to convert between the
|
|
kusano |
7d535a |
native format and IEEE format.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>HAVE_MMAP</tt>
|
|
kusano |
7d535a |
Define this if there is mmap-style support for
|
|
kusano |
7d535a |
mapping files into memory (used only to read data).
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>HOST_FILLORDER</tt>
|
|
kusano |
7d535a |
Define the native CPU bit order: one of <tt>FILLORDER_MSB2LSB</tt>
|
|
kusano |
7d535a |
or <tt>FILLORDER_LSB2MSB</tt>
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
<tt>HOST_BIGENDIAN</tt>
|
|
kusano |
7d535a |
Define the native CPU byte order: 1 if big-endian (Motorola)
|
|
kusano |
7d535a |
or 0 if little-endian (Intel); this may be used
|
|
kusano |
7d535a |
in codecs to optimize code
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
On UNIX systems <tt>HAVE_MMAP</tt> is defined through the running of
|
|
kusano |
7d535a |
the <tt>configure</tt> script; otherwise support for memory-mapped
|
|
kusano |
7d535a |
files is disabled.
|
|
kusano |
7d535a |
Note that tiffcomp.h defines <tt>HAVE_IEEEFP</tt> to be
|
|
kusano |
7d535a |
1 (<tt>BSDTYPES</tt> is not defined).
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Types and Portability
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
The software makes extensive use of C typedefs to promote portability.
|
|
kusano |
7d535a |
Two sets of typedefs are used, one for communication with clients
|
|
kusano |
7d535a |
of the library and one for internal data structures and parsing of the
|
|
kusano |
7d535a |
TIFF format. There are interactions between these two to be careful
|
|
kusano |
7d535a |
of, but for the most part you should be able to deal with portability
|
|
kusano |
7d535a |
purely by fiddling with the following machine-dependent typedefs:
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
uint8
|
|
kusano |
7d535a |
8-bit unsigned integer
|
|
kusano |
7d535a |
tiff.h
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
int8
|
|
kusano |
7d535a |
8-bit signed integer
|
|
kusano |
7d535a |
tiff.h
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
uint16
|
|
kusano |
7d535a |
16-bit unsigned integer
|
|
kusano |
7d535a |
tiff.h
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
int16
|
|
kusano |
7d535a |
16-bit signed integer
|
|
kusano |
7d535a |
tiff.h
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
uint32
|
|
kusano |
7d535a |
32-bit unsigned integer
|
|
kusano |
7d535a |
tiff.h
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
int32
|
|
kusano |
7d535a |
32-bit signed integer
|
|
kusano |
7d535a |
tiff.h
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
dblparam_t
|
|
kusano |
7d535a |
promoted type for floats
|
|
kusano |
7d535a |
tiffcomp.h
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
(to clarify <tt>dblparam_t</tt>, it is the type that float parameters are
|
|
kusano |
7d535a |
promoted to when passed by value in a function call.)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
The following typedefs are used throughout the library and interfaces
|
|
kusano |
7d535a |
to refer to certain objects whose size is dependent on the TIFF image
|
|
kusano |
7d535a |
structure:
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
typedef unsigned int ttag_t; directory tag
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
typedef uint16 tdir_t; directory index
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
typedef uint16 tsample_t; sample number
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
typedef uint32 tstrip_t; strip number
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
typedef uint32 ttile_t; tile number
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
typedef int32 tsize_t; i/o size in bytes
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
typedef void* tdata_t; image data ref
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
typedef void* thandle_t; client data handle
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
typedef int32 toff_t; file offset (should be off_t)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
typedef unsigned char* tidata_t; internal image data
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Note that <tt>tstrip_t</tt>, <tt>ttile_t</tt>, and <tt>tsize_t</tt>
|
|
kusano |
7d535a |
are constrained to be
|
|
kusano |
7d535a |
no more than 32-bit quantities by 32-bit fields they are stored
|
|
kusano |
7d535a |
in in the TIFF image. Likewise <tt>tsample_t</tt> is limited by the 16-bit
|
|
kusano |
7d535a |
field used to store the <tt>SamplesPerPixel</tt> tag. <tt>tdir_t</tt>
|
|
kusano |
7d535a |
constrains
|
|
kusano |
7d535a |
the maximum number of IFDs that may appear in an image and may
|
|
kusano |
7d535a |
be an arbitrary size (without penalty). <tt>ttag_t</tt> must be either
|
|
kusano |
7d535a |
<tt>int</tt>, <tt>unsigned int</tt>, pointer, or <tt>double</tt>
|
|
kusano |
7d535a |
because the library uses a varargs
|
|
kusano |
7d535a |
interface and ANSI C restricts the type of the parameter before an
|
|
kusano |
7d535a |
ellipsis to be a promoted type. <tt>toff_t</tt> is defined as
|
|
kusano |
7d535a |
<tt>int32</tt> because
|
|
kusano |
7d535a |
TIFF file offsets are (unsigned) 32-bit quantities. A signed
|
|
kusano |
7d535a |
value is used because some interfaces return -1 on error (sigh).
|
|
kusano |
7d535a |
Finally, note that <tt>tidata_t</tt> is used internally to the library to
|
|
kusano |
7d535a |
manipulate internal data. User-specified data references are
|
|
kusano |
7d535a |
passed as opaque handles and only cast at the lowest layers where
|
|
kusano |
7d535a |
their type is presumed.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
General Comments
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
The library is designed to hide as much of the details of TIFF from
|
|
kusano |
7d535a |
applications as
|
|
kusano |
7d535a |
possible. In particular, TIFF directories are read in their entirety
|
|
kusano |
7d535a |
into an internal format. Only the tags known by the library are
|
|
kusano |
7d535a |
available to a user and certain tag data may be maintained that a user
|
|
kusano |
7d535a |
does not care about (e.g. transfer function tables).
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Adding New Builtin Codecs
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
To add builtin support for a new compression algorithm, you can either
|
|
kusano |
7d535a |
use the "tag-extension" trick to override the handling of the
|
|
kusano |
7d535a |
TIFF Compression tag (see Adding New Tags),
|
|
kusano |
7d535a |
or do the following to add support directly to the core library:
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Define the tag value in tiff.h.
|
|
kusano |
7d535a |
Edit the file tif_codec.c to add an entry to the
|
|
kusano |
7d535a |
_TIFFBuiltinCODECS array (see how other algorithms are handled).
|
|
kusano |
7d535a |
Add the appropriate function prototype declaration to
|
|
kusano |
7d535a |
tiffiop.h (close to the bottom).
|
|
kusano |
7d535a |
Create a file with the compression scheme code, by convention files
|
|
kusano |
7d535a |
are named tif_*.c (except perhaps on some systems where the
|
|
kusano |
7d535a |
tif_ prefix pushes some filenames over 14 chars.
|
|
kusano |
7d535a |
Edit Makefile.in (and any other Makefiles)
|
|
kusano |
7d535a |
to include the new source file.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
A codec, say <tt>foo</tt>, can have many different entry points:
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
TIFFInitfoo(tif, scheme)/* initialize scheme and setup entry points in tif */
|
|
kusano |
7d535a |
fooSetupDecode(tif) /* called once per IFD after tags has been frozen */
|
|
kusano |
7d535a |
fooPreDecode(tif, sample)/* called once per strip/tile, after data is read,
|
|
kusano |
7d535a |
but before the first row is decoded */
|
|
kusano |
7d535a |
fooDecode*(tif, bp, cc, sample)/* decode cc bytes of data into the buffer */
|
|
kusano |
7d535a |
fooDecodeRow(...) /* called to decode a single scanline */
|
|
kusano |
7d535a |
fooDecodeStrip(...) /* called to decode an entire strip */
|
|
kusano |
7d535a |
fooDecodeTile(...) /* called to decode an entire tile */
|
|
kusano |
7d535a |
fooSetupEncode(tif) /* called once per IFD after tags has been frozen */
|
|
kusano |
7d535a |
fooPreEncode(tif, sample)/* called once per strip/tile, before the first row in
|
|
kusano |
7d535a |
a strip/tile is encoded */
|
|
kusano |
7d535a |
fooEncode*(tif, bp, cc, sample)/* encode cc bytes of user data (bp) */
|
|
kusano |
7d535a |
fooEncodeRow(...) /* called to decode a single scanline */
|
|
kusano |
7d535a |
fooEncodeStrip(...) /* called to decode an entire strip */
|
|
kusano |
7d535a |
fooEncodeTile(...) /* called to decode an entire tile */
|
|
kusano |
7d535a |
fooPostEncode(tif) /* called once per strip/tile, just before data is written */
|
|
kusano |
7d535a |
fooSeek(tif, row) /* seek forwards row scanlines from the beginning
|
|
kusano |
7d535a |
of a strip (row will always be >0 and <rows/strip */
|
|
kusano |
7d535a |
fooCleanup(tif) /* called when compression scheme is replaced by user */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Note that the encoding and decoding variants are only needed when
|
|
kusano |
7d535a |
a compression algorithm is dependent on the structure of the data.
|
|
kusano |
7d535a |
For example, Group 3 2D encoding and decoding maintains a reference
|
|
kusano |
7d535a |
scanline. The sample parameter identifies which sample is to be
|
|
kusano |
7d535a |
encoded or decoded if the image is organized with <tt>PlanarConfig</tt>=2
|
|
kusano |
7d535a |
(separate planes). This is important for algorithms such as JPEG.
|
|
kusano |
7d535a |
If <tt>PlanarConfig</tt>=1 (interleaved), then sample will always be 0.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Other Comments
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
The library handles most I/O buffering. There are two data buffers
|
|
kusano |
7d535a |
when decoding data: a raw data buffer that holds all the data in a
|
|
kusano |
7d535a |
strip, and a user-supplied scanline buffer that compression schemes
|
|
kusano |
7d535a |
place decoded data into. When encoding data the data in the
|
|
kusano |
7d535a |
user-supplied scanline buffer is encoded into the raw data buffer (from
|
|
kusano |
7d535a |
where it is written). Decoding routines should never have to explicitly
|
|
kusano |
7d535a |
read data -- a full strip/tile's worth of raw data is read and scanlines
|
|
kusano |
7d535a |
never cross strip boundaries. Encoding routines must be cognizant of
|
|
kusano |
7d535a |
the raw data buffer size and call <tt>TIFFFlushData1()</tt> when necessary.
|
|
kusano |
7d535a |
Note that any pending data is automatically flushed when a new strip/tile is
|
|
kusano |
7d535a |
started, so there's no need do that in the tif_postencode routine (if
|
|
kusano |
7d535a |
one exists). Bit order is automatically handled by the library when
|
|
kusano |
7d535a |
a raw strip or tile is filled. If the decoded samples are interpreted
|
|
kusano |
7d535a |
by the decoding routine before they are passed back to the user, then
|
|
kusano |
7d535a |
the decoding logic must handle byte-swapping by overriding the
|
|
kusano |
7d535a |
<tt>tif_postdecode</tt>
|
|
kusano |
7d535a |
routine (set it to <tt>TIFFNoPostDecode</tt>) and doing the required work
|
|
kusano |
7d535a |
internally. For an example of doing this look at the horizontal
|
|
kusano |
7d535a |
differencing code in the routines in tif_predict.c.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
The variables <tt>tif_rawcc</tt>, <tt>tif_rawdata</tt>, and
|
|
kusano |
7d535a |
<tt>tif_rawcp</tt> in a <tt>TIFF</tt> structure
|
|
kusano |
7d535a |
are associated with the raw data buffer. <tt>tif_rawcc</tt> must be non-zero
|
|
kusano |
7d535a |
for the library to automatically flush data. The variable
|
|
kusano |
7d535a |
<tt>tif_scanlinesize</tt> is the size a user's scanline buffer should be. The
|
|
kusano |
7d535a |
variable <tt>tif_tilesize</tt> is the size of a tile for tiled images. This
|
|
kusano |
7d535a |
should not normally be used by compression routines, except where it
|
|
kusano |
7d535a |
relates to the compression algorithm. That is, the <tt>cc</tt> parameter to the
|
|
kusano |
7d535a |
<tt>tif_decode*</tt> and <tt>tif_encode*</tt>
|
|
kusano |
7d535a |
routines should be used in terminating
|
|
kusano |
7d535a |
decompression/compression. This ensures these routines can be used,
|
|
kusano |
7d535a |
for example, to decode/encode entire strips of data.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
In general, if you have a new compression algorithm to add, work from
|
|
kusano |
7d535a |
the code for an existing routine. In particular,
|
|
kusano |
7d535a |
tif_dumpmode.c
|
|
kusano |
7d535a |
has the trivial code for the "nil" compression scheme,
|
|
kusano |
7d535a |
tif_packbits.c is a
|
|
kusano |
7d535a |
simple byte-oriented scheme that has to watch out for buffer
|
|
kusano |
7d535a |
boundaries, and tif_lzw.c has the LZW scheme that has the most
|
|
kusano |
7d535a |
complexity -- it tracks the buffer boundary at a bit level.
|
|
kusano |
7d535a |
Of course, using a private compression scheme (or private tags) limits
|
|
kusano |
7d535a |
the portability of your TIFF files.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Last updated: $Date: 2004/09/10 14:47:31 $
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|