comparison mupdf-source/include/mupdf/fitz/compressed-buffer.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 // Copyright (C) 2004-2025 Artifex Software, Inc.
2 //
3 // This file is part of MuPDF.
4 //
5 // MuPDF is free software: you can redistribute it and/or modify it under the
6 // terms of the GNU Affero General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or (at your option)
8 // any later version.
9 //
10 // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Affero General Public License
16 // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
17 //
18 // Alternative licensing terms are available from the licensor.
19 // For commercial licensing, see <https://www.artifex.com/> or contact
20 // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
21 // CA 94129, USA, for further information.
22
23 #ifndef MUPDF_FITZ_COMPRESSED_BUFFER_H
24 #define MUPDF_FITZ_COMPRESSED_BUFFER_H
25
26 #include "mupdf/fitz/system.h"
27 #include "mupdf/fitz/context.h"
28 #include "mupdf/fitz/buffer.h"
29 #include "mupdf/fitz/stream.h"
30 #include "mupdf/fitz/filter.h"
31
32 /**
33 Compression parameters used for buffers of compressed data;
34 typically for the source data for images.
35 */
36 typedef struct
37 {
38 int type;
39 union {
40 struct {
41 int color_transform; /* Use -1 for unset */
42 int invert_cmyk; /* Use 1 for standalone JPEG files */
43 } jpeg;
44 struct {
45 int smask_in_data;
46 } jpx;
47 struct {
48 fz_jbig2_globals *globals;
49 int embedded;
50 } jbig2;
51 struct {
52 int columns;
53 int rows;
54 int k;
55 int end_of_line;
56 int encoded_byte_align;
57 int end_of_block;
58 int black_is_1;
59 int damaged_rows_before_error;
60 } fax;
61 struct
62 {
63 int columns;
64 int colors;
65 int predictor;
66 int bpc;
67 }
68 flate;
69 struct
70 {
71 int columns;
72 int colors;
73 int predictor;
74 int bpc;
75 }
76 brotli;
77 struct
78 {
79 int columns;
80 int colors;
81 int predictor;
82 int bpc;
83 int early_change;
84 } lzw;
85 } u;
86 } fz_compression_params;
87
88 /**
89 Buffers of compressed data; typically for the source data
90 for images.
91 */
92 typedef struct
93 {
94 int refs;
95 fz_compression_params params;
96 fz_buffer *buffer;
97 } fz_compressed_buffer;
98
99 /**
100 Take a reference to an fz_compressed_buffer.
101 */
102 fz_compressed_buffer *fz_keep_compressed_buffer(fz_context *ctx, fz_compressed_buffer *cbuf);
103
104 /**
105 Return the storage size used for a buffer and its data.
106 Used in implementing store handling.
107
108 Never throws exceptions.
109 */
110 size_t fz_compressed_buffer_size(fz_compressed_buffer *buffer);
111
112 /**
113 Open a stream to read the decompressed version of a buffer.
114 */
115 fz_stream *fz_open_compressed_buffer(fz_context *ctx, fz_compressed_buffer *);
116
117 /**
118 Open a stream to read the decompressed version of a buffer,
119 with optional log2 subsampling.
120
121 l2factor = NULL for no subsampling, or a pointer to an integer
122 containing the maximum log2 subsample factor acceptable (0 =
123 none, 1 = halve dimensions, 2 = quarter dimensions etc). If
124 non-NULL, then *l2factor will be updated on exit with the actual
125 log2 subsample factor achieved.
126 */
127 fz_stream *fz_open_image_decomp_stream_from_buffer(fz_context *ctx, fz_compressed_buffer *, int *l2factor);
128
129 /**
130 Open a stream to read the decompressed version of another stream
131 with optional log2 subsampling.
132 */
133 fz_stream *fz_open_image_decomp_stream(fz_context *ctx, fz_stream *, fz_compression_params *, int *l2factor);
134
135 /**
136 Recognise image format strings in the first 8 bytes from image
137 data.
138 */
139 int fz_recognize_image_format(fz_context *ctx, unsigned char p[8]);
140
141 /**
142 Map from FZ_IMAGE_* value to string.
143
144 The returned string is static and therefore must not be freed.
145 */
146 const char *fz_image_type_name(int type);
147
148 /**
149 Map from (case sensitive) image type string to FZ_IMAGE_*
150 type value.
151 */
152 int fz_lookup_image_type(const char *type);
153
154 enum
155 {
156 FZ_IMAGE_UNKNOWN = 0,
157
158 /* Uncompressed samples */
159 FZ_IMAGE_RAW,
160
161 /* Compressed samples */
162 FZ_IMAGE_FAX,
163 FZ_IMAGE_FLATE,
164 FZ_IMAGE_LZW,
165 FZ_IMAGE_RLD,
166 FZ_IMAGE_BROTLI,
167
168 /* Full image formats */
169 FZ_IMAGE_BMP,
170 FZ_IMAGE_GIF,
171 FZ_IMAGE_JBIG2,
172 FZ_IMAGE_JPEG,
173 FZ_IMAGE_JPX,
174 FZ_IMAGE_JXR,
175 FZ_IMAGE_PNG,
176 FZ_IMAGE_PNM,
177 FZ_IMAGE_TIFF,
178 FZ_IMAGE_PSD,
179 };
180
181 /**
182 Drop a reference to a compressed buffer. Destroys the buffer
183 and frees any storage/other references held by it.
184
185 Never throws exceptions.
186 */
187 void fz_drop_compressed_buffer(fz_context *ctx, fz_compressed_buffer *buf);
188
189 /**
190 Create a new, UNKNOWN format, compressed_buffer.
191 */
192 fz_compressed_buffer *fz_new_compressed_buffer(fz_context *ctx);
193
194 #endif