[mapguide-commits] r4571 - in trunk/MgDev/Common: Renderers Stylization

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sun Jan 31 01:17:52 EST 2010


Author: waltweltonlair
Date: 2010-01-31 01:17:51 -0500 (Sun, 31 Jan 2010)
New Revision: 4571

Modified:
   trunk/MgDev/Common/Renderers/AGGRenderer.cpp
   trunk/MgDev/Common/Renderers/AGGW2DRewriter.cpp
   trunk/MgDev/Common/Renderers/GDRenderer.cpp
   trunk/MgDev/Common/Renderers/KmlRenderer.cpp
   trunk/MgDev/Common/Stylization/LineBuffer.cpp
Log:
Fix #1258 (AGG / GD crash when DrawScreenRaster is called with undefined image)

In both AGGRenderer and GDRenderer:
* added check for RS_ImageFormat_Unknown to DrawScreenRaster
* added check for negative native width or height for the case of non-PNG formats

Other cleanup:
* Changed a couple of calls in GDRenderer to use rs_max and not max().  For stylization & rendering all min / max calls should be done using rs_min / rs_max.
* Removed pragma warning calls for C4355 - these are no longer needed in Visual Studio 2008.


Modified: trunk/MgDev/Common/Renderers/AGGRenderer.cpp
===================================================================
--- trunk/MgDev/Common/Renderers/AGGRenderer.cpp	2010-01-30 20:26:44 UTC (rev 4570)
+++ trunk/MgDev/Common/Renderers/AGGRenderer.cpp	2010-01-31 06:17:51 UTC (rev 4571)
@@ -292,16 +292,16 @@
         scale = (double)m_width / m_extents.width();
 
     m_xform.x0 = scale;
-    m_xform.x1 = 0;
+    m_xform.x1 = 0.0;
     m_xform.x2 = -scale * m_extents.minx;
-    m_xform.y0 = 0;
+    m_xform.y0 = 0.0;
     m_xform.y1 = scale;
     m_xform.y2 = -scale * m_extents.miny;
 
     m_ixform.x0 = 1.0 / scale;
-    m_ixform.x1 = 0;
+    m_ixform.x1 = 0.0;
     m_ixform.x2 = m_extents.minx;
-    m_ixform.y0 = 0;
+    m_ixform.y0 = 0.0;
     m_ixform.y1 = m_ixform.x0;
     m_ixform.y2 = m_extents.miny;
 
@@ -506,7 +506,8 @@
 
         // convert thickness to pixels
         double thickness = use_lsym.width();
-        m_lineStroke.weight = max(1.0, _MeterToMapSize(use_lsym.units(), fabs(thickness)) * m_xform.x0);
+        double weightpx = _MeterToMapSize(use_lsym.units(), fabs(thickness)) * m_xform.x0;
+        m_lineStroke.weight = rs_max(1.0, weightpx);
 
         DrawScreenPolyline(workbuffer, &m_xform, m_lineStroke);
 
@@ -612,7 +613,8 @@
 
         // convert thickness to pixels
         double thickness = use_lsym->width();
-        m_lineStroke.weight = max(1.0, _MeterToMapSize(use_lsym->units(), fabs(thickness)) * m_xform.x0);
+        double weightpx = _MeterToMapSize(use_lsym->units(), fabs(thickness)) * m_xform.x0;
+        m_lineStroke.weight = rs_max(1.0, weightpx);
 
         DrawScreenPolyline(workbuffer, &m_xform, m_lineStroke);
 
@@ -2204,7 +2206,7 @@
     if (srclb->geom_count() == 0)
         return;
 
-    double weightpx = max(1.0, lineStroke.weight);
+    double weightpx = rs_max(1.0, lineStroke.weight);
 
     // add to the agg path storage - here it doesn't matter
     // how many geometries there are in the line buffer,
