Opened 9 years ago

Closed 5 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)

png8_on_png8.png (30.3 KB) - added by gingerbbm 9 years ago.
png_on_png.png (39.4 KB) - added by gingerbbm 9 years ago.
png_dynamicoverlay.PNG (69.4 KB) - added by jng 7 years ago.
Dynamic Overlay (PNG)
png8_dynamicoverlay.PNG (47.9 KB) - added by jng 7 years ago.
Dynamic Overlay (PNG8). Note the background color
png_tiles.PNG (76.1 KB) - added by jng 7 years ago.
Tiles (PNG)
png8_tiles.PNG (57.3 KB) - added by jng 7 years ago.
Tiles (PNG8). Note the background
high_quality_png8.patch (37.2 KB) - added by bscott 5 years ago.
MgRenderers-MGOS24RC2-x64.zip (881.0 KB) - added by jng 5 years ago.
MgRenderers-MGOS24RC2-x86.zip (782.3 KB) - added by jng 5 years ago.
743_v2.patch (44.8 KB) - added by jng 5 years ago.
v2 of Bruno's patch (includes colors handed down by baseColorPalette parameter)
MgRenderers-MGOS24RC2-x64-v2.zip (881.1 KB) - added by jng 5 years ago.
MgRenderers-MGOS24RC2-x86-v2.zip (782.6 KB) - added by jng 5 years ago.
MgRenderers-MGOS24RC2-x64-v3.zip (881.2 KB) - added by jng 5 years ago.
MgRenderers-MGOS24RC2-x86-v3.zip (782.8 KB) - added by jng 5 years ago.
743_v3.patch (45.9 KB) - added by jng 5 years ago.
v3 of Bruno's patch (fix incorrect color preservation logic, VS2008 project update)
743_v4.patch (46.3 KB) - added by jng 5 years ago.
MgRenderers-MGOS24RC2-x86-v4.zip (782.6 KB) - added by jng 5 years ago.
MgRenderers-MGOS24RC2-x64-v4.zip (881.2 KB) - added by jng 5 years ago.

Change History (36)

Changed 9 years ago by gingerbbm

Attachment: png8_on_png8.png added

Changed 9 years ago by gingerbbm

Attachment: png_on_png.png added

comment:1 Changed 9 years ago by gingerbbm

This behaviour has been observed in Firefox 2 and 3 and IE7.

comment:2 Changed 9 years ago by tomfukushima

Cc: trevorwekel added

CC'ng Trevor because he probably has info on this.

comment:3 Changed 9 years ago by jbirch

Summary: PNG8 transparency is not working for GETDYNAMICMAPOVERLAYIMAGESupport transparency with GETDYNAMICMAPOVERLAYIMAGE in PNG8 format
Type: defectenhancement

changing to enhancement request. gingerbbm, have you tested on 2.1?

comment:4 Changed 9 years ago by gingerbbm

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 Changed 8 years ago by jbirch

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 Changed 8 years ago by lgnemmi

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 Changed 8 years ago by lgnemmi

Version: 2.1.0

comment:8 Changed 7 years ago by zspitzer

Summary: Support transparency with GETDYNAMICMAPOVERLAYIMAGE in PNG8 formatPNG8 format doesn't support transparency
Version: 2.1.02.2.0

confirmed as a problem in 2.2, it affects both tiles and overlays

Changed 7 years ago by jng

Attachment: png_dynamicoverlay.PNG added

Dynamic Overlay (PNG)

Changed 7 years ago by jng

Attachment: png8_dynamicoverlay.PNG added

Dynamic Overlay (PNG8). Note the background color

Changed 7 years ago by jng

Attachment: png_tiles.PNG added

Tiles (PNG)

Changed 7 years ago by jng

Attachment: png8_tiles.PNG added

Tiles (PNG8). Note the background

comment:9 Changed 7 years ago by jng

Summary: PNG8 format doesn't support transparencyAGG 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 Changed 7 years ago by lgnemmi

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 Changed 7 years ago by lgnemmi

I would change ticket title to : AGG Renderer does not properly handle alpha transparency for PNG8 image formats

comment:12 Changed 7 years ago by jng

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 Changed 7 years ago by jng

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 Changed 6 years ago by zspitzer

Milestone: 2.4
Severity: minormajor
Type: enhancementdefect

Changed 5 years ago by bscott

Attachment: high_quality_png8.patch added

comment:15 Changed 5 years ago by bscott

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

Changed 5 years ago by jng

Changed 5 years ago by jng

Changed 5 years ago by jng

Attachment: 743_v2.patch added

v2 of Bruno's patch (includes colors handed down by baseColorPalette parameter)

Changed 5 years ago by jng

Changed 5 years ago by jng

Changed 5 years ago by jng

Changed 5 years ago by jng

Changed 5 years ago by jng

Attachment: 743_v3.patch added

v3 of Bruno's patch (fix incorrect color preservation logic, VS2008 project update)

comment:16 Changed 5 years ago by bscott

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

Changed 5 years ago by jng

Attachment: 743_v4.patch added

Changed 5 years ago by jng

Changed 5 years ago by jng

comment:17 Changed 5 years ago by jng

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 Changed 5 years ago by jng

Resolution: fixed
Status: newclosed

Fixed 2.4 (r7079) and trunk (r7080)

Note: See TracTickets for help on using tickets.