[ka-Map-users] Ka-map and AGG?

Zak James zak4ms at gmail.com
Fri Mar 7 13:57:56 EST 2008


Sacha,

I don't think the transparent colour needs to be black, and in fact it
would be better to have the php code pick up a configurable color.
That way you could have it antialias against a more suitable
background and avoid the black fuzziness.

zak

On Tue, Mar 4, 2008 at 6:51 PM, Sacha Black <sacha.black at gmail.com> wrote:
> Hi Paul,
>
>  your code works as written (when i tested separately), except that it
>  seems that it might be the subsequent event in tile.php that causes
>  the transparency of a true color + alpha image to be killed :
>
>   imagecopy( $oTile, $oGDImg, 0, 0, $tileLeft, $tileTop, $tileWidth,
>  $tileHeight );
>
>  I found reference in the PHP manual comments for imagecopy to similar problem:
>  http://us3.php.net/manual/en/function.imagecopy.php  (scroll down to
>  see somments)
>
>  so I wasn't sure what a full solution would be. I did find that this
>  works (sort of):
>
>  tile.php (around line 313) :
>
>  if ($useAlphaCh) {
>       imageAlphaBlending($oTile, false);
>
>       imagefill($oTile, 0, 0, imagecolorallocatealpha($oTile, 0, 0, 0, 127));
>       imageSaveAlpha($oTile, true);
>  }
>   $nTransparent = imagecolorallocate($oTile, 0, 0, 0);   //////
>  added these 2 lines
>  imagecolortransparent( $oTile,$nTransparent);            //////    to
>  kill black background
>  imagecopy( $oTile, $oGDImg, 0, 0, $tileLeft, $tileTop, $tileWidth,
>  $tileHeight );
>
>  but this is not a great/perfect fix:
>
>  - it preserves the rendering but it also causes black pixels in the
>  map tiles to go transparent. (because index transparency is covering
>  when alpha transparency fails to black in the imagecopy).
>  - overlay layers that are mostly transparent fare worse because the
>  remaining features will have a dark fuzzy outline due to the effects
>  of antialiasing. (so these types of overlay layers should stick with
>  regular 8bit png).
>
>  maybe someone else has a better idea how to work around the RGBA and
>  imagecopy() issue?
>
>  Sacha
>
>
>
>
>
>  On Tue, Mar 4, 2008 at 6:13 AM, Paul Spencer <pspencer at dmsolutions.ca> wrote:
>
>  > I think there is a small issue in tile.php, we need to change the
>  >  following block around line 313:
>  >
>  >  if ($useAlphaCh) {
>  >    ImageAlphaBlending($oTile, false);
>  >    imagesavealpha($oTile, true);
>  >  }
>  >
>  >  to:
>  >
>  >  if ($useAlphaCh) {
>  >    imagefill($oTile, 0, 0, imagecolorallocatealpha($oTile, 0, 0, 0,
>  >  127));
>  >    ImageAlphaBlending($oTile, false);
>  >    imagesavealpha($oTile, true);
>  >  }
>  >
>  >  Note the addition of the imagefill - this is critical to making the
>  >  tiles come out transparent.  I'm pretty sure this works.  What I don't
>  >  know is what happens if you replace the color black (0,0,0) with the
>  >  map's background color ($oMap->imagecolor->red, $oMap->imagecolor-
>  >   >green, $oMap->imagecolor->blue).
>  >
>  >  If someone could test this and confirm it works, we can commit
>  >  tile.php with the change.
>  >
>  >  Cheers
>  >
>  >  Paul
>  >
>  >
>  >
>  >  On 4-Mar-08, at 2:32 AM, Sacha Black wrote:
>  >
>  >  > Hi Hans,
>  >  >
>  >  > I reproduced your error. :(  in ms4w 2.2.7
>  >  >
>  >  > Maybe I missed this before because I was just testing with gmap, and
>  >  > my bounds didn't go outside the edge of the base data. The AGGA
>  >  > rendering looks good like you say, and that's what I saw, but with
>  >  > black outside the base data.
>  >  >
>  >  > But I don't know why it's happening. I added TRANSPARENT ON to the
>  >  > OUTPUTFORMAT and it made no difference like this:
>  >  >
>  >  > OUTPUTFORMAT
>  >  > NAME 'AGGA'
>  >  > DRIVER AGG/PNG
>  >  > IMAGEMODE RGBA
>  >  > TRANSPARENT ON ////// <- no difference with this ?
>  >  > END
>  >  >
>  >  > Also tried to add  TRANSPARENCY alpha to all the layers, and no
>  >  > change.
>  >  >
>  >  > it seems that when the tiles get created from the RGBA pngs, they are
>  >  > losing the transparency. I'm not sure where this is happening. We
>  >  > can't change the $GLOBALS['szImageCreateFunction'] back to
>  >  > "imagecreate" from "imagecreatetruecolor"because this will create an
>  >  > 8bit PNG tile, and you will lose the extra colors in the downgrade.
>  >  > Although appaently the 8 bit PNG has no problem with retaining
>  >  > transparency.....
>  >  >
>  >  >> From your example attachment it looks like maybe your overlays will
>  >  > suffice with just AGG ? did you try it:
>  >  >
>  >  > OUTPUTFORMAT
>  >  > NAME 'AGG'
>  >  > DRIVER AGG/PNG
>  >  > IMAGEMODE RGB
>  >  > END
>  >  >
>  >  > The tiles will be smaller in size and transparency is retained in my
>  >  > tests. It's not a real solution, but it might help your situation
>  >  > while we figure out why AGGA is not right.
>  >  >
>  >  > Sacha
>  >  >
>  >  >
>  >  > On Mon, Mar 3, 2008 at 10:59 AM, Hans Castorp
>  >  > <hanscastorp76 at yahoo.es> wrote:
>  >  >> Hi Lorenzo,
>  >  >>
>  >  >> Yes, I have created OUTPUTFORMAT AGGA in my mapfile.
>  >  >>
>  >  >> I you refer to put METADATA imageformat "agga", yes I did it.
>  >  >> Despite of it,
>  >  >> reading th documentation, only values accepted for imageformat are:
>  >  >> "imageformat" [DITHERED|PNG24|PNG|JPEG|GIF]
>  >  >>
>  >  >> And yes, I'm using MS4W...
>  >  >>
>  >  >> -----Mensaje original-----
>  >  >> De: Lorenzo Becchi [mailto:lorenzo at ominiverdi.com]
>  >  >> Enviado el: lunes, 03 de marzo de 2008 19:51
>  >  >> Para: Hans Castorp
>  >  >> CC: 'Sacha Black'; ka-map-users at lists.maptools.org
>  >  >>
>  >  >>
>  >  >> Asunto: Re: [ka-Map-users] Ka-map and AGG?
>  >  >>
>  >  >> Hans,
>  >  >> have you created the OUTPUTFORMAT AGGA in your mapfile?
>  >  >> have you put MEDATA format "AGGA" to your layer's metadata?
>  >  >>
>  >  >>
>  >  >> another problem could be that it seems you're using MS4W.
>  >  >> I've tested on Mac OS X and I guess Sacha did it in Linux. Am I
>  >  >> wrong?
>  >  >> hopefully, I am
>  >  >>
>  >  >> ciao
>  >  >> Lorenzo
>  >  >>
>  >  >>
>  >  >>
>  >  >> Hans Castorp wrote:
>  >  >>> Hi,
>  >  >>>
>  >  >>> Using your configuration my transparent layers are rendered with
>  >  >>> Black
>  >  >>> background (as you can see in the attachment)... First time I see
>  >  >>> it...
>  >  >>>
>  >  >>> I was suffering several troubles trying to achieve a good agg
>  >  >>> redering.
>  >  >> With
>  >  >>> your configuration all seems to work fine but this "little"
>  >  >>> trouble :) All
>  >  >> I
>  >  >>> have to do is change this black background into transparent...
>  >  >>>
>  >  >>> Only a couple of questions:
>  >  >>>
>  >  >>> I am using IMAGETYPE AGGA in my map section, is it right???
>  >  >>>
>  >  >>>
>  >  >>> I am also using 'format' =>'AGGA' in my config.php file:
>  >  >>>
>  >  >>> $aszGMap = array (
>  >  >>>         'title' => 'gmap',
>  >  >>>         'path' => 'C:/ms4w/apps/ka-m1.0/mapdata/xxx/xxx.map',
>  >  >>>         'scales' => array( 200000, 150000, 100000, 50000, 25000 ,
>  >  >>> 10000,
>  >  >>> 5000 ),
>  >  >>>         'format' =>'AGGA'
>  >  >>> );
>  >  >>>
>  >  >>> Is it right too?
>  >  >>>
>  >  >>> Thanks in advance.
>  >  >>>
>  >  >>>
>  >  >>>
>  >  >>>
>  >  >>>
>  >  >>> -----Mensaje original-----
>  >  >>> De: Sacha Black [mailto:sacha.black at gmail.com]
>  >  >>> Enviado el: lunes, 03 de marzo de 2008 18:09
>  >  >>> Para: Hans Castorp
>  >  >>> CC: Lorenzo Becchi; ka-map-users at lists.maptools.org
>  >  >>> Asunto: Re: [ka-Map-users] Ka-map and AGG?
>  >  >>>
>  >  >>> Hans,
>  >  >>>
>  >  >>> The corrections I made for Lorenzo are only typos.....
>  >  >>>
>  >  >>> check to see if your OUTPUFORMAT settings are like this (or else
>  >  >>> they
>  >  >>> will not match the settings in config.php):
>  >  >>>
>  >  >>> OUTPUTFORMAT
>  >  >>> NAME 'AGG'
>  >  >>> DRIVER AGG/PNG
>  >  >>> IMAGEMODE RGB
>  >  >>> END
>  >  >>>
>  >  >>> OUTPUTFORMAT
>  >  >>> NAME 'AGGA'
>  >  >>> DRIVER AGG/PNG
>  >  >>> IMAGEMODE RGBA
>  >  >>> END
>  >  >>>
>  >  >>> OUTPUTFORMAT
>  >  >>>   NAME 'AGG_JPEG'
>  >  >>>   DRIVER AGG/JPEG
>  >  >>>   IMAGEMODE RGB
>  >  >>> END
>  >  >>>
>  >  >>> Sacha
>  >  >>>
>  >  >>>
>  >  >>>
>  >  >>> On Mon, Mar 3, 2008 at 12:51 AM, Hans Castorp <hanscastorp76 at yahoo.es
>  >  >>> >
>  >  >>> wrote:
>  >  >>>
>  >  >>>> Making these 2 changes, my map looses transparency and all layers
>  >  >>>> are
>  >  >>>>
>  >  >>> drawn
>  >  >>>
>  >  >>>> with black background...
>  >  >>>>
>  >  >>>>
>  >  >>>> -----Mensaje original-----
>  >  >>>> De: ka-map-users-bounces at lists.maptools.org
>  >  >>>> [mailto:ka-map-users-bounces at lists.maptools.org] En nombre de
>  >  >>>> Lorenzo
>  >  >>>>
>  >  >>> Becchi
>  >  >>>
>  >  >>>> Enviado el: viernes, 29 de febrero de 2008 22:54
>  >  >>>> Para: Sacha Black
>  >  >>>> CC: ka-map-users at lists.maptools.org
>  >  >>>> Asunto: Re: [ka-Map-users] Ka-map and AGG?
>  >  >>>>
>  >  >>>>
>  >  >>>>
>  >  >>>> lovely, thanks
>  >  >>>> :-)
>  >  >>>>
>  >  >>>> I've updated CVS
>  >  >>>>
>  >  >>>> Lorenzo
>  >  >>>>
>  >  >>>>
>  >  >>>>
>  >  >>>>
>  >  >>>> Sacha Black wrote:
>  >  >>>>> Hi Lorenzo,
>  >  >>>>>
>  >  >>>>> I've tested what you sent, and there are two corrections (see the
>  >  >>>>> ////// comments below):
>  >  >>>>>
>  >  >>>>> case "AGGA":
>  >  >>>>>  $GLOBALS['szMapImageFormat'] = 'AGGA';
>  >  >>>>>  $GLOBALS['szMapImageCreateFunction'] = "imagecreatefrompng";
>  >  >>>>>  $GLOBALS['szImageExtension'] = '.png';
>  >  >>>>>  $GLOBALS['szImageCreateFunction'] =
>  >  >>>>> "imagecreatetruecolor";    /////
>  >  >>>>> <-- not 'imagecreate'
>  >  >>>>>  $GLOBALS['szImageOutputFunction'] = "imagepng";
>  >  >>>>>  $GLOBALS['szImageHeader'] = 'image/png';
>  >  >>>>> break;
>  >  >>>>>
>  >  >>>>> case "AGG_JPEG":
>  >  >>>>>  $GLOBALS['szMapImageFormat'] = 'JPEG';
>  >  >>>>>  $GLOBALS['szMapImageCreateFunction'] = "imagecreatefromjpeg";
>  >  >>>>>  $GLOBALS['szImageExtension'] = '.jpg';
>  >  >>>>>  $GLOBALS['szImageCreateFunction'] = "imagecreatetruecolor";
>  >  >>>>>  $GLOBALS['szImageOutputFunction'] = "imagejpeg";   ///// <-- not
>  >  >>>> 'imagejpg'
>  >  >>>>>  $GLOBALS['szImageHeader'] = 'image/jpeg';
>  >  >>>>> break;
>  >  >>>>>
>  >  >>>>> With these 2 corrections, everything works as expected.
>  >  >>>>>
>  >  >>>>> thanks,
>  >  >>>>>
>  >  >>>>> Sacha
>  >  >>>>>
>  >  >>>>>
>  >  >>>>> On Sun, Feb 24, 2008 at 1:07 PM, Lorenzo Becchi
>  >  >>>>
>  >  >>> <lorenzo at ominiverdi.com>
>  >  >>>
>  >  >>>> wrote:
>  >  >>>>>
>  >  >>>>>
>  >  >>>>>> Hi Sasha,
>  >  >>>>>> it seems to me it should work.
>  >  >>>>>>
>  >  >>>>>> I've set the outputformats as suggested by this page:
>  >  >>>>>> http://mapserver.gis.umn.edu/docs/howto/agg-rendering-specifics
>  >  >>>>>>
>  >  >>>>>> then I've set LAYER's METADATA
>  >  >>>>>>    imageformat "AGGA"
>  >  >>>>>>
>  >  >>>>>> seems to me, it didn't worked until I've not changed config.php
>  >  >>>>>> with
>  >  >>>>>> this lines:
>  >  >>>>>>
>  >  >>>>>>        case "AGG":
>  >  >>>>>>            $GLOBALS['szMapImageFormat'] = 'PNG';
>  >  >>>>>>            $GLOBALS['szMapImageCreateFunction'] =
>  >  >>>>
>  >  >>> "imagecreatefrompng";
>  >  >>>
>  >  >>>>>>            $GLOBALS['szImageExtension'] = '.png';
>  >  >>>>>>            $GLOBALS['szImageCreateFunction'] = "imagecreate";
>  >  >>>>>>            $GLOBALS['szImageOutputFunction'] = "imagepng";
>  >  >>>>>>            $GLOBALS['szImageHeader'] = 'image/png';
>  >  >>>>>>            break;
>  >  >>>>>>        case "AGGA":
>  >  >>>>>>            $GLOBALS['szMapImageFormat'] = 'AGGA';
>  >  >>>>>>            $GLOBALS['szMapImageCreateFunction'] =
>  >  >>>>
>  >  >>> "imagecreatefrompng";
>  >  >>>
>  >  >>>>>>            $GLOBALS['szImageExtension'] = '.png';
>  >  >>>>>>            $GLOBALS['szImageCreateFunction'] = "imagecreate";
>  >  >>>>>>            $GLOBALS['szImageOutputFunction'] = "imagepng";
>  >  >>>>>>            $GLOBALS['szImageHeader'] = 'image/png';
>  >  >>>>>>            break;
>  >  >>>>>>        case "AGG_JPEG":
>  >  >>>>>>            $GLOBALS['szMapImageFormat'] = 'JPEG';
>  >  >>>>>>            $GLOBALS['szMapImageCreateFunction'] =
>  >  >>>>
>  >  >>> "imagecreatefromjpeg";
>  >  >>>
>  >  >>>>>>            $GLOBALS['szImageExtension'] = '.jpg';
>  >  >>>>>>            $GLOBALS['szImageCreateFunction'] =
>  >  >>>>
>  >  >>> "imagecreatetruecolor";
>  >  >>>
>  >  >>>>>>            $GLOBALS['szImageOutputFunction'] = "imagejpg";
>  >  >>>>>>            $GLOBALS['szImageHeader'] = 'image/jpeg';
>  >  >>>>>>            break;
>  >  >>>>>>
>  >  >>>>>>
>  >  >>>>>> I've tested only
>  >  >>>>>> AGGA
>  >  >>>>>>
>  >  >>>>>> can you please do some more tests?
>  >  >>>>>>
>  >  >>>>>> once confirmed I'll post changes on CVS
>  >  >>>>>>
>  >  >>>>>> thanks
>  >  >>>>>> Lorenzo
>  >  >>>>>>
>  >  >>>>>>
>  >  >>>>>>
>  >  >>>> _______________________________________________
>  >  >>>> ka-Map-users mailing list
>  >  >>>> ka-Map-users at lists.maptools.org
>  >  >>>> http://lists.maptools.org/mailman/listinfo/ka-map-users
>  >  >>>>
>  >  >>>> No virus found in this incoming message.
>  >  >>>> Checked by AVG Free Edition.
>  >  >>>> Version: 7.5.516 / Virus Database: 269.21.3/1307 - Release Date:
>  >  >>>>
>  >  >>> 02/03/2008
>  >  >>>
>  >  >>>> 15:59
>  >  >>>>
>  >  >>>>
>  >  >>>> No virus found in this outgoing message.
>  >  >>>> Checked by AVG Free Edition.
>  >  >>>> Version: 7.5.516 / Virus Database: 269.21.3/1307 - Release Date:
>  >  >>>>
>  >  >>> 02/03/2008
>  >  >>>
>  >  >>>> 15:59
>  >  >>>>
>  >  >>>>
>  >  >>>>
>  >  >>>>
>  >  >>>>
>  >  >>>
>  >  >>> No virus found in this incoming message.
>  >  >>> Checked by AVG Free Edition.
>  >  >>> Version: 7.5.516 / Virus Database: 269.21.3/1307 - Release Date:
>  >  >> 02/03/2008
>  >  >>> 15:59
>  >  >>>
>  >  >>>
>  >  >>> No virus found in this outgoing message.
>  >  >>> Checked by AVG Free Edition.
>  >  >>> Version: 7.5.516 / Virus Database: 269.21.3/1307 - Release Date:
>  >  >> 02/03/2008
>  >  >>> 15:59
>  >  >>>
>  >  >>>
>  >  >>>
>  >  >>>
>  >  >>> ------------------------------------------------------------------------
>  >  >>>
>  >  >>
>  >  >> No virus found in this incoming message.
>  >  >> Checked by AVG Free Edition.
>  >  >> Version: 7.5.516 / Virus Database: 269.21.3/1307 - Release Date:
>  >  >> 02/03/2008
>  >  >> 15:59
>  >  >>
>  >  >>
>  >  >> No virus found in this outgoing message.
>  >  >> Checked by AVG Free Edition.
>  >  >> Version: 7.5.516 / Virus Database: 269.21.3/1307 - Release Date:
>  >  >> 02/03/2008
>  >  >> 15:59
>  >  >>
>  >  >>
>  >  >>
>  >  >>
>  >  > _______________________________________________
>  >  > ka-Map-users mailing list
>  >  > ka-Map-users at lists.maptools.org
>  >  > http://lists.maptools.org/mailman/listinfo/ka-map-users
>  >
>  >
>  >  __________________________________________
>  >
>  >     Paul Spencer
>  >     Chief Technology Officer
>  >     DM Solutions Group Inc
>  >     http://www.dmsolutions.ca/
>  >
>  >
>  _______________________________________________
>  ka-Map-users mailing list
>  ka-Map-users at lists.maptools.org
>  http://lists.maptools.org/mailman/listinfo/ka-map-users
>



-- 
Zak James
Applications and Software Development
DM Solutions Group Inc.
http://www.dmsolutions.ca


More information about the ka-Map-users mailing list