Opened 16 years ago
Closed 12 years ago
#743 closed defect (fixed)
AGG Renderer does not properly handle transparency for non-PNG image formats
Reported by: | gingerbbm | Owned by: | |
---|---|---|---|
Priority: | medium | Milestone: | 2.4 |
Component: | Rendering Service | Version: | 2.2.0 |
Severity: | major | Keywords: | |
Cc: | trevorwekel | External ID: |
Description
I wanted to use PNG8 for the map tiling and overlay images, for its obvious advantages over PNG. However I discovered that it doesn't work correctly for overlay images.
I edited serverconfig.ini and ajaxmappane.templ as follows:
\Server\Bin\serverconfig.ini
ImageFormat = PNG8
\WebServerExtensions\www\viewerfiles\ajaxmappane.templ
function RequestMapImage(reqId) { url = webAgent + "?OPERATION=GETDYNAMICMAPOVERLAYIMAGE&FORMAT=PNG8&VERSION... }
The attached image png8_on_png8.png shows a polygon in the overlay image that ought to be translucent. Furthermore, there is no antialiasing on the edges of the polygon. Compare and contrast with the image png_on_png.png.
There has been some discussion about this topic here:
http://n2.nabble.com/PNG-PNG8-question-regarding-overlay-transparency-td1381702.html
The problem has been experienced on the following, running on Windows Server 2003 R2 Service Pack 2 and IIS V6.0:
Attachments (18)
Change History (36)
by , 16 years ago
Attachment: | png8_on_png8.png added |
---|
by , 16 years ago
Attachment: | png_on_png.png added |
---|
comment:1 by , 16 years ago
comment:3 by , 16 years ago
Summary: | PNG8 transparency is not working for GETDYNAMICMAPOVERLAYIMAGE → Support transparency with GETDYNAMICMAPOVERLAYIMAGE in PNG8 format |
---|---|
Type: | defect → enhancement |
changing to enhancement request. gingerbbm, have you tested on 2.1?
comment:4 by , 16 years ago
No. We've been using MGE here so I've not played with the latest MGOS. I can probably find time to try it though.
comment:5 by , 15 years ago
Version: | 2.0.0 |
---|
Removing version from enhancement request. If this enhancement request has been addressed or is no longer required, please close ticket.
comment:6 by , 15 years ago
I have just tested with MG 2.1 and i have the same result. Current png8 format allows only full opacity or full transparency (binary). It does not support semi-transparency (alpha). It would be a great enhancement.
comment:7 by , 15 years ago
Version: | → 2.1.0 |
---|
comment:8 by , 14 years ago
Summary: | Support transparency with GETDYNAMICMAPOVERLAYIMAGE in PNG8 format → PNG8 format doesn't support transparency |
---|---|
Version: | 2.1.0 → 2.2.0 |
confirmed as a problem in 2.2, it affects both tiles and overlays
by , 14 years ago
Attachment: | png8_dynamicoverlay.PNG added |
---|
Dynamic Overlay (PNG8). Note the background color
comment:9 by , 14 years ago
Summary: | PNG8 format doesn't support transparency → AGG Renderer does not properly handle transparency for non-PNG image formats |
---|
As a test I just tried setting the renderer to GD in serverconfig.ini
The PNG8 tiles and overlays produced are transparent.
As another experiment, I tried doing GIF dynamic overlays in both renderers:
- GD produces transparent GIFs
- AGG produces opaque GIFs
So this leads me to believe the AGG renderer is the culprit. Or more specifically the code starting here
Ticket title update to reflect these findings
comment:10 by , 14 years ago
GIF format can only supports binary transparency (one color is 100% transparent).
PNG8 format supports binary transparency but also alpha transparency (ie 50% transparent) as PNG format do
My experiments gave that Mapguide can produce PNG8 and GIF overlay with 100% transparency
But is not able to produce PNG8 with 50% transparency.
What i understand of the code you mention is that PNG8 is processed as GIF without alpha channel.
comment:11 by , 14 years ago
I would change ticket title to : AGG Renderer does not properly handle alpha transparency for PNG8 image formats
comment:12 by , 14 years ago
More sleuthing around reveals the problem here
Running the code down the else condition path (ie. call gdImageTrueColorToPalette() directly regardless). Will produce the correct transparent result for PNG8 and GIF.
Running the code down the other path (ie. A base color palette has been defined) produces the image with an opaque background
So the problem is either in:
AGGImageIO::CreateGdImageWithPalette
or
AGGImageIO::ImageCopyForcePaletteGD
comment:13 by , 14 years ago
Ok, more sleuthing about. It seems the ImageCopyForcePaletteGD() was originally copied from the MapServer source, so I went hunting there and found this possibly related ticket
This related submission for MapServer adds the required support for paletted images with transparency. Since the ImageCopyForcePaletteGD() was originally copied from the MapServer source, the changes in this submission should be simple to port over.
comment:14 by , 13 years ago
Milestone: | → 2.4 |
---|---|
Severity: | minor → major |
Type: | enhancement → defect |
by , 12 years ago
Attachment: | high_quality_png8.patch added |
---|
comment:15 by , 12 years ago
I just worked around this problem. the problem is not only related to the transparency but the image quality in a whole. GD does handle png8 very well ( neither png24 with transparency :) )
I have took some piece of code from Mapserver to fix the problem. For my point of view the png8 output is very great. With Sheboygan i dont see any difference between png24 and png8 except for the size of the image ( 3 to 4 time smaller)
Fix is done on MgDev/Common/Renderers/AGGImageIO.cpp plus a new file mapquantization.cpp ( from mapserver )
Give it a try, i worth the effort Just switch PNG to PNG8 in the ajaxmappane.templ
And therefore there is no reason to keep the selection image in PNG it always should be PNG8
Patch is attached: high_quality_png8.patch
Bruno Scott Geomap
by , 12 years ago
Attachment: | MgRenderers-MGOS24RC2-x64.zip added |
---|
by , 12 years ago
Attachment: | MgRenderers-MGOS24RC2-x86.zip added |
---|
by , 12 years ago
Attachment: | 743_v2.patch added |
---|
v2 of Bruno's patch (includes colors handed down by baseColorPalette parameter)
by , 12 years ago
Attachment: | MgRenderers-MGOS24RC2-x64-v2.zip added |
---|
by , 12 years ago
Attachment: | MgRenderers-MGOS24RC2-x86-v2.zip added |
---|
by , 12 years ago
Attachment: | MgRenderers-MGOS24RC2-x64-v3.zip added |
---|
by , 12 years ago
Attachment: | MgRenderers-MGOS24RC2-x86-v3.zip added |
---|
by , 12 years ago
Attachment: | 743_v3.patch added |
---|
v3 of Bruno's patch (fix incorrect color preservation logic, VS2008 project update)
comment:16 by , 12 years ago
Hi jackie, This patch only works if the resulting palette_scaling_maxval is 255. If the palette_scaling_maxval is lower than 255 we have to scale down all the map palette colors so the resulting png palette will be remap correctly.
palette[i].a = (c.alpha() * (palette_scaling_maxval) + (255) / 2 ) / (255); palette[i].r = (c.red() * (palette_scaling_maxval) + (255) / 2 ) / (255); palette[i].g = (c.green() * (palette_scaling_maxval) + (255) / 2 ) / (255); palette[i].b = (c.blue() * (palette_scaling_maxval) + (255) / 2 ) / (255);
We end up with a palette_scaling_maxval < 255 when we have a lot of colors in the map. Having a aerial picture in the background produce that effect all the times.
Bruno
by , 12 years ago
Attachment: | 743_v4.patch added |
---|
by , 12 years ago
Attachment: | MgRenderers-MGOS24RC2-x86-v4.zip added |
---|
by , 12 years ago
Attachment: | MgRenderers-MGOS24RC2-x64-v4.zip added |
---|
comment:17 by , 12 years ago
Hi Bruno, I've attached v4 of your patch with your suggested line changes.
If there's no problems with this patch and there is no opposition (or response) from Autodesk, I'll land this patch on the weekend for the final release of 2.4
comment:18 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
This behaviour has been observed in Firefox 2 and 3 and IE7.