summaryrefslogtreecommitdiff
path: root/source/pdf
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-04-14 13:51:32 +0100
committerRobin Watts <robin.watts@artifex.com>2016-04-28 12:30:43 +0100
commit44fff08dc64d358df441a9e615bbaacf7b01d54a (patch)
treebab4f36472952ccdfff594fd699230f2f15b1b23 /source/pdf
parent88e9fd50724cff8d656060715fa56409ba7dab84 (diff)
downloadmupdf-44fff08dc64d358df441a9e615bbaacf7b01d54a.tar.xz
Refactor fz_image code cases.
Split compressed images (images based on a compressed buffer) and pixmap images (images based on a pixmap) out into separate subclasses.
Diffstat (limited to 'source/pdf')
-rw-r--r--source/pdf/pdf-image.c37
-rw-r--r--source/pdf/pdf-op-buffer.c2
-rw-r--r--source/pdf/pdf-stream.c6
3 files changed, 21 insertions, 24 deletions
diff --git a/source/pdf/pdf-image.c b/source/pdf/pdf-image.c
index 86ec41d8..4fec9faa 100644
--- a/source/pdf/pdf-image.c
+++ b/source/pdf/pdf-image.c
@@ -37,20 +37,22 @@ pdf_load_image_imp(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *di
if (forcemask)
{
+ fz_compressed_image *cimg = (fz_compressed_image *)image;
fz_pixmap *mask_pixmap;
+ fz_pixmap *tile = fz_compressed_image_tile(ctx, cimg);
if (image->n != 2)
{
fz_pixmap *gray;
fz_irect bbox;
fz_warn(ctx, "soft mask should be grayscale");
- gray = fz_new_pixmap_with_bbox(ctx, fz_device_gray(ctx), fz_pixmap_bbox(ctx, image->tile, &bbox));
- fz_convert_pixmap(ctx, gray, image->tile);
- fz_drop_pixmap(ctx, image->tile);
- image->tile = gray;
+ gray = fz_new_pixmap_with_bbox(ctx, fz_device_gray(ctx), fz_pixmap_bbox(ctx, tile, &bbox));
+ fz_convert_pixmap(ctx, gray, tile);
+ fz_drop_pixmap(ctx, tile);
+ tile = gray;
}
- mask_pixmap = fz_alpha_from_gray(ctx, image->tile, 1);
- fz_drop_pixmap(ctx, image->tile);
- image->tile = mask_pixmap;
+ mask_pixmap = fz_alpha_from_gray(ctx, tile, 1);
+ fz_drop_pixmap(ctx, tile);
+ fz_set_compressed_image_tile(ctx, cimg, mask_pixmap);
}
break; /* Out of fz_try */
}
@@ -158,21 +160,24 @@ pdf_load_image_imp(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *di
int num = pdf_to_num(ctx, dict);
int gen = pdf_to_gen(ctx, dict);
buffer = pdf_load_compressed_stream(ctx, doc, num, gen);
- image = fz_new_image(ctx, w, h, bpc, colorspace, 96, 96, interpolate, imagemask, decode, use_colorkey ? colorkey : NULL, buffer, mask);
+ image = fz_new_image_from_compressed_buffer(ctx, w, h, bpc, colorspace, 96, 96, interpolate, imagemask, decode, use_colorkey ? colorkey : NULL, buffer, mask);
image->invert_cmyk_jpeg = 0;
}
else
{
/* Inline stream */
stride = (w * n * bpc + 7) / 8;
- image = fz_new_image(ctx, w, h, bpc, colorspace, 96, 96, interpolate, imagemask, decode, use_colorkey ? colorkey : NULL, NULL, mask);
+ image = fz_new_image_from_compressed_buffer(ctx, w, h, bpc, colorspace, 96, 96, interpolate, imagemask, decode, use_colorkey ? colorkey : NULL, NULL, mask);
image->invert_cmyk_jpeg = 0;
- pdf_load_compressed_inline_image(ctx, doc, dict, stride * h, cstm, indexed, image);
+ pdf_load_compressed_inline_image(ctx, doc, dict, stride * h, cstm, indexed, (fz_compressed_image *)image);
}
}
- fz_catch(ctx)
+ fz_always(ctx)
{
fz_drop_colorspace(ctx, colorspace);
+ }
+ fz_catch(ctx)
+ {
fz_drop_image(ctx, mask);
fz_drop_image(ctx, image);
fz_rethrow(ctx);
@@ -269,14 +274,6 @@ pdf_load_jpx(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int forcemask)
return img;
}
-static int
-fz_image_size(fz_context *ctx, fz_image *im)
-{
- if (im == NULL)
- return 0;
- return sizeof(*im) + fz_pixmap_size(ctx, im->tile) + (im->buffer && im->buffer->buffer ? im->buffer->buffer->cap : 0);
-}
-
fz_image *
pdf_load_image(fz_context *ctx, pdf_document *doc, pdf_obj *dict)
{
@@ -303,7 +300,7 @@ pdf_add_image(fz_context *ctx, pdf_document *doc, fz_image *image, int mask)
unsigned char digest[16];
/* If we can maintain compression, do so */
- cbuffer = image->buffer;
+ cbuffer = fz_compressed_image_buffer(ctx, image);
fz_var(pixmap);
fz_var(buffer);
diff --git a/source/pdf/pdf-op-buffer.c b/source/pdf/pdf-op-buffer.c
index 241b096f..163848a0 100644
--- a/source/pdf/pdf-op-buffer.c
+++ b/source/pdf/pdf-op-buffer.c
@@ -551,7 +551,7 @@ pdf_out_BI(fz_context *ctx, pdf_processor *proc, fz_image *img)
if (img == NULL)
return;
- cbuf = img->buffer;
+ cbuf = fz_compressed_image_buffer(ctx, img);
if (cbuf == NULL)
return;
buf = cbuf->buffer;
diff --git a/source/pdf/pdf-stream.c b/source/pdf/pdf-stream.c
index 3c275d2d..167db0a7 100644
--- a/source/pdf/pdf-stream.c
+++ b/source/pdf/pdf-stream.c
@@ -344,7 +344,7 @@ pdf_open_inline_stream(fz_context *ctx, pdf_document *doc, pdf_obj *stmobj, int
}
void
-pdf_load_compressed_inline_image(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int length, fz_stream *stm, int indexed, fz_image *image)
+pdf_load_compressed_inline_image(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int length, fz_stream *stm, int indexed, fz_compressed_image *image)
{
fz_compressed_buffer *bc = fz_malloc_struct(ctx, fz_compressed_buffer);
@@ -357,14 +357,14 @@ pdf_load_compressed_inline_image(fz_context *ctx, pdf_document *doc, pdf_obj *di
stm = fz_open_leecher(ctx, stm, bc->buffer);
stm = fz_open_image_decomp_stream(ctx, stm, &bc->params, &dummy_l2factor);
- image->tile = fz_decomp_image_from_stream(ctx, stm, image, NULL, indexed, 0);
+ fz_set_compressed_image_tile(ctx, image, fz_decomp_image_from_stream(ctx, stm, image, NULL, indexed, 0));
+ fz_set_compressed_image_buffer(ctx, image, bc);
}
fz_catch(ctx)
{
fz_drop_compressed_buffer(ctx, bc);
fz_rethrow(ctx);
}
- image->buffer = bc;
}
/*