summaryrefslogtreecommitdiff
path: root/filter/filter.c
blob: 8e28a532e9a69b3de4b5637d8b5e23ed5a48e1f6 (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
50
51
52
53
54
55
56
57
58
59
#include <fitz.h>

fz_error fz_kioneedin = {
	.msg = {"<ioneedin>"},
	.func = {"<process>"},
	.file = {"filter.c"},
    .line = 0,
	.frozen = 1
};

fz_error fz_kioneedout = {
	.msg = {"<ioneedout>"},
	.func = {"<process>"},
	.file = {"filter.c"},
    .line = 0,
	.frozen = 1
};

fz_error fz_kiodone = {
	.msg = {"<iodone>"},
	.func = {"<process>"},
	.file = {"filter.c"},
    .line = 0,
	.frozen = 1
};

fz_error *
fz_process(fz_filter *f, fz_buffer *in, fz_buffer *out)
{
	fz_error *reason;
	unsigned char *oldrp;
	unsigned char *oldwp;

	assert(!out->eof);

	oldrp = in->rp;
	oldwp = out->wp;

	reason = f->process(f, in, out);

	assert(in->rp <= in->wp);
	assert(out->wp <= out->ep);

	f->consumed = in->rp > oldrp;
	f->produced = out->wp > oldwp;
	f->count += out->wp - oldwp;

	if (reason != fz_ioneedin && reason != fz_ioneedout)
		out->eof = 1;

	return reason;
}

void
fz_freefilter(fz_filter *f)
{
	f->free(f);
}