From 46215c0f35657fec6a45aadb98107bf9097eee2b Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 3 Dec 2014 00:35:34 -0500 Subject: [PATCH] fix compile of pgraster plugin --- .../input/pgraster/pgraster_wkb_reader.cpp | 106 ++++++++---------- .../input/pgraster/pgraster_wkb_reader.hpp | 7 +- 2 files changed, 53 insertions(+), 60 deletions(-) diff --git a/plugins/input/pgraster/pgraster_wkb_reader.cpp b/plugins/input/pgraster/pgraster_wkb_reader.cpp index 109438ab9..ad49ab34d 100644 --- a/plugins/input/pgraster/pgraster_wkb_reader.cpp +++ b/plugins/input/pgraster/pgraster_wkb_reader.cpp @@ -178,25 +178,20 @@ typedef enum { } -using mapnik::box2d; - template -void read_data_band(mapnik::raster_ptr raster, +mapnik::raster_ptr read_data_band(mapnik::box2d const& bbox, uint16_t width, uint16_t height, bool hasnodata, T reader) { - mapnik::image_data_32 & image = raster->data_; - + mapnik::image_data_float32 image(width, height); + //image.set(std::numeric_limits::max()); // Start with plain white (ABGR or RGBA depending on endiannes) // TODO: set to transparent instead? image.set(0xffffffff); - raster->premultiplied_alpha_ = true; - - float* data = (float*)image.getBytes(); + float* data = image.getData(); double val; val = reader(); // nodata value, need to read anyway - if ( hasnodata ) raster->set_nodata(val); for (int y=0; y(bbox, image, 1.0, true); + if ( hasnodata ) raster->set_nodata(val); + return raster; } -void -pgraster_wkb_reader::read_indexed(mapnik::raster_ptr raster) +mapnik::raster_ptr pgraster_wkb_reader::read_indexed(mapnik::box2d const& bbox, + uint16_t width, uint16_t height) { - mapnik::image_data_32 & image = raster->data_; - - // Start with all zeroes - image.set(0); - uint8_t type = read_uint8(&ptr_); int pixtype = BANDTYPE_PIXTYPE(type); @@ -227,7 +220,7 @@ pgraster_wkb_reader::read_indexed(mapnik::raster_ptr raster) if ( offline ) { MAPNIK_LOG_WARN(pgraster) << "pgraster_wkb_reader: offline band " " unsupported"; - return; + return mapnik::raster_ptr(); } MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: reading " << height_ << "x" << width_ << " pixels"; @@ -240,27 +233,27 @@ pgraster_wkb_reader::read_indexed(mapnik::raster_ptr raster) case PT_8BSI: // mapnik does not support signed anyway case PT_8BUI: - read_data_band(raster, width_, height_, hasnodata, + return read_data_band(bbox, width_, height_, hasnodata, boost::bind(read_uint8, &ptr_)); break; case PT_16BSI: // mapnik does not support signed anyway case PT_16BUI: - read_data_band(raster, width_, height_, hasnodata, + return read_data_band(bbox, width_, height_, hasnodata, boost::bind(read_uint16, &ptr_, endian_)); break; case PT_32BSI: // mapnik does not support signed anyway case PT_32BUI: - read_data_band(raster, width_, height_, hasnodata, + return read_data_band(bbox, width_, height_, hasnodata, boost::bind(read_uint32, &ptr_, endian_)); break; case PT_32BF: - read_data_band(raster, width_, height_, hasnodata, + return read_data_band(bbox, width_, height_, hasnodata, boost::bind(read_float32, &ptr_, endian_)); break; case PT_64BF: - read_data_band(raster, width_, height_, hasnodata, + return read_data_band(bbox, width_, height_, hasnodata, boost::bind(read_float64, &ptr_, endian_)); break; default: @@ -270,28 +263,25 @@ pgraster_wkb_reader::read_indexed(mapnik::raster_ptr raster) //MAPNIK_LOG_WARN(pgraster) << err.str(); throw mapnik::datasource_exception(err.str()); } - + return mapnik::raster_ptr(); } template -void read_grayscale_band(mapnik::raster_ptr raster, +mapnik::raster_ptr read_grayscale_band(mapnik::box2d const& bbox, uint16_t width, uint16_t height, bool hasnodata, T reader) { - mapnik::image_data_32 & image = raster->data_; - + mapnik::image_data_32 image(width,height); // Start with plain white (ABGR or RGBA depending on endiannes) // TODO: set to transparent instead? image.set(0xffffffff); - raster->premultiplied_alpha_ = true; int val; uint8_t * data = image.getBytes(); int ps = 4; // sizeof(image_data::pixel_type) int off; val = reader(); // nodata value, need to read anyway - if ( hasnodata ) raster->set_nodata(val); for (int y=0; y(bbox, image, 1.0, true); + if ( hasnodata ) raster->set_nodata(val); + return raster; } -void -pgraster_wkb_reader::read_grayscale(mapnik::raster_ptr raster) +mapnik::raster_ptr pgraster_wkb_reader::read_grayscale(mapnik::box2d const& bbox, + uint16_t width, uint16_t height) { uint8_t type = read_uint8(&ptr_); @@ -320,7 +313,7 @@ pgraster_wkb_reader::read_grayscale(mapnik::raster_ptr raster) if ( offline ) { MAPNIK_LOG_WARN(pgraster) << "pgraster_wkb_reader: offline band " " unsupported"; - return; + return mapnik::raster_ptr(); } switch (pixtype) { @@ -331,19 +324,19 @@ pgraster_wkb_reader::read_grayscale(mapnik::raster_ptr raster) case PT_8BSI: // mapnik does not support signed anyway case PT_8BUI: - read_grayscale_band(raster, width_, height_, hasnodata, + return read_grayscale_band(bbox, width_, height_, hasnodata, boost::bind(read_uint8, &ptr_)); break; case PT_16BSI: // mapnik does not support signed anyway case PT_16BUI: - read_grayscale_band(raster, width_, height_, hasnodata, + return read_grayscale_band(bbox, width_, height_, hasnodata, boost::bind(read_uint16, &ptr_, endian_)); break; case PT_32BSI: // mapnik does not support signed anyway case PT_32BUI: - read_grayscale_band(raster, width_, height_, hasnodata, + return read_grayscale_band(bbox, width_, height_, hasnodata, boost::bind(read_uint32, &ptr_, endian_)); break; default: @@ -353,19 +346,15 @@ pgraster_wkb_reader::read_grayscale(mapnik::raster_ptr raster) //MAPNIK_LOG_WARN(pgraster) << err.str(); throw mapnik::datasource_exception(err.str()); } - + return mapnik::raster_ptr(); } -void -pgraster_wkb_reader::read_rgba(mapnik::raster_ptr raster) +mapnik::raster_ptr pgraster_wkb_reader::read_rgba(mapnik::box2d const& bbox, + uint16_t width, uint16_t height) { - mapnik::image_data_32 & image = raster->data_; - + mapnik::image_data_32 image(width, height); // Start with plain white (ABGR or RGBA depending on endiannes) image.set(0xffffffff); - //raster->set_nodata(0xffffffff); - - raster->premultiplied_alpha_ = true; uint8_t nodataval; for (int bn=0; bn(bbox, image, 1.0, true); + raster->set_nodata(0xffffffff); + return raster; } mapnik::raster_ptr @@ -458,28 +450,30 @@ pgraster_wkb_reader::get_raster() { return mapnik::raster_ptr(); } - box2d ext(ipX,ipY,ipX+(width_*scaleX),ipY+(height_*scaleY)); + mapnik::box2d ext(ipX,ipY,ipX+(width_*scaleX),ipY+(height_*scaleY)); MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: Raster extent=" << ext; - mapnik::raster_ptr raster = std::make_shared(ext, width_, height_, 1.0); - - if ( bandno_ ) { - if ( bandno_ != 1 ) { - MAPNIK_LOG_WARN(pgraster) << "pgraster_wkb_reader: " + if ( bandno_ ) + { + if ( bandno_ != 1 ) + { + MAPNIK_LOG_WARN(pgraster) << "pgraster_wkb_reader: " "reading bands other than 1st as indexed is unsupported"; - return mapnik::raster_ptr(); + return mapnik::raster_ptr(); } MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: requested band " << bandno_; - read_indexed(raster); + return read_indexed(ext, width_, height_); } - else { - switch (numBands_) { + else + { + switch (numBands_) + { case 1: - read_grayscale(raster); + return read_grayscale(ext, width_, height_); break; case 3: case 4: - read_rgba(raster); + return read_rgba(ext, width_, height_); break; default: std::ostringstream err; @@ -491,7 +485,5 @@ pgraster_wkb_reader::get_raster() { return mapnik::raster_ptr(); } } - - return raster; - + return mapnik::raster_ptr(); } diff --git a/plugins/input/pgraster/pgraster_wkb_reader.hpp b/plugins/input/pgraster/pgraster_wkb_reader.hpp index 21f163bbd..b0ec7f8f9 100644 --- a/plugins/input/pgraster/pgraster_wkb_reader.hpp +++ b/plugins/input/pgraster/pgraster_wkb_reader.hpp @@ -29,6 +29,7 @@ // mapnik #include // for raster_ptr +#include enum pgraster_color_interp { // Automatic color interpretation: @@ -65,9 +66,9 @@ public: } private: - void read_indexed(mapnik::raster_ptr raster); - void read_grayscale(mapnik::raster_ptr raster); - void read_rgba(mapnik::raster_ptr raster); + mapnik::raster_ptr read_indexed(mapnik::box2d const& bbox, uint16_t width, uint16_t height); + mapnik::raster_ptr read_grayscale(mapnik::box2d const& bbox, uint16_t width, uint16_t height); + mapnik::raster_ptr read_rgba(mapnik::box2d const& bbox, uint16_t width, uint16_t height); //int wkbsize_; //const uint8_t* wkb_;