summaryrefslogtreecommitdiff
path: root/source/fitz/function.c
blob: 75e47a9491b38151150c244d26cd9ce81ab588fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "mupdf/fitz.h"

void
fz_eval_function(fz_context *ctx, fz_function *func, const float *in, int inlen, float *out, int outlen)
{
	float fakein[FZ_FN_MAXM];
	float fakeout[FZ_FN_MAXN];
	int i;

	if (inlen < func->m)
	{
		for (i = 0; i < func->m; ++i)
			fakein[i] = in[i];
		for (; i < inlen; ++i)
			fakein[i] = 0;
		in = fakein;
	}

	if (outlen < func->n)
	{
		func->evaluate(ctx, func, in, fakeout);
		for (i = 0; i < outlen; ++i)
			out[i] = fakeout[i];
	}
	else
	{
		func->evaluate(ctx, func, in, out);
		for (i = func->n; i < outlen; ++i)
			out[i] = 0;
	}
}

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_context *ctx, fz_function *func)
{
	return (func ? func->size : 0);
}