Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7858 views
1
#ifndef MUPDF_FITZ_PIXMAP_H
2
#define MUPDF_FITZ_PIXMAP_H
3
4
#include "mupdf/fitz/system.h"
5
#include "mupdf/fitz/context.h"
6
#include "mupdf/fitz/math.h"
7
#include "mupdf/fitz/store.h"
8
#include "mupdf/fitz/colorspace.h"
9
10
/*
11
Pixmaps represent a set of pixels for a 2 dimensional region of a
12
plane. Each pixel has n components per pixel, the last of which is
13
always alpha. The data is in premultiplied alpha when rendering, but
14
non-premultiplied for colorspace conversions and rescaling.
15
*/
16
typedef struct fz_pixmap_s fz_pixmap;
17
18
/*
19
fz_pixmap_bbox: Return the bounding box for a pixmap.
20
*/
21
fz_irect *fz_pixmap_bbox(fz_context *ctx, fz_pixmap *pix, fz_irect *bbox);
22
23
/*
24
fz_pixmap_width: Return the width of the pixmap in pixels.
25
*/
26
int fz_pixmap_width(fz_context *ctx, fz_pixmap *pix);
27
28
/*
29
fz_pixmap_height: Return the height of the pixmap in pixels.
30
*/
31
int fz_pixmap_height(fz_context *ctx, fz_pixmap *pix);
32
33
/*
34
fz_new_pixmap: Create a new pixmap, with it's origin at (0,0)
35
36
cs: The colorspace to use for the pixmap, or NULL for an alpha
37
plane/mask.
38
39
w: The width of the pixmap (in pixels)
40
41
h: The height of the pixmap (in pixels)
42
43
Returns a pointer to the new pixmap. Throws exception on failure to
44
allocate.
45
*/
46
fz_pixmap *fz_new_pixmap(fz_context *ctx, fz_colorspace *cs, int w, int h);
47
48
/*
49
fz_new_pixmap_with_bbox: Create a pixmap of a given size,
50
location and pixel format.
51
52
The bounding box specifies the size of the created pixmap and
53
where it will be located. The colorspace determines the number
54
of components per pixel. Alpha is always present. Pixmaps are
55
reference counted, so drop references using fz_drop_pixmap.
56
57
colorspace: Colorspace format used for the created pixmap. The
58
pixmap will keep a reference to the colorspace.
59
60
bbox: Bounding box specifying location/size of created pixmap.
61
62
Returns a pointer to the new pixmap. Throws exception on failure to
63
allocate.
64
*/
65
fz_pixmap *fz_new_pixmap_with_bbox(fz_context *ctx, fz_colorspace *colorspace, const fz_irect *bbox);
66
67
/*
68
fz_new_pixmap_with_data: Create a new pixmap, with it's origin at
69
(0,0) using the supplied data block.
70
71
cs: The colorspace to use for the pixmap, or NULL for an alpha
72
plane/mask.
73
74
w: The width of the pixmap (in pixels)
75
76
h: The height of the pixmap (in pixels)
77
78
samples: The data block to keep the samples in.
79
80
Returns a pointer to the new pixmap. Throws exception on failure to
81
allocate.
82
*/
83
fz_pixmap *fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h, unsigned char *samples);
84
85
/*
86
fz_new_pixmap_with_bbox_and_data: Create a pixmap of a given size,
87
location and pixel format, using the supplied data block.
88
89
The bounding box specifies the size of the created pixmap and
90
where it will be located. The colorspace determines the number
91
of components per pixel. Alpha is always present. Pixmaps are
92
reference counted, so drop references using fz_drop_pixmap.
93
94
colorspace: Colorspace format used for the created pixmap. The
95
pixmap will keep a reference to the colorspace.
96
97
bbox: Bounding box specifying location/size of created pixmap.
98
99
samples: The data block to keep the samples in.
100
101
Returns a pointer to the new pixmap. Throws exception on failure to
102
allocate.
103
*/
104
fz_pixmap *fz_new_pixmap_with_bbox_and_data(fz_context *ctx, fz_colorspace *colorspace, const fz_irect *rect, unsigned char *samples);
105
106
/*
107
fz_keep_pixmap: Take a reference to a pixmap.
108
109
pix: The pixmap to increment the reference for.
110
111
Returns pix. Does not throw exceptions.
112
*/
113
fz_pixmap *fz_keep_pixmap(fz_context *ctx, fz_pixmap *pix);
114
115
/*
116
fz_drop_pixmap: Drop a reference and free a pixmap.
117
118
Decrement the reference count for the pixmap. When no
119
references remain the pixmap will be freed.
120
121
Does not throw exceptions.
122
*/
123
void fz_drop_pixmap(fz_context *ctx, fz_pixmap *pix);
124
125
/*
126
fz_pixmap_colorspace: Return the colorspace of a pixmap
127
128
Returns colorspace. Does not throw exceptions.
129
*/
130
fz_colorspace *fz_pixmap_colorspace(fz_context *ctx, fz_pixmap *pix);
131
132
/*
133
fz_pixmap_components: Return the number of components in a pixmap.
134
135
Returns the number of components. Does not throw exceptions.
136
*/
137
int fz_pixmap_components(fz_context *ctx, fz_pixmap *pix);
138
139
/*
140
fz_pixmap_samples: Returns a pointer to the pixel data of a pixmap.
141
142
Returns the pointer. Does not throw exceptions.
143
*/
144
unsigned char *fz_pixmap_samples(fz_context *ctx, fz_pixmap *pix);
145
146
void fz_pixmap_set_resolution(fz_pixmap *pix, int res);
147
148
/*
149
fz_clear_pixmap_with_value: Clears a pixmap with the given value.
150
151
pix: The pixmap to clear.
152
153
value: Values in the range 0 to 255 are valid. Each component
154
sample for each pixel in the pixmap will be set to this value,
155
while alpha will always be set to 255 (non-transparent).
156
157
Does not throw exceptions.
158
*/
159
void fz_clear_pixmap_with_value(fz_context *ctx, fz_pixmap *pix, int value);
160
161
/*
162
fz_clear_pixmap_with_value: Clears a subrect of a pixmap with the given value.
163
164
pix: The pixmap to clear.
165
166
value: Values in the range 0 to 255 are valid. Each component
167
sample for each pixel in the pixmap will be set to this value,
168
while alpha will always be set to 255 (non-transparent).
169
170
r: the rectangle.
171
172
Does not throw exceptions.
173
*/
174
void fz_clear_pixmap_rect_with_value(fz_context *ctx, fz_pixmap *pix, int value, const fz_irect *r);
175
176
/*
177
fz_clear_pixmap_with_value: Sets all components (including alpha) of
178
all pixels in a pixmap to 0.
179
180
pix: The pixmap to clear.
181
182
Does not throw exceptions.
183
*/
184
void fz_clear_pixmap(fz_context *ctx, fz_pixmap *pix);
185
186
/*
187
fz_invert_pixmap: Invert all the pixels in a pixmap. All components
188
of all pixels are inverted (except alpha, which is unchanged).
189
190
Does not throw exceptions.
191
*/
192
void fz_invert_pixmap(fz_context *ctx, fz_pixmap *pix);
193
194
/*
195
fz_tint_pixmap: Tint all the pixels in an RGB or Gray pixmap.
196
197
Multiplies all the samples with the input color argument.
198
199
r,g,b: The color to tint with, in 0 to 255 range.
200
*/
201
void fz_tint_pixmap(fz_context *ctx, fz_pixmap *pix, int r, int g, int b);
202
203
/*
204
fz_invert_pixmap: Invert all the pixels in a given rectangle of a
205
pixmap. All components of all pixels in the rectangle are inverted
206
(except alpha, which is unchanged).
207
208
Does not throw exceptions.
209
*/
210
void fz_invert_pixmap_rect(fz_context *ctx, fz_pixmap *image, const fz_irect *rect);
211
212
/*
213
fz_gamma_pixmap: Apply gamma correction to a pixmap. All components
214
of all pixels are modified (except alpha, which is unchanged).
215
216
gamma: The gamma value to apply; 1.0 for no change.
217
218
Does not throw exceptions.
219
*/
220
void fz_gamma_pixmap(fz_context *ctx, fz_pixmap *pix, float gamma);
221
222
/*
223
fz_unmultiply_pixmap: Convert a pixmap from premultiplied to
224
non-premultiplied format.
225
226
Does not throw exceptions.
227
*/
228
void fz_unmultiply_pixmap(fz_context *ctx, fz_pixmap *pix);
229
230
/*
231
fz_convert_pixmap: Convert from one pixmap to another (assumed to be
232
the same size, but possibly with a different colorspace).
233
234
dst: the source pixmap.
235
236
src: the destination pixmap.
237
*/
238
void fz_convert_pixmap(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src);
239
240
/*
241
Pixmaps represent a set of pixels for a 2 dimensional region of a
242
plane. Each pixel has n components per pixel, the last of which is
243
always alpha. The data is in premultiplied alpha when rendering, but
244
non-premultiplied for colorspace conversions and rescaling.
245
246
x, y: The minimum x and y coord of the region in pixels.
247
248
w, h: The width and height of the region in pixels.
249
250
n: The number of color components in the image. Always
251
includes a separate alpha channel. For mask images n=1, for greyscale
252
(plus alpha) images n=2, for rgb (plus alpha) images n=3.
253
254
interpolate: A boolean flag set to non-zero if the image
255
will be drawn using linear interpolation, or set to zero if
256
image will be using nearest neighbour sampling.
257
258
xres, yres: Image resolution in dpi. Default is 96 dpi.
259
260
colorspace: Pointer to a colorspace object describing the colorspace
261
the pixmap is in. If NULL, the image is a mask.
262
263
samples: A simple block of memory w * h * n bytes of memory in which
264
the components are stored. The first n bytes are components 0 to n-1
265
for the pixel at (x,y). Each successive n bytes gives another pixel
266
in scanline order. Subsequent scanlines follow on with no padding.
267
268
free_samples: Is zero when an application has provided its own
269
buffer for pixel data through fz_new_pixmap_with_bbox_and_data.
270
If non-zero the buffer will be freed along with the the pixmap.
271
*/
272
struct fz_pixmap_s
273
{
274
fz_storable storable;
275
int x, y, w, h, n;
276
int interpolate;
277
int xres, yres;
278
fz_colorspace *colorspace;
279
unsigned char *samples;
280
int free_samples;
281
};
282
283
void fz_drop_pixmap_imp(fz_context *ctx, fz_storable *pix);
284
285
void fz_copy_pixmap_rect(fz_context *ctx, fz_pixmap *dest, fz_pixmap *src, const fz_irect *r);
286
void fz_premultiply_pixmap(fz_context *ctx, fz_pixmap *pix);
287
fz_pixmap *fz_alpha_from_gray(fz_context *ctx, fz_pixmap *gray, int luminosity);
288
unsigned int fz_pixmap_size(fz_context *ctx, fz_pixmap *pix);
289
290
fz_pixmap *fz_scale_pixmap(fz_context *ctx, fz_pixmap *src, float x, float y, float w, float h, fz_irect *clip);
291
292
typedef struct fz_scale_cache_s fz_scale_cache;
293
294
fz_scale_cache *fz_new_scale_cache(fz_context *ctx);
295
void fz_drop_scale_cache(fz_context *ctx, fz_scale_cache *cache);
296
fz_pixmap *fz_scale_pixmap_cached(fz_context *ctx, fz_pixmap *src, float x, float y, float w, float h, const fz_irect *clip, fz_scale_cache *cache_x, fz_scale_cache *cache_y);
297
298
void fz_subsample_pixmap(fz_context *ctx, fz_pixmap *tile, int factor);
299
300
fz_irect *fz_pixmap_bbox_no_ctx(fz_pixmap *src, fz_irect *bbox);
301
302
void fz_decode_tile(fz_context *ctx, fz_pixmap *pix, float *decode);
303
void fz_decode_indexed_tile(fz_context *ctx, fz_pixmap *pix, float *decode, int maxval);
304
void fz_unpack_tile(fz_context *ctx, fz_pixmap *dst, unsigned char * restrict src, int n, int depth, int stride, int scale);
305
306
/*
307
fz_md5_pixmap: Return the md5 digest for a pixmap
308
*/
309
void fz_md5_pixmap(fz_context *ctx, fz_pixmap *pixmap, unsigned char digest[16]);
310
311
fz_pixmap *fz_new_pixmap_from_8bpp_data(fz_context *ctx, int x, int y, int w, int h, unsigned char *sp, int span);
312
fz_pixmap *fz_new_pixmap_from_1bpp_data(fz_context *ctx, int x, int y, int w, int h, unsigned char *sp, int span);
313
314
#endif
315
316