ref: a105fe96aac770cd3c939c7744715a8d8982795f
parent: ac1954db2882d7e6ff01eb490e68de7294424b4d
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Nov 21 07:56:47 EST 2020
keep filters in their own files
--- /dev/null
+++ b/f_ascii85.c
@@ -1,0 +1,7 @@
+#include <u.h>
+#include <libc.h>
+#include "pdf.h"
+
+Filter filterASCII85 = {
+ .name = "ASCII85Decode",
+};
--- /dev/null
+++ b/f_asciihex.c
@@ -1,0 +1,7 @@
+#include <u.h>
+#include <libc.h>
+#include "pdf.h"
+
+Filter filterASCIIHex = {
+ .name = "ASCIIHexDecode",
+};
--- /dev/null
+++ b/f_ccittfax.c
@@ -1,0 +1,7 @@
+#include <u.h>
+#include <libc.h>
+#include "pdf.h"
+
+Filter filterCCITTFax = {
+ .name = "CCITTFaxDecode",
+};
--- /dev/null
+++ b/f_crypt.c
@@ -1,0 +1,7 @@
+#include <u.h>
+#include <libc.h>
+#include "pdf.h"
+
+Filter filterCrypt = {
+ .name = "CryptDecode",
+};
--- /dev/null
+++ b/f_dct.c
@@ -1,0 +1,16 @@
+#include <u.h>
+#include <libc.h>
+#include "pdf.h"
+
+static int
+flreadall(void *aux, Buffer *bi, Buffer *bo)
+{
+ USED(aux);
+ bufput(bo, bi->b, bi->sz);
+ return 0;
+}
+
+Filter filterDCT = {
+ .name = "DCTDecode",
+ .readall = flreadall,
+};
--- a/f_flate.c
+++ b/f_flate.c
@@ -80,8 +80,8 @@
return bufget(aux, &c, 1) == 1 ? c : -1;
}
-int
-fFlate(void *aux, Buffer *bi, Buffer *bo)
+static int
+flreadall(void *aux, Buffer *bi, Buffer *bo)
{
int r, i, rows, n;
FlateParms *fp;
@@ -119,8 +119,8 @@
return r;
}
-int
-openFlate(Filter *f, Object *o)
+static int
+flopen(Filter *f, Object *o)
{
Object *parms;
FlateParms *fp;
@@ -147,8 +147,15 @@
return 0;
}
-void
-closeFlate(Filter *f)
+static void
+flclose(Filter *f)
{
free(f->aux);
}
+
+Filter filterFlate = {
+ .name = "FlateDecode",
+ .readall = flreadall,
+ .open = flopen,
+ .close = flclose,
+};
--- /dev/null
+++ b/f_jbig2.c
@@ -1,0 +1,7 @@
+#include <u.h>
+#include <libc.h>
+#include "pdf.h"
+
+Filter filterJBIG2 = {
+ .name = "JBIG2Decode",
+};
--- /dev/null
+++ b/f_jpx.c
@@ -1,0 +1,7 @@
+#include <u.h>
+#include <libc.h>
+#include "pdf.h"
+
+Filter filterJPX = {
+ .name = "JPXDecode",
+};
--- /dev/null
+++ b/f_lzw.c
@@ -1,0 +1,7 @@
+#include <u.h>
+#include <libc.h>
+#include "pdf.h"
+
+Filter filterLZW = {
+ .name = "LZWDecode",
+};
--- /dev/null
+++ b/f_runlength.c
@@ -1,0 +1,16 @@
+#include <u.h>
+#include <libc.h>
+#include "pdf.h"
+
+static int
+flreadall(void *aux, Buffer *bi, Buffer *bo)
+{
+ USED(aux);
+ bufput(bo, bi->b, bi->sz);
+ return 0;
+}
+
+Filter filterRunLength = {
+ .name = "RunLengthDecode",
+ .readall = flreadall,
+};
--- a/filter.c
+++ b/filter.c
@@ -4,29 +4,28 @@
/* 7.4 Filters */
-int fFlate(void *aux, Buffer *bi, Buffer *bo);
-int openFlate(Filter *f, Object *o);
-void closeFlate(Filter *f);
+extern Filter filterASCII85;
+extern Filter filterASCIIHex;
+extern Filter filterCCITTFax;
+extern Filter filterCrypt;
+extern Filter filterDCT;
+extern Filter filterFlate;
+extern Filter filterJBIG2;
+extern Filter filterJPX;
+extern Filter filterLZW;
+extern Filter filterRunLength;
-static int
-fCopy(void *aux, Buffer *bi, Buffer *bo)
-{
- USED(aux);
- bufput(bo, bi->b, bi->sz);
- return 0;
-}
-
-static Filter filters[] = {
- {"ASCII85Decode", nil, nil, nil},
- {"ASCIIHexDecode", nil, nil, nil},
- {"CCITTFaxDecode", nil, nil, nil},
- {"CryptDecode", nil, nil, nil},
- {"DCTDecode", fCopy, nil, nil},
- {"FlateDecode", fFlate, openFlate, closeFlate},
- {"JBIG2Decode", nil, nil, nil},
- {"JPXDecode", nil, nil, nil},
- {"LZWDecode", nil, nil, nil},
- {"RunLengthDecode", nil, nil, nil},
+static Filter *filters[] = {
+ &filterASCII85,
+ &filterASCIIHex,
+ &filterCCITTFax,
+ &filterCrypt,
+ &filterDCT,
+ &filterFlate,
+ &filterJBIG2,
+ &filterJPX,
+ &filterLZW,
+ &filterRunLength,
};
Filter *
@@ -35,18 +34,18 @@
int i;
Filter *f;
- for(i = 0; i < nelem(filters) && strcmp(filters[i].name, name) != 0; i++);
+ for(i = 0; i < nelem(filters) && strcmp(filters[i]->name, name) != 0; i++);
if(i >= nelem(filters)){
werrstr("no such filter %q", name);
return nil;
}
- if(filters[i].readall == nil){
+ if(filters[i]->readall == nil){
werrstr("filter %q not implemented", name);
return nil;
}
if((f = malloc(sizeof(*f))) == nil)
return nil;
- memmove(f, &filters[i], sizeof(*f));
+ memmove(f, filters[i], sizeof(*f));
if(f->open != nil && f->open(f, o) != 0){
free(f);
return nil;
--- a/mkfile
+++ b/mkfile
@@ -7,7 +7,17 @@
buffer.$O\
dict.$O\
eval.$O\
+ f_dct.$O\
+ f_ascii85.$O\
+ f_asciihex.$O\
+ f_ccittfax.$O\
+ f_crypt.$O\
+ f_dct.$O\
f_flate.$O\
+ f_jbig2.$O\
+ f_jpx.$O\
+ f_lzw.$O\
+ f_runlength.$O\
filter.$O\
main.$O\
misc.$O\
@@ -20,7 +30,6 @@
xref.$O\
HFILES=\
- pdf.h\
UPDATE=\
$HFILES\
--- a/object.c
+++ b/object.c
@@ -13,10 +13,10 @@
pdfobj(Pdf *pdf, Stream *s)
{
Object *o, *o2;
+ char b[16];
vlong off;
int c, tf;
Xref xref;
- char b[16];
o = o2 = nil;
do; while(isws(c = Sgetc(s)));