shithub: pdffs

ref: c626c599b018d47759a86629c1474b04480675c6
dir: /f_jbig2.c/

View raw version
#include <u.h>
#include <libc.h>
#include "pdf.h"

/* 7.4.7 JBIG2Decode filter */

static u8int bh[] = {
	/* id string  */ 0x97, 0x4a, 0x42, 0x32, 0x0d, 0x0a, 0x1a, 0x0a,
	/* sequential */ 0x01,
	/* one page   */ 0x00, 0x00, 0x00, 0x01,
};

static int
flreadall(void *aux, Buffer *bi, Buffer *bo)
{
	Stream *s;

	s = aux;
	bufput(bo, bh, sizeof(bh));
	if(s != nil)
		bufput(bo, s->buf.b, s->buf.sz);
	bufput(bo, bi->b, bi->sz);
	bi->off = bi->sz;

	return 0;
}

static int
flopen(Filter *f, Object *o)
{
	Object *parms, *so;
	Stream *s;

	parms = dictget(o, "DecodeParms");
	s = nil;
	if((so = dictget(parms, "JBIG2Globals")) != &null && (s = Sopen(so)) == nil)
		return -1;
	f->aux = s;

	return 0;
}

static void
flclose(Filter *f)
{
	Sclose(f->aux);
}

Filter filterJBIG2 = {
	.name = "JBIG2Decode",
	.readall = flreadall,
	.open = flopen,
	.close = flclose,
};