summaryrefslogtreecommitdiff
path: root/fitz/filt_jpxd.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 /fitz/filt_jpxd.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 'fitz/filt_jpxd.c')
-rw-r--r--fitz/filt_jpxd.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/fitz/filt_jpxd.c b/fitz/filt_jpxd.c
index d0d6cdef..5700a664 100644
--- a/fitz/filt_jpxd.c
+++ b/fitz/filt_jpxd.c
@@ -18,8 +18,8 @@ static void fz_opj_info_callback(const char *msg, void *client_data)
/* fprintf(stderr, "openjpeg info: %s", msg); */
}
-fz_error
-fz_load_jpx_image(fz_context *ctx, fz_pixmap **imgp, unsigned char *data, int size, fz_colorspace *defcs)
+fz_pixmap *
+fz_load_jpx_image(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs)
{
fz_pixmap *img;
opj_event_mgr_t evtmgr;
@@ -34,7 +34,7 @@ fz_load_jpx_image(fz_context *ctx, fz_pixmap **imgp, unsigned char *data, int si
int x, y, k, v;
if (size < 2)
- return fz_error_make("not enough data to determine image format");
+ fz_throw(ctx, "not enough data to determine image format");
/* Check for SOC marker -- if found we have a bare J2K stream */
if (data[0] == 0xFF && data[1] == 0x4F)
@@ -61,16 +61,16 @@ fz_load_jpx_image(fz_context *ctx, fz_pixmap **imgp, unsigned char *data, int si
opj_destroy_decompress(info);
if (!jpx)
- return fz_error_make("opj_decode failed");
+ fz_throw(ctx, "opj_decode failed");
for (k = 1; k < jpx->numcomps; k++)
{
if (jpx->comps[k].w != jpx->comps[0].w)
- return fz_error_make("image components have different width");
+ fz_throw(ctx, "image components have different width");
if (jpx->comps[k].h != jpx->comps[0].h)
- return fz_error_make("image components have different height");
+ fz_throw(ctx, "image components have different height");
if (jpx->comps[k].prec != jpx->comps[0].prec)
- return fz_error_make("image components have different precision");
+ fz_throw(ctx, "image components have different precision");
}
n = jpx->numcomps;
@@ -112,7 +112,7 @@ fz_load_jpx_image(fz_context *ctx, fz_pixmap **imgp, unsigned char *data, int si
if (!img)
{
opj_image_destroy(jpx);
- return fz_error_make("out of memory");
+ fz_throw(ctx, "out of memory");
}
p = img->samples;
@@ -148,6 +148,5 @@ fz_load_jpx_image(fz_context *ctx, fz_pixmap **imgp, unsigned char *data, int si
opj_image_destroy(jpx);
- *imgp = img;
- return fz_okay;
+ return img;
}