tif_dir.h 11 KB

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