[mapguide-commits] r1197 - trunk/MgDev/Common/Stylization

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Mon Mar 12 12:15:07 EDT 2007


Author: traianstanev
Date: 2007-03-12 12:15:07 -0400 (Mon, 12 Mar 2007)
New Revision: 1197

Modified:
   trunk/MgDev/Common/Stylization/GDUtils.cpp
   trunk/MgDev/Common/Stylization/GDW2DRewriter.cpp
   trunk/MgDev/Common/Stylization/complex_polygon_gd.cpp
   trunk/MgDev/Common/Stylization/complex_polygon_gd.h
Log:
Remove gd-based polygon fill function that was no longer needed since we switched to the new (faster) polygon rasterizer. Changed the only remaining reference to that function (in the GD DWF rewriter) to use the new DrawScreenPolygon function which in turn calls the new rasterizer.

Modified: trunk/MgDev/Common/Stylization/GDUtils.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/GDUtils.cpp	2007-03-12 15:41:27 UTC (rev 1196)
+++ trunk/MgDev/Common/Stylization/GDUtils.cpp	2007-03-12 16:15:07 UTC (rev 1197)
@@ -20,189 +20,11 @@
 #include "stdafx.h"
 #include "GDUtils.h"
 
-
 int ConvertColor(gdImagePtr i, RS_Color& c)
 {
     return gdImageColorAllocateAlpha(i, c.red(), c.green(), c.blue(), 127 - c.alpha()/2 );
 }
 
