1 /* $XConsortium: iltiffint.h /main/4 1995/12/19 16:55:04 cde-dec $ */
5 /* PRIVATE definitions shared between /ilc/iltiff*.c files.
6 NO OTHER CODE SHOULD INCLUDE THIS FILE !
16 /* Used when this header is compiled into the DtHelp library */
17 #include "GraphicsP.h"
20 /* Defines for values of tag IL_TAG_PRIVATE_0 (34209). This is a private tag
21 read and (sometimes) written by the IL. The tag is extensible; it is variable
22 length, and the data in the tag depends on the flags. The values are always
23 an array of shorts, as follows:
24 IL_TAG_P0_FLAGS array of 16 bits. Only bit 0 is defined as follows;
25 all other bits must be zero:
26 IL_TAG_P0_FLAG_DITHER_LEVELS ignored if the image is not a palette image; else
27 image was dithered / error diffused. The red/green/blue
28 levels are stored in offsets 1..3; tag must be at least
29 IL_TAG_P0_DITHER_LEVELS_LENGTH shorts long.
31 #define IL_TAG_P0_FLAGS 0
32 #define IL_TAG_P0_FLAG_DITHER_LEVELS (1<<0)
33 #define IL_TAG_P0_DITHER_LEVELS_LENGTH 4
35 /* Size in bytes of one item (# items = TIFF "length"), for each TIFF tag type.
36 Also, # of entries of that type which fit in one long.
37 Indexed by tag type = 1..IL_MAX_TAG_TYPE (0 entry unused).
39 IL_EXTERN int _ilTagTypeItemSizes [];
41 IL_EXTERN int _ilTagTypeItemsThatFit [];
43 /* How a file image relates to its brethren. */
44 typedef enum {mainImage, childImage, maskImage} ilFileImageRelation;
46 /* One TIFF file tag, as it appears in a TIFF file. */
48 unsigned short number;
50 /* compatibility problem with long and unsigned long data fields */
54 unsigned short shorts[2];
55 /* compatibility problem with long and unsigned long data fields */
59 } ilTIFFTagRec, *ilTIFFTagPtr;
61 #define IL_TAG_SIZE (sizeof (ilTIFFTagRec))
64 typedef CARD32 ilFileOffset; /* a file offset, i.e. byte location */
66 /* Private definition of object ilFileImage.
67 This identifies one "IFD" = Image File Directory - not a directory at all,
68 it is the header for a file image: # of tags, list of tags, offset to next IFD.
71 ilFileImagePublicRec p; /* public part: MUST BE FIRST */
72 ilContext context; /* context for this file image */
73 ilFileImageRelation imageType; /* main/child/maskImage */
74 short tagCount; /* # of tags for this image */
75 ilFileOffset tagOffset; /* file offset to first tag */
76 } ilFileImageRec, *ilFileImagePtr;
78 /* Private definition of object ilFile.
79 The file exists at byte offset "offset" within "*file".
80 See the TIFF spec for a description of TIFF tiles.
81 "haveImageList" is true iff there is a *valid* image list;
82 there may be a non-null list if false. The list is invalidated
83 when a write to the file is done.
85 typedef struct _ilFileRec {
86 ilObjectRec o; /* std header: MUST BE FIRST */
88 /* Used when this header is compiled into the DtHelp library */
89 _DtGrStream *stream; /* stream handle */
91 FILE *stream; /* stdio file handle */
93 ilFileOffset offset; /* offset to start of TIFF data within file */
94 ilBool bigEndian; /* true: "MM" file; false: "II" file */
95 ilFileOffset IFDTailPtrOffset; /* offset of last IFD ptr */
96 ilBool haveImageList; /* see above */
97 ilFileImagePtr pFileImageHead,
98 pFileImageTail; /* ptr to head/tail of file image list */
99 } ilFileRec, *ilFilePtr;
102 /* Converts the 4 TIFF bytes at "_4b" to a long, returned to the long "_long",
103 based on the byte order specified by "_bigEndian" (TRUE == Motorola order).
104 Note that the 4 bytes are not necessarily on a long boundary,
105 so they must be shifted up in case long alignment is required.
107 /* compatibility problem with long and unsigned long data fields */
108 #define IL_FLIP_LONG(_bigEndian, _4b, _long) { \
109 register CARD32 _l; \
111 _l = *((ilPtr)(_4b)+0); _l <<= 8; \
112 _l |= *((ilPtr)(_4b)+1); _l <<= 8; \
113 _l |= *((ilPtr)(_4b)+2); _l <<= 8; \
114 _l |= *((ilPtr)(_4b)+3); \
117 _l = *((ilPtr)(_4b)+3); _l <<= 8; \
118 _l |= *((ilPtr)(_4b)+2); _l <<= 8; \
119 _l |= *((ilPtr)(_4b)+1); _l <<= 8; \
120 _l |= *((ilPtr)(_4b)+0); \
127 #define IL_FLIP_SHORT(_bigEndian, _2b, _short) {\
128 register unsigned short _s; \
130 _s = *((ilPtr)(_2b)+0); _s <<= 8; \
131 _s |= *((ilPtr)(_2b)+1); \
134 _s = *((ilPtr)(_2b)+1); _s <<= 8; \
135 _s |= *((ilPtr)(_2b)+0); \
140 /* Seek to the given offset within the given file, taking into
141 account the offset at which the logical file begins.
142 Returns true if seek succesful, else false.
145 /* Used when this header is compiled into the DtHelp library */
146 #define IL_SEEK(_pFile, _offset) \
147 ( _DtGrSeek ((_pFile)->stream, (_pFile)->offset + (_offset), 0) == 0 )
149 #define IL_SEEK(_pFile, _offset) \
150 ( fseek ((_pFile)->stream, (_pFile)->offset + (_offset), 0) == 0 )
153 /* Read the given number of bytes into the given buffer.
154 All read macros return true if read successful, else false.
157 /* Used when this header is compiled into the DtHelp library */
158 #define IL_READ(_pFile, _nBytes, _pBuffer) \
159 ( (_DtGrRead ((char *)(_pBuffer), _nBytes, 1, (_pFile)->stream) == 1) ? \
162 #define IL_READ(_pFile, _nBytes, _pBuffer) \
163 ( (_DtGrRead ((char *)(_pBuffer), _nBytes, 1, (_pFile)->stream) == 1) ? \
167 /* Write the given number of bytes into the given buffer.
168 Returns true if read successful, else false.
170 #define IL_WRITE(_pFile, _nBytes, _pBuffer) \
171 ( (fwrite ((char *)(_pBuffer), _nBytes, 1, (_pFile)->stream) == 1) ? \