home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Libraries / grayimage / tiff.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-30  |  10.7 KB  |  242 lines  |  [TEXT/R*ch]

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /*
  3.  ************************************************************************
  4.  *
  5.  *             Tag Image File Format (TIFF)
  6.  *
  7.  * Based on Rev 5.0 from:
  8.  *    Developer's Desk        Window Marketing Group
  9.  *    Aldus Corporation        Microsoft Corporation
  10.  *    411 First Ave. South    16011 NE 36th Way
  11.  *    Suite 200            Box 97017
  12.  *    Seattle, WA  98104    Redmond, WA  98073-9717
  13.  *    206-622-5500        206-882-8080
  14.  *
  15.  * Copyright (c) 1988, 1990 by Sam Leffler.
  16.  * All rights reserved.
  17.  *
  18.  * This file is provided for unrestricted use provided that this
  19.  * legend is included on all tape media and as a part of the
  20.  * software program in whole or part.  Users may copy, modify or
  21.  * distribute this file at will.
  22.  *
  23.  * Severely modified to define classes of all important TIFF file
  24.  * data structures, by me.
  25.  *
  26.  * $Id: tiff.h,v 1.2 1994/06/20 18:09:00 oleg Exp oleg $
  27.  *
  28.  ************************************************************************
  29.  */
  30.  
  31. #ifndef _TIFF_
  32. #define    _TIFF_
  33.  
  34. /*
  35.  *------------------------------------------------------------------------
  36.  *                TIFF file header
  37.  * It is always written at the very beginning of the TIFF file
  38.  */
  39.  
  40. class TIFFHeader
  41. {
  42.   unsigned short magic;        // magic number (defines byte order)
  43.   unsigned short version;    // TIFF version number
  44.   unsigned long  diroffset;    // byte offset to first directory
  45.  
  46.   const unsigned short TIFF_BIGENDIAN = 0x4d4d;       // Interpretation of magic
  47.   const unsigned short TIFF_LITTLEENDIAN = 0x4949;
  48.   const unsigned short TIFF_VERSION = 42;       // Interpretation of version
  49.  
  50. public:
  51.   TIFFHeader(void) : magic(TIFF_BIGENDIAN), version(TIFF_VERSION),
  52.              diroffset(sizeof(*this)) // Meaning the DIR follows 
  53.              {}                  // immediately
  54.   TIFFHeader(EndianIO& file);
  55.   ~TIFFHeader(void) {}
  56.   void write(EndianIO& file);
  57.   unsigned long directory_offset(void) const { return diroffset; }
  58. };
  59.  
  60. /*
  61.  *------------------------------------------------------------------------
  62.  *            TIFF Image File Directories 
  63.  * are comprised of a table of field descriptors of the form shown below.  
  64.  * The table is sorted in ascending order by tag.  The values associated 
  65.  * with each entry are disjoint and may appear anywhere in the file (so 
  66.  * long as they are placed on a word boundary).
  67.  *
  68.  * If the value is 4 bytes or less, then it is placed in the offset field 
  69.  * to save space.  If the value is less than 4 bytes, it is left-justified 
  70.  * in the offset field.
  71.  */
  72.  
  73. class TIFFDirEntry
  74. {
  75. public:
  76.   unsigned short tag;        // see below
  77.   unsigned short type;        // data type; see below
  78.   unsigned long  count;        // number of items; length in spec
  79.   unsigned long  val_offset;    // byte offset to field data
  80.  
  81. protected:
  82.   TIFFDirEntry(void) {}            // For use from derived classes only
  83.  
  84. public:
  85.   enum DataType {
  86.     BYTE = 1,            // 8-bit unsigned integer
  87.     ASCII = 2,            // 8-bit bytes w/ last byte null
  88.     SHORT = 3,            // 16-bit unsigned integer
  89.     LONG = 4,            // 32-bit unsigned integer
  90.     RATIONAL = 5        // 64-bit fractional (numerator+denominator)
  91.     };
  92.  
  93.   TIFFDirEntry(const short _tag, const DataType _type, const long _count,
  94.            const long _value)
  95.     : tag(_tag), type(_type), count(_count), val_offset(_value) {}
  96.  
  97.  
  98.   ~TIFFDirEntry(void) {}
  99. };
  100.  
  101. /* Types as defined in the TIFF standard for SUN3 */
  102.  
  103. typedef unsigned char  BYTE;         /* 8-bits */
  104. typedef unsigned char  ASCII;        /* 8-bits */
  105. typedef unsigned short SHORT;        /* 16 bits */
  106. typedef unsigned int   LONG;         /* 32 bits */
  107. typedef unsigned long  RATIONAL;     /* 2 LONG's numerator : denominator  */
  108.  
  109. #define INFINITY  99999
  110.  
  111. /*
  112.  *------------------------------------------------------------------------
  113.  *                TIFF Tag Definitions
  114.  *
  115.  * Those marked with a + are obsoleted by revision 5.0
  116.  */
  117. #define    TIFFTAG_SUBFILETYPE        254    /* subfile data descriptor   */
  118. #define        FILETYPE_REDUCEDIMAGE    0x1    /* reduced resolution version*/
  119. #define        FILETYPE_PAGE        0x2    /* one page of many         */
  120. #define        FILETYPE_MASK        0x4    /* transparency mask         */
  121.  
  122. #define    TIFFTAG_OSUBFILETYPE        255    /* +kind of data in subfile  */
  123. #define        OFILETYPE_IMAGE        1    /* full resolution image data*/
  124. #define        OFILETYPE_REDUCEDIMAGE    2    /* reduced size image data   */
  125. #define        OFILETYPE_PAGE        3    /* one page of many         */
  126.  
  127. #define    TIFFTAG_IMAGEWIDTH        256    /* image width in pixels     */
  128. #define    TIFFTAG_IMAGELENGTH        257    /* image height in pixels    */
  129. #define    TIFFTAG_BITSPERSAMPLE        258    /* bits per channel (sample) */
  130.  
  131. #define    TIFFTAG_COMPRESSION        259    /* data compression technique*/
  132. #define        COMPRESSION_NONE        1    /* dump mode             */
  133. #define        COMPRESSION_CCITTRLE    2    /* CCITT modified Huffman RLE*/
  134. #define        COMPRESSION_CCITTFAX3    3    /* CCITT Group 3 fax encoding*/
  135. #define        COMPRESSION_CCITTFAX4    4    /* CCITT Group 4 fax encoding*/
  136. #define        COMPRESSION_LZW        5    /* Lempel-Ziv  & Welch         */
  137. #define        COMPRESSION_NEXT        32766    /* NeXT 2-bit RLE         */
  138. #define        COMPRESSION_CCITTRLEW    32771    /* #1 w/ word alignment      */
  139. #define        COMPRESSION_PACKBITS    32773    /* Macintosh RLE         */
  140. #define        COMPRESSION_THUNDERSCAN    32809    /* ThunderScan RLE          */
  141. #define        COMPRESSION_PICIO        32900    /* old Pixar picio RLE         */
  142. #define        COMPRESSION_SGIRLE        32901    /* Silicon Graphics RLE      */
  143.  
  144. #define    TIFFTAG_PHOTOMETRIC        262    /* photometric interpretation*/
  145. #define        PHOTOMETRIC_MINISWHITE    0    /* min value is white         */
  146. #define        PHOTOMETRIC_MINISBLACK    1    /* min value is black         */
  147. #define        PHOTOMETRIC_RGB        2    /* RGB color model         */
  148. #define        PHOTOMETRIC_PALETTE        3    /* color map indexed         */
  149. #define        PHOTOMETRIC_MASK        4    /* holdout mask             */
  150. #define        PHOTOMETRIC_DEPTH        32768    /* z-depth data             */
  151.  
  152. #define    TIFFTAG_THRESHHOLDING        263    /* +thresholding used on data*/
  153. #define        THRESHHOLD_BILEVEL        1    /* b&w art scan             */
  154. #define        THRESHHOLD_HALFTONE        2    /* or dithered scan         */
  155. #define        THRESHHOLD_ERRORDIFFUSE    3    /* usually floyd-steinberg   */
  156.  
  157. #define    TIFFTAG_CELLWIDTH        264    /* +dithering matrix width   */
  158. #define    TIFFTAG_CELLLENGTH        265    /* +dithering matrix height  */
  159. #define    TIFFTAG_FILLORDER        266    /* +data order within a byte */
  160. #define        FILLORDER_MSB2LSB        1    /* most significant -> least */
  161. #define        FILLORDER_LSB2MSB        2    /* least significant -> most */
  162.  
  163. #define    TIFFTAG_DOCUMENTNAME        269    /* name of doc. image is from*/
  164. #define    TIFFTAG_IMAGEDESCRIPTION    270    /* info about image         */
  165. #define    TIFFTAG_MAKE            271    /* scanner manufacturer name */
  166. #define    TIFFTAG_MODEL            272    /* scanner model name/number */
  167. #define    TIFFTAG_STRIPOFFSETS        273    /* offsets to data strips    */
  168.  
  169. #define    TIFFTAG_ORIENTATION        274    /* +image orientation         */
  170. #define        ORIENTATION_TOPLEFT        1    /* row 0 top, col 0 lhs         */
  171. #define        ORIENTATION_TOPRIGHT    2    /* row 0 top, col 0 rhs         */
  172. #define        ORIENTATION_BOTRIGHT    3    /* row 0 bottom, col 0 rhs   */
  173. #define        ORIENTATION_BOTLEFT        4    /* row 0 bottom, col 0 lhs   */
  174. #define        ORIENTATION_LEFTTOP        5    /* row 0 lhs, col 0 top      */
  175. #define        ORIENTATION_RIGHTTOP    6    /* row 0 rhs, col 0 top      */
  176. #define        ORIENTATION_RIGHTBOT    7    /* row 0 rhs, col 0 bottom   */
  177. #define        ORIENTATION_LEFTBOT        8    /* row 0 lhs, col 0 bottom   */
  178.  
  179. #define    TIFFTAG_SAMPLESPERPIXEL        277    /* samples per pixel         */
  180. #define    TIFFTAG_ROWSPERSTRIP        278    /* rows per strip of data    */
  181. #define    TIFFTAG_STRIPBYTECOUNTS        279    /* bytes counts for strips   */
  182. #define    TIFFTAG_MINSAMPLEVALUE        280    /* +minimum sample value     */
  183. #define    TIFFTAG_MAXSAMPLEVALUE        281    /* maximum sample value      */
  184. #define    TIFFTAG_XRESOLUTION        282    /* pixels/resolution in x    */
  185. #define    TIFFTAG_YRESOLUTION        283    /* pixels/resolution in y    */
  186.  
  187. #define    TIFFTAG_PLANARCONFIG        284    /* storage organization         */
  188. #define        PLANARCONFIG_CONTIG        1    /* single image plane          */
  189. #define        PLANARCONFIG_SEPARATE    2    /* separate planes of data   */
  190.  
  191. #define    TIFFTAG_PAGENAME        285    /* page name image is from   */
  192. #define    TIFFTAG_XPOSITION        286    /* x page offset of image lhs*/
  193. #define    TIFFTAG_YPOSITION        287    /* y page offset of image lhs*/
  194. #define    TIFFTAG_FREEOFFSETS        288    /* +byte offset to free block*/
  195. #define    TIFFTAG_FREEBYTECOUNTS        289    /* +sizes of free blocks     */
  196.  
  197. #define    TIFFTAG_GRAYRESPONSEUNIT    290    /* gray scale curve accuracy */
  198. #define        GRAYRESPONSEUNIT_10S    1    /* tenths of a unit         */
  199. #define        GRAYRESPONSEUNIT_100S    2    /* hundredths of a unit         */
  200. #define        GRAYRESPONSEUNIT_1000S    3    /* thousandths of a unit     */
  201. #define        GRAYRESPONSEUNIT_10000S    4    /* ten-thousandths of a unit */
  202. #define        GRAYRESPONSEUNIT_100000S    5    /* hundred-thousandths         */
  203. #define    TIFFTAG_GRAYRESPONSECURVE    291    /* gray scale response curve */
  204. #define    TIFFTAG_GROUP3OPTIONS        292    /* 32 flag bits             */
  205. #define        GROUP3OPT_2DENCODING    0x1    /* 2-dimensional coding         */
  206. #define        GROUP3OPT_UNCOMPRESSED    0x2    /* data not compressed         */
  207. #define        GROUP3OPT_FILLBITS        0x4    /* fill to byte boundary     */
  208. #define    TIFFTAG_GROUP4OPTIONS        293    /* 32 flag bits             */
  209. #define        GROUP4OPT_UNCOMPRESSED    0x2    /* data not compressed         */
  210. #define    TIFFTAG_RESOLUTIONUNIT        296    /* units of resolutions         */
  211. #define        RESUNIT_NONE        1    /* no meaningful units         */
  212. #define        RESUNIT_INCH        2    /* english             */
  213. #define        RESUNIT_CENTIMETER        3    /* metric             */
  214. #define    TIFFTAG_PAGENUMBER        297    /* page numbers of multi-page*/
  215. #define    TIFFTAG_COLORRESPONSEUNIT    300    /* color scale curve accuracy*/
  216. #define        COLORRESPONSEUNIT_10S    1    /* tenths of a unit         */
  217. #define        COLORRESPONSEUNIT_100S    2    /* hundredths of a unit         */
  218. #define        COLORRESPONSEUNIT_1000S    3    /* thousandths of a unit     */
  219. #define        COLORRESPONSEUNIT_10000S    4    /* ten-thousandths of a unit */
  220. #define        COLORRESPONSEUNIT_100000S    5    /* hundred-thousandths         */
  221.  
  222. #define    TIFFTAG_COLORRESPONSECURVE    301    /* RGB response curve         */
  223. #define    TIFFTAG_SOFTWARE        305    /* name & release         */
  224. #define    TIFFTAG_DATETIME        306    /* creation date and time    */
  225. #define    TIFFTAG_ARTIST            315    /* creator of image         */
  226. #define    TIFFTAG_HOSTCOMPUTER        316    /* machine where created     */
  227. #define    TIFFTAG_PREDICTOR        317    /* prediction scheme w/ LZW  */
  228. #define    TIFFTAG_WHITEPOINT        318    /* image white point         */
  229. #define    TIFFTAG_PRIMARYCHROMATICITIES    319    /* primary chromaticities    */
  230. #define    TIFFTAG_COLORMAP        320    /* RGB map for pallette image*/
  231. #define    TIFFTAG_BADFAXLINES        326    /* lines w/ wrong pixel count*/
  232. #define    TIFFTAG_CLEANFAXDATA        327    /* regenerated line info     */
  233. #define         CLEANFAXDATA_CLEAN        0    /* no errors detected          */
  234. #define         CLEANFAXDATA_REGENERATED    1    /* receiver regenerated lines*/
  235. #define         CLEANFAXDATA_UNCLEAN    2    /* uncorrected errors exist  */
  236. #define    TIFFTAG_CONSECUTIVEBADFAXLINES    328    /* max consecutive bad lines */
  237.  
  238.         /* tags 32995-32999 are private tags registered to SGI          */
  239. #define    TIFFTAG_MATTEING        32995    /* alpha channel is present  */
  240.  
  241. #endif /* _TIFF_ */
  242.