-//this is adapted from gdImageFilledPolygon to draw a polygon with holes
-//contours point counts are given by the cntrs array
-//TODO: this code is written as if it belongs to gd.c, except that
-//gdMalloc and gdRealloc are replaced by malloc/realloc -- which should
-//not matter in our case since gd.dll is compiled to use the same CRT
-//as Stylization.dll
-void rs_gdImageMultiPolygon(gdImagePtr im, int* cntrs, int nCntrs, gdPointPtr p, int nPts, int c)
-{
-    int i;
-    int j;
-    int index;
-    int y;
-    int miny, maxy;
-    int x1, y1;
-    int x2, y2;
-    int ind1, ind2;
-    int ints;
-    int fill_color;
-    int offset;
-
-    if (!nPts)
-    {
-        return;
-    }
-
-    if (!im->polyAllocated)
-    {
-        //if (overflow2(sizeof (int), nPts)) {
-        //    return;
-        //}
-        im->polyInts = (int *) malloc (sizeof (int) * nPts);
-        im->polyAllocated = nPts;
-    }
-    if (im->polyAllocated < nPts)
-    {
-        while (im->polyAllocated < nPts)
-        {
-            im->polyAllocated *= 2;
-        }
-        im->polyInts = (int *) realloc (im->polyInts,
-            sizeof (int) * im->polyAllocated);
-    }
-    miny = p[0].y;
-    maxy = p[0].y;
-    for (i = 1; (i < nPts); i++)
-    {
-        if (p[i].y < miny)
-        {
-            miny = p[i].y;
-        }
-        if (p[i].y > maxy)
-        {
-            maxy = p[i].y;
-        }
-    }
-    /* 2.0.16: Optimization by Ilia Chipitsine -- don't waste time offscreen */
-    /* 2.0.26: clipping rectangle is even better */
-    if (miny < im->cy1)
-    {
-        miny = im->cy1;
-    }
-    if (maxy > im->cy2)
-    {
-        maxy = im->cy2;
-    }
-    /* Fix in 1.3: count a vertex only once */
-    for (y = miny; (y <= maxy); y++)
-    {
-        /*1.4           int interLast = 0; */
-        /*              int dirLast = 0; */
-        /*              int interFirst = 1; */
-        /* 2.0.26+      int yshift = 0; */
-        if (c == gdAntiAliased) {
-            fill_color = im->AA_color;
-        } else {
-            fill_color = c;
-        }
-
-        ints = 0;
-        offset = 0;
-
-        /*go over each contour and treat it as a polygon of its own*/
-        /*the sort of x intercepts later on will automatically take care of the even-odd fill*/
-        for (j = 0; j < nCntrs; j++)
-        {
-            for (i = 0; (i < cntrs[j]); i++)
-            {
-                if (!i)
-                {
-                    ind1 = cntrs[j] - 1 + offset;
-                    ind2 = 0            + offset;
-                }
-                else
-                {
-                    ind1 = i - 1 + offset;
-                    ind2 = i     + offset;
-                }
-                y1 = p[ind1].y;
-                y2 = p[ind2].y;
-                if (y1 < y2)
-                {
-                    x1 = p[ind1].x;
-                    x2 = p[ind2].x;
-                }
-                else if (y1 > y2)
-                {
-                    y2 = p[ind1].y;
-                    y1 = p[ind2].y;
-                    x2 = p[ind1].x;
-                    x1 = p[ind2].x;
-                }
-                else
-                {
-                    continue;
-                }
-
-                /* Do the following math as float intermediately, and round to ensure
-                * that Polygon and FilledPolygon for the same set of points have the
-                * same footprint. */
-
-                if ((y >= y1) && (y < y2))
-                {
-                    im->polyInts[ints++] = (int) ((float) ((y - y1) * (x2 - x1)) /
-                        (float) (y2 - y1) + 0.5 + x1);
-                }
-//    WCW - don't know why the last scanline is treated differently than the
-//          others - it definitely causes problems with tiles; commenting
-//          out this line until we know why this was added
-//              else if ((y == maxy) && (y > y1) && (y <= y2))
-//              {
-//                  im->polyInts[ints++] = (int) ((float) ((y - y1) * (x2 - x1)) /
-//                      (float) (y2 - y1) + 0.5 + x1);
-//              }
-            }
-
-            offset += cntrs[j];
-        }
-        /*
-        2.0.26: polygons pretty much always have less than 100 points,
-        and most of the time they have considerably less. For such trivial
-        cases, insertion sort is a good choice. Also a good choice for
-        future implementations that may wish to indirect through a table.
-        */
-        for (i = 1; (i < ints); i++) {
-            index = im->polyInts[i];
-            j = i;
-            while ((j > 0) && (im->polyInts[j - 1] > index)) {
-                im->polyInts[j] = im->polyInts[j - 1];
-                j--;
-            }
-            im->polyInts[j] = index;
-        }
-        for (i = 0; (i < (ints)); i += 2)
-        {
-#if 0
-            int minx = im->polyInts[i];
-            int maxx = im->polyInts[i + 1];
-#endif
-            /* 2.0.29: back to gdImageLine to prevent segfaults when
-            performing a pattern fill */
-            gdImageLine (im, im->polyInts[i], y, im->polyInts[i + 1], y,
-                fill_color);
-        }
-    }
-    /* If we are drawing this AA, then redraw the border with AA lines. */
-    /* This doesn't work as well as I'd like, but it doesn't clash either. */
-    if (c == gdAntiAliased) {
-
-        offset = 0;
-        for (i = 0; (i < nCntrs); i++)
-        {
-            gdImagePolygon (im, p + offset, cntrs[i], c);
-            offset += cntrs[i];
-        }
-    }
-}
-
 //axis aligned circle for setting up brushes for thick lines
 void rs_gdImageCircleForBrush(gdImagePtr im, int x, int y, int rad, RS_Color& color)
 {
@@ -262,28 +84,5 @@
     //inner non-transparent circle
     rs_gdImageCircleForBrush(brush1, sx/2, sy/2, (line_weight - 2) / 2, color);
 
-    /////////////////////////////////////////
-    //test
-    /*
-    FILE* out = fopen("c:\\dude.png", "wb");
-
-    int size = 0;
-    char* data = NULL;
-
-    data = (char*)gdImagePngPtr((gdImagePtr)brush1, &size);
-
-    if (data)
-    {
-        if (fwrite(data, 1, size, out) != (size_t)size)
-        {
-            // Error
-            _ASSERT(false);
-        }
-    }
-
-    fclose(out);
-    */
-    //////////////////////////////////////////
-
     return brush1;
 }

