xref: /libtiff-4.0.7/html/internals.html (revision 0ef31e1f)
1<HTML>
2<HEAD>
3<TITLE>
4Modifying The TIFF Library
5</TITLE>
6</HEAD>
7
8<H1>
9<IMG SRC=images/dave.gif WIDTH=107 HEIGHT=148 BORDER=2 ALIGN=left HSPACE=6>
10Modifying The TIFF Library
11</H1>
12
13
14<P>
15This chapter provides information about the internal structure of
16the library, how to control the configuration when building it, and
17how to add new support to the library.
18The following sections are found in this chapter:
19
20<UL>
21<LI><A HREF=#Config>Library Configuration</A>
22<LI><A HREF=#Portability>General Portability Comments</A>
23<LI><A HREF="#Types">Types and Portability</A>
24<LI><A HREF=#AddingTags>Adding New Tags</A>
25<LI><A HREF=#AddingCODECS>Adding New Builtin Codecs</A>
26<LI><A HREF=#AddingCODECTags>Adding New Codec-private Tags</A>
27<LI><A HREF=#Other>Other Comments</A>
28</UL>
29
30
31<A NAME="Config"><P><HR WIDTH=65% ALIGN=right><H3>Library Configuration</H3></A>
32
33Information on compiling the library is given
34<A HREF=build.html>elsewhere in this documentation</A>.
35This section describes the low-level mechanisms used to control
36the optional parts of the library that are configured at build
37time.   Control is based on
38a collection of C defines that are specified either on the compiler
39command line or in a configuration file such as <TT>port.h</TT>
40(as generated by the <TT>configure</TT> script for UNIX systems)
41or <B>tiffconf.h</B>.
42
43<P>
44Configuration defines are split into three areas:
45<UL>
46<LI>those that control which compression schemes are
47    configured as part of the builtin codecs,
48<LI>those that control support for groups of tags that
49    are considered optional, and
50<LI>those that control operating system or machine-specific support.
51</UL>
52
53<P>
54If the define <TT>COMPRESSION_SUPPORT</TT> is <STRONG>not defined</STRONG>
55then a default set of compression schemes is automatically
56configured:
57<UL>
58<LI>CCITT Group 3 and 4 algorithms (compression codes 2, 3, 4, and 32771),
59<LI>the Macintosh PackBits algorithm (compression 32773),
60<LI>a Lempel-Ziv & Welch (LZW) algorithm (compression 5),
61<LI>a 4-bit run-length encoding scheme from ThunderScan (compression 32809),
62<LI>a 2-bit encoding scheme used by NeXT (compression 32766), and
63<LI>two experimental schemes intended for images with high dynamic range
64(compression 34676 and 34677).
65</UL>
66
67To override this behaviour define <TT>COMPRESSION_SUPPORT</TT>
68and then one or more additional defines to enable configuration of
69the appropriate codecs (see the table below); e.g.
70
71<UL><PRE>
72#define	COMPRESSION_SUPPORT
73#define	CCITT_SUPPORT
74#define	PACKBITS_SUPPORT
75</PRE></UL>
76
77Several other compression schemes are configured separately from
78the default set because they depend on ancillary software
79packages that are not distributed with <TT>libtiff</TT>.
80
81<P>
82Support for JPEG compression is controlled by <TT>JPEG_SUPPORT</TT>.
83The JPEG codec that comes with <TT>libtiff</TT> is designed for
84use with release 5 or later of the Independent JPEG Group's freely
85available software distribution.
86This software can be retrieved from the directory
87<A HREF=ftp://ftp.uu.net/graphics/jpeg>ftp.uu.net:/graphics/jpeg/</A>.
88
89
90<P>
91<IMG SRC="images/info.gif" ALT="NOTE: " ALIGN=left HSPACE=8>
92<EM>Enabling JPEG support automatically enables support for
93the TIFF 6.0 colorimetry and YCbCr-related tags.</EM>
94
95<P>
96Experimental support for the deflate algorithm is controlled by
97<TT>DEFLATE_SUPPORT</TT>.
98The deflate codec that comes with <TT>libtiff</TT> is designed
99for use with version 0.99 or later of the freely available
100<TT>libz</TT> library written by Jean-loup Gailly and Mark Adler.
101The data format used by this library is described
102in the files
103<A HREF=ftp://ftp.uu.net/pub/archiving/zip/doc/zlib-3.1.doc>zlib-3.1.doc</A>,
104and
105<A HREF=ftp://ftp.uu.net/pub/archiving/zip/doc/deflate-1.1.doc>deflate-1.1.doc</A>,
106available in the directory
107<A HREF=ftp://ftp.uu.net/pub/archiving/zip/doc>ftp.uu.net:/pub/archiving/zip/doc</A>.</EM>
108The library can be retried from the directory
109<A HREF=ftp://ftp.uu.net/pub/archiving/zip/zlib/>ftp.uu.net:/pub/archiving/zip/zlib/</A>
110(or try <A HREF=ftp://quest.jpl.nasa.gov/beta/zlib/>quest.jpl.nasa.gov:/beta/zlib/</A>).
111
112<P>
113<IMG SRC="images/warning.gif" ALT="NOTE: " ALIGN=left HSPACE=8 VSPACE=6>
114<EM>The deflate algorithm is experimental.  Do not expect
115to exchange files using this compression scheme;
116it is included only because the similar, and more common,
117LZW algorithm is claimed to be governed by licensing restrictions.</EM>
118
119
120<P>
121By default <B>tiffconf.h</B> defines
122<TT>COLORIMETRY_SUPPORT</TT>,
123<TT>YCBCR_SUPPORT</TT>,
124and
125<TT>CMYK_SUPPORT</TT>.
126
127<P>
128<TABLE BORDER CELLPADDING=3>
129
130<TR><TH ALIGN=left>Define</TH><TH ALIGN=left>Description</TH></TR>
131
132<TR>
133<TD VALIGN=top><TT>CCITT_SUPPORT</TT></TD>
134<TD>CCITT Group 3 and 4 algorithms (compression codes 2, 3, 4,
135    and 32771)</TD>
136</TR>
137
138<TR>
139<TD VALIGN=top><TT>PACKBITS_SUPPORT</TT></TD>
140<TD>Macintosh PackBits algorithm (compression 32773)</TD>
141</TR>
142
143<TR>
144<TD VALIGN=top><TT>LZW_SUPPORT</TT></TD>
145<TD>Lempel-Ziv & Welch (LZW) algorithm (compression 5)</TD>
146</TR>
147
148<TR>
149<TD VALIGN=top><TT>THUNDER_SUPPORT</TT></TD>
150<TD>4-bit
151run-length encoding scheme from ThunderScan (compression 32809)</TD>
152</TR>
153
154<TR>
155<TD VALIGN=top><TT>NEXT_SUPPORT</TT></TD>
156<TD>2-bit encoding scheme used by NeXT (compression 32766)</TD>
157</TR>
158
159<TR>
160<TD VALIGN=top><TT>OJPEG_SUPPORT</TT></TD>
161<TD>obsolete JPEG scheme defined in the 6.0 spec (compression 6)</TD>
162</TR>
163
164<TR>
165<TD VALIGN=top><TT>JPEG_SUPPORT</TT></TD>
166<TD>current JPEG scheme defined in TTN2 (compression 7)</TD>
167</TR>
168
169<TR>
170<TD VALIGN=top><TT>ZIP_SUPPORT</TT></TD>
171<TD>experimental Deflate scheme (compression 32946)</TD>
172</TR>
173
174<TR>
175<TD VALIGN=top><TT>PIXARLOG_SUPPORT</TT></TD>
176<TD>Pixar's compression scheme for high-resolution color images (compression 32909)</TD>
177</TR>
178
179<TR>
180<TD VALIGN=top><TT>SGILOG_SUPPORT</TT></TD>
181<TD>SGI's compression scheme for high-resolution color images (compression 34676 and 34677)</TD>
182</TR>
183
184<TR>
185<TD VALIGN=top><TT>COLORIMETRY_SUPPORT</TT></TD>
186<TD>support for the TIFF 6.0 colorimetry tags</TD>
187</TR>
188
189<TR>
190<TD VALIGN=top><TT>YCBCR_SUPPORT</TT></TD>
191<TD>support for the TIFF 6.0 YCbCr-related tags</TD>
192</TR>
193
194<TR>
195<TD VALIGN=top><TT>CMYK_SUPPORT</TT></TD>
196<TD>support for the TIFF 6.0 CMYK-related tags</TD>
197</TR>
198
199<TR>
200<TD VALIGN=top><TT>ICC_SUPPORT</TT></TD>
201<TD>support for the ICC Profile tag; see
202<I>The ICC Profile Format Specification</I>,
203Annex B.3 "Embedding ICC Profiles in TIFF Files";
204available at
205<A HREF=http://www.color.org>http://www.color.org</A>
206</TD>
207</TR>
208
209</TABLE>
210
211
212<A NAME="Portability"><P><HR WIDTH=65% ALIGN=right><H3>General Portability Comments</H3></A>
213
214This software is developed on Silicon Graphics UNIX
215systems (big-endian, MIPS CPU, 32-bit ints,
216IEEE floating point).
217The <TT>configure</TT> shell script generates the appropriate
218include files and make files for UNIX systems.
219Makefiles exist for non-UNIX platforms that the
220code runs on -- this work has mostly been done by other people.
221
222<P>
223In general, the code is guaranteed to work only on SGI machines.
224In practice it is highly portable to any 32-bit or 64-bit system and much
225work has been done to insure portability to 16-bit systems.
226If you encounter portability problems please return fixes so
227that future distributions can be improved.
228
229<P>
230The software is written to assume an ANSI C compilation environment.
231If your compiler does not support ANSI function prototypes, <TT>const</TT>,
232and <TT>&lt;stdarg.h&gt;</TT> then you will have to make modifications to the
233software.  In the past I have tried to support compilers without <TT>const</TT>
234and systems without <TT>&lt;stdarg.h&gt;</TT>, but I am
235<EM>no longer interested in these
236antiquated environments</EM>.  With the general availability of
237the freely available GCC compiler, I
238see no reason to incorporate modifications to the software for these
239purposes.
240
241<P>
242An effort has been made to isolate as many of the
243operating system-dependencies
244as possible in two files: <B>tiffcomp.h</B> and
245<B>libtiff/tif_&lt;os&gt;.c</B>.  The latter file contains
246operating system-specific routines to do I/O and I/O-related operations.
247The UNIX (<B>tif_unix.c</B>),
248Macintosh (<B>tif_apple.c</B>),
249and VMS (<B>tif_vms.c</B>)
250code has had the most use;
251the MS/DOS support (<B>tif_msdos.c</B>) assumes
252some level of UNIX system call emulation (i.e.
253<TT>open</TT>,
254<TT>read</TT>,
255<TT>write</TT>,
256<TT>fstat</TT>,
257<TT>malloc</TT>,
258<TT>free</TT>).
259
260<P>
261Native CPU byte order is determined on the fly by
262the library and does not need to be specified.
263The <TT>HOST_FILLORDER</TT> and <TT>HOST_BIGENDIAN</TT>
264definitions are not currently used, but may be employed by
265codecs for optimization purposes.
266
267<P>
268The following defines control general portability:
269
270<P>
271<TABLE BORDER CELLPADDING=3 WIDTH=100%>
272
273<TR>
274<TD VALIGN=top><TT>BSDTYPES</TT></TD>
275<TD>Define this if your system does NOT define the
276		usual BSD typedefs: <TT>u_char</TT>,
277		<TT>u_short</TT>, <TT>u_int</TT>, <TT>u_long</TT>.</TD>
278</TR>
279
280<TR>
281<TD VALIGN=top><TT>HAVE_IEEEFP</TT></TD>
282<TD>Define this as 0 or 1 according to the floating point
283		format suported by the machine.  If your machine does
284		not support IEEE floating point then you will need to
285		add support to tif_machdep.c to convert between the
286		native format and IEEE format.</TD>
287</TR>
288
289<TR>
290<TD VALIGN=top><TT>HAVE_MMAP</TT></TD>
291<TD>Define this if there is <I>mmap-style</I> support for
292mapping files into memory (used only to read data).</TD>
293</TR>
294
295<TR>
296<TD VALIGN=top><TT>HOST_FILLORDER</TT></TD>
297<TD>Define the native CPU bit order: one of <TT>FILLORDER_MSB2LSB</TT>
298 or <TT>FILLORDER_LSB2MSB</TT></TD>
299</TR>
300
301<TR>
302<TD VALIGN=top><TT>HOST_BIGENDIAN</TT></TD>
303<TD>Define the native CPU byte order: 1 if big-endian (Motorola)
304 or 0 if little-endian (Intel); this may be used
305 in codecs to optimize code</TD>
306</TR>
307</TABLE>
308
309<P>
310On UNIX systems <TT>HAVE_MMAP</TT> is defined through the running of
311the <TT>configure</TT> script; otherwise support for memory-mapped
312files is disabled.
313Note that <B>tiffcomp.h</B> defines <TT>HAVE_IEEEFP</TT> to be
3141 (<TT>BSDTYPES</TT> is not defined).
315
316
317<A NAME="Types"><P><HR WIDTH=65% ALIGN=right><H3>Types and Portability</H3></A>
318
319The software makes extensive use of C typedefs to promote portability.
320Two sets of typedefs are used, one for communication with clients
321of the library and one for internal data structures and parsing of the
322TIFF format.  There are interactions between these two to be careful
323of, but for the most part you should be able to deal with portability
324purely by fiddling with the following machine-dependent typedefs:
325
326
327<P>
328<TABLE BORDER CELLPADDING=3 WIDTH=100%>
329
330<TR>
331<TD>uint8</TD>
332<TD>8-bit unsigned integer</TD>
333<TD>tiff.h</TD>
334</TR>
335
336<TR>
337<TD>int8</TD>
338<TD>8-bit signed integer</TD>
339<TD>tiff.h</TD>
340</TR>
341
342<TR>
343<TD>uint16</TD>
344<TD>16-bit unsigned integer</TD>
345<TD>tiff.h</TD>
346</TR>
347
348<TR>
349<TD>int16</TD>
350<TD>16-bit signed integer</TD>
351<TD>tiff.h</TD>
352</TR>
353
354<TR>
355<TD>uint32</TD>
356<TD>32-bit unsigned integer</TD>
357<TD>tiff.h</TD>
358</TR>
359
360<TR>
361<TD>int32</TD>
362<TD>32-bit signed integer</TD>
363<TD>tiff.h</TD>
364</TR>
365
366<TR>
367<TD>dblparam_t</TD>
368<TD>promoted type for floats</TD>
369<TD>tiffcomp.h</TD>
370</TR>
371
372</TABLE>
373
374<P>
375(to clarify <TT>dblparam_t</TT>, it is the type that float parameters are
376promoted to when passed by value in a function call.)
377
378<P>
379The following typedefs are used throughout the library and interfaces
380to refer to certain objects whose size is dependent on the TIFF image
381structure:
382
383
384<P>
385<TABLE BORDER CELLPADDING=3 WIDTH=100%>
386
387<TR>
388<TD WIDTH=25%>typedef unsigned int ttag_t;</TD>	<TD>directory tag</TD>
389</TR>
390
391<TR>
392<TD>typedef uint16 tdir_t;</TD>		<TD>directory index</TD>
393</TR>
394
395<TR>
396<TD>typedef uint16 tsample_t;</TD>	<TD>sample number</TD>
397</TR>
398
399<TR>
400<TD>typedef uint32 tstrip_t;</TD>	<TD>strip number</TD>
401</TR>
402
403<TR>
404<TD>typedef uint32 ttile_t;</TD>		<TD>tile number</TD>
405</TR>
406
407<TR>
408<TD>typedef int32 tsize_t;</TD>		<TD>i/o size in bytes</TD>
409</TR>
410
411<TR>
412<TD>typedef void* tdata_t;</TD>		<TD>image data ref</TD>
413</TR>
414
415<TR>
416<TD>typedef void* thandle_t;</TD>	<TD>client data handle</TD>
417</TR>
418
419<TR>
420<TD>typedef int32 toff_t;</TD>		<TD>file offset (should be off_t)</TD>
421</TR>
422
423<TR>
424<TD>typedef unsigned char* tidata_t;</TD> <TD>internal image data</TD>
425</TR>
426
427</TABLE>
428
429<P>
430Note that <TT>tstrip_t</TT>, <TT>ttile_t</TT>, and <TT>tsize_t</TT>
431are constrained to be
432no more than 32-bit quantities by 32-bit fields they are stored
433in in the TIFF image.  Likewise <TT>tsample_t</TT> is limited by the 16-bit
434field used to store the <TT>SamplesPerPixel</TT> tag.  <TT>tdir_t</TT>
435constrains
436the maximum number of IFDs that may appear in an image and may
437be an arbitrary size (without penalty).  <TT>ttag_t</TT> must be either
438<TT>int</TT>, <TT>unsigned int</TT>, pointer, or <TT>double</TT>
439because the library uses a varargs
440interface and ANSI C restricts the type of the parameter before an
441ellipsis to be a promoted type.  <TT>toff_t</TT> is defined as
442<TT>int32</TT> because
443TIFF file offsets are (unsigned) 32-bit quantities.  A signed
444value is used because some interfaces return -1 on error (sigh).
445Finally, note that <TT>tidata_t</TT> is used internally to the library to
446manipulate internal data.  User-specified data references are
447passed as opaque handles and only cast at the lowest layers where
448their type is presumed.
449
450
451<P><HR WIDTH=65% ALIGN=right><H3>General Comments</H3></A>
452
453The library is designed to hide as much of the details of TIFF from
454applications as
455possible.  In particular, TIFF directories are read in their entirety
456into an internal format.  Only the tags known by the library are
457available to a user and certain tag data may be maintained that a user
458does not care about (e.g. transfer function tables).
459
460<A NAME=AddingTags><P><HR WIDTH=65% ALIGN=right><H3>Adding New Tags</H3></A>
461
462To add support for a new directory tag you have three options.  If your
463tag is specific to a compression algorithm, see below. If you have a lot
464of tags you may want to try using Niles Ritter's runtime tag-extension
465scheme in the "contrib/tags" directory, which makes the changes
466orthogonal to the main libtiff code. Otherwise use
467the following guidelines to add support to the ``core library''.
468
469<OL>
470<LI>Define the tag in <B>tiff.h</B>.
471<LI>Add a field to the directory structure in <B>tif_dir.h</B>
472   and define a <TT>FIELD_*</TT> bit (also update the definition of
473   <TT>FIELD_CODEC</TT> to reflect your addition).
474<LI>Add an entry in the <TT>TIFFFieldInfo</TT> array defined at the top of
475   <B>tif_dirinfo.c</B>.
476   Note that you must keep this array sorted by tag
477   number and that the widest variant entry for a tag should come
478   first (e.g. <TT>LONG</TT> before <TT>SHORT</TT>).
479<LI>Add entries in <TT>_TIFFVSetField()</TT> and <TT>_TIFFVGetField()</TT>
480   for the new tag.
481<LI>(<I>optional</I>) If the value associated with the tag is not a scalar value
482   (e.g. the array for <TT>TransferFunction</TT>) and requires
483   special processing,
484   then add the appropriate code to <TT>TIFFReadDirectory()</TT> and
485   <TT>TIFFWriteDirectory()</TT>.  You're best off finding a similar tag and
486   cribbing code.
487<LI>Add support to <TT>TIFFPrintDirectory()</TT> in <B>tif_print.c</B>
488    to print the tag's value.
489</OL>
490
491<P>
492If you want to maintain portability, beware of making assumptions
493about data types.  Use the typedefs (<TT>uint16</TT>, etc. when dealing with
494data on disk and <TT>t*_t</TT> when stuff is in memory) and be careful about
495passing items through printf or similar vararg interfaces.
496
497<A NAME=AddingCODECS><P><HR WIDTH=65% ALIGN=right><H3>Adding New Builtin Codecs</H3></A>
498
499To add builtin support for a new compression algorithm, you can either
500use the "tag-extension" trick to override the handling of the
501TIFF Compression tag (see <A HREF=#AddingTags>Adding New Tags</A>, above),
502or do the following to add support directly to the core library:
503
504<OL>
505<LI>Define the tag value in <B>tiff.h</B>.
506<LI>Edit the file <B>tif_codec.c</B> to add an entry to the
507   _TIFFBuiltinCODECS array (see how other algorithms are handled).
508<LI>Add the appropriate function prototype declaration to
509   <B>tiffiop.h</B> (close to the bottom).
510<LI>Create a file with the compression scheme code, by convention files
511   are named <B>tif_*.c</B> (except perhaps on some systems where the
512   tif_ prefix pushes some filenames over 14 chars.
513<LI>Edit <B>Makefile.in</B> (and any other Makefiles)
514   to include the new source file.
515</OL>
516
517<P>
518A codec, say <TT>foo</TT>, can have many different entry points:
519
520<PRE>
521TIFFInitfoo(tif, scheme)/* initialize scheme and setup entry points in tif */
522fooSetupDecode(tif)	/* called once per IFD after tags has been frozen */
523fooPreDecode(tif, sample)/* called once per strip/tile, after data is read,
524			    but before the first row is decoded */
525fooDecode*(tif, bp, cc, sample)/* decode cc bytes of data into the buffer */
526    fooDecodeRow(...)	/* called to decode a single scanline */
527    fooDecodeStrip(...)	/* called to decode an entire strip */
528    fooDecodeTile(...)	/* called to decode an entire tile */
529fooSetupEncode(tif)	/* called once per IFD after tags has been frozen */
530fooPreEncode(tif, sample)/* called once per strip/tile, before the first row in
531			    a strip/tile is encoded */
532fooEncode*(tif, bp, cc, sample)/* encode cc bytes of user data (bp) */
533    fooEncodeRow(...)	/* called to decode a single scanline */
534    fooEncodeStrip(...)	/* called to decode an entire strip */
535    fooEncodeTile(...)	/* called to decode an entire tile */
536fooPostEncode(tif)	/* called once per strip/tile, just before data is written */
537fooSeek(tif, row)	/* seek forwards row scanlines from the beginning
538			   of a strip (row will always be &gt;0 and &lt;rows/strip */
539fooCleanup(tif)		/* called when compression scheme is replaced by user */
540</PRE>
541
542<P>
543Note that the encoding and decoding variants are only needed when
544a compression algorithm is dependent on the structure of the data.
545For example, Group 3 2D encoding and decoding maintains a reference
546scanline.  The sample parameter identifies which sample is to be
547encoded or decoded if the image is organized with <TT>PlanarConfig</TT>=2
548(separate planes).  This is important for algorithms such as JPEG.
549If <TT>PlanarConfig</TT>=1 (interleaved), then sample will always be 0.
550
551
552<A NAME=AddingCODECTags><P><HR WIDTH=65% ALIGN=right><H3>Adding New Codec-private Tags</H3></A>
553
554To add tags that are meaningful <EM>only when a particular compression
555algorithm is used</EM> follow these steps:
556
557<OL>
558<LI>Define the tag in <B>tiff.h</B>.
559<LI>Allocate storage for the tag values in the private state block of
560   the codec.
561<LI>Insure the state block is created when the codec is initialized.
562<LI>At <TT>TIFFInitfoo</TT> time override the method pointers in the
563    TIFF structure
564   for getting, setting and printing tag values.  For example,
565<PRE>
566    sp->vgetparent = tif->tif_vgetfield;
567    tif->tif_vgetfield = fooVGetField;	/* hook for codec tags */
568    sp->vsetparent = tif->tif_vsetfield;
569    tif->tif_vsetfield = fooVSetField;	/* hook for codec tags */
570    tif->tif_printdir = fooPrintDir;	/* hook for codec tags */
571</PRE>
572   (Actually you may decide not to override the
573   <TT>tif_printdir</TT> method, but rather just specify it).
574<LI>Create a private <TT>TIFFFieldInfo</TT> array for your tags and
575    merge them into the core tags at initialization time using
576    <TT>_TIFFMergeFieldInfo</TT>; e.g.
577<PRE>
578    _TIFFMergeFieldInfo(tif, fooFieldInfo, N(fooFieldInfo));
579</PRE>
580   (where <TT>N</TT> is a macro used liberaly throughout the distributed code).
581<LI>Fill in the get and set routines.  Be sure to call the parent method
582   for tags that you are not handled directly.  Also be sure to set the
583   <TT>FIELD_*</TT> bits for tags that are to be written to the file.  Note that
584   you can create ``pseudo-tags'' by defining tags that are processed
585   exclusively in the get/set routines and never written to file (see
586   the handling of <TT>TIFFTAG_FAXMODE</TT> in <B>tif_fax3.c</B>
587   for an example of this).
588<LI>Fill in the print routine, if appropriate.
589</OL>
590
591Note that space has been allocated in the <TT>FIELD_*</TT> bit space for
592codec-private tags.  Define your bits as <TT>FIELD_CODEC+&lt;offset&gt;</TT> to
593keep them away from the core tags.  If you need more tags than there
594is room for, just increase <TT>FIELD_SETLONGS</TT> at the top of
595<B>tiffiop.h</B>.
596
597
598<A NAME=Other><P><HR WIDTH=65% ALIGN=right><H3>Other Comments</H3></A>
599
600The library handles most I/O buffering.  There are two data buffers
601when decoding data: a raw data buffer that holds all the data in a
602strip, and a user-supplied scanline buffer that compression schemes
603place decoded data into.  When encoding data the data in the
604user-supplied scanline buffer is encoded into the raw data buffer (from
605where it is written).  Decoding routines should never have to explicitly
606read data -- a full strip/tile's worth of raw data is read and scanlines
607never cross strip boundaries.  Encoding routines must be cognizant of
608the raw data buffer size and call <TT>TIFFFlushData1()</TT> when necessary.
609Note that any pending data is automatically flushed when a new strip/tile is
610started, so there's no need do that in the tif_postencode routine (if
611one exists).  Bit order is automatically handled by the library when
612a raw strip or tile is filled.  If the decoded samples are interpreted
613by the decoding routine before they are passed back to the user, then
614the decoding logic must handle byte-swapping by overriding the
615<TT>tif_postdecode</TT>
616routine (set it to <TT>TIFFNoPostDecode</TT>) and doing the required work
617internally.  For an example of doing this look at the horizontal
618differencing code in the routines in <B>tif_predict.c</TT>.
619
620<P>
621The variables <TT>tif_rawcc</TT>, <TT>tif_rawdata</TT>, and
622<TT>tif_rawcp</TT> in a <TT>TIFF</TT> structure
623are associated with the raw data buffer.  <TT>tif_rawcc</TT> must be non-zero
624for the library to automatically flush data.  The variable
625<TT>tif_scanlinesize</TT> is the size a user's scanline buffer should be.  The
626variable <TT>tif_tilesize</TT> is the size of a tile for tiled images.  This
627should not normally be used by compression routines, except where it
628relates to the compression algorithm.  That is, the <TT>cc</TT> parameter to the
629<TT>tif_decode*</TT> and <TT>tif_encode*</TT>
630routines should be used in terminating
631decompression/compression.  This ensures these routines can be used,
632for example, to decode/encode entire strips of data.
633
634<P>
635In general, if you have a new compression algorithm to add, work from
636the code for an existing routine.  In particular,
637<B>tif_dumpmode.c</B>
638has the trivial code for the "nil" compression scheme,
639<B>tif_packbits.c</B> is a
640simple byte-oriented scheme that has to watch out for buffer
641boundaries, and <B>tif_lzw.c</B> has the LZW scheme that has the most
642complexity -- it tracks the buffer boundary at a bit level.
643Of course, using a private compression scheme (or private tags) limits
644the portability of your TIFF files.
645
646<P>
647<HR>
648
649<ADDRESS>
650<A HREF="sam.html">Sam Leffler</A> / <A HREF="mailto:[email protected]">[email protected]</A>.
651Last updated: $Date: 1999-07-27 21:50:27 $
652</ADDRESS>
653
654</BODY>
655</HTML>
656