From c4e870b5422207e6ca31eb2cd6694ba44faec21e Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Wed, 7 Mar 2012 17:08:41 +0000 Subject: Tweak Halftone functions A NULL halftone pointer passed to fz_halftone_pixmap is now taken to mean "use the default halftone". This means we can remove most of the halftone functions from the public API until (post 1.0) we decide to flesh out the functionality. --- apps/mudraw.c | 4 +--- fitz/fitz-internal.h | 2 ++ fitz/fitz.h | 16 ++++++++++++++-- fitz/res_halftone.c | 9 ++++++++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/apps/mudraw.c b/apps/mudraw.c index 8b3aebf5..7c79b2fa 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -240,11 +240,9 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) else if (strstr(output, ".png")) fz_write_png(ctx, pix, buf, savealpha); else if (strstr(output, ".pbm")) { - fz_halftone *ht = fz_get_default_halftone(ctx, 1); - fz_bitmap *bit = fz_halftone_pixmap(ctx, pix, ht); + fz_bitmap *bit = fz_halftone_pixmap(ctx, pix, NULL); fz_write_pbm(ctx, bit, buf); fz_drop_bitmap(ctx, bit); - fz_drop_halftone(ctx, ht); } } diff --git a/fitz/fitz-internal.h b/fitz/fitz-internal.h index f9175c65..efc08a41 100644 --- a/fitz/fitz-internal.h +++ b/fitz/fitz-internal.h @@ -559,6 +559,8 @@ struct fz_halftone_s }; fz_halftone *fz_new_halftone(fz_context *ctx, int num_comps); +fz_halftone *fz_get_default_halftone(fz_context *ctx, int num_comps); +void fz_drop_halftone(fz_context *ctx, fz_halftone *half); fz_halftone *fz_keep_halftone(fz_context *ctx, fz_halftone *half); struct fz_colorspace_s diff --git a/fitz/fitz.h b/fitz/fitz.h index 4de15e0e..a6a197ca 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -962,11 +962,23 @@ fz_image *fz_keep_image(fz_context *ctx, fz_image *image); /* A halftone is a set of threshold tiles, one per component. Each threshold tile is a pixmap, possibly of varying sizes and phases. + Currently, we only provide one 'default' halftone tile for operating + on 1 component plus alpha pixmaps (where the alpha is ignored). This + is signified by an fz_halftone pointer to NULL. */ typedef struct fz_halftone_s fz_halftone; -fz_halftone *fz_get_default_halftone(fz_context *ctx, int num_comps); -void fz_drop_halftone(fz_context *ctx, fz_halftone *half); +/* + fz_halftone_pixmap: Make a bitmap from a pixmap and a halftone. + + pix: The pixmap to generate from. Currently must be a single color + component + alpha (where the alpha is assumed to be solid). + + ht: The halftone to use. NULL implies the default halftone. + + Returns the resultant bitmap. Throws exceptions in the case of + failure to allocate. +*/ fz_bitmap *fz_halftone_pixmap(fz_context *ctx, fz_pixmap *pix, fz_halftone *ht); /* diff --git a/fitz/res_halftone.c b/fitz/res_halftone.c index b7728eb5..ec26571e 100644 --- a/fitz/res_halftone.c +++ b/fitz/res_halftone.c @@ -162,13 +162,18 @@ fz_bitmap *fz_halftone_pixmap(fz_context *ctx, fz_pixmap *pix, fz_halftone *ht) fz_bitmap *out; unsigned char *ht_line, *o, *p; int w, h, x, y, n, pstride, ostride; + fz_halftone *ht_orig = ht; - if (!pix || !ht) + if (!pix) return NULL; assert(pix->n == 2); /* Mono + Alpha */ n = pix->n-1; /* Remove alpha */ + if (ht == NULL) + { + ht = fz_get_default_halftone(ctx, n); + } ht_line = fz_malloc(ctx, pix->w * n); out = fz_new_bitmap(ctx, pix->w, pix->h, n); o = out->samples; @@ -187,5 +192,7 @@ fz_bitmap *fz_halftone_pixmap(fz_context *ctx, fz_pixmap *pix, fz_halftone *ht) o += ostride; p += pstride; } + if (!ht_orig) + fz_drop_halftone(ctx, ht); return out; } -- cgit v1.2.3