[mapguide-commits] r9498 - in sandbox/jng/tiling_v2/Server/src: Services/Mapping Services/Rendering Services/Tile UnitTesting

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Apr 26 01:47:33 PDT 2019


Author: jng
Date: 2019-04-26 01:47:32 -0700 (Fri, 26 Apr 2019)
New Revision: 9498

Added:
   sandbox/jng/tiling_v2/Server/src/Services/Rendering/ImageProcessor.cpp
   sandbox/jng/tiling_v2/Server/src/Services/Rendering/ImageProcessor.h
Modified:
   sandbox/jng/tiling_v2/Server/src/Services/Mapping/MappingUtil.h
   sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.cpp
   sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.h
   sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.vcxproj
   sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.vcxproj.filters
   sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingServiceBuild.cpp
   sandbox/jng/tiling_v2/Server/src/Services/Tile/ServerTileService.vcxproj
   sandbox/jng/tiling_v2/Server/src/Services/Tile/ServerTileService.vcxproj.filters
   sandbox/jng/tiling_v2/Server/src/UnitTesting/TestRenderingService.cpp
Log:
Refactor out some of the image processing code (metatile slicing, rendererer creation) out to a separate MgImageProcessor utility class.

Modified: sandbox/jng/tiling_v2/Server/src/Services/Mapping/MappingUtil.h
===================================================================
--- sandbox/jng/tiling_v2/Server/src/Services/Mapping/MappingUtil.h	2019-04-26 06:56:13 UTC (rev 9497)
+++ sandbox/jng/tiling_v2/Server/src/Services/Mapping/MappingUtil.h	2019-04-26 08:47:32 UTC (rev 9498)
@@ -38,6 +38,7 @@
 class RSMgFeatureReader;
 class TransformCache;
 class SE_SymbolManager;
