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 /cbz/mucbz.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 'cbz/mucbz.c')
-rw-r--r-- | cbz/mucbz.c | 73 |
1 files changed, 11 insertions, 62 deletions
diff --git a/cbz/mucbz.c b/cbz/mucbz.c index 874e1455..bcda8562 100644 --- a/cbz/mucbz.c +++ b/cbz/mucbz.c @@ -19,18 +19,9 @@ static const char *cbz_ext_list[] = { NULL }; -typedef struct cbz_image_s cbz_image; - -struct cbz_image_s -{ - fz_image base; - int xres, yres; - fz_pixmap *pix; -}; - struct cbz_page_s { - cbz_image *image; + fz_image *image; }; typedef struct cbz_entry_s cbz_entry; @@ -351,33 +342,12 @@ cbz_count_pages(cbz_document *doc) return doc->page_count; } -static void -cbz_free_image(fz_context *ctx, fz_storable *image_) -{ - cbz_image *image = (cbz_image *)image_; - - if (image == NULL) - return; - fz_drop_pixmap(ctx, image->pix); - fz_free(ctx, image); -} - -static fz_pixmap * -cbz_image_to_pixmap(fz_context *ctx, fz_image *image_, int x, int w) -{ - cbz_image *image = (cbz_image *)image_; - - return fz_keep_pixmap(ctx, image->pix); -} - cbz_page * cbz_load_page(cbz_document *doc, int number) { fz_context *ctx = doc->ctx; - unsigned char *data = NULL; + unsigned char *data; cbz_page *page = NULL; - cbz_image *image = NULL; - fz_pixmap *pixmap = NULL; int size; if (number < 0 || number >= doc->page_count) @@ -387,8 +357,6 @@ cbz_load_page(cbz_document *doc, int number) fz_var(data); fz_var(page); - fz_var(image); - fz_var(pixmap); fz_try(ctx) { page = fz_malloc_struct(ctx, cbz_page); @@ -396,26 +364,7 @@ cbz_load_page(cbz_document *doc, int number) data = cbz_read_zip_entry(doc, doc->entry[number].offset, &size); - if (size > 2 && data[0] == 0xff && data[1] == 0xd8) - pixmap = fz_load_jpeg(ctx, data, size); - else if (size > 8 && memcmp(data, "\211PNG\r\n\032\n", 8) == 0) - pixmap = fz_load_png(ctx, data, size); - else - fz_throw(ctx, "unknown image format"); - - image = fz_malloc_struct(ctx, cbz_image); - FZ_INIT_STORABLE(&image->base, 1, cbz_free_image); - image->base.w = pixmap->w; - image->base.h = pixmap->h; - image->base.get_pixmap = cbz_image_to_pixmap; - image->xres = pixmap->xres; - image->yres = pixmap->yres; - image->pix = pixmap; - page->image = image; - } - fz_always(ctx) - { - fz_free(ctx, data); + page->image = fz_new_image_from_buffer(ctx, data, size); } fz_catch(ctx) { @@ -431,17 +380,17 @@ cbz_free_page(cbz_document *doc, cbz_page *page) { if (!page) return; - fz_drop_image(doc->ctx, &page->image->base); + fz_drop_image(doc->ctx, page->image); fz_free(doc->ctx, page); } fz_rect * cbz_bound_page(cbz_document *doc, cbz_page *page, fz_rect *bbox) { - cbz_image *image = page->image; + fz_image *image = page->image; bbox->x0 = bbox->y0 = 0; - bbox->x1 = image->base.w * DPI / image->xres; - bbox->y1 = image->base.h * DPI / image->yres; + bbox->x1 = image->w * DPI / image->xres; + bbox->y1 = image->h * DPI / image->yres; return bbox; } @@ -449,11 +398,11 @@ void cbz_run_page(cbz_document *doc, cbz_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie) { fz_matrix local_ctm = *ctm; - cbz_image *image = page->image; - float w = image->base.w * DPI / image->xres; - float h = image->base.h * DPI / image->yres; + fz_image *image = page->image; + float w = image->w * DPI / image->xres; + float h = image->h * DPI / image->yres; fz_pre_scale(&local_ctm, w, h); - fz_fill_image(dev, &image->base, &local_ctm, 1); + fz_fill_image(dev, image, &local_ctm, 1); } static int |