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