[mapserver-dev] Need help chopping Image into tiles using mapserver C code

Stephen Woodbridge woodbri at swoodbridge.com
Wed Sep 23 19:02:44 EDT 2009


Hi all,

I'm writing some C code using Mapserver to generate an image and then 
chop it into tiles and save the tiles. The basic flow is like:


    oImg = msDrawMap(map, MS_FALSE);
    ret = msSaveImage(NULL, oImg, szMetaImg); /* save/debug metatile */

    for tile rows {
       for tile columns {

         oTile = msImageCreateGD(tileWidth, tileHeight, oImg->format, 
NULL, NULL);
         msImageCopyMerge(oImg->img.gd, oTile->img.gd, 0, 0, tileLeft, 
tileTop, tileWidth, tileHeight, 100);
         ret = msSaveImage(NULL, oTile, buf);
         msFreeImage(oTile);
       }
    }
    msFreeImage(oImg);


My problem is that the metatile looks great, but all the tiles are 
black. Traning through the mapserver code in msImageCopyMerge() it is 
not using the gdImageCopyMerge() and running through the for loops.

Looping at the tile images in photoshop, it looks like the pixel values 
are getting set to rgb(4,2,4), the background of the oImg, the src 
image, id rgb(128,177,211)

Does anyone have a clue on what I am missing here?

-Steve W

in gdb oTile looks substantially like oImg

Breakpoint 2, main (argc=4, argv=0x7fffffccd268) at precache3ibeta2.c:860
860                                     oTile = 
msImageCreateGD(tileWidth, tileHeight, oImg->format, NULL, NULL);
(gdb) p oImg
$1 = (imageObj *) 0x640870
(gdb) p *oImg
$2 = {width = 1680, height = 1680, imagepath = 0x63f880 "",
   imageurl = 0x63f970 "", format = 0x60db80, imageextra = 0x1187b00,
   buffer_format = 1, renderer = 0, size = 0, img = {gd = 0x6b4850,
     svg = 0x6b4850, imagemap = 0x6b4850 "", raw_16bit = 0x6b4850,
     raw_float = 0x6b4850, raw_byte = 0x6b4850 ""}}
(gdb) p *oImg->format
$3 = {name = 0x60dac0 "agg", mimetype = 0x60db20 "image/png",
   driver = 0x60dbd0 "AGG/PNG", extension = 0x60db00 "png", renderer = 7,
   imagemode = 1, transparent = 0, bands = 1, numformatoptions = 1,
   formatoptions = 0x60dc10, refcount = 3, inmapfile = 1}
(gdb) n
861                                     if (!oTile) {
(gdb)
865                                     msImageCopyMerge(oImg->img.gd, 
oTile->img.gd, 0, 0, tileLeft, tileTop, tileWidth, tileHeight, 100);
(gdb) p *oTile
$4 = {width = 200, height = 200, imagepath = 0x0, imageurl = 0x0,
   format = 0x60db80, imageextra = 0x0, buffer_format = 0, renderer = 0,
   size = 0, img = {gd = 0x11be030, svg = 0x11be030, imagemap = 
0x11be030 "",
     raw_16bit = 0x11be030, raw_float = 0x11be030, raw_byte = 0x11be030 ""}}
(gdb) p *oTile->format
$5 = {name = 0x60dac0 "agg", mimetype = 0x60db20 "image/png",
   driver = 0x60dbd0 "AGG/PNG", extension = 0x60db00 "png", renderer = 7,
   imagemode = 1, transparent = 0, bands = 1, numformatoptions = 1,
   formatoptions = 0x60dc10, refcount = 4, inmapfile = 1}
(gdb) p *oTile->format->formatoptions
$6 = 0x60db60 "INTERLACE=false"



More information about the mapserver-dev mailing list