home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mskermit / msgtif.txt < prev    next >
Text File  |  2020-01-01  |  133KB  |  3,721 lines

  1. An Aldus/Microsoft Technical Memorandum:  8/8/88    Page 1
  2.  
  3. Preface
  4.  
  5. This memorandum     has been prepared jointly by Aldus and Microsoft
  6. in conjunction    with leading scanner vendors and other interested
  7. parties.   This document  does not  represent a commitment on the
  8. part of     either Microsoft  or Aldus  to provide     support for this
  9. file format  in any  application.   When responding  to     specific
  10. issues raised  in this memo, or when requesting additional tag or
  11. field assignments, please address your correspondence to either:
  12.  
  13.    Developers_ Desk        Windows Marketing Group
  14.    Aldus Corporation        Microsoft Corporation
  15.    411 First Ave. South        16011 NE 36th Way
  16.    Suite 200            Box 97017
  17.    Seattle, WA    98104        Redmond, WA     98073-9717
  18.    (206) 622-5500        (206) 882-8080
  19.  
  20. Revision Notes
  21.  
  22. This revision  replaces _TIFF  Revision 4._   Sections in italics
  23. are new or substantially changed in this revision.  Also new, but
  24. not in italics, are Appendices F, G, and H.
  25.  
  26. The major enhancements in TIFF 5.0 are:
  27.  
  28. 1.   Compression of  grayscale and  color images, for better disk
  29. space utilization.  See Appendix F.
  30.  
  31. 2.   TIFF Classes_restricted  TIFF subsets  that can simplify the
  32. job of    the TIFF  implementor.     You may  wish to scan Appendix G
  33. before reading the rest of this document.   In fact, you may want
  34. to use    Appendix G as your main guide, and refer back to the main
  35. body of     the specification  as needed for details concerning TIFF
  36. structures and field definitions.
  37.  
  38. 3.   Support for  _palette color_   images.  See the TIFF Class P
  39. description  in      Appendix  G,     and  the   new     ColorMap   field
  40. description.
  41.  
  42. 4.   Two new  tags that     can be     used to  more fully  define  the
  43. characteristics of  full color    RGB data, and thereby potentially
  44. improve the quality of color image reproduction.  See Appendix H.
  45.  
  46. The organization  of the  document has also changed slightly.  In
  47. particular, the     tags are  listed in  alphabetical order,  within
  48. several categories, in the main body of the specification.
  49.  
  50. TIFF 5.0                      page 2
  51.  
  52.  
  53. As always,  every attempt  has been  made to add functionality in
  54. such a    way as    to minimize  incompatibility problems  with older
  55. TIFF software.     In  particular, many  TIFF  5.0  files     will  be
  56. readable even  by older     applications that  assume TIFF 4.0 or an
  57. earlier version     of the     specification.      One exception     is  with
  58. files that  use the  new TIFF  5.0 LZW    compression scheme.   Old
  59. applications will  have to  give up  in this case, of course, and
  60. will do so _gracefully_ if they have been following the rules.
  61.  
  62. We  are     grateful  to  all  of    the  draft  reviewers  for  their
  63. suggestions.   Especially helpful  were Herb  Weiner  of  Kitchen
  64. Wisdom    Publishing   Company,  Brad  Pillow  of     TrueVision,  and
  65. engineers from Hewlett Packard and Quark.  Chris Sears of Magenta
  66. Graphics provided information which is included as Appendix H.
  67.  
  68.  
  69. Abstract
  70.  
  71. This document  describes TIFF,    a tag  based file  format that is
  72. designed to promote the interchange of digital image data.
  73.  
  74. The fields  were defined  primarily with  desktop publishing  and
  75. related applications  in mind, although it is possible that other
  76. sorts of imaging applications may find TIFF to be useful.
  77.  
  78. The general  scenario for  which TIFF  was invented  assumes that
  79. applications software  for scanning  or painting  creates a  TIFF
  80. file, which  can then  be read and incorporated into a _document_
  81. or _publication_   by an application such as a desktop publishing
  82. package.
  83.  
  84. TIFF is     not a printer language or page description language, nor
  85. is it intended to be a general document interchange standard. The
  86. primary design    goal was  to provide  a rich  environment  within
  87. which the exchange of image data between application programs can
  88. be accomplished.   This     richness is  required in  order to  take
  89. advantage of  the varying  capabilities of  scanners and  similar
  90. devices.  TIFF is therefore designed to be a superset of existing
  91. image file  formats for     _desktop_   scanners (and paint programs
  92. and anything  else that     produces images with pixels in them) and
  93. will be enhanced on a continuing basis as new capabilities arise.
  94. A high    priority has been given to structuring the data in such a
  95. way as    to minimize  the pain  of future  additions.    TIFF  was
  96. designed to be an extensible interchange format.
  97.  
  98. Although TIFF  is claimed  to be  in some sense a rich format, it
  99. can easily  be used for simple scanners and applications as well,
  100. since the  application developer  need only be concerned with the
  101. capabilities that he requires.
  102.  
  103. TIFF is intended to be independent of specific operating systems,
  104. filing systems,     compilers, and processors.  The only significant
  105. assumption is  that the     storage medium supports something like a
  106. _file,_      defined as  a sequence  of 8-bit bytes, where the bytes
  107.  
  108. TIFF 5.0                      page 3
  109.  
  110.  
  111. are numbered  from 0  to N.   The  largest possible  TIFF file is
  112. 2**32 bytes  in length.      Since TIFF uses pointers (byte offsets)
  113. quite liberally,  a TIFF  file is  most easily read from a random
  114. access device  such as a hard disk or flexible diskette, although
  115. it should  be possible    to read     and write TIFF files on magnetic
  116. tape.
  117.  
  118. The recommended     MS-DOS, UNIX,    and OS/2  file extension for TIFF
  119. files is  _.TIF._   The recommended Macintosh filetype is _TIFF_.
  120. Suggestions for     conventions in     other computing environments are
  121. welcome.
  122.  
  123.  
  124. 1) Structure
  125.  
  126. In TIFF, individual fields are identified with a unique tag. This
  127. allows particular fields to be present or absent from the file as
  128. required by the application.  For an explanation of the rationale
  129. behind using a tag structure format, see Appendix A.
  130.  
  131. A TIFF file begins with an 8-byte _image file header_ that points
  132. to one    or  more  _image  file    directories._     The  image  file
  133. directories contain  information about    the images,  as     well  as
  134. pointers to the actual image data.
  135.  
  136. See Figure 1.
  137.  
  138. We will now describe these structures in more detail.
  139.  
  140. Image file header
  141.  
  142. A TIFF    file begins  with an 8-byte image file header, containing
  143. the following information:
  144.  
  145. Bytes 0-1:     The first  word of  the file  specifies    the  byte
  146. order used within the file.  Legal values are:
  147.  
  148.     _II_ (hex 4949)
  149.     _MM_ (hex 4D4D)
  150.  
  151.    In the  _II_      format,  byte     order    is  always  from  least
  152. significant to    most significant,  for    both  16-bit  and  32-bit
  153. integers.   In the  _MM_   format, byte order is always from most
  154. significant to    least significant,  for both  16-bit  and  32-bit
  155. integers.   In both  formats, character     strings are  stored into
  156. sequential byte locations.
  157.  
  158.    All    TIFF   readers    should    support     both  byte  orders_see
  159. Appendix G.
  160.  
  161. Bytes 2-3 The second  word of  the  file  is  the  TIFF     _version
  162. number._   This number, 42 (2A in hex), is not to be equated with
  163. the current  Revision of  the TIFF  specification.   In fact, the
  164. TIFF version  number (42)  has never  changed, and probably never
  165.  
  166. TIFF 5.0                      page 4
  167.  
  168.  
  169. will.    If it  ever does,  it means that TIFF has changed in some
  170. way so    radical that  a TIFF  reader should  give up immediately.
  171. The number 42 was chosen for its deep philosophical significance.
  172. It can and should be used as additional verification that this is
  173. indeed a TIFF file.
  174.  
  175.    A TIFF  file does  not have    a real version/revision number.
  176. This was  an explicit,    conscious design  decision.  In many file
  177. formats, fields     take on different meanings depending on a single
  178. version number.      The  problem is that as the file format _ages,_
  179. it becomes  increasingly difficult  to document which fields mean
  180. what in     a given  version, and older software usually has to give
  181. up if  it encounters  a file  with a  newer version  number.   We
  182. wanted TIFF  fields to have a permanent and well-defined meaning,
  183. so that     _older_ software  can usually    read _newer_  TIFF files.
  184. The bottom line is lower software release costs and more reliable
  185. software.
  186.  
  187. Bytes 4-7 This long  word contains  the offset    (in bytes) of the
  188. first Image File Directory.  The directory may be at any location
  189. in the    file after  the header but must begin on a word boundary.
  190. In particular,    an Image File Directory may follow the image data
  191. it describes.    Readers must simply follow the pointers, wherever
  192. they may lead.
  193.  
  194.    (The term  _byte offset_  is always used in this document to
  195. refer to  a location  with respect  to the beginning of the file.
  196. The first byte of the file has an offset of 0.)
  197.  
  198.  
  199. Image file directory
  200.  
  201. An Image  File Directory  (IFD) consists of a 2-byte count of the
  202. number of  entries (i.e.,  the number  of fields),  followed by a
  203. sequence of 12-byte field entries, followed by a 4-byte offset of
  204. the next  Image File  Directory (or 0 if none).     Do not forget to
  205. write the 4 bytes of 0 after the last IFD.
  206.  
  207. Each 12-byte IFD entry has the following format:
  208.  
  209. Bytes 0-1 contain the Tag for the field.
  210. Bytes 2-3 contain the field Type.
  211. Bytes 4-7 contain the  Length (_Count_    might have  been a better
  212. term) of the field.
  213. Bytes 8-11     contain the  Value Offset,  the    file  offset  (in
  214. bytes) of  the Value  for the  field.    The Value  is expected to
  215. begin on  a word  boundary; the     corresponding Value  Offset will
  216. thus be     an even  number.  This file offset may point to anywhere
  217. in the file, including after the image data.
  218.  
  219. The entries  in an  IFD must be sorted in ascending order by Tag.
  220. Note that this is not the order in which the fields are described
  221. in this     document.   For a  numerically ordered list of tags, see
  222.  
  223. TIFF 5.0                      page 5
  224.  
  225.  
  226. Appendix E.  The Values to which directory entries point need not
  227. be in any particular order in the file.
  228.  
  229. In order  to save time and space, the Value Offset is interpreted
  230. to contain  the Value  instead of  pointing to    the Value  if the
  231. Value fits  into 4  bytes.  If the Value is less than 4 bytes, it
  232. is left-justified within the 4-byte Value Offset, i.e., stored in
  233. the lower-numbered bytes.  Whether or not the Value fits within 4
  234. bytes is  determined by     looking at  the Type  and Length  of the
  235. field.
  236.  
  237. The Length  is specified in terms of the data type, not the total
  238. number of bytes.  A single 16-bit word (SHORT) has a Length of 1,
  239. not 2,    for example.   The  data  types     and  their  lengths  are
  240. described below:
  241.  
  242. 1 = BYTE  An 8-bit unsigned integer.
  243. 2 = ASCII 8-bit bytes  that store ASCII codes; the last byte must
  244. be null.
  245. 3 = SHORT A 16-bit (2-byte) unsigned integer.
  246. 4 = LONG  A 32-bit (4-byte) unsigned integer.
  247. 5 = RATIONAL   Two LONG_s:  the first represents the numerator of
  248. a fraction, the second the denominator.
  249.  
  250. The value of the Length part of an ASCII field entry includes the
  251. null.    If padding  is necessary, the Length does not include the
  252. pad byte.   Note  that there  is no  _count byte,_ as there is in
  253. Pascal-type strings.   The Length part of the field takes care of
  254. that.    The null  is not  strictly necessary, but may make things
  255. slightly simpler for C programmers.
  256.  
  257. The reader  should check  the type  to ensure  that it is what he
  258. expects.   TIFF currently  allows more than 1 valid type for some
  259. fields.      For example,    ImageWidth and ImageLength were specified
  260. as having  type SHORT.    Very large images with more than 64K rows
  261. or columns  are possible with some devices even now.  Rather than
  262. add parallel  LONG tags     for these fields, it is cleaner to allow
  263. both SHORT  and LONG  for ImageWidth  and similar  fields.    See
  264. Appendix G for specific recommendations.
  265.  
  266. Note that  there may  be more  than one IFD.  Each IFD is said to
  267. define a _subfile._   One potential use of subsequent subfiles is
  268. to describe  a _sub-image_   that  is somehow related to the main
  269. image, such as a reduced resolution version of the image.
  270.  
  271. If you have not already done so, you may wish to turn to Appendix
  272. G to study the sample TIFF images.
  273.  
  274.  
  275. 2) Definitions
  276.  
  277. Note that the TIFF structure as described in the previous section
  278. is not    specific to  imaging applications in any way.  It is only
  279.  
  280. TIFF 5.0                      page 6
  281.  
  282.  
  283. the definitions of the fields themselves that jointly describe an
  284. image.
  285.  
  286. Before we  begin defining  the fields,    we will define some basic
  287. concepts.   An image  is defined  to be     a rectangular    array  of
  288. _pixels,_  each of which consists of one or more _samples._  With
  289. monochromatic data,  we have  one sample  per pixel, and _sample_
  290. and _pixel_   can  be  used  interchangeably.     RGB  color  data
  291. contains three samples per pixel.
  292.  
  293.  
  294. 3) The Fields
  295.  
  296. This section  describes the  fields defined  in this  version  of
  297. TIFF.    More fields  may be  added in future versions_if possible
  298. they will  be added in such a way so as not to break old software
  299. that encounters a newer TIFF file.
  300.  
  301. The documentation  for each  field contains the name of the field
  302. (quite arbitrary, but convenient), the Tag value, the field Type,
  303. the Number of Values (N) expected, comments describing the field,
  304. and the     default, if  any.  Readers must assume the default value
  305. if the field does not exist.
  306.  
  307. _No default_  does not    mean that  a TIFF  writer should  not pay
  308. attention to  the tag.    It simply means that there is no default.
  309. If the    writer has reason to believe that readers will care about
  310. the value  of this  field, the writer should write the field with
  311. the appropriate value.    TIFF readers can do whatever they want if
  312. they encounter a missing _no default_ field that they care about,
  313. short of  refusing to  import the file.     For example, if a writer
  314. does  not  write  out  a  PhotometricInterpretation  field,  some
  315. applications will  interpret the  image _correctly,_  and  others
  316. will display  the image     inverted.  This is not a good situation,
  317. and writers should be careful not to let it happen.
  318.  
  319. The  fields   are  grouped   into  several  categories:       basic,
  320. informational, facsimile,  document storage and retrieval, and no
  321. longer recommended.   A     future version     of the specification may
  322. pull some of these categories into separate companion documents.
  323.  
  324. Many fields  are described  in this  document, but  most are  not
  325. _required._   See Appendix  G for  a list  of required fields, as
  326. well as     examples of  how to combine fields into valid and useful
  327. TIFF files.
  328. Basic Fields
  329.  
  330.  
  331. Basic fields  are  fields  that     are  fundamental  to  the  pixel
  332. architecture or visual characteristics of an image.
  333.  
  334. BitsPerSample
  335. Tag  = 258  (102)
  336. Type = SHORT
  337.  
  338. TIFF 5.0                      page 7
  339.  
  340.  
  341. N    = SamplesPerPixel
  342.  
  343. Number of bits per sample.  Note that this tag allows a different
  344. number of  bits per  sample for     each sample  corresponding to    a
  345. pixel.     For example, RGB color data could use a different number
  346. of bits     per sample for each of the three color planes.     Most RGB
  347. files will have the same number of BitsPerSample for each sample.
  348. Even in this case, be sure to include all three entries.  Writing
  349. _8_ when you mean _8,8,8_ sets a bad precedent for other fields.
  350.  
  351. Default = 1.  See also SamplesPerPixel.
  352.  
  353.  
  354. ColorMap
  355. Tag  = 320 (140)
  356. Type = SHORT
  357. N    = 3 * (2**BitsPerSample)
  358.  
  359. This tag  defines a  Red-Green-Blue color  map for  palette color
  360. images.      The palette color pixel value is used to index into all
  361. 3 subcurves.   For  example, a Palette color pixel having a value
  362. of 0  would be    displayed according  to the 0th entry of the Red,
  363. Green, and Blue subcurves.
  364.  
  365. The subcurves  are stored  sequentially.   The Red  entries  come
  366. first, followed     by the     Green    entries,  followed  by    the  Blue
  367. entries.   The length  of each    subcurve is  2**BitsPerSample.    A
  368. ColorMap entry    for an    8-bit Palette color image would therefore
  369. have 3    * 256  entries.      The width  of each entry is 16 bits, as
  370. implied     by  the  type    of  SHORT.    0     represents  the  minimum
  371. intensity, and    65535 represents the maximum intensity.     Black is
  372. represented by    0,0,0, and  white by  65535, 65535,  65535.   The
  373. purpose of  the color  map is to act as a _lookup_  table mapping
  374. pixel values from 0 to 2**BitsPerSample-1 into RGB triplets.
  375.  
  376. The ColorResponseCurves     field may  be used  in conjunction  with
  377. ColorMap to further refine the meaning of the RGB triplets in the
  378. ColorMap.   However, the  ColorResponseCurves default  should  be
  379. sufficient in most cases.
  380.  
  381. See also PhotometricInterpretation_palette color.
  382.  
  383. No default.   ColorMap    must be     included in  all  palette  color
  384. images.
  385.  
  386.  
  387. ColorResponseCurves
  388. Tag  = 301 (12D)
  389. Type = SHORT
  390. N    = 3 * (2**BitsPerSample)
  391.  
  392. This tag  defines three     color response curves, one each for Red,
  393. Green and  Blue color  information.   The Red entries come first,
  394. followed by the Green entries, followed by the Blue entries.  The
  395.  
  396. TIFF 5.0                      page 8
  397.  
  398.  
  399. length    of   each  subcurve   is  2**BitsPerSample,   using   the
  400. BitsPerSample value corresponding to the respective primary.  The
  401. width of  each entry is 16 bits, as implied by the type of SHORT.
  402. 0 represents  the minimum  intensity, and  65535  represents  the
  403. maximum intensity.   Black  is represented by 0,0,0, and white by
  404. 65535, 65535,  65535.    Therefore, a ColorResponseCurve entry for
  405. RGB data  where each of the samples is 8 bits deep would have 3 *
  406. 256 entries, each consisting of a SHORT.
  407.  
  408. The purpose of the color response curves is to refine the content
  409. of RGB color images.
  410.  
  411. See Appendix H, section VII, for further information.
  412.  
  413. Default:  curves based on the NTSC recommended gamma of 2.2.
  414.  
  415.  
  416. Compression
  417. Tag  = 259  (103)
  418. Type = SHORT
  419. N    = 1
  420.  
  421. 1 =  No compression,  but pack    data into  bytes  as  tightly  as
  422. possible, with    no unused  bits except    at the end of a row.  The
  423. bytes are  stored as  an array of type BYTE, for BitsPerSample <=
  424. 8,  SHORT   if    BitsPerSample    >  8  and  <=  16,  and     LONG  if
  425. BitsPerSample >     16 and <= 32.    The byte ordering of data >8 bits
  426. must be     consistent with  that specified  in the TIFF file header
  427. (bytes 0  and 1).   _II_    format  files  will     have  the  least
  428. significant bytes  preceeding the  most significant  bytes  while
  429. _MM_  format files will have the opposite.
  430.  
  431.    If the  number of  bits per    sample is not a power of 2, and
  432. you are willing to give up some space for better performance, you
  433. may wish to use the next higher power of 2.  For example, if your
  434. data can  be represented  in 6 bits, you may wish to specify that
  435. it is 8 bits deep.
  436.  
  437.    Rows are  required to  begin on byte boundaries.  The number
  438. of bytes  per row  is therefore     (ImageWidth *    SamplesPerPixel *
  439. BitsPerSample  +   7)  /  8,  assuming    integer     arithmetic,  for
  440. PlanarConfiguration=1.       Bytes  per    row  is      (ImageWidth    *
  441. BitsPerSample + 7) / 8 for PlanarConfiguration=2.
  442.  
  443.    Some graphics  systems want rows to be word- or double-word-
  444. aligned.   Uncompressed TIFF  rows will     need to  be copied  into
  445. word- or  double-word-padded row  buffers before  being passed to
  446. the graphics routines in these environments.
  447.  
  448. 2 =  CCITT Group  3 1-Dimensional  Modified  Huffman  run  length
  449. encoding.   See Appendix  B:   _Data Compression  --  Scheme  2._
  450. BitsPerSample must  be 1,  since  this    type  of  compression  is
  451. defined only for bilevel images.
  452.  
  453. TIFF 5.0                      page 9
  454.  
  455.  
  456.    When     you  decompress  data    that  has  been     compressed  by
  457. Compression=2, you  must translate  white runs into 0_s and black
  458. runs into  1_s.      Therefore, the normal PhotometricInterpretation
  459. for those  compression types  is 0  (WhiteIsZero).   If a  reader
  460. encounters a  PhotometricInterpretation of  1  (BlackIsZero)  for
  461. such an     image, the  image should  be displayed     and printed with
  462. black and white reversed.
  463.  
  464. 5 = LZW Compression,  for grayscale, mapped color, and full color
  465. images.     See Appendix F.
  466.  
  467. 32773 =     PackBits compression,    a simple byte oriented run length
  468. scheme for 1-bit images.  See Appendix C.
  469.  
  470. Data compression only applies to raster image data, as pointed to
  471. by StripOffsets.  All other TIFF information is unaffected.
  472.  
  473. Default = 1.
  474.  
  475.  
  476. GrayResponseCurve
  477. Tag  = 291 (123)
  478. Type = SHORT
  479. N    = 2**BitsPerSample
  480.  
  481. The purpose  of the  gray response curve and the gray units is to
  482. provide more  exact photometric     interpretation     information  for
  483. gray scale image data, in terms of optical density.
  484.  
  485. The  GrayScaleResponseUnits   specifies     the   accuracy     of   the
  486. information contained  in the  curve.    Since optical  density is
  487. specified in  terms of    fractional numbers, this tag is necessary
  488. to know     how to     interpret the    stored integer    information.  For
  489. example, if  GrayScaleResponseUnits is    set to 4 (ten-thousandths
  490. of a  unit), and a GrayScaleResponseCurve number for gray level 4
  491. is 3455,  then the  resulting actual  value is    0.3455.      Optical
  492. densitometers typically measure densities within the range of 0.0
  493. to 2.0.
  494.  
  495. If the    gray scale  response curve  is known  for the data in the
  496. TIFF file, and if the gray scale response of the output device is
  497. known, then  an intelligent  conversion can  be made  between the
  498. input data and the output device.  For example, the output can be
  499. made to     look just  like the  input.   In addition,  if the input
  500. image lacks  contrast (as  can be  seen from the response curve),
  501. then appropriate contrast enhancements can be made.
  502.  
  503. The purpose  of the  gray scale     response curve     is to    act as    a
  504. _lookup_   table mapping values from 0 to 2**BitsPerSample-1 into
  505. specific   density    values.       The     0th   element     of   the
  506. GrayResponseCurve array     is used to define the gray value for all
  507. pixels    having     a  value   of    0,   the  1st    element     of   the
  508. GrayResponseCurve array     is used to define the gray value for all
  509. pixels having  a value of 1, and so on, up to 2**BitsPerSample-1.
  510.  
  511. TIFF 5.0                      page 10
  512.  
  513.  
  514. If your     data is  _really,_ say, 7-bit data, but you are adding a
  515. 1-bit pad  to each  pixel to  turn it into 8-bit data, everything
  516. still works:   If  the data is high-order justified, half of your
  517. GrayResponseCurve entries  (the odd ones, probably) will never be
  518. used, but  that doesn_t     hurt anything.     If the data is low-order
  519. justified, your     pixel values  will be between 0 and 127, so make
  520. your GrayResponseCurve    accordingly.   What your  curve does from
  521. 128 to    255 doesnÆt matter.    Note that low-order justification is
  522. probably not  a good  idea, however,  since not     all applications
  523. look at GrayResponseCurve.  Note also that LZW compression yields
  524. the same  compression ratio  regardless of  whether the     data  is
  525. high-order or low-order justified.
  526.  
  527. It is  permissable to  have a  GrayResponseCurve even for bilevel
  528. (1-bit) images.      The  GrayResponseCurve will  have 2 values.  It
  529. should be noted, however, that TIFF B readers are not required to
  530. pay attention  to  GrayResponseCurves  in  TIFF     B  files.    See
  531. Appendix G.
  532.  
  533. If both     GrayResponseCurve and    PhotometricInterpretation  fields
  534. exist  in   the     IFD,    GrayResponseCurve  values   override  the
  535. PhotometricInterpretation value.   But it is a good idea to write
  536. out both, since some applications do not yet pay attention to the
  537. GrayResponseCurve.
  538.  
  539. Writers may  wish to  purchase a  Kodak Reflection Density Guide,
  540. catalog number    146 5947,  available for  $10 or  so at     prepress
  541. supply houses,    to help them figure out reasonable density values
  542. for their scanner or frame grabber.  If that sounds like too much
  543. work,    we    recommend      a    curve   that    is    linear    in
  544. intensity/reflectance.    To compute reflectance from density:  R =
  545. 1 /  pow(10,D).      To compute  density from reflectance: D = log10
  546. (1/R).     A typical  4-bit GrayResponseCurve  may  look    therefore
  547. something like:      2000,     1177, 875, 699, 574, 477, 398, 331, 273,
  548. 222, 176,  135, 97, 62, 30, 0, assuming GrayResponseUnit=3.  Such
  549. a curve would be consistent with PhotometricInterpretation=1.
  550.  
  551. See also GrayResponseUnit, PhotometricInterpretation, ColorMap.
  552.  
  553.  
  554. GrayResponseUnit
  555. Tag  = 290 (122)
  556. Type = SHORT
  557. N    = 1
  558.  
  559. 1 = Number represents tenths of a unit.
  560. 2 = Number represents hundredths of a unit.
  561. 3 = Number represents thousandths of a unit.
  562. 4 = Number represents ten-thousandths of a unit.
  563. 5 = Number represents hundred-thousandths of a unit.
  564.  
  565. Modifies GrayResponseCurve.
  566.  
  567. See also GrayResponseCurve.
  568.  
  569. TIFF 5.0                      page 11
  570.  
  571.  
  572.  
  573. For historical    reasons, the  default is 2.  However, for greater
  574. accuracy, we recommend using 3.
  575.  
  576.  
  577. ImageLength
  578. Tag  = 257  (101)
  579. Type = SHORT or LONG
  580. N    = 1
  581.  
  582. The image_s  length (height) in pixels (Y: vertical).  The number
  583. of rows     (sometimes described as _scan lines") in the image.  See
  584. also ImageWidth.
  585.  
  586. No default.
  587.  
  588.  
  589. ImageWidth
  590. Tag  = 256  (100)
  591. Type = SHORT or LONG
  592. N    = 1
  593.  
  594. The image_s  width, in    pixels (X:  horizontal).   The number  of
  595. columns in the image.  See also ImageLength.
  596.  
  597. No default.
  598.  
  599.  
  600. NewSubfileType
  601. Tag =  254  (FE)
  602. Type = LONG
  603. N = 1
  604.  
  605. Replaces the  old SubfileType  field, due  to limitations  in the
  606. definition of that field.
  607.  
  608. A general  indication of  the kind  of data  that is contained in
  609. this subfile.    This  field is    made up of a set of 32 flag bits.
  610. Unused bits are expected to be 0.  Bit 0 is the low-order bit.
  611.  
  612. Currently defined values are:
  613.  
  614. Bit 0      is 1    if the    image is  a reduced resolution version of
  615. another image in this TIFF file; else the bit is 0.
  616. Bit 1      is 1    if the    image is  a single  page of  a multi-page
  617. image (see the PageNumber tag description); else the bit is 0.
  618. Bit 2      is 1    if the    image defines  a  transparency    mask  for
  619. another image  in this    TIFF file.  The PhotometricInterpretation
  620. value must be 4, designating a transparency mask.
  621.  
  622. These values  have been     defined as  bit flags    because they  are
  623. pretty much independent of each other.    For example, it be useful
  624. to have     four images  in a  single TIFF     file: a  full resolution
  625. image, a  reduced resolution  image, a    transparency mask for the
  626.  
  627. TIFF 5.0                      page 12
  628.  
  629.  
  630. full resolution     image, and  a transparency  mask for the reduced
  631. resolution image.  Each of the four images would have a different
  632. value for the NewSubfileType field.
  633.  
  634. Default is 0.
  635.  
  636.  
  637. PhotometricInterpretation
  638. Tag  = 262  (106)
  639. Type = SHORT
  640. N    = 1
  641.  
  642. 0 =  For bilevel  and grayscale     images:   0 is     imaged as white.
  643. 2**BitsPerSample-1 is  imaged as  black.    If    GrayResponseCurve
  644. exists,     it   overrides     the   PhotometricInterpretation   value,
  645. although  it  is  safer     to  make  them     match,     since    some  old
  646. applications may still be ignoring GrayResponseCurve. This is the
  647. normal value for Compression=2.
  648.  
  649. 1 =  For bilevel  and grayscale     images:   0 is     imaged as black.
  650. 2**BitsPerSample-1  is    imaged    as  white.  If    GrayResponseCurve
  651. exists,     it   overrides     the   PhotometricInterpretation   value,
  652. although  it  is  safer     to  make  them     match,     since    some  old
  653. applications may  still be  ignoring GrayResponseCurve.     If  this
  654. value is  specified for     Compression=2, the  image should display
  655. and print reversed.
  656.  
  657. 2 = RGB.  In the RGB model, a color is described as a combination
  658. of the    three primary  colors of  light (red, green, and blue) in
  659. particular concentrations.   For  each of  the three  samples,    0
  660. represents minimum intensity, and 2**BitsPerSample - 1 represents
  661. maximum intensity.   Thus  an RGB  value  of  (0,0,0)  represents
  662. black,    and   (255,255,255)  represents      white,  assuming  8-bit
  663. samples.   For PlanarConfiguration = 1, the samples are stored in
  664. the indicated  order:    first Red,  then Green,     then Blue.   For
  665. PlanarConfiguration =  2, the  StripOffsets for the sample planes
  666. are stored  in the  indicated order:   first the Red sample plane
  667. StripOffsets, then  the Green  plane StripOffsets,  then the Blue
  668. plane StripOffsets.
  669.  
  670.    The ColorResponseCurves field may be used to globally refine
  671. or alter  the color  balance of     an RGB     image without    having to
  672. change the values of the pixels themselves.
  673.  
  674. 3="Palette color._     In this    mode, a color is described with a
  675. single sample.     The  sample is     used as  an index into ColorMap.
  676. The sample  is used to index into each of the red, green and blue
  677. curve tables to retrieve an RGB triplet defining an actual color.
  678. When this  PhotometricInterpretation value  is    used,  the  color
  679. response curves     must also  be supplied.  SamplesPerPixel must be
  680. 1.
  681.  
  682. 4 =  Transparency Mask.      This    means that  the image  is used to
  683. define an  irregularly shaped region of another image in the same
  684.  
  685. TIFF 5.0                      page 13
  686.  
  687.  
  688. TIFF  file.    SamplesPerPixel     and  BitsPerSample  must  be  1.
  689. PackBits compression  is recommended.     The  1-bits  define  the
  690. interior of  the region;  the 0-bits  define the  exterior of the
  691. region.     The Transparency Mask must have the same ImageLength and
  692. ImageWidth as the main image.
  693.  
  694.    A reader  application can  use the  mask to    determine which
  695. parts of the image to display.    Main image pixels that correspond
  696. to 1-bits  in the  transparency mask  are imaged to the screen or
  697. printer, but  main image  pixels that correspond to 0-bits in the
  698. mask are not displayed or printed.
  699.  
  700.    It is  possible to  generalize the  notion of a transparency
  701. mask to     include partial  transparency, but  it is not clear that
  702. such information would be useful to a desktop publishing program.
  703.  
  704. No default.   That  means that    if you    care  if  your    image  is
  705. displayed and  printed as  _normal_ vs _inverted,_ you must write
  706. out this  field.   Do not rely on applications defaulting to what
  707. you want!   PhotometricInterpretation  =  1  is     recommended  for
  708. bilevel (except     for Compression=2)  and grayscale images, due to
  709. popular user  interfaces for changing the brightness and contrast
  710. of images.
  711.  
  712.  
  713. PlanarConfiguration
  714. Tag  = 284  (11C)
  715. Type = SHORT
  716. N    = 1
  717.  
  718. 1 =  The sample values for each pixel are stored contiguously, so
  719. that   there    is   a      single   image    plane.          See
  720. PhotometricInterpretation to  determine the  order of the samples
  721. within the  pixel data.      So,  for RGB    data, the  data is stored
  722. RGBRGBRGB...and so on.
  723.  
  724. 2 =  The samples  are stored  in separate  _sample planes._   The
  725. values in StripOffsets and StripByteCounts are then arranged as a
  726. 2-dimensional array, with SamplesPerPixel rows and StripsPerImage
  727. columns.      (All of  the columns  for row  0 are  stored first,
  728. followed   by     the   columns      of   row   1,      and    so   on.)
  729. PhotometricInterpretation describes  the type  of  data     that  is
  730. stored in  each sample    plane.     For example,  RGB data is stored
  731. with the  Red samples  in one sample plane, the Green in another,
  732. and the Blue in another.
  733.  
  734. If SamplesPerPixel  is 1,  PlanarConfiguration is irrelevant, and
  735. should not be included.
  736. Default is 1.  See also BitsPerSample, SamplesPerPixel.
  737.  
  738.  
  739. Predictor
  740. Tag  = 317 (13D)
  741. Type = SHORT
  742.  
  743. TIFF 5.0                      page 14
  744.  
  745.  
  746. N    = 1
  747.  
  748. To be used when Compression=5 (LZW).  See Appendix F.
  749.  
  750. 1 = No prediction scheme used before coding.
  751.  
  752. Default is 1.
  753.  
  754.  
  755. ResolutionUnit
  756. Tag  = 296 (128)
  757. Type = SHORT
  758. N    = 1
  759.  
  760. To be used with XResolution and YResolution.
  761.  
  762. 1 =  No absolute  unit of  measurement.     Used for images that may
  763. have a    non-square  aspect  ratio,  but     no  meaningful     absolute
  764. dimensions.   The drawback  of ResolutionUnit=1 is that different
  765. applications will  import the  image at different sizes.  Even if
  766. the decision  is quite    arbitrary, it might be better to use dots
  767. per inch  or  dots  per     centimeter,  and  pick     XResolution  and
  768. YResolution such that the aspect ratio is correct and the maximum
  769. dimension of  the image is about four inches (the _four_ is quite
  770. arbitrary.)
  771. 2 = Inch.
  772. 3 = Centimeter.
  773.  
  774. Default is 2.  See also XResolution, YResolution.
  775.  
  776.  
  777. RowsPerStrip
  778. Tag  = 278  (116)
  779. Type = SHORT or LONG
  780. N    = 1
  781.  
  782. The number  of rows  per strip.     The image data is organized into
  783. strips for  fast access     to individual    rows  when  the     data  is
  784. compressed_though this    field is  valid even  if the  data is not
  785. compressed.
  786.  
  787. RowsPerStrip and  ImageLength together    tell  us  the  number  of
  788. strips in  the entire  image.    The equation  is StripsPerImage =
  789. (ImageLength + RowsPerStrip - 1) / RowsPerStrip, assuming integer
  790. arithmetic.
  791.  
  792. Note that  either SHORT     or LONG  values can  be used  to specify
  793. RowsPerStrip.    SHORT values  may be  used for    small TIFF files.
  794. It should  be noted,  however, that  earlier  TIFF  specification
  795. revisions required  LONG values     and that  some software  may not
  796. expect SHORT values.  See Appendix G for further recommendations.
  797.  
  798. Default is  2**32 -  1, which  is effectively infinity.     That is,
  799. the entire  image is  one strip.   We  do not  recommend a single
  800.  
  801. TIFF 5.0                      page 15
  802.  
  803.  
  804. strip, however.      Choose  RowsPerStrip such  that each    strip  is
  805. about 8K  bytes, even  if the  data is    not compressed,     since it
  806. makes buffering     simpler for  readers.     The _8K_  part is pretty
  807. arbitrary, but seems to work well.
  808.  
  809. See also ImageLength, StripOffsets, StripByteCounts.
  810.  
  811.  
  812. SamplesPerPixel
  813. Tag  = 277  (115)
  814. Type = SHORT
  815. N    = 1
  816.  
  817. The number  of samples    per pixel.    SamplesPerPixel  is  1  for
  818. bilevel, grayscale, and palette color images.  SamplesPerPixel is
  819. 3 for RGB images.
  820.  
  821. Default = 1.  See also BitsPerSample, PhotometricInterpretation.
  822.  
  823.  
  824. StripByteCounts
  825. Tag  = 279  (117)
  826. Type = SHORT or LONG
  827. N    = StripsPerImage for PlanarConfiguration equal to 1.
  828.    = SamplesPerPixel  * StripsPerImage    for PlanarConfiguration
  829. equal to 2
  830.  
  831. For each strip, the number of bytes in that strip.  The existence
  832. of  this   field  greatly   simplifies    the  chore  of    buffering
  833. compressed data, if the strip size is reasonable.
  834.  
  835. No default.  See also StripOffsets, RowsPerStrip.
  836.  
  837.  
  838. StripOffsets
  839. Tag  = 273  (111)
  840. Type = SHORT or LONG
  841. N    = StripsPerImage for PlanarConfiguration equal to 1.
  842.    = SamplesPerPixel  * StripsPerImage    for PlanarConfiguration
  843. equal to 2
  844.  
  845. For each  strip, the  byte offset  of that  strip.  The offset is
  846. specified with    respect to  the beginning of the TIFF file.  Note
  847. that this  implies that     each strip has a location independent of
  848. the locations  of other     strips.   This feature may be useful for
  849. editing applications.  This field is the only way for a reader to
  850. find the image data, and hence must exist.
  851.  
  852. Note that  either SHORT or LONG values can be used to specify the
  853. strip offsets.     SHORT    values    may be used for small TIFF files.
  854. It should  be noted,  however, that  earlier TIFF  specifications
  855. required LONG strip offsets and that some software may not expect
  856. SHORT values.  See Appendix G for further recommendations.
  857.  
  858. TIFF 5.0                      page 16
  859.  
  860.  
  861. No default.  See also StripByteCounts, RowsPerStrip.
  862.  
  863.  
  864. XResolution
  865. Tag  = 282  (11A)
  866. Type = RATIONAL
  867. N    = 1
  868.  
  869. The number of pixels per ResolutionUnit in the X direction, i.e.,
  870. in the    ImageWidth direction.    It  is, of  course, not mandatory
  871. that the  image be  actually printed  at the size implied by this
  872. parameter.   It is  up to the application to use this information
  873. as it wishes.
  874.  
  875. No default.  See also YResolution, ResolutionUnit.
  876.  
  877.  
  878. YResolution
  879. Tag  = 283  (11B)
  880. Type = RATIONAL
  881. N    = 1
  882.  
  883. The number of pixels per ResolutionUnit in the Y direction, i.e.,
  884. in the ImageLength direction.
  885.  
  886. No default.  See also XResolution, ResolutionUnit.
  887.  
  888.  
  889. Informational Fields
  890.  
  891.  
  892. Informational  fields    are  fields   that  can      provide  useful
  893. information to    a user,     such as where the image came from.  Most
  894. are ASCII  fields.   An application could have some sort of _More
  895. Info..._ dialog box to display such information.
  896.  
  897. Artist
  898. Tag  = 315  (13B)
  899. Type = ASCII
  900.  
  901. Person who created the image.
  902.  
  903. If you need to attach a Copyright notice to an image, this is the
  904. place to  do it.  In fact, you may wish to write out the contents
  905. of the field immediately after the 8-byte TIFF header.    Just make
  906. sure your  IFD and field pointers are set accordingly, and you_re
  907. all set.
  908.  
  909.  
  910. DateTime
  911. Tag  = 306  (132)
  912. Type = ASCII
  913. N    = 20
  914.  
  915. TIFF 5.0                      page 17
  916.  
  917.  
  918. Date and  time of  image creation.   Use  the format  _YYYY:MM:DD
  919. HH:MM:SS_, with hours on a 24-hour clock, and one space character
  920. between the  date and  the time.    The     length     of  the  string,
  921. including the null, is 20 bytes.
  922.  
  923.  
  924. HostComputer
  925. Tag  = 316  (13C)
  926. Type = ASCII
  927.  
  928. _ENIAC_, or whatever.
  929.  
  930. See also Make, Model, Software.
  931.  
  932.  
  933. ImageDescription
  934. Tag  = 270 (10E)
  935. Type = ASCII
  936.  
  937. For example,  a user  may wish    to attach a comment such as _1988
  938. company picnic_ to an image.
  939.  
  940. It has    been suggested    that  this  is    what  the  newspaper  and
  941. magazine industry calls a _slug._
  942.  
  943.  
  944. Make
  945. Tag  = 271  (10F)
  946. Type = ASCII
  947.  
  948. Manufacturer of the scanner, video digitizer, or whatever.
  949.  
  950. See also Model, Software.
  951.  
  952.  
  953. Model
  954. Tag  = 272  (110)
  955. Type = ASCII
  956.  
  957. The  model  name/number     of  the  scanner,  video  digitizer,  or
  958. whatever.
  959.  
  960. This tag is intended for user information only.
  961.  
  962. See also Make, Software.
  963.  
  964.  
  965. Software
  966. Tag  = 305  (131)
  967. Type = ASCII
  968.  
  969. Name and  release number of the software package that created the
  970. image.
  971.  
  972. TIFF 5.0                      page 18
  973.  
  974.  
  975. This tag is intended for user information only.
  976.  
  977. See also Make, Model.
  978.  
  979.  
  980. Facsimile Fields
  981.  
  982.  
  983. Facsimile fields  may be  useful if  you are  using TIFF to store
  984. facsimile messages  in _raw_  form.  They are not recommended for
  985. use in interchange with desktop publishing applications.
  986.  
  987. Compression (a basic tag)
  988. Tag  = 259  (103)
  989. Type = SHORT
  990. N    = 1
  991.  
  992. 3 =  Facsimile-compatible CCITT     Group 3, exactly as specified in
  993. _Standardization of  Group 3  facsimile     apparatus  for     document
  994. transmission,_     Recommendation T.4,  Volume VII, Fascicle VII.3,
  995. Terminal Equipment  and Protocols  for    Telematic  Services,  The
  996. International  Telegraph  and  Telephone  Consultative    Committee
  997. (CCITT), Geneva,  1985, pages  16 through  31.     Each strip  must
  998. begin on  a byte  boundary.   (But recall  that an image can be a
  999. single strip.)     Rows  that are     not the first row of a strip are
  1000. not required  to begin on a byte boundary.  The data is stored as
  1001. bytes,    not   words_byte-reversal  is    not  allowed.     See  the
  1002. Group3Options field for Group 3 options such as 1D vs 2D coding.
  1003.  
  1004. 4 =  Facsimile-compatible CCITT     Group 4, exactly as specified in
  1005. _Facsimile Coding  Schemes and Coding Control Functions for Group
  1006. 4 Facsimile Apparatus,_     Recommendation T.6, Volume VII, Fascicle
  1007. VII.3, Terminal     Equipment and    Protocols for Telematic Services,
  1008. The International  Telegraph and Telephone Consultative Committee
  1009. (CCITT), Geneva,  1985, pages  40 through  48.     Each strip  must
  1010. begin on  a byte  boundary.  Rows that are not the first row of a
  1011. strip are  not required to begin on a byte boundary.  The data is
  1012. stored as  bytes, not  words.    See the     Group4Options field  for
  1013. Group 4 options.
  1014.  
  1015.  
  1016. Group3Options
  1017. Tag  = 292  (124)
  1018. Type = LONG
  1019. N    = 1
  1020.  
  1021. See Compression=3.   This  field is  made up  of a set of 32 flag
  1022. bits.    Unused bits are expected to be 0.  Bit 0 is the low-order
  1023. bit.   It is probably not safe to try to read the file if any bit
  1024. of this field is set that you don_t know the meaning of.
  1025.  
  1026. Bit 0      is 1    for 2-dimensional  coding (else     1-dimensional is
  1027. assumed).   For 2-D  coding, if more than one strip is specified,
  1028. each strip  must begin    with a    1-dimensionally coded line.  That
  1029.  
  1030. TIFF 5.0                      page 19
  1031.  
  1032.  
  1033. is, RowsPerStrip  should be  a multiple     of  _Parameter     K_    as
  1034. documented in the CCITT specification.
  1035.  
  1036. Bit 1      is 1 if uncompressed mode is used.
  1037.  
  1038. Bit 2      is 1    if fill     bits have been added as necessary before
  1039. EOL codes  such that  EOL always  ends on  a byte  boundary, thus
  1040. ensuring an  eol-sequence of  a 1 byte preceded by a zero nibble:
  1041. xxxx-0000 0000-0001.
  1042.  
  1043. Default     is   0,  for  basic  1-dimensional  coding.    See  also
  1044. Compression.
  1045.  
  1046.  
  1047. Group4Options
  1048. Tag  =    293  (125)
  1049. Type = LONG
  1050. N    = 1
  1051.  
  1052. See Compression=4.   This  field is  made up  of a set of 32 flag
  1053. bits.    Unused bits are expected to be 0.  Bit 0 is the low-order
  1054. bit.   It is probably not safe to try to read the file if any bit
  1055. of this     field is  set that  you don_t know the meaning of.  Gray
  1056. scale and color coding schemes are under study, and will be added
  1057. when finalized.
  1058.  
  1059. For 2-D     coding, each  strip is     encoded as if it were a separate
  1060. image.     In particular, each strip begins on a byte boundary; and
  1061. the coding  for the first row of a strip is encoded independently
  1062. of the    previous row,  using horizontal codes, as if the previous
  1063. row is    entirely white.      Each strip ends with the 24-bit end-of-
  1064. facsimile block (EOFB).
  1065.  
  1066. Bit 0      is unused.
  1067. Bit 1      is 1 if uncompressed mode is used.
  1068.  
  1069. Default is  0, for  basic 2-dimensional     binary compression.  See
  1070. also Compression.
  1071.  
  1072.  
  1073. Document Storage and Retrieval Fields
  1074.  
  1075.  
  1076. These fields  may be  useful for  document storage  and retrieval
  1077. applications.    They are  not recommended  for use in interchange
  1078. with desktop publishing applications.
  1079.  
  1080. DocumentName
  1081. Tag  = 269  (10D)
  1082. Type = ASCII
  1083.  
  1084. The name of the document from which this image was scanned.
  1085.  
  1086. See also PageName.
  1087.  
  1088. TIFF 5.0                      page 20
  1089.  
  1090.  
  1091.  
  1092.  
  1093. PageName
  1094. Tag  = 285  (11D)
  1095. Type = ASCII
  1096.  
  1097. The name of the page from which this image was scanned.
  1098.  
  1099. See also DocumentName.
  1100.  
  1101. No default.
  1102.  
  1103. PageNumber
  1104. Tag  = 297  (129)
  1105. Type = SHORT
  1106. N    = 2
  1107.  
  1108. This tag is used to specify page numbers of a multiple page (e.g.
  1109. facsimile) document.   Two SHORT values are specified.    The first
  1110. value is the page number; the second value is the total number of
  1111. pages in the document.
  1112.  
  1113. Note that  pages need  not appear  in numerical order.    The first
  1114. page is 0 (zero).
  1115.  
  1116. No default.
  1117.  
  1118.  
  1119. XPosition
  1120. Tag  = 286  (11E)
  1121. Type = RATIONAL
  1122.  
  1123. The X  offset of  the left side of the image, with respect to the
  1124. left side of the page, in ResolutionUnits.
  1125.  
  1126. No default.  See also YPosition.
  1127.  
  1128.  
  1129. YPosition
  1130. Tag  = 287  (11F)
  1131. Type = RATIONAL
  1132.  
  1133. The Y  offset of the top of the image, with respect to the top of
  1134. the page, in ResolutionUnits.  In the TIFF coordinate scheme, the
  1135. positive Y  direction  is  down,  so  that  YPosition  is  always
  1136. positive.
  1137.  
  1138. No default.  See also XPosition.
  1139.  
  1140.  
  1141. No Longer Recommended
  1142.  
  1143. TIFF 5.0                      page 21
  1144.  
  1145.  
  1146. These fields  are not  recommended except  perhaps for local use.
  1147. They should  not be used for image interchange.     They have either
  1148. been superseded     by other fields, have been found to have serious
  1149. drawbacks, or are simply not as useful as once thought.     They may
  1150. be dropped entirely from a future revision of the specification.
  1151.  
  1152. CellLength
  1153. Tag  = 265  (109)
  1154. Type = SHORT
  1155. N    = 1
  1156.  
  1157. The length, in 1-bit samples, of the dithering/halftoning matrix.
  1158. Assumes that Threshholding = 2.
  1159.  
  1160. This field,  plus CellWidth  and Threshholding,     are  problematic
  1161. because they  cannot safely be used to reverse-engineer grayscale
  1162. image data  out of dithered/halftoned black-and-white data, which
  1163. is their  only plausible  purpose.  The only _right_ way to do it
  1164. is to  not bother  with anything  like these  fields, and instead
  1165. write  some  sophisticated  pattern-matching  software    that  can
  1166. handle screen  angles that  are not  multiples of 45 degrees, and
  1167. other such challenging dithered/halftoned data.
  1168.  
  1169. So we  do not  recommend trying     to convert dithered or halftoned
  1170. data into  grayscale data.   Dithered  and halftoned data require
  1171. careful treatment  to avoid  _stretch marks,_ but it can be done.
  1172. If you    want grayscale images, get them directly from the scanner
  1173. or frame grabber or whatever.
  1174.  
  1175. No default.  See also Threshholding.
  1176.  
  1177.  
  1178. CellWidth
  1179. Tag  = 264  (108)
  1180. Type = SHORT
  1181. N    = 1
  1182.  
  1183. The width, in 1-bit samples, of the dithering/halftoning matrix.
  1184.  
  1185. No default.   See  also Threshholding.      See  the  comments  for
  1186. CellLength.
  1187.  
  1188.  
  1189. FillOrder
  1190. Tag  = 266  (10A)
  1191. Type = SHORT
  1192. N    = 1
  1193.  
  1194. The order of data values within a byte.
  1195. 1 = most significant bits of the byte are filled first.     That is,
  1196. data values  (or code  words) are  ordered from high order bit to
  1197. low order bit within a byte.
  1198. 2 =  least significant    bits are  filled  first.    Since  little
  1199. interest has  been expressed  in least-significant  fill order to
  1200.  
  1201. TIFF 5.0                      page 22
  1202.  
  1203.  
  1204. date, and since it is easy and inexpensive for writers to reverse
  1205. bit order (use a 256-byte lookup table), we recommend FillOrder=2
  1206. for private (non-interchange) use only.
  1207.  
  1208. Default is FillOrder = 1.
  1209.  
  1210.  
  1211. FreeByteCounts
  1212. Tag  = 289  (121)
  1213. Type = LONG
  1214.  
  1215. For each  _free block_     in  the file, the number of bytes in the
  1216. block.
  1217.  
  1218. TIFF  readers    can  ignore  FreeOffsets  and  FreeByteCounts  if
  1219. present.
  1220.  
  1221. FreeOffsets and     FreeByteCounts do  not constitute a remapping of
  1222. the logical address space of the file.
  1223.  
  1224. Since this  information can  be generated  by scanning    the IFDs,
  1225. StripOffsets, and StripByteCounts, FreeByteCounts and FreeOffsets
  1226. are not needed.
  1227.  
  1228. In addition, it is not clear what should happen if FreeByteCounts
  1229. and FreeOffsets exist in more than one IFD.
  1230.  
  1231. See also FreeOffsets.
  1232.  
  1233.  
  1234. FreeOffsets
  1235. Tag  = 288  (120)
  1236. Type = LONG
  1237.  
  1238. For each _free block_  in the file, its byte offset.
  1239.  
  1240. See also FreeByteCounts.
  1241.  
  1242.  
  1243. MaxSampleValue
  1244. Tag  = 281  (119)
  1245. Type = SHORT
  1246. N    = SamplesPerPixel
  1247.  
  1248. The maximum  used sample  value.    For     example,  if  the  image
  1249. consists of  6-bit data     low-order-justified  into  8-bit  bytes,
  1250. MaxSampleValue will  be no  greater than 63. This is field is not
  1251. to be  used to    affect the  visual appearance  of the  image when
  1252. displayed.   Nor should     the values  of     this  field  affect  the
  1253. interpretation of  any other  field.    Use  it     for  statistical
  1254. purposes only.
  1255.  
  1256. Default is 2**(BitsPerSample) - 1.
  1257.  
  1258. TIFF 5.0                      page 23
  1259.  
  1260.  
  1261.  
  1262. MinSampleValue
  1263. Tag  = 280  (118)
  1264. Type = SHORT
  1265. N    = SamplesPerPixel
  1266.  
  1267. The minimum  used sample  value.  This field is not to be used to
  1268. affect the  visual appearance  of the  image when displayed.  See
  1269. the comments for MaxSampleValue.
  1270.  
  1271. Default is 0.
  1272.  
  1273.  
  1274. SubfileType
  1275. Tag  = 255  (FF)
  1276. Type = SHORT
  1277. N    = 1
  1278.  
  1279. A general  indication of  the kind  of data  that is contained in
  1280. this subfile.  Currently defined values are:
  1281.  
  1282. 1 =  full  resolution  image  data_ImageWidth,    ImageLength,  and
  1283. StripOffsets are required fields; and
  1284. 2 =  reduced resolution     image data_ImageWidth,     ImageLength, and
  1285. StripOffsets are  required fields.   It is further assumed that a
  1286. reduced resolution  image is  a reduced     version  of  the  entire
  1287. extent of the corresponding full resolution data.
  1288. 3 =  single page  of a    multi-page image  (see the PageNumber tag
  1289. description).
  1290.  
  1291. Note that several image types can be found in a single TIFF file,
  1292. with each subfile described by its own IFD.
  1293.  
  1294. No default.
  1295.  
  1296. Continued use  of this    field is not recommended.  Writers should
  1297. instead use the new and more general NewSubfileType field.
  1298.  
  1299.  
  1300. Orientation
  1301. Tag  = 274 (112)
  1302. Type = SHORT
  1303. N    = 1
  1304.  
  1305. 1 =  The 0th  row represents the visual top of the image, and the
  1306. 0th column represents the visual left hand side.
  1307. 2 =  The 0th  row represents the visual top of the image, and the
  1308. 0th column represents the visual right hand side.
  1309. 3 =  The 0th  row represents  the visual bottom of the image, and
  1310. the 0th column represents the visual right hand side.
  1311. 4 =  The 0th  row represents  the visual bottom of the image, and
  1312. the 0th column represents the visual left hand side.
  1313. 5 =  The 0th  row represents  the visual  left hand  side of  the
  1314. image, and the 0th column represents the visual top.
  1315.  
  1316. TIFF 5.0                      page 24
  1317.  
  1318.  
  1319. 6 =  The 0th  row represents  the visual  right hand  side of the
  1320. image, and the 0th column represents the visual top.
  1321. 7 =  The 0th  row represents  the visual  right hand  side of the
  1322. image, and the 0th column represents the visual bottom.
  1323. 8 =  The 0th  row represents  the visual  left hand  side of  the
  1324. image, and the 0th column represents the visual bottom.
  1325.  
  1326. Default is 1.
  1327.  
  1328. This field is recommended for private (non-interchange) use only.
  1329. It is extremely costly for most readers to perform image rotation
  1330. _on the     fly,_ i.e.,  when importing  and printing;  and users of
  1331. most  desktop  publishing  applications     do  not  expect  a  file
  1332. imported by the application to be altered permanently in any way.
  1333.  
  1334.  
  1335. Threshholding
  1336. Tag  = 263  (107)
  1337. Type = SHORT
  1338. N    = 1
  1339.  
  1340. 1 = a bilevel _line art_  scan.     BitsPerSample must be 1.
  1341. 2 =  a _dithered_   scan, usually of continuous tone data such as
  1342. photographs. BitsPerSample must be 1.
  1343. 3 = Error Diffused.
  1344.  
  1345. Default is Threshholding = 1.  See also CellWidth, CellLength.
  1346. 4) Private Fields
  1347.  
  1348. An organization     may wish to store information that is meaningful
  1349. to only that organization in a TIFF file.  Tags numbered 32768 or
  1350. higher    are  reserved  for  that  purpose.    Upon  request,  the
  1351. administrator will  allocate and register a block of private tags
  1352. for an    organization, to  avoid     possible  conflicts  with  other
  1353. organizations.     Tags are  normally allocated  in blocks of five.
  1354. If that is not enough, feel free to ask for more. You do not need
  1355. to tell     the TIFF administrator or anyone else what you are going
  1356. to use them for.
  1357.  
  1358. Private enumerated  values  can     be  accommodated  in  a  similar
  1359. fashion.   For example,     you may  wish to  experiment with  a new
  1360. compression scheme  within TIFF.   Enumeration constants numbered
  1361. 32768 or  higher are  reserved for  private usage.  Upon request,
  1362. the  administrator   will  allocate   and  register  a    block  of
  1363. enumerated values  for a  particular field  (Compression, in  our
  1364. example), to avoid possible conflicts.
  1365.  
  1366. Tags and  values which    are allocated in the private number range
  1367. are not     prohibited from  being included  in a future revision of
  1368. this specification.   Several  such instances can be found in the
  1369. TIFF specification.
  1370.  
  1371. Do not    choose your  own tag  numbers.    If you do, it could cause
  1372. serious problems some day.
  1373.  
  1374. TIFF 5.0                      page 25
  1375.  
  1376.  
  1377.  
  1378.  
  1379. 5) Image File Format Issues
  1380.  
  1381. In the    quest to  give users no reason NOT to buy a product, some
  1382. scanning and  image editing  applications overwhelm users with an
  1383. incredible number  of _Save  As..._ options.  Let_s get rid of as
  1384. many of     these as  we possibly    can.   For example, a single TIFF
  1385. choice should  suffice once most major readers are supporting the
  1386. three TIFF compression schemes; then writers can always compress.
  1387. And given  TIFF_s flexibility,    including private  tag and  image
  1388. editing     support   features,  there  does  not    seem  to  be  any
  1389. legitimate reason  for continuing  to  write  image  files  using
  1390. proprietary formats.
  1391.  
  1392. Along the  same lines,    there is no excuse for making a user have
  1393. to know     the file  format of  a file  that is  to be  read by  an
  1394. application program.   TIFF  files, as    well as     most other  file
  1395. formats, contain  sufficient information  to enable  software  to
  1396. automatically and  reliably distinguish     one type  of  file  from
  1397. another.
  1398.  
  1399.  
  1400. 6) For Further Information
  1401.  
  1402. Contact the  Aldus Developers_ Desk for sample TIFF files, source
  1403. code fragments,     and  a     list  of  features  that  are    currently
  1404. supported in  Aldus products.    The Aldus Developers_ Desk is the
  1405. current _TIFF administrator._
  1406.  
  1407. Various TIFF  related  aids  are  found     in  Microsoft_s  Windows
  1408. Developers Tookit for developers writing Windows applications.
  1409.  
  1410. Finally, a  number of  scanner vendors are providing various TIFF
  1411. services, such    as helping  to distribute  the TIFF specification
  1412. and answering  TIFF questions.     Contact  the appropriate product
  1413. manager or developer support service group.
  1414.  
  1415. TIFF 5.0                      page 26
  1416.  
  1417.  
  1418. Appendix A:  Tag Structure Rationale
  1419.  
  1420.  
  1421. A file    format is  defined by  both form (structure) and content.
  1422. The content of TIFF consists of definitions of individual fields.
  1423. It is therefore the content that we are ultimately interested in.
  1424. The structure  merely tells  us how  to find the fields.  Yet the
  1425. structure deserves  serious consideration for a number of reasons
  1426. that are not at all obvious at first glance.  Since the structure
  1427. described  herein   departs  significantly   from  several  other
  1428. approaches, it may be useful to discuss the rationale behind it.
  1429.  
  1430. The simplest,  most straightforward  structure for something like
  1431. an image  file is  a positional     format.  In a positional scheme,
  1432. the location  of the  data defines  what the  data  means.    For
  1433. example, the  field for     _number of  rows_ might  begin     at  byte
  1434. offset 30 in the image file.
  1435.  
  1436. This approach  is simple and easy to implement and is perfect for
  1437. static environments.   But  if a  significant amount  of  ongoing
  1438. change must  be accommodated,  subtle problems    begin to  appear.
  1439. For example,  suppose that  a field  must be superseded by a new,
  1440. more general  field.  You could bump a version number to flag the
  1441. change.      Then    new  software  has  no    problem     doing    something
  1442. sensible with  old data, and all old software will reject the new
  1443. data, even  software that  didn_t care about the old field.  This
  1444. may seem like no more than a minor annoyance at first glance, but
  1445. causing old  software to  break more  often than  it would really
  1446. need to     can be very costly and, inevitably, causes much gnashing
  1447. of teeth among customers.
  1448.  
  1449. Furthermore, it     can be     avoided.   One approach  is to     store    a
  1450. _valid_ flag  bit for each field.  Now you don_t have to bump the
  1451. version number,     as long  as you  can put the new field somewhere
  1452. that doesn_t  disturb any  of the  old fields.    Old software that
  1453. didn_t care about that old field anyway can continue to function.
  1454. (Old software  that did     care will of course have to give up, but
  1455. this is an unavoidable price to be paid for the sake of progress,
  1456. barring total omniscience.)
  1457.  
  1458. Another problem     that crops  up frequently is that certain fields
  1459. are likely  to make  sense only     if  other  fields  have  certain
  1460. values.      This is not such a serious problem in practice; it just
  1461. makes things  more confusing.    Nevertheless,  we note    that  the
  1462. _valid_ flag bits described in the previous paragraph can help to
  1463. clarify the situation.
  1464.  
  1465. Field-dumping  programs      can  be  very     helpful  for  diagnostic
  1466. purposes.   A desirable     characteristic of such a program is that
  1467. it doesn_t  have to  know much    about what  it is  dumping.    In
  1468. particular, it would be nice if the program could dump ASCII data
  1469. in ASCII  format, integer  data in  integer format,  and  so  on,
  1470. without having    to teach  the program  about new  fields all  the
  1471. time.    So maybe  we should  add a  _data type_     component to our
  1472.  
  1473. TIFF 5.0                      page 27
  1474.  
  1475.  
  1476. fields, plus  information on  how long    the field is, so that our
  1477. dump program can walk through the fields without knowing what the
  1478. fields _mean."
  1479.  
  1480. But note  that if we add one more component to each field, namely
  1481. a tag  that tells  what the field means, we can dispense with the
  1482. _valid_ flag  bits, and     we can     also avoid  wasting space on the
  1483. non-valid fields in the file.  Simple image creation applications
  1484. can write out several fields and be done.
  1485.  
  1486. We have     now derived  the essentials  of a  tag-based image  file
  1487. format.
  1488.  
  1489. Finally, a  caveat.  A tag based scheme cannot guarantee painless
  1490. growth.      But is  does provide    a useful  tool to  assist in  the
  1491. process.
  1492.  
  1493. TIFF 5.0                      page 28
  1494.  
  1495.  
  1496. Appendix B:  Data Compression_Scheme 2
  1497.  
  1498.  
  1499. Abstract
  1500.  
  1501. This document  describes a  method for    compressing bilevel  data
  1502. that is     based on  the CCITT  Group 3  1D  facsimile  compression
  1503. scheme.
  1504.  
  1505.  
  1506. References
  1507.  
  1508. 1.   _Standardization of Group 3 facsimile apparatus for document
  1509. transmission,_ Recommendation  T.4, Volume  VII, Fascicle  VII.3,
  1510. Terminal Equipment  and Protocols  for    Telematic  Services,  The
  1511. International  Telegraph  and  Telephone  Consultative    Committee
  1512. (CCITT), Geneva, 1985, pages 16 through 31.
  1513. 2.   _Facsimile Coding    Schemes and  Coding Control Functions for
  1514. Group 4     Facsimile Apparatus,_    Recommendation T.6,  Volume  VII,
  1515. Fascicle VII.3,     Terminal Equipment  and Protocols  for Telematic
  1516. Services, The  International Telegraph and Telephone Consultative
  1517. Committee (CCITT), Geneva, 1985, pages 40 through 48.
  1518.  
  1519. We do  not believe that these documents are necessary in order to
  1520. implement Compression=2.   We  have included  (verbatim     in  most
  1521. places) all the pertinent information in this Appendix.     However,
  1522. if you    wish to     order the  documents, you  can     write    to  ANSI,
  1523. Attention: Sales,  1430 Broadway, New York, N.Y., 10018.  Ask for
  1524. the publication     listed above_it contains both Recommendation T.4
  1525. and T.6.
  1526.  
  1527.  
  1528. Relationship to the CCITT Specifications
  1529.  
  1530. The  CCITT   Group  3    and  Group   4    specifications     describe
  1531. communications protocols for a particular class of devices.  They
  1532. are not     by themselves sufficient to describe a disk data format.
  1533. Fortunately, however,  the CCITT  coding schemes  can be  readily
  1534. adapted to this different environment.    The following is one such
  1535. adaptation.   Most of  the language  is copied    directly from the
  1536. CCITT specifications.
  1537.  
  1538.  
  1539. Coding Scheme
  1540.  
  1541. A line    (row) of  data is composed of a series of variable length
  1542. code words.  Each code word represents a run length of either all
  1543. white or  all black.   (Actually,  more than one code word may be
  1544. required to  code a  given run,     in a  manner  described  below.)
  1545. White runs and black runs alternate.
  1546.  
  1547. In order  to ensure  that the  receiver (decompressor)    maintains
  1548. color synchronization, all data lines will begin with a white run
  1549. length code  word set.     If  the actual     scan line  begins with a
  1550.  
  1551. TIFF 5.0                      page 29
  1552.  
  1553.  
  1554. black run,  a white  run length     of zero  will be sent (written).
  1555. Black or  white run  lengths are  defined by  the code    words  in
  1556. Tables 1  and 2.   The    code words are of two types:  Terminating
  1557. code  words   and  Make-up  code  words.    Each  run  length  is
  1558. represented by    zero or     more  Make-up    code  words  followed  by
  1559. exactly one Terminating code word.
  1560.  
  1561. Run lengths  in the  range of  0 to  63 pels (pixels) are encoded
  1562. with their appropriate Terminating code word.  Note that there is
  1563. a different list of code words for black and white run lengths.
  1564.  
  1565. Run lengths in the range of 64 to 2623 (2560+63) pels are encoded
  1566. first by  the Make-up  code word representing the run length that
  1567. is nearest  to, not  longer than,  that required.   This  is then
  1568. followed by the Terminating code word representing the difference
  1569. between the required run length and the run length represented by
  1570. the Make-up code.
  1571.  
  1572. Run lengths  in the range of lengths longer than or equal to 2624
  1573. pels are  coded first  by the  Make-up code  of     2560.      If  the
  1574. remaining part    of the run (after the first Make-up code of 2560)
  1575. is 2560     pels or  greater, additional Make-up code(s) of 2560 are
  1576. issued until the remaining part of the run becomes less than 2560
  1577. pels.    Then  the  remaining  part  of    the  run  is  encoded  by
  1578. Terminating code  or  by  Make-up  code     plus  Terminating  code,
  1579. according to the range mentioned above.
  1580.  
  1581. It is  considered an  unrecoverable error  if the  sum of the run
  1582. lengths for  a line  does not  equal the  value of the ImageWidth
  1583. field.
  1584.  
  1585. New rows always begin on the next available byte boundary.
  1586.  
  1587. No EOL    code words  are used.    No fill bits are used, except for
  1588. the ignored  bits at  the end  of the last byte of a row.  RTC is
  1589. not used.
  1590.  
  1591.  
  1592. Table 1/T.4  Terminating codes
  1593.  
  1594.  
  1595. White           Black
  1596. run Code  run Code
  1597. length      word length     word
  1598. ----     ---- ------    ----
  1599.  
  1600. 0   00110101   0   0000110111
  1601. 1   000111     1   010
  1602. 2   0111  2   11
  1603. 3   1000  3   10
  1604. 4   1011  4   011
  1605. 5   1100  5   0011
  1606. 6   1110  6   0010
  1607. 7   1111  7   00011
  1608.  
  1609. TIFF 5.0                      page 30
  1610.  
  1611.  
  1612. 8   10011      8   000101
  1613. 9   10100      9   000100
  1614. 10   00111     10   0000100
  1615. 11   01000     11   0000101
  1616. 12   001000    12   0000111
  1617. 13   000011    13   00000100
  1618. 14   110100    14   00000111
  1619. 15   110101    15   000011000
  1620. 16   101010    16   0000010111
  1621. 17   101011    17   0000011000
  1622. 18   0100111   18   0000001000
  1623. 19   0001100   19   00001100111
  1624. 20   0001000   20   00001101000
  1625. 21   0010111   21   00001101100
  1626. 22   0000011   22   00000110111
  1627. 23   0000100   23   00000101000
  1628. 24   0101000   24   00000010111
  1629. 25   0101011   25   00000011000
  1630. 26   0010011   26   000011001010
  1631. 27   0100100   27   000011001011
  1632. 28   0011000   28   000011001100
  1633. 29   00000010  29   000011001101
  1634. 30   00000011  30   000001101000
  1635. 31   00011010  31   000001101001
  1636. 32   00011011  32   000001101010
  1637. 33   00010010  33   000001101011
  1638. 34   00010011  34   000011010010
  1639. 35   00010100  35   000011010011
  1640. 36   00010101  36   000011010100
  1641. 37   00010110  37   000011010101
  1642. 38   00010111  38   000011010110
  1643. 39   00101000  39   000011010111
  1644. 40   00101001  40   000001101100
  1645. 41   00101010  41   000001101101
  1646. 42   00101011  42   000011011010
  1647. 43   00101100  43   000011011011
  1648. 44   00101101  44   000001010100
  1649. 45   00000100  45   000001010101
  1650. 46   00000101  46   000001010110
  1651. 47   00001010  47   000001010111
  1652. 48   00001011  48   000001100100
  1653. 49   01010010  49   000001100101
  1654. 50   01010011  50   000001010010
  1655. 51   01010100  51   000001010011
  1656. 52   01010101  52   000000100100
  1657. 53   00100100  53   000000110111
  1658. 54   00100101  54   000000111000
  1659. 55   01011000  55   000000100111
  1660. 56   01011001  56   000000101000
  1661. 57   01011010  57   000001011000
  1662. 58   01011011  58   000001011001
  1663. 59   01001010  59   000000101011
  1664. 60   01001011  60   000000101100
  1665. 61   00110010  61   000001011010
  1666.  
  1667. TIFF 5.0                      page 31
  1668.  
  1669.  
  1670. 62   00110011  62   000001100110
  1671. 63   00110100  63   000001100111
  1672.  
  1673.  
  1674.  
  1675.  
  1676. Table 2/T.4  Make-up codes
  1677.  
  1678. White           Black
  1679. run Code  run Code
  1680. length      word        length    word
  1681. ------      ---- ------     ----
  1682.  
  1683. 64 11011       64 0000001111
  1684. 128 10010      128 000011001000
  1685. 192 010111     192 000011001001
  1686. 256 0110111    256 000001011011
  1687. 320 00110110   320 000000110011
  1688. 384 00110111   384 000000110100
  1689. 448 01100100   448 000000110101
  1690. 512 01100101   512 0000001101100
  1691. 576 01101000   576 0000001101101
  1692. 640 01100111   640 0000001001010
  1693. 704 011001100  704 0000001001011
  1694. 768 011001101  768 0000001001100
  1695. 832 011010010  832 0000001001101
  1696. 896 011010011  896 0000001110010
  1697. 960 011010100  960 0000001110011
  1698. 1024 011010101 1024 0000001110100
  1699. 1088 011010110 1088 0000001110101
  1700. 1152 011010111 1152 0000001110110
  1701. 1216 011011000 1216 0000001110111
  1702. 1280 011011001 1280 0000001010010
  1703. 1344 011011010 1344 0000001010011
  1704. 1408 011011011 1408 0000001010100
  1705. 1472 010011000 1472 0000001010101
  1706. 1536 010011001 1536 0000001011010
  1707. 1600 010011010 1600 0000001011011
  1708. 1664 011000    1664 0000001100100
  1709. 1728 010011011 1728 0000001100101
  1710. EOL 000000000001    EOL 000000000001
  1711.  
  1712.  
  1713.  
  1714.  
  1715. Additional make-up codes
  1716.  
  1717. White
  1718. and
  1719. Black      Make-up
  1720. run  code
  1721. length      word
  1722. ------      ----
  1723.  
  1724. TIFF 5.0                      page 32
  1725.  
  1726.  
  1727. 1792 00000001000
  1728. 1856 00000001100
  1729. 1920 00000001101
  1730. 1984 000000010010
  1731. 2048 000000010011
  1732. 2112 000000010100
  1733. 2176 000000010101
  1734. 2240 000000010110
  1735. 2304 000000010111
  1736. 2368 000000011100
  1737. 2432 000000011101
  1738. 2496 000000011110
  1739. 2560 000000011111
  1740.  
  1741. TIFF 5.0                      page 33
  1742.  
  1743.  
  1744. Appendix C: Data Compression_Scheme 32773_
  1745. _PackBits_
  1746.  
  1747.  
  1748. Abstract
  1749.  
  1750. This document  describes a  simple compression scheme for bilevel
  1751. scanned and paint type files.
  1752.  
  1753.  
  1754. Motivation
  1755.  
  1756. The TIFF  specification defines     a number of compression schemes.
  1757. Compression type  1 is    really no  compression, other  than basic
  1758. pixel  packing.        Compression      type    2,   based  on    CCITT  1D
  1759. compression,  is   powerful,  but   not     trivial   to  implement.
  1760. Compression type  5 is    typically very effective for most bilevel
  1761. images, as  well as  many deeper images such as palette color and
  1762. grayscale images, but is also not trivial to implement.     PackBits
  1763. is a simple but often effective alternative.
  1764.  
  1765.  
  1766. Description
  1767.  
  1768. Several good schemes were already in use in various settings.  We
  1769. somewhat arbitrarily picked the Macintosh PackBits scheme.  It is
  1770. byte oriented,    so there  is no problem with word alignment.  And
  1771. it has a good worst case behavior (at most 1 extra byte for every
  1772. 128 input  bytes).    For  Macintosh  users,  there  are  toolbox
  1773. utilities PackBits  and UnPackBits that will do the work for you,
  1774. but it is easy to implement your own routines.
  1775.  
  1776. A pseudo code fragment to unpack might look like this:
  1777.  
  1778. Loop  until  you  get  the  number  of    unpacked  bytes     you  are
  1779. expecting:
  1780.    Read the next source byte into n.
  1781.    If n is between 0 and 127 inclusive, copy the next n+1 bytes
  1782. literally.
  1783.    Else if  n is  between -127    and -1 inclusive, copy the next
  1784. byte -n+1 times.
  1785.    Else if n is 128, noop.
  1786. Endloop
  1787.  
  1788. In the    inverse routine,  it_s best to encode a 2-byte repeat run
  1789. as a replicate run except when preceded and followed by a literal
  1790. run, in     which case it_s best to merge the three into one literal
  1791. run.  Always encode 3-byte repeats as replicate runs.
  1792.  
  1793. So that_s the algorithm.  Here are some other rules:
  1794.  
  1795. ╤    Each row  must be packed separately.  Do not compress across
  1796. row boundaries.
  1797.  
  1798. TIFF 5.0                      page 34
  1799.  
  1800.  
  1801. ╤    The number  of uncompressed  bytes per    row is defined to be
  1802. (ImageWidth +  7) / 8.    If the uncompressed bitmap is required to
  1803. have an     even number  of bytes    per row,  decompress  into  word-
  1804. aligned buffers.
  1805. ╤    If a  run is  larger  than  128     bytes,     simply     encode     the
  1806. remainder of the run as one or more additional replicate runs.
  1807.  
  1808. When  PackBits     data  is  uncompressed,  the  result  should  be
  1809. interpreted as per compression type 1 (no compression).
  1810.  
  1811. TIFF 5.0                      page 35
  1812.  
  1813.  
  1814. Appendix D
  1815.  
  1816.  
  1817. Appendix D  has been  deleted.     It formerly contained guidelines
  1818. for passing  TIFF files on the Microsoft Windows Clipboard.  This
  1819. was judged to not be a good idea, in light of the ever-increasing
  1820. size of     scanned images.   Applications are instead encouraged to
  1821. employ file-based  mechanisms to  exchange  TIFF  data.       Aldus_
  1822. PageMaker, for    example, implements  a _File  Place_  command  to
  1823. allow TIFF files to be imported.
  1824.  
  1825. TIFF 5.0                      page 36
  1826.  
  1827.  
  1828. Appendix E:  Numerical List of TIFF Tags
  1829.  
  1830.  
  1831. NewSubfileType
  1832. Tag  =    254  (FE)
  1833. Type = LONG
  1834. N    = 1
  1835.  
  1836. SubfileType
  1837. Tag  = 255  (FF)
  1838. Type = SHORT
  1839. N    = 1
  1840.  
  1841. ImageWidth
  1842. Tag  = 256  (100)
  1843. Type = SHORT or LONG
  1844. N    = 1
  1845.  
  1846. ImageLength
  1847. Tag  = 257  (101)
  1848. Type = SHORT or LONG
  1849. N    = 1
  1850.  
  1851. BitsPerSample
  1852. Tag  = 258  (102)
  1853. Type = SHORT
  1854. N    = SamplesPerPixel
  1855.  
  1856. Compression
  1857. Tag  = 259  (103)
  1858. Type = SHORT
  1859. N    = 1
  1860.  
  1861. PhotometricInterpretation
  1862. Tag  = 262  (106)
  1863. Type = SHORT
  1864. N    = 1
  1865.  
  1866.  
  1867. Threshholding
  1868. Tag  = 263  (107)
  1869. Type = SHORT
  1870. N    = 1
  1871.  
  1872. CellWidth
  1873. Tag  = 264  (108)
  1874. Type = SHORT
  1875. N    = 1
  1876.  
  1877. CellLength
  1878. Tag  = 265  (109)
  1879. Type = SHORT
  1880. N    = 1
  1881.  
  1882. TIFF 5.0                      page 37
  1883.  
  1884.  
  1885. FillOrder
  1886. Tag  = 266  (10A)
  1887. Type = SHORT
  1888. N    = 1
  1889.  
  1890. DocumentName
  1891. Tag  = 269  (10D)
  1892. Type = ASCII
  1893.  
  1894. ImageDescription
  1895. Tag  = 270 (10E)
  1896. Type = ASCII
  1897.  
  1898. Make
  1899. Tag  = 271  (10F)
  1900. Type = ASCII
  1901.  
  1902. Model
  1903. Tag  = 272  (110)
  1904. Type = ASCII
  1905.  
  1906. StripOffsets
  1907. Tag  = 273  (111)
  1908. Type = SHORT or LONG
  1909. N    = StripsPerImage for PlanarConfiguration equal to 1.
  1910.    = SamplesPerPixel  * StripsPerImage    for PlanarConfiguration
  1911. equal to 2
  1912.  
  1913. Orientation
  1914. Tag  = 274 (112)
  1915. Type = SHORT
  1916. N    = 1
  1917.  
  1918. SamplesPerPixel
  1919. Tag  = 277  (115)
  1920. Type = SHORT
  1921. N    = 1
  1922.  
  1923. RowsPerStrip
  1924. Tag  = 278  (116)
  1925. Type = SHORT or LONG
  1926. N    = 1
  1927.  
  1928. StripByteCounts
  1929. Tag  = 279  (117)
  1930. Type = LONG or SHORT
  1931. N    = StripsPerImage for PlanarConfiguration equal to 1.
  1932.    = SamplesPerPixel  * StripsPerImage    for PlanarConfiguration
  1933. equal to 2.
  1934.  
  1935. MinSampleValue
  1936. Tag  = 280  (118)
  1937. Type = SHORT
  1938. N    = SamplesPerPixel
  1939.  
  1940. TIFF 5.0                      page 38
  1941.  
  1942.  
  1943.  
  1944. MaxSampleValue
  1945. Tag  = 281  (119)
  1946. Type = SHORT
  1947. N    = SamplesPerPixel
  1948.  
  1949. XResolution
  1950. Tag  = 282  (11A)
  1951. Type = RATIONAL
  1952. N    = 1
  1953.  
  1954. YResolution
  1955. Tag  = 283  (11B)
  1956. Type = RATIONAL
  1957. N    = 1
  1958.  
  1959. PlanarConfiguration
  1960. Tag  = 284  (11C)
  1961. Type = SHORT
  1962. N    = 1
  1963.  
  1964. PageName
  1965. Tag  = 285  (11D)
  1966. Type = ASCII
  1967.  
  1968.  
  1969. XPosition
  1970. Tag  = 286  (11E)
  1971. Type = RATIONAL
  1972.  
  1973. YPosition
  1974. Tag  = 287  (11F)
  1975. Type = RATIONAL
  1976.  
  1977. FreeOffsets
  1978. Tag  = 288  (120)
  1979. Type = LONG
  1980.  
  1981. FreeByteCounts
  1982. Tag  = 289  (121)
  1983. Type = LONG
  1984.  
  1985. GrayResponseUnit
  1986. Tag  = 290 (122)
  1987. Type = SHORT
  1988. N    = 1
  1989.  
  1990. GrayResponseCurve
  1991. Tag  = 291 (123)
  1992. Type = SHORT
  1993. N    = 2**BitsPerSample
  1994.  
  1995. Group3Options
  1996. Tag  = 292  (124)
  1997.  
  1998. TIFF 5.0                      page 39
  1999.  
  2000.  
  2001. Type = LONG
  2002. N    = 1
  2003.  
  2004. Group4Options
  2005. Tag  =    293  (125)
  2006. Type = LONG
  2007. N    = 1
  2008.  
  2009. ResolutionUnit
  2010. Tag  = 296 (128)
  2011. Type = SHORT
  2012. N    = 1
  2013.  
  2014. PageNumber
  2015. Tag  = 297  (129)
  2016. Type = SHORT
  2017. N    = 2
  2018.  
  2019. ColorResponseCurves
  2020. Tag  = 301 (12D)
  2021. Type = SHORT
  2022. N    = 3 * (2**BitsPerSample)
  2023.  
  2024. Software
  2025. Tag  = 305  (131)
  2026. Type = ASCII
  2027.  
  2028. DateTime
  2029. Tag  = 306  (132)
  2030. Type = ASCII
  2031. N    = 20
  2032.  
  2033. Artist
  2034. Tag  = 315  (13B)
  2035. Type = ASCII
  2036.  
  2037. HostComputer
  2038. Tag  = 316  (13C)
  2039. Type = ASCII
  2040.  
  2041. Predictor
  2042. Tag  = 317 (13D)
  2043. Type = SHORT
  2044. N    = 1
  2045.  
  2046. WhitePoint
  2047. Tag  = 318 (13E)
  2048. Type = RATIONAL
  2049. N    = 2
  2050.  
  2051. PrimaryChromaticities
  2052. Tag  = 319 (13F)
  2053. Type = RATIONAL
  2054. N    = 6
  2055.  
  2056. TIFF 5.0                      page 40
  2057.  
  2058.  
  2059.  
  2060. ColorMap
  2061. Tag  = 320 (140)
  2062. Type = SHORT
  2063. N    = 3 * (2**BitsPerSample)
  2064.  
  2065. TIFF 5.0                      page 41
  2066.  
  2067.  
  2068. Appendix F:  Data Compression_Scheme 5_LZW
  2069. Compression
  2070.  
  2071.  
  2072. Abstract
  2073.  
  2074. This document describes an adaptive compression scheme for raster
  2075. images.
  2076.  
  2077.  
  2078. Reference
  2079.  
  2080. Terry  A.   Welch,  _A     Technique  for      High    Performance  Data
  2081. Compression_,  IEEE   Computer,     vol.    17  no.     6  (June  1984).
  2082. Describes the  basic Lempel-Ziv     & Welch  (LZW) algorithm.    The
  2083. author_s goal  in the  article is  to describe    a  hardware-based
  2084. compressor that could be built into a disk controller or database
  2085. engine, and  used on  all types     of data.   There  is no specific
  2086. discussion of  raster images.     We  intend  to     give  sufficient
  2087. information in    this Appendix so that the article is not required
  2088. reading.
  2089.  
  2090.  
  2091. Requirements
  2092.  
  2093. A compression  scheme with  the following  characteristics should
  2094. work well in a desktop publishing environment:
  2095.  
  2096. ╤    Must work well for images of any bit depth, including images
  2097. deeper than 8 bits per sample.
  2098. ╤    Must be effective:  an average compression ratio of at least
  2099. 2:1 or    better.       And    it  must  have    a  reasonable  worst-case
  2100. behavior, in case something really strange is thrown at it.
  2101. ╤    Should    not  depend  on     small    variations  between  pixels.
  2102. Palette color  images tend  to contain    abrupt changes    in  index
  2103. values, due to common patterning and dithering techniques.  These
  2104. abrupt changes    do tend to be repetitive, however, and the scheme
  2105. should make use of this fact.
  2106. ╤    For images  generated by  paint programs,  the scheme should
  2107. not depend on a particular pattern width.  8x8 pixel patterns are
  2108. common now, but we should not assume that this situation will not
  2109. change.
  2110. ╤    Must be     fast.     It should  not take  more than 5 seconds to
  2111. decompress a  100K byte     grayscale image on a 68020- or 386-based
  2112. computer.   Compression can  be slower,     but probably not by more
  2113. than a factor of 2 or 3.
  2114. ╤    The level  of implementation  complexity must be reasonable.
  2115. We would like something that can be implemented in no more than a
  2116. couple of  weeks  by  a_competent  software  engineer  with  some
  2117. experience  in     image    processing.    The   compiled    code  for
  2118. compression and     decompression combined     should be  no more  than
  2119. about 10K.
  2120. ╤    Does not require floating point software or hardware.
  2121.  
  2122. TIFF 5.0                      page 42
  2123.  
  2124.  
  2125.  
  2126. The following  sections describe  an algorithm based on the _LZW_
  2127. (Lempel-Ziv & Welch) technique that meets the above requirements.
  2128. In addition  meeting our  requirements,     LZW  has  the    following
  2129. characteristics:
  2130.  
  2131. ╤    LZW is fully reversible.  All information is preserved.     But
  2132. if noise  or information  is removed  from an  image, perhaps  by
  2133. smoothing or  zeroing some  low-order bitplanes,  LZW  compresses
  2134. images to  a smaller  size.   Thus,   5-bit, 6-bit, or 7-bit data
  2135. masquerading as     8-bit data  compresses better    than  true  8-bit
  2136. data. Smooth  images also  compress better than noisy images, and
  2137. simple images compress better than complex images.
  2138. φ    On a  68082- or     386-based computer,  LZW  software  can  be
  2139. written to  compress at     between 30K  and 80K  bytes per  second,
  2140. depending on image characteristics.  LZW decompression speeds are
  2141. typically about 50K bytes per second.
  2142. φ    LZW works  well on  bilevel images,  too.   It always  beats
  2143. PackBits,  and     generally  ties   CCITT  1D  (Modified     Huffman)
  2144. compression, on our test images.  Tying CCITT 1D is impressive in
  2145. that LZW  seems to be considerably faster than CCITT 1D, at least
  2146. in our implementation.
  2147. φ    Our implementation is written in C, and compiles to about 2K
  2148. bytes of object code each for the compressor and decompressor.
  2149. φ    One of    the nice  things about    LZW is that it is used quite
  2150. widely in  other applications  such as    archival programs, and is
  2151. therefore more of a known quantity.
  2152.  
  2153.  
  2154. The Algorithm
  2155.  
  2156. Each strip  is compressed  independently.   We strongly recommend
  2157. that RowsPerStrip  be chosen  such that each strip contains about
  2158. 8K bytes  before compression.    We  want to keep the strips small
  2159. enough so  that the  compressed and  uncompressed versions of the
  2160. strip can  be kept entirely in memory even on small machines, but
  2161. large enough to maintain nearly optimal compression ratios.
  2162.  
  2163. The LZW     algorithm is  based on     a translation    table, or  string
  2164. table, that  maps strings  of input  characters into  codes.  The
  2165. TIFF implementation  uses variable-length  codes, with    a maximum
  2166. code length of 12 bits.     This string table is different for every
  2167. strip, and,  remarkably, does  not need to be kept around for the
  2168. decompressor.      The  trick   is  to    make   the   decompressor
  2169. automatically build  the same  table as is built when compressing
  2170. the data.   We    use a  C-like pseudocode  to describe  the coding
  2171. scheme:
  2172.  
  2173.    InitializeStringTable();
  2174.    WriteCode(ClearCode);
  2175.    _ = the empty string;
  2176.    for each character in the strip {
  2177.     K = GetNextCharacter();
  2178.     if _+K is in the string table {
  2179.  
  2180. TIFF 5.0                      page 43
  2181.  
  2182.  
  2183.          _ = _+K;  /* string concatenation */
  2184.     } else {
  2185.          WriteCode (CodeFromString(_));
  2186.          AddTableEntry(_+K);
  2187.          _ = K;
  2188.     }
  2189.    } /* end of for loop */
  2190.    WriteCode (CodeFromString(_));
  2191.    WriteCode (EndOfInformation);
  2192.  
  2193. That_s    it.    The  scheme  is    simple,     although  it  is  fairly
  2194. challenging  to     implement  efficiently.    But     we  need  a  few
  2195. explanations before we go on to decompression.
  2196.  
  2197. The  _characters_   that  make    up  the     LZW  strings  are  bytes
  2198. containing TIFF     uncompressed (Compression=1)  image data, in our
  2199. implementation.      For example,    if BitsPerSample is 4, each 8-bit
  2200. LZW character will contain two 4-bit pixels.  If BitsPerSample is
  2201. 16, each 16-bit pixel will span two 8-bit LZW characters.
  2202.  
  2203. (It is    also possible to implement a version of LZW where the LZW
  2204. character depth equals BitsPerSample, as was described by Draft 2
  2205. of Revision  5.0.   But     there    is  a  major  problem  with  this
  2206. approach.   If BitsPerSample  is greater  than 11, we can not use
  2207. 12-bit-maximum    codes,     so  that  the    resulting  LZW    table  is
  2208. unacceptably large.   Fortunately,  due to the adaptive nature of
  2209. LZW, we     do not     pay a    significant compression ratio penalty for
  2210. combining several  pixels into    one byte before compressing.  For
  2211. example, our  4-bit sample  images  compressed    about  3  percent
  2212. worse, and  our 1-bit  images compressed  about 5 percent better.
  2213. And it    is easier to write an LZW compressor that always uses the
  2214. same character    depth than  it is  to write  one which can handle
  2215. varying depths.)
  2216.  
  2217. We can    now describe  some of the routine and variable references
  2218. in our pseudocode:
  2219.  
  2220. InitializeStringTable() initializes  the string     table to contain
  2221. all possible  single-character strings.      There     are 256 of them,
  2222. numbered 0 through 255, since our characters are bytes.
  2223.  
  2224. WriteCode() writes  a code  to the output stream.  The first code
  2225. written is a Clear code, which is defined to be code #256.
  2226.  
  2227. _ is our _prefix string._
  2228.  
  2229. GetNextCharacter() retrieves  the next    character value     from the
  2230. input stream.    This  will be number between 0 and 255, since our
  2231. characters are bytes.
  2232.  
  2233. The _+_ signs indicate string concatenation.
  2234.  
  2235. AddTableEntry() adds a table entry.  (InitializeStringTable() has
  2236. already put  256 entries  in our table.     Each entry consists of a
  2237.  
  2238. TIFF 5.0                      page 44
  2239.  
  2240.  
  2241. single-character string, and its associated code value, which is,
  2242. in our    application, identical to the character itself.     That is,
  2243. the 0th     entry in  our table  consists of  the string  <0>,  with
  2244. corresponding code  value of  <0>, the    1st entry  in  the  table
  2245. consists of the string <1>, with corresponding code value of <1>,
  2246. ..., and  the 255th  entry in  our table  consists of  the string
  2247. <255>, with  corresponding code     value of  <255>.)   So the first
  2248. entry that  we add  to our  string table will be at position 256,
  2249. right?     Well, not  quite, since  we will reserve code #256 for a
  2250. special      _Clear_   code,   and      code     #257    for   a      special
  2251. _EndOfInformation_ code     that we will write out at the end of the
  2252. strip.    So the first multiple-character entry added to the string
  2253. table will be at position 258.
  2254.  
  2255. Let_s try  an example.     Suppose  we have  input data  that looks
  2256. like:
  2257.  
  2258. Pixel 0:  <7>
  2259. Pixel 1:  <7>
  2260. Pixel 2:  <7>
  2261. Pixel 3:  <8>
  2262. Pixel 4:  <8>
  2263. Pixel 5:  <7>
  2264. Pixel 6:  <7>
  2265. Pixel 7:  <6>
  2266. Pixel 8:  <6>
  2267.  
  2268. First, we read Pixel 0 into K.    _K is then simply <7>, since _ is
  2269. the empty string at this point.     Is the string <7> already in the
  2270. string table?  Of course, since all single character strings were
  2271. put in    the table  by InitializeStringTable().    So set _ equal to
  2272. <7>, and go to the top of the loop.
  2273.  
  2274. Read Pixel 1 into K.  Does _K (<7><7>) exist in the string table?
  2275. No, so we get to do some real work.  We write the code associated
  2276. with _    to output  (write <7>  to output), and add _K (<7><7>) to
  2277. the table  as entry  258.   Store K  (<7>) into     _.    Note  that
  2278. although we have added the string consisting of Pixel 0 and Pixel
  2279. 1 to  the table, we _re-use_ Pixel 1 as the beginning of the next
  2280. string.
  2281.  
  2282. Back at     the top  of the  loop.     We read Pixel 2 into K.  Does _K
  2283. (<7><7>) exist    in the    string table?    Yes,  the entry     we  just
  2284. added, entry 258, contains exactly <7><7>.  So we just add K onto
  2285. the end of _, so that _ is now <7><7>.
  2286.  
  2287. Back at     the top  of the  loop.     We read Pixel 3 into K.  Does _K
  2288. (<7><7><8>) exist  in the  string table?   No,    so write the code
  2289. associated with     _ (<258>)  to output, and add _K to the table as
  2290. entry 259.  Store K (<8>) into _.
  2291.  
  2292. Back at     the top  of the  loop.     We read Pixel 4 into K.  Does _K
  2293. (<8><8>) exist    in the    string table?    No,  so     write    the  code
  2294.  
  2295. TIFF 5.0                      page 45
  2296.  
  2297.  
  2298. associated with     _ (<8>)  to output,  and add  _K to the table as
  2299. entry 260.  Store K (<8>) into _.
  2300.  
  2301. Continuing, we get the following results:
  2302.  
  2303.    After reading: We write to output: And add table entry:
  2304.    Pixel 0
  2305.    Pixel 1   <7>  258: <7><7>
  2306.    Pixel 2
  2307.    Pixel 3   <258>     259: <7><7><8>
  2308.    Pixel 4   <8>  260: <8><8>
  2309.    Pixel 5   <8>  261: <8><7>
  2310.    Pixel 6
  2311.    Pixel 7   <258>     262: <7><7><6>
  2312.    Pixel 8   <6>  263: <6><6>
  2313.  
  2314. WriteCode() also  requires some     explanation.    The  output  code
  2315. stream,     <7><258><8><8><258><6>...  in    our  example,  should  be
  2316. written using as few bits as possible.    When we are just starting
  2317. out, we     can use  9-bit codes, since our new string table entries
  2318. are greater  than 255  but less     than 512.  But when we add table
  2319. entry 512,  we must  switch to 10-bit codes.  Likewise, we switch
  2320. to 11-bit  codes at  1024, and    12-bit codes  at 2048.     We  will
  2321. somewhat arbitrarily limit ourselves to 12-bit codes, so that our
  2322. table can  have at most 4096 entries.  If we push it any farther,
  2323. tables tend to get too large.
  2324.  
  2325. What happens  if we run out of room in our string table?  This is
  2326. where the afore-mentioned Clear code comes in.    As soon as we use
  2327. entry 4094, we write out a (12-bit) Clear code.      (If we wait any
  2328. longer to  write the  Clear code,  the decompressor  might try to
  2329. interpret the  Clear code  as a 13-bit code.)  At this point, the
  2330. compressor re-initializes the string table and starts writing out
  2331. 9-bit codes again.
  2332.  
  2333. Note that  whenever you     write a code and add a table entry, _ is
  2334. not left  empty.   It contains exactly one character.  Be careful
  2335. not to    lose it     when you  write an end-of-table Clear code.  You
  2336. can either write it out as a 12-bit code before writing the Clear
  2337. code, in  which case  you will    want to     do it right after adding
  2338. table entry  4093, or  after the  clear code  as  a  9-bit  code.
  2339. Decompression gives the same result in either case.
  2340.  
  2341. To make     things a  little simpler  for the  decompressor, we will
  2342. require that  each strip  begins with a Clear code, and ends with
  2343. an EndOfInformation code.
  2344.  
  2345. Every LZW-compressed  strip must  begin on  a byte  boundary.  It
  2346. need not  begin on  a word  boundary.    LZW compression codes are
  2347. stored into  bytes in  high-to-low-order fashion, i.e., FillOrder
  2348. is assumed  to be  1.  The compressed codes are written as bytes,
  2349. not  words,  so     that  the  compressed    data  will  be    identical
  2350. regardless of whether it is an _II_ or _MM_ file.
  2351.  
  2352. TIFF 5.0                      page 46
  2353.  
  2354.  
  2355. Note that  the LZW string table is a continuously updated history
  2356. of the    strings that  have been encountered in the data.  It thus
  2357. reflects the characteristics of the data, providing a high degree
  2358. of adaptability.
  2359.  
  2360.  
  2361. LZW Decoding
  2362.  
  2363. The procedure for decompression is a little more complicated, but
  2364. still not too bad:
  2365.  
  2366.    while ((Code = GetNextCode()) != EoiCode) {
  2367.     if (Code == ClearCode) {
  2368.          InitializeTable();
  2369.          Code = GetNextCode();
  2370.          if (Code == EoiCode)
  2371.           break;
  2372.          WriteString(StringFromCode(Code));
  2373.          OldCode = Code;
  2374.     }  /* end of ClearCode case */
  2375.  
  2376.     else {
  2377.          if (IsInTable(Code)) {
  2378.           WriteString(StringFromCode(Code));
  2379.           AddStringToTable(StringFromCode(OldCode)+Firs
  2380. tChar(StringFromCode(Code)));
  2381.           OldCode = Code;
  2382.          } else {
  2383.           OutString   =       StringFromCode(OldCode)    +
  2384. FirstChar(StringFromCode(OldCode));
  2385.           WriteString(OutString);
  2386.           AddStringToTable(OutString);
  2387.           OldCode = Code;
  2388.          }
  2389.     } /* end of not-ClearCode case */
  2390.    } /* end of while loop */
  2391.  
  2392. The function  GetNextCode() retrieves the next code from the LZW-
  2393. coded data.  It must keep track of bit boundaries.  It knows that
  2394. the first code that it gets will be a 9-bit code.  We add a table
  2395. entry each  time we get a code, so GetNextCode() must switch over
  2396. to 10-bit codes as soon as string #511 is stored into the table.
  2397.  
  2398. The function  StringFromCode() gets  the string associated with a
  2399. particular code from the string table.
  2400.  
  2401. The function  AddStringToTable() adds  a  string  to  the  string
  2402. table.     The _+_  sign joining    the two     parts of the argument to
  2403. AddStringToTable indicate string concatenation.
  2404.  
  2405. StringFromCode() looks    up the    string associated  with     a  given
  2406. code.
  2407.  
  2408. WriteString() adds a string to the output stream.
  2409.  
  2410. TIFF 5.0                      page 47
  2411.  
  2412.  
  2413.  
  2414.  
  2415. When SamplesPerPixel Is Greater Than 1
  2416.  
  2417. We  have   so  far   described    the   compression  scheme  as  if
  2418. SamplesPerPixel were  always 1,     as will  be  be  the  case  with
  2419. palette color  and grayscale  images.  But what do we do with RGB
  2420. image data?
  2421.  
  2422. Tests on  our sample  images indicate  that the     LZW  compression
  2423. ratio     is    nearly     identical    regardless    of      whether
  2424. PlanarConfiguration=1 or  PlanarConfiguration=2, for  RGB images.
  2425. So use    whichever configuration     you prefer,  and simply compress
  2426. the bytes in the strip.
  2427.  
  2428. It is  worth cautioning     that compression  ratios on our test RGB
  2429. images were disappointing low: somewhere between 1.1 to 1 and 1.5
  2430. to 1,  depending on the image.    Vendors are urged to do what they
  2431. can to    remove as  much noise  from  their  images  as    possible.
  2432. Preliminary tests  indicate that significantly better compression
  2433. ratios are  possible with  less noisy  images.    Even something as
  2434. simple as  zeroing out one or two least-significant bitplanes may
  2435. be  quite   effective,    with   little  or  no  perceptible  image
  2436. degradation.
  2437.  
  2438.  
  2439. Implementation
  2440.  
  2441. The exact  structure of     the string  table and the method used to
  2442. determine if  a string    is already  in the table are probably the
  2443. most significant  design decisions in the implementation of a LZW
  2444. compressor and    decompressor.    Hashing has  been suggested  as a
  2445. useful technique for the compressor.  We have chosen a tree based
  2446. approach, with    good results.    The decompressor is actually more
  2447. straightforward,  as   well  as      faster,  since   no  search  is
  2448. involved_strings can be accessed directly by code value.
  2449.  
  2450.  
  2451. Performance
  2452.  
  2453. Many  people   do  not     realize  that    the  performance  of  any
  2454. compression scheme  depends greatly  on the type of data to which
  2455. it is  applied.      A scheme that works well on one data set may do
  2456. poorly on the next.
  2457.  
  2458. But since  we do  not want  to burden  the world  with    too  many
  2459. compression schemes, an adaptive scheme such as LZW that performs
  2460. quite well  on a wide range of images is very desirable.  LZW may
  2461. not always  give optimal  compression ratios,  but  its     adaptive
  2462. nature and relative simplicity seem to make it a good choice.
  2463.  
  2464. Experiments thus  far indicate    that we     can  expect  compression
  2465. ratios of  between 1.5    and 3.0     to 1  from LZW,  with no loss of
  2466. data, on  continuous tone  grayscale scanned  images.  If we zero
  2467.  
  2468. TIFF 5.0                      page 48
  2469.  
  2470.  
  2471. the least  significant one or two bitplanes of 8-bit data, higher
  2472. ratios can be achieved.     These bitplanes often consist chiefly of
  2473. noise, in  which case  little or no loss in image quality will be
  2474. perceived.   Palette color  images created  in    a  paint  program
  2475. generally compress  much  better  than    continuous  tone  scanned
  2476. images, since paint images tend to be more repetitive.    It is not
  2477. unusual to  achieve compression     ratios of 10 to 1 or better when
  2478. using LZW on palette color paint images.
  2479.  
  2480. By way    of comparison, PackBits, used in TIFF for black and white
  2481. bilevel images, does not do well on color paint images, much less
  2482. continuous tone     grayscale and    color images.  1.2 to 1 seemed to
  2483. be about average for 4-bit images, and 8-bit images are worse.
  2484.  
  2485. It has    been suggested that the CCITT 1D scheme could be used for
  2486. continuous tone     images, by compressing each bitplane separately.
  2487. No doubt  some    compression  could  be    achieved,  but    it  seems
  2488. unlikely that  a scheme     based on a fixed table that is optimized
  2489. for short  black runs  separated by  longer white runs would be a
  2490. very good choice on any of the bitplanes.  It would do quite well
  2491. on the    high-order bitplanes  (but so would a simpler scheme like
  2492. PackBits), and    would do quite poorly on the low-order bitplanes.
  2493. We believe  that the  compression ratios  would generally  not be
  2494. very impressive, and the process would in addition be quite slow.
  2495. Splitting  the    pixels    into  bitplanes     and  putting  them  back
  2496. together is  somewhat expensive,  and the  coding is  also fairly
  2497. slow when implemented in software.
  2498.  
  2499. Another     approach   that  has  been  suggested    uses  uses  a  2D
  2500. differencing step  following by     coding the  differences using    a
  2501. fixed table  of variable-length codes.    This type of scheme works
  2502. quite well  on many  8-bit  grayscale  images,    and  is     probably
  2503. simpler     to  implement    than  LZW.    But  it  has  a  number  of
  2504. disadvantages when  used on  a wide variety of images.    First, it
  2505. is not    adaptive.   This makes    a big difference when compressing
  2506. data such as 8-bit images that have been _sharpened_ using one of
  2507. the standard  techniques.  Such images tend to get larger instead
  2508. of smaller  when  compressed.     Another  disadvantage    of  these
  2509. schemes is  that they  do not  do well    with a    wide range of bit
  2510. depths.      The built-in    code table  has to  be    optimized  for    a
  2511. particular bit depth in order to be effective.
  2512.  
  2513. Finally,  we   should  mention     _lossy_   compression     schemes.
  2514. Extensive research  has been  done in  the area of lossy, or non-
  2515. information-preserving    image    compression.    These  techniques
  2516. generally yield     much  higher  compression  ratios  than  can  be
  2517. achieved  by   fully-reversible,   information-preserving   image
  2518. compression  techniques      such    as   PackBits  and   LZW.    Some
  2519. disadvantages:       many     of   the   lossy   techniques     are   so
  2520. computationally expensive  that hardware  assists  are    required.
  2521. Others    are  so     complicated  that  most  microcomputer     software
  2522. vendors could  not afford either the expense of implementation or
  2523. the increase  in  application  object  code  size.    Yet  others
  2524.  
  2525. TIFF 5.0                      page 49
  2526.  
  2527.  
  2528. sacrifice enough  image     quality  to  make  them  unsuitable  for
  2529. publishing use.
  2530.  
  2531. In spite  of these  difficulties, we  believe that there will one
  2532. day be    a standardized    lossy compression  scheme for  full color
  2533. images    that  will  be    usable    for  publishing     applications  on
  2534. microcomputers.      An International  Standards Organization group,
  2535. ISO/IEC/JTC1/SC2/WG8, in cooperation with CCITT Study Group VIII,
  2536. is hard at work on a scheme that might be appropriate.    We expect
  2537. that a    future revision of TIFF will incorporate this scheme once
  2538. it is  finalized, if it turns out to satisfy the needs of desktop
  2539. publishers and    others in the microcomputer community.    This will
  2540. augment, not replace, LZW as an approved TIFF compression scheme.
  2541. LZW will  very likely  remain the  scheme of  choice for  Palette
  2542. color images,  and perhaps  4-bit grayscale  images, and may well
  2543. overtake CCITT 1D and PackBits for bilevel images.
  2544.  
  2545.  
  2546. Future LZW Extensions
  2547.  
  2548. Some images  compress better  using LZW     coding if they are first
  2549. subjected to  a process     wherein each  pixel value is replaced by
  2550. the  difference     between  the  pixel  and  the    preceding  pixel.
  2551. Performing this     differencing in two dimensions helps some images
  2552. even more.  However, many images do not compress better with this
  2553. extra preprocessing,  and for a significant number of images, the
  2554. compression ratio is actually worse.  We are therefore not making
  2555. differencing an integral part of the TIFF LZW compression scheme.
  2556.  
  2557. However,  it   is  possible   that  a    _prediction_  stage  like
  2558. differencing may  exist which  is effective over a broad range of
  2559. images.     If such a scheme is found, it may be incorporated in the
  2560. next major TIFF revision.  If so, a new value will be defined for
  2561. the new     _Predictor_ TIFF  tag.     Therefore, all TIFF readers that
  2562. read LZW files must pay attention to the Predictor tag.     If it is
  2563. 1, which  is the  default case,     LZW  decompression  may  proceed
  2564. safely.      If it     is not     1, and the reader does not recognize the
  2565. specified prediction scheme, the reader should give up.
  2566.  
  2567.  
  2568. Acknowledgements
  2569.  
  2570. The original  LZW reference  has already  been given.  The use of
  2571. ClearCode as a technique to handle overflow was borrowed from the
  2572. compression scheme used by the Graphics Interchange Format (GIF),
  2573. a small-color-paint-image-file    format used  by     CompuServe  that
  2574. also is an adaptation of the LZW technique.  Joff Morgan and Eric
  2575. Robinson of  Aldus were     each instrumental  in their  own way  in
  2576. getting LZW off the ground.
  2577.  
  2578. TIFF 5.0                      page 50
  2579.  
  2580.  
  2581. Appendix G: TIFF Classes
  2582.  
  2583.  
  2584. Rationale
  2585.  
  2586. TIFF was  designed to  make  life  easier  for    scanner     vendors,
  2587. desktop publishing  software developers,  and users  of these two
  2588. classes of products, by reducing the proliferation of proprietary
  2589. scanned     image     formats.    It     has  succeeded     far  beyond  our
  2590. expectations in     this respect.     But  we had  expected that  TIFF
  2591. would be of interest to only a dozen or so scanner vendors (there
  2592. weren_t any  more than    that in     1985), and  another dozen  or so
  2593. desktop publishing  software vendors.    This  turned out  to be a
  2594. gross underestimate.   The only problem with this sort of success
  2595. is that     TIFF was  designed to    be powerful  and flexible, at the
  2596. expense of  simplicity.      It takes  a fair  amount of  effort  to
  2597. handle all  the options     currently defined  in this specification
  2598. (probably no  application does    a  complete  job),  and     that  is
  2599. currently the  only way     you can be sure that you will be able to
  2600. import any  TIFF image,     since there are so many image-generating
  2601. applications out there now.
  2602.  
  2603. So here     is an attempt to channel some of the flexibility of TIFF
  2604. into more  restrictive paths,  using what  we have learned in the
  2605. past two  years about which options are the most useful.  Such an
  2606. undertaking is    of course filled with fairly arbitrary decisions.
  2607. But the     result is  that writers can more easily write files that
  2608. will be     successfully read by a wide variety of applications, and
  2609. readers can know when they can stop adding TIFF features.
  2610.  
  2611. The price  we pay for TIFF Classes is some loss in the ability to
  2612. adapt.     Once we  establish the requirements for a TIFF Class, we
  2613. can never add new requirements, since old software would not know
  2614. about these  new requirements.    (The best we can do at that point
  2615. is establish new TIFF Classes.    But the problem with that is that
  2616. we could quickly have too many TIFF Classes.)  So we must believe
  2617. that we know what we are doing in establishing these Classes.  If
  2618. we do not, any mistakes will be expensive.
  2619.  
  2620.  
  2621. Overview
  2622.  
  2623. Four TIFF Classes have been defined:
  2624.  
  2625. ╤    Class B for bilevel (1-bit) images
  2626. ╤    Class G for grayscale images
  2627. ╤    Class P for palette color images
  2628. ╤    Class R for RGB full color images
  2629.  
  2630. To save     time and  space, we will usually say _TIFF B_, _TIFF G_,
  2631. _TIFF P,_  and _TIFF R._  If we are talking about all four types,
  2632. we may write _TIFF X._
  2633.  
  2634. TIFF 5.0                      page 51
  2635.  
  2636.  
  2637. (Note to  fax people:    if  you are  interested in  a fax  TIFF F
  2638. Class, please  get together  and decide     what should  be in  TIFF
  2639. Class F     files.     Let us know if we can help in any way.     When you
  2640. have decided,  send us    your results,  so that we can include the
  2641. information here.)
  2642.  
  2643.  
  2644. Core Requirements
  2645.  
  2646. This section  describes requirements  that are common to all TIFF
  2647. Class X images.
  2648.  
  2649. General Requirements
  2650.  
  2651. The following  are required  characteristics of     all TIFF Class X
  2652. files.
  2653.  
  2654. Where there are options, TIFF X writers can do whichever one they
  2655. want, though  we will  often recommend    a particular  choice, but
  2656. TIFF X    readers must  be able  to handle all of them.  Please pay
  2657. close attention     to the     recommendations.  It is possible that at
  2658. some point  in the future, new and even-simpler TIFF classes will
  2659. be defined that include only recommended features.
  2660.  
  2661. You will  need to  read at  least the first three sections of the
  2662. main specification  in order  to fully    understand the    following
  2663. discussion.
  2664.  
  2665. Defaults.  TIFF X writers may, but are not required, to write out
  2666. a field that has a default value, if the default value is the one
  2667. desired.   TIFF X  readers must     be  prepared  to  handle  either
  2668. situation.
  2669.  
  2670. Other fields.    TIFF  X readers     must be  prepared  to    encounter
  2671. fields other  than the    required fields     in TIFF X files.  TIFF X
  2672. writers     are  allowed  to  write  fields  such    as  Make,  Model,
  2673. DateTime, and so on, and TIFF X readers can certainly make use of
  2674. such fields  if they  exist.   TIFF X  readers must not, however,
  2675. refuse to read the file if such optional fields do not exist.
  2676.  
  2677. _MM_ and  æIIÆ byte order.  TIFF X readers must be able to handle
  2678. both byte  orders.    TIFF  writers  can  do  whichever     is  most
  2679. convenient  or     efficient.    Images    are   crossing    the   IBM
  2680. PC/Macintosh boundary  (and others  as well)  with a surprisingly
  2681. high frequency.      We could force writers to all use the same byte
  2682. order, but  preliminary evidence  indicates that  this will cause
  2683. problems  when     we  start   seeing  greater-than-8-bit      images.
  2684. Reversing bytes     while scanning could well slow down the scanning
  2685. process enough    to cause  the scanning    mechanism to  stop, which
  2686. tends to create image quality problems.
  2687.  
  2688. Multiple subfiles.   TIFF X readers must be prepared for multiple
  2689. images (i.e.,  subfiles) per  TIFF file,  although they     are  not
  2690. required to do anything with any image after the first one.  TIFF
  2691.  
  2692. TIFF 5.0                      page 52
  2693.  
  2694.  
  2695. X writers  must be  sure to write a long word of 0 after the last
  2696. IFD (this is the standard way of signalling that this IFD was the
  2697. last one) as indicated in the TIFF structure discussion.
  2698.  
  2699. If a  TIFF X  writer writes multiple subfiles, the first one must
  2700. be the    full resolution     image.      Subsequent subimages,     such  as
  2701. reduced resolution  images and    transparency masks, may be in any
  2702. order in  the TIFF  file.   If a reader wants to make use of such
  2703. subimages, it  will have to scan the IFDÆs before deciding how to
  2704. proceed.
  2705.  
  2706. TIFF X    Editors.   Editors, applications  that modify TIFF files,
  2707. have a few additional requirements.
  2708.  
  2709. TIFF editors  must be  especially careful  about subfiles.   If a
  2710. TIFF editor  edits a full-resolution subfile, but does not update
  2711. an accompanying     reduced-resolution subfile,  a reader    that uses
  2712. the reduced-resolution    subfile for  screen display  will display
  2713. the wrong  thing.   So TIFF  editors must  either  create  a  new
  2714. reduced-resolution subfile  when  they    alter  a  full-resolution
  2715. subfile, or  else they    must simply delete any subfiles that they
  2716. aren_t prepared to deal with.
  2717.  
  2718. A similar  situation arises with the fields themselves.     A TIFF X
  2719. editor need  only worry     about the  TIFF X  required fields.   In
  2720. particular, it    is unnecessary,     and probably  dangerous, for  an
  2721. editor to  copy fields    that it does not understand.  It may have
  2722. altered the  file in  a way that is incompatible with the unknown
  2723. fields.
  2724.  
  2725.  
  2726. Required Fields
  2727.  
  2728. NewSubfileType.     LONG.    Recommended but not required.
  2729.  
  2730. ImageWidth.   SHORT or    LONG.    (That is, both _SHORT_ and _LONG_
  2731. TIFF data  types are  allowed, and  must be  handled properly  by
  2732. readers.   TIFF writers     can use either.)  TIFF X readers are not
  2733. required to  read arbitrarily  large files however.  Some readers
  2734. will give  up if the entire image cannot fit in available memory.
  2735. (In such cases the reader should inform the user of the nature of
  2736. the problem.)    Others    will  probably    not  be     able  to  handle
  2737. ImageWidth greater  than 65535.      Recommendation: use LONG, since
  2738. resolutions seem to keep going up.
  2739.  
  2740. ImageLength.  SHORT or LONG.  Recommendation: use  LONG.
  2741.  
  2742. RowsPerStrip.  SHORT or LONG.  Readers must be able to handle any
  2743. value between  1 and  2**32-1.     However, some readers may try to
  2744. read an     entire strip  into memory  at one  time, so  that if the
  2745. entire image is one strip, the application may run out of memory.
  2746. Recommendation 1:   Set     RowsPerStrip such  that the size of each
  2747. strip is  about 8K  bytes.   Do this  even for uncompressed data,
  2748. since it  is easy  for a  writer and  makes  things  simpler  for
  2749.  
  2750. TIFF 5.0                      page 53
  2751.  
  2752.  
  2753. readers.  (Note:  extremely wide, high-resolution images may have
  2754. rows larger  than 8K  bytes; in this case, RowsPerStrip should be
  2755. 1,  and      the  strip  will  just  have    to  be    larger    than  8K.
  2756. Recommendation 2: use LONG.
  2757.  
  2758. StripOffsets.    SHORT or  LONG.     As explained in the main part of
  2759. the  specification,   the  number   of    StripOffsets  depends  on
  2760. RowsPerStrip and  ImageLength.    Recommendation:     always use LONG.
  2761. (LONG must, of course, be used if the file is more than 64K bytes
  2762. in length.)
  2763.  
  2764. StripByteCounts.   SHORT or  LONG.   Many existing TIFF images do
  2765. not contain StripByteCounts, because, in a strict sense, they are
  2766. unnecessary.   It is  possible to  write an efficient TIFF reader
  2767. that does  not need  to know  in advance  the  exact  size  of    a
  2768. compressed strip.   But     it does  make things  considerably  more
  2769. complicated, so     we will require StripByteCounts in TIFF X files.
  2770. Recommendation:      use SHORT,  since strips are not supposed to be
  2771. very large.
  2772.  
  2773. XResolution, YResolution.   RATIONAL.    Note  that the    X  and    Y
  2774. resolutions may     be unequal.   A  TIFF X  reader must  be able to
  2775. handle this  case.   TIFF X pixel-editors will typically not care
  2776. about the  resolution,    but  applications  such     as  page  layout
  2777. programs will.
  2778.  
  2779. ResolutionUnit.      SHORT.   TIFF X  readers must     be  prepared  to
  2780. handle all three values for ResolutionUnit.
  2781.  
  2782.  
  2783. TIFF Class B - Bilevel
  2784.  
  2785. Required (in addition to the above core requirements)
  2786.  
  2787. The following fields and values are required for TIFF B files, in
  2788. addition to  the fields     required for  all  TIFF  X  images  (see
  2789. above).
  2790.  
  2791. SamplesPerPixel =  1.    SHORT.     (Since this  is the default, the
  2792. field need  not be  present.   The same     thing    holds  for  other
  2793. required TIFF X fields that have defaults.)
  2794.  
  2795. BitsPerSample = 1.  SHORT.
  2796.  
  2797. Compression = 1, 2 (CCITT 1D), or 32773 (PackBits).  SHORT.  TIFF
  2798. B readers  must handle all three.  Recommendation:  use PackBits.
  2799. It  is    simple,     effective,  fast,  and     has  a     good  worst-case
  2800. behavior.    CCITT  1D    is  definitely    more  effective     in  some
  2801. situations, such as scanning a page of body text, but is tough to
  2802. implement and  test, fairly  slow,  and     has  a     poor  worst-case
  2803. behavior.   Besides, scanning a page of 12 point text is not very
  2804. useful for  publishing applications,  unless the  image     data  is
  2805. turned into  ASCII text     via OCR  software, which  is outside the
  2806. scope of TIFF.
  2807.  
  2808. TIFF 5.0                      page 54
  2809.  
  2810.  
  2811.  
  2812. PhotometricInterpretation = 0 or 1.  SHORT.
  2813. A Sample TIFF B Image
  2814.  
  2815. Offset           Value
  2816. (hex)      Name (mostly hex)
  2817.  
  2818. Header:
  2819. 0000 Byte Order        4D4D
  2820. 0002 Version   002A
  2821. 0004 1st IFD pointer     00000014
  2822.  
  2823. IFD:
  2824. 0014 Entry Count    000D
  2825. 0016 NewSubfileType 00FE 0004 00000001    00000000
  2826. 0022 ImageWidth        0100 0004 00000001    000007D0
  2827. 002E ImageLength    0101 0004 00000001    00000BB8
  2828. 003A Compression    0103 0003 00000001    8005 0000
  2829. 0046 PhotometricInterpretation       0106 0003 00000001  0001 0000
  2830. 0052 StripOffsets   0111 0004 000000BC    000000B6
  2831. 005E RowsPerStrip   0116 0004 00000001    00000010
  2832. 006A StripByteCounts     0117 0003 000000BC  000003A6
  2833. 0076 XResolution    011A 0005 00000001    00000696
  2834. 0082 YResolution    011B 0005 00000001    0000069E
  2835. 008E Software  0131 0002 0000000E  000006A6
  2836. 009A DateTime  0132 0002 00000014  000006B6
  2837. 00A6 Next IFD pointer     00000000
  2838.  
  2839. Fields pointed to by the tags:
  2840. 00B6 StripOffsets   Offset0, Offset1, ... Offset187
  2841. 03A6 StripByteCounts     Count0, Count1, ... Count187
  2842. 0696 XResolution    0000012C 00000001
  2843. 069E YResolution    0000012C 00000001
  2844. 06A6 Software  "PageMaker 3.0"
  2845. 06B6 DateTime  "1988:02:18 13:59:59"
  2846.  
  2847.  
  2848. Image Data:
  2849. 00000700  Compressed data for strip 10
  2850. xxxxxxxx  Compressed data for strip 179
  2851. xxxxxxxx  Compressed data for strip 53
  2852. xxxxxxxx  Compressed data for strip 160
  2853. .
  2854. .
  2855. .
  2856.  
  2857. End of example
  2858.  
  2859. Comments on the TIFF B example
  2860.  
  2861. 1.   The IFD  in our example starts at position hex 14.     It could
  2862. have been  anywhere in    the file  as long as the position is even
  2863. and greater  than or equal to 8, since the TIFF header is 8 bytes
  2864. long and must be the first thing in a TIFF file.
  2865.  
  2866. TIFF 5.0                      page 55
  2867.  
  2868.  
  2869.  
  2870. 2.   With 16 rows per strip, we have 188 strips in all.
  2871.  
  2872. 3.   The example  uses a  number  of  optional    fields,     such  as
  2873. DateTime.   TIFF X  readers must safely skip over these fields if
  2874. they do not want to use the information.  And TIFF X readers must
  2875. not require that such fields be present.
  2876.  
  2877. 4.   Just for  fun, our example has highly fragmented image data;
  2878. the strips  of our  image are  not even in sequential order.  The
  2879. point is  that strip  offsets must  not be ignored.  Never assume
  2880. that strip  N+1 follows     strip N.    Incidentally,  there  is  no
  2881. requirement that  the image  data follows  the    IFD  information.
  2882. Just the follow the pointers, whether they be IFD pointers, field
  2883. pointers, or Strip Offsets.
  2884.  
  2885.  
  2886.  
  2887. TIFF Class G - Grayscale
  2888.  
  2889. Required (in addition to the above core requirements)
  2890.  
  2891. SamplesPerPixel = 1.  SHORT.
  2892.  
  2893. BitsPerSample =     4,  8.       SHORT.    There  seems  to  be  little
  2894. justification for  working with grayscale images shallower than 4
  2895. bits, and 5-bit , 6-bit, and 7-bit images can easily be stored as
  2896. 8-bit images, as long as you can compress the _unused_ bit planes
  2897. without penalty.  And we can do just that with LZW (Compression =
  2898. 5.)
  2899.  
  2900. Compression = 1 or 5 (LZW).  SHORT.  Recommendation: use 5, since
  2901. LZW decompression is turning out to be quite fast.
  2902.  
  2903. PhotometricInterpretation = 0 or 1.  SHORT.   Recommendation: use
  2904. 1, due    to popular  user interfaces  for adjusting brightness and
  2905. contrast.
  2906.  
  2907.  
  2908.  
  2909. TIFF Class P - Palette Color
  2910.  
  2911. Required (in addition to the above core requirements)
  2912.  
  2913. SamplesPerPixel = 1.  SHORT.  We use each pixel value as an index
  2914. into all three color tables in ColorMap.
  2915.  
  2916. BitsPerSample =     1,2,3,4,5,6,7, or 8.  SHORT.  1,2,3,4, and 8 are
  2917. probably the  most common,  but as long as we are doing that, the
  2918. rest come pretty much for free.
  2919.  
  2920. Compression = 1 or 5.  SHORT.
  2921.  
  2922. PhotometricInterpretation = 3 (Palette Color).    SHORT.
  2923.  
  2924. TIFF 5.0                      page 56
  2925.  
  2926.  
  2927.  
  2928. ColorMap.  SHORT.
  2929.  
  2930. Note that  bilevel and    grayscale images  can be  represented  as
  2931. special cases  of palette  color images.  As soon as enough major
  2932. applications support  palette color  images, we may want to start
  2933. getting rid  of     distinctions  between    bilevel,  grayscale,  and
  2934. palette color images.
  2935.  
  2936.  
  2937. TIFF Class R - RGB Full Color
  2938.  
  2939. Required (in addition to the above Core Requirements)
  2940.  
  2941. SamplesPerPixel = 3.  SHORT.  One sample each for Red, Green, and
  2942. Blue.
  2943.  
  2944. BitsPerSample =     8,8,8.      SHORT.  Shallower samples can easily be
  2945. stored as 8-bit samples with no penalty if the data is compressed
  2946. with LZW.  And evidence to date indicates that images deeper than
  2947. 8 bits    per sample are not worth the extra work, even in the most
  2948. demanding publishing applications.
  2949.  
  2950. PlanarConfiguration = 1 or 2.  SHORT.  Recommendation:    use 1.
  2951.  
  2952. Compression = 1 or 5.  SHORT.
  2953.  
  2954. PhotometricInterpretation = 2 (RGB).  SHORT.
  2955.  
  2956. Recommended
  2957.  
  2958. Recommended for     TIFF Class  R, but not required, are the new (as
  2959. of Revision 5.0) colorimetric information tags.     See Appendix H.
  2960.  
  2961.  
  2962. Conformance and User Interface
  2963.  
  2964. Applications that  write valid    TIFF X files should include _TIFF
  2965. B_ and/or  _TIFF G_  and/or _TIFF  P_ and/or  _TIFF R_    and/or in
  2966. their product  spec sheets, if they can write the respective TIFF
  2967. Class X     files.      If your  application writes  all four     of these
  2968. types, you  may wish to write it as _TIFF B,G,P,R._  Of course, a
  2969. term like  _TIFF B,_  while fine  for  communicating  with  other
  2970. vendors, will  not convey much information to a typical user.  In
  2971. this case,  a  phrase  such  as     _Standard  TIFF  Black-and-White
  2972. Scanned Images_ might be better.
  2973.  
  2974. The same  terminology guidelines  apply to applications that read
  2975. TIFF Class X files.
  2976.  
  2977. If your     application reads more kinds of files than it writes, or
  2978. vice versa,  it would  be a  good idea    to make that clear to the
  2979. buyer.     For example, if your application reads TIFF B and TIFF G
  2980.  
  2981. TIFF 5.0                      page 57
  2982.  
  2983.  
  2984. files, but writes only TIFF G files, you should write it that way
  2985. in the spec sheet.
  2986.  
  2987. TIFF 5.0                      page 58
  2988.  
  2989.  
  2990. Appendix H: Image Colorimetry Information
  2991.  
  2992. Chris Sears
  2993. 210 Lake Street
  2994. San Francisco, CA 94118
  2995.  
  2996. June 4, 1988
  2997. Revised August 8, 1988
  2998.  
  2999.  
  3000. I. Introduction
  3001.  
  3002. Our goal is to accurately reproduce a color image using different
  3003. devices.   Accuracy requires  techniques  of  measurement  and    a
  3004. standard  of   comparison.     Different  devices   imply  device
  3005. independence.    Colorimetry provides the framework to solve these
  3006. problems.  When an image has a complete colorimetric description,
  3007. in principle  it  can  be  reproduced  identically  on    different
  3008. monitors and using different media, such as offset lithography.
  3009.  
  3010. The colorimetry     data is  specified when  the image is created or
  3011. changed.   A scanned image has colorimetry data derived from  the
  3012. filters and  light sources  of the  scanner and a synthetic image
  3013. has colorimetry     data corresponding to the monitor used to create
  3014. it or  the monitor model of the rendering environment.    This data
  3015. is used     to map     an input  image to  the markings  or colors of a
  3016. particular output device.
  3017.  
  3018. Section II  describes various  standards organizations    and their
  3019. work in color.
  3020. Section III describes our motivation for seeking these tags.
  3021. Section IV describes our goals of reproduction.
  3022. Sections V, VI and VII introduce the colorimetry tags.
  3023. Section VIII specifies the tags themselves.
  3024. Section IX describes the defaults.
  3025. Section X discusses the limitations and some of the other issues.
  3026. Section XI provides a few references.
  3027.  
  3028.  
  3029. II. Related Standards
  3030.  
  3031. TIFF is     a general  standard for describing image data.     It would
  3032. be foolish  for us  to change  TIFF in    a way  that did not match
  3033. existing industry  and international  standards.   Therefore,  we
  3034. have taken  pains to  note in the discussion below the efforts of
  3035. various standards organizations and select defaults from the work
  3036. of these organizations.
  3037.  
  3038. CIE  (Commission Internationale de lÆEclairage)  The basis of the
  3039. colorimetry information     is the     CIE 1931  Standard Observer [3].
  3040. While other color models could be supported [1] [4], CIE 1931 XYZ
  3041. is the    international standard    accepted  across  industries  for
  3042. specifying  color   and     CIE  xyY  is  the  chromaticity  diagram
  3043. associated with CIE 1931 XYZ tristimulus values.
  3044.  
  3045. TIFF 5.0                      page 59
  3046.  
  3047.  
  3048.  
  3049. NTSC (National Television  System Committee)  NTSC is of interest
  3050. primarily  for     historical  reasons  and  its    use  in     encoding
  3051. television data.   Manufacturing  standards for monitors have for
  3052. some time  drifted significantly  from the  1953 NTSC colorimetry
  3053. specification.
  3054.  
  3055. SMPTE      (Society of  Motion Picture  and Television  Engineers)
  3056. Most of     the work  by NTSC  has been  largely subsumed    by SMPTE.
  3057. This organization  has a  set of  standards  called  "Recommended
  3058. Practices" that     apply to  various technical  aspects of film and
  3059. television production [5] [6].
  3060.  
  3061. ISO  (International  Standards    Organization)     ISO  has  become
  3062. involved in  color standards  through work on a color addendum to
  3063. "Office Document Architecture (ODA) and Interchange Format" [7].
  3064.  
  3065. ANSI (American    National   Standards  Institute)    ANSI  is  the
  3066. American representative to ISO .
  3067.  
  3068.  
  3069. III. Motivation
  3070.  
  3071. Our motivation    for defining  these tags  stems from our research
  3072. and  development  in  color  separation     technology.    With  the
  3073. information described here and the RGB pixel data, we have all of
  3074. the  information  necessary  for  generating  high-quality  color
  3075. separations.  We could supply the colorimetry information outside
  3076. of the    image  file.    But  since  TIFF  provides  a  convenient
  3077. mechanism for  bundling all  of the  relevant  information  in    a
  3078. single place,  tags are     defined to  describe this information in
  3079. color TIFF files.
  3080.  
  3081. A color     image rendered     with incorrect     colorimetry  information
  3082. looks different     from the original.  One of our early test images
  3083. has an artifact in it where the image was scanned with one set of
  3084. primaries and  color ramps  were  overlaid  on    top  of     it  with
  3085. different primaries.  The blue ramp looked purple when we printed
  3086. it. Using incorrect gamma tables or white points can also lead to
  3087. distorted images.  The best way to avoid these kinds of errors is
  3088. to allow  the creator  of an  image  to     supply     the  colorimetry
  3089. information along with the RGB values [1] [2].
  3090.  
  3091. The purpose  of the  colorimetry data  is to  allow a  projective
  3092. transformation from the primaries and white point of the image to
  3093. the primaries  and white  point of  the rendering  media.   Gamma
  3094. reflects the non-linear transfer gradient of real media.
  3095.  
  3096.  
  3097. IV. Colorimetric Color Reproduction
  3098.  
  3099. Earlier we  said that given the proper colorimetric data an image
  3100. could be  rendered identically    using  two  different  calibrated
  3101. devices.   By identical,  we mean  colorimetric reproduction [9].
  3102.  
  3103. TIFF 5.0                      page 60
  3104.  
  3105.  
  3106. Specifically, the  chromaticities  match  and  the  luminance  is
  3107. scaled to correspond to the luminance range of the output device.
  3108. Because of this, we only need the chromaticity coordinates of the
  3109. white point  and primaries.   The absolute luminance is arbitrary
  3110. and unnecessary.
  3111.  
  3112.  
  3113. V. White Point
  3114.  
  3115. In TIFF 4.0, the white point was specified as D65.  This appendix
  3116. allocates a  separate tag  for describing the white point and D65
  3117. is the logical default since it is the SMPTE standard [6].
  3118.  
  3119. The white  point is  defined  colorimetrically    in  the     CIE  xyY
  3120. chromaticity diagram.    While  it is  rare for monitors to differ
  3121. from D65,  scanned images  often  have    different  white  points.
  3122. Rendered images     can have  arbitrary white  points.   The graphic
  3123. arts use D50 as the standard viewing light source [8].
  3124.  
  3125.  
  3126. VI. Primary Chromaticities
  3127.  
  3128. In TIFF     4.0, the  primary color  chromaticities matched the NTSC
  3129. specification.    With the wide variety of color scanners, monitors
  3130. and renderers,    TIFF needs  a mechanism for accurately describing
  3131. the chromaticities  of the  primary colors.   We use SMPTE as the
  3132. default chromaticity  since conventional  monitors are    closer to
  3133. SMPTE and  some monitors  (Conrac 6545)     are manufactured  to the
  3134. SMPTE specifications.    We  donÆt use the NTSC chromaticities and
  3135. white point  because present day monitors donÆt use them and must
  3136. be _matrixed_ to approximate them.
  3137.  
  3138. As an  example, the primary color chromaticities used by the Sony
  3139. Trinatron differ  from those  recommended by  SMPTE.  In general,
  3140. since  real  monitors  vary  from  the    industry  standards,  the
  3141. chromaticities of  primaries are described in the CIE xyY system.
  3142. This  allows   a  reproduction     system     to  compensate     for  the
  3143. differences.
  3144.  
  3145.  
  3146. VII. Color Response Curves
  3147.  
  3148. This tag  defines three     color response curves, one each for red,
  3149. green, and blue color information.  The width of each entry is 16
  3150. bits, as  implied by  the type    SHORT.     The minimum intensity is
  3151. represented by 0 and the maximum by 65535.  For example, black is
  3152. represented by    0,0,0 and  white by  65535, 65535,  65535.    The
  3153. length of  each curve is 2**BitsPerSample.  A ColorResponseCurves
  3154. field for RGB data where each of the samples is 8 bits deep would
  3155. have 3*256  entries.   The 256    red  entries  would  come  first,
  3156. followed by 256 green entries, followed by 256 blue entries.
  3157.  
  3158. The purpose  of the  ColorResponseCurves field    is to  act  as    a
  3159. lookup table  mapping sample values to specific intensity values,
  3160.  
  3161. TIFF 5.0                      page 61
  3162.  
  3163.  
  3164. so that     an image  created on  one system  can    be  displayed  on
  3165. another      with     minimal   loss      of   color   fidelity.      The
  3166. ColorResponseCurves field thus describes the _gamma_ of an image,
  3167. so that     a TIFF     reader on another system can compensate for both
  3168. the image gamma and the gamma of the reading system.
  3169.  
  3170. Gamma is  a term that relates to the typically nonlinear response
  3171. of most     display devices,  including monitors.     In  most display
  3172. systems, the  voltage applied to the CRT is directly proportional
  3173. to the    value of  the red,  green, or  blue sample.  However, the
  3174. resulting luminance  emitted by     the  phosphor    is  not     directly
  3175. proportional to     the voltage.    This relationship is approximated
  3176. in most displays by
  3177.  
  3178.    luminance = voltage ** gamma
  3179.  
  3180. The NTSC  standard gamma  of 2.2 adequately describes most common
  3181. video systems.    The standard  gamma of    2.2 implies a dim viewing
  3182. surround.   (We know of no SMPTE recommended practice for gamma.)
  3183. The following example uses an 8 bit sample with value of 127.
  3184.  
  3185.    voltage = 127 / 255 = 0.4980
  3186.    luminance = 0.4980 ** 2.2 = 0.2157
  3187.  
  3188. In the    examples below,     we only  consider a  single primary  and
  3189. therefore only a single curve.    The same analysis applies to each
  3190. of the    red, green,  and blue  primaries and  curves.    Also, and
  3191. without loss  of generality,  we assume that there is no hardware
  3192. color map, so that we must alter the pixel values themselves.  If
  3193. there is  a color  map, the  manipulations can be done on the map
  3194. instead of on the pixels.
  3195.  
  3196. If no  ColorResponseCurves field  exists in  a color  image,  the
  3197. reader should  assume a     gamma of  2.2 for each of the primaries.
  3198. This default curve can be generated with the following C code:
  3199.  
  3200.    ValuesPerSample = 1 << BitsPerSample;
  3201.    for (curve[0] = 0, i = 1; i < ValuesPerSample; i++)
  3202.     curve[i] =  floor (pow    (i /  (ValuesPerSample -  1.0),
  3203. 2.2) * 65535.0 + .5);
  3204.  
  3205. The displaying    or rendering  application can know its own gamma,
  3206. which we  will call  the _destination  gamma._     (An uncalibrated
  3207. system can usually assume that its gamma is 2.2 without going too
  3208. far  wrong.)     Using     this  information  the     application  can
  3209. compensate for the gamma of the image, as we shall see below.
  3210.  
  3211. If  the     source     and  destination  systems  are     both  adequately
  3212. described  by    a  gamma  of  2.2,  the     writer     would    omit  the
  3213. ColorResponseCurves field,  and the  reader can     simply read  the
  3214. image directly into the frame buffer.  If a writer writes out the
  3215. ColorResponseCurves field,  then a  reader must     assume that  the
  3216. gammas    differ.       A  reader  must  then  perform  the    following
  3217. computation on each sample in the image:
  3218.  
  3219. TIFF 5.0                      page 62
  3220.  
  3221.  
  3222.  
  3223.    NewSampleValue  =   floor  (pow   (curve[OldSampleValue]   /
  3224. 65535.0, 1.0 / DestinationGamma) *
  3225.      (ValuesPerSample - 1.0) + .5);
  3226.  
  3227. Of course,  if the _gamma_ of the destination system is not well-
  3228. approximated with  an exponential  function, an     arbitrary  table
  3229. lookup may  be used  in place  of raising  the    value  to  1.0    /
  3230. DestinationGamma.
  3231.  
  3232. Leave out  ColorResponseCurves if  using the default gamma.  This
  3233. saves about  1.5K in  the  most     common     case,    and,  after  all,
  3234. omission is the better part of compression.
  3235.  
  3236. Do not    use this  field to  store frame     buffer color  maps.  Use
  3237. instead      the     ColorMap   field.     Note,      however,   that
  3238. ColorResponseCurves may     be used  to refine  the information in a
  3239. ColorMap if desired.
  3240.  
  3241. The above  examples assume  that a  single parameter gamma system
  3242. adequately approximates the response characteristics of the image
  3243. source and  destination systems.   This will usually be true, but
  3244. our use     of a table instead of a single gamma parameter gives the
  3245. flexibility  to     describe  more     complex  relationships,  without
  3246. requiring additional computation or complexity.
  3247.  
  3248.  
  3249. VIII. New Tags and Changes
  3250. The following tags should be placed in the "Basic Fields" section
  3251. of
  3252. the TIFF specification:
  3253.  
  3254. White Point
  3255. Tag  = 318 (13E)
  3256. Type = RATIONAL
  3257. N    = 2
  3258.  
  3259. The white  point of the image.    Note that this value is described
  3260. using  the  1931  CIE  xyY  chromaticity  diagram  and    only  the
  3261. chromaticity is     specified.  The luminance component is arbitrary
  3262. and not     specified.   This can correspond to the white point of a
  3263. monitor that  the image     was painted  on,  the    filter    set/light
  3264. source combination  of a  scanner, or  to the  white point of the
  3265. illumination model of a rendering package.
  3266.  
  3267. Default is the SMPTE white point, D65:    x = 0.313, y = 0.329.
  3268.  
  3269. The ordering is x, y.
  3270.  
  3271.  
  3272. PrimaryChromaticities
  3273. Tag  = 319 (13F)
  3274. Type = RATIONAL
  3275. N    = 6
  3276.  
  3277. TIFF 5.0                      page 63
  3278.  
  3279.  
  3280.  
  3281. The primary  color chromaticities.   Note  that these  values are
  3282. described using     the 1931  CIE xyY  chromaticity diagram and only
  3283. the chromaticities  are     specified.    For  paint  images,  these
  3284. represent the  chromaticities of  the  monitor    and  for  scanned
  3285. images    they   are  derived  from  the    filter    set/light  source
  3286. combination of a scanner.
  3287.  
  3288. Default is the SMPTE primary color chromaticities:
  3289.  
  3290.    Red: x = 0.635 y = 0.340
  3291.    Green:    x = 0.305 y = 0.595
  3292.    Blue:     x = 0.155 y = 0.070
  3293.  
  3294. The ordering is red x, red y, green x, green y, blue x, blue y.
  3295.  
  3296. Color Response Curves
  3297.  
  3298. Default for  ColorResponseCurves represents  curves corresponding
  3299. to the NTSC standard gamma of 2.2.
  3300.  
  3301.  
  3302. IX. Defaults
  3303.  
  3304. The defaults  used by  TIFF reflect industry standards.     Both the
  3305. WhitePoint and    PrimaryChromaticities tags have defaults that are
  3306. promoted  by   SMPTE  .        In    addition,  the    default     for  the
  3307. ColorResponseCurves tag matches the NTSC specification of a gamma
  3308. of 2.2.
  3309.  
  3310. The purpose  of these  defaults is to allow reasonable results in
  3311. the absence  of     accurate  colorimetry    data.     An  uncalibrated
  3312. scanner or  paint system  produces an  image  that  be    displayed
  3313. identically, though  probably incorrectly  on two  different  but
  3314. calibrated systems.   This is better then the uncertain situation
  3315. where the  image might    be rendered  differently on two different
  3316. but calibrated systems.
  3317.  
  3318.  
  3319. X. Limitations and Issues
  3320.  
  3321. This section  discusses several     of the     limitations  and  issues
  3322. involved in colorimetric reproduction.
  3323.  
  3324. Scope of Usefulness
  3325.  
  3326. For many  purposes the    data recommended  here is unnecessary and
  3327. can be omitted.     For presentation graphics where there are only a
  3328. few colors,  being able     to tell  red from green is probably good
  3329. enough.      In this  case the  tags can  be ignored and there is no
  3330. overhead.   In more  demanding color  reproduction  environments,
  3331. this data  allows images to be described device independently and
  3332. at small cost.
  3333.  
  3334. TIFF 5.0                      page 64
  3335.  
  3336.  
  3337. User Burdens
  3338.  
  3339. The data we recommend isnÆt a user burden; it is really a systems
  3340. issue.     It allows  a systems  solution but  doesnÆt require user
  3341. intercession.    Calibration however  is a  separate issue.  It is
  3342. likely to involve the user.
  3343.  
  3344. Resolution Versus Fidelity
  3345.  
  3346. Some manufacturers  supply greater than 24 bits of resolution for
  3347. color specification.   The  purpose of    this is     either to  avoid
  3348. artifacts such    as contouring  in the shadows or in some cases to
  3349. be more     specific or  device independent  about the  color.  Both
  3350. reasons can  be misguided.   Other, less expensive techniques can
  3351. be used     to prevent artifacts, such as deeper color maps.  As for
  3352. accuracy, fidelity is more important than precision.
  3353.  
  3354. Colorimetric Color Reproduction
  3355.  
  3356. There are other choices for objectives of color reproduction [9].
  3357. Spectral color    reproduction is a stronger condition and most are
  3358. weaker, such  as preferred  color  reproduction.    While  device
  3359. independent spectral  color reproduction  is  impossible,  device
  3360. independent  colorimetric  reproduction     is  possible,    within    a
  3361. tolerance and within the limits of the gamuts of the devices.  By
  3362. choosing a  strong criteria  we allow the important objectives of
  3363. weaker criteria, such as preferred color reproduction, to be part
  3364. of design packages.
  3365.  
  3366. Metamerism
  3367.  
  3368. If two    patches of  color  are    identical  under  one  light  and
  3369. different under     another, they    are said  to be     metameric pairs.
  3370. Colorimetric  color  reproduction  is  a  weaker  condition  than
  3371. spectral color reproduction and hence allows metamerism problems.
  3372. By standardizing  the viewing  conditions we  can largely finesse
  3373. the metamerism    problem for  print.   Because television is self-
  3374. luminous and doesnÆt use spectral absorption, metamerism isnÆt so
  3375. much a problem.
  3376.  
  3377. Color Models - xyY Versus Luv, etc.
  3378.  
  3379. We choose  xyY over  Luv [1]  because XYZ  is  the  international
  3380. standard for  color specification  and xyY  is    the  chromaticity
  3381. diagram associated  with XYZ.    Luv is meant for color difference
  3382. measurement.
  3383.  
  3384. Ambient Environment And Viewing Surrounds
  3385.  
  3386. The viewing environment affects how the eye perceives color.  The
  3387. eye adapts  to a  dark room  and it adapts to a colored surround.
  3388. While  these   problems     can   be  compensated     for  within  the
  3389. colorimetric framework    [4], it is much better to finesse them by
  3390. standardizing.     The design environment should match the intended
  3391.  
  3392. TIFF 5.0                      page 65
  3393.  
  3394.  
  3395. viewing environment.   Specifically it should not be a pitch dark
  3396. room and,  on average,    it should  be of  a neutral  color.   For
  3397. print, ANSI recommends a Munsell N-8 surface [8].
  3398.  
  3399.  
  3400. XI. References
  3401.  
  3402. In particular,    we would  like to mention the work of Stuart Ring
  3403. of the    Copy Products  Division of the Eastman Kodak Company.  He
  3404. and  his  colleagues  are  promoting  a     color    data  interchange
  3405. paradigm.   They are  working closely  with the     ISO 8613 Working
  3406. Group [7].
  3407.  
  3408. [1]  Color Data     Interchange Paradigm,    Eastman Kodak, Rochester,
  3409. New York, 7 December 1987.
  3410.  
  3411. [2]  Color  Reproduction   and    Illumination  Models,  Roy  Hall,
  3412. International Summer  Institute:   State of  the Art  in Computer
  3413. Graphics, 1986.
  3414.  
  3415. [3]  CIE   Colorimetry:       Official   Recommendations     of   the
  3416. International Commission on Illumination, Publication 15-2, 1986.
  3417.  
  3418. [4]  Color Science:  Concepts and  Methods, Quantitative Data and
  3419. Formulae, Gunter  Wyszecki, W.S.  Stiles, John    Wiley  and  Sons,
  3420. Inc., New York, New York, 1982.
  3421.  
  3422. [5]  Color Monitor  Colorimetry, SMPTE    Recommended  Practice  RP
  3423. 145-1987.
  3424.  
  3425. [6]  Color Temperature    for  Color  Television    Studio    Monitors,
  3426. SMPTE Recommended Practice RP 37.
  3427.  
  3428. [7]  Office   Document     Architecture    (ODA)    and   Interchange
  3429. Format_Addendum on Colour, ISO 8613 Working Draft.
  3430.  
  3431. [8]  ANSI Standard PH 2.30-1985.
  3432.  
  3433. [9]  The Reproduction  of Colour  in  Photography,  Printing  and
  3434. Television, R.    W. G.  Hunt, Fountain  Press, Tolworth,     England,
  3435. 1987.
  3436.  
  3437. [10] Raster  Graphics    Handbook,  The    Conrac    Corporation,  Van
  3438. Nostrand Reinhold  Company, New     York,    New  York,  1985.    Good
  3439. description of gamma.
  3440.  
  3441. TIFF 5.0                      page 66
  3442.  
  3443.  
  3444. Appendix I:  Horizontal Differencing Predictor
  3445.  
  3446.  
  3447. This appendix,    written after  the release of Revision 5.0 of the
  3448. TIFF specification,  is still  in draft     form.     Please send  any
  3449. comments to the Aldus Developers Desk.
  3450.  
  3451.  
  3452. Revision 5.0  of the  TIFF specification defined a new tag called
  3453. _Predictor_  that  describes  techniques  that    may  be     used  in
  3454. conjuction with     TIFF compression  schemes.    We  now    define    a
  3455. Predictor that    greatly     improves  compression    ratios    for  some
  3456. images.
  3457.  
  3458. The horizontal    differencing predictor    is assigned the tag value
  3459. Predictor = 2:
  3460.  
  3461. Predictor
  3462. Tag  = 317 (13D)
  3463. Type = SHORT
  3464. N    = 1
  3465.  
  3466. A predictor  a mathematical operator that is applied to the image
  3467. data before  the encoding  scheme is  applied.     Currently (as of
  3468. revision 5.0)  this tag     is used  only with  LZW  (Compression=5)
  3469. encoding, since     LZW is     probably the  only TIFF  encoding scheme
  3470. that benefits  significantly from a predictor step.  See Appendix
  3471. F.
  3472.  
  3473. 1 = No prediction scheme used before coding.
  3474. 2 = Horizontal differencing. See Appendix I.
  3475.  
  3476. Default is 1.
  3477.  
  3478.  
  3479. The algorithm
  3480.  
  3481. The idea  is to     make use  of the  fact that many continuous tone
  3482. images rarely  vary much  in pixel  value from    one pixel  to the
  3483. next.    In such     images,  if  we  replace  the    pixel  values  by
  3484. differences between  consecutive pixels,  many of the differences
  3485. should be  0, plus  or minus  1, and  so on.   This  reduces  the
  3486. apparent information  content, and  thus allows LZW to encode the
  3487. data more compactly.
  3488.  
  3489. Assuming 8-bit    grayscale  pixels  for    the  moment,  a     basic    C
  3490. implementation might look something like this:
  3491.  
  3492.    char image[ ][ ];
  3493.    int    row, col;
  3494.  
  3495.    /* take horizontal differences:
  3496.     */
  3497.    for (row = 0; row < nrows; row++)
  3498.  
  3499. TIFF 5.0                      page 67
  3500.  
  3501.  
  3502.     for (col = ncols - 1; col >= 1; col--)
  3503.          image[row][col] -= image[row][col-1];
  3504.  
  3505. If we  don_t have 8-bit samples, we need to work a little harder,
  3506. so that     we can make better use of the architecture of most CPUs.
  3507. Suppose we  have 4-bit    samples, packed     two to a byte, in normal
  3508. TIFF uncompressed  (i.e., Compression=1)  fashion.   In order  to
  3509. find differences,  we want to first expand each 4-bit sample into
  3510. an 8-bit  byte, so  that we  have one  sample per byte, low-order
  3511. justified.   We then  perform the  above horizontal differencing.
  3512. Once the  differencing has  been completed, we then repack the 4-
  3513. bit differences     two to     a  byte,  in  normal  TIFF  uncompressed
  3514. fashion.
  3515.  
  3516. If the    samples are  greater than  8  bits  deep,  expanding  the
  3517. samples into  16-bit words  instead of 8-bit bytes seems like the
  3518. best way to perform the subtraction on most computers.
  3519.  
  3520. Note that we have not lost any data up to this point, nor will we
  3521. lose any  data later  on.   It    might  at  first  seem    that  our
  3522. differencing might  turn 8-bit samples into 9-bit differences, 4-
  3523. bit samples  into 5-bit differences, and so on.     But it turns out
  3524. that we     can completely     ignore the  _overflow_     bits  caused  by
  3525. subtracting a  larger number  from a  smaller  number  and  still
  3526. reverse the  process  without  error.     Normal     twos  complement
  3527. arithmetic does just what we want.  Try an example by hand if you
  3528. need more convincing.
  3529.  
  3530. Up  to    this  point  we     have  implicitly  assumed  that  we  are
  3531. compressing  bilevel   or  grayscale   images.       An  additional
  3532. consideration arises in the case of color images.
  3533.  
  3534. If PlanarConfiguration    is 2,  there is no problem.  Differencing
  3535. proceeds the same way as it would for grayscale data.
  3536.  
  3537. If  PlanarConfiguration     is  1,     however,  things  get    a  little
  3538. trickier.   If    we  didnÆt  do  anything  special,  we  would  be
  3539. subtracting red     sample values    from green  sample values,  green
  3540. sample values  from blue  sample values,  and blue  sample values
  3541. from red sample values, which would not give the LZW coding stage
  3542. much redundancy     to work  with.      So we     will do  our  horizontal
  3543. differences with  an offset  of SamplesPerPixel     (3, in     the  RGB
  3544. case).    In other words, we will subtract red from red, green from
  3545. green, and  blue from blue.  The LZW coding stage is identical to
  3546. the SamplesPerPixel=1 case.  We require that BitsPerSample be the
  3547. same for all 3 samples.
  3548.  
  3549.  
  3550. Results and guidelines
  3551.  
  3552. LZW without  differencing works     well  for  1-bit  images,  4-bit
  3553. grayscale images, and synthetic color images.  But natural 24-bit
  3554. color images  and some 8-bit grayscale images do much better with
  3555. differencing.  For example, our 24-bit natural test images hardly
  3556.  
  3557. TIFF 5.0                      page 68
  3558.  
  3559.  
  3560. compressed at  all using  _plain_ LZW:    the  average  compression
  3561. ratio was  1.04     to  1.       The    average     compression  ratio  with
  3562. horizontal differencing     was 1.40  to 1.  (A compression ratio of
  3563. 1.40 to 1 means that if the uncompressed image is 1.40MB in size,
  3564. the compressed version is 1MB in size.)
  3565.  
  3566. Although  the    combination  of      LZW  coding    with   horizontal
  3567. differencing does  not result  in any  loss of    data, it  may  be
  3568. worthwhile in  some situations    to give     up some  information  by
  3569. removing as  much noise     as possible  from the    image data before
  3570. doing the  differencing, especially  with  8-bit  samples.    The
  3571. simplest way  to get  rid of noise is to mask off one or two low-
  3572. order bits  of each 8-bit sample.  On our 24-bit test images, LZW
  3573. with horizontal differencing yielded an average compression ratio
  3574. of 1.4 to 1.  When the low-order bit was masked from each sample,
  3575. the compression     ratio climbed to 1.8 to 1; the compression ratio
  3576. was 2.4     to 1  when masking  two bits,    and 3.4 to 1 when masking
  3577. three bits.   Of  course, the  more you     mask, the  more you risk
  3578. losing useful information along with the noise.     We encourage you
  3579. to experiment  to find    the best compromise for your device.  For
  3580. some applications it may be useful to let the user make the final
  3581. decision.
  3582.  
  3583. Interestingly, most  of our RGB images compressed slightly better
  3584. using PlanarConfiguration=1.   One  might think     that compressing
  3585. the  red,   green,  and      blue     difference   planes   separately
  3586. (PlanarConfiguration=2) might  give  better  compression  results
  3587. than  mixing   the  differences      together   before   compressing
  3588. (PlanarConfiguration=1), but this does not appear to be the case.
  3589.  
  3590. Incidentally,  we  tried  taking  both    horizontal  and     vertical
  3591. differences,  but   the     extra     complexity  of      two-dimensional
  3592. differencing did  not appear  to pay  off for  most of    our  test
  3593. images.     About one third of the images compressed slightly better
  3594. with two-dimensional  differencing, about  one    third  compressed
  3595. slightly worse, and the rest were about the same.
  3596.  
  3597. TIFF 5.0                      page 69
  3598.  
  3599.  
  3600. Appendix J:  Palette Color
  3601.  
  3602.  
  3603. This appendix,    written after  the release of Revision 5.0 of the
  3604. TIFF specification,  is still  in draft     form.     Please send  any
  3605. comments to the Aldus Developers Desk.
  3606.  
  3607.  
  3608. Revision  5.0    of  the      TIFF    specification    defined      a   new
  3609. PhotometricInterpretation value     called _palette color._  We have
  3610. been wondering    lately if this additional complexity is worth the
  3611. implementation expense.      If  not, let_s  drop it before too many
  3612. people start creating palette color images.
  3613.  
  3614.  
  3615. The Proposal
  3616.  
  3617. Instead of a separate palette color image type, there seems to be
  3618. no compelling reason why palette (mapped) color images should not
  3619. be stored as _full color_ (usually 24-bit) RGB images.
  3620.  
  3621.  
  3622. Objections
  3623.  
  3624. The most  obvious objection is the amount of space required.  But
  3625. if you    care about how much space the image takes up on disk, you
  3626. should use  LZW compression,  which is    ideally     suited     to  most
  3627. palette color  images.     (LZW compresses  most paint-type palette
  3628. color images  5:1 or  more.)   And if you use LZW compression, it
  3629. turns out  that palette     color images stored as full color images
  3630. compress to  almost exactly the same size as palette color images
  3631. stored as  palette color  images.  That is, with LZW compression,
  3632. there is  no penalty  for storing  palette color  images as  full
  3633. color RGB  images.   The resulting  file may  be  a  few  percent
  3634. larger, but  it will not be three times as large.  See Appendix F
  3635. for more information on how LZW works.
  3636.  
  3637. Another objection  might be  that an  application might     want  to
  3638. process the  image differently    if it is _really_ a palette color
  3639. image. But  we can easily add auxiliary information that can help
  3640. a TIFF    reader to quickly categorize color images if it wants to.
  3641. See the _New tags_ section below.
  3642.  
  3643.  
  3644. Benefits
  3645.  
  3646. It may    be obvious,  but it  is probably  worth discussing why we
  3647. want  to   abolish   palette   color   images    as   a     distinct
  3648. classification.
  3649.  
  3650. The main  problem is  that palette color as a separate type makes
  3651. life more  hazardous and  confusing for     users.       The    confusion
  3652. factor is  aggravated because  users already  have to be somewhat
  3653. aware of  distinctions    between     bilevel,  grayscale,  and  color
  3654.  
  3655. TIFF 5.0                      page 70
  3656.  
  3657.  
  3658. images.      Having two  main types of color images is hard for many
  3659. users to  grasp, and  it is probably not possible to totally hide
  3660. this complexity     from the user in certain situations.  The hazard
  3661. level goes  up because some applications may accept palette color
  3662. but not     full color  images, or     full color but not palette color
  3663. images, or may accept 8-bit palette color images but not 4-bit or
  3664. 3-bit palette color images.
  3665.  
  3666. The second  problem is    that writing and maintaining code to deal
  3667. with an     additional image  type is  somewhat expensive    for  TIFF
  3668. readers.  The cost of supporting palette color images will depend
  3669. on the    application, but  we believe  that, in    general, the cost
  3670. will be     substantial.    It seems  to make  more sense  to put the
  3671. burden on  TIFF writers to convert palette color images into full
  3672. color image  form than    to make TIFF readers handle an additional
  3673. color image  type, since there are more TIFF readers than writers
  3674. at this point.
  3675.  
  3676.  
  3677. New tags
  3678.  
  3679. Here are  some proposed     new tags that can help to classify color
  3680. images, and  make up  for not  having a     separate  palette  color
  3681. class.    They are not required for TIFF Class R , but are strongly
  3682. recommended for     color TIFF  images created by palette-type color
  3683. paint programs.
  3684.  
  3685. ColorImageType
  3686. Tag  = 318 (13E)
  3687. Type = SHORT
  3688. N    = 1
  3689.  
  3690. Gives TIFF  color image     readers a  better idea     of what  kind of
  3691. color image it is.  There will be borderline cases.
  3692.  
  3693. 1 = Continuous tone, natural image.
  3694. 2 =  Synthetic image, using a greatly restricted range of colors.
  3695. Such images  are produced  by most  color paint     programs.    See
  3696. ColorList for a list of colors used in this image.
  3697.  
  3698. Default is 1.
  3699.  
  3700. ColorList
  3701. Tag  = 319 (13F)
  3702. Type = BYTE or SHORT
  3703. N    = the  number of  colors that  are used in this image, times
  3704. SamplesPerPixel
  3705.  
  3706. A list    of colors that are used in this image.    Use of this field
  3707. is only     practical for    images containing  a  greatly  restricted
  3708. (usually  less     than  or   equal  to    256)  range   of  colors.
  3709. ColorImageType should be 2.  See ColorImageType.
  3710.  
  3711. TIFF 5.0                      page 71
  3712.  
  3713.  
  3714. The list  is organized    as an array of RGB triplets, with no pad.
  3715. The RGB     triplets are  not guaranteed  to be  in  any  particular
  3716. order.     Note that the red, green, and blue components can either
  3717. be a  BYTE or  a SHORT    in length.  BYTE should be sufficient for
  3718. most applications.
  3719.  
  3720. No default.
  3721.