write-pixmap.h 15 KB

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