diff options
author | Robin Watts <robin.watts@artifex.com> | 2013-05-20 17:23:12 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-05-21 14:20:47 +0100 |
commit | d021304f9ff6f74bcc53bf7f42a504bd1b033266 (patch) | |
tree | 91a45a7de144ab94a7d4edb2f2cc8cc67f205c3b | |
parent | a3d00b2c51c1df23258f774f58268be794384c27 (diff) | |
download | mupdf-d021304f9ff6f74bcc53bf7f42a504bd1b033266.tar.xz |
Add PWG options structure for writing PWGs.
This should (pretty much) give us enough to write a mupdftoraster
equivalent of gstoraster.
-rw-r--r-- | apps/mudraw.c | 2 | ||||
-rw-r--r-- | fitz/fitz.h | 54 | ||||
-rw-r--r-- | fitz/res_pixmap.c | 58 |
3 files changed, 92 insertions, 22 deletions
diff --git a/apps/mudraw.c b/apps/mudraw.c index 7efb9aae..3194e7cb 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -583,7 +583,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) { if (strstr(output, "%d") != NULL) append = 0; - fz_write_pwg(ctx, pix, buf, append); + fz_write_pwg(ctx, pix, buf, append, NULL); append = 1; } else if (output_format == OUT_PBM) { diff --git a/fitz/fitz.h b/fitz/fitz.h index 05bf85fb..7b3f33f5 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -1720,13 +1720,61 @@ void fz_write_pam(fz_context *ctx, fz_pixmap *pixmap, char *filename, int saveal */ void fz_write_png(fz_context *ctx, fz_pixmap *pixmap, char *filename, int savealpha); +typedef struct fz_pwg_options_s fz_pwg_options; + +struct fz_pwg_options_s +{ + /* These are not interpreted as CStrings by the writing code, but + * are rather copied directly out. */ + char media_class[64]; + char media_color[64]; + char media_type[64]; + char output_type[64]; + + unsigned int advance_distance; + int advance_media; + int collate; + int cut_media; + int duplex; + int insert_sheet; + int jog; + int leading_edge; + int manual_feed; + unsigned int media_position; + unsigned int media_weight; + int mirror_print; + int negative_print; + unsigned int num_copies; + int orientation; + int output_face_up; + unsigned int PageSize[2]; + int separations; + int tray_switch; + int tumble; + + int media_type_num; + int compression; + unsigned int row_count; + unsigned int row_feed; + unsigned int row_step; + + /* These are not interpreted as CStrings by the writing code, but + * are rather copied directly out. */ + char rendering_intent[64]; + char page_size_name[64]; +}; + /* fz_write_pwg: Save a pixmap as a pwg filename: The filename to save as (including extension). + append: If non-zero, then append a new page to existing file. + + pwg: NULL, or a pointer to an options structure (initialised to zero + before being filled in, for future expansion). */ -void fz_write_pwg(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append); +void fz_write_pwg(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append, const fz_pwg_options *pwg); /* fz_write_pbm: Save a bitmap as a pbm @@ -1858,7 +1906,7 @@ void fz_output_png(fz_output *out, const fz_pixmap *pixmap, int savealpha); /* Output a pixmap to an output stream as a pwg raster. */ -void fz_output_pwg(fz_output *out, const fz_pixmap *pixmap); +void fz_output_pwg(fz_output *out, const fz_pixmap *pixmap, const fz_pwg_options *pwg); /* Output the file header to a pwg stream, ready for pages to follow it. @@ -1868,7 +1916,7 @@ void fz_output_pwg_file_header(fz_output *out); /* Output a page to a pwg stream to follow a header, or other pages. */ -void fz_output_pwg_page(fz_output *out, const fz_pixmap *pixmap); +void fz_output_pwg_page(fz_output *out, const fz_pixmap *pixmap, const fz_pwg_options *pwg); /* Get an image as a png in a buffer. diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c index 18d05231..711b33d3 100644 --- a/fitz/res_pixmap.c +++ b/fitz/res_pixmap.c @@ -736,9 +736,9 @@ fz_output_pwg_file_header(fz_output *out) } void -fz_output_pwg_page(fz_output *out, const fz_pixmap *pixmap) +fz_output_pwg_page(fz_output *out, const fz_pixmap *pixmap, const fz_pwg_options *pwg) { - static const unsigned char zero[4] = { 0 }; + static const unsigned char zero[64] = { 0 }; unsigned char *sp; int y, x, i, sn, dn, ss; fz_context *ctx; @@ -757,33 +757,53 @@ fz_output_pwg_page(fz_output *out, const fz_pixmap *pixmap) dn--; /* Page Header: */ - for (i=0; i < 276; i += 4) - fz_write(out, zero, 4); + fz_write(out, pwg ? pwg->media_class : zero, 64); + fz_write(out, pwg ? pwg->media_color : zero, 64); + fz_write(out, pwg ? pwg->media_type : zero, 64); + fz_write(out, pwg ? pwg->output_type : zero, 64); + fz_write_int32be(out, pwg ? pwg->advance_distance : 0); + fz_write_int32be(out, pwg ? pwg->advance_media : 0); + fz_write_int32be(out, pwg ? pwg->collate : 0); + fz_write_int32be(out, pwg ? pwg->cut_media : 0); + fz_write_int32be(out, pwg ? pwg->duplex : 0); fz_write_int32be(out, pixmap->xres); fz_write_int32be(out, pixmap->yres); /* CUPS format says that 284->300 are supposed to be the bbox of the * page in points. PWG says 'Reserved'. */ for (i=284; i < 300; i += 4) fz_write(out, zero, 4); - for (i=300; i < 340; i += 4) - fz_write(out, zero, 4); - fz_write_int32be(out, 1); /* 1 copy */ - for (i=344; i < 352; i += 4) + fz_write_int32be(out, pwg ? pwg->insert_sheet : 0); + fz_write_int32be(out, pwg ? pwg->jog : 0); + fz_write_int32be(out, pwg ? pwg->leading_edge : 0); + /* CUPS format says that 312->320 are supposed to be the margins of + * the lower left hand edge of page in points. PWG says 'Reserved'. */ + for (i=312; i < 320; i += 4) fz_write(out, zero, 4); + fz_write_int32be(out, pwg ? pwg->manual_feed : 0); + fz_write_int32be(out, pwg ? pwg->media_position : 0); + fz_write_int32be(out, pwg ? pwg->media_weight : 0); + fz_write_int32be(out, pwg ? pwg->mirror_print : 0); + fz_write_int32be(out, pwg ? pwg->negative_print : 0); + fz_write_int32be(out, pwg ? pwg->num_copies : 0); + fz_write_int32be(out, pwg ? pwg->orientation : 0); + fz_write_int32be(out, pwg ? pwg->output_face_up : 0); fz_write_int32be(out, pixmap->w * 72/ pixmap->xres); /* Page size in points */ fz_write_int32be(out, pixmap->h * 72/ pixmap->yres); - for (i=360; i < 372; i += 4) - fz_write(out, zero, 4); + fz_write_int32be(out, pwg ? pwg->separations : 0); + fz_write_int32be(out, pwg ? pwg->tray_switch : 0); + fz_write_int32be(out, pwg ? pwg->tumble : 0); fz_write_int32be(out, pixmap->w); /* Page image in pixels */ fz_write_int32be(out, pixmap->h); - fz_write_int32be(out, 0); /* Reserved */ + fz_write_int32be(out, pwg ? pwg->media_type_num : 0); fz_write_int32be(out, 8); /* Bits per color */ fz_write_int32be(out, 8*dn); /* Bits per pixel */ fz_write_int32be(out, pixmap->w * dn); /* Bytes per line */ fz_write_int32be(out, 0); /* Chunky pixels */ fz_write_int32be(out, dn == 1 ? 18 /* Sgray */ : 19 /* Srgb */); /* Colorspace */ - for (i=404; i < 420; i += 4) - fz_write(out, zero, 4); + fz_write_int32be(out, pwg ? pwg->compression : 0); + fz_write_int32be(out, pwg ? pwg->row_count : 0); + fz_write_int32be(out, pwg ? pwg->row_feed : 0); + fz_write_int32be(out, pwg ? pwg->row_step : 0); fz_write_int32be(out, dn); /* Num Colors */ for (i=424; i < 452; i += 4) fz_write(out, zero, 4); @@ -794,8 +814,10 @@ fz_output_pwg_page(fz_output *out, const fz_pixmap *pixmap) fz_write_int32be(out, 0); /* ImageBoxTop */ fz_write_int32be(out, pixmap->w); /* ImageBoxRight */ fz_write_int32be(out, pixmap->h); /* ImageBoxBottom */ - for (i=480; i < 1796; i += 4) + for (i=480; i < 1668; i += 4) fz_write(out, zero, 4); + fz_write(out, pwg ? pwg->rendering_intent : zero, 64); + fz_write(out, pwg ? pwg->page_size_name : zero, 64); /* Now output the actual bitmap, using a packbits like compression */ sp = pixmap->samples; @@ -866,14 +888,14 @@ fz_output_pwg_page(fz_output *out, const fz_pixmap *pixmap) } void -fz_output_pwg(fz_output *out, const fz_pixmap *pixmap) +fz_output_pwg(fz_output *out, const fz_pixmap *pixmap, const fz_pwg_options *pwg) { fz_output_pwg_file_header(out); - fz_output_pwg_page(out, pixmap); + fz_output_pwg_page(out, pixmap, pwg); } void -fz_write_pwg(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append) +fz_write_pwg(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append, const fz_pwg_options *pwg) { FILE *fp; fz_output *out = NULL; @@ -891,7 +913,7 @@ fz_write_pwg(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append) out = fz_new_output_with_file(ctx, fp); if (!append) fz_output_pwg_file_header(out); - fz_output_pwg_page(out, pixmap); + fz_output_pwg_page(out, pixmap, pwg); } fz_always(ctx) { |