home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / utilities / utilst / tifftext / TIFF
Text File  |  1994-02-13  |  131KB  |  1,965 lines

  1.  
  2. TIFF 5.0       An Aldus/Microsoft Technical Memorandum:  8/8/88        Page 1
  3.  
  4. Preface
  5.  
  6.  
  7. This memorandum has been prepared jointly by Aldus and Microsoft in conjunction with leading scanner vendors and other interested parties.  This document does not represent a commitment on the part of either Microsoft or Aldus to provide support for this file format in any application.  When responding to specific issues raised in this memo, or when requesting additional tag or field assignments, please address your correspondence to either:
  8.  
  9.         Developers' Desk        Windows Marketing Group
  10.         Aldus Corporation       Microsoft Corporation
  11.         411 First Ave. South    16011 NE 36th Way
  12.         Suite 200               Box 97017
  13.         Seattle, WA  98104      Redmond, WA  98073-9717
  14.         (206) 622-5500          (206) 882-8080
  15.  
  16.  
  17.  
  18. Revision Notes
  19.  
  20. This revision replaces 'TIFF Revision 4.'  Sections in italics are new or substantially changed in this revision.  Also new, but not in italics, are Appendices F, G, and H.
  21.  
  22. The major enhancements in TIFF 5.0 are:
  23.  
  24. 1.      Compression of grayscale and color images, for better disk space utilization.  See Appendix F.
  25.  
  26. 2.      TIFF Classes'restricted TIFF subsets that can simplify the job of the TIFF implementor.  You may wish to scan Appendix G before reading the rest of this document.   In fact, you may want to use Appendix G as your main guide, and refer back to the main body of the specification as needed for details concerning TIFF structures and field definitions.
  27.  
  28. 3.      Support for 'palette color'  images.  See the TIFF Class P description in Appendix G, and the new ColorMap field description.
  29.  
  30. 4.      Two new tags that can be used to more fully define the characteristics of full color RGB data, and thereby potentially improve the quality of color image reproduction.  See Appendix H.
  31.  
  32. The organization of the document has also changed slightly.  In particular, the tags are listed in alphabetical order, within several categories, in the main body of the specification.  
  33.  
  34. As always, every attempt has been made to add functionality in such a way as to minimize incompatibility problems with older TIFF software.  In particular, many TIFF 5.0 files will be readable even by older applications that assume TIFF 4.0 or an earlier version of the specification.  One exception is with files that use the new TIFF 5.0 LZW compression scheme.  Old applications will have to give up in this case, of course, and will do so 'gracefully' if they have been following the rules.  
  35.  
  36. We are grateful to all of the draft reviewers for their suggestions.  Especially helpful were Herb Weiner of Kitchen Wisdom Publishing Company, Brad Pillow of TrueVision, and engineers from Hewlett Packard and Quark.  Chris Sears of Magenta Graphics provided information which is included as Appendix H.
  37.  
  38.  
  39. Abstract
  40.  
  41. This document describes TIFF, a tag based file format that is designed to promote the interchange of digital image data.
  42.  
  43. The fields were defined primarily with desktop publishing and related applications in mind, although it is possible that other sorts of imaging applications may find TIFF to be useful.
  44.  
  45. The general scenario for which TIFF was invented assumes that applications software for scanning or painting creates a TIFF file, which can then be read and incorporated into a 'document'  or 'publication'  by an application such as a desktop publishing package.
  46.  
  47. TIFF is not a printer language or page description language, nor is it intended to be a general document interchange standard. The primary design goal was to provide a rich environment within which the exchange of image data between application programs can be accomplished.  This richness is required in order to take advantage of the varying capabilities of scanners and similar devices.  TIFF is therefore designed to be a superset of existing image file formats for 'desktop'  scanners (and paint programs and anything else that produces images with pixels in them) and will be enhanced on a continuing basis as new capabilities arise.  A high priority has been given to structuring the data in such a way as to minimize the pain of future additions.  TIFF was designed to be an extensible interchange format.
  48.  
  49. Although TIFF is claimed to be in some sense a rich format, it can easily be used for simple scanners and applications as well, since the application developer need only be concerned with the capabilities that he requires.
  50.  
  51. TIFF is intended to be independent of specific operating systems, filing systems, compilers, and processors.  The only significant assumption is that the storage medium supports something like a 'file,'  defined as a sequence of 8-bit bytes, where the bytes are numbered from 0 to N.  The largest possible TIFF file is 2**32 bytes in length.  Since TIFF uses pointers (byte offsets) quite liberally, a TIFF file is most easily read from a random access device such as a hard disk or flexible diskette, although it should be possible to read and write TIFF files on magnetic tape.
  52.  
  53. The recommended MS-DOS, UNIX, and OS/2 file extension for TIFF files is '.TIF.'   The recommended Macintosh filetype is 'TIFF'.  Suggestions for conventions in other computing environments are welcome.
  54.  
  55.  
  56. 1) Structure
  57.  
  58. In TIFF, individual fields are identified with a unique tag. This allows particular fields to be present or absent from the file as required by the application.  For an explanation of the rationale behind using a tag structure format, see Appendix A.
  59.  
  60. A TIFF file begins with an 8-byte 'image file header' that points to one or more 'image file directories.'  The image file directories contain information about the images, as well as pointers to the actual image data.
  61.  
  62. See Figure 1.
  63.  
  64. We will now describe these structures in more detail.
  65.  
  66. Image file header
  67.  
  68. A TIFF file begins with an 8-byte image file header, containing the following information:
  69.  
  70. Bytes 0-1:      The first word of the file specifies the byte order used within the file.  Legal values are:
  71.  
  72.                 'II'    (hex 4949)
  73.                 'MM'    (hex 4D4D)
  74.  
  75.         In the 'II'  format, byte order is always from least significant to most significant, for both 16-bit and 32-bit integers.  In the 'MM'  format, byte order is always from most significant to least significant, for both 16-bit and 32-bit integers.  In both formats, character strings are stored into sequential byte locations.
  76.  
  77.         All TIFF readers should support both byte orders'see Appendix G.
  78.  
  79. Bytes 2-3       The second word of the file is the TIFF 'version number.'  This number, 42 (2A in hex), is not to be equated with the current Revision of the TIFF specification.  In fact, the TIFF version number (42) has never changed, and probably never will.  If it ever does, it means that TIFF has changed in some way so radical that a TIFF reader should give up immediately.  The number 42 was chosen for its deep philosophical significance.  It can and should be used as additional verification that this is indeed a TIFF file.
  80.  
  81.         A TIFF file does not have a real version/revision number.  This was an explicit, conscious design decision.  In many file formats, fields take on different meanings depending on a single version number.  The problem is that as the file format 'ages,' it becomes increasingly difficult to document which fields mean what in a given version, and older software usually has to give up if it encounters a file with a newer version number.  We wanted TIFF fields to have a permanent and well-defined meaning, so that 'older' software can usually read 'newer' TIFF files.  The bottom line is lower software release costs and more reliable software.
  82.  
  83. Bytes 4-7       This long word contains the offset (in bytes) of the first Image File Directory.  The directory may be at any location in the file after the header but must begin on a word boundary.  In particular, an Image File Directory may follow the image data it describes.  Readers must simply follow the pointers, wherever they may lead.
  84.  
  85.         (The term 'byte offset' is always used in this document to refer to a location with respect to the beginning of the file.  The first byte of the file has an offset of 0.)
  86.  
  87.  
  88. Image file directory
  89.  
  90. An Image File Directory (IFD) consists of a 2-byte count of the number of entries (i.e., the number of fields), followed by a sequence of 12-byte field entries, followed by a 4-byte offset of the next Image File Directory (or 0 if none).  Do not forget to write the 4 bytes of 0 after the last IFD.
  91.  
  92. Each 12-byte IFD entry has the following format:
  93.  
  94. Bytes 0-1       contain the Tag for the field.
  95. Bytes 2-3       contain the field Type.
  96. Bytes 4-7       contain the Length ('Count' might have been a better term) of the field.
  97. Bytes 8-11      contain the Value Offset, the file offset (in bytes) of the Value for the field.  The Value is expected to begin on a word boundary; the corresponding Value Offset will thus be an even number.  This file offset may point to anywhere in the file, including after the image data.
  98.  
  99. The entries in an IFD must be sorted in ascending order by Tag.  Note that this is not the order in which the fields are described in this document.  For a numerically ordered list of tags, see Appendix E.  The Values to which directory entries point need not be in any particular order in the file.
  100.  
  101. In order to save time and space, the Value Offset is interpreted to contain the Value instead of pointing to the Value if the Value fits into 4 bytes.  If the Value is less than 4 bytes, it is left-justified within the 4-byte Value Offset, i.e., stored in the lower-numbered bytes.  Whether or not the Value fits within 4 bytes is determined by looking at the Type and Length of the field.
  102.  
  103. The Length is specified in terms of the data type, not the total number of bytes.  A single 16-bit word (SHORT) has a Length of 1, not 2, for example.  The data types and their lengths are described below:
  104.  
  105. 1 = BYTE        An 8-bit unsigned integer.
  106. 2 = ASCII       8-bit bytes that store ASCII codes; the last byte must be null.
  107. 3 = SHORT       A 16-bit (2-byte) unsigned integer.
  108. 4 = LONG        A 32-bit (4-byte) unsigned integer.
  109. 5 = RATIONAL    Two LONG's:  the first represents the numerator of a fraction, the second the denominator.
  110.  
  111. The value of the Length part of an ASCII field entry includes the null.  If padding is necessary, the Length does not include the pad byte.  Note that there is no 'count byte,' as there is in Pascal-type strings.  The Length part of the field takes care of that.  The null is not strictly necessary, but may make things slightly simpler for C programmers.
  112.  
  113. The reader should check the type to ensure that it is what he expects.  TIFF currently allows more than 1 valid type for some fields.  For example, ImageWidth and ImageLength were specified as having type SHORT.  Very large images with more than 64K rows or columns are possible with some devices even now.  Rather than add parallel LONG tags for these fields, it is cleaner to allow both SHORT and LONG for ImageWidth and similar fields.  See Appendix G for specific recommendations.
  114.  
  115. Note that there may be more than one IFD.  Each IFD is said to define a 'subfile.'   One potential use of subsequent subfiles is to describe a 'sub-image'  that is somehow related to the main image, such as a reduced resolution version of the image.
  116.  
  117. If you have not already done so, you may wish to turn to Appendix G to study the sample TIFF images.
  118.  
  119.  
  120. 2) Definitions
  121.  
  122. Note that the TIFF structure as described in the previous section is not specific to imaging applications in any way.  It is only the definitions of the fields themselves that jointly describe an image.
  123.  
  124. Before we begin defining the fields, we will define some basic concepts.  An image is defined to be a rectangular array of 'pixels,'  each of which consists of one or more 'samples.'  With monochromatic data, we have one sample per pixel, and 'sample'  and 'pixel'  can be used interchangeably.  RGB color data contains three samples per pixel.
  125.  
  126.  
  127. 3) The Fields
  128.  
  129. This section describes the fields defined in this version of TIFF.  More fields may be added in future versions'if possible they will be added in such a way so as not to break old software that encounters a newer TIFF file.  
  130.  
  131. The documentation for each field contains the name of the field (quite arbitrary, but convenient), the Tag value, the field Type, the Number of Values (N) expected, comments describing the field, and the default, if any.  Readers must assume the default value if the field does not exist.  
  132.  
  133. 'No default' does not mean that a TIFF writer should not pay attention to the tag.  It simply means that there is no default.  If the writer has reason to believe that readers will care about the value of this field, the writer should write the field with the appropriate value.  TIFF readers can do whatever they want if they encounter a missing 'no default' field that they care about, short of refusing to import the file.  For example, if a writer does not write out a PhotometricInterpretation field, some applications will interpret the image 'correctly,' and others will display the image inverted.  This is not a good situation, and writers should be careful not to let it happen.
  134.  
  135. The fields are grouped into several categories:  basic, informational, facsimile, document storage and retrieval, and no longer recommended.  A future version of the specification may pull some of these categories into separate companion documents.
  136.  
  137. Many fields are described in this document, but most are not 'required.'  See Appendix G for a list of required fields, as well as examples of how to combine fields into valid and useful TIFF files.
  138. Basic Fields
  139.  
  140.  
  141. Basic fields are fields that are fundamental to the pixel architecture or visual characteristics of an image.
  142.  
  143. BitsPerSample
  144. Tag     = 258  (102)
  145. Type    = SHORT
  146. N       = SamplesPerPixel
  147.  
  148. Number of bits per sample.  Note that this tag allows a different number of bits per sample for each sample corresponding to a pixel.  For example, RGB color data could use a different number of bits per sample for each of the three color planes.  Most RGB files will have the same number of BitsPerSample for each sample.  Even in this case, be sure to include all three entries.  Writing '8' when you mean '8,8,8' sets a bad precedent for other fields.
  149.  
  150. Default = 1.  See also SamplesPerPixel.
  151.  
  152.  
  153. ColorMap
  154. Tag     = 320 (140)
  155. Type    = SHORT
  156. N       = 3 * (2**BitsPerSample)
  157.  
  158. This tag defines a Red-Green-Blue color map for palette color images.  The palette color pixel value is used to index into all 3 subcurves.  For example, a Palette color pixel having a value of 0 would be displayed according to the 0th entry of the Red, Green, and Blue subcurves.
  159.  
  160. The subcurves are stored sequentially.  The Red entries come first, followed by the Green entries, followed by the Blue entries.  The length of each subcurve is 2**BitsPerSample.  A ColorMap entry for an 8-bit Palette color image would therefore have 3 * 256 entries.  The width of each entry is 16 bits, as implied by the type of SHORT.  0 represents the minimum intensity, and 65535 represents the maximum intensity.  Black is represented by 0,0,0, and white by 65535, 65535, 65535.  The purpose of the color map is to act as a 'lookup'  table mapping pixel values from 0 to 2**BitsPerSample-1 into RGB triplets.
  161.  
  162. The ColorResponseCurves field may be used in conjunction with ColorMap to further refine the meaning of the RGB triplets in the ColorMap.  However, the ColorResponseCurves default should be sufficient in most cases.
  163.  
  164. See also PhotometricInterpretation'palette color.
  165.  
  166. No default.  ColorMap must be included in all palette color images.
  167.  
  168.  
  169. ColorResponseCurves
  170. Tag     = 301 (12D)
  171. Type    = SHORT
  172. N       = 3 * (2**BitsPerSample)
  173.  
  174. This tag defines three color response curves, one each for Red, Green and Blue color information.  The Red entries come first, followed by the Green entries, followed by the Blue entries.  The length of each subcurve is 2**BitsPerSample, using the BitsPerSample value corresponding to the respective primary.  The width of each entry is 16 bits, as implied by the type of SHORT.  0 represents the minimum intensity, and 65535 represents the maximum intensity.  Black is represented by 0,0,0, and white by 65535, 65535, 65535.  Therefore, a ColorResponseCurve entry for RGB data where each of the samples is 8 bits deep would have 3 * 256 entries, each consisting of a SHORT.
  175.  
  176. The purpose of the color response curves is to refine the content of RGB color images.
  177.  
  178. See Appendix H, section VII, for further information.
  179.  
  180. Default:  curves based on the NTSC recommended gamma of 2.2.
  181.  
  182.  
  183. Compression
  184. Tag     = 259  (103)
  185. Type    = SHORT
  186. N       = 1
  187.  
  188. 1 = No compression, but pack data into bytes as tightly as possible, with no unused bits except at the end of a row.  The bytes are stored as an array of type BYTE, for BitsPerSample <= 8, SHORT if BitsPerSample > 8 and <= 16, and LONG if BitsPerSample > 16 and <= 32.  The byte ordering of data >8 bits must be consistent with that specified in the TIFF file header (bytes 0 and 1).  'II'  format files will have the least significant bytes preceeding the most significant bytes while 'MM'  format files will have the opposite.
  189.  
  190.         If the number of bits per sample is not a power of 2, and you are willing to give up some space for better performance, you may wish to use the next higher power of 2.  For example, if your data can be represented in 6 bits, you may wish to specify that it is 8 bits deep.
  191.  
  192.         Rows are required to begin on byte boundaries.  The number of bytes per row is therefore (ImageWidth * SamplesPerPixel * BitsPerSample + 7) / 8, assuming integer arithmetic, for PlanarConfiguration=1.  Bytes per row is (ImageWidth * BitsPerSample + 7) / 8 for PlanarConfiguration=2.  
  193.  
  194.         Some graphics systems want rows to be word- or double-word-aligned.  Uncompressed TIFF rows will need to be copied into word- or double-word-padded row buffers before being passed to the graphics routines in these environments.
  195.  
  196. 2 = CCITT Group 3 1-Dimensional Modified Huffman run length encoding.  See Appendix B:  'Data Compression -- Scheme 2.'  BitsPerSample must be 1, since this type of compression is defined only for bilevel images.
  197.  
  198.         When you decompress data that has been compressed by  Compression=2, you must translate white runs into 0's and black runs into 1's.  Therefore, the normal PhotometricInterpretation for those compression types is 0 (WhiteIsZero).  If a reader encounters a PhotometricInterpretation of 1 (BlackIsZero) for such an image, the image should be displayed and printed with black and white reversed.
  199.  
  200. 5 = LZW Compression,  for grayscale, mapped color, and full color images.  See Appendix F.
  201.  
  202. 32773 = PackBits compression, a simple byte oriented run length scheme for 1-bit images.  See Appendix C.
  203.  
  204. Data compression only applies to raster image data, as pointed to by StripOffsets.  All other TIFF information is unaffected.
  205.  
  206. Default = 1.
  207.  
  208.  
  209. GrayResponseCurve
  210. Tag     = 291 (123)
  211. Type    = SHORT
  212. N       = 2**BitsPerSample
  213.  
  214. The purpose of the gray response curve and the gray units is to provide more exact photometric interpretation information for gray scale image data, in terms of optical density.
  215.  
  216. The GrayScaleResponseUnits specifies the accuracy of the information contained in the curve.  Since optical density is specified in terms of fractional numbers, this tag is necessary to know how to interpret the stored integer information.  For example, if GrayScaleResponseUnits is set to 4 (ten-thousandths of a unit), and a GrayScaleResponseCurve number for gray level 4 is 3455, then the resulting actual value is 0.3455.  Optical densitometers typically measure densities within the range of 0.0 to 2.0.
  217.  
  218. If the gray scale response curve is known for the data in the TIFF file, and if the gray scale response of the output device is known, then an intelligent conversion can be made between the input data and the output device.  For example, the output can be made to look just like the input.  In addition, if the input image lacks contrast (as can be seen from the response curve), then appropriate contrast enhancements can be made.
  219.  
  220. The purpose of the gray scale response curve is to act as a 'lookup'  table mapping values from 0 to 2**BitsPerSample-1 into specific density values.  The 0th element of the GrayResponseCurve array is used to define the gray value for all pixels having a value of 0, the 1st element of the GrayResponseCurve array is used to define the gray value for all pixels having a value of 1, and so on, up to 2**BitsPerSample-1.  If your data is 'really,' say, 7-bit data, but you are adding a 1-bit pad to each pixel to turn it into 8-bit data, everything still works:  If the data is high-order justified, half of your GrayResponseCurve entries (the odd ones, probably) will never be used, but that doesn't hurt anything.  If the data is low-order justified, your pixel values will be between 0 and 127, so make your GrayResponseCurve accordingly.  What your curve does from 128 to 255 doesn‹t matter.  Note that low-order justification is probably not a good idea, however, since not all applications look at GrayResponseCurve.  Note also that LZW compression yields the same compression ratio regardless of whether the data is high-order or low-order justified.
  221.  
  222. It is permissable to have a GrayResponseCurve even for bilevel (1-bit) images.  The GrayResponseCurve will have 2 values.  It should be noted, however, that TIFF B readers are not required to pay attention to GrayResponseCurves in TIFF B files.  See Appendix G.
  223.  
  224. If both GrayResponseCurve and PhotometricInterpretation fields exist in the IFD, GrayResponseCurve values override the PhotometricInterpretation value.  But it is a good idea to write out both, since some applications do not yet pay attention to the GrayResponseCurve.
  225.  
  226. Writers may wish to purchase a Kodak Reflection Density Guide, catalog number 146 5947, available for $10 or so at prepress supply houses, to help them figure out reasonable density values for their scanner or frame grabber.  If that sounds like too much work, we recommend a curve that is linear in intensity/reflectance.  To compute reflectance from density:  R = 1 / pow(10,D).  To compute density from reflectance: D = log10 (1/R).  A typical 4-bit GrayResponseCurve may look therefore something like:  2000, 1177, 875, 699, 574, 477, 398, 331, 273, 222, 176, 135, 97, 62, 30, 0, assuming GrayResponseUnit=3.  Such a curve would be consistent with PhotometricInterpretation=1.
  227.  
  228. See also GrayResponseUnit, PhotometricInterpretation, ColorMap.
  229.  
  230.  
  231. GrayResponseUnit
  232. Tag     = 290 (122)
  233. Type    = SHORT
  234. N       = 1
  235.  
  236. 1 = Number represents tenths of a unit.
  237. 2 = Number represents hundredths of a unit.
  238. 3 = Number represents thousandths of a unit.
  239. 4 = Number represents ten-thousandths of a unit.
  240. 5 = Number represents hundred-thousandths of a unit.
  241.  
  242. Modifies GrayResponseCurve.
  243.  
  244. See also GrayResponseCurve.
  245.  
  246. For historical reasons, the default is 2.  However, for greater accuracy, we recommend using 3.
  247.  
  248.  
  249. ImageLength
  250. Tag     = 257  (101)
  251. Type    = SHORT or LONG
  252. N       = 1
  253.  
  254. The image's length (height) in pixels (Y: vertical).  The number of rows (sometimes described as 'scan lines") in the image.  See also ImageWidth.
  255.  
  256. No default.
  257.  
  258.  
  259. ImageWidth
  260. Tag     = 256  (100) 
  261. Type    = SHORT or LONG
  262. N       = 1
  263.  
  264. The image's width, in pixels (X: horizontal).  The number of columns in the image.  See also ImageLength.
  265.  
  266. No default.
  267.  
  268.  
  269. NewSubfileType
  270. Tag =  254  (FE)
  271. Type = LONG
  272. N = 1
  273.  
  274. Replaces the old SubfileType field, due to limitations in the definition of that field.
  275.  
  276. A general indication of the kind of data that is contained in this subfile.  This field is made up of a set of 32 flag bits.  Unused bits are expected to be 0.  Bit 0 is the low-order bit.
  277.  
  278. Currently defined values are:
  279.  
  280. Bit 0   is 1 if the image is a reduced resolution version of another image in this TIFF file; else the bit is 0.
  281. Bit 1   is 1 if the image is a single page of a multi-page image (see the PageNumber tag description); else the bit is 0.
  282. Bit 2   is 1 if the image defines a transparency mask for another image in this TIFF file.  The PhotometricInterpretation value must be 4, designating a transparency mask.
  283.  
  284. These values have been defined as bit flags because they are pretty much independent of each other.  For example, it be useful to have four images in a single TIFF file: a full resolution image, a reduced resolution image, a transparency mask for the full resolution image, and a transparency mask for the reduced resolution image.  Each of the four images would have a different value for the NewSubfileType field.
  285.  
  286. Default is 0.
  287.  
  288.  
  289. PhotometricInterpretation
  290. Tag     = 262  (106)
  291. Type    = SHORT
  292. N       = 1
  293.  
  294. 0 = For bilevel and grayscale images:  0 is imaged as white.  2**BitsPerSample-1 is imaged as black.  If GrayResponseCurve exists, it overrides the PhotometricInterpretation value, although it is safer to make them match, since some old applications may still be ignoring GrayResponseCurve. This is the normal value for Compression=2.
  295.  
  296. 1 = For bilevel and grayscale images:  0 is imaged as black. 2**BitsPerSample-1 is imaged as white. If GrayResponseCurve exists, it overrides the PhotometricInterpretation value, although it is safer to make them match, since some old applications may still be ignoring GrayResponseCurve. If this value is specified for Compression=2, the image should display and print reversed.
  297.  
  298. 2 = RGB.  In the RGB model, a color is described as a combination of the three primary colors of light (red, green, and blue) in particular concentrations.  For each of the three samples, 0 represents minimum intensity, and 2**BitsPerSample - 1 represents maximum intensity.  Thus an RGB value of (0,0,0) represents black, and (255,255,255) represents white, assuming 8-bit samples.  For PlanarConfiguration = 1, the samples are stored in the indicated order:  first Red, then Green, then Blue.  For PlanarConfiguration = 2, the StripOffsets for the sample planes are stored in the indicated order:  first the Red sample plane StripOffsets, then the Green plane StripOffsets, then the Blue plane StripOffsets.
  299.  
  300.         The ColorResponseCurves field may be used to globally refine or alter the color balance of an RGB image without having to change the values of the pixels themselves.
  301.  
  302. 3="Palette color.'   In this mode, a color is described with a single sample.  The sample is used as an index into ColorMap.  The sample is used to index into each of the red, green and blue curve tables to retrieve an RGB triplet defining an actual color.  When this PhotometricInterpretation value is used, the color response curves must also be supplied.  SamplesPerPixel must be 1.
  303.  
  304. 4 = Transparency Mask.  This means that the image is used to define an irregularly shaped region of another image in the same TIFF file.  SamplesPerPixel and BitsPerSample must be 1.  PackBits compression is recommended.  The 1-bits define the interior of the region; the 0-bits define the exterior of the region.  The Transparency Mask must have the same ImageLength and ImageWidth as the main image. 
  305.  
  306.         A reader application can use the mask to determine which parts of the image to display.  Main image pixels that correspond to 1-bits in the transparency mask are imaged to the screen or printer, but main image pixels that correspond to 0-bits in the mask are not displayed or printed. 
  307.  
  308.         It is possible to generalize the notion of a transparency mask to include partial transparency, but it is not clear that such information would be useful to a desktop publishing program.
  309.  
  310. No default.  That means that if you care if your image is displayed and printed as 'normal' vs 'inverted,' you must write out this field.  Do not rely on applications defaulting to what you want!  PhotometricInterpretation = 1 is recommended for bilevel (except for Compression=2) and grayscale images, due to popular user interfaces for changing the brightness and contrast of images. 
  311.  
  312.  
  313. PlanarConfiguration
  314. Tag     = 284  (11C)
  315. Type    = SHORT
  316. N       = 1
  317.  
  318. 1 = The sample values for each pixel are stored contiguously, so that there is a single image plane.   See PhotometricInterpretation to determine the order of the samples within the pixel data.  So, for RGB data, the data is stored RGBRGBRGB...and so on. 
  319.  
  320. 2 = The samples are stored in separate 'sample planes.'   The values in StripOffsets and StripByteCounts are then arranged as a 2-dimensional array, with SamplesPerPixel rows and StripsPerImage columns.    (All of the columns for row 0 are stored first, followed by the columns of row 1, and so on.)  PhotometricInterpretation describes the type of data that is stored in each sample plane.  For example, RGB data is stored with the Red samples in one sample plane, the Green in another, and the Blue in another.
  321.  
  322. If SamplesPerPixel is 1, PlanarConfiguration is irrelevant, and should not be included.
  323. Default is 1.  See also BitsPerSample, SamplesPerPixel.
  324.  
  325.  
  326. Predictor
  327. Tag     = 317 (13D)
  328. Type    = SHORT
  329. N       = 1
  330.  
  331. To be used when Compression=5 (LZW).  See Appendix F.
  332.  
  333. 1 = No prediction scheme used before coding.
  334.  
  335. Default is 1.
  336.  
  337.  
  338. ResolutionUnit
  339. Tag     = 296 (128)
  340. Type    = SHORT
  341. N       = 1
  342.  
  343. To be used with XResolution and YResolution.
  344.  
  345. 1 = No absolute unit of measurement.  Used for images that may have a non-square aspect ratio, but no meaningful absolute dimensions.  The drawback of ResolutionUnit=1 is that different applications will import the image at different sizes.  Even if the decision is quite arbitrary, it might be better to use dots per inch or dots per centimeter, and pick XResolution and YResolution such that the aspect ratio is correct and the maximum dimension of the image is about four inches (the 'four' is quite arbitrary.)
  346. 2 = Inch.
  347. 3 = Centimeter.
  348.  
  349. Default is 2.  See also XResolution, YResolution.
  350.  
  351.  
  352. RowsPerStrip
  353. Tag     = 278  (116)
  354. Type    = SHORT or LONG
  355. N       = 1
  356.  
  357. The number of rows per strip.  The image data is organized into strips for fast access to individual rows when the data is compressed'though this field is valid even if the data is not compressed.
  358.  
  359. RowsPerStrip and ImageLength together tell us the number of strips in the entire image.  The equation is StripsPerImage = (ImageLength + RowsPerStrip - 1) / RowsPerStrip, assuming integer arithmetic.
  360.  
  361. Note that either SHORT or LONG values can be used to specify RowsPerStrip.  SHORT values may be used for small TIFF files.   It should be noted, however, that earlier TIFF specification revisions required LONG values and that some software may not expect SHORT values.  See Appendix G for further recommendations.
  362.  
  363. Default is 2**32 - 1, which is effectively infinity.  That is, the entire image is one strip.  We do not recommend a single strip, however.  Choose RowsPerStrip such that each strip is about 8K bytes, even if the data is not compressed, since it makes buffering simpler for readers.  The '8K' part is pretty arbitrary, but seems to work well.
  364.  
  365. See also ImageLength, StripOffsets, StripByteCounts.
  366.  
  367.  
  368. SamplesPerPixel
  369. Tag     = 277  (115)
  370. Type    = SHORT
  371. N       = 1
  372.  
  373. The number of samples per pixel.  SamplesPerPixel is 1 for bilevel, grayscale, and palette color images.  SamplesPerPixel is 3 for RGB images.
  374.  
  375. Default = 1.  See also BitsPerSample, PhotometricInterpretation.
  376.  
  377.  
  378. StripByteCounts
  379. Tag     = 279  (117)
  380. Type    = SHORT or LONG
  381. N       = StripsPerImage for PlanarConfiguration equal to 1.
  382.         = SamplesPerPixel * StripsPerImage for PlanarConfiguration equal to 2
  383.  
  384. For each strip, the number of bytes in that strip.  The existence of this field greatly simplifies the chore of buffering compressed data, if the strip size is reasonable.
  385.  
  386. No default.  See also StripOffsets, RowsPerStrip.
  387.  
  388.  
  389. StripOffsets
  390. Tag     = 273  (111)
  391. Type    = SHORT or LONG
  392. N       = StripsPerImage for PlanarConfiguration equal to 1.
  393.         = SamplesPerPixel * StripsPerImage for PlanarConfiguration equal to 2
  394.  
  395. For each strip, the byte offset of that strip.  The offset is specified with respect to the beginning of the TIFF file.  Note that this implies that each strip has a location independent of the locations of other strips.  This feature may be useful for editing applications.  This field is the only way for a reader to find the image data, and hence must exist.
  396.  
  397. Note that either SHORT or LONG values can be used to specify the strip offsets.  SHORT values  may be used for small TIFF files.   It should be noted, however, that earlier TIFF specifications required LONG strip offsets and that some software may not expect SHORT values.  See Appendix G for further recommendations.
  398.  
  399. No default.  See also StripByteCounts, RowsPerStrip.
  400.  
  401.  
  402. XResolution
  403. Tag     = 282  (11A)
  404. Type    = RATIONAL
  405. N       = 1
  406.  
  407. The number of pixels per ResolutionUnit in the X direction, i.e., in the ImageWidth direction.  It is, of course, not mandatory that the image be actually printed at the size implied by this parameter.  It is up to the application to use this information as it wishes.
  408.  
  409. No default.  See also YResolution, ResolutionUnit.
  410.  
  411.  
  412. YResolution
  413. Tag     = 283  (11B)
  414. Type    = RATIONAL
  415. N       = 1
  416.  
  417. The number of pixels per ResolutionUnit in the Y direction, i.e., in the ImageLength direction.
  418.  
  419. No default.  See also XResolution, ResolutionUnit.
  420.  
  421.  
  422. Informational Fields
  423.  
  424.  
  425. Informational fields are fields that can provide useful information to a user, such as where the image came from.  Most are ASCII fields.  An application could have some sort of 'More Info...' dialog box to display such information.
  426.  
  427. Artist
  428. Tag     = 315  (13B)
  429. Type    = ASCII
  430.  
  431. Person who created the image.
  432.  
  433. If you need to attach a Copyright notice to an image, this is the place to do it.  In fact, you may wish to write out the contents of the field immediately after the 8-byte TIFF header.  Just make sure your IFD and field pointers are set accordingly, and you're all set.
  434.  
  435.  
  436. DateTime
  437. Tag     = 306  (132)
  438. Type    = ASCII
  439. N       = 20
  440.  
  441. Date and time of image creation.  Use the format 'YYYY:MM:DD HH:MM:SS', with hours on a 24-hour clock, and one space character between the date and the time.  The length of the string, including the null, is 20 bytes.
  442.  
  443.  
  444. HostComputer
  445. Tag     = 316  (13C)
  446. Type    = ASCII
  447.  
  448. 'ENIAC', or whatever.  
  449.  
  450. See also Make, Model, Software.
  451.  
  452.  
  453. ImageDescription
  454. Tag     = 270 (10E)
  455. Type    = ASCII
  456.  
  457. For example, a user may wish to attach a comment such as '1988 company picnic' to an image.
  458.  
  459. It has been suggested that this is what the newspaper and magazine industry calls a 'slug.'
  460.  
  461.  
  462. Make
  463. Tag     = 271  (10F)
  464. Type    = ASCII
  465.  
  466. Manufacturer of the scanner, video digitizer, or whatever.
  467.  
  468. See also Model, Software.
  469.  
  470.  
  471. Model
  472. Tag     = 272  (110)
  473. Type    = ASCII
  474.  
  475. The model name/number of the scanner, video digitizer, or whatever.
  476.  
  477. This tag is intended for user information only.
  478.  
  479. See also Make, Software.
  480.  
  481.  
  482. Software
  483. Tag     = 305  (131)
  484. Type    = ASCII
  485.  
  486. Name and release number of the software package that created the image.
  487.  
  488. This tag is intended for user information only.
  489.  
  490. See also Make, Model.
  491.  
  492.  
  493. Facsimile Fields
  494.  
  495.  
  496. Facsimile fields may be useful if you are using TIFF to store facsimile messages in 'raw' form.  They are not recommended for use in interchange with desktop publishing applications.
  497.  
  498. Compression (a basic tag)
  499. Tag     = 259  (103)
  500. Type    = SHORT
  501. N       = 1
  502.  
  503. 3 = Facsimile-compatible CCITT Group 3, exactly as specified in 'Standardization of Group 3 facsimile apparatus for document transmission,'  Recommendation T.4, Volume VII, Fascicle VII.3, Terminal Equipment and Protocols for Telematic Services, The International Telegraph and Telephone Consultative Committee (CCITT), Geneva, 1985, pages 16 through 31.  Each strip must begin on a byte boundary.  (But recall that an image can be a single strip.)  Rows that are not the first row of a strip are not required to begin on a byte boundary.  The data is stored as bytes, not words'byte-reversal is not allowed.  See the Group3Options field for Group 3 options such as 1D vs 2D coding.
  504.  
  505. 4 = Facsimile-compatible CCITT Group 4, exactly as specified in 'Facsimile Coding Schemes and Coding Control Functions for Group 4 Facsimile Apparatus,'  Recommendation T.6, Volume VII, Fascicle VII.3, Terminal Equipment and Protocols for Telematic Services, The International Telegraph and Telephone Consultative Committee (CCITT), Geneva, 1985, pages 40 through 48.  Each strip must begin on a byte boundary.  Rows that are not the first row of a strip are not required to begin on a byte boundary.  The data is stored as bytes, not words.  See the Group4Options field for Group 4 options.
  506.  
  507.  
  508. Group3Options
  509. Tag     = 292  (124)
  510. Type    = LONG
  511. N       = 1
  512.  
  513. See Compression=3.  This field is made up of a set of 32 flag bits.  Unused bits are expected to be 0.  Bit 0 is the low-order bit.  It is probably not safe to try to read the file if any bit of this field is set that you don't know the meaning of.
  514.  
  515. Bit 0   is 1 for 2-dimensional coding (else 1-dimensional is assumed).  For 2-D coding, if more than one strip is specified, each strip must begin with a 1-dimensionally coded line.  That is, RowsPerStrip should be a multiple of 'Parameter K'  as documented in the CCITT specification.
  516.  
  517. Bit 1   is 1 if uncompressed mode is used.
  518.  
  519. Bit 2   is 1 if fill bits have been added as necessary before EOL codes such that EOL always ends on a byte boundary, thus ensuring an eol-sequence of a 1 byte preceded by a zero nibble:  xxxx-0000 0000-0001.
  520.  
  521. Default is 0, for basic 1-dimensional coding.  See also Compression.
  522.  
  523.  
  524. Group4Options
  525. Tag     =  293  (125)
  526. Type    = LONG
  527. N       = 1
  528.  
  529. See Compression=4.  This field is made up of a set of 32 flag bits.  Unused bits are expected to be 0.  Bit 0 is the low-order bit.  It is probably not safe to try to read the file if any bit of this field is set that you don't know the meaning of.  Gray scale and color coding schemes are under study, and will be added when finalized.
  530.  
  531. For 2-D coding, each strip is encoded as if it were a separate image.  In particular, each strip begins on a byte boundary; and the coding for the first row of a strip is encoded independently of the previous row, using horizontal codes, as if the previous row is entirely white.  Each strip ends with the 24-bit end-of-facsimile block (EOFB).
  532.  
  533. Bit 0   is unused.
  534. Bit 1   is 1 if uncompressed mode is used.
  535.  
  536. Default is 0, for basic 2-dimensional binary compression.  See also Compression.
  537.  
  538.  
  539. Document Storage and Retrieval Fields
  540.  
  541.  
  542. These fields may be useful for document storage and retrieval applications.  They are not recommended for use in interchange with desktop publishing applications.
  543.  
  544. DocumentName
  545. Tag     = 269  (10D)
  546. Type    = ASCII
  547.  
  548. The name of the document from which this image was scanned.
  549.  
  550. See also PageName.
  551.  
  552.  
  553. PageName
  554. Tag     = 285  (11D)
  555. Type    = ASCII
  556.  
  557. The name of the page from which this image was scanned.
  558.  
  559. See also DocumentName.
  560.  
  561. No default.
  562.  
  563. PageNumber
  564. Tag     = 297  (129)
  565. Type    = SHORT
  566. N       = 2
  567.  
  568. This tag is used to specify page numbers of a multiple page (e.g. facsimile) document.  Two SHORT values are specified.  The first value is the page number; the second value is the total number of pages in the document.
  569.  
  570. Note that pages need not appear in numerical order.  The first page is 0 (zero).
  571.  
  572. No default.
  573.  
  574.  
  575. XPosition
  576. Tag     = 286  (11E)
  577. Type    = RATIONAL
  578.  
  579. The X offset of the left side of the image, with respect to the left side of the page, in ResolutionUnits.
  580.  
  581. No default.  See also YPosition.
  582.  
  583.  
  584. YPosition
  585. Tag     = 287  (11F)
  586. Type    = RATIONAL
  587.  
  588. The Y offset of the top of the image, with respect to the top of the page, in ResolutionUnits.  In the TIFF coordinate scheme, the positive Y direction is down, so that YPosition is always positive.
  589.  
  590. No default.  See also XPosition.
  591.  
  592.  
  593. No Longer Recommended
  594.  
  595.  
  596. These fields are not recommended except perhaps for local use.  They should not be used for image interchange.  They have either been superseded by other fields, have been found to have serious drawbacks, or are simply not as useful as once thought.  They may be dropped entirely from a future revision of the specification.
  597.  
  598. CellLength
  599. Tag     = 265  (109)
  600. Type    = SHORT
  601. N       = 1
  602.  
  603. The length, in 1-bit samples, of the dithering/halftoning matrix.  Assumes that Threshholding = 2.
  604.  
  605. This field, plus CellWidth and Threshholding, are problematic because they cannot safely be used to reverse-engineer grayscale image data out of dithered/halftoned black-and-white data, which is their only plausible purpose.  The only 'right' way to do it is to not bother with anything like these fields, and instead write some sophisticated pattern-matching software that can handle screen angles that are not multiples of 45 degrees, and other such challenging dithered/halftoned data.
  606.  
  607. So we do not recommend trying to convert dithered or halftoned data into grayscale data.  Dithered and halftoned data require careful treatment to avoid 'stretch marks,' but it can be done.  If you want grayscale images, get them directly from the scanner or frame grabber or whatever.
  608.  
  609. No default.  See also Threshholding.
  610.  
  611.  
  612. CellWidth
  613. Tag     = 264  (108)
  614. Type    = SHORT
  615. N       = 1
  616.  
  617. The width, in 1-bit samples, of the dithering/halftoning matrix.  
  618.  
  619. No default.  See also Threshholding.  See the comments for CellLength.
  620.  
  621.  
  622. FillOrder
  623. Tag     = 266  (10A)
  624. Type    = SHORT
  625. N       = 1
  626.  
  627. The order of data values within a byte.
  628. 1 = most significant bits of the byte are filled first.  That is, data values (or code words) are ordered from high order bit to low order bit within a byte.  
  629. 2 = least significant bits are filled first.  Since little interest has been expressed in least-significant fill order to date, and since it is easy and inexpensive for writers to reverse bit order (use a 256-byte lookup table), we recommend FillOrder=2 for private (non-interchange) use only.  
  630.  
  631. Default is FillOrder = 1.
  632.  
  633.  
  634. FreeByteCounts
  635. Tag     = 289  (121)
  636. Type    = LONG
  637.  
  638. For each 'free block'  in the file, the number of bytes in the block.
  639.  
  640. TIFF readers can ignore FreeOffsets and FreeByteCounts if present.  
  641.  
  642. FreeOffsets and FreeByteCounts do not constitute a remapping of the logical address space of the file.
  643.  
  644. Since this information can be generated by scanning the IFDs, StripOffsets, and StripByteCounts, FreeByteCounts and FreeOffsets are not needed.
  645.  
  646. In addition, it is not clear what should happen if FreeByteCounts and FreeOffsets exist in more than one IFD.
  647.  
  648. See also FreeOffsets.
  649.  
  650.  
  651. FreeOffsets
  652. Tag     = 288  (120)
  653. Type    = LONG
  654.  
  655. For each 'free block'  in the file, its byte offset.
  656.  
  657. See also FreeByteCounts.
  658.  
  659.  
  660. MaxSampleValue
  661. Tag     = 281  (119)
  662. Type    = SHORT
  663. N       = SamplesPerPixel
  664.  
  665. The maximum used sample value.  For example, if the image consists of 6-bit data low-order-justified into 8-bit bytes, MaxSampleValue will be no greater than 63. This is field is not to be used to affect the visual appearance of the image when displayed.  Nor should the values of this field affect the interpretation of any other field.   Use it for statistical purposes only.
  666.  
  667. Default is 2**(BitsPerSample) - 1.
  668.  
  669.  
  670. MinSampleValue
  671. Tag     = 280  (118)
  672. Type    = SHORT
  673. N       = SamplesPerPixel
  674.  
  675. The minimum used sample value.  This field is not to be used to affect the visual appearance of the image when displayed.  See the comments for MaxSampleValue.
  676.  
  677. Default is 0.
  678.  
  679.  
  680. SubfileType
  681. Tag     = 255  (FF)
  682. Type    = SHORT
  683. N       = 1
  684.  
  685. A general indication of the kind of data that is contained in this subfile.  Currently defined values are:
  686.  
  687. 1 = full resolution image data'ImageWidth, ImageLength, and StripOffsets are required fields; and
  688. 2 = reduced resolution image data'ImageWidth, ImageLength, and StripOffsets are required fields.  It is further assumed that a reduced resolution image is a reduced version of the entire extent of the corresponding full resolution data.
  689. 3 = single page of a multi-page image (see the PageNumber tag description).
  690.  
  691. Note that several image types can be found in a single TIFF file, with each subfile described by its own IFD.
  692.  
  693. No default.
  694.  
  695. Continued use of this field is not recommended.  Writers should instead use the new and more general NewSubfileType field.
  696.  
  697.  
  698. Orientation
  699. Tag     = 274 (112)
  700. Type    = SHORT
  701. N       = 1
  702.  
  703. 1 =     The 0th row represents the visual top of the image, and the 0th column represents the visual left hand side.
  704. 2 =     The 0th row represents the visual top of the image, and the 0th column represents the visual right hand side.
  705. 3 =     The 0th row represents the visual bottom of the image, and the 0th column represents the visual right hand side.
  706. 4 =     The 0th row represents the visual bottom of the image, and the 0th column represents the visual left hand side.
  707. 5 =     The 0th row represents the visual left hand side of the image, and the 0th column represents the visual top.
  708. 6 =     The 0th row represents the visual right hand side of the image, and the 0th column represents the visual top.
  709. 7 =     The 0th row represents the visual right hand side of the image, and the 0th column represents the visual bottom.
  710. 8 =     The 0th row represents the visual left hand side of the image, and the 0th column represents the visual bottom.
  711.  
  712. Default is 1.
  713.  
  714. This field is recommended for private (non-interchange) use only.  It is extremely costly for most readers to perform image rotation 'on the fly,' i.e., when importing and printing; and users of most desktop publishing applications do not expect a file imported by the application to be altered permanently in any way. 
  715.  
  716.  
  717. Threshholding
  718. Tag     = 263  (107)
  719. Type    = SHORT
  720. N       = 1
  721.  
  722. 1 = a bilevel 'line art'  scan.  BitsPerSample must be 1.
  723. 2 = a 'dithered'  scan, usually of continuous tone data such as photographs. BitsPerSample must be 1.
  724. 3 = Error Diffused. 
  725.  
  726. Default is Threshholding = 1.  See also CellWidth, CellLength.
  727. 4) Private Fields
  728.  
  729. An organization may wish to store information that is meaningful to only that organization in a TIFF file.  Tags numbered 32768 or higher are reserved for that purpose.  Upon request, the administrator will allocate and register a block of private tags for an organization, to avoid possible conflicts with other organizations.  Tags are normally allocated in blocks of five.  If that is not enough, feel free to ask for more. You do not need to tell the TIFF administrator or anyone else what you are going to use them for.
  730.  
  731. Private enumerated values can be accommodated in a similar fashion.  For example, you may wish to experiment with a new compression scheme within TIFF.  Enumeration constants numbered 32768 or higher are reserved for private usage.  Upon request, the administrator will allocate and register a block of enumerated values for a particular field (Compression, in our example), to avoid possible conflicts.
  732.  
  733. Tags and values which are allocated in the private number range are not prohibited from being included in a future revision of this specification.  Several such instances can be found in the TIFF specification.
  734.  
  735. Do not choose your own tag numbers.  If you do, it could cause serious problems some day.
  736.  
  737.  
  738. 5) Image File Format Issues
  739.  
  740. In the quest to give users no reason NOT to buy a product, some scanning and image editing applications overwhelm users with an incredible number of 'Save As...' options.  Let's get rid of as many of these as we possibly can.  For example, a single TIFF choice should suffice once most major readers are supporting the three TIFF compression schemes; then writers can always compress.  And given TIFF's flexibility, including private tag and image editing support features, there does not seem to be any legitimate reason for continuing to write image files using proprietary formats.
  741.  
  742. Along the same lines, there is no excuse for making a user have to know the file format of a file that is to be read by an application program.  TIFF files, as well as most other file formats, contain sufficient information to enable software to automatically and reliably distinguish one type of file from another.
  743.  
  744.  
  745. 6) For Further Information
  746.  
  747. Contact the Aldus Developers' Desk for sample TIFF files, source code fragments, and a list of features that are currently supported in Aldus products.  The Aldus Developers' Desk is the current 'TIFF administrator.'
  748.  
  749. Various TIFF related aids are found in Microsoft's Windows Developers Tookit for developers writing Windows applications.
  750.  
  751. Finally, a number of scanner vendors are providing various TIFF services, such as helping to distribute the TIFF specification and answering TIFF questions.  Contact the appropriate product manager or developer support service group.
  752.  
  753.  
  754.  
  755.  
  756.  
  757. Appendix A:  Tag Structure Rationale
  758.  
  759.  
  760. A file format is defined by both form (structure) and content.  The content of TIFF consists of definitions of individual fields.  It is therefore the content that we are ultimately interested in.  The structure merely tells us how to find the fields.  Yet the structure deserves serious consideration for a number of reasons that are not at all obvious at first glance.  Since the structure described herein departs significantly from several other approaches, it may be useful to discuss the rationale behind it.
  761.  
  762. The simplest, most straightforward structure for something like an image file is a positional format.  In a positional scheme, the location of the data defines what the data means.  For example, the field for 'number of rows' might begin at byte offset 30 in the image file.
  763.  
  764. This approach is simple and easy to implement and is perfect for static environments.  But if a significant amount of ongoing change must be accommodated, subtle problems begin to appear.  For example, suppose that a field must be superseded by a new, more general field.  You could bump a version number to flag the change.  Then new software has no problem doing something sensible with old data, and all old software will reject the new data, even software that didn't care about the old field.  This may seem like no more than a minor annoyance at first glance, but causing old software to break more often than it would really need to can be very costly and, inevitably, causes much gnashing of teeth among customers.
  765.  
  766. Furthermore, it can be avoided.  One approach is to store a 'valid' flag bit for each field.  Now you don't have to bump the version number, as long as you can put the new field somewhere that doesn't disturb any of the old fields.  Old software that didn't care about that old field anyway can continue to function.  (Old software that did care will of course have to give up, but this is an unavoidable price to be paid for the sake of progress, barring total omniscience.)
  767.  
  768. Another problem that crops up frequently is that certain fields are likely to make sense only if other fields have certain values.  This is not such a serious problem in practice; it just makes things more confusing.  Nevertheless, we note that the 'valid' flag bits described in the previous paragraph can help to clarify the situation.
  769.  
  770. Field-dumping programs can be very helpful for diagnostic purposes.  A desirable characteristic of such a program is that it doesn't have to know much about what it is dumping.  In particular, it would be nice if the program could dump ASCII data in ASCII format, integer data in integer format, and so on, without having to teach the program about new fields all the time.  So maybe we should add a 'data type' component to our fields, plus information on how long the field is, so that our dump program can walk through the fields without knowing what the fields 'mean."
  771.  
  772. But note that if we add one more component to each field, namely a tag that tells what the field means, we can dispense with the 'valid' flag bits, and we can also avoid wasting space on the non-valid fields in the file.  Simple image creation applications can write out several fields and be done.
  773.  
  774. We have now derived the essentials of a tag-based image file format. 
  775.  
  776. Finally, a caveat.  A tag based scheme cannot guarantee painless growth.  But is does provide a useful tool to assist in the process. 
  777.  
  778. Appendix B:  Data Compression'Scheme 2
  779.  
  780.  
  781. Abstract
  782.  
  783. This document describes a method for compressing bilevel data that is based on the CCITT Group 3 1D facsimile compression scheme.
  784.  
  785.  
  786. References
  787.  
  788. 1.      'Standardization of Group 3 facsimile apparatus for document transmission,' Recommendation T.4, Volume VII, Fascicle VII.3, Terminal Equipment and Protocols for Telematic Services, The International Telegraph and Telephone Consultative Committee (CCITT), Geneva, 1985, pages 16 through 31.
  789. 2.      'Facsimile Coding Schemes and Coding Control Functions for Group 4 Facsimile Apparatus,' Recommendation T.6, Volume VII, Fascicle VII.3, Terminal Equipment and Protocols for Telematic Services, The International Telegraph and Telephone Consultative Committee (CCITT), Geneva, 1985, pages 40 through 48.
  790.  
  791. We do not believe that these documents are necessary in order to implement Compression=2.  We have included (verbatim in most places) all the pertinent information in this Appendix.  However, if you wish to order the documents, you can write to ANSI, Attention: Sales, 1430 Broadway, New York, N.Y., 10018.  Ask for the publication listed above'it contains both Recommendation T.4 and T.6.
  792.  
  793.  
  794. Relationship to the CCITT Specifications
  795.  
  796. The CCITT Group 3 and Group 4 specifications describe communications protocols for a particular class of devices.  They are not by themselves sufficient to describe a disk data format.  Fortunately, however, the CCITT coding schemes can be readily adapted to this different environment.  The following is one such adaptation.  Most of the language is copied directly from the CCITT specifications.
  797.  
  798.  
  799. Coding Scheme
  800.  
  801. A line (row) of data is composed of a series of variable length code words.  Each code word represents a run length of either all white or all black.  (Actually, more than one code word may be required to code a given run, in a manner described below.)  White runs and black runs alternate.
  802.  
  803. In order to ensure that the receiver (decompressor) maintains color synchronization, all data lines will begin with a white run length code word set.  If the actual scan line begins with a black run, a white run length of zero will be sent (written).  Black or white run lengths are defined by the code words in Tables 1 and 2.  The code words are of two types:  Terminating code words and Make-up code words.  Each run length is represented by zero or more Make-up code words followed by exactly one Terminating code word.
  804.  
  805. Run lengths in the range of 0 to 63 pels (pixels) are encoded with their appropriate Terminating code word.  Note that there is a different list of code words for black and white run lengths.
  806.  
  807. Run lengths in the range of 64 to 2623 (2560+63) pels are encoded first by the Make-up code word representing the run length that is nearest to, not longer than, that required.  This is then followed by the Terminating code word representing the difference between the required run length and the run length represented by the Make-up code.
  808.  
  809. Run lengths in the range of lengths longer than or equal to 2624 pels are coded first by the Make-up code of 2560.  If the remaining part of the run (after the first Make-up code of 2560) is 2560 pels or greater, additional Make-up code(s) of 2560 are issued until the remaining part of the run becomes less than 2560 pels.  Then the remaining part of the run is encoded by Terminating code or by Make-up code plus Terminating code, according to the range mentioned above.
  810.  
  811. It is considered an unrecoverable error if the sum of the run lengths for a line does not equal the value of the ImageWidth field.
  812.  
  813. New rows always begin on the next available byte boundary.
  814.  
  815. No EOL code words are used.  No fill bits are used, except for the ignored bits at the end of the last byte of a row.  RTC is not used.
  816.  
  817.  
  818. Table 1/T.4  Terminating codes
  819.  
  820.  
  821. White           Black
  822.  run    Code     run    Code
  823. length  word    length  word
  824.  ----   ----    ------  ----
  825.  
  826.  0      00110101         0      0000110111
  827.  1      000111   1      010
  828.  2      0111     2      11
  829.  3      1000     3      10
  830.  4      1011     4      011
  831.  5      1100     5      0011
  832.  6      1110     6      0010
  833.  7      1111     7      00011
  834.  8      10011    8      000101
  835.  9      10100    9      000100
  836. 10      00111   10      0000100
  837. 11      01000   11      0000101
  838. 12      001000  12      0000111
  839. 13      000011  13      00000100
  840. 14      110100  14      00000111
  841. 15      110101  15      000011000
  842. 16      101010  16      0000010111
  843. 17      101011  17      0000011000
  844. 18      0100111 18      0000001000
  845. 19      0001100 19      00001100111
  846. 20      0001000 20      00001101000
  847. 21      0010111 21      00001101100
  848. 22      0000011 22      00000110111
  849. 23      0000100 23      00000101000
  850. 24      0101000 24      00000010111
  851. 25      0101011 25      00000011000
  852. 26      0010011 26      000011001010
  853. 27      0100100 27      000011001011
  854. 28      0011000 28      000011001100
  855. 29      00000010        29      000011001101
  856. 30      00000011        30      000001101000
  857. 31      00011010        31      000001101001
  858. 32      00011011        32      000001101010
  859. 33      00010010        33      000001101011
  860. 34      00010011        34      000011010010
  861. 35      00010100        35      000011010011
  862. 36      00010101        36      000011010100
  863. 37      00010110        37      000011010101
  864. 38      00010111        38      000011010110
  865. 39      00101000        39      000011010111
  866. 40      00101001        40      000001101100
  867. 41      00101010        41      000001101101
  868. 42      00101011        42      000011011010
  869. 43      00101100        43      000011011011
  870. 44      00101101        44      000001010100
  871. 45      00000100        45      000001010101
  872. 46      00000101        46      000001010110
  873. 47      00001010        47      000001010111
  874. 48      00001011        48      000001100100
  875. 49      01010010        49      000001100101
  876. 50      01010011        50      000001010010
  877. 51      01010100        51      000001010011
  878. 52      01010101        52      000000100100
  879. 53      00100100        53      000000110111
  880. 54      00100101        54      000000111000
  881. 55      01011000        55      000000100111
  882. 56      01011001        56      000000101000
  883. 57      01011010        57      000001011000
  884. 58      01011011        58      000001011001
  885. 59      01001010        59      000000101011
  886. 60      01001011        60      000000101100
  887. 61      00110010        61      000001011010
  888. 62      00110011        62      000001100110
  889. 63      00110100        63      000001100111    
  890.  
  891.  
  892.  
  893.  
  894. Table 2/T.4  Make-up codes
  895.  
  896. White           Black
  897.  run    Code     run    Code
  898. length  word    length  word
  899. ------  ----    ------  ----
  900.  
  901.   64    11011     64    0000001111
  902.  128    10010    128    000011001000
  903.  192    010111   192    000011001001
  904.  256    0110111  256    000001011011
  905.  320    00110110         320    000000110011
  906.  384    00110111         384    000000110100
  907.  448    01100100         448    000000110101
  908.  512    01100101         512    0000001101100
  909.  576    01101000         576    0000001101101
  910.  640    01100111         640    0000001001010
  911.  704    011001100        704    0000001001011
  912.  768    011001101        768    0000001001100
  913.  832    011010010        832    0000001001101
  914.  896    011010011        896    0000001110010
  915.  960    011010100        960    0000001110011
  916. 1024    011010101       1024    0000001110100
  917. 1088    011010110       1088    0000001110101
  918. 1152    011010111       1152    0000001110110
  919. 1216    011011000       1216    0000001110111
  920. 1280    011011001       1280    0000001010010
  921. 1344    011011010       1344    0000001010011
  922. 1408    011011011       1408    0000001010100
  923. 1472    010011000       1472    0000001010101
  924. 1536    010011001       1536    0000001011010
  925. 1600    010011010       1600    0000001011011
  926. 1664    011000  1664    0000001100100
  927. 1728    010011011       1728    0000001100101
  928.  EOL    000000000001     EOL    000000000001
  929.  
  930.  
  931.  
  932.  
  933. Additional make-up codes
  934.  
  935. White
  936. and
  937. Black   Make-up
  938. run     code
  939. length  word
  940. ------  ----
  941.  
  942. 1792    00000001000
  943. 1856    00000001100
  944. 1920    00000001101
  945. 1984    000000010010
  946. 2048    000000010011
  947. 2112    000000010100
  948. 2176    000000010101
  949. 2240    000000010110
  950. 2304    000000010111
  951. 2368    000000011100
  952. 2432    000000011101
  953. 2496    000000011110
  954. 2560    000000011111
  955.  
  956.  
  957.  
  958.  
  959. Appendix C: Data Compression'Scheme 32773'
  960. 'PackBits'
  961.  
  962.  
  963. Abstract
  964.  
  965. This document describes a simple compression scheme for bilevel scanned and paint type files.
  966.  
  967.  
  968. Motivation
  969.  
  970. The TIFF specification defines a number of compression schemes.  Compression type 1 is really no compression, other than basic pixel packing.  Compression type 2, based on CCITT 1D compression, is powerful, but not trivial to implement.  Compression type 5 is typically very effective for most bilevel images, as well as many deeper images such as palette color and grayscale images, but is also not trivial to implement.  PackBits is a simple but often effective alternative.
  971.  
  972.  
  973. Description
  974.  
  975. Several good schemes were already in use in various settings.  We somewhat arbitrarily picked the Macintosh PackBits scheme.  It is byte oriented, so there is no problem with word alignment.  And it has a good worst case behavior (at most 1 extra byte for every 128 input bytes).  For Macintosh users, there are toolbox utilities PackBits and UnPackBits that will do the work for you, but it is easy to implement your own routines.
  976.  
  977. A pseudo code fragment to unpack might look like this:
  978.  
  979. Loop until you get the number of unpacked bytes you are expecting:
  980.         Read the next source byte into n.
  981.         If n is between 0 and 127 inclusive, copy the next n+1 bytes literally.
  982.         Else if n is between -127 and -1 inclusive, copy the next byte -n+1 times.
  983.         Else if n is 128, noop.
  984. Endloop
  985.  
  986. In the inverse routine, it's best to encode a 2-byte repeat run as a replicate run except when preceded and followed by a literal run, in which case it's best to merge the three into one literal run.  Always encode 3-byte repeats as replicate runs.
  987.  
  988. So that's the algorithm.  Here are some other rules:
  989.  
  990. Ñ       Each row must be packed separately.  Do not compress across row boundaries.  
  991. Ñ       The number of uncompressed bytes per row is defined to be (ImageWidth + 7) / 8.  If the uncompressed bitmap is required to have an even number of bytes per row, decompress into word-aligned buffers.
  992. Ñ       If a run is larger than 128 bytes, simply encode the remainder of the run as one or more additional replicate runs.
  993.  
  994. When PackBits data is uncompressed, the result should be interpreted as per compression type 1 (no compression).
  995.  
  996. Appendix D
  997.  
  998.  
  999. Appendix D has been deleted.  It formerly contained guidelines for passing TIFF files on the Microsoft Windows Clipboard.  This was judged to not be a good idea, in light of the ever-increasing size of scanned images.  Applications are instead encouraged to employ file-based mechanisms to exchange TIFF data.  Aldus' PageMaker, for example, implements a 'File Place' command to allow TIFF files to be imported.
  1000.  
  1001. Appendix E:  Numerical List of TIFF Tags
  1002.  
  1003.  
  1004. NewSubfileType
  1005. Tag     =  254  (FE)
  1006. Type    = LONG
  1007. N       = 1
  1008.  
  1009. SubfileType
  1010. Tag     = 255  (FF)
  1011. Type    = SHORT
  1012. N       = 1
  1013.  
  1014. ImageWidth
  1015. Tag     = 256  (100)
  1016. Type    = SHORT or LONG
  1017. N       = 1
  1018.  
  1019. ImageLength
  1020. Tag     = 257  (101) 
  1021. Type    = SHORT or LONG
  1022. N       = 1
  1023.  
  1024. BitsPerSample
  1025. Tag     = 258  (102)
  1026. Type    = SHORT
  1027. N       = SamplesPerPixel
  1028.  
  1029. Compression
  1030. Tag     = 259  (103)
  1031. Type    = SHORT
  1032. N       = 1
  1033.  
  1034. PhotometricInterpretation
  1035. Tag     = 262  (106)
  1036. Type    = SHORT
  1037. N       = 1
  1038.  
  1039.  
  1040. Threshholding
  1041. Tag     = 263  (107)
  1042. Type    = SHORT
  1043. N       = 1
  1044.  
  1045. CellWidth
  1046. Tag     = 264  (108)
  1047. Type    = SHORT
  1048. N       = 1
  1049.  
  1050. CellLength
  1051. Tag     = 265  (109)
  1052. Type    = SHORT
  1053. N       = 1
  1054.  
  1055. FillOrder
  1056. Tag     = 266  (10A)
  1057. Type    = SHORT
  1058. N       = 1
  1059.  
  1060. DocumentName
  1061. Tag     = 269  (10D)
  1062. Type    = ASCII
  1063.  
  1064. ImageDescription
  1065. Tag     = 270 (10E)
  1066. Type    = ASCII
  1067.  
  1068. Make
  1069. Tag     = 271  (10F)
  1070. Type    = ASCII
  1071.  
  1072. Model
  1073. Tag     = 272  (110)
  1074. Type    = ASCII
  1075.  
  1076. StripOffsets
  1077. Tag     = 273  (111)
  1078. Type    = SHORT or LONG
  1079. N       = StripsPerImage for PlanarConfiguration equal to 1.
  1080.         = SamplesPerPixel * StripsPerImage for PlanarConfiguration equal to 2
  1081.  
  1082. Orientation
  1083. Tag     = 274 (112)
  1084. Type    = SHORT
  1085. N       = 1
  1086.  
  1087. SamplesPerPixel
  1088. Tag     = 277  (115)
  1089. Type    = SHORT
  1090. N       = 1
  1091.  
  1092. RowsPerStrip
  1093. Tag     = 278  (116)
  1094. Type    = SHORT or LONG
  1095. N       = 1
  1096.  
  1097. StripByteCounts
  1098. Tag     = 279  (117)
  1099. Type    = LONG or SHORT
  1100. N       = StripsPerImage for PlanarConfiguration equal to 1.
  1101.         = SamplesPerPixel * StripsPerImage for PlanarConfiguration equal to 2.
  1102.  
  1103. MinSampleValue
  1104. Tag     = 280  (118)
  1105. Type    = SHORT
  1106. N       = SamplesPerPixel
  1107.  
  1108. MaxSampleValue
  1109. Tag     = 281  (119)
  1110. Type    = SHORT
  1111. N       = SamplesPerPixel
  1112.  
  1113. XResolution
  1114. Tag     = 282  (11A)
  1115. Type    = RATIONAL
  1116. N       = 1
  1117.  
  1118. YResolution
  1119. Tag     = 283  (11B)
  1120. Type    = RATIONAL
  1121. N       = 1
  1122.  
  1123. PlanarConfiguration
  1124. Tag     = 284  (11C)
  1125. Type    = SHORT
  1126. N       = 1
  1127.  
  1128. PageName
  1129. Tag     = 285  (11D)
  1130. Type    = ASCII
  1131.  
  1132.  
  1133. XPosition
  1134. Tag     = 286  (11E)
  1135. Type    = RATIONAL
  1136.  
  1137. YPosition
  1138. Tag     = 287  (11F)
  1139. Type    = RATIONAL
  1140.  
  1141. FreeOffsets
  1142. Tag     = 288  (120)
  1143. Type    = LONG
  1144.  
  1145. FreeByteCounts
  1146. Tag     = 289  (121)
  1147. Type    = LONG
  1148.  
  1149. GrayResponseUnit
  1150. Tag     = 290 (122)
  1151. Type    = SHORT
  1152. N       = 1
  1153.  
  1154. GrayResponseCurve
  1155. Tag     = 291 (123)
  1156. Type    = SHORT
  1157. N       = 2**BitsPerSample
  1158.  
  1159. Group3Options
  1160. Tag     = 292  (124)
  1161. Type    = LONG
  1162. N       = 1
  1163.  
  1164. Group4Options
  1165. Tag     =  293  (125)
  1166. Type    = LONG
  1167. N       = 1
  1168.  
  1169. ResolutionUnit
  1170. Tag     = 296 (128)
  1171. Type    = SHORT
  1172. N       = 1
  1173.  
  1174. PageNumber
  1175. Tag     = 297  (129)
  1176. Type    = SHORT
  1177. N       = 2
  1178.  
  1179. ColorResponseCurves
  1180. Tag     = 301 (12D)
  1181. Type    = SHORT
  1182. N       = 3 * (2**BitsPerSample)
  1183.  
  1184. Software
  1185. Tag     = 305  (131)
  1186. Type    = ASCII
  1187.  
  1188. DateTime
  1189. Tag     = 306  (132)
  1190. Type    = ASCII
  1191. N       = 20
  1192.  
  1193. Artist
  1194. Tag     = 315  (13B)
  1195. Type    = ASCII
  1196.  
  1197. HostComputer
  1198. Tag     = 316  (13C)
  1199. Type    = ASCII
  1200.  
  1201. Predictor
  1202. Tag     = 317 (13D)
  1203. Type    = SHORT
  1204. N       = 1
  1205.  
  1206. WhitePoint
  1207. Tag     = 318 (13E)
  1208. Type    = RATIONAL
  1209. N       = 2
  1210.  
  1211. PrimaryChromaticities
  1212. Tag     = 319 (13F)
  1213. Type    = RATIONAL
  1214. N       = 6
  1215.  
  1216. ColorMap
  1217. Tag     = 320 (140)
  1218. Type    = SHORT
  1219. N       = 3 * (2**BitsPerSample)
  1220.  
  1221. Appendix F:  Data Compression'Scheme 5'LZW
  1222. Compression
  1223.  
  1224.  
  1225. Abstract
  1226.  
  1227. This document describes an adaptive compression scheme for raster images.
  1228.  
  1229.  
  1230. Reference
  1231.  
  1232. Terry A. Welch, 'A Technique for High Performance Data Compression', IEEE Computer, vol. 17 no. 6 (June 1984).  Describes the basic Lempel-Ziv & Welch (LZW) algorithm.  The author's goal in the article is to describe a hardware-based compressor that could be built into a disk controller or database engine, and used on all types of data.  There is no specific discussion of raster images.  We intend to give sufficient information in this Appendix so that the article is not required reading.
  1233.  
  1234.  
  1235. Requirements
  1236.  
  1237. A compression scheme with the following characteristics should work well in a desktop publishing environment:
  1238.  
  1239. Ñ       Must work well for images of any bit depth, including images deeper than 8 bits per sample.
  1240. Ñ       Must be effective:  an average compression ratio of at least 2:1 or better.  And it must have a reasonable worst-case behavior, in case something really strange is thrown at it.
  1241. Ñ       Should not depend on small variations between pixels.  Palette color images tend to contain abrupt changes in index values, due to common patterning and dithering techniques.  These abrupt changes do tend to be repetitive, however, and the scheme should make use of this fact.
  1242. Ñ       For images generated by paint programs, the scheme should not depend on a particular pattern width.  8x8 pixel patterns are common now, but we should not assume that this situation will not change.
  1243. Ñ       Must be fast.  It should not take more than 5 seconds to decompress a 100K byte grayscale image on a 68020- or 386-based computer.  Compression can be slower, but probably not by more than a factor of 2 or 3.
  1244. Ñ       The level of implementation complexity must be reasonable.  We would like something that can be implemented in no more than a couple of weeks by a'competent software engineer with some experience in image processing.  The compiled code for compression and decompression combined should be no more than about 10K.
  1245. Ñ       Does not require floating point software or hardware.
  1246.  
  1247.  
  1248. The following sections describe an algorithm based on the 'LZW'  (Lempel-Ziv & Welch) technique that meets the above requirements.  In addition meeting our requirements, LZW has the following characteristics:
  1249.  
  1250. Ñ       LZW is fully reversible.  All information is preserved.  But if noise or information is removed from an image, perhaps by smoothing or zeroing some low-order bitplanes, LZW compresses images to a smaller size.  Thus,  5-bit, 6-bit, or 7-bit data masquerading as 8-bit data compresses better than true 8-bit data. Smooth images also compress better than noisy images, and simple images compress better than complex images.
  1251. í       On a 68082- or 386-based computer, LZW software can be written to compress at between 30K and 80K bytes per second, depending on image characteristics.  LZW decompression speeds are typically about 50K bytes per second.
  1252. í       LZW works well on bilevel images, too.  It always beats PackBits, and generally ties CCITT 1D (Modified Huffman) compression, on our test images.  Tying CCITT 1D is impressive in that LZW seems to be considerably faster than CCITT 1D, at least in our implementation.
  1253. í       Our implementation is written in C, and compiles to about 2K bytes of object code each for the compressor and decompressor.
  1254. í       One of the nice things about LZW is that it is used quite widely in other applications such as archival programs, and is therefore more of a known quantity.
  1255.  
  1256.  
  1257. The Algorithm
  1258.  
  1259. Each strip is compressed independently.  We strongly recommend that RowsPerStrip be chosen such that each strip contains about 8K bytes before compression.  We want to keep the strips small enough so that the compressed and uncompressed versions of the strip can be kept entirely in memory even on small machines, but large enough to maintain nearly optimal compression ratios.
  1260.  
  1261. The LZW algorithm is based on a translation table, or string table, that maps strings of input characters into codes.  The TIFF implementation uses variable-length codes, with a maximum code length of 12 bits.  This string table is different for every strip, and, remarkably, does not need to be kept around for the decompressor.  The trick is to make the decompressor automatically build the same table as is built when compressing the data.  We use a C-like pseudocode to describe the coding scheme:
  1262.  
  1263.         InitializeStringTable();
  1264.         WriteCode(ClearCode);
  1265.         ' = the empty string;
  1266.         for each character in the strip {
  1267.                 K = GetNextCharacter();
  1268.                 if '+K is in the string table {
  1269.                         ' = '+K;        /* string concatenation */
  1270.                 } else {
  1271.                         WriteCode (CodeFromString('));
  1272.                         AddTableEntry('+K);
  1273.                         ' = K;
  1274.                 }
  1275.         } /* end of for loop */
  1276.         WriteCode (CodeFromString('));
  1277.         WriteCode (EndOfInformation);
  1278.                 
  1279. That's it.  The scheme is simple, although it is fairly challenging to implement efficiently.  But we need a few explanations before we go on to decompression.
  1280.  
  1281. The 'characters' that make up the LZW strings are bytes containing TIFF uncompressed (Compression=1) image data, in our implementation.  For example, if BitsPerSample is 4, each 8-bit LZW character will contain two 4-bit pixels.  If BitsPerSample is 16, each 16-bit pixel will span two 8-bit LZW characters.
  1282.  
  1283. (It is also possible to implement a version of LZW where the LZW character depth equals BitsPerSample, as was described by Draft 2 of Revision 5.0.  But there is a major problem with this approach.  If BitsPerSample is greater than 11, we can not use 12-bit-maximum codes, so that the resulting LZW table is unacceptably large.  Fortunately, due to the adaptive nature of LZW, we do not pay a significant compression ratio penalty for combining several pixels into one byte before compressing.  For example, our 4-bit sample images compressed about 3 percent worse, and our 1-bit images compressed about 5 percent better.  And it is easier to write an LZW compressor that always uses the same character depth than it is to write one which can handle varying depths.)
  1284.  
  1285. We can now describe some of the routine and variable references in our pseudocode:
  1286.  
  1287. InitializeStringTable() initializes the string table to contain all possible single-character strings.  There are 256 of them, numbered 0 through 255, since our characters are bytes.
  1288.  
  1289. WriteCode() writes a code to the output stream.  The first code written is a Clear code, which is defined to be code #256.
  1290.  
  1291. ' is our 'prefix string.'
  1292.  
  1293. GetNextCharacter() retrieves the next character value from the input stream.  This will be number between 0 and 255, since our characters are bytes.
  1294.  
  1295. The '+' signs indicate string concatenation.
  1296.  
  1297. AddTableEntry() adds a table entry.  (InitializeStringTable() has already put 256 entries in our table.  Each entry consists of a single-character string, and its associated code value, which is, in our application, identical to the character itself.  That is, the 0th entry in our table consists of the string <0>, with corresponding code value of <0>, the 1st entry in the table consists of the string <1>, with corresponding code value of <1>, ..., and the 255th entry in our table consists of the string <255>, with corresponding code value of <255>.)   So the first entry that we add to our string table will be at position 256, right?  Well, not quite, since we will reserve code #256 for a special 'Clear' code, and code #257 for a special 'EndOfInformation' code that we will write out at the end of the strip.  So the first multiple-character entry added to the string table will be at position 258.
  1298.  
  1299. Let's try an example.  Suppose we have input data that looks like:
  1300.  
  1301. Pixel 0:        <7>
  1302. Pixel 1:        <7>
  1303. Pixel 2:        <7>
  1304. Pixel 3:        <8>
  1305. Pixel 4:        <8>
  1306. Pixel 5:        <7>
  1307. Pixel 6:        <7>
  1308. Pixel 7:        <6>
  1309. Pixel 8:        <6>
  1310.  
  1311. First, we read Pixel 0 into K.  'K is then simply <7>, since ' is the empty string at this point.  Is the string <7> already in the string table?  Of course, since all single character strings were put in the table by InitializeStringTable().  So set ' equal to <7>, and go to the top of the loop.
  1312.  
  1313. Read Pixel 1 into K.  Does 'K (<7><7>) exist in the string table?  No, so we get to do some real work.  We write the code associated with ' to output (write <7> to output), and add 'K (<7><7>) to the table as entry 258.  Store K (<7>) into '.  Note that although we have added the string consisting of Pixel 0 and Pixel 1 to the table, we 're-use' Pixel 1 as the beginning of the next string.
  1314.  
  1315. Back at the top of the loop.  We read Pixel 2 into K.  Does 'K (<7><7>) exist in the string table?  Yes, the entry we just added, entry 258, contains exactly <7><7>.  So we just add K onto the end of ', so that ' is now <7><7>.
  1316.  
  1317. Back at the top of the loop.  We read Pixel 3 into K.  Does 'K (<7><7><8>) exist in the string table?  No, so write the code associated with ' (<258>) to output, and add 'K to the table as entry 259.  Store K (<8>) into '.
  1318.  
  1319. Back at the top of the loop.  We read Pixel 4 into K.  Does 'K (<8><8>) exist in the string table?  No, so write the code associated with ' (<8>) to output, and add 'K to the table as entry 260.  Store K (<8>) into '.
  1320.  
  1321. Continuing, we get the following results:
  1322.  
  1323.         After reading:  We write to output:     And add table entry:
  1324.         Pixel 0
  1325.         Pixel 1 <7>     258: <7><7>
  1326.         Pixel 2
  1327.         Pixel 3 <258>   259: <7><7><8>
  1328.         Pixel 4 <8>     260: <8><8>
  1329.         Pixel 5 <8>     261: <8><7>
  1330.         Pixel 6
  1331.         Pixel 7 <258>   262: <7><7><6>
  1332.         Pixel 8 <6>     263: <6><6>
  1333.  
  1334. WriteCode() also requires some explanation.  The output code stream, <7><258><8><8><258><6>... in our example, should be written using as few bits as possible.  When we are just starting out, we can use 9-bit codes, since our new string table entries are greater than 255 but less than 512.  But when we add table entry 512, we must switch to 10-bit codes.  Likewise, we switch to 11-bit codes at 1024, and 12-bit codes at 2048.  We will somewhat arbitrarily limit ourselves to 12-bit codes, so that our table can have at most 4096 entries.  If we push it any farther, tables tend to get too large.
  1335.  
  1336. What happens if we run out of room in our string table?  This is where the afore-mentioned Clear code comes in.  As soon as we use entry 4094, we write out a (12-bit) Clear code.   (If we wait any longer to write the Clear code, the decompressor might try to interpret the Clear code as a 13-bit code.)  At this point, the compressor re-initializes the string table and starts writing out 9-bit codes again.
  1337.  
  1338. Note that whenever you write a code and add a table entry, ' is not left empty.  It contains exactly one character.  Be careful not to lose it when you write an end-of-table Clear code.  You can either write it out as a 12-bit code before writing the Clear code, in which case you will want to do it right after adding table entry 4093, or after the clear code as a 9-bit code.  Decompression gives the same result in either case.
  1339.  
  1340. To make things a little simpler for the decompressor, we will require that each strip begins with a Clear code, and ends with an EndOfInformation code.
  1341.  
  1342. Every LZW-compressed strip must begin on a byte boundary.  It need not begin on a word boundary.  LZW compression codes are stored into bytes in high-to-low-order fashion, i.e., FillOrder is assumed to be 1.  The compressed codes are written as bytes, not words, so that the compressed data will be identical regardless of whether it is an 'II' or 'MM' file.
  1343.  
  1344. Note that the LZW string table is a continuously updated history of the strings that have been encountered in the data.  It thus reflects the characteristics of the data, providing a high degree of adaptability.
  1345.  
  1346.  
  1347. LZW Decoding
  1348.  
  1349. The procedure for decompression is a little more complicated, but still not too bad:
  1350.                 
  1351.         while ((Code = GetNextCode()) != EoiCode) {
  1352.                 if (Code == ClearCode) {
  1353.                         InitializeTable();
  1354.                         Code = GetNextCode();
  1355.                         if (Code == EoiCode)
  1356.                                 break;
  1357.                         WriteString(StringFromCode(Code));
  1358.                         OldCode = Code;
  1359.                 }  /* end of ClearCode case */
  1360.  
  1361.                 else {
  1362.                         if (IsInTable(Code)) {
  1363.                                 WriteString(StringFromCode(Code));
  1364.                                 AddStringToTable(StringFromCode(OldCode)+FirstChar(StringFromCode(Code)));
  1365.                                 OldCode = Code;
  1366.                         } else {
  1367.                                 OutString = StringFromCode(OldCode) + FirstChar(StringFromCode(OldCode));
  1368.                                 WriteString(OutString);
  1369.                                 AddStringToTable(OutString);
  1370.                                 OldCode = Code;
  1371.                         }
  1372.                 } /* end of not-ClearCode case */
  1373.         } /* end of while loop */
  1374.  
  1375. The function GetNextCode() retrieves the next code from the LZW-coded data.  It must keep track of bit boundaries.  It knows that the first code that it gets will be a 9-bit code.  We add a table entry each time we get a code, so GetNextCode() must switch over to 10-bit codes as soon as string #511 is stored into the table.
  1376.  
  1377. The function StringFromCode() gets the string associated with a particular code from the string table.
  1378.  
  1379. The function AddStringToTable() adds a string to the string table.  The '+' sign joining the two parts of the argument to AddStringToTable indicate string concatenation.
  1380.  
  1381. StringFromCode() looks up the string associated with a given code.
  1382.  
  1383. WriteString() adds a string to the output stream.
  1384.  
  1385.  
  1386. When SamplesPerPixel Is Greater Than 1
  1387.  
  1388. We have so far described the compression scheme as if SamplesPerPixel were always 1, as will be be the case with palette color and grayscale images.  But what do we do with RGB image data?
  1389.  
  1390. Tests on our sample images indicate that the LZW compression ratio is nearly identical regardless of whether PlanarConfiguration=1 or PlanarConfiguration=2, for RGB images.  So use whichever configuration you prefer, and simply compress the bytes in the strip.
  1391.  
  1392. It is worth cautioning that compression ratios on our test RGB images were disappointing low: somewhere between 1.1 to 1 and 1.5 to 1, depending on the image.  Vendors are urged to do what they can to remove as much noise from their images as possible.  Preliminary tests indicate that significantly better compression ratios are possible with less noisy images.  Even something as simple as zeroing out one or two least-significant bitplanes may be quite effective, with little or no perceptible image degradation.
  1393.  
  1394.  
  1395. Implementation
  1396.  
  1397. The exact structure of the string table and the method used to determine if a string is already in the table are probably the most significant design decisions in the implementation of a LZW compressor and decompressor.  Hashing has been suggested as a useful technique for the compressor.  We have chosen a tree based approach, with good results.  The decompressor is actually more straightforward, as well as faster, since no search is involved'strings can be accessed directly by code value.
  1398.  
  1399.  
  1400. Performance
  1401.  
  1402. Many people do not realize that the performance of any compression scheme depends greatly on the type of data to which it is applied.  A scheme that works well on one data set may do poorly on the next.
  1403.  
  1404. But since we do not want to burden the world with too many compression schemes, an adaptive scheme such as LZW that performs quite well on a wide range of images is very desirable.  LZW may not always give optimal compression ratios, but its adaptive nature and relative simplicity seem to make it a good choice.
  1405.  
  1406. Experiments thus far indicate that we can expect compression ratios of between 1.5 and 3.0 to 1 from LZW, with no loss of data, on continuous tone grayscale scanned images.  If we zero the least significant one or two bitplanes of 8-bit data, higher ratios can be achieved.  These bitplanes often consist chiefly of noise, in which case little or no loss in image quality will be perceived.  Palette color images created in a paint program generally compress much better than continuous tone scanned images, since paint images tend to be more repetitive.  It is not unusual to achieve compression ratios of 10 to 1 or better when using LZW on palette color paint images.
  1407.  
  1408. By way of comparison, PackBits, used in TIFF for black and white bilevel images, does not do well on color paint images, much less continuous tone grayscale and color images.  1.2 to 1 seemed to be about average for 4-bit images, and 8-bit images are worse.
  1409.  
  1410. It has been suggested that the CCITT 1D scheme could be used for continuous tone images, by compressing each bitplane separately.  No doubt some compression could be achieved, but it seems unlikely that a scheme based on a fixed table that is optimized for short black runs separated by longer white runs would be a very good choice on any of the bitplanes.  It would do quite well on the high-order bitplanes (but so would a simpler scheme like PackBits), and would do quite poorly on the low-order bitplanes.  We believe that the compression ratios would generally not be very impressive, and the process would in addition be quite slow.  Splitting the pixels into bitplanes and putting them back together is somewhat expensive, and the coding is also fairly slow when implemented in software.
  1411.  
  1412. Another approach that has been suggested uses uses a 2D differencing step following by coding the differences using a fixed table of variable-length codes.  This type of scheme works quite well on many 8-bit grayscale images, and is probably simpler to implement than LZW.  But it has a number of disadvantages when used on a wide variety of images.  First, it is not adaptive.  This makes a big difference when compressing data such as 8-bit images that have been 'sharpened' using one of the standard techniques.  Such images tend to get larger instead of smaller when compressed.  Another disadvantage of these schemes is that they do not do well with a wide range of bit depths.  The built-in code table has to be optimized for a particular bit depth in order to be effective.
  1413.  
  1414. Finally, we should mention 'lossy' compression schemes.  Extensive research has been done in the area of lossy, or non-information-preserving image compression.  These techniques generally yield much higher compression ratios than can be achieved by fully-reversible, information-preserving image compression techniques such as PackBits and LZW.  Some disadvantages:  many of the lossy techniques are so computationally expensive that hardware assists are required.  Others are so complicated that most microcomputer software vendors could not afford either the expense of implementation or the increase in application object code size.  Yet others sacrifice enough image quality to make them unsuitable for publishing use.  
  1415.  
  1416. In spite of these difficulties, we believe that there will one day be a standardized lossy compression scheme for full color images that will be usable for publishing applications on microcomputers.  An International Standards Organization group, ISO/IEC/JTC1/SC2/WG8, in cooperation with CCITT Study Group VIII, is hard at work on a scheme that might be appropriate.  We expect that a future revision of TIFF will incorporate this scheme once it is finalized, if it turns out to satisfy the needs of desktop publishers and others in the microcomputer community.  This will augment, not replace, LZW as an approved TIFF compression scheme.  LZW will very likely remain the scheme of choice for Palette color images, and perhaps 4-bit grayscale images, and may well overtake CCITT 1D and PackBits for bilevel images.
  1417.  
  1418.  
  1419. Future LZW Extensions
  1420.  
  1421. Some images compress better using LZW coding if they are first subjected to a process wherein each pixel value is replaced by the difference between the pixel and the preceding pixel.  Performing this differencing in two dimensions helps some images even more.  However, many images do not compress better with this extra preprocessing, and for a significant number of images, the compression ratio is actually worse.  We are therefore not making differencing an integral part of the TIFF LZW compression scheme.  
  1422.  
  1423. However, it is possible that a 'prediction' stage like differencing may exist which is effective over a broad range of images.  If such a scheme is found, it may be incorporated in the next major TIFF revision.  If so, a new value will be defined for the new 'Predictor' TIFF tag.  Therefore, all TIFF readers that read LZW files must pay attention to the Predictor tag.  If it is 1, which is the default case, LZW decompression may proceed safely.  If it is not 1, and the reader does not recognize the specified prediction scheme, the reader should give up.
  1424.  
  1425.  
  1426. Acknowledgements
  1427.  
  1428. The original LZW reference has already been given.  The use of ClearCode as a technique to handle overflow was borrowed from the compression scheme used by the Graphics Interchange Format (GIF), a small-color-paint-image-file format used by CompuServe that also is an adaptation of the LZW technique.  Joff Morgan and Eric Robinson of Aldus were each instrumental in their own way in getting LZW off the ground.
  1429.  
  1430. Appendix G: TIFF Classes
  1431.  
  1432.  
  1433. Rationale
  1434.  
  1435. TIFF was designed to make life easier for scanner vendors, desktop publishing software developers, and users of these two classes of products, by reducing the proliferation of proprietary scanned image formats.  It has succeeded far beyond our expectations in this respect.  But we had expected that TIFF would be of interest to only a dozen or so scanner vendors (there weren't any more than that in 1985), and another dozen or so desktop publishing software vendors.  This turned out to be a gross underestimate.  The only problem with this sort of success is that TIFF was designed to be powerful and flexible, at the expense of simplicity.  It takes a fair amount of effort to handle all the options currently defined in this specification (probably no application does a complete job), and that is currently the only way you can be sure that you will be able to import any TIFF image, since there are so many image-generating applications out there now.
  1436.  
  1437. So here is an attempt to channel some of the flexibility of TIFF into more restrictive paths, using what we have learned in the past two years about which options are the most useful.  Such an undertaking is of course filled with fairly arbitrary decisions.  But the result is that writers can more easily write files that will be successfully read by a wide variety of applications, and readers can know when they can stop adding TIFF features.
  1438.  
  1439. The price we pay for TIFF Classes is some loss in the ability to adapt.  Once we establish the requirements for a TIFF Class, we can never add new requirements, since old software would not know about these new requirements.  (The best we can do at that point is establish new TIFF Classes.  But the problem with that is that we could quickly have too many TIFF Classes.)  So we must believe that we know what we are doing in establishing these Classes.  If we do not, any mistakes will be expensive.
  1440.  
  1441.  
  1442. Overview
  1443.  
  1444. Four TIFF Classes have been defined:
  1445.  
  1446. Ñ       Class B for bilevel (1-bit) images
  1447. Ñ       Class G for grayscale images
  1448. Ñ       Class P for palette color images
  1449. Ñ       Class R for RGB full color images
  1450.  
  1451. To save time and space, we will usually say 'TIFF B', 'TIFF G', 'TIFF P,' and 'TIFF R.'  If we are talking about all four types, we may write 'TIFF X.'
  1452.  
  1453. (Note to fax people:  if you are interested in a fax TIFF F Class, please get together and decide what should be in TIFF Class F files.  Let us know if we can help in any way.  When you have decided, send us your results, so that we can include the information here.)
  1454.  
  1455.  
  1456. Core Requirements
  1457.  
  1458. This section describes requirements that are common to all TIFF Class X images.
  1459.  
  1460. General Requirements
  1461.  
  1462. The following are required characteristics of all TIFF Class X files.  
  1463.  
  1464. Where there are options, TIFF X writers can do whichever one they want, though we will often recommend a particular choice, but TIFF X readers must be able to handle all of them.  Please pay close attention to the recommendations.  It is possible that at some point in the future, new and even-simpler TIFF classes will be defined that include only recommended features.  
  1465.  
  1466. You will need to read at least the first three sections of the main specification in order to fully understand the following discussion.
  1467.  
  1468. Defaults.  TIFF X writers may, but are not required, to write out a field that has a default value, if the default value is the one desired.  TIFF X readers must be prepared to handle either situation.
  1469.  
  1470. Other fields.  TIFF X readers must be prepared to encounter fields other than the required fields in TIFF X files.  TIFF X writers are allowed to write fields such as Make, Model, DateTime, and so on, and TIFF X readers can certainly make use of such fields if they exist.  TIFF X readers must not, however, refuse to read the file if such optional fields do not exist.
  1471.  
  1472. 'MM' and ’II‹ byte order.  TIFF X readers must be able to handle both byte orders.  TIFF writers can do whichever is most convenient or efficient.  Images are crossing the IBM PC/Macintosh boundary (and others as well) with a surprisingly high frequency.  We could force writers to all use the same byte order, but preliminary evidence indicates that this will cause problems when we start seeing greater-than-8-bit images.   Reversing bytes while scanning could well slow down the scanning process enough to cause the scanning mechanism to stop, which tends to create image quality problems.
  1473.  
  1474. Multiple subfiles.  TIFF X readers must be prepared for multiple images (i.e., subfiles) per TIFF file, although they are not required to do anything with any image after the first one.  TIFF X writers must be sure to write a long word of 0 after the last IFD (this is the standard way of signalling that this IFD was the last one) as indicated in the TIFF structure discussion.  
  1475.  
  1476. If a TIFF X writer writes multiple subfiles, the first one must be the full resolution image.  Subsequent subimages, such as reduced resolution images and transparency masks, may be in any order in the TIFF file.  If a reader wants to make use of such subimages, it will have to scan the IFD‹s before deciding how to proceed.
  1477.  
  1478. TIFF X Editors.  Editors, applications that modify TIFF files, have a few additional requirements.
  1479.  
  1480. TIFF editors must be especially careful about subfiles.  If a TIFF editor edits a full-resolution subfile, but does not update an accompanying reduced-resolution subfile, a reader that uses the reduced-resolution subfile for screen display will display the wrong thing.  So TIFF editors must either create a new reduced-resolution subfile when they alter a full-resolution subfile, or else they must simply delete any subfiles that they aren't prepared to deal with.
  1481.  
  1482. A similar situation arises with the fields themselves.  A TIFF X editor need only worry about the TIFF X required fields.  In particular, it is unnecessary, and probably dangerous, for an editor to copy fields that it does not understand.  It may have altered the file in a way that is incompatible with the unknown fields.
  1483.  
  1484.  
  1485. Required Fields
  1486.  
  1487. NewSubfileType.  LONG.  Recommended but not required.
  1488.  
  1489. ImageWidth.  SHORT or LONG.  (That is, both 'SHORT' and 'LONG' TIFF data types are allowed, and must be handled properly by readers.  TIFF writers can use either.)  TIFF X readers are not required to read arbitrarily large files however.  Some readers will give up if the entire image cannot fit in available memory.  (In such cases the reader should inform the user of the nature of the problem.)  Others will probably not be able to handle ImageWidth greater than 65535.  Recommendation: use LONG, since resolutions seem to keep going up.
  1490.  
  1491. ImageLength.  SHORT or LONG.  Recommendation: use  LONG.
  1492.  
  1493. RowsPerStrip.  SHORT or LONG.  Readers must be able to handle any value between 1 and 2**32-1.  However, some readers may try to read an entire strip into memory at one time, so that if the entire image is one strip, the application may run out of memory.  Recommendation 1:  Set RowsPerStrip such that the size of each strip is about 8K bytes.  Do this even for uncompressed data, since it is easy for a writer and makes things simpler for readers.  (Note:  extremely wide, high-resolution images may have rows larger than 8K bytes; in this case, RowsPerStrip should be 1, and the strip will just have to be larger than 8K.  Recommendation 2: use LONG.
  1494.  
  1495. StripOffsets.  SHORT or LONG.  As explained in the main part of the specification, the number of StripOffsets depends on RowsPerStrip and ImageLength.  Recommendation:  always use LONG.  (LONG must, of course, be used if the file is more than 64K bytes in length.)
  1496.  
  1497. StripByteCounts.  SHORT or LONG.  Many existing TIFF images do not contain StripByteCounts, because, in a strict sense, they are unnecessary.  It is possible to write an efficient TIFF reader that does not need to know in advance the exact size of a compressed strip.  But it does make things considerably more complicated, so we will require StripByteCounts in TIFF X files.  Recommendation:  use SHORT, since strips are not supposed to be very large.
  1498.  
  1499. XResolution, YResolution.  RATIONAL.  Note that the X and Y resolutions may be unequal.  A TIFF X reader must be able to handle this case.  TIFF X pixel-editors will typically not care about the resolution, but applications such as page layout programs will.
  1500.  
  1501. ResolutionUnit.  SHORT.  TIFF X readers must be prepared to handle all three values for ResolutionUnit.
  1502.  
  1503.  
  1504. TIFF Class B - Bilevel
  1505.  
  1506. Required (in addition to the above core requirements)
  1507.  
  1508. The following fields and values are required for TIFF B files, in addition to the fields required for all TIFF X images (see above).
  1509.  
  1510. SamplesPerPixel = 1.  SHORT.  (Since this is the default, the field need not be present.  The same thing holds for other required TIFF X fields that have defaults.)
  1511.  
  1512. BitsPerSample = 1.  SHORT.  
  1513.  
  1514. Compression = 1, 2 (CCITT 1D), or 32773 (PackBits).  SHORT.  TIFF B readers must handle all three.  Recommendation:  use PackBits.  It is simple, effective, fast, and has a good worst-case behavior.  CCITT 1D is definitely more effective in some situations, such as scanning a page of body text, but is tough to implement and test, fairly slow, and has a poor worst-case behavior.  Besides, scanning a page of 12 point text is not very useful for publishing applications, unless the image data is turned into ASCII text via OCR software, which is outside the scope of TIFF.
  1515.  
  1516. PhotometricInterpretation = 0 or 1.  SHORT.
  1517. A Sample TIFF B Image
  1518.  
  1519. Offset          Value
  1520. (hex)   Name    (mostly hex)
  1521.  
  1522. Header:
  1523. 0000    Byte Order      4D4D
  1524. 0002    Version 002A
  1525. 0004    1st IFD pointer 00000014
  1526.  
  1527. IFD:
  1528. 0014    Entry Count     000D
  1529. 0016    NewSubfileType  00FE    0004    00000001        00000000
  1530. 0022    ImageWidth      0100    0004    00000001        000007D0
  1531. 002E    ImageLength     0101    0004    00000001        00000BB8
  1532. 003A    Compression     0103    0003    00000001        8005 0000
  1533. 0046    PhotometricInterpretation       0106    0003    00000001        0001 0000
  1534. 0052    StripOffsets    0111    0004    000000BC        000000B6
  1535. 005E    RowsPerStrip    0116    0004    00000001        00000010
  1536. 006A    StripByteCounts 0117    0003    000000BC        000003A6
  1537. 0076    XResolution     011A    0005    00000001        00000696
  1538. 0082    YResolution     011B    0005    00000001        0000069E
  1539. 008E    Software        0131    0002    0000000E        000006A6
  1540. 009A    DateTime        0132    0002    00000014        000006B6
  1541. 00A6    Next IFD pointer        00000000
  1542.  
  1543. Fields pointed to by the tags:
  1544. 00B6    StripOffsets    Offset0, Offset1, ... Offset187
  1545. 03A6    StripByteCounts Count0, Count1, ... Count187
  1546. 0696    XResolution     0000012C 00000001
  1547. 069E    YResolution     0000012C 00000001
  1548. 06A6    Software        "PageMaker 3.0"
  1549. 06B6    DateTime        "1988:02:18 13:59:59"
  1550.  
  1551.  
  1552. Image Data:
  1553. 00000700        Compressed data for strip 10
  1554. xxxxxxxx        Compressed data for strip 179
  1555. xxxxxxxx        Compressed data for strip 53
  1556. xxxxxxxx        Compressed data for strip 160
  1557. .
  1558. .
  1559. .
  1560.  
  1561. End of example
  1562.  
  1563. Comments on the TIFF B example
  1564.  
  1565. 1.      The IFD in our example starts at position hex 14.  It could have been anywhere in the file as long as the position is even and greater than or equal to 8, since the TIFF header is 8 bytes long and must be the first thing in a TIFF file.
  1566.  
  1567. 2.      With 16 rows per strip, we have 188 strips in all.
  1568.  
  1569. 3.      The example uses a number of optional fields, such as DateTime.  TIFF X readers must safely skip over these fields if they do not want to use the information.  And TIFF X readers must not require that such fields be present.
  1570.  
  1571. 4.      Just for fun, our example has highly fragmented image data; the strips of our image are not even in sequential order.  The point is that strip offsets must not be ignored.  Never assume that strip N+1 follows strip N.  Incidentally, there is no requirement that the image data follows the IFD information.  Just the follow the pointers, whether they be IFD pointers, field pointers, or Strip Offsets.
  1572.  
  1573.  
  1574.  
  1575. TIFF Class G - Grayscale
  1576.  
  1577. Required (in addition to the above core requirements)
  1578.  
  1579. SamplesPerPixel = 1.  SHORT.
  1580.  
  1581. BitsPerSample = 4, 8.  SHORT.  There seems to be little justification for working with grayscale images shallower than 4 bits, and 5-bit , 6-bit, and 7-bit images can easily be stored as 8-bit images, as long as you can compress the 'unused' bit planes without penalty.  And we can do just that with LZW (Compression = 5.)
  1582.  
  1583. Compression = 1 or 5 (LZW).  SHORT.  Recommendation: use 5, since LZW decompression is turning out to be quite fast.
  1584.  
  1585. PhotometricInterpretation = 0 or 1.  SHORT.   Recommendation: use 1, due to popular user interfaces for adjusting brightness and contrast.
  1586.  
  1587.  
  1588.  
  1589. TIFF Class P - Palette Color
  1590.  
  1591. Required (in addition to the above core requirements)
  1592.  
  1593. SamplesPerPixel = 1.  SHORT.  We use each pixel value as an index into all three color tables in ColorMap.
  1594.  
  1595. BitsPerSample = 1,2,3,4,5,6,7, or 8.  SHORT.  1,2,3,4, and 8 are probably the most common, but as long as we are doing that, the rest come pretty much for free.
  1596.  
  1597. Compression = 1 or 5.  SHORT.  
  1598.  
  1599. PhotometricInterpretation = 3 (Palette Color).  SHORT.
  1600.  
  1601. ColorMap.  SHORT.
  1602.  
  1603. Note that bilevel and grayscale images can be represented as special cases of palette color images.  As soon as enough major applications support palette color images, we may want to start getting rid of distinctions between bilevel, grayscale, and palette color images.
  1604.  
  1605.  
  1606. TIFF Class R - RGB Full Color
  1607.  
  1608. Required (in addition to the above Core Requirements)
  1609.  
  1610. SamplesPerPixel = 3.  SHORT.  One sample each for Red, Green, and Blue.
  1611.  
  1612. BitsPerSample = 8,8,8.  SHORT.  Shallower samples can easily be stored as 8-bit samples with no penalty if the data is compressed with LZW.  And evidence to date indicates that images deeper than 8 bits per sample are not worth the extra work, even in the most demanding publishing applications.
  1613.  
  1614. PlanarConfiguration = 1 or 2.  SHORT.  Recommendation:  use 1.
  1615.  
  1616. Compression = 1 or 5.  SHORT.  
  1617.  
  1618. PhotometricInterpretation = 2 (RGB).  SHORT.
  1619.  
  1620. Recommended
  1621.  
  1622. Recommended for TIFF Class R, but not required, are the new (as of Revision 5.0) colorimetric information tags.  See Appendix H.
  1623.  
  1624.  
  1625. Conformance and User Interface
  1626.  
  1627. Applications that write valid TIFF X files should include 'TIFF B' and/or 'TIFF G' and/or 'TIFF P' and/or 'TIFF R' and/or in their product spec sheets, if they can write the respective TIFF Class X files.  If your application writes all four of these types, you may wish to write it as 'TIFF B,G,P,R.'  Of course, a term like 'TIFF B,' while fine for communicating with other vendors, will not convey much information to a typical user.  In this case, a phrase such as 'Standard TIFF Black-and-White Scanned Images' might be better.
  1628.  
  1629. The same terminology guidelines apply to applications that read TIFF Class X files.
  1630.  
  1631. If your application reads more kinds of files than it writes, or vice versa, it would be a good idea to make that clear to the buyer.  For example, if your application reads TIFF B and TIFF G files, but writes only TIFF G files, you should write it that way in the spec sheet.
  1632.  
  1633. Appendix H: Image Colorimetry Information
  1634.  
  1635. Chris Sears
  1636. 210 Lake Street
  1637. San Francisco, CA 94118
  1638.  
  1639. June 4, 1988
  1640. Revised August 8, 1988
  1641.  
  1642.  
  1643. I. Introduction
  1644.  
  1645. Our goal is to accurately reproduce a color image using different devices.  Accuracy requires techniques of measurement and a standard of comparison.  Different devices imply device independence.  Colorimetry provides the framework to solve these problems.  When an image has a complete colorimetric description, in principle it can be reproduced identically on different monitors and using different media, such as offset lithography.
  1646.  
  1647. The colorimetry data is specified when the image is created or changed.  A scanned image has colorimetry data derived from  the filters and light sources of the scanner and a synthetic image has colorimetry data corresponding to the monitor used to create it or the monitor model of the rendering environment.  This data is used to map an input image to the markings or colors of a particular output device.
  1648.  
  1649. Section II describes various standards organizations and their work in color.
  1650. Section III describes our motivation for seeking these tags.
  1651. Section IV describes our goals of reproduction.
  1652. Sections V, VI and VII introduce the colorimetry tags.
  1653. Section VIII specifies the tags themselves.
  1654. Section IX describes the defaults.
  1655. Section X discusses the limitations and some of the other issues.
  1656. Section XI provides a few references.
  1657.  
  1658.  
  1659. II. Related Standards
  1660.  
  1661. TIFF is a general standard for describing image data.  It would be foolish for us to change TIFF in a way that did not match existing industry and international standards.  Therefore, we have taken pains to note in the discussion below the efforts of various standards organizations and select defaults from the work of these organizations.
  1662.  
  1663. CIE     (Commission Internationale de l‹Eclairage)  The basis of the colorimetry information is the CIE 1931 Standard Observer [3].  While other color models could be supported [1] [4], CIE 1931 XYZ is the international standard accepted across industries for specifying color and CIE xyY is the chromaticity diagram associated with CIE 1931 XYZ tristimulus values.
  1664.  
  1665. NTSC    (National Television System Committee)  NTSC is of interest primarily for historical reasons and its use in encoding television data.  Manufacturing standards for monitors have for some time drifted significantly from the 1953 NTSC colorimetry specification.
  1666.  
  1667. SMPTE   (Society of Motion Picture and Television Engineers)   Most of the work by NTSC has been largely subsumed by SMPTE.  This organization has a set of standards called "Recommended Practices" that apply to various technical aspects of film and television production [5] [6].
  1668.  
  1669. ISO     (International Standards Organization)  ISO has become involved in color standards through work on a color addendum to "Office Document Architecture (ODA) and Interchange Format" [7].
  1670.  
  1671. ANSI    (American National Standards Institute)  ANSI is the American representative to ISO .
  1672.  
  1673.  
  1674. III. Motivation
  1675.  
  1676. Our motivation for defining these tags stems from our research and development in color separation technology.  With the information described here and the RGB pixel data, we have all of the information necessary for generating high-quality color separations.  We could supply the colorimetry information outside of the image file.  But since TIFF provides a convenient mechanism for bundling all of the relevant information in a single place, tags are defined to describe this information in color TIFF files.
  1677.  
  1678. A color image rendered with incorrect colorimetry information looks different from the original.  One of our early test images has an artifact in it where the image was scanned with one set of primaries and color ramps were overlaid on top of it with different primaries.  The blue ramp looked purple when we printed it. Using incorrect gamma tables or white points can also lead to distorted images.  The best way to avoid these kinds of errors is to allow the creator of an image to supply the colorimetry information along with the RGB values [1] [2].
  1679.  
  1680. The purpose of the colorimetry data is to allow a projective transformation from the primaries and white point of the image to the primaries and white point of the rendering media.  Gamma reflects the non-linear transfer gradient of real media.
  1681.  
  1682.  
  1683. IV. Colorimetric Color Reproduction
  1684.  
  1685. Earlier we said that given the proper colorimetric data an image could be rendered identically using two different calibrated devices.  By identical, we mean colorimetric reproduction [9].  Specifically, the chromaticities match and the luminance is scaled to correspond to the luminance range of the output device.  Because of this, we only need the chromaticity coordinates of the white point and primaries.  The absolute luminance is arbitrary and unnecessary.
  1686.  
  1687.  
  1688. V. White Point
  1689.  
  1690. In TIFF 4.0, the white point was specified as D65.  This appendix allocates a separate tag for describing the white point and D65 is the logical default since it is the SMPTE standard [6].
  1691.  
  1692. The white point is defined colorimetrically in the CIE xyY chromaticity diagram.  While it is rare for monitors to differ from D65, scanned images often have different white points.  Rendered images can have arbitrary white points.  The graphic arts use D50 as the standard viewing light source [8].
  1693.  
  1694.  
  1695. VI. Primary Chromaticities
  1696.  
  1697. In TIFF 4.0, the primary color chromaticities matched the NTSC specification.  With the wide variety of color scanners, monitors and renderers, TIFF needs a mechanism for accurately describing the chromaticities of the primary colors.  We use SMPTE as the default chromaticity since conventional monitors are closer to SMPTE and some monitors (Conrac 6545) are manufactured to the SMPTE specifications.  We don‹t use the NTSC chromaticities and white point because present day monitors don‹t use them and must be 'matrixed' to approximate them.
  1698.  
  1699. As an example, the primary color chromaticities used by the Sony Trinatron differ from those recommended by SMPTE.  In general, since real monitors vary from the industry standards, the chromaticities of primaries are described in the CIE xyY system.  This allows a reproduction system to compensate for the differences.
  1700.  
  1701.  
  1702. VII. Color Response Curves
  1703.  
  1704. This tag defines three color response curves, one each for red, green, and blue color information.  The width of each entry is 16 bits, as implied by the type SHORT.  The minimum intensity is represented by 0 and the maximum by 65535.  For example, black is represented by 0,0,0 and white by 65535, 65535, 65535.  The length of each curve is 2**BitsPerSample.  A ColorResponseCurves field for RGB data where each of the samples is 8 bits deep would have 3*256 entries.  The 256 red entries would come first, followed by 256 green entries, followed by 256 blue entries.
  1705.  
  1706. The purpose of the ColorResponseCurves field is to act as a lookup table mapping sample values to specific intensity values, so that an image created on one system can be displayed on another with minimal loss of color fidelity.  The ColorResponseCurves field thus describes the 'gamma' of an image, so that a TIFF reader on another system can compensate for both the image gamma and the gamma of the reading system.
  1707.  
  1708. Gamma is a term that relates to the typically nonlinear response of most display devices, including monitors.  In most display systems, the voltage applied to the CRT is directly proportional to the value of the red, green, or blue sample.  However, the resulting luminance emitted by the phosphor is not directly proportional to the voltage.  This relationship is approximated in most displays by
  1709.  
  1710.         luminance = voltage ** gamma
  1711.  
  1712. The NTSC standard gamma of 2.2 adequately describes most common video systems. The standard gamma of 2.2 implies a dim viewing surround.  (We know of no SMPTE recommended practice for gamma.)  The following example uses an 8 bit sample with value of 127.
  1713.  
  1714.         voltage = 127 / 255 = 0.4980
  1715.         luminance = 0.4980 ** 2.2 = 0.2157
  1716.  
  1717. In the examples below, we only consider a single primary and therefore only a single curve.  The same analysis applies to each of the red, green, and blue primaries and curves.  Also, and without loss of generality, we assume that there is no hardware color map, so that we must alter the pixel values themselves.  If there is a color map, the manipulations can be done on the map instead of on the pixels.
  1718.  
  1719. If no ColorResponseCurves field exists in a color image, the reader should assume a gamma of 2.2 for each of the primaries.  This default curve can be generated with the following C code:
  1720.  
  1721.         ValuesPerSample = 1 << BitsPerSample;
  1722.         for (curve[0] = 0, i = 1; i < ValuesPerSample; i++)
  1723.                 curve[i] = floor (pow (i / (ValuesPerSample - 1.0), 2.2) * 65535.0 + .5);
  1724.  
  1725. The displaying or rendering application can know its own gamma, which we will call the 'destination gamma.'  (An uncalibrated system can usually assume that its gamma is 2.2 without going too far wrong.)  Using this information the application can compensate for the gamma of the image, as we shall see below.
  1726.  
  1727. If the source and destination systems are both adequately described by a gamma of 2.2, the writer would omit the ColorResponseCurves field, and the reader can simply read the image directly into the frame buffer.  If a writer writes out the ColorResponseCurves field, then a reader must assume that the gammas differ.  A reader must then perform the following computation on each sample in the image:
  1728.  
  1729.         NewSampleValue = floor (pow (curve[OldSampleValue] / 65535.0, 1.0 / DestinationGamma) * 
  1730.           (ValuesPerSample - 1.0) + .5);
  1731.  
  1732. Of course, if the 'gamma' of the destination system is not well-approximated with an exponential function, an arbitrary table lookup may be used in place of raising the value to 1.0 / DestinationGamma.
  1733.  
  1734. Leave out ColorResponseCurves if using the default gamma.  This saves about 1.5K in the most common case, and, after all, omission is the better part of compression.
  1735.  
  1736. Do not use this field to store frame buffer color maps.  Use instead the ColorMap field.  Note, however, that ColorResponseCurves may be used to refine the information in a ColorMap if desired.
  1737.  
  1738. The above examples assume that a single parameter gamma system adequately approximates the response characteristics of the image source and destination systems.  This will usually be true, but our use of a table instead of a single gamma parameter gives the flexibility to describe more complex relationships, without requiring additional computation or complexity.
  1739.  
  1740.  
  1741. VIII. New Tags and Changes
  1742. The following tags should be placed in the "Basic Fields" section of
  1743. the TIFF specification:
  1744.  
  1745. White Point
  1746. Tag     = 318 (13E)
  1747. Type    = RATIONAL
  1748. N       = 2
  1749.  
  1750. The white point of the image.  Note that this value is described using the 1931 CIE xyY chromaticity diagram and only the chromaticity is specified.  The luminance component is arbitrary and not specified.  This can correspond to the white point of a monitor that the image was painted on, the filter set/light source combination of a scanner, or to the white point of the illumination model of a rendering package.
  1751.  
  1752. Default is the SMPTE white point, D65:  x = 0.313, y = 0.329.
  1753.  
  1754. The ordering is x, y.
  1755.  
  1756.  
  1757. PrimaryChromaticities
  1758. Tag     = 319 (13F)
  1759. Type    = RATIONAL
  1760. N       = 6
  1761.  
  1762. The primary color chromaticities.  Note that these values are described using the 1931 CIE xyY chromaticity diagram and only the chromaticities are specified.  For paint images, these represent the chromaticities of the monitor and for scanned images they are derived from the filter set/light source combination of a scanner.
  1763.  
  1764. Default is the SMPTE primary color chromaticities:
  1765.  
  1766.         Red:    x = 0.635       y = 0.340
  1767.         Green:  x = 0.305       y = 0.595
  1768.         Blue:   x = 0.155       y = 0.070
  1769.  
  1770. The ordering is red x, red y, green x, green y, blue x, blue y.
  1771.  
  1772. Color Response Curves
  1773.  
  1774. Default for ColorResponseCurves represents curves corresponding to the NTSC standard gamma of 2.2.
  1775.  
  1776.  
  1777. IX. Defaults
  1778.  
  1779. The defaults used by TIFF reflect industry standards.  Both the WhitePoint and PrimaryChromaticities tags have defaults that are promoted by SMPTE .  In addition, the default for the ColorResponseCurves tag matches the NTSC specification of a gamma of 2.2.
  1780.  
  1781. The purpose of these defaults is to allow reasonable results in the absence of accurate colorimetry data.  An uncalibrated scanner or paint system produces an image that be displayed identically, though probably incorrectly on two different but calibrated systems.  This is better then the uncertain situation where the image might be rendered differently on two different but calibrated systems.
  1782.  
  1783.  
  1784. X. Limitations and Issues
  1785.  
  1786. This section discusses several of the limitations and issues involved in colorimetric reproduction.
  1787.  
  1788. Scope of Usefulness
  1789.  
  1790. For many purposes the data recommended here is unnecessary and can be omitted.  For presentation graphics where there are only a few colors, being able to tell red from green is probably good enough.  In this case the tags can be ignored and there is no overhead.  In more demanding color reproduction environments, this data allows images to be described device independently and at small cost.
  1791.  
  1792. User Burdens
  1793.  
  1794. The data we recommend isn‹t a user burden; it is really a systems issue.  It allows a systems solution but doesn‹t require user intercession.  Calibration however is a separate issue.  It is likely to involve the user.
  1795.  
  1796. Resolution Versus Fidelity
  1797.  
  1798. Some manufacturers supply greater than 24 bits of resolution for color specification.  The purpose of this is either to avoid artifacts such as contouring in the shadows or in some cases to be more specific or device independent about the color.  Both reasons can be misguided.  Other, less expensive techniques can be used to prevent artifacts, such as deeper color maps.  As for accuracy, fidelity is more important than precision.
  1799.  
  1800. Colorimetric Color Reproduction
  1801.  
  1802. There are other choices for objectives of color reproduction [9].  Spectral color reproduction is a stronger condition and most are weaker, such as preferred color reproduction.  While device independent spectral color reproduction is impossible, device independent colorimetric reproduction is possible, within a tolerance and within the limits of the gamuts of the devices.  By choosing a strong criteria we allow the important objectives of weaker criteria, such as preferred color reproduction, to be part of design packages.
  1803.  
  1804. Metamerism
  1805.  
  1806. If two patches of color are identical under one light and different under another, they are said to be metameric pairs.  Colorimetric color reproduction is a weaker condition than spectral color reproduction and hence allows metamerism problems.  By standardizing the viewing conditions we can largely finesse the metamerism problem for print.  Because television is self-luminous and doesn‹t use spectral absorption, metamerism isn‹t so much a problem.
  1807.  
  1808. Color Models - xyY Versus Luv, etc.
  1809.  
  1810. We choose xyY over Luv [1] because XYZ is the international standard for color specification and xyY is the chromaticity diagram associated with XYZ.  Luv is meant for color difference measurement.
  1811.  
  1812. Ambient Environment And Viewing Surrounds
  1813.  
  1814. The viewing environment affects how the eye perceives color.  The eye adapts to a dark room and it adapts to a colored surround.  While these problems can be compensated for within the colorimetric framework [4], it is much better to finesse them by standardizing.  The design environment should match the intended viewing environment.  Specifically it should not be a pitch dark room and, on average, it should be of a neutral color.  For print, ANSI recommends a Munsell N-8 surface [8].
  1815.  
  1816.  
  1817. XI. References
  1818.  
  1819. In particular, we would like to mention the work of Stuart Ring of the Copy Products Division of the Eastman Kodak Company.  He and his colleagues are promoting a color data interchange paradigm.  They are working closely with the ISO 8613 Working Group [7].
  1820.  
  1821. [1]     Color Data Interchange Paradigm, Eastman Kodak, Rochester, New York, 7 December 1987.
  1822.  
  1823. [2]     Color Reproduction and Illumination Models, Roy Hall, International Summer Institute:  State of the Art in Computer Graphics, 1986.
  1824.  
  1825. [3]     CIE Colorimetry: Official Recommendations of the International Commission on Illumination, Publication 15-2, 1986.
  1826.  
  1827. [4]     Color Science: Concepts and Methods, Quantitative Data and Formulae, Gunter Wyszecki, W.S. Stiles, John Wiley and Sons, Inc., New York, New York, 1982.
  1828.  
  1829. [5]     Color Monitor Colorimetry, SMPTE Recommended Practice RP 145-1987.
  1830.  
  1831. [6]     Color Temperature for Color Television Studio Monitors, SMPTE Recommended Practice RP 37.
  1832.  
  1833. [7]     Office Document Architecture (ODA) and Interchange Format'Addendum on Colour, ISO 8613 Working Draft.
  1834.  
  1835. [8]     ANSI Standard PH 2.30-1985.
  1836.  
  1837. [9]     The Reproduction of Colour in Photography, Printing and Television, R. W. G. Hunt, Fountain Press, Tolworth, England, 1987.
  1838.  
  1839. [10]    Raster Graphics Handbook, The Conrac Corporation, Van Nostrand Reinhold Company, New York, New York, 1985.  Good description of gamma.
  1840.  
  1841.  
  1842.  
  1843. Appendix I:  Horizontal Differencing Predictor
  1844.  
  1845.  
  1846. This appendix, written after the release of Revision 5.0 of the TIFF specification, is still in draft form.  Please send any comments to the Aldus Developers Desk.
  1847.  
  1848.  
  1849. Revision 5.0 of the TIFF specification defined a new tag called 'Predictor' that describes techniques that may be used in conjuction with TIFF compression schemes.  We now define a Predictor that greatly improves compression ratios for some images.
  1850.  
  1851. The horizontal differencing predictor is assigned the tag value Predictor = 2:
  1852.  
  1853. Predictor
  1854. Tag     = 317 (13D)
  1855. Type    = SHORT
  1856. N       = 1
  1857.  
  1858. A predictor a mathematical operator that is applied to the image data before the encoding scheme is applied.  Currently (as of revision 5.0) this tag is used only with LZW (Compression=5) encoding, since LZW is probably the only TIFF encoding scheme that benefits significantly from a predictor step.  See Appendix F.
  1859.  
  1860. 1 = No prediction scheme used before coding.
  1861. 2 = Horizontal differencing. See Appendix I.
  1862.  
  1863. Default is 1.
  1864.  
  1865.  
  1866. The algorithm
  1867.  
  1868. The idea is to make use of the fact that many continuous tone images rarely vary much in pixel value from one pixel to the next.  In such images, if we replace the pixel values by differences between consecutive pixels, many of the differences should be 0, plus or minus 1, and so on.  This reduces the apparent information content, and thus allows LZW to encode the data more compactly.
  1869.  
  1870. Assuming 8-bit grayscale pixels for the moment, a basic C implementation might look something like this:
  1871.  
  1872.         char    image[ ][ ];
  1873.         int     row, col;
  1874.  
  1875.         /* take horizontal differences:
  1876.          */
  1877.         for (row = 0; row < nrows; row++)
  1878.                 for (col = ncols - 1; col >= 1; col--)
  1879.                         image[row][col] -= image[row][col-1];
  1880.  
  1881. If we don't have 8-bit samples, we need to work a little harder, so that we can make better use of the architecture of most CPUs.  Suppose we have 4-bit samples, packed two to a byte, in normal TIFF uncompressed (i.e., Compression=1) fashion.  In order to find differences, we want to first expand each 4-bit sample into an 8-bit byte, so that we have one sample per byte, low-order justified.  We then perform the above horizontal differencing.  Once the differencing has been completed, we then repack the 4-bit differences two to a byte, in normal TIFF uncompressed fashion.
  1882.  
  1883. If the samples are greater than 8 bits deep, expanding the samples into 16-bit words instead of 8-bit bytes seems like the best way to perform the subtraction on most computers.
  1884.  
  1885. Note that we have not lost any data up to this point, nor will we lose any data later on.  It might at first seem that our differencing might turn 8-bit samples into 9-bit differences, 4-bit samples into 5-bit differences, and so on.  But it turns out that we can completely ignore the 'overflow' bits caused by subtracting a larger number from a smaller number and still reverse the process without error.  Normal twos complement arithmetic does just what we want.  Try an example by hand if you need more convincing.
  1886.  
  1887. Up to this point we have implicitly assumed that we are compressing bilevel or grayscale images.  An additional consideration arises in the case of color images.
  1888.  
  1889. If PlanarConfiguration is 2, there is no problem.  Differencing proceeds the same way as it would for grayscale data.
  1890.  
  1891. If PlanarConfiguration is 1, however, things get a little trickier.  If we didn‹t do anything special, we would be subtracting red sample values from green sample values, green sample values from blue sample values, and blue sample values from red sample values, which would not give the LZW coding stage much redundancy to work with.  So we will do our horizontal differences with an offset of SamplesPerPixel (3, in the RGB case).  In other words, we will subtract red from red, green from green, and blue from blue.  The LZW coding stage is identical to the SamplesPerPixel=1 case.  We require that BitsPerSample be the same for all 3 samples.
  1892.  
  1893.  
  1894. Results and guidelines
  1895.  
  1896. LZW without differencing works well for 1-bit images, 4-bit grayscale images, and synthetic color images.  But natural 24-bit color images and some 8-bit grayscale images do much better with differencing.  For example, our 24-bit natural test images hardly compressed at all using 'plain' LZW: the average compression ratio was 1.04 to 1.  The average compression ratio with horizontal differencing was 1.40 to 1.  (A compression ratio of 1.40 to 1 means that if the uncompressed image is 1.40MB in size, the compressed version is 1MB in size.)
  1897.  
  1898. Although the combination of LZW coding with horizontal differencing does not result in any loss of data, it may be worthwhile in some situations to give up some information by removing as much noise as possible from the image data before doing the differencing, especially with 8-bit samples.  The simplest way to get rid of noise is to mask off one or two low-order bits of each 8-bit sample.  On our 24-bit test images, LZW with horizontal differencing yielded an average compression ratio of 1.4 to 1.  When the low-order bit was masked from each sample, the compression ratio climbed to 1.8 to 1; the compression ratio was 2.4 to 1 when masking two bits, and 3.4 to 1 when masking three bits.  Of course, the more you mask, the more you risk losing useful information along with the noise.  We encourage you to experiment to find the best compromise for your device.  For some applications it may be useful to let the user make the final decision.
  1899.  
  1900. Interestingly, most of our RGB images compressed slightly better using PlanarConfiguration=1.  One might think that compressing the red, green, and blue difference planes separately (PlanarConfiguration=2) might give better compression results than mixing the differences together before compressing (PlanarConfiguration=1), but this does not appear to be the case.
  1901.  
  1902. Incidentally, we tried taking both horizontal and vertical differences, but the extra complexity of two-dimensional differencing did not appear to pay off for most of our test images.  About one third of the images compressed slightly better with two-dimensional differencing, about one third compressed slightly worse, and the rest were about the same.
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908. Appendix J:  Palette Color
  1909.  
  1910.  
  1911. This appendix, written after the release of Revision 5.0 of the TIFF specification, is still in draft form.  Please send any comments to the Aldus Developers Desk.
  1912.  
  1913.  
  1914. Revision 5.0 of the TIFF specification defined a new PhotometricInterpretation value called 'palette color.'  We have been wondering lately if this additional complexity is worth the implementation expense.  If not, let's drop it before too many people start creating palette color images.
  1915.  
  1916.  
  1917. The Proposal
  1918.  
  1919. Instead of a separate palette color image type, there seems to be no compelling reason why palette (mapped) color images should not be stored as 'full color' (usually 24-bit) RGB images.
  1920.  
  1921.  
  1922. Objections
  1923.  
  1924. The most obvious objection is the amount of space required.  But if you care about how much space the image takes up on disk, you should use LZW compression, which is ideally suited to most palette color images.  (LZW compresses most paint-type palette color images 5:1 or more.)  And if you use LZW compression, it turns out that palette color images stored as full color images compress to almost exactly the same size as palette color images stored as palette color images.  That is, with LZW compression, there is no penalty for storing palette color images as full color RGB images.  The resulting file may be a few percent larger, but it will not be three times as large.  See Appendix F for more information on how LZW works.
  1925.  
  1926. Another objection might be that an application might want to process the image differently if it is 'really' a palette color image. But we can easily add auxiliary information that can help a TIFF reader to quickly categorize color images if it wants to.  See the 'New tags' section below.
  1927.  
  1928.  
  1929. Benefits
  1930.  
  1931. It may be obvious, but it is probably worth discussing why we want to abolish palette color images as a distinct classification.
  1932.  
  1933. The main problem is that palette color as a separate type makes life more hazardous and confusing for users.  The confusion factor is aggravated because users already have to be somewhat aware of distinctions between bilevel, grayscale, and color images.  Having two main types of color images is hard for many users to grasp, and it is probably not possible to totally hide this complexity from the user in certain situations.  The hazard level goes up because some applications may accept palette color but not full color images, or full color but not palette color images, or may accept 8-bit palette color images but not 4-bit or 3-bit palette color images.
  1934.  
  1935. The second problem is that writing and maintaining code to deal with an additional image type is somewhat expensive for TIFF readers.  The cost of supporting palette color images will depend on the application, but we believe that, in general, the cost will be substantial.  It seems to make more sense to put the burden on TIFF writers to convert palette color images into full color image form than to make TIFF readers handle an additional color image type, since there are more TIFF readers than writers at this point.
  1936.  
  1937.  
  1938. New tags
  1939.  
  1940. Here are some proposed new tags that can help to classify color images, and make up for not having a separate palette color class.  They are not required for TIFF Class R , but are strongly recommended for color TIFF images created by palette-type color paint programs.
  1941.  
  1942. ColorImageType
  1943. Tag     = 318 (13E)
  1944. Type    = SHORT
  1945. N       = 1
  1946.  
  1947. Gives TIFF color image readers a better idea of what kind of color image it is.  There will be borderline cases.
  1948.  
  1949. 1 = Continuous tone, natural image.
  1950. 2 = Synthetic image, using a greatly restricted range of colors.  Such images are produced by most color paint programs.  See ColorList for a list of colors used in this image.
  1951.  
  1952. Default is 1.
  1953.  
  1954. ColorList
  1955. Tag     = 319 (13F)
  1956. Type    = BYTE or SHORT
  1957. N       = the number of colors that are used in this image, times SamplesPerPixel
  1958.  
  1959. A list of colors that are used in this image.  Use of this field is only practical for images containing a greatly restricted (usually less than or equal to 256) range of colors.  ColorImageType should be 2.  See ColorImageType.
  1960.  
  1961. The list is organized as an array of RGB triplets, with no pad.  The RGB triplets are not guaranteed to be in any particular order.  Note that the red, green, and blue components can either be a BYTE or a SHORT in length.  BYTE should be sufficient for most applications.
  1962.  
  1963. No default.
  1964.  
  1965.