Opened 19 years ago

Closed 19 years ago

Last modified 19 years ago

#1231 closed defect (fixed)

Transparency and 24 bits PNG output

Reported by: marc.jacquin@… Owned by: warmerdam
Priority: high Milestone:
Component: MapServer C Library Version: 4.4
Severity: normal Keywords:
Cc:

Description

8 bits PNG with Transparency set in the map file is OK. But using the default 
PNG24 output does not produce transparency.
PNG24 does not produce 24 bits PNG but 8 bits PNG instead.

Fix guideline : in mapoutput.c

#if defined(USE_GD_PNG) && GD2_VERS > 1
    if( strcasecmp(driver,"GD/PNG24") == 0 )
    {
        format = msAllocOutputFormat( map, "png24", "GD/PNG" );
        format->mimetype = strdup("image/png24"); // MJ : because mimetype is 
used to define output format later on
        format->imagemode = MS_IMAGEMODE_RGB;
        format->extension = strdup("png");
        format->renderer = MS_RENDER_WITH_GD;
	format->bands = 3;
	format->transparent = map->transparent; // MJ for transparency 
    }
#endif /* USE_GD_PNG */

Marc

Change History (8)

comment:1 by sdlime, 19 years ago

Cc: warmerdam@… added

comment:2 by fwarmerdam, 19 years ago

Randy,

Note that a 24bit PNG file with transparency is really a 32bit PNG file
operating in RGBA mode.  

So, setting transparent true and mode to MS_IMAGEMODE_RGB is a conflict.  
msOutputFormatValidate() will actually fix this up by promoting the type
to MS_IMAGEMODE_RGBA - but we shouldn't depend on that. 

Also, I don't like the idea of setting the transparent flag based on 
map->transparent.  I will note that if you actually use PNG24 in a map 
with transparent set on, the msApplyOutputFormat() function should create 
a new 32bit outputformat similiar to PNG24 with the transparent flag set 
on and the mode set to RGBA.  

On the issue of mime type, is image/png24 a well known mime type?  We don't
want to start returning stuff with arbitrary new mimetypes by default if 
we can avoid it.  Perhaps you could explain the situation where you need
this in more detail.  Is it for when WMS requests set the format by mime
type?  If so, I think there is a syntax for adding parameters to a mimetype
that is more appropriate.  Something like "image/png;bits=24" or something
like that.  I would need to do some digging to find the details.  The 
advantage of using the particular syntax is that browers still use the
handler for image/png, but when selecting a WMS FORMAT you can distinguish
between variations. 

Steve ... if you want, you can assign this one to me, and put yourself in 
the cc list. 



comment:3 by sdlime, 19 years ago

Cc: steve.lime@… added; warmerdam@… removed
Owner: changed from sdlime to fwarmerdam
Reassigning to Frank...

comment:4 by fwarmerdam, 19 years ago

Resolution: fixed
Status: newclosed
I have changed the 24bit mime type to "image/png; mode=24bit".  This should
allow it to be selected independently from the 8bit png type. 

comment:5 by fwarmerdam, 19 years ago

I should add the change was only made in 4.5.  I'm a little leery about 
backporting it into 4.4.2 but the change is certainly small.  Anyone else
have an opinion?

comment:6 by sdlime, 19 years ago

Assuming it works in 4.5 this seems ok to me to move to 4.4.2. This bug had to 
topics, transparency and mime-type. Is the transparency issue still out there?

Steve

comment:7 by fwarmerdam, 19 years ago

Marc suggested making png24 support an alpha layer, but that would really 
make it png32. I'm not terribly opposed to *adding* a png32 but I don't 
think it should replace png24.  

So, in short, I don't think that the suggested change for transparency is
a good idea.  

The user always has the option of declaring a 32bit output format in their
map file with transparency enabled. 

I will backport the mimetype change to 4.4.2. 

comment:8 by dmorissette, 19 years ago

This change broke the writeOutputformatobject() in mapfile.c: the space in the
"image/png; mode=24bit" value confuses the parser.

I'll add quotes around all string values in writeOutputformatobject() and
backport to 4.4.x
Note: See TracTickets for help on using tickets.