@@ -2410,6 +2412,9 @@
                                    RS_ImageFormat format, int native_width, int native_height,
                                    double x, double y, double w, double h, double angledeg)
 {
+    if (format == RS_ImageFormat_Unknown)
+        return;
+
     // if it's PNG, decode it and come back around
     if (format == RS_ImageFormat_PNG)
     {
@@ -2421,6 +2426,9 @@
         return;
     }
 
+    if (native_width < 0 || native_height < 0)
+        return;
+
     // set up the image insertion transformation
     agg::trans_affine img_mtx;
     img_mtx.reset();

Modified: trunk/MgDev/Common/Renderers/AGGW2DRewriter.cpp
===================================================================
--- trunk/MgDev/Common/Renderers/AGGW2DRewriter.cpp	2010-01-30 20:26:44 UTC (rev 4570)
+++ trunk/MgDev/Common/Renderers/AGGW2DRewriter.cpp	2010-01-31 06:17:51 UTC (rev 4571)
@@ -434,7 +434,8 @@
     double end = outlineEllipse.end_degree() * (M_PI / 180.0);
 
     //get W2D line weight
-    double thick = rs_max(1.0, rewriter->ScaleW2DNumber(file, file.rendition().line_weight().weight_value()));
+    double weightpx = rewriter->ScaleW2DNumber(file, file.rendition().line_weight().weight_value());
+    weightpx = rs_max(1.0, weightpx);
 
     LineBuffer* ell = LineBufferPool::NewLineBuffer(rewriter->GetBufferPool(), 20);
     std::auto_ptr<LineBuffer> spEllLB(ell);
@@ -443,7 +444,7 @@
     ell->MoveTo(dstpts->x_coord(0) + major * cos(start), dstpts->y_coord(0) + minor * sin(start));
     ell->ArcTo(dstpts->x_coord(0), dstpts->y_coord(0), major, minor, start, end);
 
-    SE_LineStroke lineStroke(color.argb(), thick);
+    SE_LineStroke lineStroke(color.argb(), weightpx);
     AGGRenderer::DrawScreenPolyline((agg_context*)rewriter->GetW2DTargetImage(), ell, NULL, lineStroke);
 
     LineBufferPool::FreeLineBuffer(rewriter->GetBufferPool(), spDstLB.release());
@@ -655,8 +656,9 @@
 
     if (dstpts)
     {
-        double thick = rs_max(1.0, rewriter->ScaleW2DNumber(file, file.rendition().line_weight().weight_value()));
-        SE_LineStroke lineStroke(color.argb(), thick);
+        double weightpx = rewriter->ScaleW2DNumber(file, file.rendition().line_weight().weight_value());
+        weightpx = rs_max(1.0, weightpx);
+        SE_LineStroke lineStroke(color.argb(), weightpx);
         AGGRenderer::DrawScreenPolyline((agg_context*)rewriter->GetW2DTargetImage(), dstpts, NULL, lineStroke);
         LineBufferPool::FreeLineBuffer(rewriter->GetBufferPool(), spDstLB.release());
     }

Modified: trunk/MgDev/Common/Renderers/GDRenderer.cpp
===================================================================
--- trunk/MgDev/Common/Renderers/GDRenderer.cpp	2010-01-30 20:26:44 UTC (rev 4570)
+++ trunk/MgDev/Common/Renderers/GDRenderer.cpp	2010-01-31 06:17:51 UTC (rev 4571)
@@ -68,10 +68,7 @@
 // maximum allowed size for images
 #define IMAGE_SIZE_MAX 2048.0*2048.0
 
-//using this in contructor
-#pragma warning(disable:4355)
 
-
 // Dummy class used to automate initialization/uninitialization of GD.
 class CInitGD
 {
@@ -757,7 +754,7 @@
 
                 //default bounds of symbol data in W2D
                 //for symbols created by MapGuide Studio
-                RS_Bounds src(0, 0, SYMBOL_MAX, SYMBOL_MAX);
+                RS_Bounds src(0.0, 0.0, SYMBOL_MAX, SYMBOL_MAX);
                 SymbolTrans st = SymbolTrans(src, dst, refX, refY, angleRad);
 
                 if (m_imsym)
@@ -769,7 +766,7 @@
                     //also we will use a slight boundary offset
                     //hardcoded to 1 pixel so that geometry exactly on the edge
                     //draws just inside the image
-                    RS_Bounds dst1(1, 1, (double)(imsymw-1), (double)(imsymh-1));
+                    RS_Bounds dst1(1.0, 1.0, (double)(imsymw-1), (double)(imsymh-1));
                     st = SymbolTrans(src, dst1, 0.0, 0.0, 0.0);
 
                     m_imw2d = m_imsym;
@@ -880,8 +877,8 @@
                         tempx = poly[i].x;
                         tempy = poly[i].y;
 
-                        pts[i].x = (int)(tempx * (superw - 10.) + 5.);
-                        pts[i].y = (int)((superh - 10.) - tempy * (superh - 10.) + 5.);
+                        pts[i].x = (int)(tempx * (superw - 10.0) + 5.0);
+                        pts[i].y = (int)((superh - 10.0) - tempy * (superh - 10.0) + 5.0);
                     }
 
                     // initialize the temporary supersampled symbol image to a transparent background
@@ -994,16 +991,16 @@
             //construct transformer from cached image space
             //to rotated map space -- we need this in order to
             //take into account the insertion point
-            RS_Bounds src(0, 0, imsymw, imsymh);
+            RS_Bounds src(0.0, 0.0, imsymw, imsymh);
             SymbolTrans trans(src, dst, refX, refY, angleRad);
 
             //initialize 4 corner points of symbol -- we will
             //destructively transform this array to destination map space
             RS_F_Point b[4];
-            b[0].x = 0.0; b[0].y = 0.0;
-            b[1].x = imsymw; b[1].y = 0.0;
+            b[0].x =    0.0; b[0].y =    0.0;
+            b[1].x = imsymw; b[1].y =    0.0;
             b[2].x = imsymw; b[2].y = imsymh;
-            b[3].x = 0.0; b[3].y = imsymh;
+            b[3].x =    0.0; b[3].y = imsymh;
 
             for (int i=0; i<4; i++)
             {
@@ -1063,17 +1060,17 @@
 
         //default bounds of symbol data in W2D
         //for symbols created by MapGuide Studio
-        RS_Bounds src(0, 0, SYMBOL_MAX, SYMBOL_MAX);
+        RS_Bounds src(0.0, 0.0, SYMBOL_MAX, SYMBOL_MAX);
 
         //a square that we will transform into the dst bounds
-        RS_F_Point box[5];
-        box[0].x = 0;
-        box[0].y = 0;
+        RS_F_Point box[4];
+        box[0].x = 0.0;
+        box[0].y = 0.0;
         box[1].x = SYMBOL_MAX;
-        box[1].y = 0;
+        box[1].y = 0.0;
         box[2].x = SYMBOL_MAX;
         box[2].y = SYMBOL_MAX;
-        box[3].x = 0;
+        box[3].x = 0.0;
         box[3].y = SYMBOL_MAX;
 
         //construct transformer -- same as the
@@ -2543,6 +2540,9 @@
                                   RS_ImageFormat format, int native_width, int native_height,
                                   double x, double y, double w, double h, double angleDeg)
 {
+    if (format == RS_ImageFormat_Unknown)
+        return;
+
     // compute the scaled / rotated size
     double rotatedW = w;
     double rotatedH = h;
@@ -2562,6 +2562,9 @@
     gdImagePtr src = NULL;
     if (format == RS_ImageFormat_ABGR)
     {
+        if (native_width < 0 || native_height < 0)
+            return;
+
         src = gdImageCreateTrueColor(native_width, native_height);
 
         //TODO: figure out a way to do this without copying the whole thing
@@ -2584,6 +2587,9 @@
     }
     else if (format == RS_ImageFormat_ARGB)
     {
+        if (native_width < 0 || native_height < 0)
+            return;
+
         src = gdImageCreateTrueColor(native_width, native_height);
 
         //TODO: figure out a way to do this without copying the whole thing

Modified: trunk/MgDev/Common/Renderers/KmlRenderer.cpp
===================================================================
--- trunk/MgDev/Common/Renderers/KmlRenderer.cpp	2010-01-30 20:26:44 UTC (rev 4570)
+++ trunk/MgDev/Common/Renderers/KmlRenderer.cpp	2010-01-31 06:17:51 UTC (rev 4571)
@@ -23,9 +23,6 @@
 #include "UnicodeString.h"
 #include "PolygonUtils.h"
 
-//using this in contructor
-#pragma warning(disable:4355)
-
 const double ELEV_FACTOR = 0.1;
 
 

Modified: trunk/MgDev/Common/Stylization/LineBuffer.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/LineBuffer.cpp	2010-01-30 20:26:44 UTC (rev 4570)
+++ trunk/MgDev/Common/Stylization/LineBuffer.cpp	2010-01-31 06:17:51 UTC (rev 4571)
@@ -687,10 +687,10 @@
 
     // if it's almost a straight line, avoid numeric instability
     // by just adding two lines instead of tessellating a curve
-    double minx = rs_min(x0, rs_min (x1, x2));
-    double maxx = rs_max(x0, rs_max (x1, x2));
-    double miny = rs_min(y0, rs_min (y1, y2));
-    double maxy = rs_max(y0, rs_max (y1, y2));
+    double minx = rs_min(x0, rs_min(x1, x2));
+    double maxx = rs_max(x0, rs_max(x1, x2));
+    double miny = rs_min(y0, rs_min(y1, y2));
+    double maxy = rs_max(y0, rs_max(y1, y2));
 
     double boxArea = (maxx - minx) * (maxy - miny);
 



More information about the mapguide-commits mailing list