summaryrefslogtreecommitdiff
path: root/filter/filter.c
blob: 25bbd441690309ce3171d9023cd7414f55d637fd (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
#include <fitz.h>

fz_error fz_kioneedin = { "<ioneedin>", "<process>", "filter.c", 0, 1 };
fz_error fz_kioneedout = { "<ioneedout>", "<process>", "filter.c", 0, 1 };
fz_error fz_kiodone = { "<iodone>", "<process>", "filter.c", 0, 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_dropfilter(fz_filter *f)
{
	if (f->drop)
		f->drop(f);
	fz_free(f);
}