2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: iltiffint.h /main/4 1995/12/19 16:55:04 cde-dec $ */
27 /* PRIVATE definitions shared between /ilc/iltiff*.c files.
28 NO OTHER CODE SHOULD INCLUDE THIS FILE !
38 /* Used when this header is compiled into the DtHelp library */
39 #include "GraphicsP.h"
42 /* Defines for values of tag IL_TAG_PRIVATE_0 (34209). This is a private tag
43 read and (sometimes) written by the IL. The tag is extensible; it is variable
44 length, and the data in the tag depends on the flags. The values are always
45 an array of shorts, as follows:
46 IL_TAG_P0_FLAGS array of 16 bits. Only bit 0 is defined as follows;
47 all other bits must be zero:
48 IL_TAG_P0_FLAG_DITHER_LEVELS ignored if the image is not a palette image; else
49 image was dithered / error diffused. The red/green/blue
50 levels are stored in offsets 1..3; tag must be at least
51 IL_TAG_P0_DITHER_LEVELS_LENGTH shorts long.
53 #define IL_TAG_P0_FLAGS 0
54 #define IL_TAG_P0_FLAG_DITHER_LEVELS (1<<0)
55 #define IL_TAG_P0_DITHER_LEVELS_LENGTH 4
57 /* Size in bytes of one item (# items = TIFF "length"), for each TIFF tag type.
58 Also, # of entries of that type which fit in one long.
59 Indexed by tag type = 1..IL_MAX_TAG_TYPE (0 entry unused).
61 IL_EXTERN int _ilTagTypeItemSizes [];
63 IL_EXTERN int _ilTagTypeItemsThatFit [];
65 /* How a file image relates to its brethren. */
66 typedef enum {mainImage, childImage, maskImage} ilFileImageRelation;
68 /* One TIFF file tag, as it appears in a TIFF file. */
70 unsigned short number;
72 /* compatibility problem with long and unsigned long data fields */
76 unsigned short shorts[2];
77 /* compatibility problem with long and unsigned long data fields */
81 } ilTIFFTagRec, *ilTIFFTagPtr;
83 #define IL_TAG_SIZE (sizeof (ilTIFFTagRec))
86 typedef CARD32 ilFileOffset; /* a file offset, i.e. byte location */
88 /* Private definition of object ilFileImage.
89 This identifies one "IFD" = Image File Directory - not a directory at all,
90 it is the header for a file image: # of tags, list of tags, offset to next IFD.
93 ilFileImagePublicRec p; /* public part: MUST BE FIRST */
94 ilContext context; /* context for this file image */
95 ilFileImageRelation imageType; /* main/child/maskImage */
96 short tagCount; /* # of tags for this image */
97 ilFileOffset tagOffset; /* file offset to first tag */
98 } ilFileImageRec, *ilFileImagePtr;
100 /* Private definition of object ilFile.
101 The file exists at byte offset "offset" within "*file".
102 See the TIFF spec for a description of TIFF tiles.
103 "haveImageList" is true iff there is a *valid* image list;
104 there may be a non-null list if false. The list is invalidated
105 when a write to the file is done.
107 typedef struct _ilFileRec {
108 ilObjectRec o; /* std header: MUST BE FIRST */
110 /* Used when this header is compiled into the DtHelp library */
111 _DtGrStream *stream; /* stream handle */
113 FILE *stream; /* stdio file handle */
115 ilFileOffset offset; /* offset to start of TIFF data within file */
116 ilBool bigEndian; /* true: "MM" file; false: "II" file */
117 ilFileOffset IFDTailPtrOffset; /* offset of last IFD ptr */
118 ilBool haveImageList; /* see above */
119 ilFileImagePtr pFileImageHead,
120 pFileImageTail; /* ptr to head/tail of file image list */
121 } ilFileRec, *ilFilePtr;
124 /* Converts the 4 TIFF bytes at "_4b" to a long, returned to the long "_long",
125 based on the byte order specified by "_bigEndian" (TRUE == Motorola order).
126 Note that the 4 bytes are not necessarily on a long boundary,
127 so they must be shifted up in case long alignment is required.
129 /* compatibility problem with long and unsigned long data fields */
130 #define IL_FLIP_LONG(_bigEndian, _4b, _long) { \
131 register CARD32 _l; \
133 _l = *((ilPtr)(_4b)+0); _l <<= 8; \
134 _l |= *((ilPtr)(_4b)+1); _l <<= 8; \
135 _l |= *((ilPtr)(_4b)+2); _l <<= 8; \
136 _l |= *((ilPtr)(_4b)+3); \
139 _l = *((ilPtr)(_4b)+3); _l <<= 8; \
140 _l |= *((ilPtr)(_4b)+2); _l <<= 8; \
141 _l |= *((ilPtr)(_4b)+1); _l <<= 8; \
142 _l |= *((ilPtr)(_4b)+0); \
149 #define IL_FLIP_SHORT(_bigEndian, _2b, _short) {\
150 register unsigned short _s; \
152 _s = *((ilPtr)(_2b)+0); _s <<= 8; \
153 _s |= *((ilPtr)(_2b)+1); \
156 _s = *((ilPtr)(_2b)+1); _s <<= 8; \
157 _s |= *((ilPtr)(_2b)+0); \
162 /* Seek to the given offset within the given file, taking into
163 account the offset at which the logical file begins.
164 Returns true if seek succesful, else false.
167 /* Used when this header is compiled into the DtHelp library */
168 #define IL_SEEK(_pFile, _offset) \
169 ( _DtGrSeek ((_pFile)->stream, (_pFile)->offset + (_offset), 0) == 0 )
171 #define IL_SEEK(_pFile, _offset) \
172 ( fseek ((_pFile)->stream, (_pFile)->offset + (_offset), 0) == 0 )
175 /* Read the given number of bytes into the given buffer.
176 All read macros return true if read successful, else false.
179 /* Used when this header is compiled into the DtHelp library */
180 #define IL_READ(_pFile, _nBytes, _pBuffer) \
181 ( (_DtGrRead ((char *)(_pBuffer), _nBytes, 1, (_pFile)->stream) == 1) ? \
184 #define IL_READ(_pFile, _nBytes, _pBuffer) \
185 ( (_DtGrRead ((char *)(_pBuffer), _nBytes, 1, (_pFile)->stream) == 1) ? \
189 /* Write the given number of bytes into the given buffer.
190 Returns true if read successful, else false.
192 #define IL_WRITE(_pFile, _nBytes, _pBuffer) \
193 ( (fwrite ((char *)(_pBuffer), _nBytes, 1, (_pFile)->stream) == 1) ? \