From 4e928c68b1852b860122bac28cc0f3af96c3156e Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 13 Feb 2018 13:22:15 +0100 Subject: mutool extract: Don't save raw CMYK jpegs when the -r flag is enabled. --- source/tools/pdfextract.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'source/tools') diff --git a/source/tools/pdfextract.c b/source/tools/pdfextract.c index 000210dd..6de26689 100644 --- a/source/tools/pdfextract.c +++ b/source/tools/pdfextract.c @@ -73,6 +73,7 @@ writejpeg(fz_context *ctx, const unsigned char *data, size_t len, const char *fi out = fz_new_output_with_path(ctx, buf, 0); fz_try(ctx) { + printf("extracting image %s\n", buf); fz_write_data(ctx, out, data, len); fz_close_output(ctx, out); } @@ -102,23 +103,29 @@ static void saveimage(int num) cbuf = fz_compressed_image_buffer(ctx, image); fz_snprintf(buf, sizeof(buf), "img-%04d", num); type = cbuf == NULL ? FZ_IMAGE_UNKNOWN : cbuf->params.type; + if (image->use_colorkey) type = FZ_IMAGE_UNKNOWN; if (image->use_decode) type = FZ_IMAGE_UNKNOWN; if (image->mask) type = FZ_IMAGE_UNKNOWN; - switch (type) + if (dorgb) { - case FZ_IMAGE_JPEG: + enum fz_colorspace_type ctype = fz_colorspace_type(ctx, image->colorspace); + if (ctype != FZ_COLORSPACE_RGB && ctype != FZ_COLORSPACE_GRAY) + type = FZ_IMAGE_UNKNOWN; + } + + if (type == FZ_IMAGE_JPEG) { unsigned char *data; size_t len = fz_buffer_storage(ctx, cbuf->buffer, &data); - fz_snprintf(buf, sizeof(buf), "img-%04d", num); writejpeg(ctx, data, len, buf); break; } - default: + else + { pix = fz_get_pixmap_from_image(ctx, image, NULL, NULL, 0, 0); writepixmap(ctx, pix, buf, dorgb); } -- cgit v1.2.3