[poppler] poppler/poppler: FlateStream.cc, NONE, 1.1 FlateStream.h, NONE, 1.1 Makefile.am, 1.5, 1.6 Stream.cc, 1.2, 1.3 Stream.h, 1.2, 1.3

Jeff Muizelaar jrmuizel at freedesktop.org
Wed Apr 27 13:56:20 PDT 2005


Update of /cvs/poppler/poppler/poppler
In directory gabe:/tmp/cvs-serv21581/poppler

Modified Files:
	Makefile.am Stream.cc Stream.h 
Added Files:
	FlateStream.cc FlateStream.h 
Log Message:
2005-04-27  Jeff Muizelaar  <jeff at 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.


--- NEW FILE: FlateStream.cc ---
//========================================================================
//
// 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);
}

--- NEW FILE: FlateStream.h ---
//========================================================================
//
// 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

Index: Makefile.am
===================================================================
RCS file: /cvs/poppler/poppler/poppler/Makefile.am,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Makefile.am	12 Apr 2005 15:37:39 -0000	1.5
+++ Makefile.am	27 Apr 2005 20:56:18 -0000	1.6
@@ -49,6 +49,17 @@
 
 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 @@
 	$(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 @@
 	$(splash_sources)	\
 	$(cairo_sources)	\
 	$(libjpeg_sources)	\
+	$(zlib_sources)		\
 	Annot.cc		\
 	Array.cc 		\
 	BuiltinFont.cc		\
@@ -156,4 +169,4 @@
 	PSOutputDev.cc		\
 	TextOutputDev.cc	\
 	PageLabelInfo.h		\
-	PageLabelInfo.cc
+	PageLabelInfo.cc	

Index: Stream.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/Stream.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Stream.cc	11 Mar 2005 21:42:52 -0000	1.2
+++ Stream.cc	27 Apr 2005 20:56:18 -0000	1.3
@@ -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 @@
 
 #endif
 
+#ifndef ENABLE_ZLIB
 //------------------------------------------------------------------------
 // FlateStream
 //------------------------------------------------------------------------
@@ -3715,6 +3720,7 @@
   codeSize -= bits;
   return c;
 }
+#endif
 
 //------------------------------------------------------------------------
 // EOFStream

Index: Stream.h
===================================================================
RCS file: /cvs/poppler/poppler/poppler/Stream.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Stream.h	11 Mar 2005 21:42:52 -0000	1.2
+++ Stream.h	27 Apr 2005 20:56:18 -0000	1.3
@@ -635,6 +635,7 @@
 };
 #endif
 
+#ifndef ENABLE_ZLIB
 //------------------------------------------------------------------------
 // FlateStream
 //------------------------------------------------------------------------
@@ -709,6 +710,7 @@
   int getHuffmanCodeWord(FlateHuffmanTab *tab);
   int getCodeWord(int bits);
 };
+#endif
 
 //------------------------------------------------------------------------
 // EOFStream



More information about the poppler mailing list