From 40d1f669aaf262d645b75de05b638cc51d8da2e2 Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Mon, 13 Jun 2005 16:28:17 +0000 Subject: [PATCH] applying patch_095,098 svn path=/branches/kpdf/annotations/kdegraphics/kpdf/; revision=425003 --- xpdf/xpdf/FlateStream.cc | 107 +++++++++++++++++++++++++++++++++++++++ xpdf/xpdf/FlateStream.h | 67 ++++++++++++++++++++++++ xpdf/xpdf/Makefile.am | 2 +- xpdf/xpdf/Stream.cc | 4 +- xpdf/xpdf/Stream.h | 2 +- 5 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 xpdf/xpdf/FlateStream.cc create mode 100644 xpdf/xpdf/FlateStream.h diff --git a/xpdf/xpdf/FlateStream.cc b/xpdf/xpdf/FlateStream.cc new file mode 100644 index 000000000..0e6b06e9b --- /dev/null +++ b/xpdf/xpdf/FlateStream.cc @@ -0,0 +1,107 @@ +//======================================================================== +// +// 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; +} + +GString *FlateStream::getPSFilter(int psLevel, const char *indent) { + GString *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); +} diff --git a/xpdf/xpdf/FlateStream.h b/xpdf/xpdf/FlateStream.h new file mode 100644 index 000000000..357f5714e --- /dev/null +++ b/xpdf/xpdf/FlateStream.h @@ -0,0 +1,67 @@ +//======================================================================== +// +// FlateStream.h +// +// Copyright (C) 2005, Jeff Muizelaar +// +//======================================================================== + +#ifndef FLATESTREAM_H +#define FLATESTREAM_H +#include + +#ifdef USE_GCC_PRAGMAS +#pragma interface +#endif + + +#ifdef USE_GCC_PRAGMAS +#pragma implementation +#endif + +#include +#include +#include +#ifndef WIN32 +#include +#endif +#include +#include +#include "goo/gmem.h" +#include "goo/gfile.h" +#include "Error.h" +#include "Object.h" +#ifndef NO_DECRYPTION +#include "Decrypt.h" +#endif +#include "Stream.h" + +extern "C" { +#include +} + +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 GString *getPSFilter(int psLevel, const 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 diff --git a/xpdf/xpdf/Makefile.am b/xpdf/xpdf/Makefile.am index 936711014..b71cf7612 100644 --- a/xpdf/xpdf/Makefile.am +++ b/xpdf/xpdf/Makefile.am @@ -4,7 +4,7 @@ libxpdf_la_LDFLAGS = $(all_libraries) libxpdf_la_LIBADD = $(LIB_X11) $(LIBFREETYPE_LIBS) $(LIBPAPER_LIBS) $(XFT_LIBS) $(LIBJPEG_LIBS) ../goo/libgoo.la ../fofi/libfofi.la ../splash/libsplash.la libxpdf_la_SOURCES = Annot.cc Array.cc BuiltinFont.cc BuiltinFontTables.cc \ Catalog.cc CharCodeToUnicode.cc CMap.cc Decrypt.cc Dict.cc DCTStream.cc \ - FontEncodingTables.cc Function.cc Gfx.cc \ + FontEncodingTables.cc FlateStream.cc Function.cc Gfx.cc \ GfxFont.cc GfxState.cc GlobalParams.cc JArithmeticDecoder.cc \ JBIG2Stream.cc Lexer.cc Link.cc NameToCharCode.cc Object.cc Outline.cc \ OutputDev.cc PDFDoc.cc PDFDocEncoding.cc PSTokenizer.cc \ diff --git a/xpdf/xpdf/Stream.cc b/xpdf/xpdf/Stream.cc index 249e4282e..ba2552047 100644 --- a/xpdf/xpdf/Stream.cc +++ b/xpdf/xpdf/Stream.cc @@ -33,6 +33,7 @@ #include "JPXStream.h" #include "Stream-CCITT.h" #include "DCTStream.h" +#include "FlateStream.h" #ifdef __DJGPP__ static GBool setDJSYSFLAGS = gFalse; @@ -3178,7 +3179,7 @@ GString *DCTStream::getPSFilter(int psLevel, const char *indent) { GBool DCTStream::isBinary(GBool /*last*/) { return str->isBinary(gTrue); } -#endif + //------------------------------------------------------------------------ // FlateStream //------------------------------------------------------------------------ @@ -3709,6 +3710,7 @@ int FlateStream::getCodeWord(int bits) { codeSize -= bits; return c; } +#endif //------------------------------------------------------------------------ // EOFStream diff --git a/xpdf/xpdf/Stream.h b/xpdf/xpdf/Stream.h index bc1e077c8..cca65c65c 100644 --- a/xpdf/xpdf/Stream.h +++ b/xpdf/xpdf/Stream.h @@ -637,7 +637,6 @@ private: int readMarker(); int read16(); }; -#endif //------------------------------------------------------------------------ // FlateStream @@ -713,6 +712,7 @@ private: int getHuffmanCodeWord(FlateHuffmanTab *tab); int getCodeWord(int bits); }; +#endif //------------------------------------------------------------------------ // EOFStream