2
0

tif_dir.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /* $Id: tif_dir.h,v 1.54 2011-02-18 20:53:05 fwarmerdam Exp $ */
  2. /*
  3. * Copyright (c) 1988-1997 Sam Leffler
  4. * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  5. *
  6. * Permission to use, copy, modify, distribute, and sell this software and
  7. * its documentation for any purpose is hereby granted without fee, provided
  8. * that (i) the above copyright notices and this permission notice appear in
  9. * all copies of the software and related documentation, and (ii) the names of
  10. * Sam Leffler and Silicon Graphics may not be used in any advertising or
  11. * publicity relating to the software without the specific, prior written
  12. * permission of Sam Leffler and Silicon Graphics.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  15. * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  16. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  17. *
  18. * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  19. * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
  22. * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  23. * OF THIS SOFTWARE.
  24. */
  25. #ifndef _TIFFDIR_
  26. #define _TIFFDIR_
  27. /*
  28. * ``Library-private'' Directory-related Definitions.
  29. */
  30. typedef struct {
  31. const TIFFField *info;
  32. int count;
  33. void *value;
  34. } TIFFTagValue;
  35. /*
  36. * TIFF Image File Directories are comprised of a table of field
  37. * descriptors of the form shown below. The table is sorted in
  38. * ascending order by tag. The values associated with each entry are
  39. * disjoint and may appear anywhere in the file (so long as they are
  40. * placed on a word boundary).
  41. *
  42. * If the value is 4 bytes or less, in ClassicTIFF, or 8 bytes or less in
  43. * BigTIFF, then it is placed in the offset field to save space. If so,
  44. * it is left-justified in the offset field.
  45. */
  46. typedef struct {
  47. uint16 tdir_tag; /* see below */
  48. uint16 tdir_type; /* data type; see below */
  49. uint64 tdir_count; /* number of items; length in spec */
  50. union {
  51. uint16 toff_short;
  52. uint32 toff_long;
  53. uint64 toff_long8;
  54. } tdir_offset; /* either offset or the data itself if fits */
  55. } TIFFDirEntry;
  56. /*
  57. * Internal format of a TIFF directory entry.
  58. */
  59. typedef struct {
  60. #define FIELD_SETLONGS 4
  61. /* bit vector of fields that are set */
  62. unsigned long td_fieldsset[FIELD_SETLONGS];
  63. uint32 td_imagewidth, td_imagelength, td_imagedepth;
  64. uint32 td_tilewidth, td_tilelength, td_tiledepth;
  65. uint32 td_subfiletype;
  66. uint16 td_bitspersample;
  67. uint16 td_sampleformat;
  68. uint16 td_compression;
  69. uint16 td_photometric;
  70. uint16 td_threshholding;
  71. uint16 td_fillorder;
  72. uint16 td_orientation;
  73. uint16 td_samplesperpixel;
  74. uint32 td_rowsperstrip;
  75. uint16 td_minsamplevalue, td_maxsamplevalue;
  76. double* td_sminsamplevalue;
  77. double* td_smaxsamplevalue;
  78. float td_xresolution, td_yresolution;
  79. uint16 td_resolutionunit;
  80. uint16 td_planarconfig;
  81. float td_xposition, td_yposition;
  82. uint16 td_pagenumber[2];
  83. uint16* td_colormap[3];
  84. uint16 td_halftonehints[2];
  85. uint16 td_extrasamples;
  86. uint16* td_sampleinfo;
  87. /* even though the name is misleading, td_stripsperimage is the number
  88. * of striles (=strips or tiles) per plane, and td_nstrips the total
  89. * number of striles */
  90. uint32 td_stripsperimage;
  91. uint32 td_nstrips; /* size of offset & bytecount arrays */
  92. uint64* td_stripoffset;
  93. uint64* td_stripbytecount;
  94. int td_stripbytecountsorted; /* is the bytecount array sorted ascending? */
  95. #if defined(DEFER_STRILE_LOAD)
  96. TIFFDirEntry td_stripoffset_entry; /* for deferred loading */
  97. TIFFDirEntry td_stripbytecount_entry; /* for deferred loading */
  98. #endif
  99. uint16 td_nsubifd;
  100. uint64* td_subifd;
  101. /* YCbCr parameters */
  102. uint16 td_ycbcrsubsampling[2];
  103. uint16 td_ycbcrpositioning;
  104. /* Colorimetry parameters */
  105. uint16* td_transferfunction[3];
  106. float* td_refblackwhite;
  107. /* CMYK parameters */
  108. int td_inknameslen;
  109. char* td_inknames;
  110. int td_customValueCount;
  111. TIFFTagValue *td_customValues;
  112. } TIFFDirectory;
  113. /*
  114. * Field flags used to indicate fields that have been set in a directory, and
  115. * to reference fields when manipulating a directory.
  116. */
  117. /*
  118. * FIELD_IGNORE is used to signify tags that are to be processed but otherwise
  119. * ignored. This permits antiquated tags to be quietly read and discarded.
  120. * Note that a bit *is* allocated for ignored tags; this is understood by the
  121. * directory reading logic which uses this fact to avoid special-case handling
  122. */
  123. #define FIELD_IGNORE 0
  124. /* multi-item fields */
  125. #define FIELD_IMAGEDIMENSIONS 1
  126. #define FIELD_TILEDIMENSIONS 2
  127. #define FIELD_RESOLUTION 3
  128. #define FIELD_POSITION 4
  129. /* single-item fields */
  130. #define FIELD_SUBFILETYPE 5
  131. #define FIELD_BITSPERSAMPLE 6
  132. #define FIELD_COMPRESSION 7
  133. #define FIELD_PHOTOMETRIC 8
  134. #define FIELD_THRESHHOLDING 9
  135. #define FIELD_FILLORDER 10
  136. #define FIELD_ORIENTATION 15
  137. #define FIELD_SAMPLESPERPIXEL 16
  138. #define FIELD_ROWSPERSTRIP 17
  139. #define FIELD_MINSAMPLEVALUE 18
  140. #define FIELD_MAXSAMPLEVALUE 19
  141. #define FIELD_PLANARCONFIG 20
  142. #define FIELD_RESOLUTIONUNIT 22
  143. #define FIELD_PAGENUMBER 23
  144. #define FIELD_STRIPBYTECOUNTS 24
  145. #define FIELD_STRIPOFFSETS 25
  146. #define FIELD_COLORMAP 26
  147. #define FIELD_EXTRASAMPLES 31
  148. #define FIELD_SAMPLEFORMAT 32
  149. #define FIELD_SMINSAMPLEVALUE 33
  150. #define FIELD_SMAXSAMPLEVALUE 34
  151. #define FIELD_IMAGEDEPTH 35
  152. #define FIELD_TILEDEPTH 36
  153. #define FIELD_HALFTONEHINTS 37
  154. #define FIELD_YCBCRSUBSAMPLING 39
  155. #define FIELD_YCBCRPOSITIONING 40
  156. #define FIELD_REFBLACKWHITE 41
  157. #define FIELD_TRANSFERFUNCTION 44
  158. #define FIELD_INKNAMES 46
  159. #define FIELD_SUBIFD 49
  160. /* FIELD_CUSTOM (see tiffio.h) 65 */
  161. /* end of support for well-known tags; codec-private tags follow */
  162. #define FIELD_CODEC 66 /* base of codec-private tags */
  163. /*
  164. * Pseudo-tags don't normally need field bits since they are not written to an
  165. * output file (by definition). The library also has express logic to always
  166. * query a codec for a pseudo-tag so allocating a field bit for one is a
  167. * waste. If codec wants to promote the notion of a pseudo-tag being ``set''
  168. * or ``unset'' then it can do using internal state flags without polluting
  169. * the field bit space defined for real tags.
  170. */
  171. #define FIELD_PSEUDO 0
  172. #define FIELD_LAST (32*FIELD_SETLONGS-1)
  173. #define BITn(n) (((unsigned long)1L)<<((n)&0x1f))
  174. #define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n)/32])
  175. #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  176. #define TIFFSetFieldBit(tif, field) (BITFIELDn(tif, field) |= BITn(field))
  177. #define TIFFClrFieldBit(tif, field) (BITFIELDn(tif, field) &= ~BITn(field))
  178. #define FieldSet(fields, f) (fields[(f)/32] & BITn(f))
  179. #define ResetFieldBit(fields, f) (fields[(f)/32] &= ~BITn(f))
  180. typedef enum {
  181. TIFF_SETGET_UNDEFINED = 0,
  182. TIFF_SETGET_ASCII = 1,
  183. TIFF_SETGET_UINT8 = 2,
  184. TIFF_SETGET_SINT8 = 3,
  185. TIFF_SETGET_UINT16 = 4,
  186. TIFF_SETGET_SINT16 = 5,
  187. TIFF_SETGET_UINT32 = 6,
  188. TIFF_SETGET_SINT32 = 7,
  189. TIFF_SETGET_UINT64 = 8,
  190. TIFF_SETGET_SINT64 = 9,
  191. TIFF_SETGET_FLOAT = 10,
  192. TIFF_SETGET_DOUBLE = 11,
  193. TIFF_SETGET_IFD8 = 12,
  194. TIFF_SETGET_INT = 13,
  195. TIFF_SETGET_UINT16_PAIR = 14,
  196. TIFF_SETGET_C0_ASCII = 15,
  197. TIFF_SETGET_C0_UINT8 = 16,
  198. TIFF_SETGET_C0_SINT8 = 17,
  199. TIFF_SETGET_C0_UINT16 = 18,
  200. TIFF_SETGET_C0_SINT16 = 19,
  201. TIFF_SETGET_C0_UINT32 = 20,
  202. TIFF_SETGET_C0_SINT32 = 21,
  203. TIFF_SETGET_C0_UINT64 = 22,
  204. TIFF_SETGET_C0_SINT64 = 23,
  205. TIFF_SETGET_C0_FLOAT = 24,
  206. TIFF_SETGET_C0_DOUBLE = 25,
  207. TIFF_SETGET_C0_IFD8 = 26,
  208. TIFF_SETGET_C16_ASCII = 27,
  209. TIFF_SETGET_C16_UINT8 = 28,
  210. TIFF_SETGET_C16_SINT8 = 29,
  211. TIFF_SETGET_C16_UINT16 = 30,
  212. TIFF_SETGET_C16_SINT16 = 31,
  213. TIFF_SETGET_C16_UINT32 = 32,
  214. TIFF_SETGET_C16_SINT32 = 33,
  215. TIFF_SETGET_C16_UINT64 = 34,
  216. TIFF_SETGET_C16_SINT64 = 35,
  217. TIFF_SETGET_C16_FLOAT = 36,
  218. TIFF_SETGET_C16_DOUBLE = 37,
  219. TIFF_SETGET_C16_IFD8 = 38,
  220. TIFF_SETGET_C32_ASCII = 39,
  221. TIFF_SETGET_C32_UINT8 = 40,
  222. TIFF_SETGET_C32_SINT8 = 41,
  223. TIFF_SETGET_C32_UINT16 = 42,
  224. TIFF_SETGET_C32_SINT16 = 43,
  225. TIFF_SETGET_C32_UINT32 = 44,
  226. TIFF_SETGET_C32_SINT32 = 45,
  227. TIFF_SETGET_C32_UINT64 = 46,
  228. TIFF_SETGET_C32_SINT64 = 47,
  229. TIFF_SETGET_C32_FLOAT = 48,
  230. TIFF_SETGET_C32_DOUBLE = 49,
  231. TIFF_SETGET_C32_IFD8 = 50,
  232. TIFF_SETGET_OTHER = 51
  233. } TIFFSetGetFieldType;
  234. #if defined(__cplusplus)
  235. extern "C" {
  236. #endif
  237. extern const TIFFFieldArray* _TIFFGetFields(void);
  238. extern const TIFFFieldArray* _TIFFGetExifFields(void);
  239. extern void _TIFFSetupFields(TIFF* tif, const TIFFFieldArray* infoarray);
  240. extern void _TIFFPrintFieldInfo(TIFF*, FILE*);
  241. extern int _TIFFFillStriles(TIFF*);
  242. typedef enum {
  243. tfiatImage,
  244. tfiatExif,
  245. tfiatOther
  246. } TIFFFieldArrayType;
  247. struct _TIFFFieldArray {
  248. TIFFFieldArrayType type; /* array type, will be used to determine if IFD is image and such */
  249. uint32 allocated_size; /* 0 if array is constant, other if modified by future definition extension support */
  250. uint32 count; /* number of elements in fields array */
  251. TIFFField* fields; /* actual field info */
  252. };
  253. struct _TIFFField {
  254. uint32 field_tag; /* field's tag */
  255. short field_readcount; /* read count/TIFF_VARIABLE/TIFF_SPP */
  256. short field_writecount; /* write count/TIFF_VARIABLE */
  257. TIFFDataType field_type; /* type of associated data */
  258. uint32 reserved; /* reserved for future extension */
  259. TIFFSetGetFieldType set_field_type; /* type to be passed to TIFFSetField */
  260. TIFFSetGetFieldType get_field_type; /* type to be passed to TIFFGetField */
  261. unsigned short field_bit; /* bit in fieldsset bit vector */
  262. unsigned char field_oktochange; /* if true, can change while writing */
  263. unsigned char field_passcount; /* if true, pass dir count on set */
  264. char* field_name; /* ASCII name */
  265. TIFFFieldArray* field_subfields; /* if field points to child ifds, child ifd field definition array */
  266. };
  267. extern int _TIFFMergeFields(TIFF*, const TIFFField[], uint32);
  268. extern const TIFFField* _TIFFFindOrRegisterField(TIFF *, uint32, TIFFDataType);
  269. extern TIFFField* _TIFFCreateAnonField(TIFF *, uint32, TIFFDataType);
  270. #if defined(__cplusplus)
  271. }
  272. #endif
  273. #endif /* _TIFFDIR_ */
  274. /* vim: set ts=8 sts=8 sw=8 noet: */
  275. /*
  276. * Local Variables:
  277. * mode: c
  278. * c-basic-offset: 8
  279. * fill-column: 78
  280. * End:
  281. */