diff options
-rw-r--r-- | include/mupdf/fitz/bitmap.h | 2 | ||||
-rw-r--r-- | include/mupdf/fitz/output-pnm.h | 4 | ||||
-rw-r--r-- | source/fitz/bitmap.c | 16 | ||||
-rw-r--r-- | source/fitz/halftone.c | 8 | ||||
-rw-r--r-- | source/tools/mudraw.c | 10 |
5 files changed, 33 insertions, 7 deletions
diff --git a/include/mupdf/fitz/bitmap.h b/include/mupdf/fitz/bitmap.h index feb9afa6..84a624bc 100644 --- a/include/mupdf/fitz/bitmap.h +++ b/include/mupdf/fitz/bitmap.h @@ -53,6 +53,8 @@ typedef struct fz_halftone_s fz_halftone; */ fz_bitmap *fz_new_bitmap_from_pixmap(fz_context *ctx, fz_pixmap *pix, fz_halftone *ht); +fz_bitmap *fz_new_bitmap_from_pixmap_band(fz_context *ctx, fz_pixmap *pix, fz_halftone *ht, int band, int bandheight); + struct fz_bitmap_s { int refs; diff --git a/include/mupdf/fitz/output-pnm.h b/include/mupdf/fitz/output-pnm.h index ba12b807..f941b396 100644 --- a/include/mupdf/fitz/output-pnm.h +++ b/include/mupdf/fitz/output-pnm.h @@ -32,4 +32,8 @@ void fz_save_bitmap_as_pbm(fz_context *ctx, fz_bitmap *bitmap, char *filename); void fz_write_bitmap_as_pbm(fz_context *ctx, fz_output *out, fz_bitmap *bitmap); +void fz_write_pbm_header(fz_context *ctx, fz_output *out, int w, int h); + +void fz_write_pbm_band(fz_context *ctx, fz_output *out, fz_bitmap *bitmap); + #endif 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 @@ -46,16 +46,28 @@ fz_clear_bitmap(fz_context *ctx, fz_bitmap *bit) } 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; 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 @@ -172,6 +172,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; unsigned char *o, *p; @@ -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) |