shithub: pdffs

Download patch

ref: 76bd9fac44e61eb25333f79206175db9485a3d9c
parent: 75ceb243faad4aa529afef047473ece203113eff
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Nov 21 15:26:02 EST 2020

ascii85 filter

--- a/f_ascii85.c
+++ b/f_ascii85.c
@@ -2,6 +2,35 @@
 #include <libc.h>
 #include "pdf.h"
 
+static int
+flreadall(void *aux, Buffer *bi, Buffer *bo)
+{
+	int i, j, insz;
+	uchar *in;
+	u32int x;
+
+	USED(aux);
+
+	in = bufdata(bi, &insz);
+	for(i = j = 0; i < insz; i++){
+		if(!isws(in[i]))
+			in[j++] = in[i];
+	}
+	insz = j;
+	for(i = 0; i < insz; i += 5){
+		for(x = 0, j = 0; j < 5; j++)
+			x = x*85 + ((i+j < insz ? in[i+j] : 'u') - 33);
+		bufput(bo, (uchar*)&x+3, 1);
+		bufput(bo, (uchar*)&x+2, 1);
+		bufput(bo, (uchar*)&x+1, 1);
+		bufput(bo, (uchar*)&x+0, 1);
+	}
+	in = bufdata(bo, &insz);
+
+	return 0;
+}
+
 Filter filterASCII85 = {
 	.name = "ASCII85Decode",
+	.readall = flreadall,
 };