[gdal-dev] Re: Transparent PNG with color table (palette)

canduc17 candini at meeo.it
Thu Jun 17 05:28:47 EDT 2010


I have implemented in C++ an example of color table applied to a band, taking
as reference the python script reported in this thread:

Ludwig wrote:
> 
> 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)
> 

My code:

// Create a color table for the Air Quality output image
	GDALColorTable *colorTable = new GDALColorTable();
	GDALColorEntry black, green, yellow, orange, red, lightRed;
	// Setting RGB colors for 6 classes
	black.c1    = 0;	black.c2    = 0;	black.c3    = 0;	black.c4    = 0;
	green.c1    = 0;	green.c2  = 255;	green.c3    = 0;	green.c4    = 0;
	yellow.c1   = 255;	yellow.c2 = 255;	yellow.c3   = 0;	yellow.c4   = 0;
	orange.c1   = 255;	orange.c2 = 150;	orange.c3   = 0;	orange.c4   = 0;
	red.c1      = 255;	red.c2      = 0;	red.c3      = 0;	red.c4      = 0;
	lightRed.c1 = 150;	lightRed.c2 = 0;	lightRed.c3 = 0;	lightRed.c4 = 0;

	// Link every color to a pixel value
	colorTable->SetColorEntry(0, &black);
	colorTable->SetColorEntry(1, &green);
	colorTable->SetColorEntry(2, &yellow);
	colorTable->SetColorEntry(3, &orange);
	colorTable->SetColorEntry(4, &red);
	colorTable->SetColorEntry(5, &lightRed);

	// Apply the table to the band
	myOutBand->SetColorTable(colorTable);

	// Delete the GDALColorTable object
	delete colorTable;

I hope this could be helpful for someone.
-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Transparent-PNG-with-color-table-palette-tp2030306p5190147.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list