+class Stylizer;
 
 namespace MdfModel
 {

Added: sandbox/jng/tiling_v2/Server/src/Services/Rendering/ImageProcessor.cpp
===================================================================
--- sandbox/jng/tiling_v2/Server/src/Services/Rendering/ImageProcessor.cpp	                        (rev 0)
+++ sandbox/jng/tiling_v2/Server/src/Services/Rendering/ImageProcessor.cpp	2019-04-26 08:47:32 UTC (rev 9498)
@@ -0,0 +1,221 @@
+//
+//  Copyright (C) 2004-2019 by Autodesk, Inc.
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of version 2.1 of the GNU Lesser
+//  General Public License as published by the Free Software Foundation.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+#include "MapGuideCommon.h"
+#include "ImageProcessor.h"
+#include "AGGRenderer.h"
+#include "GDRenderer.h"
+#include "StylizationUtil.h"
+#include "ProfileRenderMapResult.h"
+#include "MappingUtil.h"
+
+bool MgImageProcessor::HasColorMap(CREFSTRING format)
+{
+    return format == L"PNG8" || format == L"GIF";
+}
+
+MgByteReader* MgImageProcessor::CreateImageFromRenderer(MgMap* map,
+                                                        Renderer* dr,
+                                                        INT32 saveWidth,
+                                                        INT32 saveHeight,
+                                                        CREFSTRING format,
+                                                        CREFSTRING rendererName,
+                                                        ProfileRenderMapResult* pPRMResult,
+                                                        unsigned int* frameBuffer)
+{
+    if (NULL != pPRMResult)
+    {
+        // Set the start time of creating map image
+        pPRMResult->SetCreateImageTime(MgTimerUtil::GetTime());
+    }
+
+    /*
+        //-------------------------------------------------------
+        // draw a border around the tile - used for debugging
+        RS_LineStroke ls;
+        ls.color() = RS_Color(128, 128, 128, 64);
+
+        LineBuffer lb(5);
+        double mcsMinX = b.minx;
+        double mcsMaxX = b.maxx;
+        double mcsMinY = b.miny;
+        double mcsMaxY = b.maxy;
+        double incX = (mcsMaxX - mcsMinX) / saveWidth  / 10.0;
+        double incY = (mcsMaxY - mcsMinY) / saveHeight / 10.0;
+        lb.MoveTo(mcsMinX + incX, mcsMinY + incY);
+        lb.LineTo(mcsMaxX - incX, mcsMinY + incY);
+        lb.LineTo(mcsMaxX - incX, mcsMaxY - incY);
+        lb.LineTo(mcsMinX + incX, mcsMaxY - incY);
+        lb.LineTo(mcsMinX + incX, mcsMinY + incY);
+        dr->ProcessPolyline(&lb, ls);
+        //-------------------------------------------------------
+    */
+
+    // get a byte representation of the image
+    auto_ptr<RS_ByteData> data;
+    Ptr<MgByteSource> bs;
+
+    try
+    {
+        // call the image renderer to create the image
+        if (wcscmp(rendererName.c_str(), L"AGG") == 0)
+        {
+            if (format == MgImageFormats::Meta)  // we dont use the colorPalette here for meta tiling
+            {                       // as this call only returns the framebuffer
+                data.reset(((AGGRenderer*)dr)->Save(format, saveWidth, saveHeight, NULL, NULL));
+                // copy the framebuffer into the reader, RenderTileFromMetatile is taking it from there
+            }
+            else
+            {
+                //-------------------------------------------------------
+                /// RFC60 code to correct colormaps by UV
+                //-------------------------------------------------------
+                // We examine the expressions collected from xml definitions of all layers.
+                // The map object has a list from all color entries found in the most recent
+                // layer stylization.
+                // * TODO - currently they are interpreted as ffffffff 32-bit RGBA string values
+                // * adding expresssions and other interpretations should be done in ParseColorStrings
+                // * the color Palette for the renderer is a vector<RS_Color>
+                if (HasColorMap(format))
+                {
+                    RS_ColorVector tileColorPalette;
+                    MgMappingUtil::ParseColorStrings(&tileColorPalette, map);
+                    //              printf("<<<<<<<<<<<<<<<<<<<<< MgServerRenderingService::ColorPalette->size(): %d\n", tileColorPalette.size());
+                    data.reset(((AGGRenderer*)dr)->Save(format, saveWidth, saveHeight, &tileColorPalette, frameBuffer));
+                }
+                else
+                    data.reset(((AGGRenderer*)dr)->Save(format, saveWidth, saveHeight, NULL, frameBuffer));
+            }
+        }
+        else
+            data.reset(((GDRenderer*)dr)->Save(format, saveWidth, saveHeight));
+    }
+    catch (exception e)
+    {
+        ACE_DEBUG((LM_DEBUG, L"(%t) %w caught in RenderingService ColorPaletteGeneration\n", e.what()));
+        throw e;
+    }
+
+    if (NULL != data.get())
+    {
+        // put this into a byte source
+        bs = new MgByteSource(data->GetBytes(), data->GetNumBytes());
+
+        if (format == MgImageFormats::Gif)
+            bs->SetMimeType(MgMimeType::Gif);
+        else if (format == MgImageFormats::Jpeg)
+            bs->SetMimeType(MgMimeType::Jpeg);
+        else if (format == MgImageFormats::Png || format == MgImageFormats::Png8)
+            bs->SetMimeType(MgMimeType::Png);
+        else if (format == MgImageFormats::Tiff)
+            bs->SetMimeType(MgMimeType::Tiff);
+        else if (format == MgImageFormats::Meta)         // add a mimetype for our metatile
+            bs->SetMimeType(MgMimeType::Meta);
+    }
+    else
+        throw new MgNullReferenceException(L"MgImageProcessor.CreateImageFromRenderer", __LINE__, __WFILE__, NULL, L"MgNoDataFromRenderer", NULL);
+
+    if (NULL != pPRMResult)
+    {
+        // Calculate the time spent on stylizing labels
+        double createImageTime = MgTimerUtil::GetTime() - pPRMResult->GetCreateImageTime();
+        pPRMResult->SetCreateImageTime(createImageTime);
+
+        pPRMResult->SetImageFormat(format);
+        pPRMResult->SetRendererType(rendererName);
+    }
+
+    return bs->GetReader();
+}
+
+MgByteReader* MgImageProcessor::RenderTileFromMetaTile(MgMap * map, MgMetatile * metaTile, CREFSTRING rendererName, MgIRendererFactory* factory, INT32 subTileX, INT32 subTileY)
+{
+    Ptr<MgByteReader> image = metaTile->GetImage();
+    INT32 metaTileFactor = metaTile->GetMetaTilingFactor();
+    INT32 origTileWidth = metaTile->GetRequestedWidth();
+    INT32 origTileHeight = metaTile->GetRequestedHeight();
+    STRING origTileFormat = metaTile->GetTileImageFormat();
+
+    MgByteSource* bs = image->GetByteSource();
+    // upcast to bytesource Impl to access bytearray member
+    ByteSourceMemoryImpl* source = dynamic_cast<ByteSourceMemoryImpl*>(bs->GetSourceImpl());
+    assert(source);
+    assert(bs->GetMimeType() == MgMimeType::Meta);
+    INT32 size = (INT32)source->GetLength();
+
+    // some checking: the complete meta tile of 32b pixels should be in the framebuffer handed over
+    INT32 expectedSize = 4 * (metaTileFactor * origTileWidth)
+        * (metaTileFactor * origTileHeight);
+    assert(size == expectedSize);
+
+    INT32 scaledTileWidth = origTileWidth;
+    INT32 scaledTileHeight = origTileHeight;
+
+    // For extent-driven tile rendering like XYZ, the raw image frame buffer of the tile may not actually 
+    // be square which means the meta-tile itself would not be square, so when we sub-divide we must make 
+    // sure to not sub-divide by the original width/height, but by its *proportially scaled* width/height, 
+    // which we then pass it down to AGGRenderer::Save() to write the buffer back up to the originally 
+    // requested size, scaling as appropriate.
+    if (metaTileFactor > 1)
+    {
+        scaledTileWidth = (INT32)(metaTile->GetWidth() / metaTileFactor);
+        scaledTileHeight = (INT32)(metaTile->GetHeight() / metaTileFactor);
+
+        // This may be the same or may be less, but it can't be more!
+        _ASSERT(scaledTileWidth <= origTileWidth);
+        _ASSERT(scaledTileHeight <= origTileHeight);
+    }
+
+    // use the map's background color, but always make it fully transparent
+    RS_Color bgColor;
+    StylizationUtil::ParseColor(map->GetBackgroundColor(), bgColor);
+    bgColor.alpha() = 0;
+    // Must create renderer under the scaled width/height and not original
+    auto_ptr<SE_Renderer> dr(factory->CreateRenderer(rendererName, scaledTileWidth, scaledTileHeight, bgColor, true));
+    RS_ColorVector tileColorPalette;
+    if (rendererName == L"AGG" && HasColorMap(origTileFormat))
+    {
+        MgMappingUtil::ParseColorStrings(&tileColorPalette, map);
+    }
+
+    // now copy tile from meta framebuffer to new one...
+    // use unsigned int pointer arithmetic for pixels!
+    //MgByte* byteBuffer = source->Bytes();     // here we access the bytearray inside the bytesource
+    MgByte* byteBuffer = source->BytesNoAddRef();
+    assert(size == byteBuffer->GetLength());  // double check the buffer size
+
+    // get pointer to the framebuffer containing the metatile 
+    unsigned int *framebuf = (unsigned int*)byteBuffer->Bytes();
+
+    // allocate subtile buffer to copy new framebuf with changed dimensions
+    // place buffer in allocated MgByte auto_ptr object for destruction at end of scope
+    auto_ptr<MgByte> subTileBytes(new MgByte((unsigned char*)new unsigned int[scaledTileWidth * scaledTileHeight],
+        scaledTileWidth * scaledTileHeight * sizeof(int), MgByte::New));
+    // get the pointer to the internal target buffer
+    unsigned int* subTileBuf = (unsigned int*)subTileBytes->Bytes();
+    for (int y = 0; y < scaledTileHeight; y++)    // rows
+        for (int x = 0; x < scaledTileWidth; x++)    // columns innerloop
+        {  // this copies the 32bit pixels from the meta tile framebuffer to the subtile framebuffer
+            *(subTileBuf + x
+                + y * scaledTileWidth)                 // target address in subtile
+                = *(framebuf + (x + (subTileX * scaledTileWidth))   // X address in meta tile
+                    + (y + (subTileY * scaledTileHeight))  // Y address in meta tile
+                    * scaledTileWidth * metaTileFactor);  // use width of metaTile here
+        }
+    // then call the image renderer to convert the framebuffer bitmap into the desired image format
+    return CreateImageFromRenderer(map, dr.get(), origTileWidth, origTileHeight, origTileFormat, rendererName, NULL, subTileBuf);
+}

Added: sandbox/jng/tiling_v2/Server/src/Services/Rendering/ImageProcessor.h
===================================================================
--- sandbox/jng/tiling_v2/Server/src/Services/Rendering/ImageProcessor.h	                        (rev 0)
+++ sandbox/jng/tiling_v2/Server/src/Services/Rendering/ImageProcessor.h	2019-04-26 08:47:32 UTC (rev 9498)
@@ -0,0 +1,54 @@
+//
+//  Copyright (C) 2004-2019 by Autodesk, Inc.
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of version 2.1 of the GNU Lesser
+//  General Public License as published by the Free Software Foundation.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+#ifndef MGIMAGEPROCESSOR_H
+#define MGIMAGEPROCESSOR_H
+
+class SE_Renderer;
+
+class MgIRendererFactory
+{
+public:
+    MG_SERVER_RENDERING_API virtual SE_Renderer* CreateRenderer(CREFSTRING rendererName,
+                                                                INT32 width,
+                                                                INT32 height,
+                                                                RS_Color& bgColor,
+                                                                bool requiresClipping,
+                                                                bool localOverposting = false,
+                                                                double tileExtentOffset = 0.0) = 0;
+};
+
+/// \brief
+/// Image processing utils
+class MG_SERVER_RENDERING_API MgImageProcessor
+{
+public:
+    static bool HasColorMap(CREFSTRING format);
+
+    static MgByteReader* CreateImageFromRenderer(MgMap* map,
+                                                 Renderer* dr,
+                                                 INT32 saveWidth,
+                                                 INT32 saveHeight,
+                                                 CREFSTRING format,
+                                                 CREFSTRING rendererName,
+                                                 ProfileRenderMapResult* pPRMResult,
+                                                 unsigned int* frameBuffer = NULL);
+
+    static MgByteReader* RenderTileFromMetaTile(MgMap* map, MgMetatile* metaTile, CREFSTRING rendererName, MgIRendererFactory* factory, INT32 subTileX, INT32 subTileY);
+};
+
+#endif
\ No newline at end of file

Modified: sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.cpp
===================================================================
--- sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.cpp	2019-04-26 06:56:13 UTC (rev 9497)
+++ sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.cpp	2019-04-26 08:47:32 UTC (rev 9498)
@@ -45,11 +45,6 @@
 static const INT32 FILTER_SELECTABLE = 2;
 static const INT32 FILTER_HASTOOLTIPS = 4;
 
-inline bool hasColorMap (STRING format)
-{
-    return format == L"PNG8" || format == L"GIF";
-}
-
 IMPLEMENT_CREATE_SERVICE(MgServerRenderingService)
 
 
@@ -470,7 +465,7 @@
 
     // initialize the renderer (set clipping to false so that we label
     // the unclipped geometry)
-    auto_ptr<SE_Renderer> dr(CreateRenderer(width, height, bgColor, false, true, tileExtentOffset));
+    auto_ptr<SE_Renderer> dr(CreateRenderer(m_rendererName, width, height, bgColor, false, true, tileExtentOffset));
 
     // create a temporary collection containing all the layers for the base group
     Ptr<MgLayerCollection> layers = map->GetLayers();
@@ -499,86 +494,6 @@
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-// gets called with a bitmap in the bytereader to be split up into metatile^2 images
-MgByteReader* MgServerRenderingService::RenderTileFromMetaTile(MgMap* map, MgMetatile* metaTile, INT32 subTileX, INT32 subTileY)
-{
-    Ptr<MgByteReader> image = metaTile->GetImage();
-    INT32 metaTileFactor = metaTile->GetMetaTilingFactor();
-    INT32 origTileWidth = metaTile->GetRequestedWidth();
-    INT32 origTileHeight = metaTile->GetRequestedHeight();
-    STRING origTileFormat = metaTile->GetTileImageFormat();
-
-    MgByteSource* bs = image->GetByteSource();
-    // upcast to bytesource Impl to access bytearray member
-    ByteSourceMemoryImpl* source = dynamic_cast<ByteSourceMemoryImpl*>(bs->GetSourceImpl());
-    assert(source);
-    assert(bs->GetMimeType() == MgMimeType::Meta);
-    INT32 size = (INT32)source->GetLength();
-
-    // some checking: the complete meta tile of 32b pixels should be in the framebuffer handed over
-    INT32 expectedSize = 4 * (metaTileFactor * origTileWidth)
-                         * (metaTileFactor * origTileHeight);
-    assert(size == expectedSize);
-
-    INT32 scaledTileWidth = origTileWidth;
-    INT32 scaledTileHeight = origTileHeight;
-
-    // For extent-driven tile rendering like XYZ, the raw image frame buffer of the tile may not actually 
-    // be square which means the meta-tile itself would not be square, so when we sub-divide we must make 
-    // sure to not sub-divide by the original width/height, but by its *proportially scaled* width/height, 
-    // which we then pass it down to AGGRenderer::Save() to write the buffer back up to the originally 
-    // requested size, scaling as appropriate.
-    if (metaTileFactor > 1)
-    {
-        scaledTileWidth = (INT32)(metaTile->GetWidth() / metaTileFactor);
-        scaledTileHeight = (INT32)(metaTile->GetHeight() / metaTileFactor);
-
-        // This may be the same or may be less, but it can't be more!
-        _ASSERT(scaledTileWidth <= origTileWidth);
-        _ASSERT(scaledTileHeight <= origTileHeight);
-    }
-
-    // use the map's background color, but always make it fully transparent
-    RS_Color bgColor;
-    StylizationUtil::ParseColor(map->GetBackgroundColor(), bgColor);
-    bgColor.alpha() = 0;
-    // Must create renderer under the scaled width/height and not original
-    auto_ptr<SE_Renderer> dr(CreateRenderer(scaledTileWidth, scaledTileHeight, bgColor, true));
-    RS_ColorVector tileColorPalette;
-    if (m_rendererName == L"AGG" && hasColorMap(origTileFormat))
-    {
-        MgMappingUtil::ParseColorStrings(&tileColorPalette, map);
-    }
-
-    // now copy tile from meta framebuffer to new one...
-    // use unsigned int pointer arithmetic for pixels!
-    //MgByte* byteBuffer = source->Bytes();     // here we access the bytearray inside the bytesource
-    MgByte* byteBuffer = source->BytesNoAddRef();
-    assert(size == byteBuffer->GetLength());  // double check the buffer size
-
-    // get pointer to the framebuffer containing the metatile 
-    unsigned int *framebuf = (unsigned int*)byteBuffer->Bytes();
-
-    // allocate subtile buffer to copy new framebuf with changed dimensions
-    // place buffer in allocated MgByte auto_ptr object for destruction at end of scope
-    auto_ptr<MgByte> subTileBytes(new MgByte((unsigned char*)new unsigned int[scaledTileWidth * scaledTileHeight],
-        scaledTileWidth * scaledTileHeight * sizeof(int), MgByte::New));
-    // get the pointer to the internal target buffer
-    unsigned int* subTileBuf = (unsigned int*)subTileBytes->Bytes();
-    for (int y = 0; y < scaledTileHeight; y++)    // rows
-        for (int x = 0; x < scaledTileWidth; x++)    // columns innerloop
-        {  // this copies the 32bit pixels from the meta tile framebuffer to the subtile framebuffer
-            *(subTileBuf + x
-                + y * scaledTileWidth)                 // target address in subtile
-                = *(framebuf + (x + (subTileX * scaledTileWidth))   // X address in meta tile
-                    + (y + (subTileY * scaledTileHeight))  // Y address in meta tile
-                    * scaledTileWidth * metaTileFactor);  // use width of metaTile here
-        }
-    // then call the image renderer to convert the framebuffer bitmap into the desired image format
-    return CreateImage(map, dr.get(), origTileWidth, origTileHeight, origTileFormat, NULL, subTileBuf);
-}
-
-///////////////////////////////////////////////////////////////////////////////
 // default arg bKeepSelection = true
 MgByteReader* MgServerRenderingService::RenderDynamicOverlay(MgMap* map,
                                                              MgSelection* selection,
@@ -673,7 +588,7 @@
     bgColor.alpha() = 0;
 
     // initialize the renderer
-    auto_ptr<SE_Renderer> dr(CreateRenderer(width, height, bgColor, true));
+    auto_ptr<SE_Renderer> dr(CreateRenderer(m_rendererName, width, height, bgColor, true));
 
     bool bIncludeDynamicLayers = ((options->GetBehavior() & MgRenderingOptions::RenderLayers) == MgRenderingOptions::RenderLayers);
     bool bIncludeBaseLayers = ((options->GetBehavior() & MgRenderingOptions::RenderBaseLayers) == MgRenderingOptions::RenderBaseLayers);
@@ -869,7 +784,7 @@
     // initialize the renderer with the rendering canvas size - in this
     // case it is not necessarily the same size as the requested image
     // size due to support for non-square pixels
-    auto_ptr<SE_Renderer> dr(CreateRenderer(drawWidth, drawHeight, bgcolor, false));
+    auto_ptr<SE_Renderer> dr(CreateRenderer(m_rendererName, drawWidth, drawHeight, bgcolor, false));
 
     // call the internal helper API to do all the stylization overhead work
     ret = RenderMapInternal(map, selection, NULL, dr.get(), drawWidth, drawHeight, width, height, format, scale, b, true, bKeepSelection, true, NULL);
@@ -1008,7 +923,7 @@
                      backgroundColor->GetAlpha());
 
     // initialize the appropriate map renderer
-    auto_ptr<SE_Renderer> dr(CreateRenderer(width, height, bgcolor, bClip));
+    auto_ptr<SE_Renderer> dr(CreateRenderer(m_rendererName, width, height, bgcolor, bClip));
 
     if(NULL != pPRMResult)
     {
@@ -1113,7 +1028,7 @@
                 point = point_buf;
 
                 RS_Color bgColor; // not used
-                impRenderer.reset(CreateRenderer(1, 1, bgColor, false));
+                impRenderer.reset(CreateRenderer(m_rendererName, 1, 1, bgColor, false));
             }
         }
     }
