[gdal-dev] core dumping on PNG RGB creation

Even Rouault even.rouault at mines-paris.org
Mon Feb 2 18:09:16 EST 2009


It looks like you're looking for big troubles ;-)

If SUPPORT_CREATE is not defined by default in standard GDAL built, it means 
that it is not production ready... After having looked at the code a bit, I 
can tell you that it is definitely not ready to work bullet-proof and would 
require a lot of love. I think it will probably never meet the expectations 
for a driver supporting Create() (random write access for example), because 
of the way libpng works. 

In particular, it can't support writing separately in raster bands in 
multiband case like what you are doing (it would require caching the data for 
each whole band...). You should use interleaved writing (write data for the 3 
bands of the first line, then write data for the 3 bands of the second line, 
etc.) but I'm afraid you'll go into other issues again, like the file not 
being properly closed, uninitalized variables, being unable to read the 
content of the created dataset without closing it (which might be an issue if 
cache size is not sufficient), etc etc...

So my advice if you want to safely generate a PNG : use the MEM driver to 
write your data and then CreateCopy() the MEM dataset into a PNG.

Something like :

import osgeo.gdal as gdal
import numpy
buf = (numpy.random.rand(100*100*3)*255).round() % 255
buf = buf.reshape(100,100,3)
driver = gdal.GetDriverByName('MEM')
ds = driver.Create('tmp.mem', 100,100,3)
ds2 = gdal.GetDriverByName('PNG').CreateCopy('tmp.png', ds)
ds = None
ds2 = None


Le Monday 02 February 2009 21:13:22 Jared Rubin, vous avez écrit :
> But if the following define is set when building gdal
> -DSUPPORT_CREATE then the PNG driver will support the CREATE method
> Jared
> On Mon, 2009-02-02 at 20:05 +0000, Lucena, Ivan wrote:
> > That is because the PNG driver
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev

More information about the gdal-dev mailing list