[poppler] 2 commits - poppler/Gfx.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Tue Aug 25 15:46:29 PDT 2009


 poppler/Gfx.cc |   38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)

New commits:
commit bf5811f5331292ccf30f1b0f089fe43d351d96be
Author: Albert Astals Cid <aacid at kde.org>
Date:   Wed Aug 26 00:43:46 2009 +0200

    Improve shading color rendering
    
    Shading is not necessarily lineal so require another bisection to
    assume all the area in between have the same color. Fixes bug #20238

diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index c3372d2..81a4ab8 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -2828,7 +2828,22 @@ void Gfx::doRadialShFill(GfxRadialShading *shading) {
     }
     while (ib - ia > 1) {
       if (isSameGfxColor(colorB, colorA, nComps, radialColorDelta) && ib < radialMaxSplits) {
-	break;
+	// The shading is not necessarily lineal so having two points with the
+	// same color does not mean all the areas in between have the same color too
+	// Do another bisection to be a bit more sure we are not doing something wrong
+	GfxColor colorC;
+	int ic = (ia + ib) / 2;
+	double sc = sMin + ((double)ic / (double)radialMaxSplits) * (sMax - sMin);
+	double tc = t0 + sc * (t1 - t0);
+	if (tc < t0) {
+	  shading->getColor(t0, &colorC);
+	} else if (tc > t1) {
+	  shading->getColor(t1, &colorC);
+	} else {
+	  shading->getColor(tc, &colorC);
+	}
+	if (isSameGfxColor(colorC, colorA, nComps, radialColorDelta))
+	  break;
       }
       ib = (ia + ib) / 2;
       sb = sMin + ((double)ib / (double)radialMaxSplits) * (sMax - sMin);
commit e94430b790fde6ce7b7cb163c2e0adf2d071c81d
Author: Albert Astals Cid <aacid at kde.org>
Date:   Wed Aug 26 00:42:49 2009 +0200

    Make code a bit more readable

diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index 3023cba..c3372d2 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -293,6 +293,15 @@ Operator Gfx::opTab[] = {
 
 #define numOps (sizeof(opTab) / sizeof(Operator))
 
+static inline GBool isSameGfxColor(const GfxColor &colorA, const GfxColor &colorB, uint nComps, double delta) {
+  for (uint k = 0; k < nComps; ++k) {
+    if (abs(colorA.c[k] - colorB.c[k]) > delta) {
+      return false;
+    }
+  }
+  return true;
+}
+
 //------------------------------------------------------------------------
 // GfxResources
 //------------------------------------------------------------------------
@@ -2512,12 +2521,7 @@ void Gfx::doAxialShFill(GfxAxialShading *shading) {
 	tt = t0 + (t1 - t0) * ta[j];
       }
       shading->getColor(tt, &color1);
-      for (k = 0; k < nComps; ++k) {
-	if (abs(color1.c[k] - color0.c[k]) > axialColorDelta) {
-	  break;
-	}
-      }
-      if (k == nComps) {
+      if (isSameGfxColor(color1, color0, nComps, axialColorDelta)) {
          // in these two if what we guarantee is that if we are skipping lots of 
          // positions because the colors are the same, we still create a region
          // with vertexs passing by bboxIntersections[1] and bboxIntersections[2]
@@ -2823,12 +2827,7 @@ void Gfx::doRadialShFill(GfxRadialShading *shading) {
       shading->getColor(tb, &colorB);
     }
     while (ib - ia > 1) {
-      for (k = 0; k < nComps; ++k) {
-	if (abs(colorB.c[k] - colorA.c[k]) > radialColorDelta) {
-	  break;
-	}
-      }
-      if (k == nComps && ib < radialMaxSplits) {
+      if (isSameGfxColor(colorB, colorA, nComps, radialColorDelta) && ib < radialMaxSplits) {
 	break;
       }
       ib = (ia + ib) / 2;


More information about the poppler mailing list