summaryrefslogtreecommitdiff
path: root/xps/xps_image.c
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2011-10-04 18:44:19 +0100
committerRobin Watts <Robin.Watts@artifex.com>2011-10-04 18:44:19 +0100
commitd208be26537db558edb70236ae517cea31b7ebab (patch)
tree57da95b97e354a53bd4517a42010e90968f007d9 /xps/xps_image.c
parentba46cad4b09bb957085900a203206c8fa5868cd4 (diff)
downloadmupdf-d208be26537db558edb70236ae517cea31b7ebab.tar.xz
Move to exception handling rather than error passing throughout.
This frees us from passing errors back everywhere, and hence enables us to pass results back as return values. Rather than having to explicitly check for errors everywhere and bubble them, we now allow exception handling to do the work for us; the downside to this is that we no longer emit as much debugging information as we did before (though this could be put back in). For now, the debugging information we have lost has been retained in comments with 'RJW:' at the start. This code needs fuller testing, but is being committed as a work in progress.
Diffstat (limited to 'xps/xps_image.c')
-rw-r--r--xps/xps_image.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/xps/xps_image.c b/xps/xps_image.c
index dfe0dd91..129637d9 100644
--- a/xps/xps_image.c
+++ b/xps/xps_image.c
@@ -1,40 +1,37 @@
#include "fitz.h"
#include "muxps.h"
-static int
-xps_decode_image(fz_context *doc, fz_pixmap **imagep, byte *buf, int len)
+static fz_pixmap *
+xps_decode_image(fz_context *ctx, byte *buf, int len)
{
- int error;
+ fz_pixmap *image;
if (len < 8)
- return fz_error_make("unknown image file format");
+ fz_throw(ctx, "unknown image file format");
if (buf[0] == 0xff && buf[1] == 0xd8)
{
- error = xps_decode_jpeg(doc, imagep, buf, len);
- if (error)
- return fz_error_note(error, "cannot decode jpeg image");
+ image = xps_decode_jpeg(ctx, buf, len);
+ /* RJW: "cannot decode jpeg image" */
}
else if (memcmp(buf, "\211PNG\r\n\032\n", 8) == 0)
{
- error = xps_decode_png(doc, imagep, buf, len);
- if (error)
- return fz_error_note(error, "cannot decode png image");
+ image = xps_decode_png(ctx, buf, len);
+ /* RJW: "cannot decode png image" */
}
else if (memcmp(buf, "II", 2) == 0 && buf[2] == 0xBC)
{
- return fz_error_make("JPEG-XR codec is not available");
+ fz_throw(ctx, "JPEG-XR codec is not available");
}
else if (memcmp(buf, "MM", 2) == 0 || memcmp(buf, "II", 2) == 0)
{
- error = xps_decode_tiff(doc, imagep, buf, len);
- if (error)
- return fz_error_note(error, "cannot decode TIFF image");
+ image = xps_decode_tiff(ctx, buf, len);
+ /* RJW: "cannot decode TIFF image" */
}
else
- return fz_error_make("unknown image file format");
+ fz_throw(ctx, "unknown image file format");
- return fz_okay;
+ return image;
}
static void
@@ -106,7 +103,6 @@ xps_parse_image_brush(xps_document *doc, fz_matrix ctm, fz_rect area,
{
xps_part *part;
fz_pixmap *image;
- int code;
part = xps_find_image_brush_source_part(doc, base_uri, root);
if (!part) {
@@ -114,8 +110,12 @@ xps_parse_image_brush(xps_document *doc, fz_matrix ctm, fz_rect area,
return;
}
- code = xps_decode_image(doc->ctx, &image, part->data, part->size);
- if (code < 0) {
+ fz_try(doc->ctx)
+ {
+ image = xps_decode_image(doc->ctx, part->data, part->size);
+ }
+ fz_catch(doc->ctx)
+ {
xps_free_part(doc, part);
fz_error_handle(-1, "cannot decode image resource");
return;