[mapserver-dev] Using mapserver.a to generate tiles

thomas bonfort thomas.bonfort at gmail.com
Thu Aug 26 01:47:52 EDT 2010


Steve,

RGBA quantization code directly writes to a png stream, so the gdImg
you're getting back isn't the actual quantized one.

I'd do something in the likes of:

msAlphaAGG2GD(img);

//chop img into tiles with msImageCopyMerge

foreach tile:
  // create gdIOCtx for filename
  msImageSaveImageRgbaQuantized(tileImg,ctx,format);



Plus, this way you quantize each tile with it's own palette which will
give you better results

hope this helps,
thomas

On Thu, Aug 26, 2010 at 05:05, Stephen Woodbridge
<woodbri at swoodbridge.com> wrote:
> Hi all,
>
> I guess these questions might be targeted at Steve L and/or Thomas Bonfort,
> but I'll take info from anyone that might know.
>
> I have written a C program that uses mapserver.a and generates tiles for
> seeding a tile cache. It works great with GD and AGG rendering when I
> quantize the output images as 8-bit png images that can be transparent or
> not.
>
> I have run into two problems:
>
> Rendering transparent overlays with AGG and then palettizing the image
> leaves dark pixels along the lines as an artifact of the anti aliasing and
> the palettization. But I can chop these meta tiles into tiles with no
> problems.
>
> If I try to generate RGBA tiles, these artifacts are not seen in the meta
> tile if I leave the image as RGBA, but when I chop the metatile into tiles
> the background is no longer transparent (I'm guessing it is RGB and not
> RGBA.
>
> The code makes calls like these:
>
> // read the mapfile, and setup the layers, extents, outputformat, then
> oImg = msDrawMap(map, MS_FALSE);
>
> // save the image to force color reduction
> // for the RGBA case ie: not palettized
> // this appears to change  buffer_format = 7 to buffer_format = 1
> ret = msSaveImage(NULL, oImg, szMetaImg);
>
> // we cycle through the rows, cols of the metatile write the tiles
> oTile = msImageCreateGD(tileWidth, tileHeight, oImg->format, NULL, NULL,
> map->resolution, map->defresolution);
>
> msImageCopyMerge(oTile, oImg, 0, 0, tileLeft, tileTop, tileWidth,
> tileHeight, 100);
>
> ret = msSaveImage(NULL, oTile, qtp);
> msFreeImage(oTile);
>
>
> So, I'm guessing that the change in buffer_format is somehow affecting the
> behavior of msImageCreateGD() or msImageCopyMerge() that is affecting the
> alpha transparency when I create the tiles. Can anyone shed some light on
> that and how I might work around that.
>
> Second, since the RGBA tile issue was an attempt to work around the dark
> speck artifacts on the anti aliased lines that get palleted, any thoughts on
> how to remove the specks.
>
> Third, but less important at the moment, I am aware this all changes in 6.0
> and I am curious about what happens when the GD code is removed. But I can
> probably wait till that is in trunk and go digging after that.
>
> My mapfile looks like the following. I have tried various combinations of
> options on the various OUTPUTFORMATs.
>
> -Steve W
>
> MAP
>  NAME "Statesp020"
>  EXTENT -19941038.1 1999506.7 20013931.8 11539767.3
>  SIZE 700 550
>  SHAPEPATH "/u/data/flytecomm/gisdata/"
>  #SYMBOLSET "/u/data/maps/symbols/symbols.sym"
>  #FONTSET "/u/data/maps/fontset.txt"
>  IMAGECOLOR 0 0 0
> # IMAGETYPE 'agg_qn' # this leaves artifacts along the lines
> # IMAGETYPE 'PNG8'   # no artifacts but lines are not anti aliased
> # IMAGETYPE 'agg_32png' # metatile is ok, tiles have black bgcolor
>  IMAGETYPE 'agg_32png' # tile are not transparent
>  TRANSPARENT ON
>  UNITS METERS
> #  DEBUG 5
> #  CONFIG MS_EEORFILE "stderr"
>
>  OUTPUTFORMAT
>    NAME "agg_qn"
>    DRIVER "AGG/PNG"
>    EXTENSION "png"
>    MIMETYPE "image/png"
>    IMAGEMODE RGBA
>    TRANSPARENT ON
>    FORMATOPTION "INTERLACE=false"
>    FORMATOPTION "QUANTIZE_NEW=ON"
>    FORMATOPTION "QUANTIZE_FORCE=ON"
>    FORMATOPTION "QUANTIZE_DITHER=OFF"
>    FORMATOPTION "QUANTIZE_COLORS=256"
>    FORMATOPTION "TRANSPARENT=ON"
>  END
>
>  OUTPUTFORMAT
>    NAME "agg_32png"
>    DRIVER "AGG/PNG"
>    EXTENSION "png"
>    MIMETYPE "image/png"
>    IMAGEMODE RGBA
>    TRANSPARENT ON                # comment or not does not help
>    FORMATOPTION "INTERLACE=OFF"
>    FORMATOPTION "TRANSPARENT=ON" # comment or not does not help
>  END
>
>  OUTPUTFORMAT
>    NAME PNG8
>    DRIVER "GD/PNG"
>    EXTENSION "png"
>    MIMETYPE "image/png"
>    IMAGEMODE RGBA
>    TRANSPARENT ON
>    FORMATOPTION "INTERLACE=false"
>    FORMATOPTION "QUANTIZE_NEW=ON"
>    FORMATOPTION "QUANTIZE_FORCE=ON"
>    FORMATOPTION "QUANTIZE_DITHER=OFF"
>    FORMATOPTION "QUANTIZE_COLORS=256"
>    FORMATOPTION "TRANSPARENT=ON"
>  END
>
> #  PROJECTION
> #    # Sperical Mercator
> #    "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0
> +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs"
> #  END
>
>  SYMBOL
>    NAME 'circle'
>    TYPE ELLIPSE
>    POINTS 1 1 END
>    FILLED true
>  END
>
>  LAYER
>    NAME "states"
>    TYPE POLYGON
>    STATUS DEFAULT
>    TRANSPARENCY ALPHA
>    DATA "states/statesp020-900913"
>    CLASS
>      STYLE
>        WIDTH 1.0
>        #SIZE 3.0
>        #SYMBOL 'circle'
>        #COLOR "#b5d29c"
>        OUTLINECOLOR "#88ff88"
>      END
>    END
>  END
>
> END
> _______________________________________________
> mapserver-dev mailing list
> mapserver-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-dev
>


More information about the mapserver-dev mailing list