@@ -1374,7 +1289,7 @@
 
     MG_THROW()  // to skip a faulty tile we need to rethrow the exception which could be thrown in StylizeLayers
 
-    Ptr<MgByteReader> ret = CreateImage(map, dr, saveWidth, saveHeight, format, pPRMResult);
+    Ptr<MgByteReader> ret = MgImageProcessor::CreateImageFromRenderer(map, dr, saveWidth, saveHeight, format, m_rendererName, pPRMResult);
 
     return ret.Detach();
 }
@@ -1410,7 +1325,7 @@
                      backgroundColor->GetAlpha());
 
     //initialize a renderer
-    auto_ptr<Renderer> dr(CreateRenderer(width, height, bgcolor, false, false, 0.0));
+    auto_ptr<Renderer> dr(CreateRenderer(m_rendererName, width, height, bgcolor, false, false, 0.0));
 
     RS_Bounds b(0,0,width,height);
 
@@ -1901,8 +1816,9 @@
 
 
 ///////////////////////////////////////////////////////////////////////////////
-SE_Renderer* MgServerRenderingService::CreateRenderer(int width,
-                                                      int height,
+SE_Renderer* MgServerRenderingService::CreateRenderer(CREFSTRING rendererName,
+                                                      INT32 width,
+                                                      INT32 height,
                                                       RS_Color& bgColor,
                                                       bool requiresClipping,
                                                       bool localOverposting,
@@ -1909,7 +1825,7 @@
                                                       double tileExtentOffset)
 {
     SE_Renderer* renderer = NULL;
-    if (wcscmp(m_rendererName.c_str(), L"AGG") == 0)
+    if (wcscmp(rendererName.c_str(), L"AGG") == 0)
         renderer = new AGGRenderer(width, height, bgColor, requiresClipping, localOverposting, tileExtentOffset);
     else
         renderer = new GDRenderer(width, height, bgColor, requiresClipping, localOverposting, tileExtentOffset);
@@ -1950,7 +1866,7 @@
 
     MgMappingUtil::StylizeLayers(m_svcResource, m_svcFeature, m_svcDrawing, m_pCSFactory, map,
                                     layers, NULL, ds, dr, dstCs, expandExtents, false, scale,
-                                    false, hasColorMap(format), pPRLsResult);
+                                    false, MgImageProcessor::HasColorMap(format), pPRLsResult);
 
     if(NULL != pPRMResult)
     {
@@ -2300,120 +2216,6 @@
     }
 }
 
