From d53ab7a97c018aaa0e0adcaabcebcc72c080f724 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sat, 29 Oct 2016 15:53:58 +0800 Subject: Let pixmap colorspace conversion create new pixmap. This moves dropping the converted pixmap into fz_convert_pixmap(), which relieves every caller from doing so. Moreover resolution, position and interpolation are kept. --- source/fitz/pixmap.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'source/fitz/pixmap.c') diff --git a/source/fitz/pixmap.c b/source/fitz/pixmap.c index 9131a7a1..1d080576 100644 --- a/source/fitz/pixmap.c +++ b/source/fitz/pixmap.c @@ -859,6 +859,36 @@ fz_pixmap_size(fz_context *ctx, fz_pixmap * pix) return sizeof(*pix) + pix->n * pix->w * pix->h; } +fz_pixmap * +fz_convert_pixmap(fz_context *ctx, fz_pixmap *pix, fz_colorspace *ds, int keep_alpha) +{ + fz_pixmap *cvt; + + if (!ds && !keep_alpha) + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot both throw away and keep alpha"); + + cvt = fz_new_pixmap(ctx, ds, pix->w, pix->h, keep_alpha && pix->alpha); + + cvt->xres = pix->xres; + cvt->yres = pix->yres; + cvt->x = pix->x; + cvt->y = pix->y; + cvt->interpolate = pix->interpolate; + + fz_try(ctx) + { + fz_pixmap_converter *pc = fz_lookup_pixmap_converter(ctx, ds, pix->colorspace); + pc(ctx, cvt, pix); + } + fz_catch(ctx) + { + fz_drop_pixmap(ctx, cvt); + fz_rethrow(ctx); + } + + return cvt; +} + fz_pixmap * fz_new_pixmap_from_8bpp_data(fz_context *ctx, int x, int y, int w, int h, unsigned char *sp, int span) { -- cgit v1.2.3