summaryrefslogtreecommitdiff
path: root/stream/filt_a85e.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2005-03-30 08:30:22 +0200
committerTor Andersson <tor@ghostscript.com>2005-03-30 08:30:22 +0200
commitee154f16bd09a43359967f7e7b86c3677c09461d (patch)
tree08896cfa9ff55e05bfe7855965c620d45115d4d5 /stream/filt_a85e.c
parent460ad7040d67a4a93a153f98095ff952a2b15d37 (diff)
downloadmupdf-ee154f16bd09a43359967f7e7b86c3677c09461d.tar.xz
rename part 1 -- files
Diffstat (limited to 'stream/filt_a85e.c')
-rw-r--r--stream/filt_a85e.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/stream/filt_a85e.c b/stream/filt_a85e.c
new file mode 100644
index 00000000..d9cd22c6
--- /dev/null
+++ b/stream/filt_a85e.c
@@ -0,0 +1,127 @@
+#include <fitz.h>
+
+typedef struct fz_a85e_s fz_a85e;
+
+struct fz_a85e_s
+{
+ fz_filter super;
+ int c;
+};
+
+fz_error *
+fz_newa85e(fz_filter **fp, fz_obj *params)
+{
+ FZ_NEWFILTER(fz_a85e, f, a85e);
+ f->c = 0;
+ return nil;
+}
+
+void
+fz_dropa85e(fz_filter *f)
+{
+}
+
+fz_error *
+fz_processa85e(fz_filter *filter, fz_buffer *in, fz_buffer *out)
+{
+ fz_a85e *f = (fz_a85e*)filter;
+ unsigned long word;
+ int count;
+ int n;
+
+ n = 0;
+
+ while (1)
+ {
+ if (f->c >= 70) {
+ if (out->wp + 1 > out->ep)
+ return fz_ioneedout;
+ *out->wp++ = '\n';
+ f->c = 0;
+ n ++;
+ }
+
+ if (in->rp + 4 <= in->wp)
+ {
+ word = (in->rp[0] << 24) |
+ (in->rp[1] << 16) |
+ (in->rp[2] << 8) |
+ (in->rp[3]);
+ if (word == 0) {
+ if (out->wp + 1 > out->ep)
+ return fz_ioneedout;
+ *out->wp++ = 'z';
+ f->c ++;
+ n ++;
+ }
+ else {
+ unsigned long v1, v2, v3, v4;
+
+ if (out->wp + 5 > out->ep)
+ return fz_ioneedout;
+
+ v4 = word / 85;
+ v3 = v4 / 85;
+ v2 = v3 / 85;
+ v1 = v2 / 85;
+
+ *out->wp++ = (v1 % 85) + '!';
+ *out->wp++ = (v2 % 85) + '!';
+ *out->wp++ = (v3 % 85) + '!';
+ *out->wp++ = (v4 % 85) + '!';
+ *out->wp++ = (word % 85) + '!';
+ f->c += 5;
+ n += 5;
+ }
+ in->rp += 4;
+ }
+
+ else if (in->eof)
+ {
+ unsigned long divisor;
+
+ if (in->rp == in->wp)
+ goto needinput; /* handle clean eof here */
+
+ count = in->wp - in->rp;
+
+ if (out->wp + count + 3 > out->ep)
+ return fz_ioneedout;
+
+ word = 0;
+ switch (count) {
+ case 3: word |= in->rp[2] << 8;
+ case 2: word |= in->rp[1] << 16;
+ case 1: word |= in->rp[0] << 24;
+ }
+ in->rp += count;
+
+ divisor = 85L * 85 * 85 * 85;
+ while (count-- >= 0) {
+ *out->wp++ = ((word / divisor) % 85) + '!';
+ divisor /= 85;
+ }
+
+ *out->wp++ = '~';
+ *out->wp++ = '>';
+ out->eof = 1;
+ return fz_iodone;
+ }
+
+ else {
+ goto needinput;
+ }
+ }
+
+needinput:
+ if (in->eof) {
+ if (out->wp + 2 > out->ep)
+ return fz_ioneedout;
+ *out->wp++ = '~';
+ *out->wp++ = '>';
+ out->eof = 1;
+ return fz_iodone;
+ }
+ return fz_ioneedin;
+}
+