-////////////////////////////////////////////////////////////////////////////////
-inline MgByteReader* MgServerRenderingService::CreateImage(MgMap* map,
-                                                           Renderer* dr,
-                                                           INT32 saveWidth,
-                                                           INT32 saveHeight,
-                                                           CREFSTRING format,
-                                                           ProfileRenderMapResult* pPRMResult,
-                                                           unsigned int* frameBuffer)
-{
-    if(NULL != pPRMResult)
-    {
-        // Set the start time of creating map image
-        pPRMResult->SetCreateImageTime(MgTimerUtil::GetTime());
-    }
-
-/*
-    //-------------------------------------------------------
-    // draw a border around the tile - used for debugging
-    RS_LineStroke ls;
-    ls.color() = RS_Color(128, 128, 128, 64);
-
-    LineBuffer lb(5);
-    double mcsMinX = b.minx;
-    double mcsMaxX = b.maxx;
-    double mcsMinY = b.miny;
-    double mcsMaxY = b.maxy;
-    double incX = (mcsMaxX - mcsMinX) / saveWidth  / 10.0;
-    double incY = (mcsMaxY - mcsMinY) / saveHeight / 10.0;
-    lb.MoveTo(mcsMinX + incX, mcsMinY + incY);
-    lb.LineTo(mcsMaxX - incX, mcsMinY + incY);
-    lb.LineTo(mcsMaxX - incX, mcsMaxY - incY);
-    lb.LineTo(mcsMinX + incX, mcsMaxY - incY);
-    lb.LineTo(mcsMinX + incX, mcsMinY + incY);
-    dr->ProcessPolyline(&lb, ls);
-    //-------------------------------------------------------
-*/
-
-    // get a byte representation of the image
-    auto_ptr<RS_ByteData> data;
-    Ptr<MgByteSource> bs;
-
-    try
-    {
-        // call the image renderer to create the image
-        if (wcscmp(m_rendererName.c_str(), L"AGG") == 0)
-        {
-            if (format == MgImageFormats::Meta)  // we dont use the colorPalette here for meta tiling
-            {                       // as this call only returns the framebuffer
-                data.reset(((AGGRenderer*)dr)->Save(format, saveWidth, saveHeight, NULL, NULL));
-                // copy the framebuffer into the reader, RenderTileFromMetatile is taking it from there
-            }
-            else
-            {
-                //-------------------------------------------------------
-                /// RFC60 code to correct colormaps by UV
-                //-------------------------------------------------------
-                // We examine the expressions collected from xml definitions of all layers.
-                // The map object has a list from all color entries found in the most recent
-                // layer stylization.
-                // * TODO - currently they are interpreted as ffffffff 32-bit RGBA string values
-                // * adding expresssions and other interpretations should be done in ParseColorStrings
-                // * the color Palette for the renderer is a vector<RS_Color>
-                if (hasColorMap(format))
-                {
-                    RS_ColorVector tileColorPalette;
-                    MgMappingUtil::ParseColorStrings(&tileColorPalette, map);
-                    //              printf("<<<<<<<<<<<<<<<<<<<<< MgServerRenderingService::ColorPalette->size(): %d\n", tileColorPalette.size());
-                    data.reset(((AGGRenderer*)dr)->Save(format, saveWidth, saveHeight, &tileColorPalette, frameBuffer));
-                }
-                else
-                    data.reset(((AGGRenderer*)dr)->Save(format, saveWidth, saveHeight, NULL, frameBuffer));
-            }
-        }
-        else
-            data.reset(((GDRenderer*)dr)->Save(format, saveWidth, saveHeight));
-    }
-    catch (exception e)
-    {
-        ACE_DEBUG((LM_DEBUG, L"(%t) %w caught in RenderingService ColorPaletteGeneration\n", e.what()));
-        throw e;
-    }
-
-    if (NULL != data.get())
-    {
-        // put this into a byte source
-        bs = new MgByteSource(data->GetBytes(), data->GetNumBytes());
-
-        if (format == MgImageFormats::Gif)
-            bs->SetMimeType(MgMimeType::Gif);
-        else if (format == MgImageFormats::Jpeg)
-            bs->SetMimeType(MgMimeType::Jpeg);
-        else if (format == MgImageFormats::Png || format == MgImageFormats::Png8)
-            bs->SetMimeType(MgMimeType::Png);
-        else if (format == MgImageFormats::Tiff)
-            bs->SetMimeType(MgMimeType::Tiff);
-        else if (format == MgImageFormats::Meta)         // add a mimetype for our metatile
-            bs->SetMimeType(MgMimeType::Meta);
-    }
-    else
-        throw new MgNullReferenceException(L"MgServerRenderingService.CreateImage", __LINE__, __WFILE__, NULL, L"MgNoDataFromRenderer", NULL);
-    
-    if(NULL != pPRMResult)
-    {
-        // Calculate the time spent on stylizing labels
-        double createImageTime = MgTimerUtil::GetTime() - pPRMResult->GetCreateImageTime();
-        pPRMResult->SetCreateImageTime(createImageTime);
-
-        pPRMResult->SetImageFormat(format);
-        pPRMResult->SetRendererType(m_rendererName);
-    }
-
-    return bs->GetReader();
-}
-
 MgByteReader* MgServerRenderingService::RenderTile(MgMap* map,
                                                    CREFSTRING baseMapLayerGroupName,
                                                    INT32 tileColumn,
@@ -2654,7 +2456,7 @@
 
     // initialize the renderer (set clipping to false so that we label
     // the unclipped geometry)
-    auto_ptr<SE_Renderer> dr(CreateRenderer(drawWidth, drawHeight, bgColor, false, true, tileExtentOffset));
+    auto_ptr<SE_Renderer> dr(CreateRenderer(m_rendererName, drawWidth, drawHeight, bgColor, false, true, tileExtentOffset));
 
     // create a temporary collection containing all the layers for the base group
     Ptr<MgLayerCollection> layers = map->GetLayers();

Modified: sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.h
===================================================================
--- sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.h	2019-04-26 06:56:13 UTC (rev 9497)
+++ sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.h	2019-04-26 08:47:32 UTC (rev 9498)
@@ -19,6 +19,7 @@
 #define MGSERVERRENDERINGSERVICE_H
 
 #include "ServerRenderingDllExport.h"
+#include "ImageProcessor.h"
 
 class SE_Renderer;
 class FeatureInfoRenderer;
@@ -30,7 +31,7 @@
     class ProfileRenderMapResult;
 }
 
