diff options
author | Robin Watts <robin.watts@artifex.com> | 2015-01-06 18:19:40 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2015-02-10 20:29:18 +0000 |
commit | 65ada9d7fc252f3dad9b2d3a4a9e571d16358cbd (patch) | |
tree | fbed4d01a134291110ed6095f08d5500370fb4c0 /source/fitz | |
parent | da04ae926d5ba78fd87f4d5da4c1c889b511c74b (diff) | |
download | mupdf-65ada9d7fc252f3dad9b2d3a4a9e571d16358cbd.tar.xz |
Attempting to render a JPEG with xres and yres set to 1 fails.
We end up trying to scale the JPEG up 72 times and fail a malloc.
A better plan is to make the image handler disbelieve any xres or
yres values less than 72dpi. We take care to still preserve aspect
ratios etc.
Diffstat (limited to 'source/fitz')
-rw-r--r-- | source/fitz/image.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/source/fitz/image.c b/source/fitz/image.c index 556e841b..09d39043 100644 --- a/source/fitz/image.c +++ b/source/fitz/image.c @@ -1,5 +1,7 @@ #include "mupdf/fitz.h" +#define SANE_DPI 72.0f + fz_pixmap * fz_new_pixmap_from_image(fz_context *ctx, fz_image *image, int w, int h) { @@ -542,3 +544,43 @@ fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer) return fz_new_image(ctx, w, h, 8, cspace, xres, yres, 0, 0, NULL, NULL, bc, NULL); } + +void +fz_image_get_sanitised_res(fz_image *image, int *xres, int *yres) +{ + *xres = image->xres; + *yres = image->yres; + if (*xres < 0 || *yres < 0 || (*xres == 0 && *yres == 0)) + { + /* If neither xres or yres is sane, pick a sane value */ + *xres = SANE_DPI; *yres = SANE_DPI; + } + else if (*xres == 0) + { + *xres = *yres; + } + else if (*yres == 0) + { + *yres = *xres; + } + + /* Scale xres and yres up until we get beleivable values */ + if (*xres < SANE_DPI || *yres < SANE_DPI) + { + if (*xres == *yres) + { + *xres = SANE_DPI; + *yres = SANE_DPI; + } + else if (*xres < *yres) + { + *yres = *yres * SANE_DPI / *xres; + *xres = SANE_DPI; + } + else + { + *xres = *xres * SANE_DPI / *yres; + *yres = SANE_DPI; + } + } +} |