[poppler] poppler/GfxState.cc poppler/GfxState.h

Albert Astals Cid aacid at kemper.freedesktop.org
Sun Jan 25 14:18:03 PST 2009


 poppler/GfxState.cc |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 poppler/GfxState.h  |   15 +++++++++++++
 2 files changed, 75 insertions(+)

New commits:
commit 90f95127d8d89cfcadeb7d701437ab07ce4a8a61
Author: Koji Otani <sho at bbr.jp>
Date:   Sun Jan 25 23:17:39 2009 +0100

    Cache last 5 GfxICCBasedColorSpace

diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc
index 913245b..0de4840 100644
--- a/poppler/GfxState.cc
+++ b/poppler/GfxState.cc
@@ -1410,6 +1410,12 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr) {
     iccProfileStreamA.gen = 0;
   }
   obj1.free();
+#ifdef USE_CMS
+  // check cache
+  if (iccProfileStreamA.num > 0
+     && (cs = GfxICCBasedCache::lookup(iccProfileStreamA.num,
+          iccProfileStreamA.gen)) != NULL) return cs;
+#endif
   arr->get(1, &obj1);
   if (!obj1.isStream()) {
     error(-1, "Bad ICCBased color space (stream)");
@@ -1516,6 +1522,10 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr) {
     cmsCloseProfile(hp);
   }
   obj1.free();
+  // put this colorSpace into cache
+  if (iccProfileStreamA.num > 0) {
+    GfxICCBasedCache::put(iccProfileStreamA.num,iccProfileStreamA.gen,cs);
+  }
 #endif
   return cs;
 }
@@ -1654,6 +1664,56 @@ void GfxICCBasedColorSpace::getDefaultRanges(double *decodeLow,
 #endif
 }
 
+#ifdef USE_CMS
+GfxICCBasedCache
+   GfxICCBasedCache::cache[GFX_ICCBASED_CACHE_SIZE];
+
+GfxICCBasedCache::GfxICCBasedCache()
+{
+  num = 0;
+  gen = 0;
+  colorSpace = 0;
+}
+
+GfxICCBasedColorSpace *GfxICCBasedCache::lookup(int numA, int genA)
+{
+  int i;
+
+  if (cache[0].num == numA && cache[0].gen == genA) {
+    return (GfxICCBasedColorSpace *)cache[0].colorSpace->copy();
+  }
+  for (i = 1;i < GFX_ICCBASED_CACHE_SIZE && cache[i].num > 0;i++) {
+    if (cache[i].num == numA && cache[i].gen == genA) {
+      int j;
+      GfxICCBasedCache hit = cache[i];
+
+      for (j = 0;j < i;j++) {
+	cache[j+1] = cache[j];
+      }
+      cache[0] = hit;
+      return (GfxICCBasedColorSpace *)hit.colorSpace->copy();
+    }
+  }
+  return NULL;
+}
+
+void GfxICCBasedCache::put(int numA, int genA,
+  GfxICCBasedColorSpace *cs)
+{
+  int i;
+
+  if (cache[GFX_ICCBASED_CACHE_SIZE-1].num > 0) {
+    delete cache[GFX_ICCBASED_CACHE_SIZE-1].colorSpace;
+  }
+  for (i = 0;i < GFX_ICCBASED_CACHE_SIZE-1 && cache[i].num > 0;i++) {
+    cache[i+1] = cache[i];
+  }
+  cache[0].num = numA;
+  cache[0].gen = genA;
+  cache[0].colorSpace = (GfxICCBasedColorSpace *)cs->copy();
+}
+#endif
+
 //------------------------------------------------------------------------
 // GfxIndexedColorSpace
 //------------------------------------------------------------------------
diff --git a/poppler/GfxState.h b/poppler/GfxState.h
index 1a0aacf..ad5fae6 100644
--- a/poppler/GfxState.h
+++ b/poppler/GfxState.h
@@ -497,6 +497,21 @@ private:
 #endif
 };
 
+#ifdef USE_CMS
+#define GFX_ICCBASED_CACHE_SIZE 5
+class GfxICCBasedCache {
+public:
+  static GfxICCBasedColorSpace *lookup(int numA, int genA);
+  static void put(int numA, int genA, GfxICCBasedColorSpace *cs);
+private:
+  GfxICCBasedCache();
+  int num;
+  int gen;
+  GfxICCBasedColorSpace *colorSpace;
+  static GfxICCBasedCache cache[GFX_ICCBASED_CACHE_SIZE];
+};
+#endif
+
 //------------------------------------------------------------------------
 // GfxIndexedColorSpace
 //------------------------------------------------------------------------


More information about the poppler mailing list