-class MG_SERVER_RENDERING_API MgServerRenderingService : public MgRenderingService
+class MG_SERVER_RENDERING_API MgServerRenderingService : public MgRenderingService, public MgIRendererFactory
 {
     DECLARE_CLASSNAME(MgServerRenderingService)
 
@@ -283,8 +284,6 @@
                                           double tileExtentOffset,
                                           INT32 metaTilingFactor);
 
-    MgByteReader* RenderTileFromMetaTile(MgMap* map, MgMetatile* metaTile, INT32 subTileX, INT32 subTileY);
-
 private:
     static void ComputeScaledDimensions(RS_Bounds& extent, INT32 width, INT32 height, INT32 dpi,
                                         double metersPerUnit, INT32& drawWidth, INT32& drawHeight, double& scale);
@@ -346,12 +345,13 @@
                          INT32 layerAttributeFilter,
                          FeatureInfoRenderer* selRenderer);
 
-    SE_Renderer* CreateRenderer(int width,
-                                int height,
-                                RS_Color& bgColor,
-                                bool requiresClipping,
-                                bool localOverposting = false,
-                                double tileExtentOffset = 0.0);
+    virtual SE_Renderer* CreateRenderer(CREFSTRING rendererName,
+                                        INT32 width,
+                                        INT32 height,
+                                        RS_Color& bgColor,
+                                        bool requiresClipping,
+                                        bool localOverposting = false,
+                                        double tileExtentOffset = 0.0);
 
     void RenderLayers(MgMap* map,
                       MgReadOnlyLayerCollection* layers,
@@ -384,14 +384,6 @@
                           INT32 saveHeight,
                           ProfileRenderMapResult* pPRMResult);
 
