Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/leptonica/src/imageio.h @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 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 /*! | |
| 28 * \file imageio.h | |
| 29 * | |
| 30 * <pre> | |
| 31 * General features of image I/O in leptonica | |
| 32 * | |
| 33 * At present, there are 9 file formats for images that can be read | |
| 34 * and written: | |
| 35 * png (requires libpng, libz) | |
| 36 * jpeg (requires libjpeg) | |
| 37 * tiff (requires libtiff, libz) | |
| 38 * gif (requires libgif) | |
| 39 * webp (requires libwebp) | |
| 40 * jp2 (requires libopenjp2) | |
| 41 * bmp (no library required) | |
| 42 * pnm (no library required) | |
| 43 * spix (no library required) | |
| 44 * Additionally, there are two file formats for writing (only) images: | |
| 45 * PostScript (requires libpng, libz, libjpeg, libtiff) | |
| 46 * pdf (requires libpng, libz, libjpeg, libtiff) | |
| 47 * | |
| 48 * For all 9 read/write formats, leptonica provides interconversion | |
| 49 * between pix (with raster data) and formatted image data: | |
| 50 * Conversion from pix (typically compression): | |
| 51 * pixWrite(): pix --> file | |
| 52 * pixWriteStream(): pix --> filestream (aka FILE*) | |
| 53 * pixWriteMem(): pix --> memory buffer | |
| 54 * Conversion to pix (typically decompression): | |
| 55 * pixRead(): file --> pix | |
| 56 * pixReadStream(): filestream --> pix | |
| 57 * pixReadMem(): memory buffer --> pix | |
| 58 * | |
| 59 * Conversions for which the image data is not compressed are: | |
| 60 * * uncompressed tiff (IFF_TIFF) | |
| 61 * * bmp | |
| 62 * * pnm | |
| 63 * * spix (fast serialization that copies the pix raster data) | |
| 64 * | |
| 65 * The image header (metadata) information can be read from either | |
| 66 * the compressed file or a memory buffer, for all 9 formats. | |
| 67 * </pre> | |
| 68 */ | |
| 69 | |
| 70 #ifndef LEPTONICA_IMAGEIO_H | |
| 71 #define LEPTONICA_IMAGEIO_H | |
| 72 | |
| 73 /* --------------------------------------------------------------- * | |
| 74 * Image file format types * | |
| 75 * --------------------------------------------------------------- */ | |
| 76 /* | |
| 77 * The IFF_DEFAULT flag is used to write the file out in the | |
| 78 * same (input) file format that the pix was read from. If the pix | |
| 79 * was not read from file, the input format field will be | |
| 80 * IFF_UNKNOWN and the output file format will be chosen to | |
| 81 * be compressed and lossless; namely, IFF_TIFF_G4 for d = 1 | |
| 82 * and IFF_PNG for everything else. | |
| 83 * | |
| 84 * In the future, new format types that have defined extensions | |
| 85 * will be added before IFF_DEFAULT, and will be kept in sync with | |
| 86 * the file format extensions in writefile.c. The positions of | |
| 87 * file formats before IFF_DEFAULT will remain invariant. | |
| 88 */ | |
| 89 | |
| 90 /*! Image Formats */ | |
| 91 enum { | |
| 92 IFF_UNKNOWN = 0, | |
| 93 IFF_BMP = 1, | |
| 94 IFF_JFIF_JPEG = 2, | |
| 95 IFF_PNG = 3, | |
| 96 IFF_TIFF = 4, | |
| 97 IFF_TIFF_PACKBITS = 5, | |
| 98 IFF_TIFF_RLE = 6, | |
| 99 IFF_TIFF_G3 = 7, | |
| 100 IFF_TIFF_G4 = 8, | |
| 101 IFF_TIFF_LZW = 9, | |
| 102 IFF_TIFF_ZIP = 10, | |
| 103 IFF_PNM = 11, | |
| 104 IFF_PS = 12, | |
| 105 IFF_GIF = 13, | |
| 106 IFF_JP2 = 14, | |
| 107 IFF_WEBP = 15, | |
| 108 IFF_LPDF = 16, | |
| 109 IFF_TIFF_JPEG = 17, | |
| 110 IFF_DEFAULT = 18, | |
| 111 IFF_SPIX = 19 | |
| 112 }; | |
| 113 | |
| 114 /* Convenient macro for checking requested tiff output */ | |
| 115 #define L_FORMAT_IS_TIFF(f) ((f) == IFF_TIFF || (f) == IFF_TIFF_PACKBITS || \ | |
| 116 (f) == IFF_TIFF_RLE || (f) == IFF_TIFF_G3 || \ | |
| 117 (f) == IFF_TIFF_G4 || (f) == IFF_TIFF_LZW || \ | |
| 118 (f) == IFF_TIFF_ZIP || (f) == IFF_TIFF_JPEG) | |
| 119 | |
| 120 | |
| 121 /* --------------------------------------------------------------- * | |
| 122 * Format header ids * | |
| 123 * --------------------------------------------------------------- */ | |
| 124 /*! Header Ids */ | |
| 125 enum { | |
| 126 BMP_ID = 0x4d42, /*!< BM - for bitmaps */ | |
| 127 TIFF_BIGEND_ID = 0x4d4d, /*!< MM - for 'motorola' */ | |
| 128 TIFF_LITTLEEND_ID = 0x4949 /*!< II - for 'intel' */ | |
| 129 }; | |
| 130 | |
| 131 | |
| 132 /* --------------------------------------------------------------- * | |
| 133 * Hinting bit flags in jpeg reader * | |
| 134 * --------------------------------------------------------------- */ | |
| 135 /*! Jpeg Hints */ | |
| 136 /* The default behavior is now to fail on data corruption. */ | |
| 137 enum { | |
| 138 L_JPEG_READ_LUMINANCE = 1, /*!< only want luminance data; no chroma */ | |
| 139 L_JPEG_CONTINUE_WITH_BAD_DATA = 2 /*!< return possibly damaged pix */ | |
| 140 }; | |
| 141 | |
| 142 | |
| 143 /* --------------------------------------------------------------- * | |
| 144 * Jp2k codecs * | |
| 145 * --------------------------------------------------------------- */ | |
| 146 /*! Jp2k Codecs */ | |
| 147 enum { | |
| 148 L_J2K_CODEC = 1, /*!< codestream */ | |
| 149 L_JP2_CODEC = 2 /*!< file format with 'ihdr' */ | |
| 150 }; | |
| 151 | |
| 152 | |
| 153 /* --------------------------------------------------------------- * | |
| 154 * Pdf formatted encoding types * | |
| 155 * --------------------------------------------------------------- */ | |
| 156 /*! Pdf Encoding */ | |
| 157 enum { | |
| 158 L_DEFAULT_ENCODE = 0, /*!< use default encoding based on image */ | |
| 159 L_JPEG_ENCODE = 1, /*!< use dct encoding: 8 and 32 bpp, no cmap */ | |
| 160 L_G4_ENCODE = 2, /*!< use ccitt g4 fax encoding: 1 bpp */ | |
| 161 L_FLATE_ENCODE = 3, /*!< use flate encoding: any depth, cmap ok */ | |
| 162 L_JP2K_ENCODE = 4 /*!< use jp2k encoding: 8 and 32 bpp, no cmap */ | |
| 163 }; | |
| 164 | |
| 165 | |
| 166 /* --------------------------------------------------------------- * | |
| 167 * Compressed image data * | |
| 168 * --------------------------------------------------------------- */ | |
| 169 /* | |
| 170 * In use, either datacomp or data85 will be produced, depending | |
| 171 * on whether the data needs to be ascii85 encoded. PostScript | |
| 172 * requires ascii85 encoding; pdf does not. | |
| 173 * | |
| 174 * For the colormap (flate compression only), PostScript uses ascii85 | |
| 175 * encoding and pdf uses a bracketed array of space-separated | |
| 176 * hex-encoded rgb triples. Only tiff g4 (type == L_G4_ENCODE) uses | |
| 177 * the minisblack field. | |
| 178 */ | |
| 179 | |
| 180 /*! Compressed image data */ | |
| 181 struct L_Compressed_Data | |
| 182 { | |
| 183 l_int32 type; /*!< encoding type: L_JPEG_ENCODE, etc */ | |
| 184 l_uint8 *datacomp; /*!< gzipped raster data */ | |
| 185 size_t nbytescomp; /*!< number of compressed bytes */ | |
| 186 char *data85; /*!< ascii85-encoded gzipped raster data */ | |
| 187 size_t nbytes85; /*!< number of ascii85 encoded bytes */ | |
| 188 char *cmapdata85; /*!< ascii85-encoded uncompressed cmap */ | |
| 189 char *cmapdatahex; /*!< hex pdf array for the cmap */ | |
| 190 l_int32 ncolors; /*!< number of colors in cmap */ | |
| 191 l_int32 w; /*!< image width */ | |
| 192 l_int32 h; /*!< image height */ | |
| 193 l_int32 bps; /*!< bits/sample; typ. 1, 2, 4 or 8 */ | |
| 194 l_int32 spp; /*!< samples/pixel; typ. 1 or 3 */ | |
| 195 l_int32 minisblack; /*!< tiff g4 photometry */ | |
| 196 l_int32 predictor; /*!< flate data has PNG predictors */ | |
| 197 size_t nbytes; /*!< number of uncompressed raster bytes */ | |
| 198 l_int32 res; /*!< resolution (ppi) */ | |
| 199 }; | |
| 200 typedef struct L_Compressed_Data L_COMP_DATA; | |
| 201 | |
| 202 | |
| 203 /* ------------------------------------------------------------------------- * | |
| 204 * Pdf multi image flags * | |
| 205 * ------------------------------------------------------------------------- */ | |
| 206 /*! Pdf MultiImage */ | |
| 207 enum { | |
| 208 L_FIRST_IMAGE = 1, /*!< first image to be used */ | |
| 209 L_NEXT_IMAGE = 2, /*!< intermediate image; not first or last */ | |
| 210 L_LAST_IMAGE = 3 /*!< last image to be used */ | |
| 211 }; | |
| 212 | |
| 213 | |
| 214 /* ------------------------------------------------------------------------- * | |
| 215 * Intermediate pdf generation data * | |
| 216 * ------------------------------------------------------------------------- */ | |
| 217 /* | |
| 218 * This accumulates data for generating a pdf of a single page consisting | |
| 219 * of an arbitrary number of images. | |
| 220 * | |
| 221 * None of the strings have a trailing newline. | |
| 222 */ | |
| 223 | |
| 224 /*! Intermediate pdf generation data */ | |
| 225 struct L_Pdf_Data | |
| 226 { | |
| 227 char *title; /*!< optional title for pdf */ | |
| 228 l_int32 n; /*!< number of images */ | |
| 229 l_int32 ncmap; /*!< number of colormaps */ | |
| 230 struct L_Ptra *cida; /*!< array of compressed image data */ | |
| 231 char *id; /*!< %PDF-1.2 id string */ | |
| 232 char *obj1; /*!< catalog string */ | |
| 233 char *obj2; /*!< metadata string */ | |
| 234 char *obj3; /*!< pages string */ | |
| 235 char *obj4; /*!< page string (variable data) */ | |
| 236 char *obj5; /*!< content string (variable data) */ | |
| 237 char *poststream; /*!< post-binary-stream string */ | |
| 238 char *trailer; /*!< trailer string (variable data) */ | |
| 239 struct Pta *xy; /*!< store (xpt, ypt) array */ | |
| 240 struct Pta *wh; /*!< store (wpt, hpt) array */ | |
| 241 struct Box *mediabox; /*!< bounding region for all images */ | |
| 242 struct Sarray *saprex; /*!< pre-binary-stream xobject strings */ | |
| 243 struct Sarray *sacmap; /*!< colormap pdf object strings */ | |
| 244 struct L_Dna *objsize; /*!< sizes of each pdf string object */ | |
| 245 struct L_Dna *objloc; /*!< location of each pdf string object */ | |
| 246 l_int32 xrefloc; /*!< location of xref */ | |
| 247 }; | |
| 248 typedef struct L_Pdf_Data L_PDF_DATA; | |
| 249 | |
| 250 #endif /* LEPTONICA_IMAGEIO_H */ |
