summaryrefslogtreecommitdiff
path: root/source/fitz/load-jpeg.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/fitz/load-jpeg.c')
-rw-r--r--source/fitz/load-jpeg.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/source/fitz/load-jpeg.c b/source/fitz/load-jpeg.c
index 266cfc80..810d49e0 100644
--- a/source/fitz/load-jpeg.c
+++ b/source/fitz/load-jpeg.c
@@ -145,7 +145,7 @@ static fz_colorspace *extract_icc_profile(fz_context *ctx, jpeg_saved_marker_ptr
fz_always(ctx)
fz_drop_buffer(ctx, buff);
fz_catch(ctx)
- fz_warn(ctx, "Failed to ICC Profile from JPEG");
+ fz_warn(ctx, "could not load ICC profile in JPEG image");
return cs;
}
@@ -259,11 +259,12 @@ fz_load_jpeg(fz_context *ctx, const unsigned char *rbuf, size_t rlen)
struct jpeg_error_mgr err;
struct jpeg_source_mgr src;
unsigned char *row[1], *sp, *dp;
- fz_colorspace *colorspace, *cs = NULL;
+ fz_colorspace *colorspace, *icc;
unsigned int x;
int k, stride;
fz_pixmap *image = NULL;
+ fz_var(colorspace);
fz_var(image);
fz_var(row);
@@ -297,19 +298,18 @@ fz_load_jpeg(fz_context *ctx, const unsigned char *rbuf, size_t rlen)
jpeg_start_decompress(&cinfo);
- if (cinfo.output_components == 1)
- colorspace = fz_device_gray(ctx);
+ icc = extract_icc_profile(ctx, cinfo.marker_list);
+ if (icc != NULL)
+ colorspace = icc;
+ else if (cinfo.output_components == 1)
+ colorspace = fz_keep_colorspace(ctx, fz_device_gray(ctx));
else if (cinfo.output_components == 3)
- colorspace = fz_device_rgb(ctx);
+ colorspace = fz_keep_colorspace(ctx, fz_device_rgb(ctx));
else if (cinfo.output_components == 4)
- colorspace = fz_device_cmyk(ctx);
+ colorspace = fz_keep_colorspace(ctx, fz_device_cmyk(ctx));
else
fz_throw(ctx, FZ_ERROR_GENERIC, "bad number of components in jpeg: %d", cinfo.num_components);
- cs = extract_icc_profile(ctx, cinfo.marker_list);
- if (cs != NULL)
- colorspace = cs;
-
image = fz_new_pixmap(ctx, colorspace, cinfo.output_width, cinfo.output_height, NULL, 0);
if (extract_exif_resolution(cinfo.marker_list, &image->xres, &image->yres))
@@ -378,7 +378,7 @@ fz_load_jpeg_info(fz_context *ctx, const unsigned char *rbuf, size_t rlen, int *
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr err;
struct jpeg_source_mgr src;
- fz_colorspace *cs = NULL;
+ fz_colorspace *icc;
fz_try(ctx)
{
@@ -407,18 +407,21 @@ fz_load_jpeg_info(fz_context *ctx, const unsigned char *rbuf, size_t rlen, int *
jpeg_read_header(&cinfo, 1);
- if (cinfo.num_components == 1)
- *cspacep = fz_device_gray(ctx);
+ *xp = cinfo.image_width;
+ *yp = cinfo.image_height;
+
+ icc = extract_icc_profile(ctx, cinfo.marker_list);
+ if (icc != NULL)
+ *cspacep = icc;
+ else if (cinfo.num_components == 1)
+ *cspacep = fz_keep_colorspace(ctx, fz_device_gray(ctx));
else if (cinfo.num_components == 3)
- *cspacep = fz_device_rgb(ctx);
+ *cspacep = fz_keep_colorspace(ctx, fz_device_rgb(ctx));
else if (cinfo.num_components == 4)
- *cspacep = fz_device_cmyk(ctx);
+ *cspacep = fz_keep_colorspace(ctx, fz_device_cmyk(ctx));
else
fz_throw(ctx, FZ_ERROR_GENERIC, "bad number of components in jpeg: %d", cinfo.num_components);
- *xp = cinfo.image_width;
- *yp = cinfo.image_height;
-
if (extract_exif_resolution(cinfo.marker_list, xresp, yresp))
/* XPS prefers EXIF resolution to JFIF density */;
else if (extract_app13_resolution(cinfo.marker_list, xresp, yresp))
@@ -439,10 +442,6 @@ fz_load_jpeg_info(fz_context *ctx, const unsigned char *rbuf, size_t rlen, int *
*yresp = 0;
}
- cs = extract_icc_profile(ctx, cinfo.marker_list);
- if (cs != NULL)
- *cspacep = cs;
-
if (*xresp <= 0) *xresp = 96;
if (*yresp <= 0) *yresp = 96;
}