[poppler] [PATCH 4/5] use libjpeg for DCTStream

Albert Astals Cid tsdgeos at yahoo.es
Fri Mar 4 12:23:02 PST 2005


What does this patch give us? I mean Kristian has mentioned that libjpeg has 
obviously had more eyes looking for possible bugs and such, but what about 
speed? Is it faster, the same or slower using libjpeg instead of DCTStream?

Albert

A Divendres 04 Març 2005 20:35, Jeff Muizelaar va escriure:
> This patch has auto* stuff that is really rough
>
> 2005-03-02  Jeff Muizelaar  <jrmuizel at nit.ca>
>
> 	* configure.ac: Add check for libjpeg.
>
> 	* DCTStream.cc, DCTStream.h, Stream.cc, Stream.h, Makefile.am:
> 	Conditionally use libjpeg instead of xpdf jpeg decoder.
>
> diff -rupN 05-mask-getline/configure.ac 06-libjpeg/configure.ac
> --- 05-mask-getline/configure.ac	2005-03-01 14:20:23.000000000 -0500
> +++ 06-libjpeg/configure.ac	2005-03-02 17:01:35.000000000 -0500
> @@ -82,6 +82,31 @@ if test "$xpdf_cv_func_fseek64" = yes -a
>    AC_DEFINE(HAVE_FSEEK64)
>  fi
>
> +dnl Test for libjpeg
> +LIBJPEG_LIBS=
> +AC_CHECK_LIB(jpeg, jpeg_destroy_decompress,
> +  jpeg_ok=yes,
> +  jpeg_ok=no
> +  AC_MSG_WARN(*** JPEG loader will not be built (JPEG library not found)
> ***)) +if test "$jpeg_ok" = yes; then
> +  AC_MSG_CHECKING([for jpeglib.h])
> +  AC_TRY_CPP(
> +[#include <stdio.h>
> +#undef PACKAGE
> +#undef VERSION
> +#undef HAVE_STDLIB_H
> +#include <jpeglib.h>],
> +    jpeg_ok=yes,
> +    jpeg_ok=no)
> +  AC_MSG_RESULT($jpeg_ok)
> +  if test "$jpeg_ok" = yes; then
> +    LIBJPEG_LIBS="-ljpeg"
> +  fi
> +else
> +  AC_MSG_WARN(*** JPEG loader will not be built (JPEG header file not
> found) ***) +fi
> +AC_SUBST(LIBJPEG_LIBS)
> +
>  dnl Check for freetype headers
>  FREETYPE_LIBS=
>  FREETYPE_CFLAGS=
> @@ -118,6 +143,15 @@ if test x$enable_cairo_output = xyes; th
>    PKG_CHECK_MODULES(CAIRO, cairo >= 0.3)
>  fi
>
> +AC_ARG_ENABLE(libjpeg,
> +	      AC_HELP_STRING([--disable-libjpeg],
> +	                     [Don't build against libjpeg.]),,
> +	      enable_libjpeg="yes")
> +AM_CONDITIONAL(BUILD_LIBJPEG, test x$enable_libjpeg = xyes)
> +if test x$enable_libjpeg = xno; then
> +  AC_DEFINE([DISABLE_LIBJPEG], [1], [Disable libjpeg support.])
> +fi
> +
>  AC_ARG_ENABLE(gtk-test,
>                AC_HELP_STRING([--disable-gtk-test],
>  	                     [Don't compile GTK+ test program.]),,
> diff -rupN 05-mask-getline/poppler/DCTStream.cc
> 06-libjpeg/poppler/DCTStream.cc ---
> 05-mask-getline/poppler/DCTStream.cc	1969-12-31 19:00:00.000000000 -0500
> +++ 06-libjpeg/poppler/DCTStream.cc	2005-03-02 17:26:49.000000000 -0500 @@
> -0,0 +1,104 @@
> +#include "DCTStream.h"
> +
> +#ifndef DISABLE_LIBJPEG
> +static void str_init_source(j_decompress_ptr cinfo)
> +{
> +}
> +
> +static boolean str_fill_input_buffer(j_decompress_ptr cinfo)
> +{
> +  struct str_src_mgr * src = (struct str_src_mgr *)cinfo->src;
> +  src->buffer = src->str->getChar();
> +  src->pub.next_input_byte = &src->buffer;
> +  src->pub.bytes_in_buffer = 1;
> +  return TRUE;
> +}
> +
> +static void str_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
> +{
> +  struct str_src_mgr * src = (struct str_src_mgr *)cinfo->src;
> +  if (num_bytes > 0) {
> +    while (num_bytes > (long) src->pub.bytes_in_buffer) {
> +      num_bytes -= (long) src->pub.bytes_in_buffer;
> +      str_fill_input_buffer(cinfo);
> +    }
> +    src->pub.next_input_byte += (size_t) num_bytes;
> +    src->pub.bytes_in_buffer -= (size_t) num_bytes;
> +  }
> +}
> +
> +static void str_term_source(j_decompress_ptr cinfo)
> +{
> +}
> +
> +DCTStream::DCTStream(Stream *strA):
> +  FilterStream(strA) {
> +
> +  jpeg_create_decompress(&cinfo);
> +  src.pub.init_source = str_init_source;
> +  src.pub.fill_input_buffer = str_fill_input_buffer;
> +  src.pub.skip_input_data = str_skip_input_data;
> +  src.pub.resync_to_restart = jpeg_resync_to_restart;
> +  src.pub.term_source = str_term_source;
> +  src.pub.bytes_in_buffer = 0;
> +  src.pub.next_input_byte = NULL;
> +  src.str = str;
> +  cinfo.src = (jpeg_source_mgr *)&src;
> +  cinfo.err = jpeg_std_error(&jerr);
> +  x = 0;
> +}
> +
> +DCTStream::~DCTStream() {
> +  jpeg_destroy_decompress(&cinfo);
> +  delete str;
> +}
> +
> +void DCTStream::reset() {
> +  int row_stride;
> +
> +  str->reset();
> +  jpeg_read_header(&cinfo, TRUE);
> +  jpeg_start_decompress(&cinfo);
> +
> +  row_stride = cinfo.output_width * cinfo.output_components;
> +  row_buffer = cinfo.mem->alloc_sarray((j_common_ptr) &cinfo, JPOOL_IMAGE,
> row_stride, 1); +}
> +
> +int DCTStream::getChar() {
> +  int c;
> +
> +  if (x == 0) {
> +    if (cinfo.output_scanline < cinfo.output_height)
> +      jpeg_read_scanlines(&cinfo, row_buffer, 1);
> +    else return EOF;
> +  }
> +  c = row_buffer[0][x];
> +  x++;
> +  if (x == cinfo.output_width * cinfo.output_components)
> +    x = 0;
> +  return c;
> +}
> +
> +int DCTStream::lookChar() {
> +  int c;
> +  c = row_buffer[0][x];
> +  return c;
> +}
> +
> +GooString *DCTStream::getPSFilter(int psLevel, char *indent) {
> +  GooString *s;
> +
> +  if (psLevel < 2) {
> +    return NULL;
> +  }
> +  if (!(s = str->getPSFilter(psLevel, indent))) {
> +    return NULL;
> +  }
> +  s->append(indent)->append("<< >> /DCTDecode filter\n");
> +  return s;
> +}
> +
> +GBool DCTStream::isBinary(GBool last) {
> +  return str->isBinary(gTrue);
> +}
> +#endif
> diff -rupN 05-mask-getline/poppler/DCTStream.h
> 06-libjpeg/poppler/DCTStream.h ---
> 05-mask-getline/poppler/DCTStream.h	1969-12-31 19:00:00.000000000 -0500 +++
> 06-libjpeg/poppler/DCTStream.h	2005-03-02 17:10:50.000000000 -0500 @@ -0,0
> +1,71 @@
> +//========================================================================
> +//
> +// DCTStream.h
> +//
> +// Copyright 1996-2003 Glyph & Cog, LLC
> +//
> +//========================================================================
> +
> +#ifndef DCTSTREAM_H
> +#define DCTSTREAM_H
> +#include <config.h>
> +#ifndef DISABLE_LIBJPEG
> +
> +#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"
> +
> +#include <jpeglib.h>
> +
> +struct str_src_mgr {
> +    struct jpeg_source_mgr pub;
> +    JOCTET buffer;
> +    Stream *str;
> +};
> +
> +
> +class DCTStream: public FilterStream {
> +public:
> +
> +  DCTStream(Stream *strA);
> +  virtual ~DCTStream();
> +  virtual StreamKind getKind() { return strDCT; }
> +  virtual void reset();
> +  virtual int getChar();
> +  virtual int lookChar();
> +  virtual GooString *getPSFilter(int psLevel, char *indent);
> +  virtual GBool isBinary(GBool last = gTrue);
> +  Stream *getRawStream() { return str; }
> +
> +private:
> +  int x;
> +  struct jpeg_decompress_struct cinfo;
> +  struct jpeg_error_mgr jerr;
> +  struct str_src_mgr src;
> +  JSAMPARRAY row_buffer;
> +};
> +#endif //DISABLE_LIBJPEG
> +#endif
> diff -rupN 05-mask-getline/poppler/Makefile.am
> 06-libjpeg/poppler/Makefile.am ---
> 05-mask-getline/poppler/Makefile.am	2005-03-01 14:50:48.000000000 -0500 +++
> 06-libjpeg/poppler/Makefile.am	2005-03-02 15:58:36.000000000 -0500 @@ -34,6
> +34,11 @@ cairo_libs =					\
>
>  endif
>
> +if BUILD_LIBJPEG
> +libjpeg_libs =					\
> +	$(LIBJPEG_LIBS)
> +
> +endif
>
>  INCLUDES =					\
>  	-I$(top_srcdir)				\
> @@ -46,7 +51,8 @@ libpoppler_la_LIBADD =				\
>  	$(top_builddir)/goo/libgoo.la		\
>  	$(top_builddir)/fofi/libfofi.la		\
>  	$(splash_libs)				\
> -	$(cairo_libs)
> +	$(cairo_libs)				\
> +	$(libjpeg_libs)
>
>  poppler_includedir = $(includedir)/poppler
>  poppler_include_HEADERS =	\
> @@ -62,6 +68,7 @@ poppler_include_HEADERS =	\
>  	CMap.h			\
>  	Decrypt.h		\
>  	Dict.h			\
> +	DCTStream.h		\
>  	Error.h			\
>  	FontEncodingTables.h	\
>  	Function.cc		\
> @@ -109,6 +116,7 @@ libpoppler_la_SOURCES =		\
>  	Catalog.cc 		\
>  	CharCodeToUnicode.cc	\
>  	CMap.cc			\
> +	DCTStream.cc		\
>  	Decrypt.cc		\
>  	Dict.cc 		\
>  	Error.cc 		\
> diff -rupN 05-mask-getline/poppler/Stream.cc 06-libjpeg/poppler/Stream.cc
> --- 05-mask-getline/poppler/Stream.cc	2005-03-01 15:02:08.000000000 -0500
> +++ 06-libjpeg/poppler/Stream.cc	2005-03-02 17:13:26.000000000 -0500
> @@ -31,6 +31,7 @@
>  #include "Stream.h"
>  #include "JBIG2Stream.h"
>  #include "JPXStream.h"
> +#include "DCTStream.h"
>  #include "Stream-CCITT.h"
>
>  #ifdef __DJGPP__
> @@ -1785,7 +1786,7 @@ GooString *CCITTFaxStream::getPSFilter(i
>  GBool CCITTFaxStream::isBinary(GBool last) {
>    return str->isBinary(gTrue);
>  }
> -
> +#ifdef DISABLE_LIBJPEG
>  //------------------------------------------------------------------------
>  // DCTStream
>  //------------------------------------------------------------------------
> @@ -3176,7 +3177,7 @@ GooString *DCTStream::getPSFilter(int ps
>  GBool DCTStream::isBinary(GBool last) {
>    return str->isBinary(gTrue);
>  }
> -
> +#endif
>  //------------------------------------------------------------------------
>  // FlateStream
>  //------------------------------------------------------------------------
> diff -rupN 05-mask-getline/poppler/Stream.h 06-libjpeg/poppler/Stream.h
> --- 05-mask-getline/poppler/Stream.h	2005-03-01 15:03:08.000000000 -0500
> +++ 06-libjpeg/poppler/Stream.h	2005-03-02 17:27:39.000000000 -0500
> @@ -531,7 +531,7 @@ private:
>    short lookBits(int n);
>    void eatBits(int n) { inputBits -= n; }
>  };
> -
> +#if DISABLE_LIBJPEG
>  //------------------------------------------------------------------------
>  // DCTStream
>  //------------------------------------------------------------------------
> @@ -632,7 +632,7 @@ private:
>    int readMarker();
>    int read16();
>  };
> -
> +#endif
>  //------------------------------------------------------------------------
>  // FlateStream
>  //------------------------------------------------------------------------
> _______________________________________________
> poppler mailing list
> poppler at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/poppler



More information about the poppler mailing list