Changes between Version 5 and Version 6 of MapGuideRfc60


Ignore:
Timestamp:
Mar 24, 2009, 6:11:35 AM (15 years ago)
Author:
uvlite
Comment:

We are in final testing now... pleace comment soon to change things.

Legend:

Unmodified
Added
Removed
Modified
  • MapGuideRfc60

    v5 v6  
    2525
    2626The color quantization for PNG8 tiles does not preserve the base colors of the map. This leads to visible color differences in adjacent map tiles.
    27 By providing color hints of the base colors of the map in a palette file the visual appearance of the map can be significantly improved.
     27By providing the base colors of the map as a palette to the image renderer the visual appearance of the map can be significantly improved.
    2828
    2929== Motivation ==
    3030
    3131The color palette for PNG8 tiles is computed in the AGG renderer from truecolor tiles (AGGImageIO.cpp) on a one by one basis.
    32 The used quantization algorithm in the gd library (gd_topal.c) does not preserve the base colors of the map.
    33 Therefore adjacent map tiles might use different colors for map areas crossing tile boundaries. This is easily visible to the human eye.
     32The used quantization algorithm in the gd library (gd_topal.c) does not preserve the base colors of the map as they are not know at this place.
     33Therefore adjacent map tiles might use different colors for map areas crossing tile boundaries. This is very obvious and disturbing to the human eye.
    3434
    3535Ticket #813 PNG8 Compression isn't preserving fill colors
     
    3737== Proposed Solution ==
    3838
    39 By providing the base colors of the map in a palette file and using an improved color quantification algorithm which adds a forced palette to the image
    40 the resulting map can be significantly improved. This can be done easily by adding borrowing the function `msImageCopyForcePaletteGD` from the mapserver code base which does exactly that.
     39By providing the base colors of the map in a palette file and using an improved color quantification algorithm which adds a forced palette to the image the resulting map can be significantly improved.
     40This can be done by using the median-cut algorithm as used in the mapserver code base in the function `msImageCopyForcePaletteGD`.
    4141
    4242{{{
     
    5353 */
    5454static int msImageCopyForcePaletteGD(gdImagePtr src, gdImagePtr dst, int method);
    55 gdImagePtr msImageCreateWithPaletteGD( gdImagePtr img24, const char *palette, int sx, int sy);
     55/// create an empty paletted gdImage of size (x,y) using the base colors provided in the baseColorPalette
     56/// the original truecolor image img24 is used to fill up the remaining slots of the palette if needed
     57gdImagePtr CreateGdImageWithPalette( gdImagePtr img24, RSCOLORLIST* baseColorPalette, int sx, int sy)
    5658}}}
    5759
    58 To further improve this approach some runtime test code needs be added to make sure that ''important colors'' are part of the used palette.
    59 In the simplest case an exception is thrown if the color of a single color tile is missing in the provided palette creating an error message.
     60== server code integration ==
    6061
    61 As a next improvement for such run time testing some histogram based heuristics can be used to detect ''important'' colors (e.g. n% pixels of a tile with n TBD).
     62The interesting task is how to feed the base colors of the map to the Image Renderer making the image.
     63The base colors of a map can be extracted most efficiently during map generation in MapingUtil::StylizeLayers().
     64To do this the VectorLayerDefiniton gets an additional method called VectorLayerDefiniton::ComputeUsedColors(scaleRange).
     65At the end of the stylization this method is called and the resulting color list is stored in the runtime map object MgMap.
     66(Map->SetColorPalette(pStringColorList))
    6267
    63 Furthermore the `base color palette` should stored as a resource in the map definition.
    64 To disburden the administrator from having to compute the base colors and add them as a resource manually,   
    65 some code in the TilingService should extract the map colors from the map and layer definitions upon startup.
    66 This method should also be hooked into the code that deletes the tile cache after a change in the map definition.
    67 The correct place to add such code should be discussed further.
    68 
    69 The desired mode '''''UseFillColorPalette''''' should be controlled with a configuration entry in the [TileServiceProperties] section of the serverconfig.ini file.
     68The RenderingService reads the color list from the map object, sorts and uniquifies it, and converts it into a more appropriate Colortype.
     69This color palette is then passed down via the AGGRenderer to the AGGImageIO objects Save method. Here the png color quantification
     70algorithm is included to force the provided palette into the rendered image - this way making sure that the correct base colors survive the compression and/or color quantization. 
    7071
    7172== Implications ==
    72 
    73 No Implications as the additional behaviour is off by default.
     73No Implications are intended as this behaviour is desired by default. We just get better looking maps. The cost of extracting the colors from the in-memory representation of the XML data describing the map are presumed to be negligable.
    7474
    7575== Test Plan ==
    7676
    77 A few different approaches have been suggested above. Testing depends on which one will be chosen. Currently an Australian map showing good
    78 test cases in a certain zoom level is used to verify the algorithm. As the underlying map requires a certain complexity to expose the mapping
    79 error in the color quantization automated testing seems excessively expensive. If the Sheybogan map exposes this problem seems questionable.
     77Currently an Australian map showing good test cases in a certain zoom level is used to verify the algorithm.
     78Since the underlying map requires a certain complexity to expose the mapping error in the color quantization,
     79setting up a unit test seems excessively complex. Any ideas are most welcome.
    8080
    81 However, some tunrime tests should be included. One such runtime test is to check for the existence of `important` colors in the provided color map. This verifies that no base color has been missed in the provided color map.
    82 If similar code is used to incrementally create the color map the only test I can think of is a visual examination of a map with known problems
    83 as any color histogram
     81So far some debugging code has been included to verify the collection of the colors within the rendering service.
     82The success is then evaluated on visually inspecting the map and testing if the base colors made it through using IrfanView.
     83
     84Any suggestions are most welcome.
    8485
    8586== Funding/Resources ==
    8687
    87 Some funding is supposed to be provided by Explore Australia.
     88Some funding is to be provided by Explore Australia.
     89
     90== closed Issues ==
     91
     92No user stored palettes are used in this approach as the colors are defined in the map & layer definitions. The whole idea of providing the colors in an external file has been dropped as its more consistent and also fairly easy to create another version of the map having  other colors defined within.
     93Supplying an user specified color palette to override the colors specified in the map fails at the missing mapping from a linear color list to the complex hierarchical structure of the map definition.
     94
     95== open Issues ==
     96
     97The quantization algorithm uses lots of resources. 3 different memory allocation schemes have been provided. Selecting those is supposedly too specific to warrant a server option entry. However, the correct approach needs to be decided by a system architect with deeper insight into the MapGuide architecture.