-    MgByteReader* CreateImage(MgMap* map,
-                              Renderer* dr,
-                              INT32 saveWidth,
-                              INT32 saveHeight,
-                              CREFSTRING format,
-                              ProfileRenderMapResult* pPRMResult,
-                              unsigned int* frameBuffer = NULL);
-
     // member data
     Ptr<MgFeatureService> m_svcFeature;
     Ptr<MgResourceService> m_svcResource;

Modified: sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.vcxproj
===================================================================
--- sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.vcxproj	2019-04-26 06:56:13 UTC (rev 9497)
+++ sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.vcxproj	2019-04-26 08:47:32 UTC (rev 9498)
@@ -198,6 +198,12 @@
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="ImageProcessor.cpp">
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
+    </ClCompile>
     <ClCompile Include="OpQueryFeatureProperties.cpp">
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
@@ -303,6 +309,7 @@
     <ClCompile Include="ServerRenderingServiceBuild.cpp" />
   </ItemGroup>
   <ItemGroup>
+    <ClInclude Include="ImageProcessor.h" />
     <ClInclude Include="OpQueryFeatureProperties.h" />
     <ClInclude Include="OpQueryFeatures.h" />
     <ClInclude Include="OpRenderDynamicOverlay.h" />

Modified: sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.vcxproj.filters
===================================================================
--- sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.vcxproj.filters	2019-04-26 06:56:13 UTC (rev 9497)
+++ sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.vcxproj.filters	2019-04-26 08:47:32 UTC (rev 9498)
@@ -48,6 +48,7 @@
     <ClCompile Include="OpRenderMetatileXYZ.cpp">
       <Filter>Ops</Filter>
     </ClCompile>
