From d144f97f4e5c667b86c16ee4bfc0113d00afa81e Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Wed, 8 Jul 2015 08:29:53 -0700 Subject: [PATCH] Render NODATA as transparent and clip highbit data ala GDAL for greyscale outputs. Addresses #2661 --- plugins/input/pgraster/pgraster_wkb_reader.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/input/pgraster/pgraster_wkb_reader.cpp b/plugins/input/pgraster/pgraster_wkb_reader.cpp index 0320fe106..87f71c093 100644 --- a/plugins/input/pgraster/pgraster_wkb_reader.cpp +++ b/plugins/input/pgraster/pgraster_wkb_reader.cpp @@ -271,18 +271,30 @@ mapnik::raster_ptr read_grayscale_band(mapnik::box2d const& bbox, int val; + int nodataval; uint8_t * data = image.bytes(); int ps = 4; // sizeof(image::pixel_type) int off; - val = reader(); // nodata value, need to read anyway + nodataval = reader(); // nodata value, need to read anyway for (int y=0; y 255 ) val = 255; + // Calculate pixel offset off = y * width * ps + x * ps; - // Pixel space is RGBA + // Pixel space is RGBA, fill all w/ same value for Grey data[off+0] = val; data[off+1] = val; data[off+2] = val; + // Set the alpha channel for transparent nodata values + // Nodata handling is *manual* at the driver level + if ( hasnodata && val == nodataval ) { + data[off+3] = 0x00; // transparent + } else { + data[off+3] = 0xFF; // opaque + } } } mapnik::raster_ptr raster = std::make_shared(bbox, image, 1.0);