iltiffint.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. /* PRIVATE definitions shared between /ilc/iltiff*.c files.
  27. NO OTHER CODE SHOULD INCLUDE THIS FILE !
  28. */
  29. #ifndef ILINT_H
  30. #include "ilint.h"
  31. #endif
  32. #ifndef ILFILE_H
  33. #include "ilfile.h"
  34. #endif
  35. #ifdef DTLIB
  36. /* Used when this header is compiled into the DtHelp library */
  37. #include "GraphicsP.h"
  38. #endif /* DTLIB */
  39. /* Defines for values of tag IL_TAG_PRIVATE_0 (34209). This is a private tag
  40. read and (sometimes) written by the IL. The tag is extensible; it is variable
  41. length, and the data in the tag depends on the flags. The values are always
  42. an array of shorts, as follows:
  43. IL_TAG_P0_FLAGS array of 16 bits. Only bit 0 is defined as follows;
  44. all other bits must be zero:
  45. IL_TAG_P0_FLAG_DITHER_LEVELS ignored if the image is not a palette image; else
  46. image was dithered / error diffused. The red/green/blue
  47. levels are stored in offsets 1..3; tag must be at least
  48. IL_TAG_P0_DITHER_LEVELS_LENGTH shorts long.
  49. */
  50. #define IL_TAG_P0_FLAGS 0
  51. #define IL_TAG_P0_FLAG_DITHER_LEVELS (1<<0)
  52. #define IL_TAG_P0_DITHER_LEVELS_LENGTH 4
  53. /* Size in bytes of one item (# items = TIFF "length"), for each TIFF tag type.
  54. Also, # of entries of that type which fit in one long.
  55. Indexed by tag type = 1..IL_MAX_TAG_TYPE (0 entry unused).
  56. */
  57. IL_EXTERN int _ilTagTypeItemSizes [];
  58. IL_EXTERN int _ilTagTypeItemsThatFit [];
  59. /* How a file image relates to its brethren. */
  60. typedef enum {mainImage, childImage, maskImage} ilFileImageRelation;
  61. /* One TIFF file tag, as it appears in a TIFF file. */
  62. typedef struct {
  63. unsigned short number;
  64. unsigned short type;
  65. /* compatibility problem with long and unsigned long data fields */
  66. CARD32 length;
  67. union {
  68. char chars[4];
  69. unsigned short shorts[2];
  70. /* compatibility problem with long and unsigned long data fields */
  71. INT32 aLong;
  72. CARD32 offset;
  73. } data;
  74. } ilTIFFTagRec, *ilTIFFTagPtr;
  75. #define IL_TAG_SIZE (sizeof (ilTIFFTagRec))
  76. typedef CARD32 ilFileOffset; /* a file offset, i.e. byte location */
  77. /* Private definition of object ilFileImage.
  78. This identifies one "IFD" = Image File Directory - not a directory at all,
  79. it is the header for a file image: # of tags, list of tags, offset to next IFD.
  80. */
  81. typedef struct {
  82. ilFileImagePublicRec p; /* public part: MUST BE FIRST */
  83. ilContext context; /* context for this file image */
  84. ilFileImageRelation imageType; /* main/child/maskImage */
  85. short tagCount; /* # of tags for this image */
  86. ilFileOffset tagOffset; /* file offset to first tag */
  87. } ilFileImageRec, *ilFileImagePtr;
  88. /* Private definition of object ilFile.
  89. The file exists at byte offset "offset" within "*file".
  90. See the TIFF spec for a description of TIFF tiles.
  91. "haveImageList" is true iff there is a *valid* image list;
  92. there may be a non-null list if false. The list is invalidated
  93. when a write to the file is done.
  94. */
  95. typedef struct _ilFileRec {
  96. ilObjectRec o; /* std header: MUST BE FIRST */
  97. #ifdef DTLIB
  98. /* Used when this header is compiled into the DtHelp library */
  99. _DtGrStream *stream; /* stream handle */
  100. #else
  101. FILE *stream; /* stdio file handle */
  102. #endif /* DTLIB */
  103. ilFileOffset offset; /* offset to start of TIFF data within file */
  104. ilBool bigEndian; /* true: "MM" file; false: "II" file */
  105. ilFileOffset IFDTailPtrOffset; /* offset of last IFD ptr */
  106. ilBool haveImageList; /* see above */
  107. ilFileImagePtr pFileImageHead,
  108. pFileImageTail; /* ptr to head/tail of file image list */
  109. } ilFileRec, *ilFilePtr;
  110. /* Converts the 4 TIFF bytes at "_4b" to a long, returned to the long "_long",
  111. based on the byte order specified by "_bigEndian" (TRUE == Motorola order).
  112. Note that the 4 bytes are not necessarily on a long boundary,
  113. so they must be shifted up in case long alignment is required.
  114. */
  115. /* compatibility problem with long and unsigned long data fields */
  116. #define IL_FLIP_LONG(_bigEndian, _4b, _long) { \
  117. CARD32 _l; \
  118. if (_bigEndian) { \
  119. _l = *((ilPtr)(_4b)+0); _l <<= 8; \
  120. _l |= *((ilPtr)(_4b)+1); _l <<= 8; \
  121. _l |= *((ilPtr)(_4b)+2); _l <<= 8; \
  122. _l |= *((ilPtr)(_4b)+3); \
  123. } \
  124. else { \
  125. _l = *((ilPtr)(_4b)+3); _l <<= 8; \
  126. _l |= *((ilPtr)(_4b)+2); _l <<= 8; \
  127. _l |= *((ilPtr)(_4b)+1); _l <<= 8; \
  128. _l |= *((ilPtr)(_4b)+0); \
  129. } \
  130. (_long) = _l; \
  131. }
  132. /* Same for a short.
  133. */
  134. #define IL_FLIP_SHORT(_bigEndian, _2b, _short) {\
  135. unsigned short _s; \
  136. if (_bigEndian) { \
  137. _s = *((ilPtr)(_2b)+0); _s <<= 8; \
  138. _s |= *((ilPtr)(_2b)+1); \
  139. } \
  140. else { \
  141. _s = *((ilPtr)(_2b)+1); _s <<= 8; \
  142. _s |= *((ilPtr)(_2b)+0); \
  143. } \
  144. (_short) = _s; \
  145. }
  146. /* Seek to the given offset within the given file, taking into
  147. account the offset at which the logical file begins.
  148. Returns true if seek successful, else false.
  149. */
  150. #ifdef DTLIB
  151. /* Used when this header is compiled into the DtHelp library */
  152. #define IL_SEEK(_pFile, _offset) \
  153. ( _DtGrSeek ((_pFile)->stream, (_pFile)->offset + (_offset), 0) == 0 )
  154. #else
  155. #define IL_SEEK(_pFile, _offset) \
  156. ( fseek ((_pFile)->stream, (_pFile)->offset + (_offset), 0) == 0 )
  157. #endif /* DTLIB */
  158. /* Read the given number of bytes into the given buffer.
  159. All read macros return true if read successful, else false.
  160. */
  161. #ifdef DTLIB
  162. /* Used when this header is compiled into the DtHelp library */
  163. #define IL_READ(_pFile, _nBytes, _pBuffer) \
  164. ( (_DtGrRead ((char *)(_pBuffer), _nBytes, 1, (_pFile)->stream) == 1) ? \
  165. TRUE : FALSE )
  166. #else
  167. #define IL_READ(_pFile, _nBytes, _pBuffer) \
  168. ( (_DtGrRead ((char *)(_pBuffer), _nBytes, 1, (_pFile)->stream) == 1) ? \
  169. TRUE : FALSE )
  170. #endif /* DTLIB */
  171. /* Write the given number of bytes into the given buffer.
  172. Returns true if read successful, else false.
  173. */
  174. #define IL_WRITE(_pFile, _nBytes, _pBuffer) \
  175. ( (fwrite ((char *)(_pBuffer), _nBytes, 1, (_pFile)->stream) == 1) ? \
  176. TRUE : FALSE )
  177. #endif