+    <ClCompile Include="ImageProcessor.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="OpQueryFeatureProperties.h">
@@ -92,6 +93,7 @@
     <ClInclude Include="OpRenderMetatileXYZ.h">
       <Filter>Ops</Filter>
     </ClInclude>
+    <ClInclude Include="ImageProcessor.h" />
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="ServerRenderingService.rc" />

Modified: sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingServiceBuild.cpp
===================================================================
--- sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingServiceBuild.cpp	2019-04-26 06:56:13 UTC (rev 9497)
+++ sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingServiceBuild.cpp	2019-04-26 08:47:32 UTC (rev 9498)
@@ -20,6 +20,7 @@
 #endif
 #include "FeatureInfoRenderer.cpp"
 #include "FeaturePropRenderer.cpp"
+#include "ImageProcessor.cpp"
 #include "OpRenderDynamicOverlay.cpp"
 #include "OpRenderMap.cpp"
 #include "OpRenderMapLegend.cpp"

Modified: sandbox/jng/tiling_v2/Server/src/Services/Tile/ServerTileService.vcxproj
===================================================================
--- sandbox/jng/tiling_v2/Server/src/Services/Tile/ServerTileService.vcxproj	2019-04-26 06:56:13 UTC (rev 9497)
+++ sandbox/jng/tiling_v2/Server/src/Services/Tile/ServerTileService.vcxproj	2019-04-26 08:47:32 UTC (rev 9498)
@@ -198,6 +198,12 @@
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="MetatileCache.cpp">
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
+    </ClCompile>
     <ClCompile Include="OpClearCache.cpp">
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
@@ -291,6 +297,7 @@
     </ClCompile>
   </ItemGroup>
   <ItemGroup>
+    <ClInclude Include="MetatileCache.h" />
     <ClInclude Include="OpClearCache.h" />
     <ClInclude Include="OpGetDefaultTileSizeX.h" />
     <ClInclude Include="OpGetDefaultTileSizeY.h" />

