[Gdal-dev] Transparent PNG with color table (palette)
Ludwig M Brinckmann
ludwigbrinckmann at gmail.com
Mon May 28 16:17:09 EDT 2007
That now works, thanks.
For the benefit of others this poorly coded Python example shows the way to
use the MEM dataset with GCPs and ColorTable with transparencies to then
create both a paletted GTiff (no transparencies supported, so the
transparent green appear in the tiff, but the GCPs are there), and a PNG
(with transparencies, but without GCPs):
import gdal
import gdal_array
import gdalconst
import numpy
rows = 10
cols = 10
data = numpy.ones((rows,cols), numpy.uint8)
data[4:7,...] = 0
driver = gdal.GetDriverByName('MEM')
image = driver.Create('dummy', rows, cols, 1, gdalconst.GDT_Byte)
gcps = []
gcps.append (gdal.GCP(1,2,3,4))
image.SetGCPs(gcps, '')
colorTable = gdal.ColorTable()
greentransparent = (0, 255, 0, 0)
blue = (0,0, 255,255)
colorTable.SetColorEntry(0, greentransparent)
colorTable.SetColorEntry(1, blue)
b = image.GetRasterBand(1)
b.SetRasterColorTable(colorTable)
b.WriteArray(data)
tiffdriver = gdal.GetDriverByName('GTiff')
tiffdriver.CreateCopy('dummy.tif', image)
pngdriver = gdal.GetDriverByName('PNG')
pngdriver.CreateCopy('dummy.png', image)
Frank, while I was building from svn trunk, I stumbled over a number of C++
comments in C files/ headers
port/cpl_port.h line 209
alg/gdal_crs.c line 402
frmts/nitf/nitfile.c line 533/535
frmts/nitfimage.c 2x
frmts/mgrs.c line 400
port/cps_multiproc.h line 35++
Thanks for your very quick help.
Ludwig
On 28/05/07, Ludwig M Brinckmann <ludwigbrinckmann at gmail.com> wrote:
>
> Thanks, you are a star.
>
> I will see if that works for me and report back.
>
> Regards,
>
> Ludwig
>
> On 28/05/07, Frank Warmerdam < warmerdam at pobox.com> wrote:
> >
> > Ludwig M Brinckmann wrote:
> > > Maybe this was a bit premature.
> > >
> > > Unfortunately, the MEM dataset does not support the SetGCPs method,
> > even
> > > though the documentation says it 'should' .
> > > (" Memory datasets should support for most kinds of auxilary
> > information
> > > including metadata, coordinate systems, georeferencing, GCPs, color
> > > interpretation, nodata, color tables and all pixel data types.")
> >
> > Ludwig,
> >
> > I see your analysis is correct - the MEM driver actually lacked GCP
> > support
> > despite the docs. I have added this in trunk, if that is convenient for
> > you.
> >
> > Best regards,
> > --
> >
> > ---------------------------------------+--------------------------------------
> > I set the clouds in motion - turn up | Frank Warmerdam,
> > warmerdam at pobox.com
> > light and sound - activate the windows | http://pobox.com/~warmerdam<http://pobox.com/%7Ewarmerdam>
> > and watch the world go round - Rush | President OSGeo,
> > http://osgeo.org
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20070528/a69acb70/attachment.html
More information about the Gdal-dev
mailing list