Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / lib / DtHelp / il / iltiffint.h
1 /* $XConsortium: iltiffint.h /main/4 1995/12/19 16:55:04 cde-dec $ */
2 #ifndef ILTIFFINT_H
3 #define ILTIFFINT_H
4
5      /* PRIVATE definitions shared between /ilc/iltiff*.c files.
6         NO OTHER CODE SHOULD INCLUDE THIS FILE !
7      */
8 #ifndef ILINT_H
9 #include "ilint.h"
10 #endif
11 #ifndef ILFILE_H
12 #include "ilfile.h"
13 #endif
14
15 #ifdef DTLIB
16 /* Used when this header is compiled into the DtHelp library */
17 #include "GraphicsP.h"
18 #endif /* DTLIB */
19
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.
30     */
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
34
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).
38     */
39 IL_EXTERN int _ilTagTypeItemSizes [];
40
41 IL_EXTERN int _ilTagTypeItemsThatFit [];
42
43     /*  How a file image relates to its brethren. */
44 typedef enum {mainImage, childImage, maskImage} ilFileImageRelation;
45
46     /*  One TIFF file tag, as it appears in a TIFF file. */
47 typedef struct {
48     unsigned short      number;
49     unsigned short      type;
50 /* compatibility problem with long and unsigned long data fields */
51     CARD32              length;
52     union {
53         char            chars[4];
54         unsigned short  shorts[2];
55 /* compatibility problem with long and unsigned long data fields */
56         INT32           aLong;
57         CARD32          offset;
58         } data;
59     } ilTIFFTagRec, *ilTIFFTagPtr;
60
61 #define IL_TAG_SIZE (sizeof (ilTIFFTagRec))
62
63
64 typedef CARD32        ilFileOffset;         /* a file offset, i.e. byte location */
65
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.
69     */
70 typedef struct {
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;
77
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.
84     */
85 typedef struct _ilFileRec {
86     ilObjectRec         o;                  /* std header: MUST BE FIRST */
87 #ifdef DTLIB
88     /* Used when this header is compiled into the DtHelp library */
89     _DtGrStream         *stream;             /* stream handle */
90 #else
91     FILE                *stream;             /* stdio file handle */
92 #endif /* DTLIB */
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;
100
101
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.
106     */
107 /* compatibility problem with long and unsigned long data fields */
108 #define IL_FLIP_LONG(_bigEndian, _4b, _long) {  \
109     register CARD32 _l;                  \
110     if (_bigEndian) {                           \
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);                \
115         }                                       \
116     else {                                      \
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);                \
121         }                                       \
122     (_long) = _l;                               \
123     }
124
125     /*  Same for a short.
126     */
127 #define IL_FLIP_SHORT(_bigEndian, _2b, _short) {\
128     register unsigned short _s;                 \
129     if (_bigEndian) {                           \
130         _s = *((ilPtr)(_2b)+0); _s <<= 8;       \
131         _s |= *((ilPtr)(_2b)+1);                \
132         }                                       \
133     else {                                      \
134         _s = *((ilPtr)(_2b)+1); _s <<= 8;       \
135         _s |= *((ilPtr)(_2b)+0);                \
136         }                                       \
137     (_short) = _s;                              \
138     }
139
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.
143     */
144 #ifdef DTLIB
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 )
148 #else
149 #define IL_SEEK(_pFile, _offset) \
150     ( fseek ((_pFile)->stream, (_pFile)->offset + (_offset), 0) == 0 )
151 #endif /* DTLIB */
152
153     /*  Read the given number of bytes into the given buffer.
154         All read macros return true if read successful, else false.
155     */
156 #ifdef DTLIB
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) ? \
160       TRUE : FALSE )
161 #else
162 #define IL_READ(_pFile, _nBytes, _pBuffer) \
163     ( (_DtGrRead ((char *)(_pBuffer), _nBytes, 1, (_pFile)->stream) == 1) ? \
164       TRUE : FALSE )
165 #endif /* DTLIB */
166
167     /*  Write the given number of bytes into the given buffer.
168         Returns true if read successful, else false.
169     */
170 #define IL_WRITE(_pFile, _nBytes, _pBuffer) \
171     ( (fwrite ((char *)(_pBuffer), _nBytes, 1, (_pFile)->stream) == 1) ? \
172       TRUE : FALSE )
173
174
175 #endif