fix compile of pgraster plugin
This commit is contained in:
parent
ce7085ab63
commit
46215c0f35
2 changed files with 53 additions and 60 deletions
|
@ -178,25 +178,20 @@ typedef enum {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using mapnik::box2d;
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void read_data_band(mapnik::raster_ptr raster,
|
mapnik::raster_ptr read_data_band(mapnik::box2d<double> const& bbox,
|
||||||
uint16_t width, uint16_t height,
|
uint16_t width, uint16_t height,
|
||||||
bool hasnodata, T reader)
|
bool hasnodata, T reader)
|
||||||
{
|
{
|
||||||
mapnik::image_data_32 & image = raster->data_;
|
mapnik::image_data_float32 image(width, height);
|
||||||
|
//image.set(std::numeric_limits<float>::max());
|
||||||
// Start with plain white (ABGR or RGBA depending on endiannes)
|
// Start with plain white (ABGR or RGBA depending on endiannes)
|
||||||
// TODO: set to transparent instead?
|
// TODO: set to transparent instead?
|
||||||
image.set(0xffffffff);
|
image.set(0xffffffff);
|
||||||
|
|
||||||
raster->premultiplied_alpha_ = true;
|
float* data = image.getData();
|
||||||
|
|
||||||
float* data = (float*)image.getBytes();
|
|
||||||
double val;
|
double val;
|
||||||
val = reader(); // nodata value, need to read anyway
|
val = reader(); // nodata value, need to read anyway
|
||||||
if ( hasnodata ) raster->set_nodata(val);
|
|
||||||
for (int y=0; y<height; ++y) {
|
for (int y=0; y<height; ++y) {
|
||||||
for (int x=0; x<width; ++x) {
|
for (int x=0; x<width; ++x) {
|
||||||
val = reader();
|
val = reader();
|
||||||
|
@ -204,16 +199,14 @@ void read_data_band(mapnik::raster_ptr raster,
|
||||||
data[off] = val;
|
data[off] = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(bbox, image, 1.0, true);
|
||||||
|
if ( hasnodata ) raster->set_nodata(val);
|
||||||
|
return raster;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
mapnik::raster_ptr pgraster_wkb_reader::read_indexed(mapnik::box2d<double> const& bbox,
|
||||||
pgraster_wkb_reader::read_indexed(mapnik::raster_ptr raster)
|
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_);
|
uint8_t type = read_uint8(&ptr_);
|
||||||
|
|
||||||
int pixtype = BANDTYPE_PIXTYPE(type);
|
int pixtype = BANDTYPE_PIXTYPE(type);
|
||||||
|
@ -227,7 +220,7 @@ pgraster_wkb_reader::read_indexed(mapnik::raster_ptr raster)
|
||||||
if ( offline ) {
|
if ( offline ) {
|
||||||
MAPNIK_LOG_WARN(pgraster) << "pgraster_wkb_reader: offline band "
|
MAPNIK_LOG_WARN(pgraster) << "pgraster_wkb_reader: offline band "
|
||||||
" unsupported";
|
" unsupported";
|
||||||
return;
|
return mapnik::raster_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: reading " << height_ << "x" << width_ << " pixels";
|
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:
|
case PT_8BSI:
|
||||||
// mapnik does not support signed anyway
|
// mapnik does not support signed anyway
|
||||||
case PT_8BUI:
|
case PT_8BUI:
|
||||||
read_data_band(raster, width_, height_, hasnodata,
|
return read_data_band(bbox, width_, height_, hasnodata,
|
||||||
boost::bind(read_uint8, &ptr_));
|
boost::bind(read_uint8, &ptr_));
|
||||||
break;
|
break;
|
||||||
case PT_16BSI:
|
case PT_16BSI:
|
||||||
// mapnik does not support signed anyway
|
// mapnik does not support signed anyway
|
||||||
case PT_16BUI:
|
case PT_16BUI:
|
||||||
read_data_band(raster, width_, height_, hasnodata,
|
return read_data_band(bbox, width_, height_, hasnodata,
|
||||||
boost::bind(read_uint16, &ptr_, endian_));
|
boost::bind(read_uint16, &ptr_, endian_));
|
||||||
break;
|
break;
|
||||||
case PT_32BSI:
|
case PT_32BSI:
|
||||||
// mapnik does not support signed anyway
|
// mapnik does not support signed anyway
|
||||||
case PT_32BUI:
|
case PT_32BUI:
|
||||||
read_data_band(raster, width_, height_, hasnodata,
|
return read_data_band(bbox, width_, height_, hasnodata,
|
||||||
boost::bind(read_uint32, &ptr_, endian_));
|
boost::bind(read_uint32, &ptr_, endian_));
|
||||||
break;
|
break;
|
||||||
case PT_32BF:
|
case PT_32BF:
|
||||||
read_data_band(raster, width_, height_, hasnodata,
|
return read_data_band(bbox, width_, height_, hasnodata,
|
||||||
boost::bind(read_float32, &ptr_, endian_));
|
boost::bind(read_float32, &ptr_, endian_));
|
||||||
break;
|
break;
|
||||||
case PT_64BF:
|
case PT_64BF:
|
||||||
read_data_band(raster, width_, height_, hasnodata,
|
return read_data_band(bbox, width_, height_, hasnodata,
|
||||||
boost::bind(read_float64, &ptr_, endian_));
|
boost::bind(read_float64, &ptr_, endian_));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -270,28 +263,25 @@ pgraster_wkb_reader::read_indexed(mapnik::raster_ptr raster)
|
||||||
//MAPNIK_LOG_WARN(pgraster) << err.str();
|
//MAPNIK_LOG_WARN(pgraster) << err.str();
|
||||||
throw mapnik::datasource_exception(err.str());
|
throw mapnik::datasource_exception(err.str());
|
||||||
}
|
}
|
||||||
|
return mapnik::raster_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void read_grayscale_band(mapnik::raster_ptr raster,
|
mapnik::raster_ptr read_grayscale_band(mapnik::box2d<double> const& bbox,
|
||||||
uint16_t width, uint16_t height,
|
uint16_t width, uint16_t height,
|
||||||
bool hasnodata, T reader)
|
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)
|
// Start with plain white (ABGR or RGBA depending on endiannes)
|
||||||
// TODO: set to transparent instead?
|
// TODO: set to transparent instead?
|
||||||
image.set(0xffffffff);
|
image.set(0xffffffff);
|
||||||
|
|
||||||
raster->premultiplied_alpha_ = true;
|
|
||||||
|
|
||||||
int val;
|
int val;
|
||||||
uint8_t * data = image.getBytes();
|
uint8_t * data = image.getBytes();
|
||||||
int ps = 4; // sizeof(image_data::pixel_type)
|
int ps = 4; // sizeof(image_data::pixel_type)
|
||||||
int off;
|
int off;
|
||||||
val = reader(); // nodata value, need to read anyway
|
val = reader(); // nodata value, need to read anyway
|
||||||
if ( hasnodata ) raster->set_nodata(val);
|
|
||||||
for (int y=0; y<height; ++y) {
|
for (int y=0; y<height; ++y) {
|
||||||
for (int x=0; x<width; ++x) {
|
for (int x=0; x<width; ++x) {
|
||||||
val = reader();
|
val = reader();
|
||||||
|
@ -302,10 +292,13 @@ void read_grayscale_band(mapnik::raster_ptr raster,
|
||||||
data[off+2] = val;
|
data[off+2] = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(bbox, image, 1.0, true);
|
||||||
|
if ( hasnodata ) raster->set_nodata(val);
|
||||||
|
return raster;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
mapnik::raster_ptr pgraster_wkb_reader::read_grayscale(mapnik::box2d<double> const& bbox,
|
||||||
pgraster_wkb_reader::read_grayscale(mapnik::raster_ptr raster)
|
uint16_t width, uint16_t height)
|
||||||
{
|
{
|
||||||
uint8_t type = read_uint8(&ptr_);
|
uint8_t type = read_uint8(&ptr_);
|
||||||
|
|
||||||
|
@ -320,7 +313,7 @@ pgraster_wkb_reader::read_grayscale(mapnik::raster_ptr raster)
|
||||||
if ( offline ) {
|
if ( offline ) {
|
||||||
MAPNIK_LOG_WARN(pgraster) << "pgraster_wkb_reader: offline band "
|
MAPNIK_LOG_WARN(pgraster) << "pgraster_wkb_reader: offline band "
|
||||||
" unsupported";
|
" unsupported";
|
||||||
return;
|
return mapnik::raster_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (pixtype) {
|
switch (pixtype) {
|
||||||
|
@ -331,19 +324,19 @@ pgraster_wkb_reader::read_grayscale(mapnik::raster_ptr raster)
|
||||||
case PT_8BSI:
|
case PT_8BSI:
|
||||||
// mapnik does not support signed anyway
|
// mapnik does not support signed anyway
|
||||||
case PT_8BUI:
|
case PT_8BUI:
|
||||||
read_grayscale_band(raster, width_, height_, hasnodata,
|
return read_grayscale_band(bbox, width_, height_, hasnodata,
|
||||||
boost::bind(read_uint8, &ptr_));
|
boost::bind(read_uint8, &ptr_));
|
||||||
break;
|
break;
|
||||||
case PT_16BSI:
|
case PT_16BSI:
|
||||||
// mapnik does not support signed anyway
|
// mapnik does not support signed anyway
|
||||||
case PT_16BUI:
|
case PT_16BUI:
|
||||||
read_grayscale_band(raster, width_, height_, hasnodata,
|
return read_grayscale_band(bbox, width_, height_, hasnodata,
|
||||||
boost::bind(read_uint16, &ptr_, endian_));
|
boost::bind(read_uint16, &ptr_, endian_));
|
||||||
break;
|
break;
|
||||||
case PT_32BSI:
|
case PT_32BSI:
|
||||||
// mapnik does not support signed anyway
|
// mapnik does not support signed anyway
|
||||||
case PT_32BUI:
|
case PT_32BUI:
|
||||||
read_grayscale_band(raster, width_, height_, hasnodata,
|
return read_grayscale_band(bbox, width_, height_, hasnodata,
|
||||||
boost::bind(read_uint32, &ptr_, endian_));
|
boost::bind(read_uint32, &ptr_, endian_));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -353,19 +346,15 @@ pgraster_wkb_reader::read_grayscale(mapnik::raster_ptr raster)
|
||||||
//MAPNIK_LOG_WARN(pgraster) << err.str();
|
//MAPNIK_LOG_WARN(pgraster) << err.str();
|
||||||
throw mapnik::datasource_exception(err.str());
|
throw mapnik::datasource_exception(err.str());
|
||||||
}
|
}
|
||||||
|
return mapnik::raster_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
mapnik::raster_ptr pgraster_wkb_reader::read_rgba(mapnik::box2d<double> const& bbox,
|
||||||
pgraster_wkb_reader::read_rgba(mapnik::raster_ptr raster)
|
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)
|
// Start with plain white (ABGR or RGBA depending on endiannes)
|
||||||
image.set(0xffffffff);
|
image.set(0xffffffff);
|
||||||
//raster->set_nodata(0xffffffff);
|
|
||||||
|
|
||||||
raster->premultiplied_alpha_ = true;
|
|
||||||
|
|
||||||
uint8_t nodataval;
|
uint8_t nodataval;
|
||||||
for (int bn=0; bn<numBands_; ++bn) {
|
for (int bn=0; bn<numBands_; ++bn) {
|
||||||
|
@ -411,6 +400,9 @@ pgraster_wkb_reader::read_rgba(mapnik::raster_ptr raster)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(bbox, image, 1.0, true);
|
||||||
|
raster->set_nodata(0xffffffff);
|
||||||
|
return raster;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapnik::raster_ptr
|
mapnik::raster_ptr
|
||||||
|
@ -458,28 +450,30 @@ pgraster_wkb_reader::get_raster() {
|
||||||
return mapnik::raster_ptr();
|
return mapnik::raster_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
box2d<double> ext(ipX,ipY,ipX+(width_*scaleX),ipY+(height_*scaleY));
|
mapnik::box2d<double> ext(ipX,ipY,ipX+(width_*scaleX),ipY+(height_*scaleY));
|
||||||
MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: Raster extent=" << ext;
|
MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: Raster extent=" << ext;
|
||||||
|
|
||||||
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(ext, width_, height_, 1.0);
|
if ( bandno_ )
|
||||||
|
{
|
||||||
if ( bandno_ ) {
|
if ( bandno_ != 1 )
|
||||||
if ( bandno_ != 1 ) {
|
{
|
||||||
MAPNIK_LOG_WARN(pgraster) << "pgraster_wkb_reader: "
|
MAPNIK_LOG_WARN(pgraster) << "pgraster_wkb_reader: "
|
||||||
"reading bands other than 1st as indexed is unsupported";
|
"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_;
|
MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: requested band " << bandno_;
|
||||||
read_indexed(raster);
|
return read_indexed(ext, width_, height_);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
switch (numBands_) {
|
{
|
||||||
|
switch (numBands_)
|
||||||
|
{
|
||||||
case 1:
|
case 1:
|
||||||
read_grayscale(raster);
|
return read_grayscale(ext, width_, height_);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
case 4:
|
case 4:
|
||||||
read_rgba(raster);
|
return read_rgba(ext, width_, height_);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
std::ostringstream err;
|
std::ostringstream err;
|
||||||
|
@ -491,7 +485,5 @@ pgraster_wkb_reader::get_raster() {
|
||||||
return mapnik::raster_ptr();
|
return mapnik::raster_ptr();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return mapnik::raster_ptr();
|
||||||
return raster;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
// mapnik
|
// mapnik
|
||||||
#include <mapnik/feature.hpp> // for raster_ptr
|
#include <mapnik/feature.hpp> // for raster_ptr
|
||||||
|
#include <mapnik/box2d.hpp>
|
||||||
|
|
||||||
enum pgraster_color_interp {
|
enum pgraster_color_interp {
|
||||||
// Automatic color interpretation:
|
// Automatic color interpretation:
|
||||||
|
@ -65,9 +66,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void read_indexed(mapnik::raster_ptr raster);
|
mapnik::raster_ptr read_indexed(mapnik::box2d<double> const& bbox, uint16_t width, uint16_t height);
|
||||||
void read_grayscale(mapnik::raster_ptr raster);
|
mapnik::raster_ptr read_grayscale(mapnik::box2d<double> const& bbox, uint16_t width, uint16_t height);
|
||||||
void read_rgba(mapnik::raster_ptr raster);
|
mapnik::raster_ptr read_rgba(mapnik::box2d<double> const& bbox, uint16_t width, uint16_t height);
|
||||||
|
|
||||||
//int wkbsize_;
|
//int wkbsize_;
|
||||||
//const uint8_t* wkb_;
|
//const uint8_t* wkb_;
|
||||||
|
|
Loading…
Add table
Reference in a new issue