[poppler] poppler/splash: SplashScreen.cc, 1.2, 1.3 SplashScreen.h, 1.1.1.1, 1.2

Albert Astals Cid aacid at freedesktop.org
Sun Oct 16 07:25:34 PDT 2005


Update of /cvs/poppler/poppler/splash
In directory gabe:/tmp/cvs-serv25305/splash

Modified Files:
	SplashScreen.cc SplashScreen.h 
Log Message:
Merge SplashScreen.[cc|h] from xpdf 3.01


Index: SplashScreen.cc
===================================================================
RCS file: /cvs/poppler/poppler/splash/SplashScreen.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- SplashScreen.cc	27 Aug 2005 08:43:43 -0000	1.2
+++ SplashScreen.cc	16 Oct 2005 14:25:32 -0000	1.3
@@ -10,6 +10,7 @@
 #pragma implementation
 #endif
 
+#include <string.h>
 #include "goo/gmem.h"
 #include "SplashMath.h"
 #include "SplashScreen.h"
@@ -23,85 +24,118 @@
 // Gamma correction (gamma = 1 / 1.33) is also computed here.
 SplashScreen::SplashScreen(int sizeA) {
   SplashCoord *dist;
-  SplashCoord u, v, d;
-  int x, y, x1, y1, i;
+  SplashCoord u, v, d, val;
+  int size2, x, y, x1, y1, i;
 
-  size = sizeA >> 1;
-  if (size < 1) {
-    size = 1;
+  size2 = sizeA >> 1;
+  if (size2 < 1) {
+    size2 = 1;
   }
+  size = size2 << 1;
 
   // initialize the threshold matrix
-  mat = (SplashCoord *)gmallocn(2 * size * size, sizeof(SplashCoord));
-  for (y = 0; y < 2 * size; ++y) {
+  mat = (SplashCoord *)gmallocn(size * size, sizeof(SplashCoord));
+  for (y = 0; y < size; ++y) {
     for (x = 0; x < size; ++x) {
       mat[y * size + x] = -1;
     }
   }
 
   // build the distance matrix
-  dist = (SplashCoord *)gmallocn(2 * size * size, sizeof(SplashCoord));
-  for (y = 0; y < size; ++y) {
-    for (x = 0; x < size; ++x) {
-      if (x + y < size - 1) {
-	u = (SplashCoord)x + 0.5 - 0;  //~ (-0.5);
+  dist = (SplashCoord *)gmallocn(size * size2, sizeof(SplashCoord));
+  for (y = 0; y < size2; ++y) {
+    for (x = 0; x < size2; ++x) {
+      if (x + y < size2 - 1) {
+	u = (SplashCoord)x + 0.5 - 0;
 	v = (SplashCoord)y + 0.5 - 0;
       } else {
-	u = (SplashCoord)x + 0.5 - (SplashCoord)size; //~ ((SplashCoord)size - 0.5);
-	v = (SplashCoord)y + 0.5 - (SplashCoord)size;
+	u = (SplashCoord)x + 0.5 - (SplashCoord)size2;
+	v = (SplashCoord)y + 0.5 - (SplashCoord)size2;
       }
-      dist[y * size + x] = u*u + v*v;
+      dist[y * size2 + x] = u*u + v*v;
     }
   }
-  for (y = 0; y < size; ++y) {
-    for (x = 0; x < size; ++x) {
+  for (y = 0; y < size2; ++y) {
+    for (x = 0; x < size2; ++x) {
       if (x < y) {
-	u = (SplashCoord)x + 0.5 - 0;  //~ (-0.5);
-	v = (SplashCoord)y + 0.5 - (SplashCoord)size;
+	u = (SplashCoord)x + 0.5 - 0;
+	v = (SplashCoord)y + 0.5 - (SplashCoord)size2;
       } else {
-	u = (SplashCoord)x + 0.5 - (SplashCoord)size; //~ ((SplashCoord)size - 0.5);
+	u = (SplashCoord)x + 0.5 - (SplashCoord)size2;
 	v = (SplashCoord)y + 0.5 - 0;
       }
-      dist[(size + y) * size + x] = u*u + v*v;
+      dist[(size2 + y) * size2 + x] = u*u + v*v;
     }
   }
 
   // build the threshold matrix
+  minVal = 1;
+  maxVal = 0;
   x1 = y1 = 0; // make gcc happy
-  for (i = 1; i <= 2 * size * size; ++i) {
-    d = 2 * size * size;
-    for (y = 0; y < 2 * size; ++y) {
-      for (x = 0; x < size; ++x) {
+  for (i = 1; i <= size * size2; ++i) {
+    d = size * size2;
+    for (y = 0; y < size; ++y) {
+      for (x = 0; x < size2; ++x) {
 	if (mat[y * size + x] < 0 &&
-	    dist[y * size + x] < d) {
+	    dist[y * size2 + x] < d) {
 	  x1 = x;
 	  y1 = y;
-	  d = dist[y1 * size + x1];
+	  d = dist[y1 * size2 + x1];
 	}
       }
     }
-    u = 1.0 - (SplashCoord)i / (SplashCoord)(2 * size * size + 1);
-    mat[y1 * size + x1] = splashPow(u, 1.33);
+    u = (SplashCoord)1 - (SplashCoord)i / (SplashCoord)(size * size2 + 1);
+    val = splashPow(u, 1.33);
+    if (val < minVal) {
+      minVal = val;
+    }
+    if (val > maxVal) {
+      maxVal = val;
+    }
+    mat[y1 * size + x1] = val;
+    if (y1 < size2) {
+      mat[(y1 + size2) * size + x1 + size2] = val;
+    } else {
+      mat[(y1 - size2) * size + x1 + size2] = val;
+    }
   }
 
   gfree(dist);
 }
 
+SplashScreen::SplashScreen(SplashScreen *screen) {
+  int n;
+
+  size = screen->size;
+  n = size * size * sizeof(SplashCoord);
+  mat = (SplashCoord *)gmalloc(n);
+  memcpy(mat, screen->mat, n);
+  minVal = screen->minVal;
+  maxVal = screen->maxVal;
+}
+
 SplashScreen::~SplashScreen() {
   gfree(mat);
 }
 
 int SplashScreen::test(int x, int y, SplashCoord value) {
-  SplashCoord *mat1;
   int xx, yy;
 
-  xx = x % (2 * size);
-  yy = y % (2 * size);
-  mat1 = mat;
-  if ((xx / size) ^ (yy / size)) {
-    mat1 += size * size;
+  if (value < minVal) {
+    return 0;
   }
-  xx %= size;
-  yy %= size;
-  return value < mat1[yy * size + xx] ? 0 : 1;
+  if (value >= maxVal) {
+    return 1;
+  }
+  if ((xx = x % size) < 0) {
+    xx = -xx;
+  }
+  if ((yy = y % size) < 0) {
+    yy = -yy;
+  }
+  return value < mat[yy * size + xx] ? 0 : 1;
+}
+
+GBool SplashScreen::isStatic(SplashCoord value) {
+  return value < minVal || value >= maxVal;
 }

Index: SplashScreen.h
===================================================================
RCS file: /cvs/poppler/poppler/splash/SplashScreen.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- SplashScreen.h	3 Mar 2005 19:45:59 -0000	1.1.1.1
+++ SplashScreen.h	16 Oct 2005 14:25:32 -0000	1.2
@@ -21,18 +21,28 @@
 public:
 
   SplashScreen(int sizeA);
+  SplashScreen(SplashScreen *screen);
   ~SplashScreen();
 
-  SplashScreen *copy() { return new SplashScreen(size << 1); }
+  SplashScreen *copy() { return new SplashScreen(this); }
 
   // Return the computed pixel value (0=black, 1=white) for the gray
   // level <value> at (<x>, <y>).
   int test(int x, int y, SplashCoord value);
 
+  // Returns true if value is above the white threshold or below the
+  // black threshold, i.e., if the corresponding halftone will be
+  // solid white or black.
+  GBool isStatic(SplashCoord value);
+
 private:
 
   SplashCoord *mat;		// threshold matrix
   int size;			// size of the threshold matrix
+  SplashCoord minVal;		// any pixel value below minVal generates
+				//   solid black
+  SplashCoord maxVal;		// any pixel value above maxVal generates
+				//   solid white
 };
 
 #endif



More information about the poppler mailing list