diff options
author | Robin Watts <robin.watts@artifex.com> | 2013-04-05 15:49:10 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-04-11 19:00:39 +0100 |
commit | 53b5ede268394d651df1f12da490884bf870006a (patch) | |
tree | 72145964ff775415674c73b1e05ea18669238278 /xps/xps_image.c | |
parent | 05f9887c211fff4195b5959bc71d2ef4b773fdc2 (diff) | |
download | mupdf-53b5ede268394d651df1f12da490884bf870006a.tar.xz |
Move pdf_image to fz_image.
In order to be able to output images (either in the pdfwrite device or
in the html conversion), we need to be able to get to the original
compressed data stream (or else we're going to end up recompressing
images). To do that, we need to expose all of the contents of pdf_image
into fz_image, so it makes sense to just amalgamate the two.
This has knock on effects for the creation of indexed colorspaces,
requiring some of that logic to be moved.
Also, we need to make xps use the same structures; this means pushing
PNG and TIFF support into the decoding code. Also we need to be able
to load just the headers from PNG/TIFF/JPEGs as xps doesn't include
dimension/resolution information.
Also, separate out all the fz_image stuff into fitz/res_image.c rather
than having it in res_pixmap.
Diffstat (limited to 'xps/xps_image.c')
-rw-r--r-- | xps/xps_image.c | 85 |
1 files changed, 10 insertions, 75 deletions
diff --git a/xps/xps_image.c b/xps/xps_image.c index 449b5dda..ea8d547b 100644 --- a/xps/xps_image.c +++ b/xps/xps_image.c @@ -1,77 +1,12 @@ #include "muxps-internal.h" -typedef struct xps_image_s xps_image; - -struct xps_image_s -{ - fz_image base; - fz_pixmap *pix; - int xres; - int yres; -}; - -static void -xps_free_image(fz_context *ctx, fz_storable *image_) -{ - xps_image *image = (xps_image *)image_; - - if (image == NULL) - return; - - fz_drop_colorspace(ctx, image->base.colorspace); - fz_drop_pixmap(ctx, image->pix); - fz_free(ctx, image); -} - -static fz_pixmap * -xps_image_to_pixmap(fz_context *ctx, fz_image *image_, int x, int w) -{ - xps_image *image = (xps_image *)image_; - - return fz_keep_pixmap(ctx, image->pix); -} - static fz_image * -xps_load_image(fz_context *ctx, byte *buf, int len) +xps_load_image(fz_context *ctx, xps_part *part) { - fz_pixmap *pix; - xps_image *image; - - if (len < 8) - fz_throw(ctx, "unknown image file format"); - - if (buf[0] == 0xff && buf[1] == 0xd8) - pix = fz_load_jpeg(ctx, buf, len); - else if (memcmp(buf, "\211PNG\r\n\032\n", 8) == 0) - pix = fz_load_png(ctx, buf, len); - else if (memcmp(buf, "II", 2) == 0 && buf[2] == 0xBC) - fz_throw(ctx, "JPEG-XR codec is not available"); - else if (memcmp(buf, "MM", 2) == 0 || memcmp(buf, "II", 2) == 0) - pix = fz_load_tiff(ctx, buf, len); - else - fz_throw(ctx, "unknown image file format"); - - fz_try(ctx) - { - image = fz_malloc_struct(ctx, xps_image); - - FZ_INIT_STORABLE(&image->base, 1, xps_free_image); - image->base.w = pix->w; - image->base.h = pix->h; - image->base.mask = NULL; - image->base.colorspace = pix->colorspace; - image->base.get_pixmap = xps_image_to_pixmap; - image->xres = pix->xres; - image->yres = pix->yres; - image->pix = pix; - } - fz_catch(ctx) - { - fz_drop_pixmap(ctx, pix); - fz_rethrow(ctx); - } - - return &image->base; + /* Ownership of data always passes in here */ + byte *data = part->data; + part->data = NULL; + return fz_new_image_from_buffer(ctx, data, part->size); } /* FIXME: area unused! */ @@ -79,16 +14,16 @@ static void xps_paint_image_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *root, void *vimage) { - xps_image *image = vimage; + fz_image *image = vimage; float xs, ys; fz_matrix local_ctm = *ctm; if (image->xres == 0 || image->yres == 0) return; - xs = image->base.w * 96 / image->xres; - ys = image->base.h * 96 / image->yres; + xs = image->w * 96 / image->xres; + ys = image->h * 96 / image->yres; fz_pre_scale(&local_ctm, xs, ys); - fz_fill_image(doc->dev, &image->base, &local_ctm, doc->opacity[doc->opacity_top]); + fz_fill_image(doc->dev, image, &local_ctm, doc->opacity[doc->opacity_top]); } static xps_part * @@ -160,7 +95,7 @@ xps_parse_image_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *ar fz_try(doc->ctx) { - image = xps_load_image(doc->ctx, part->data, part->size); + image = xps_load_image(doc->ctx, part); } fz_always(doc->ctx) { |