summaryrefslogtreecommitdiff
path: root/source/fitz
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2014-07-17 16:19:28 +0200
committerTor Andersson <tor.andersson@artifex.com>2014-07-17 16:19:28 +0200
commit21b8f3b454732f0a68f66eba223ee8afe754ced1 (patch)
treea70a8402c7ac9cb78796980d1abbacfa8673aa7e /source/fitz
parent2a1a79c623636c8cf47a96ca8424174a9283aa10 (diff)
downloadmupdf-21b8f3b454732f0a68f66eba223ee8afe754ced1.tar.xz
Add feature testing device, and call it from mudraw with -T flag.
Currently only tests for the presence of non-grayscale color.
Diffstat (limited to 'source/fitz')
-rw-r--r--source/fitz/test-device.c85
1 files changed, 85 insertions, 0 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;
+}