[poppler] poppler/JPEG2000Stream.cc poppler/JPEG2000Stream.h

Albert Astals Cid aacid at kemper.freedesktop.org
Tue Jan 6 13:58:57 PST 2015


 poppler/JPEG2000Stream.cc |   49 ++++++++++++++++++++++++----------------------
 poppler/JPEG2000Stream.h  |    7 +-----
 2 files changed, 28 insertions(+), 28 deletions(-)

New commits:
commit 636faafcb84b856580398f7883b6406d645c85d1
Author: Adam Reichold <adamreichold at myopera.com>
Date:   Tue Jan 6 22:57:20 2015 +0100

    JPEG2000Stream: Inline doGetChar and doLookChar

diff --git a/poppler/JPEG2000Stream.cc b/poppler/JPEG2000Stream.cc
index 2d48899..35e98b8 100644
--- a/poppler/JPEG2000Stream.cc
+++ b/poppler/JPEG2000Stream.cc
@@ -7,7 +7,8 @@
 // Copyright 2008-2010, 2012 Albert Astals Cid <aacid at kde.org>
 // Copyright 2011 Daniel Glöckner <daniel-gl at gmx.net>
 // Copyright 2014 Thomas Freitag <Thomas.Freitag at alfa.de>
-// Copyright 2013,2014 Adrian Johnson <ajohnson at redneon.com>
+// Copyright 2013, 2014 Adrian Johnson <ajohnson at redneon.com>
+// Copyright 2015 Adam Reichold <adam.reichold at t-online.de>
 //
 // Licensed under GPLv2 or later
 //
@@ -49,6 +50,22 @@ struct JPXStreamPrivate {
 #endif
 };
 
+static inline int doLookChar(JPXStreamPrivate* priv) {
+  if (unlikely(priv->counter >= priv->npixels))
+    return EOF;
+
+  return ((unsigned char *)priv->image->comps[priv->ccounter].data)[priv->counter];
+}
+
+static inline int doGetChar(JPXStreamPrivate* priv) {
+  const int result = doLookChar(priv);
+  if (++priv->ccounter == priv->ncomps) {
+    priv->ccounter = 0;
+    ++priv->counter;
+  }
+  return result;
+}
+
 JPXStream::JPXStream(Stream *strA) : FilterStream(strA) {
   priv = new JPXStreamPrivate;
   priv->inited = gFalse;
@@ -91,8 +108,10 @@ Goffset JPXStream::getPos() {
 }
 
 int JPXStream::getChars(int nChars, Guchar *buffer) {
+  if (unlikely(priv->inited == gFalse)) { init(); }
+
   for (int i = 0; i < nChars; ++i) {
-    const int c = doGetChar();
+    const int c = doGetChar(priv);
     if (likely(c != EOF)) buffer[i] = c;
     else return i;
   }
@@ -100,30 +119,15 @@ int JPXStream::getChars(int nChars, Guchar *buffer) {
 }
 
 int JPXStream::getChar() {
-  return doGetChar();
-}
+  if (unlikely(priv->inited == gFalse)) { init(); }
 
-int JPXStream::doLookChar() {
-  if (unlikely(priv->inited == gFalse))
-    init();
-
-  if (unlikely(priv->counter >= priv->npixels))
-    return EOF;
-
-  return ((unsigned char *)priv->image->comps[priv->ccounter].data)[priv->counter];
+  return doGetChar(priv);
 }
 
 int JPXStream::lookChar() {
-  return doLookChar();
-}
+  if (unlikely(priv->inited == gFalse)) { init(); }
 
-int JPXStream::doGetChar() {
-  int result = doLookChar();
-  if (++priv->ccounter == priv->ncomps) {
-    priv->ccounter = 0;
-    ++priv->counter;
-  }
-  return result;
+  return doLookChar(priv);
 }
 
 GooString *JPXStream::getPSFilter(int psLevel, const char *indent) {
@@ -135,8 +139,7 @@ GBool JPXStream::isBinary(GBool last) {
 }
 
 void JPXStream::getImageParams(int *bitsPerComponent, StreamColorSpaceMode *csMode) {
-  if (priv->inited == gFalse)
-    init();
+  if (unlikely(priv->inited == gFalse)) { init(); }
 
   *bitsPerComponent = 8;
   if (priv->image && priv->image->numcomps == 3)
diff --git a/poppler/JPEG2000Stream.h b/poppler/JPEG2000Stream.h
index 50b7586..73b6bdd 100644
--- a/poppler/JPEG2000Stream.h
+++ b/poppler/JPEG2000Stream.h
@@ -6,7 +6,8 @@
 //
 // Copyright 2008, 2010 Albert Astals Cid <aacid at kde.org>
 // Copyright 2011 Daniel Glöckner <daniel-gl at gmx.net>
-// Copyright 2013,2014 Adrian Johnson <ajohnson at redneon.com>
+// Copyright 2013, 2014 Adrian Johnson <ajohnson at redneon.com>
+// Copyright 2015 Adam Reichold <adam.reichold at t-online.de>
 //
 // Licensed under GPLv2 or later
 //
@@ -49,10 +50,6 @@ private:
   void init();
   virtual GBool hasGetChars() { return true; }
   virtual int getChars(int nChars, Guchar *buffer);
-
-  int doGetChar();
-
-  int doLookChar();
 };
 
 #endif


More information about the poppler mailing list