summaryrefslogtreecommitdiff
path: root/stream/filt_flate.c
diff options
context:
space:
mode:
Diffstat (limited to 'stream/filt_flate.c')
-rw-r--r--stream/filt_flate.c56
1 files changed, 45 insertions, 11 deletions
diff --git a/stream/filt_flate.c b/stream/filt_flate.c
index c34a49b7..777d6d56 100644
--- a/stream/filt_flate.c
+++ b/stream/filt_flate.c
@@ -21,6 +21,8 @@ fz_error *
fz_newflated(fz_filter **fp, fz_obj *params)
{
fz_error *eo;
+ fz_obj *obj;
+ int zipfmt;
int ei;
FZ_NEWFILTER(fz_flate, f, flated);
@@ -31,8 +33,24 @@ fz_newflated(fz_filter **fp, fz_obj *params)
f->z.next_in = nil;
f->z.avail_in = 0;
- ei = inflateInit(&f->z);
- if (ei != Z_OK) {
+ zipfmt = 0;
+
+ if (params)
+ {
+ obj = fz_dictgets(params, "ZIP");
+ if (obj) zipfmt = fz_tobool(obj);
+ }
+
+ if (zipfmt)
+ {
+ /* if windowbits is negative the zlib header is skipped */
+ ei = inflateInit2(&f->z, -15);
+ }
+ else
+ ei = inflateInit(&f->z);
+
+ if (ei != Z_OK)
+ {
eo = fz_throw("ioerror: inflateInit: %s", f->z.msg);
fz_free(f);
return eo;
@@ -74,18 +92,21 @@ fz_processflated(fz_filter *f, fz_buffer *in, fz_buffer *out)
in->rp = in->wp - zp->avail_in;
out->wp = out->ep - zp->avail_out;
- if (err == Z_STREAM_END) {
+ if (err == Z_STREAM_END)
+ {
out->eof = 1;
return fz_iodone;
}
- else if (err == Z_OK) {
+ else if (err == Z_OK)
+ {
if (in->rp == in->wp && !in->eof)
return fz_ioneedin;
if (out->wp == out->ep)
return fz_ioneedout;
return fz_ioneedin; /* hmm, what's going on here? */
}
- else {
+ else
+ {
return fz_throw("ioerror: inflate: %s", zp->msg);
}
}
@@ -96,15 +117,20 @@ fz_newflatee(fz_filter **fp, fz_obj *params)
fz_obj *obj;
fz_error *eo;
int effort;
+ int zipfmt;
int ei;
FZ_NEWFILTER(fz_flate, f, flatee);
effort = -1;
+ zipfmt = 0;
- if (params) {
+ if (params)
+ {
obj = fz_dictgets(params, "Effort");
if (obj) effort = fz_toint(obj);
+ obj = fz_dictgets(params, "ZIP");
+ if (obj) effort = fz_tobool(obj);
}
f->z.zalloc = zmalloc;
@@ -113,8 +139,13 @@ fz_newflatee(fz_filter **fp, fz_obj *params)
f->z.next_in = nil;
f->z.avail_in = 0;
- ei = deflateInit(&f->z, effort);
- if (ei != Z_OK) {
+ if (zipfmt)
+ ei = deflateInit2(&f->z, effort, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
+ else
+ ei = deflateInit(&f->z, effort);
+
+ if (ei != Z_OK)
+ {
eo = fz_throw("ioerror: deflateInit: %s", f->z.msg);
fz_free(f);
return eo;
@@ -158,18 +189,21 @@ fz_processflatee(fz_filter *f, fz_buffer *in, fz_buffer *out)
in->rp = in->wp - zp->avail_in;
out->wp = out->ep - zp->avail_out;
- if (err == Z_STREAM_END) {
+ if (err == Z_STREAM_END)
+ {
out->eof = 1;
return fz_iodone;
}
- else if (err == Z_OK) {
+ else if (err == Z_OK)
+ {
if (in->rp == in->wp && !in->eof)
return fz_ioneedin;
if (out->wp == out->ep)
return fz_ioneedout;
return fz_ioneedin; /* hmm? */
}
- else {
+ else
+ {
return fz_throw("ioerror: deflate: %s", zp->msg);
}
}