Modified: sandbox/jng/tiling_v2/Server/src/Services/Tile/ServerTileService.vcxproj.filters
===================================================================
--- sandbox/jng/tiling_v2/Server/src/Services/Tile/ServerTileService.vcxproj.filters	2019-04-26 06:56:13 UTC (rev 9497)
+++ sandbox/jng/tiling_v2/Server/src/Services/Tile/ServerTileService.vcxproj.filters	2019-04-26 08:47:32 UTC (rev 9498)
@@ -38,6 +38,7 @@
       <Filter>Ops</Filter>
     </ClCompile>
     <ClCompile Include="TileCacheXYZProvider.cpp" />
+    <ClCompile Include="MetatileCache.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="OpClearCache.h">
@@ -72,6 +73,7 @@
       <Filter>Ops</Filter>
     </ClInclude>
     <ClInclude Include="TileCacheXYZProvider.h" />
+    <ClInclude Include="MetatileCache.h" />
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="ServerTileService.rc" />

Modified: sandbox/jng/tiling_v2/Server/src/UnitTesting/TestRenderingService.cpp
===================================================================
--- sandbox/jng/tiling_v2/Server/src/UnitTesting/TestRenderingService.cpp	2019-04-26 06:56:13 UTC (rev 9497)
+++ sandbox/jng/tiling_v2/Server/src/UnitTesting/TestRenderingService.cpp	2019-04-26 08:47:32 UTC (rev 9498)
@@ -26,6 +26,7 @@
 #include "FoundationDefs.h"
 #include "SE_Renderer.h"
 #include "ServerRenderingService.h"
+#include "ImageProcessor.h"
 
 const STRING TEST_LOCALE = L"en";
 
@@ -1742,11 +1743,11 @@
         //metaTile->ToFile(L"../UnitTestFiles/RenderTile_Metatile at 4_6.png");
         //CPPUNIT_ASSERT(metaTile->IsRewindable());
         //metaTile->Rewind();
-        
-        Ptr<MgByteReader> tile4_6 = renderSvc->RenderTileFromMetaTile(map, metaTile, 0, 0);
-        Ptr<MgByteReader> tile4_7 = renderSvc->RenderTileFromMetaTile(map, metaTile, 0, 1);
-        Ptr<MgByteReader> tile5_6 = renderSvc->RenderTileFromMetaTile(map, metaTile, 1, 0);
-        Ptr<MgByteReader> tile5_7 = renderSvc->RenderTileFromMetaTile(map, metaTile, 1, 1);
+        STRING rendererName = L"AGG";
+        Ptr<MgByteReader> tile4_6 = MgImageProcessor::RenderTileFromMetaTile(map, metaTile, rendererName, renderSvc, 0, 0);
+        Ptr<MgByteReader> tile4_7 = MgImageProcessor::RenderTileFromMetaTile(map, metaTile, rendererName, renderSvc, 0, 1);
+        Ptr<MgByteReader> tile5_6 = MgImageProcessor::RenderTileFromMetaTile(map, metaTile, rendererName, renderSvc, 1, 0);
+        Ptr<MgByteReader> tile5_7 = MgImageProcessor::RenderTileFromMetaTile(map, metaTile, rendererName, renderSvc, 1, 1);
 
 
         tile4_6->ToFile(GetPath(L"../UnitTestFiles/RenderTile_4_6_Metatiled", imageFormat, extension));
@@ -1788,12 +1789,12 @@
         //metaTile->ToFile(L"../UnitTestFiles/RenderTileXYZ_Metatile at 16798_23891_16.png");
         //CPPUNIT_ASSERT(metaTile->IsRewindable());
         //metaTile->Rewind();
+        STRING rendererName = L"AGG";
+        Ptr<MgByteReader> tile_16798_23891 = MgImageProcessor::RenderTileFromMetaTile(map, metaTile, rendererName, renderSvc, 0, 0);
+        Ptr<MgByteReader> tile_16799_23891 = MgImageProcessor::RenderTileFromMetaTile(map, metaTile, rendererName, renderSvc, 1, 0);
+        Ptr<MgByteReader> tile_16798_23892 = MgImageProcessor::RenderTileFromMetaTile(map, metaTile, rendererName, renderSvc, 0, 1);
+        Ptr<MgByteReader> tile_16799_23892 = MgImageProcessor::RenderTileFromMetaTile(map, metaTile, rendererName, renderSvc, 1, 1);
 
-        Ptr<MgByteReader> tile_16798_23891 = renderSvc->RenderTileFromMetaTile(map, metaTile, 0, 0);
-        Ptr<MgByteReader> tile_16799_23891 = renderSvc->RenderTileFromMetaTile(map, metaTile, 1, 0);
-        Ptr<MgByteReader> tile_16798_23892 = renderSvc->RenderTileFromMetaTile(map, metaTile, 0, 1);
-        Ptr<MgByteReader> tile_16799_23892 = renderSvc->RenderTileFromMetaTile(map, metaTile, 1, 1);
-
         tile_16798_23891->ToFile(GetPath(L"../UnitTestFiles/RenderTileXYZ_16798_23891_16_Metatiled", imageFormat, extension));
         tile_16799_23891->ToFile(GetPath(L"../UnitTestFiles/RenderTileXYZ_16799_23891_16_Metatiled", imageFormat, extension));
         tile_16798_23892->ToFile(GetPath(L"../UnitTestFiles/RenderTileXYZ_16798_23892_16_Metatiled", imageFormat, extension));



More information about the mapguide-commits mailing list