Commit c2db3e1b authored by Jeff Muizelaar's avatar Jeff Muizelaar

2005-04-27 Jeff Muizelaar <jeff@infidigm.net>

	* configure.ac:
	* poppler/FlateStream.cc:
	* poppler/FlateStream.h:
	* poppler/Makefile.am:
	* poppler/Stream.cc:
	* poppler/Stream.h: Add a reimplementation of FlateStream using
	zlib.
parent bc0afe52
2005-04-27 Jeff Muizelaar <jeff@infidigm.net>
* configure.ac:
* poppler/FlateStream.cc:
* poppler/FlateStream.h:
* poppler/Makefile.am:
* poppler/Stream.cc:
* poppler/Stream.h: Add a reimplementation of FlateStream using
zlib.
2005-04-27 Kristian Høgsberg <krh@redhat.com>
* poppler/Catalog.cc (NameTree::lookup): Fix bsearch return value
......
......@@ -82,6 +82,34 @@ if test "$xpdf_cv_func_fseek64" = yes -a "$xpdf_cv_func_ftell64" = yes; then
AC_DEFINE(HAVE_FSEEK64)
fi
dnl Test for zlib
AC_ARG_ENABLE(zlib,
AC_HELP_STRING([--disable-zlib],
[Don't build against zlib.]),
enable_zlib=$enableval,
enable_zlib="try")
if test x$enable_zlib = xyes; then
AC_CHECK_LIB([z], [inflate],,
AC_MSG_ERROR("*** zlib library not found ***"))
AC_CHECK_HEADERS([zlib.h],,
AC_MSG_ERROR("*** zlib headers not found ***"))
elif test x$enable_zlib = xtry; then
AC_CHECK_LIB([z], [inflate],
[enable_zlib="yes"],
[enable_zlib="no"])
AC_CHECK_HEADERS([zlib.h],,
[enable_zlib="no"])
fi
if test x$enable_zlib = xyes; then
ZLIB_LIBS="-lz"
AC_SUBST(ZLIB_LIBS)
AC_DEFINE(ENABLE_ZLIB)
fi
AM_CONDITIONAL(BUILD_ZLIB, test x$enable_zlib = xyes)
AH_TEMPLATE([ENABLE_ZLIB],
[Use zlib instead of builtin zlib decoder.])
dnl Test for libjpeg
AC_ARG_ENABLE(libjpeg,
......@@ -314,3 +342,4 @@ echo " cairo output: $enable_cairo_output"
echo " qt wrapper: $enable_poppler_qt"
echo " glib wrapper: $enable_poppler_glib"
echo " use libjpeg: $enable_libjpeg"
echo " use zlib: $enable_zlib"
//========================================================================
//
// FlateStream.cc
//
// Copyright (C) 2005, Jeff Muizelaar
//
//========================================================================
#include "FlateStream.h"
FlateStream::FlateStream(Stream *strA, int predictor, int columns, int colors, int bits) :
FilterStream(strA)
{
if (predictor != 1) {
pred = new StreamPredictor(this, predictor, columns, colors, bits);
} else {
pred = NULL;
}
out_pos = 0;
memset(&d_stream, 0, sizeof(d_stream));
}
FlateStream::~FlateStream() {
inflateEnd(&d_stream);
delete str;
}
void FlateStream::reset() {
//FIXME: what are the semantics of reset?
//i.e. how much intialization has to happen in the constructor?
str->reset();
memset(&d_stream, 0, sizeof(d_stream));
inflateInit(&d_stream);
d_stream.avail_in = 0;
status = Z_OK;
out_pos = 0;
out_buf_len = 0;
}
int FlateStream::getRawChar() {
if (fill_buffer())
return EOF;
return out_buf[out_pos++];
}
int FlateStream::getChar() {
if (pred)
return pred->getChar();
else
return getRawChar();
}
int FlateStream::lookChar() {
if (pred)
return pred->lookChar();
if (fill_buffer())
return EOF;
return out_buf[out_pos];
}
int FlateStream::fill_buffer() {
if (out_pos >= out_buf_len) {
if (status == Z_STREAM_END) {
return -1;
}
d_stream.avail_out = sizeof(out_buf);
d_stream.next_out = out_buf;
out_pos = 0;
/* buffer is empty so we need to fill it */
if (d_stream.avail_in == 0) {
int c;
/* read from the source stream */
while (d_stream.avail_in < sizeof(in_buf) && (c = str->getChar()) != EOF) {
in_buf[d_stream.avail_in++] = c;
}
d_stream.next_in = in_buf;
}
while (d_stream.avail_out && d_stream.avail_in && (status == Z_OK || status == Z_BUF_ERROR)) {
status = inflate(&d_stream, Z_SYNC_FLUSH);
}
out_buf_len = sizeof(out_buf) - d_stream.avail_out;
if (status != Z_OK && status != Z_STREAM_END)
return -1;
if (!out_buf_len)
return -1;
}
return 0;
}
GooString *FlateStream::getPSFilter(int psLevel, char *indent) {
GooString *s;
if (psLevel < 3 || pred) {
return NULL;
}
if (!(s = str->getPSFilter(psLevel, indent))) {
return NULL;
}
s->append(indent)->append("<< >> /FlateDecode filter\n");
return s;
}
GBool FlateStream::isBinary(GBool last) {
return str->isBinary(gTrue);
}
//========================================================================
//
// FlateStream.h
//
// Copyright (C) 2005, Jeff Muizelaar
//
//========================================================================
#ifndef FLATESTREAM_H
#define FLATESTREAM_H
#include <config.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#ifdef USE_GCC_PRAGMAS
#pragma implementation
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#ifndef WIN32
#include <unistd.h>
#endif
#include <string.h>
#include <ctype.h>
#include "goo/gmem.h"
#include "goo/gfile.h"
#include "poppler-config.h"
#include "Error.h"
#include "Object.h"
#ifndef NO_DECRYPTION
#include "Decrypt.h"
#endif
#include "Stream.h"
extern "C" {
#include <zlib.h>
}
class FlateStream: public FilterStream {
public:
FlateStream(Stream *strA, int predictor, int columns, int colors, int bits);
virtual ~FlateStream();
virtual StreamKind getKind() { return strFlate; }
virtual void reset();
virtual int getChar();
virtual int lookChar();
virtual int getRawChar();
virtual GooString *getPSFilter(int psLevel, char *indent);
virtual GBool isBinary(GBool last = gTrue);
private:
int fill_buffer(void);
z_stream d_stream;
StreamPredictor *pred;
int status;
unsigned char in_buf[4096];
unsigned char out_buf[4096];
int out_pos;
int out_buf_len;
};
#endif
......@@ -49,6 +49,17 @@ libjpeg_libs = \
endif
if BUILD_ZLIB
zlib_sources = \
FlateStream.h \
FlateStream.cc
zlib_libs = \
$(ZLIB_LIBS)
endif
INCLUDES = \
-I$(top_srcdir) \
$(splash_includes) \
......@@ -62,7 +73,8 @@ libpoppler_la_LIBADD = \
$(top_builddir)/fofi/libfofi.la \
$(splash_libs) \
$(cairo_libs) \
$(libjpeg_libs)
$(libjpeg_libs) \
$(zlib_libs)
poppler_includedir = $(includedir)/poppler
poppler_include_HEADERS = \
......@@ -119,6 +131,7 @@ libpoppler_la_SOURCES = \
$(splash_sources) \
$(cairo_sources) \
$(libjpeg_sources) \
$(zlib_sources) \
Annot.cc \
Array.cc \
BuiltinFont.cc \
......@@ -156,4 +169,4 @@ libpoppler_la_SOURCES = \
PSOutputDev.cc \
TextOutputDev.cc \
PageLabelInfo.h \
PageLabelInfo.cc
PageLabelInfo.cc
......@@ -37,6 +37,10 @@
#include "DCTStream.h"
#endif
#ifdef ENABLE_ZLIB
#include "FlateStream.h"
#endif
#ifdef __DJGPP__
static GBool setDJSYSFLAGS = gFalse;
#endif
......@@ -3185,6 +3189,7 @@ GBool DCTStream::isBinary(GBool last) {
#endif
#ifndef ENABLE_ZLIB
//------------------------------------------------------------------------
// FlateStream
//------------------------------------------------------------------------
......@@ -3715,6 +3720,7 @@ int FlateStream::getCodeWord(int bits) {
codeSize -= bits;
return c;
}
#endif
//------------------------------------------------------------------------
// EOFStream
......
......@@ -635,6 +635,7 @@ private:
};
#endif
#ifndef ENABLE_ZLIB
//------------------------------------------------------------------------
// FlateStream
//------------------------------------------------------------------------
......@@ -709,6 +710,7 @@ private:
int getHuffmanCodeWord(FlateHuffmanTab *tab);
int getCodeWord(int bits);
};
#endif
//------------------------------------------------------------------------
// EOFStream
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment