Opened 17 years ago
Last modified 17 years ago
#1466 closed defect (fixed)
Support paletted and multi-band nodata values in PNG file creation
Reported by: | Owned by: | warmerdam | |
---|---|---|---|
Priority: | highest | Milestone: | |
Component: | GDAL_Raster | Version: | 1.4.0 |
Severity: | normal | Keywords: | |
Cc: |
Description
The following is an excerpt from my email correspondence with Frank about nodata value support in the PNG CreateCopy routine: I see that the PNG driver supports conventional nodata values in CreateCopy() for one band greyscale files. For RGB files it only supports the "NODATA_VALUES" metadata item which is used when all the bands have to match a particular value for the pixel to be considered nodata. The code looks like this: /* -------------------------------------------------------------------- */ /* Try to handle nodata values as a tRNS block (note for */ /* paletted images, we save the effect to apply as part of */ /* palette). */ /* -------------------------------------------------------------------- */ int bHaveNoData = FALSE; double dfNoDataValue = -1; png_color_16 sTRNSColor; dfNoDataValue = poSrcDS->GetRasterBand(1)->GetNoDataValue( &bHaveNoData ); if( (nColorType == PNG_COLOR_TYPE_GRAY ) && dfNoDataValue > 0 && dfNoDataValue < 65536 ) { sTRNSColor.gray = (png_uint_16) dfNoDataValue; png_set_tRNS( hPNG, psPNGInfo, NULL, 0, &sTRNSColor ); } // RGB case. if( nColorType == PNG_COLOR_TYPE_RGB && poSrcDS->GetMetadataItem( "NODATA_VALUES" ) != NULL ) { char **papszValues = CSLTokenizeString( poSrcDS->GetMetadataItem( "NODATA_VALUES" ) ); if( CSLCount(papszValues) >= 3 ) { sTRNSColor.red = (png_uint_16) atoi(papszValues[0]); sTRNSColor.green = (png_uint_16) atoi(papszValues[1]); sTRNSColor.blue = (png_uint_16) atoi(papszValues[2]); png_set_tRNS( hPNG, psPNGInfo, NULL, 0, &sTRNSColor ); } CSLDestroy( papszValues ); } It seems to me that at the very least we the above code should be upgrade to support nodata for paletted images as well. I also think that if NODATA_VALUES does not exist,we should consider using the regular nodata values for RGB images.
Note:
See TracTickets
for help on using tickets.