diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/fitz/test-device.c | 85 | ||||
-rw-r--r-- | source/tools/mudraw.c | 27 |
2 files changed, 106 insertions, 6 deletions
diff --git a/source/fitz/test-device.c b/source/fitz/test-device.c new file mode 100644 index 00000000..e128e053 --- /dev/null +++ b/source/fitz/test-device.c @@ -0,0 +1,85 @@ +#include <mupdf/fitz.h> + +static void +fz_test_colorspace(fz_context *ctx, fz_colorspace *colorspace, int *iscolor) +{ + if (colorspace && colorspace != fz_device_gray(ctx)) + *iscolor = 1; +} + +static void +fz_test_color(fz_context *ctx, fz_colorspace *colorspace, float *color, int *iscolor) +{ + if (colorspace && colorspace != fz_device_gray(ctx)) + { + float rgb[3]; + fz_convert_color(ctx, fz_device_rgb(ctx), rgb, colorspace, color); + if (rgb[0] != rgb[1] || rgb[0] != rgb[2]) + *iscolor = 1; + } +} + +static void +fz_test_fill_path(fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, + fz_colorspace *colorspace, float *color, float alpha) +{ + fz_test_color(dev->ctx, colorspace, color, dev->user); +} + +static void +fz_test_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, + const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) +{ + fz_test_color(dev->ctx, colorspace, color, dev->user); +} + +static void +fz_test_fill_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, + fz_colorspace *colorspace, float *color, float alpha) +{ + fz_test_color(dev->ctx, colorspace, color, dev->user); +} + +static void +fz_test_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, + const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) +{ + fz_test_color(dev->ctx, colorspace, color, dev->user); +} + +static void +fz_test_fill_shade(fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha) +{ + fz_test_colorspace(dev->ctx, shade->colorspace, dev->user); +} + +static void +fz_test_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha) +{ + fz_test_colorspace(dev->ctx, image->colorspace, dev->user); +} + +static void +fz_test_fill_image_mask(fz_device *dev, fz_image *image, const fz_matrix *ctm, + fz_colorspace *colorspace, float *color, float alpha) +{ + fz_test_color(dev->ctx, colorspace, color, dev->user); +} + +fz_device * +fz_new_test_device(fz_context *ctx, int *iscolor) +{ + fz_device *dev = fz_new_device(ctx, iscolor); + + dev->fill_path = fz_test_fill_path; + dev->stroke_path = fz_test_stroke_path; + dev->fill_text = fz_test_fill_text; + dev->stroke_text = fz_test_stroke_text; + dev->fill_shade = fz_test_fill_shade; + dev->fill_image = fz_test_fill_image; + dev->fill_image_mask = fz_test_fill_image_mask; + + *iscolor = 0; + + return dev; +} diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c index 0eb5e477..79092d9c 100644 --- a/source/tools/mudraw.c +++ b/source/tools/mudraw.c @@ -122,6 +122,7 @@ static int memtrace_current = 0; static int memtrace_peak = 0; static int memtrace_total = 0; static int showmemory = 0; +static int showfeatures = 0; static fz_text_sheet *sheet = NULL; static fz_colorspace *colorspace; static char *filename; @@ -162,6 +163,7 @@ static void usage(void) "\t-G -\tgamma correct output\n" "\t-I\tinvert output\n" "\t-l\tprint outline\n" + "\t-T\ttest for features (grayscale or color)\n" "\t-i\tignore errors and continue with the next file\n" "\tpages\tcomma separated list of ranges\n"); exit(1); @@ -308,9 +310,22 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) } } - if (showmd5 || showtime) + if (showmd5 || showtime || showfeatures) printf("page %s %d", filename, pagenum); + if (showfeatures) + { + int iscolor; + dev = fz_new_test_device(ctx, &iscolor); + if (list) + fz_run_display_list(list, dev, &fz_identity, &fz_infinite_rect, NULL); + else + fz_run_page(doc, page, dev, &fz_identity, &cookie); + fz_free_device(dev); + dev = NULL; + printf(" %s", iscolor ? "color" : "grayscale"); + } + if (pdfout) { fz_matrix ctm; @@ -656,7 +671,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) printf(" %dms", diff); } - if (showmd5 || showtime) + if (showmd5 || showtime || showfeatures) printf("\n"); if (showmemory) @@ -811,7 +826,7 @@ int main(int argc, char **argv) fz_var(doc); - while ((c = fz_getopt(argc, argv, "lo:F:p:r:R:b:c:dgmtx5G:Iw:h:fiMB:")) != -1) + while ((c = fz_getopt(argc, argv, "lo:F:p:r:R:b:c:dgmTtx5G:Iw:h:fiMB:")) != -1) { switch (c) { @@ -828,6 +843,7 @@ int main(int argc, char **argv) case 't': showtext++; break; case 'x': showxml++; break; case '5': showmd5++; break; + case 'T': showfeatures++; break; case 'g': out_cs = CS_GRAY; break; case 'd': uselist = 0; break; case 'c': out_cs = parse_colorspace(fz_optarg); break; @@ -844,7 +860,7 @@ int main(int argc, char **argv) if (fz_optind == argc) usage(); - if (!showtext && !showxml && !showtime && !showmd5 && !showoutline && !output) + if (!showtext && !showxml && !showtime && !showmd5 && !showoutline && !showfeatures && !output) { printf("nothing to do\n"); exit(0); @@ -915,7 +931,6 @@ int main(int argc, char **argv) fprintf(stderr, "Banded operation not compatible with MD5\n"); exit(1); } - } { @@ -1031,7 +1046,7 @@ int main(int argc, char **argv) if (showoutline) drawoutline(ctx, doc); - if (showtext || showxml || showtime || showmd5 || output) + if (showtext || showxml || showtime || showmd5 || showfeatures || output) { if (fz_optind == argc || !isrange(argv[fz_optind])) drawrange(ctx, doc, "1-"); |