summaryrefslogtreecommitdiff
path: root/fitz
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-10-01 19:20:45 +0100
committerRobin Watts <robin.watts@artifex.com>2013-03-26 13:58:59 +0000
commit68660cd89703996ca315b4affcf37582ed660237 (patch)
treee44026bfde0a28f27e136d0fa2bc83130c773eeb /fitz
parent266a1a44d2f6e73878fb742e088ea722873a182e (diff)
downloadmupdf-68660cd89703996ca315b4affcf37582ed660237.tar.xz
Make pdf_functions public as fz_functions.
Implementations remain unexposed, but this means we can safely pass functions in shades without having to 'sample' them (though we may still choose to do this for speed).
Diffstat (limited to 'fitz')
-rw-r--r--fitz/fitz-internal.h32
-rw-r--r--fitz/res_func.c48
2 files changed, 80 insertions, 0 deletions
diff --git a/fitz/fitz-internal.h b/fitz/fitz-internal.h
index 01f32172..a54a4780 100644
--- a/fitz/fitz-internal.h
+++ b/fitz/fitz-internal.h
@@ -1274,6 +1274,38 @@ fz_text *fz_clone_text(fz_context *ctx, fz_text *old);
void fz_print_text(fz_context *ctx, FILE *out, fz_text*);
/*
+ * The generic function support.
+ */
+
+typedef struct fz_function_s fz_function;
+
+void fz_eval_function(fz_context *ctx, fz_function *func, float *in, int inlen, float *out, int outlen);
+fz_function *fz_keep_function(fz_context *ctx, fz_function *func);
+void fz_drop_function(fz_context *ctx, fz_function *func);
+unsigned int fz_function_size(fz_function *func);
+#ifndef DEBUG
+void pdf_debug_function(fz_function *func);
+#endif
+
+enum
+{
+ FZ_FN_MAXN = FZ_MAX_COLORS,
+ FZ_FN_MAXM = FZ_MAX_COLORS
+};
+
+struct fz_function_s
+{
+ fz_storable storable;
+ unsigned int size;
+ int m; /* number of input values */
+ int n; /* number of output values */
+ void (*evaluate)(fz_context *ctx, fz_function *func, float *in, float *out);
+#ifndef NDEBUG
+ void (*debug)(fz_function *func);
+#endif
+};
+
+/*
* The shading code uses gouraud shaded triangle meshes.
*/
diff --git a/fitz/res_func.c b/fitz/res_func.c
new file mode 100644
index 00000000..a8ffa907
--- /dev/null
+++ b/fitz/res_func.c
@@ -0,0 +1,48 @@
+#include "fitz-internal.h"
+
+void
+fz_eval_function(fz_context *ctx, fz_function *func, float *in_, int inlen, float *out_, int outlen)
+{
+ float fakein[FZ_FN_MAXM];
+ float fakeout[FZ_FN_MAXN];
+ float *in = in_;
+ float *out = out_;
+
+ if (inlen < func->m)
+ {
+ in = fakein;
+ memset(in, 0, sizeof(float) * func->m);
+ memcpy(in, in_, sizeof(float) * inlen);
+ }
+
+ if (outlen < func->n)
+ {
+ out = fakeout;
+ memset(out, 0, sizeof(float) * func->n);
+ }
+ else
+ memset(out, 0, sizeof(float) * outlen);
+
+ func->evaluate(ctx, func, in, out);
+
+ if (outlen < func->n)
+ memcpy(out_, out, sizeof(float) * outlen);
+}
+
+fz_function *
+fz_keep_function(fz_context *ctx, fz_function *func)
+{
+ return (fz_function *)fz_keep_storable(ctx, &func->storable);
+}
+
+void
+fz_drop_function(fz_context *ctx, fz_function *func)
+{
+ fz_drop_storable(ctx, &func->storable);
+}
+
+unsigned int
+fz_function_size(fz_function *func)
+{
+ return (func ? func->size : 0);
+}