comparison mupdf-source/include/mupdf/fitz/write-pixmap.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_WRITE_PIXMAP_H
24 #define MUPDF_FITZ_WRITE_PIXMAP_H
25
26 #include "mupdf/fitz/system.h"
27 #include "mupdf/fitz/context.h"
28 #include "mupdf/fitz/output.h"
29 #include "mupdf/fitz/band-writer.h"
30 #include "mupdf/fitz/pixmap.h"
31 #include "mupdf/fitz/bitmap.h"
32 #include "mupdf/fitz/buffer.h"
33 #include "mupdf/fitz/image.h"
34 #include "mupdf/fitz/writer.h"
35
36 /**
37 PCL output
38 */
39 typedef struct
40 {
41 /* Features of a particular printer */
42 int features;
43 const char *odd_page_init;
44 const char *even_page_init;
45
46 /* Options for this job */
47 int tumble;
48 int duplex_set;
49 int duplex;
50 int paper_size;
51 int manual_feed_set;
52 int manual_feed;
53 int media_position_set;
54 int media_position;
55 int orientation;
56
57 /* Updated as we move through the job */
58 int page_count;
59 } fz_pcl_options;
60
61 /**
62 Initialize PCL option struct for a given preset.
63
64 Currently defined presets include:
65
66 generic Generic PCL printer
67 ljet4 HP DeskJet
68 dj500 HP DeskJet 500
69 fs600 Kyocera FS-600
70 lj HP LaserJet, HP LaserJet Plus
71 lj2 HP LaserJet IIp, HP LaserJet IId
72 lj3 HP LaserJet III
73 lj3d HP LaserJet IIId
74 lj4 HP LaserJet 4
75 lj4pl HP LaserJet 4 PL
76 lj4d HP LaserJet 4d
77 lp2563b HP 2563B line printer
78 oce9050 Oce 9050 Line printer
79 */
80 void fz_pcl_preset(fz_context *ctx, fz_pcl_options *opts, const char *preset);
81
82 /**
83 Parse PCL options.
84
85 Currently defined options and values are as follows:
86
87 preset=X Either "generic" or one of the presets as for fz_pcl_preset.
88 spacing=0 No vertical spacing capability
89 spacing=1 PCL 3 spacing (<ESC>*p+<n>Y)
90 spacing=2 PCL 4 spacing (<ESC>*b<n>Y)
91 spacing=3 PCL 5 spacing (<ESC>*b<n>Y and clear seed row)
92 mode2 Disable/Enable mode 2 graphics compression
93 mode3 Disable/Enable mode 3 graphics compression
94 eog_reset End of graphics (<ESC>*rB) resets all parameters
95 has_duplex Duplex supported (<ESC>&l<duplex>S)
96 has_papersize Papersize setting supported (<ESC>&l<sizecode>A)
97 has_copies Number of copies supported (<ESC>&l<copies>X)
98 is_ljet4pjl Disable/Enable HP 4PJL model-specific output
99 is_oce9050 Disable/Enable Oce 9050 model-specific output
100 */
101 fz_pcl_options *fz_parse_pcl_options(fz_context *ctx, fz_pcl_options *opts, const char *args);
102
103 /**
104 Create a new band writer, outputting monochrome pcl.
105 */
106 fz_band_writer *fz_new_mono_pcl_band_writer(fz_context *ctx, fz_output *out, const fz_pcl_options *options);
107
108 /**
109 Write a bitmap as mono PCL.
110 */
111 void fz_write_bitmap_as_pcl(fz_context *ctx, fz_output *out, const fz_bitmap *bitmap, const fz_pcl_options *pcl);
112
113 /**
114 Save a bitmap as mono PCL.
115 */
116 void fz_save_bitmap_as_pcl(fz_context *ctx, fz_bitmap *bitmap, char *filename, int append, const fz_pcl_options *pcl);
117
118 /**
119 Create a new band writer, outputting color pcl.
120 */
121 fz_band_writer *fz_new_color_pcl_band_writer(fz_context *ctx, fz_output *out, const fz_pcl_options *options);
122
123 /**
124 Write an (RGB) pixmap as color PCL.
125 */
126 void fz_write_pixmap_as_pcl(fz_context *ctx, fz_output *out, const fz_pixmap *pixmap, const fz_pcl_options *pcl);
127
128 /**
129 Save an (RGB) pixmap as color PCL.
130 */
131 void fz_save_pixmap_as_pcl(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append, const fz_pcl_options *pcl);
132
133 /**
134 PCLm output
135 */
136 typedef struct
137 {
138 int compress;
139 int strip_height;
140
141 /* Updated as we move through the job */
142 int page_count;
143 } fz_pclm_options;
144
145 /**
146 Parse PCLm options.
147
148 Currently defined options and values are as follows:
149
150 compression=none: No compression
151 compression=flate: Flate compression
152 strip-height=n: Strip height (default 16)
153 */
154 fz_pclm_options *fz_parse_pclm_options(fz_context *ctx, fz_pclm_options *opts, const char *args);
155
156 /**
157 Create a new band writer, outputting pclm
158 */
159 fz_band_writer *fz_new_pclm_band_writer(fz_context *ctx, fz_output *out, const fz_pclm_options *options);
160
161 /**
162 Write a (Greyscale or RGB) pixmap as pclm.
163 */
164 void fz_write_pixmap_as_pclm(fz_context *ctx, fz_output *out, const fz_pixmap *pixmap, const fz_pclm_options *options);
165
166 /**
167 Save a (Greyscale or RGB) pixmap as pclm.
168 */
169 void fz_save_pixmap_as_pclm(fz_context *ctx, fz_pixmap *pixmap, const char *filename, int append, const fz_pclm_options *options);
170
171 /**
172 PDFOCR output
173 */
174 typedef struct
175 {
176 int compress;
177 int strip_height;
178 char language[256];
179 char datadir[1024];
180
181 int skew_correct; /* 0 = no skew correction. 1 = automatic. 2 = use specified angle. */
182 float skew_angle; /* Only used if skew == 2 */
183 int skew_border; /* 0 = increase size so no content is lost. 1 = maintain size. 2 = decrease size so no new pixels are visible. */
184
185 /* Updated as we move through the job */
186 int page_count;
187 } fz_pdfocr_options;
188
189 /**
190 Parse PDFOCR options.
191
192 Currently defined options and values are as follows:
193
194 compression=none: No compression
195 compression=flate: Flate compression
196 strip-height=n: Strip height (default 16)
197 ocr-language=<lang>: OCR Language (default eng)
198 ocr-datadir=<datadir>: OCR data path (default rely on TESSDATA_PREFIX)
199 */
200 fz_pdfocr_options *fz_parse_pdfocr_options(fz_context *ctx, fz_pdfocr_options *opts, const char *args);
201
202 /**
203 Create a new band writer, outputting pdfocr.
204
205 Ownership of output stays with the caller, the band writer
206 borrows the reference. The caller must keep the output around
207 for the duration of the band writer, and then close/drop as
208 appropriate.
209 */
210 fz_band_writer *fz_new_pdfocr_band_writer(fz_context *ctx, fz_output *out, const fz_pdfocr_options *options);
211
212 /**
213 Set the progress callback for a pdfocr bandwriter.
214 */
215 void fz_pdfocr_band_writer_set_progress(fz_context *ctx, fz_band_writer *writer, fz_pdfocr_progress_fn *progress_fn, void *progress_arg);
216
217 /**
218 Write a (Greyscale or RGB) pixmap as pdfocr.
219 */
220 void fz_write_pixmap_as_pdfocr(fz_context *ctx, fz_output *out, const fz_pixmap *pixmap, const fz_pdfocr_options *options);
221
222 /**
223 Save a (Greyscale or RGB) pixmap as pdfocr.
224 */
225 void fz_save_pixmap_as_pdfocr(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append, const fz_pdfocr_options *options);
226
227 /**
228 Save a (Greyscale or RGB) pixmap as a png.
229 */
230 void fz_save_pixmap_as_png(fz_context *ctx, fz_pixmap *pixmap, const char *filename);
231
232 /**
233 Write a pixmap as a JPEG.
234 */
235 void fz_write_pixmap_as_jpeg(fz_context *ctx, fz_output *out, fz_pixmap *pix, int quality, int invert_cmyk);
236
237 /**
238 Save a pixmap as a JPEG.
239 */
240 void fz_save_pixmap_as_jpeg(fz_context *ctx, fz_pixmap *pixmap, const char *filename, int quality);
241
242 /**
243 Write a (Greyscale or RGB) pixmap as a png.
244 */
245 void fz_write_pixmap_as_png(fz_context *ctx, fz_output *out, const fz_pixmap *pixmap);
246
247 /**
248 Pixmap data as JP2K with no subsampling.
249
250 quality = 100 = lossless
251 otherwise for a factor of x compression use 100-x. (so 80 is 1:20 compression)
252 */
253 void fz_write_pixmap_as_jpx(fz_context *ctx, fz_output *out, fz_pixmap *pix, int quality);
254
255 /**
256 Save pixmap data as JP2K with no subsampling.
257
258 quality = 100 = lossless
259 otherwise for a factor of x compression use 100-x. (so 80 is 1:20 compression)
260 */
261 void fz_save_pixmap_as_jpx(fz_context *ctx, fz_pixmap *pixmap, const char *filename, int q);
262
263 /**
264 Create a new png band writer (greyscale or RGB, with or without
265 alpha).
266 */
267 fz_band_writer *fz_new_png_band_writer(fz_context *ctx, fz_output *out);
268
269 /**
270 Re-encode a given image as a PNG into a buffer.
271
272 Ownership of the buffer is returned.
273 */
274 fz_buffer *fz_new_buffer_from_image_as_png(fz_context *ctx, fz_image *image, fz_color_params color_params);
275 fz_buffer *fz_new_buffer_from_image_as_pbm(fz_context *ctx, fz_image *image, fz_color_params color_params);
276 fz_buffer *fz_new_buffer_from_image_as_pkm(fz_context *ctx, fz_image *image, fz_color_params color_params);
277 fz_buffer *fz_new_buffer_from_image_as_pnm(fz_context *ctx, fz_image *image, fz_color_params color_params);
278 fz_buffer *fz_new_buffer_from_image_as_pam(fz_context *ctx, fz_image *image, fz_color_params color_params);
279 fz_buffer *fz_new_buffer_from_image_as_psd(fz_context *ctx, fz_image *image, fz_color_params color_params);
280 fz_buffer *fz_new_buffer_from_image_as_jpeg(fz_context *ctx, fz_image *image, fz_color_params color_params, int quality, int invert_cmyk);
281 fz_buffer *fz_new_buffer_from_image_as_jpx(fz_context *ctx, fz_image *image, fz_color_params color_params, int quality);
282
283 /**
284 Re-encode a given pixmap as a PNG into a buffer.
285
286 Ownership of the buffer is returned.
287 */
288 fz_buffer *fz_new_buffer_from_pixmap_as_png(fz_context *ctx, fz_pixmap *pixmap, fz_color_params color_params);
289 fz_buffer *fz_new_buffer_from_pixmap_as_pbm(fz_context *ctx, fz_pixmap *pixmap, fz_color_params color_params);
290 fz_buffer *fz_new_buffer_from_pixmap_as_pkm(fz_context *ctx, fz_pixmap *pixmap, fz_color_params color_params);
291 fz_buffer *fz_new_buffer_from_pixmap_as_pnm(fz_context *ctx, fz_pixmap *pixmap, fz_color_params color_params);
292 fz_buffer *fz_new_buffer_from_pixmap_as_pam(fz_context *ctx, fz_pixmap *pixmap, fz_color_params color_params);
293 fz_buffer *fz_new_buffer_from_pixmap_as_psd(fz_context *ctx, fz_pixmap *pix, fz_color_params color_params);
294 fz_buffer *fz_new_buffer_from_pixmap_as_jpeg(fz_context *ctx, fz_pixmap *pixmap, fz_color_params color_params, int quality, int invert_cmyk);
295 fz_buffer *fz_new_buffer_from_pixmap_as_jpx(fz_context *ctx, fz_pixmap *pix, fz_color_params color_params, int quality);
296
297 /**
298 Save a pixmap as a pnm (greyscale or rgb, no alpha).
299 */
300 void fz_save_pixmap_as_pnm(fz_context *ctx, fz_pixmap *pixmap, const char *filename);
301
302 /**
303 Write a pixmap as a pnm (greyscale or rgb, no alpha).
304 */
305 void fz_write_pixmap_as_pnm(fz_context *ctx, fz_output *out, fz_pixmap *pixmap);
306
307 /**
308 Create a band writer targeting pnm (greyscale or rgb, no
309 alpha).
310 */
311 fz_band_writer *fz_new_pnm_band_writer(fz_context *ctx, fz_output *out);
312
313 /**
314 Save a pixmap as a pnm (greyscale, rgb or cmyk, with or without
315 alpha).
316 */
317 void fz_save_pixmap_as_pam(fz_context *ctx, fz_pixmap *pixmap, const char *filename);
318
319 /**
320 Write a pixmap as a pnm (greyscale, rgb or cmyk, with or without
321 alpha).
322 */
323 void fz_write_pixmap_as_pam(fz_context *ctx, fz_output *out, fz_pixmap *pixmap);
324
325 /**
326 Create a band writer targeting pnm (greyscale, rgb or cmyk,
327 with or without alpha).
328 */
329 fz_band_writer *fz_new_pam_band_writer(fz_context *ctx, fz_output *out);
330
331 /**
332 Save a bitmap as a pbm.
333 */
334 void fz_save_bitmap_as_pbm(fz_context *ctx, fz_bitmap *bitmap, const char *filename);
335
336 /**
337 Write a bitmap as a pbm.
338 */
339 void fz_write_bitmap_as_pbm(fz_context *ctx, fz_output *out, fz_bitmap *bitmap);
340
341 /**
342 Create a new band writer, targeting pbm.
343 */
344 fz_band_writer *fz_new_pbm_band_writer(fz_context *ctx, fz_output *out);
345
346 /**
347 Save a pixmap as a pbm. (Performing halftoning).
348 */
349 void fz_save_pixmap_as_pbm(fz_context *ctx, fz_pixmap *pixmap, const char *filename);
350
351 /**
352 Save a CMYK bitmap as a pkm.
353 */
354 void fz_save_bitmap_as_pkm(fz_context *ctx, fz_bitmap *bitmap, const char *filename);
355
356 /**
357 Write a CMYK bitmap as a pkm.
358 */
359 void fz_write_bitmap_as_pkm(fz_context *ctx, fz_output *out, fz_bitmap *bitmap);
360
361 /**
362 Create a new pkm band writer for CMYK pixmaps.
363 */
364 fz_band_writer *fz_new_pkm_band_writer(fz_context *ctx, fz_output *out);
365
366 /**
367 Save a CMYK pixmap as a pkm. (Performing halftoning).
368 */
369 void fz_save_pixmap_as_pkm(fz_context *ctx, fz_pixmap *pixmap, const char *filename);
370
371 /**
372 Write a (gray, rgb, or cmyk, no alpha) pixmap out as postscript.
373 */
374 void fz_write_pixmap_as_ps(fz_context *ctx, fz_output *out, const fz_pixmap *pixmap);
375
376 /**
377 Save a (gray, rgb, or cmyk, no alpha) pixmap out as postscript.
378 */
379 void fz_save_pixmap_as_ps(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append);
380
381 /**
382 Create a postscript band writer for gray, rgb, or cmyk, no
383 alpha.
384 */
385 fz_band_writer *fz_new_ps_band_writer(fz_context *ctx, fz_output *out);
386
387 /**
388 Write the file level header for ps band writer output.
389 */
390 void fz_write_ps_file_header(fz_context *ctx, fz_output *out);
391
392 /**
393 Write the file level trailer for ps band writer output.
394 */
395 void fz_write_ps_file_trailer(fz_context *ctx, fz_output *out, int pages);
396
397 /**
398 Save a pixmap as a PSD file.
399 */
400 void fz_save_pixmap_as_psd(fz_context *ctx, fz_pixmap *pixmap, const char *filename);
401
402 /**
403 Write a pixmap as a PSD file.
404 */
405 void fz_write_pixmap_as_psd(fz_context *ctx, fz_output *out, const fz_pixmap *pixmap);
406
407 /**
408 Open a PSD band writer.
409 */
410 fz_band_writer *fz_new_psd_band_writer(fz_context *ctx, fz_output *out);
411
412 typedef struct
413 {
414 /* These are not interpreted as CStrings by the writing code,
415 * but are rather copied directly out. */
416 char media_class[64];
417 char media_color[64];
418 char media_type[64];
419 char output_type[64];
420
421 unsigned int advance_distance;
422 int advance_media;
423 int collate;
424 int cut_media;
425 int duplex;
426 int insert_sheet;
427 int jog;
428 int leading_edge;
429 int manual_feed;
430 unsigned int media_position;
431 unsigned int media_weight;
432 int mirror_print;
433 int negative_print;
434 unsigned int num_copies;
435 int orientation;
436 int output_face_up;
437 unsigned int PageSize[2];
438 int separations;
439 int tray_switch;
440 int tumble;
441
442 int media_type_num;
443 int compression;
444 unsigned int row_count;
445 unsigned int row_feed;
446 unsigned int row_step;
447
448 /* These are not interpreted as CStrings by the writing code, but
449 * are rather copied directly out. */
450 char rendering_intent[64];
451 char page_size_name[64];
452 } fz_pwg_options;
453
454 /**
455 Save a pixmap as a PWG.
456 */
457 void fz_save_pixmap_as_pwg(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append, const fz_pwg_options *pwg);
458
459 /**
460 Save a bitmap as a PWG.
461 */
462 void fz_save_bitmap_as_pwg(fz_context *ctx, fz_bitmap *bitmap, char *filename, int append, const fz_pwg_options *pwg);
463
464 /**
465 Write a pixmap as a PWG.
466 */
467 void fz_write_pixmap_as_pwg(fz_context *ctx, fz_output *out, const fz_pixmap *pixmap, const fz_pwg_options *pwg);
468
469 /**
470 Write a bitmap as a PWG.
471 */
472 void fz_write_bitmap_as_pwg(fz_context *ctx, fz_output *out, const fz_bitmap *bitmap, const fz_pwg_options *pwg);
473
474 /**
475 Write a pixmap as a PWG page.
476
477 Caller should provide a file header by calling
478 fz_write_pwg_file_header, but can then write several pages to
479 the same file.
480 */
481 void fz_write_pixmap_as_pwg_page(fz_context *ctx, fz_output *out, const fz_pixmap *pixmap, const fz_pwg_options *pwg);
482
483 /**
484 Write a bitmap as a PWG page.
485
486 Caller should provide a file header by calling
487 fz_write_pwg_file_header, but can then write several pages to
488 the same file.
489 */
490 void fz_write_bitmap_as_pwg_page(fz_context *ctx, fz_output *out, const fz_bitmap *bitmap, const fz_pwg_options *pwg);
491
492 /**
493 Create a new monochrome pwg band writer.
494 */
495 fz_band_writer *fz_new_mono_pwg_band_writer(fz_context *ctx, fz_output *out, const fz_pwg_options *pwg);
496
497 /**
498 Create a new color pwg band writer.
499 */
500 fz_band_writer *fz_new_pwg_band_writer(fz_context *ctx, fz_output *out, const fz_pwg_options *pwg);
501
502 /**
503 Output the file header to a pwg stream, ready for pages to follow it.
504 */
505 void fz_write_pwg_file_header(fz_context *ctx, fz_output *out); /* for use by mudraw.c */
506
507 #endif