shithub: pdffs

Download patch

ref: e74f20021a4e51323d1c0f9356e9ff2a8030139c
parent: 6c254ed21adcbe5c3ee8af5449d06cb88bdd351e
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Apr 9 11:11:25 EDT 2021

jbig2: extract as a full jbig2 file, honor JBIG2Globals

--- a/f_flate.c
+++ b/f_flate.c
@@ -3,7 +3,6 @@
 #include <flate.h>
 #include "pdf.h"
 
-
 static int
 bw(void *aux, void *d, int n)
 {
--- a/f_jbig2.c
+++ b/f_jbig2.c
@@ -2,11 +2,23 @@
 #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)
 {
-	USED(aux);
+	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;
 
@@ -13,7 +25,30 @@
 	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,
 };