[Gdal-dev] Transparent PNG with color table (palette)

Ludwig M Brinckmann ludwigbrinckmann at gmail.com
Mon May 28 11:06:45 EDT 2007


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.")

This works with the GTiff driver, but not with MEM:

import gdal
import gdal_array
import gdalconst
import numpy

rows = 10
cols = 10

data = numpy.ones((rows,cols), numpy.int16)

driver = gdal.GetDriverByName('MEM')
image = driver.Create('dummy', rows, cols, 1, gdalconst.GDT_Int16)
gcps = []
gcps.append(gdal.GCP(1,2,3,4))
image.SetGCPs(gcps, '')


Ludwig


On 28/05/07, Ludwig M Brinckmann <ludwigbrinckmann at gmail.com> wrote:
>
> Many thanks,
>
> that seems to work beautifully.
>
> So far I had been using tiff images as an intermediate container when
> creating files for which no Create() method is available, but the in memory
> MEM format  of course is much superior, no fuss with temp files and no need
> to write to disk.
>
> Regards
>
> Ludwig
>
>
> On 28/05/07, Frank Warmerdam <warmerdam at pobox.com> wrote:
> >
> > Ludwig M Brinckmann wrote:
> > > I need to create paletted PNG files with transparency.
> > >
> > > I understand that I need to pass in a colour table with the alpha
> > > channel set to 0.
> > >
> > > As I cannot create PNGs directly, I first create a Tiff with the
> > > colourtable and then do a CreateCopy.
> > >
> > > But when I then look at the PNG colour table, the transparency values
> > > are gone (all set to 255). This is also true for the intermediate Tiff
> > > file -- which is understandable as single band tiffs don't do
> > > transparency. I think when creating the tiff the colourtable is
> > adjusted
> > > so that it works for the Tiff, but then my transparencies are lost.
> > (If
> > > someone thinks this is a bug, I will turn my code into a short
> > example).
> > >
> > > I tried to alter the colour table after creating the tiff (or the
> > > createCopy of the PNG), but this is not supported.
> > >
> > > What's the best way to do this -- maybe I just need a better
> > > intermediate format that does transparencies and can be created (which
> > > one?)
> >
> > Ludwig,
> >
> > If you image isn't too large, and you are doing programatically (or
> > via scripts) you might want to use MEM format as your intermediate
> > format.
> > I believe it supports fully featured color tables, and no mess and fuss
> > with intermediate file cleanup.
> >
> >    http://www.gdal.org/frmt_mem.html
> >
> > Note, when creating MEM datasets and not needing to attach to an
> > existing
> > array in memory, just use any name for the dataset, such as "tempimage".
> >
> > 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/63e0460c/attachment.html


More information about the Gdal-dev mailing list