imageio.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*====================================================================*
  2. - Copyright (C) 2001 Leptonica. All rights reserved.
  3. -
  4. - Redistribution and use in source and binary forms, with or without
  5. - modification, are permitted provided that the following conditions
  6. - are met:
  7. - 1. Redistributions of source code must retain the above copyright
  8. - notice, this list of conditions and the following disclaimer.
  9. - 2. Redistributions in binary form must reproduce the above
  10. - copyright notice, this list of conditions and the following
  11. - disclaimer in the documentation and/or other materials
  12. - provided with the distribution.
  13. -
  14. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
  18. - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  22. - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *====================================================================*/
  26. /*!
  27. * \file imageio.h
  28. *
  29. * <pre>
  30. * General features of image I/O in leptonica
  31. *
  32. * At present, there are 9 file formats for images that can be read
  33. * and written:
  34. * png (requires libpng, libz)
  35. * jpeg (requires libjpeg)
  36. * tiff (requires libtiff, libz)
  37. * gif (requires libgif)
  38. * webp (requires libwebp)
  39. * jp2 (requires libopenjp2)
  40. * bmp (no library required)
  41. * pnm (no library required)
  42. * spix (no library required)
  43. * Additionally, there are two file formats for writing (only) images:
  44. * PostScript (requires libpng, libz, libjpeg, libtiff)
  45. * pdf (requires libpng, libz, libjpeg, libtiff)
  46. *
  47. * For all 9 read/write formats, leptonica provides interconversion
  48. * between pix (with raster data) and formatted image data:
  49. * Conversion from pix (typically compression):
  50. * pixWrite(): pix --> file
  51. * pixWriteStream(): pix --> filestream (aka FILE*)
  52. * pixWriteMem(): pix --> memory buffer
  53. * Conversion to pix (typically decompression):
  54. * pixRead(): file --> pix
  55. * pixReadStream(): filestream --> pix
  56. * pixReadMem(): memory buffer --> pix
  57. *
  58. * Conversions for which the image data is not compressed are:
  59. * * uncompressed tiff (IFF_TIFF)
  60. * * bmp
  61. * * pnm
  62. * * spix (fast serialization that copies the pix raster data)
  63. *
  64. * The image header (metadata) information can be read from either
  65. * the compressed file or a memory buffer, for all 9 formats.
  66. * </pre>
  67. */
  68. #ifndef LEPTONICA_IMAGEIO_H
  69. #define LEPTONICA_IMAGEIO_H
  70. /* --------------------------------------------------------------- *
  71. * Image file format types *
  72. * --------------------------------------------------------------- */
  73. /*
  74. * The IFF_DEFAULT flag is used to write the file out in the
  75. * same (input) file format that the pix was read from. If the pix
  76. * was not read from file, the input format field will be
  77. * IFF_UNKNOWN and the output file format will be chosen to
  78. * be compressed and lossless; namely, IFF_TIFF_G4 for d = 1
  79. * and IFF_PNG for everything else.
  80. *
  81. * In the future, new format types that have defined extensions
  82. * will be added before IFF_DEFAULT, and will be kept in sync with
  83. * the file format extensions in writefile.c. The positions of
  84. * file formats before IFF_DEFAULT will remain invariant.
  85. */
  86. /*! Image file format types */
  87. enum {
  88. IFF_UNKNOWN = 0,
  89. IFF_BMP = 1,
  90. IFF_JFIF_JPEG = 2,
  91. IFF_PNG = 3,
  92. IFF_TIFF = 4,
  93. IFF_TIFF_PACKBITS = 5,
  94. IFF_TIFF_RLE = 6,
  95. IFF_TIFF_G3 = 7,
  96. IFF_TIFF_G4 = 8,
  97. IFF_TIFF_LZW = 9,
  98. IFF_TIFF_ZIP = 10,
  99. IFF_PNM = 11,
  100. IFF_PS = 12,
  101. IFF_GIF = 13,
  102. IFF_JP2 = 14,
  103. IFF_WEBP = 15,
  104. IFF_LPDF = 16,
  105. IFF_DEFAULT = 17,
  106. IFF_SPIX = 18
  107. };
  108. /* --------------------------------------------------------------- *
  109. * Format header ids *
  110. * --------------------------------------------------------------- */
  111. /*! Format header ids */
  112. enum {
  113. BMP_ID = 0x4d42, /*!< BM - for bitmaps */
  114. TIFF_BIGEND_ID = 0x4d4d, /*!< MM - for 'motorola' */
  115. TIFF_LITTLEEND_ID = 0x4949 /*!< II - for 'intel' */
  116. };
  117. /* --------------------------------------------------------------- *
  118. * Hinting bit flags in jpeg reader *
  119. * --------------------------------------------------------------- */
  120. /*! Hinting bit flags in jpeg reader */
  121. enum {
  122. L_JPEG_READ_LUMINANCE = 1, /*!< only want luminance data; no chroma */
  123. L_JPEG_FAIL_ON_BAD_DATA = 2 /*!< don't return possibly damaged pix */
  124. };
  125. /* --------------------------------------------------------------- *
  126. * Pdf formatted encoding types *
  127. * --------------------------------------------------------------- */
  128. /*! Pdf formatted encoding types */
  129. enum {
  130. L_DEFAULT_ENCODE = 0, /*!< use default encoding based on image */
  131. L_JPEG_ENCODE = 1, /*!< use dct encoding: 8 and 32 bpp, no cmap */
  132. L_G4_ENCODE = 2, /*!< use ccitt g4 fax encoding: 1 bpp */
  133. L_FLATE_ENCODE = 3, /*!< use flate encoding: any depth, cmap ok */
  134. L_JP2K_ENCODE = 4 /*!< use jp2k encoding: 8 and 32 bpp, no cmap */
  135. };
  136. /* --------------------------------------------------------------- *
  137. * Compressed image data *
  138. * --------------------------------------------------------------- */
  139. /*
  140. * In use, either datacomp or data85 will be produced, depending
  141. * on whether the data needs to be ascii85 encoded. PostScript
  142. * requires ascii85 encoding; pdf does not.
  143. *
  144. * For the colormap (flate compression only), PostScript uses ascii85
  145. * encoding and pdf uses a bracketed array of space-separated
  146. * hex-encoded rgb triples. Only tiff g4 (type == L_G4_ENCODE) uses
  147. * the minisblack field.
  148. */
  149. /*! Compressed image data */
  150. struct L_Compressed_Data
  151. {
  152. l_int32 type; /*!< encoding type: L_JPEG_ENCODE, etc */
  153. l_uint8 *datacomp; /*!< gzipped raster data */
  154. size_t nbytescomp; /*!< number of compressed bytes */
  155. char *data85; /*!< ascii85-encoded gzipped raster data */
  156. size_t nbytes85; /*!< number of ascii85 encoded bytes */
  157. char *cmapdata85; /*!< ascii85-encoded uncompressed cmap */
  158. char *cmapdatahex; /*!< hex pdf array for the cmap */
  159. l_int32 ncolors; /*!< number of colors in cmap */
  160. l_int32 w; /*!< image width */
  161. l_int32 h; /*!< image height */
  162. l_int32 bps; /*!< bits/sample; typ. 1, 2, 4 or 8 */
  163. l_int32 spp; /*!< samples/pixel; typ. 1 or 3 */
  164. l_int32 minisblack; /*!< tiff g4 photometry */
  165. l_int32 predictor; /*!< flate data has PNG predictors */
  166. size_t nbytes; /*!< number of uncompressed raster bytes */
  167. l_int32 res; /*!< resolution (ppi) */
  168. };
  169. typedef struct L_Compressed_Data L_COMP_DATA;
  170. /* ------------------------------------------------------------------------- *
  171. * Pdf multi image flags *
  172. * ------------------------------------------------------------------------- */
  173. /*! Pdf multi image flags */
  174. enum {
  175. L_FIRST_IMAGE = 1, /*!< first image to be used */
  176. L_NEXT_IMAGE = 2, /*!< intermediate image; not first or last */
  177. L_LAST_IMAGE = 3 /*!< last image to be used */
  178. };
  179. /* ------------------------------------------------------------------------- *
  180. * Intermediate pdf generation data *
  181. * ------------------------------------------------------------------------- */
  182. /*
  183. * This accumulates data for generating a pdf of a single page consisting
  184. * of an arbitrary number of images.
  185. *
  186. * None of the strings have a trailing newline.
  187. */
  188. /*! Intermediate pdf generation data */
  189. struct L_Pdf_Data
  190. {
  191. char *title; /*!< optional title for pdf */
  192. l_int32 n; /*!< number of images */
  193. l_int32 ncmap; /*!< number of colormaps */
  194. struct L_Ptra *cida; /*!< array of compressed image data */
  195. char *id; /*!< %PDF-1.2 id string */
  196. char *obj1; /*!< catalog string */
  197. char *obj2; /*!< metadata string */
  198. char *obj3; /*!< pages string */
  199. char *obj4; /*!< page string (variable data) */
  200. char *obj5; /*!< content string (variable data) */
  201. char *poststream; /*!< post-binary-stream string */
  202. char *trailer; /*!< trailer string (variable data) */
  203. struct Pta *xy; /*!< store (xpt, ypt) array */
  204. struct Pta *wh; /*!< store (wpt, hpt) array */
  205. struct Box *mediabox; /*!< bounding region for all images */
  206. struct Sarray *saprex; /*!< pre-binary-stream xobject strings */
  207. struct Sarray *sacmap; /*!< colormap pdf object strings */
  208. struct L_Dna *objsize; /*!< sizes of each pdf string object */
  209. struct L_Dna *objloc; /*!< location of each pdf string object */
  210. l_int32 xrefloc; /*!< location of xref */
  211. };
  212. typedef struct L_Pdf_Data L_PDF_DATA;
  213. #endif /* LEPTONICA_IMAGEIO_H */