Modified: trunk/MgDev/Common/Stylization/GDW2DRewriter.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/GDW2DRewriter.cpp	2007-03-12 15:41:27 UTC (rev 1196)
+++ trunk/MgDev/Common/Stylization/GDW2DRewriter.cpp	2007-03-12 16:15:07 UTC (rev 1197)
@@ -174,8 +174,6 @@
             color = override;
     }
 
-    int gdc = ConvertColor((gdImagePtr)rewriter->GetW2DTargetImage(), color);
-
     //transform point and draw the contour set
     int numcntrs = contourSet.contours();
     WT_Integer32* cntrcounts = contourSet.counts();
@@ -186,10 +184,25 @@
 
     if (dst_cntr)
     {
-        rs_gdImageMultiPolygon((gdImagePtr)rewriter->GetW2DTargetImage(),
-                    (int*)cntrcounts, numcntrs,
-                    (gdPointPtr)(dst_cntr), totalPts,
-                    gdc);
+        //we will call the new screen space polygon API.
+        //Unfortunately we need to convert the raw contour data into a LineBuffer.
+        //This code path is rarely called, so performance should not be a problem.
+        LineBuffer lb(totalPts);
+
+        for (int j=0; j<numcntrs; j++)
+        {
+            for (int i=0; i<cntrcounts[j]; i++)
+            {
+                if (i)
+                    lb.LineTo(dst_cntr->x, dst_cntr->y);
+                else
+                    lb.MoveTo(dst_cntr->x, dst_cntr->y);
+
+                dst_cntr++;
+            }
+        }
+
+        rewriter->DrawScreenPolygon(&lb, color.argb());
     }
 
     return WT_Result::Success;

Modified: trunk/MgDev/Common/Stylization/complex_polygon_gd.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/complex_polygon_gd.cpp	2007-03-12 15:41:27 UTC (rev 1196)
+++ trunk/MgDev/Common/Stylization/complex_polygon_gd.cpp	2007-03-12 16:15:07 UTC (rev 1197)
@@ -349,8 +349,7 @@
     while (CurrentEdge != NULL) {
         LeftX = CurrentEdge->X;
         CurrentEdge = CurrentEdge->NextEdge;
-        if (LeftX < CurrentEdge->X)
-            DrawHorizontalLineSeg(YToScan, LeftX, CurrentEdge->X-1, Color, target);
+        DrawHorizontalLineSeg(YToScan, LeftX, CurrentEdge->X-1, Color, target);
         CurrentEdge = CurrentEdge->NextEdge;
     }
 }

Modified: trunk/MgDev/Common/Stylization/complex_polygon_gd.h
===================================================================
--- trunk/MgDev/Common/Stylization/complex_polygon_gd.h	2007-03-12 15:41:27 UTC (rev 1196)
+++ trunk/MgDev/Common/Stylization/complex_polygon_gd.h	2007-03-12 16:15:07 UTC (rev 1197)
@@ -21,7 +21,10 @@
     //for all the rest of the code to work with it
     inline void DrawHorizontalLineSeg(int Y, int StartX, int EndX, int Color, gdImagePtr target)
     {
-        gdImageLine(target, StartX, Y, EndX, Y, Color);
+        if (StartX <= EndX)
+            gdImageLine(target, StartX, Y, EndX, Y, Color);
+        //else //this condition fixes a case when EndX is to the left of StartX and we draw one pixel more than we should
+        //    gdImageLine(target, StartX, Y, StartX, Y, Color);
     }
 
     void BuildGET(Point *, int* Contours, int nContours, EdgeState *, int MaxY);



More information about the mapguide-commits mailing list