From d8b0666bd1ca7e2678dd28da8154484c65623b65 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Wed, 16 Mar 2016 18:03:49 +0000 Subject: mutool draw: Add banded mode output for pbm files. --- source/fitz/bitmap.c | 16 ++++++++++++++-- source/fitz/halftone.c | 8 +++++++- source/tools/mudraw.c | 10 ++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) (limited to 'source') diff --git a/source/fitz/bitmap.c b/source/fitz/bitmap.c index b6eba35f..bc14162a 100644 --- a/source/fitz/bitmap.c +++ b/source/fitz/bitmap.c @@ -45,8 +45,22 @@ fz_clear_bitmap(fz_context *ctx, fz_bitmap *bit) memset(bit->samples, 0, bit->stride * bit->h); } +void +fz_write_pbm_header(fz_context *ctx, fz_output *out, int w, int h) +{ + fz_printf(ctx, out, "P4\n%d %d\n", w, h); +} + void fz_write_bitmap_as_pbm(fz_context *ctx, fz_output *out, fz_bitmap *bitmap) +{ + fz_write_pbm_header(ctx, out, bitmap->w, bitmap->h); + + fz_write_pbm_band(ctx, out, bitmap); +} + +void +fz_write_pbm_band(fz_context *ctx, fz_output *out, fz_bitmap *bitmap) { unsigned char *p; int h, bytestride; @@ -54,8 +68,6 @@ fz_write_bitmap_as_pbm(fz_context *ctx, fz_output *out, fz_bitmap *bitmap) if (bitmap->n != 1) fz_throw(ctx, FZ_ERROR_GENERIC, "too many color components in bitmap"); - fz_printf(ctx, out, "P4\n%d %d\n", bitmap->w, bitmap->h); - p = bitmap->samples; h = bitmap->h; bytestride = (bitmap->w + 7) >> 3; diff --git a/source/fitz/halftone.c b/source/fitz/halftone.c index 705d4718..8cc48a14 100644 --- a/source/fitz/halftone.c +++ b/source/fitz/halftone.c @@ -171,6 +171,11 @@ static void do_threshold_1(unsigned char *ht_line, unsigned char *pixmap, unsign } fz_bitmap *fz_new_bitmap_from_pixmap(fz_context *ctx, fz_pixmap *pix, fz_halftone *ht) +{ + return fz_new_bitmap_from_pixmap_band(ctx, pix, ht, 0, 0); +} + +fz_bitmap *fz_new_bitmap_from_pixmap_band(fz_context *ctx, fz_pixmap *pix, fz_halftone *ht, int band, int bandheight) { fz_bitmap *out = NULL; unsigned char *ht_line = NULL; @@ -186,6 +191,7 @@ fz_bitmap *fz_new_bitmap_from_pixmap(fz_context *ctx, fz_pixmap *pix, fz_halfton fz_var(ht_line); fz_var(out); + band *= bandheight; n = pix->n-1; /* Remove alpha */ if (ht == NULL) { @@ -200,7 +206,7 @@ fz_bitmap *fz_new_bitmap_from_pixmap(fz_context *ctx, fz_pixmap *pix, fz_halfton h = pix->h; x = pix->x; - y = pix->y; + y = pix->y + band; w = pix->w; ostride = out->stride; pstride = pix->w * pix->n; diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c index 54363f03..461f574b 100644 --- a/source/tools/mudraw.c +++ b/source/tools/mudraw.c @@ -631,6 +631,8 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) fz_write_pam_header(ctx, out, pix->w, totalheight, pix->n, savealpha); else if (output_format == OUT_PNG) poc = fz_write_png_header(ctx, out, pix->w, totalheight, pix->n, savealpha); + else if (output_format == OUT_PBM) + fz_write_pbm_header(ctx, out, pix->w, totalheight); } for (band = 0; band < bands; band++) @@ -684,8 +686,8 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) fz_write_pixmap_as_pcl(ctx, out, pix, &options); } else if (output_format == OUT_PBM) { - fz_bitmap *bit = fz_new_bitmap_from_pixmap(ctx, pix, NULL); - fz_write_bitmap_as_pbm(ctx, out, bit); + fz_bitmap *bit = fz_new_bitmap_from_pixmap_band(ctx, pix, NULL, band, bandheight); + fz_write_pbm_band(ctx, out, bit); fz_drop_bitmap(ctx, bit); } else if (output_format == OUT_TGA) @@ -1009,9 +1011,9 @@ int mudraw_main(int argc, char **argv) if (bandheight) { - if (output_format != OUT_PAM && output_format != OUT_PGM && output_format != OUT_PPM && output_format != OUT_PNM && output_format != OUT_PNG) + if (output_format != OUT_PAM && output_format != OUT_PGM && output_format != OUT_PPM && output_format != OUT_PNM && output_format != OUT_PNG && output_format != OUT_PBM) { - fprintf(stderr, "Banded operation only possible with PAM, PGM, PPM, PNM and PNG outputs\n"); + fprintf(stderr, "Banded operation only possible with PAM, PBM, PGM, PPM, PNM and PNG outputs\n"); exit(1); } if (showmd5) -- cgit v1.2.3