lib/DtHelp/il: remove register keyword
[oweals/cde.git] / cde / lib / DtHelp / il / iltiffint.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: iltiffint.h /main/4 1995/12/19 16:55:04 cde-dec $ */
24 #ifndef ILTIFFINT_H
25 #define ILTIFFINT_H
26
27      /* PRIVATE definitions shared between /ilc/iltiff*.c files.
28         NO OTHER CODE SHOULD INCLUDE THIS FILE !
29      */
30 #ifndef ILINT_H
31 #include "ilint.h"
32 #endif
33 #ifndef ILFILE_H
34 #include "ilfile.h"
35 #endif
36
37 #ifdef DTLIB
38 /* Used when this header is compiled into the DtHelp library */
39 #include "GraphicsP.h"
40 #endif /* DTLIB */
41
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.
52     */
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
56
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).
60     */
61 IL_EXTERN int _ilTagTypeItemSizes [];
62
63 IL_EXTERN int _ilTagTypeItemsThatFit [];
64
65     /*  How a file image relates to its brethren. */
66 typedef enum {mainImage, childImage, maskImage} ilFileImageRelation;
67
68     /*  One TIFF file tag, as it appears in a TIFF file. */
69 typedef struct {
70     unsigned short      number;
71     unsigned short      type;
72 /* compatibility problem with long and unsigned long data fields */
73     CARD32              length;
74     union {
75         char            chars[4];
76         unsigned short  shorts[2];
77 /* compatibility problem with long and unsigned long data fields */
78         INT32           aLong;
79         CARD32          offset;
80         } data;
81     } ilTIFFTagRec, *ilTIFFTagPtr;
82
83 #define IL_TAG_SIZE (sizeof (ilTIFFTagRec))
84
85
86 typedef CARD32        ilFileOffset;         /* a file offset, i.e. byte location */
87
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.
91     */
92 typedef struct {
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;
99
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.
106     */
107 typedef struct _ilFileRec {
108     ilObjectRec         o;                  /* std header: MUST BE FIRST */
109 #ifdef DTLIB
110     /* Used when this header is compiled into the DtHelp library */
111     _DtGrStream         *stream;             /* stream handle */
112 #else
113     FILE                *stream;             /* stdio file handle */
114 #endif /* DTLIB */
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;
122
123
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.
128     */
129 /* compatibility problem with long and unsigned long data fields */
130 #define IL_FLIP_LONG(_bigEndian, _4b, _long) {  \
131     CARD32 _l;                  \
132     if (_bigEndian) {                           \
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);                \
137         }                                       \
138     else {                                      \
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);                \
143         }                                       \
144     (_long) = _l;                               \
145     }
146
147     /*  Same for a short.
148     */
149 #define IL_FLIP_SHORT(_bigEndian, _2b, _short) {\
150     unsigned short _s;                 \
151     if (_bigEndian) {                           \
152         _s = *((ilPtr)(_2b)+0); _s <<= 8;       \
153         _s |= *((ilPtr)(_2b)+1);                \
154         }                                       \
155     else {                                      \
156         _s = *((ilPtr)(_2b)+1); _s <<= 8;       \
157         _s |= *((ilPtr)(_2b)+0);                \
158         }                                       \
159     (_short) = _s;                              \
160     }
161
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 successful, else false.
165     */
166 #ifdef DTLIB
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 )
170 #else
171 #define IL_SEEK(_pFile, _offset) \
172     ( fseek ((_pFile)->stream, (_pFile)->offset + (_offset), 0) == 0 )
173 #endif /* DTLIB */
174
175     /*  Read the given number of bytes into the given buffer.
176         All read macros return true if read successful, else false.
177     */
178 #ifdef DTLIB
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) ? \
182       TRUE : FALSE )
183 #else
184 #define IL_READ(_pFile, _nBytes, _pBuffer) \
185     ( (_DtGrRead ((char *)(_pBuffer), _nBytes, 1, (_pFile)->stream) == 1) ? \
186       TRUE : FALSE )
187 #endif /* DTLIB */
188
189     /*  Write the given number of bytes into the given buffer.
190         Returns true if read successful, else false.
191     */
192 #define IL_WRITE(_pFile, _nBytes, _pBuffer) \
193     ( (fwrite ((char *)(_pBuffer), _nBytes, 1, (_pFile)->stream) == 1) ? \
194       TRUE : FALSE )
195
196
197 #endif