Changes between Version 5 and Version 6 of MapGuideRfc60
- Timestamp:
- 03/24/09 06:11:35 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
MapGuideRfc60
v5 v6 25 25 26 26 The 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 filethe visual appearance of the map can be significantly improved.27 By providing the base colors of the map as a palette to the image renderer the visual appearance of the map can be significantly improved. 28 28 29 29 == Motivation == 30 30 31 31 The 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 visibleto the human eye.32 The 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. 33 Therefore adjacent map tiles might use different colors for map areas crossing tile boundaries. This is very obvious and disturbing to the human eye. 34 34 35 35 Ticket #813 PNG8 Compression isn't preserving fill colors … … 37 37 == Proposed Solution == 38 38 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.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 the resulting map can be significantly improved. 40 This can be done by using the median-cut algorithm as used in the mapserver code base in the function `msImageCopyForcePaletteGD`. 41 41 42 42 {{{ … … 53 53 */ 54 54 static 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 57 gdImagePtr CreateGdImageWithPalette( gdImagePtr img24, RSCOLORLIST* baseColorPalette, int sx, int sy) 56 58 }}} 57 59 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 == 60 61 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). 62 The interesting task is how to feed the base colors of the map to the Image Renderer making the image. 63 The base colors of a map can be extracted most efficiently during map generation in MapingUtil::StylizeLayers(). 64 To do this the VectorLayerDefiniton gets an additional method called VectorLayerDefiniton::ComputeUsedColors(scaleRange). 65 At 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)) 62 67 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. 68 The RenderingService reads the color list from the map object, sorts and uniquifies it, and converts it into a more appropriate Colortype. 69 This color palette is then passed down via the AGGRenderer to the AGGImageIO objects Save method. Here the png color quantification 70 algorithm 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. 70 71 71 72 == Implications == 72 73 No Implications as the additional behaviour is off by default. 73 No 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. 74 74 75 75 == Test Plan == 76 76 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. 77 Currently an Australian map showing good test cases in a certain zoom level is used to verify the algorithm. 78 Since the underlying map requires a certain complexity to expose the mapping error in the color quantization, 79 setting up a unit test seems excessively complex. Any ideas are most welcome. 80 80 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 81 So far some debugging code has been included to verify the collection of the colors within the rendering service. 82 The success is then evaluated on visually inspecting the map and testing if the base colors made it through using IrfanView. 83 84 Any suggestions are most welcome. 84 85 85 86 == Funding/Resources == 86 87 87 Some funding is supposed to be provided by Explore Australia. 88 Some funding is to be provided by Explore Australia. 89 90 == closed Issues == 91 92 No 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. 93 Supplying 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 97 The 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.