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