Merge pull request #3671 from mapnik/tiff-multiband-grey
TIFF I/O : add support for multiple bands in 'scanline` reading metho…
This commit is contained in:
commit
f205f3859d
11 changed files with 941 additions and 728 deletions
|
@ -40,15 +40,27 @@ class raster : private util::noncopyable
|
|||
{
|
||||
public:
|
||||
box2d<double> ext_;
|
||||
box2d<double> query_ext_;
|
||||
image_any data_;
|
||||
double filter_factor_;
|
||||
boost::optional<double> nodata_;
|
||||
|
||||
template <typename ImageData>
|
||||
raster(box2d<double> const& ext,
|
||||
box2d<double> const& query_ext,
|
||||
ImageData && data,
|
||||
double filter_factor)
|
||||
: ext_(ext),
|
||||
query_ext_(query_ext),
|
||||
data_(std::move(data)),
|
||||
filter_factor_(filter_factor) {}
|
||||
|
||||
template <typename ImageData>
|
||||
raster(box2d<double> const& ext,
|
||||
ImageData && data,
|
||||
double filter_factor)
|
||||
: ext_(ext),
|
||||
query_ext_(ext),
|
||||
data_(std::move(data)),
|
||||
filter_factor_(filter_factor) {}
|
||||
|
||||
|
@ -71,7 +83,6 @@ public:
|
|||
{
|
||||
filter_factor_ = factor;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ struct image_dispatcher
|
|||
image_dispatcher(int start_x, int start_y,
|
||||
int width, int height,
|
||||
double scale_x, double scale_y,
|
||||
double offset_x, double offset_y,
|
||||
scaling_method_e method, double filter_factor,
|
||||
double opacity, composite_mode_e comp_op,
|
||||
raster_symbolizer const& sym, feature_impl const& feature,
|
||||
|
@ -63,15 +64,17 @@ struct image_dispatcher
|
|||
height_(height),
|
||||
scale_x_(scale_x),
|
||||
scale_y_(scale_y),
|
||||
offset_x_(offset_x),
|
||||
offset_y_(offset_y),
|
||||
method_(method),
|
||||
filter_factor_(filter_factor),
|
||||
opacity_(opacity),
|
||||
comp_op_(comp_op),
|
||||
sym_(sym),
|
||||
feature_(feature),
|
||||
composite_(composite),
|
||||
nodata_(nodata),
|
||||
need_scaling_(need_scaling) {}
|
||||
opacity_(opacity),
|
||||
comp_op_(comp_op),
|
||||
sym_(sym),
|
||||
feature_(feature),
|
||||
composite_(composite),
|
||||
nodata_(nodata),
|
||||
need_scaling_(need_scaling) {}
|
||||
|
||||
void operator() (image_null const&) const {} //no-op
|
||||
void operator() (image_rgba8 const& data_in) const
|
||||
|
@ -79,7 +82,7 @@ struct image_dispatcher
|
|||
if (need_scaling_)
|
||||
{
|
||||
image_rgba8 data_out(width_, height_, true, true);
|
||||
scale_image_agg(data_out, data_in, method_, scale_x_, scale_y_, 0.0, 0.0, filter_factor_, nodata_);
|
||||
scale_image_agg(data_out, data_in, method_, scale_x_, scale_y_, offset_x_, offset_y_, filter_factor_, nodata_);
|
||||
composite_(data_out, comp_op_, opacity_, start_x_, start_y_);
|
||||
}
|
||||
else
|
||||
|
@ -97,7 +100,7 @@ struct image_dispatcher
|
|||
if (need_scaling_)
|
||||
{
|
||||
image_type data_out(width_, height_);
|
||||
scale_image_agg(data_out, data_in, method_, scale_x_, scale_y_, 0.0, 0.0, filter_factor_, nodata_);
|
||||
scale_image_agg(data_out, data_in, method_, scale_x_, scale_y_, offset_x_, offset_y_, filter_factor_, nodata_);
|
||||
if (colorizer) colorizer->colorize(dst, data_out, nodata_, feature_);
|
||||
}
|
||||
else
|
||||
|
@ -114,6 +117,8 @@ private:
|
|||
int height_;
|
||||
double scale_x_;
|
||||
double scale_y_;
|
||||
double offset_x_;
|
||||
double offset_y_;
|
||||
scaling_method_e method_;
|
||||
double filter_factor_;
|
||||
double opacity_;
|
||||
|
@ -210,12 +215,17 @@ void render_raster_symbolizer(raster_symbolizer const& sym,
|
|||
if (source)
|
||||
{
|
||||
box2d<double> target_ext = box2d<double>(source->ext_);
|
||||
prj_trans.backward(target_ext, PROJ_ENVELOPE_POINTS);
|
||||
box2d<double> target_query_ext = box2d<double>(source->query_ext_);
|
||||
if (!prj_trans.equal()) {
|
||||
prj_trans.backward(target_ext, PROJ_ENVELOPE_POINTS);
|
||||
prj_trans.backward(target_query_ext, PROJ_ENVELOPE_POINTS);
|
||||
}
|
||||
box2d<double> ext = common.t_.forward(target_ext);
|
||||
int start_x = static_cast<int>(std::floor(ext.minx()+.5));
|
||||
int start_y = static_cast<int>(std::floor(ext.miny()+.5));
|
||||
int end_x = static_cast<int>(std::floor(ext.maxx()+.5));
|
||||
int end_y = static_cast<int>(std::floor(ext.maxy()+.5));
|
||||
box2d<double> query_ext = common.t_.forward(target_query_ext);
|
||||
int start_x = static_cast<int>(std::floor(query_ext.minx()+.5));
|
||||
int start_y = static_cast<int>(std::floor(query_ext.miny()+.5));
|
||||
int end_x = static_cast<int>(std::floor(query_ext.maxx()+.5));
|
||||
int end_y = static_cast<int>(std::floor(query_ext.maxy()+.5));
|
||||
int raster_width = end_x - start_x;
|
||||
int raster_height = end_y - start_y;
|
||||
if (raster_width > 0 && raster_height > 0)
|
||||
|
@ -236,17 +246,20 @@ void render_raster_symbolizer(raster_symbolizer const& sym,
|
|||
|
||||
if (!prj_trans.equal())
|
||||
{
|
||||
double offset_x = ext.minx() - start_x;
|
||||
double offset_y = ext.miny() - start_y;
|
||||
// This path does not currently work and is still being figured out.
|
||||
double offset_x = query_ext.minx() - start_x;
|
||||
double offset_y = query_ext.miny() - start_y;
|
||||
unsigned mesh_size = static_cast<unsigned>(get<value_integer>(sym,keys::mesh_size,feature, common.vars_, 16));
|
||||
detail::image_warp_dispatcher<F> dispatcher(prj_trans, start_x, start_y, raster_width, raster_height,
|
||||
target_ext, source->ext_, offset_x, offset_y, mesh_size,
|
||||
target_query_ext, source->ext_, offset_x, offset_y, mesh_size,
|
||||
scaling_method, source->get_filter_factor(),
|
||||
opacity, comp_op, sym, feature, composite, source->nodata());
|
||||
util::apply_visitor(dispatcher, source->data_);
|
||||
}
|
||||
else
|
||||
{
|
||||
double offset_x = query_ext.minx() - ext.minx();
|
||||
double offset_y = query_ext.miny() - ext.miny();
|
||||
double image_ratio_x = ext.width() / source->data_.width();
|
||||
double image_ratio_y = ext.height() / source->data_.height();
|
||||
double eps = 1e-5;
|
||||
|
@ -256,6 +269,7 @@ void render_raster_symbolizer(raster_symbolizer const& sym,
|
|||
(std::abs(start_y) > eps);
|
||||
detail::image_dispatcher<F> dispatcher(start_x, start_y, raster_width, raster_height,
|
||||
image_ratio_x, image_ratio_y,
|
||||
offset_x, offset_y,
|
||||
scaling_method, source->get_filter_factor(),
|
||||
opacity, comp_op, sym, feature, composite, source->nodata(), scale);
|
||||
util::apply_visitor(dispatcher, source->data_);
|
||||
|
|
|
@ -68,7 +68,7 @@ gdal_datasource::gdal_datasource(parameters const& params)
|
|||
#endif
|
||||
|
||||
boost::optional<std::string> file = params.get<std::string>("file");
|
||||
if (! file) throw datasource_exception("missing <file> parameter");
|
||||
if (!file) throw datasource_exception("missing <file> parameter");
|
||||
|
||||
boost::optional<std::string> base = params.get<std::string>("base");
|
||||
if (base)
|
||||
|
|
|
@ -187,19 +187,9 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
int width = end_x - x_off;
|
||||
int height = end_y - y_off;
|
||||
|
||||
// don't process almost invisible data
|
||||
if (box.width() < 0.5)
|
||||
{
|
||||
width = 0;
|
||||
}
|
||||
if (box.height() < 0.5)
|
||||
{
|
||||
height = 0;
|
||||
}
|
||||
|
||||
//calculate actual box2d of returned raster
|
||||
box2d<double> feature_raster_extent(x_off, y_off, x_off + width, y_off + height);
|
||||
intersect = t.backward(feature_raster_extent);
|
||||
feature_raster_extent = t.backward(feature_raster_extent);
|
||||
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Raster extent=" << raster_extent_;
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: View extent=" << intersect;
|
||||
|
@ -208,374 +198,380 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
|
||||
if (width > 0 && height > 0)
|
||||
{
|
||||
double width_res = std::get<0>(q.resolution());
|
||||
double height_res = std::get<1>(q.resolution());
|
||||
int im_width = int(width_res * intersect.width() + 0.5);
|
||||
int im_height = int(height_res * intersect.height() + 0.5);
|
||||
|
||||
double filter_factor = q.get_filter_factor();
|
||||
im_width = int(im_width * filter_factor + 0.5);
|
||||
im_height = int(im_height * filter_factor + 0.5);
|
||||
|
||||
// case where we need to avoid upsampling so that the
|
||||
// image can be later scaled within raster_symbolizer
|
||||
if (im_width >= width || im_height >= height)
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Image Size=(" << width << "," << height << ")";
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Reading band=" << band_;
|
||||
if (band_ > 0) // we are querying a single band
|
||||
{
|
||||
im_width = width;
|
||||
im_height = height;
|
||||
}
|
||||
|
||||
if (im_width > 0 && im_height > 0)
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Image Size=(" << im_width << "," << im_height << ")";
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Reading band=" << band_;
|
||||
if (band_ > 0) // we are querying a single band
|
||||
GDALRasterBand * band = dataset_.GetRasterBand(band_);
|
||||
if (band_ > nbands_)
|
||||
{
|
||||
GDALRasterBand * band = dataset_.GetRasterBand(band_);
|
||||
if (band_ > nbands_)
|
||||
std::ostringstream s;
|
||||
s << "GDAL Plugin: " << band_ << " is an invalid band, dataset only has " << nbands_ << "bands";
|
||||
throw datasource_exception(s.str());
|
||||
}
|
||||
GDALDataType band_type = band->GetRasterDataType();
|
||||
switch (band_type)
|
||||
{
|
||||
case GDT_Byte:
|
||||
{
|
||||
mapnik::image_gray8 image(width, height);
|
||||
image.set(std::numeric_limits<std::uint8_t>::max());
|
||||
raster_nodata = band->GetNoDataValue(&raster_has_nodata);
|
||||
raster_io_error = band->RasterIO(GF_Read, x_off, y_off, width, height,
|
||||
image.data(), image.width(), image.height(),
|
||||
GDT_Byte, 0, 0);
|
||||
if (raster_io_error == CE_Failure)
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "GDAL Plugin: " << band_ << " is an invalid band, dataset only has " << nbands_ << "bands";
|
||||
throw datasource_exception(s.str());
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
GDALDataType band_type = band->GetRasterDataType();
|
||||
switch (band_type)
|
||||
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(feature_raster_extent, intersect, image, 0.0);
|
||||
// set nodata value to be used in raster colorizer
|
||||
if (nodata_value_) raster->set_nodata(*nodata_value_);
|
||||
else raster->set_nodata(raster_nodata);
|
||||
feature->set_raster(raster);
|
||||
break;
|
||||
}
|
||||
case GDT_Float64:
|
||||
case GDT_Float32:
|
||||
{
|
||||
mapnik::image_gray32f image(width, height);
|
||||
image.set(std::numeric_limits<float>::max());
|
||||
raster_nodata = band->GetNoDataValue(&raster_has_nodata);
|
||||
raster_io_error = band->RasterIO(GF_Read, x_off, y_off, width, height,
|
||||
image.data(), image.width(), image.height(),
|
||||
GDT_Float32, 0, 0);
|
||||
if (raster_io_error == CE_Failure)
|
||||
{
|
||||
case GDT_Byte:
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(feature_raster_extent, intersect, image, 0.0);
|
||||
// set nodata value to be used in raster colorizer
|
||||
if (nodata_value_) raster->set_nodata(*nodata_value_);
|
||||
else raster->set_nodata(raster_nodata);
|
||||
feature->set_raster(raster);
|
||||
break;
|
||||
}
|
||||
case GDT_UInt16:
|
||||
{
|
||||
mapnik::image_gray16 image(width, height);
|
||||
image.set(std::numeric_limits<std::uint16_t>::max());
|
||||
raster_nodata = band->GetNoDataValue(&raster_has_nodata);
|
||||
raster_io_error = band->RasterIO(GF_Read, x_off, y_off, width, height,
|
||||
image.data(), image.width(), image.height(),
|
||||
GDT_UInt16, 0, 0);
|
||||
if (raster_io_error == CE_Failure)
|
||||
{
|
||||
mapnik::image_gray8 image(im_width, im_height);
|
||||
image.set(std::numeric_limits<std::uint8_t>::max());
|
||||
raster_nodata = band->GetNoDataValue(&raster_has_nodata);
|
||||
raster_io_error = band->RasterIO(GF_Read, x_off, y_off, width, height,
|
||||
image.data(), image.width(), image.height(),
|
||||
GDT_Byte, 0, 0);
|
||||
if (raster_io_error == CE_Failure)
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(feature_raster_extent, intersect, image, 0.0);
|
||||
// set nodata value to be used in raster colorizer
|
||||
if (nodata_value_) raster->set_nodata(*nodata_value_);
|
||||
else raster->set_nodata(raster_nodata);
|
||||
feature->set_raster(raster);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case GDT_Int16:
|
||||
{
|
||||
mapnik::image_gray16s image(width, height);
|
||||
image.set(std::numeric_limits<std::int16_t>::max());
|
||||
raster_nodata = band->GetNoDataValue(&raster_has_nodata);
|
||||
raster_io_error = band->RasterIO(GF_Read, x_off, y_off, width, height,
|
||||
image.data(), image.width(), image.height(),
|
||||
GDT_Int16, 0, 0);
|
||||
if (raster_io_error == CE_Failure)
|
||||
{
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(feature_raster_extent, intersect, image, 0.0);
|
||||
// set nodata value to be used in raster colorizer
|
||||
if (nodata_value_) raster->set_nodata(*nodata_value_);
|
||||
else raster->set_nodata(raster_nodata);
|
||||
feature->set_raster(raster);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else // working with all bands
|
||||
{
|
||||
mapnik::image_rgba8 image(width, height);
|
||||
image.set(std::numeric_limits<std::uint32_t>::max());
|
||||
for (int i = 0; i < nbands_; ++i)
|
||||
{
|
||||
GDALRasterBand * band = dataset_.GetRasterBand(i + 1);
|
||||
#ifdef MAPNIK_LOG
|
||||
get_overview_meta(band);
|
||||
#endif
|
||||
GDALColorInterp color_interp = band->GetColorInterpretation();
|
||||
switch (color_interp)
|
||||
{
|
||||
case GCI_RedBand:
|
||||
red = band;
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found red band";
|
||||
break;
|
||||
case GCI_GreenBand:
|
||||
green = band;
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found green band";
|
||||
break;
|
||||
case GCI_BlueBand:
|
||||
blue = band;
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found blue band";
|
||||
break;
|
||||
case GCI_AlphaBand:
|
||||
alpha = band;
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found alpha band";
|
||||
break;
|
||||
case GCI_GrayIndex:
|
||||
grey = band;
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found gray band";
|
||||
break;
|
||||
case GCI_PaletteIndex:
|
||||
{
|
||||
grey = band;
|
||||
#ifdef MAPNIK_LOG
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found gray band, and colortable...";
|
||||
GDALColorTable *color_table = band->GetColorTable();
|
||||
|
||||
if (color_table)
|
||||
{
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
int count = color_table->GetColorEntryCount();
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Color Table count=" << count;
|
||||
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
const GDALColorEntry *ce = color_table->GetColorEntry (j);
|
||||
if (! ce) continue;
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Color entry RGB=" << ce->c1 << "," <<ce->c2 << "," << ce->c3;
|
||||
}
|
||||
}
|
||||
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(intersect, image, filter_factor);
|
||||
// set nodata value to be used in raster colorizer
|
||||
if (nodata_value_) raster->set_nodata(*nodata_value_);
|
||||
else raster->set_nodata(raster_nodata);
|
||||
feature->set_raster(raster);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case GDT_Float64:
|
||||
case GDT_Float32:
|
||||
case GCI_Undefined:
|
||||
#if GDAL_VERSION_NUM <= 1730
|
||||
if (nbands_ == 4)
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found undefined band (assumming alpha band)";
|
||||
alpha = band;
|
||||
}
|
||||
else
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found undefined band (assumming gray band)";
|
||||
grey = band;
|
||||
}
|
||||
#else
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found undefined band (assumming gray band)";
|
||||
grey = band;
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
MAPNIK_LOG_WARN(gdal) << "gdal_featureset: Band type unknown!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (red && green && blue)
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Processing rgb bands...";
|
||||
raster_nodata = red->GetNoDataValue(&raster_has_nodata);
|
||||
GDALColorTable *color_table = red->GetColorTable();
|
||||
bool has_nodata = nodata_value_ || raster_has_nodata;
|
||||
|
||||
// we can deduce the alpha channel from nodata in the Byte case
|
||||
// by reusing the reading of R,G,B bands directly
|
||||
if (has_nodata && !color_table && red->GetRasterDataType() == GDT_Byte)
|
||||
{
|
||||
mapnik::image_gray32f image(im_width, im_height);
|
||||
image.set(std::numeric_limits<float>::max());
|
||||
raster_nodata = band->GetNoDataValue(&raster_has_nodata);
|
||||
raster_io_error = band->RasterIO(GF_Read, x_off, y_off, width, height,
|
||||
image.data(), image.width(), image.height(),
|
||||
double apply_nodata = nodata_value_ ? *nodata_value_ : raster_nodata;
|
||||
// read the data in and create an alpha channel from the nodata values
|
||||
// TODO - we assume here the nodata value for the red band applies to all bands
|
||||
// more details about this at http://trac.osgeo.org/gdal/ticket/2734
|
||||
float* imageData = (float*)image.bytes();
|
||||
raster_io_error = red->RasterIO(GF_Read, x_off, y_off, width, height,
|
||||
imageData, image.width(), image.height(),
|
||||
GDT_Float32, 0, 0);
|
||||
if (raster_io_error == CE_Failure) {
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
int len = image.width() * image.height();
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
if (std::fabs(apply_nodata - imageData[i]) < nodata_tolerance_)
|
||||
{
|
||||
*reinterpret_cast<unsigned *>(&imageData[i]) = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*reinterpret_cast<unsigned *>(&imageData[i]) = 0xFFFFFFFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Use dataset RasterIO in priority in 99.9% of the cases */
|
||||
if( red->GetBand() == 1 && green->GetBand() == 2 && blue->GetBand() == 3 )
|
||||
{
|
||||
int nBandsToRead = 3;
|
||||
if( alpha != nullptr && alpha->GetBand() == 4 && !raster_has_nodata )
|
||||
{
|
||||
nBandsToRead = 4;
|
||||
alpha = nullptr; // to avoid reading it again afterwards
|
||||
}
|
||||
raster_io_error = dataset_.RasterIO(GF_Read, x_off, y_off, width, height,
|
||||
image.bytes(),
|
||||
image.width(), image.height(), GDT_Byte,
|
||||
nBandsToRead, nullptr,
|
||||
4, 4 * image.width(), 1);
|
||||
if (raster_io_error == CE_Failure) {
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
raster_io_error = red->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 0,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
if (raster_io_error == CE_Failure) {
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
raster_io_error = green->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 1,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
if (raster_io_error == CE_Failure) {
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
raster_io_error = blue->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 2,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
if (raster_io_error == CE_Failure) {
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
}
|
||||
|
||||
// In the case we skipped initializing the alpha channel
|
||||
if (has_nodata && !color_table && red->GetRasterDataType() == GDT_Byte)
|
||||
{
|
||||
double apply_nodata = nodata_value_ ? *nodata_value_ : raster_nodata;
|
||||
if( apply_nodata >= 0 && apply_nodata <= 255 )
|
||||
{
|
||||
int len = image.width() * image.height();
|
||||
GByte* pabyBytes = (GByte*) image.bytes();
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
// TODO - we assume here the nodata value for the red band applies to all bands
|
||||
// more details about this at http://trac.osgeo.org/gdal/ticket/2734
|
||||
if (std::fabs(apply_nodata - pabyBytes[4*i]) < nodata_tolerance_)
|
||||
pabyBytes[4*i + 3] = 0;
|
||||
else
|
||||
pabyBytes[4*i + 3] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (grey)
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Processing gray band...";
|
||||
raster_nodata = grey->GetNoDataValue(&raster_has_nodata);
|
||||
GDALColorTable* color_table = grey->GetColorTable();
|
||||
bool has_nodata = nodata_value_ || raster_has_nodata;
|
||||
if (!color_table && has_nodata)
|
||||
{
|
||||
double apply_nodata = nodata_value_ ? *nodata_value_ : raster_nodata;
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: applying nodata value for layer=" << apply_nodata;
|
||||
// first read the data in and create an alpha channel from the nodata values
|
||||
float* imageData = (float*)image.bytes();
|
||||
raster_io_error = grey->RasterIO(GF_Read, x_off, y_off, width, height,
|
||||
imageData, image.width(), image.height(),
|
||||
GDT_Float32, 0, 0);
|
||||
if (raster_io_error == CE_Failure)
|
||||
{
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(intersect, image, filter_factor);
|
||||
// set nodata value to be used in raster colorizer
|
||||
if (nodata_value_) raster->set_nodata(*nodata_value_);
|
||||
else raster->set_nodata(raster_nodata);
|
||||
feature->set_raster(raster);
|
||||
break;
|
||||
}
|
||||
case GDT_UInt16:
|
||||
{
|
||||
mapnik::image_gray16 image(im_width, im_height);
|
||||
image.set(std::numeric_limits<std::uint16_t>::max());
|
||||
raster_nodata = band->GetNoDataValue(&raster_has_nodata);
|
||||
raster_io_error = band->RasterIO(GF_Read, x_off, y_off, width, height,
|
||||
image.data(), image.width(), image.height(),
|
||||
GDT_UInt16, 0, 0);
|
||||
if (raster_io_error == CE_Failure)
|
||||
int len = image.width() * image.height();
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(intersect, image, filter_factor);
|
||||
// set nodata value to be used in raster colorizer
|
||||
if (nodata_value_) raster->set_nodata(*nodata_value_);
|
||||
else raster->set_nodata(raster_nodata);
|
||||
feature->set_raster(raster);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case GDT_Int16:
|
||||
{
|
||||
mapnik::image_gray16s image(im_width, im_height);
|
||||
image.set(std::numeric_limits<std::int16_t>::max());
|
||||
raster_nodata = band->GetNoDataValue(&raster_has_nodata);
|
||||
raster_io_error = band->RasterIO(GF_Read, x_off, y_off, width, height,
|
||||
image.data(), image.width(), image.height(),
|
||||
GDT_Int16, 0, 0);
|
||||
if (raster_io_error == CE_Failure)
|
||||
{
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(intersect, image, filter_factor);
|
||||
// set nodata value to be used in raster colorizer
|
||||
if (nodata_value_) raster->set_nodata(*nodata_value_);
|
||||
else raster->set_nodata(raster_nodata);
|
||||
feature->set_raster(raster);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else // working with all bands
|
||||
{
|
||||
mapnik::image_rgba8 image(im_width, im_height);
|
||||
image.set(std::numeric_limits<std::uint32_t>::max());
|
||||
for (int i = 0; i < nbands_; ++i)
|
||||
{
|
||||
GDALRasterBand * band = dataset_.GetRasterBand(i + 1);
|
||||
#ifdef MAPNIK_LOG
|
||||
get_overview_meta(band);
|
||||
#endif
|
||||
GDALColorInterp color_interp = band->GetColorInterpretation();
|
||||
switch (color_interp)
|
||||
{
|
||||
case GCI_RedBand:
|
||||
red = band;
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found red band";
|
||||
break;
|
||||
case GCI_GreenBand:
|
||||
green = band;
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found green band";
|
||||
break;
|
||||
case GCI_BlueBand:
|
||||
blue = band;
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found blue band";
|
||||
break;
|
||||
case GCI_AlphaBand:
|
||||
alpha = band;
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found alpha band";
|
||||
break;
|
||||
case GCI_GrayIndex:
|
||||
grey = band;
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found gray band";
|
||||
break;
|
||||
case GCI_PaletteIndex:
|
||||
{
|
||||
grey = band;
|
||||
#ifdef MAPNIK_LOG
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found gray band, and colortable...";
|
||||
GDALColorTable *color_table = band->GetColorTable();
|
||||
|
||||
if (color_table)
|
||||
if (std::fabs(apply_nodata - imageData[i]) < nodata_tolerance_)
|
||||
{
|
||||
int count = color_table->GetColorEntryCount();
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Color Table count=" << count;
|
||||
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
const GDALColorEntry *ce = color_table->GetColorEntry (j);
|
||||
if (! ce) continue;
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Color entry RGB=" << ce->c1 << "," <<ce->c2 << "," << ce->c3;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case GCI_Undefined:
|
||||
#if GDAL_VERSION_NUM <= 1730
|
||||
if (nbands_ == 4)
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found undefined band (assumming alpha band)";
|
||||
alpha = band;
|
||||
*reinterpret_cast<unsigned *>(&imageData[i]) = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found undefined band (assumming gray band)";
|
||||
grey = band;
|
||||
*reinterpret_cast<unsigned *>(&imageData[i]) = 0xFFFFFFFF;
|
||||
}
|
||||
#else
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found undefined band (assumming gray band)";
|
||||
grey = band;
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
MAPNIK_LOG_WARN(gdal) << "gdal_featureset: Band type unknown!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (red && green && blue)
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Processing rgb bands...";
|
||||
raster_nodata = red->GetNoDataValue(&raster_has_nodata);
|
||||
GDALColorTable *color_table = red->GetColorTable();
|
||||
bool has_nodata = nodata_value_ || raster_has_nodata;
|
||||
|
||||
// we can deduce the alpha channel from nodata in the Byte case
|
||||
// by reusing the reading of R,G,B bands directly
|
||||
if (has_nodata && !color_table && red->GetRasterDataType() == GDT_Byte)
|
||||
raster_io_error = grey->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 0,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
if (raster_io_error == CE_Failure)
|
||||
{
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
|
||||
raster_io_error = grey->RasterIO(GF_Read,x_off, y_off, width, height, image.bytes() + 1,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
if (raster_io_error == CE_Failure)
|
||||
{
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
|
||||
raster_io_error = grey->RasterIO(GF_Read,x_off, y_off, width, height, image.bytes() + 2,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
|
||||
if (raster_io_error == CE_Failure)
|
||||
{
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
|
||||
if (color_table)
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Loading color table...";
|
||||
for (unsigned y = 0; y < image.height(); ++y)
|
||||
{
|
||||
double apply_nodata = nodata_value_ ? *nodata_value_ : raster_nodata;
|
||||
// read the data in and create an alpha channel from the nodata values
|
||||
// TODO - we assume here the nodata value for the red band applies to all bands
|
||||
// more details about this at http://trac.osgeo.org/gdal/ticket/2734
|
||||
float* imageData = (float*)image.bytes();
|
||||
raster_io_error = red->RasterIO(GF_Read, x_off, y_off, width, height,
|
||||
imageData, image.width(), image.height(),
|
||||
GDT_Float32, 0, 0);
|
||||
if (raster_io_error == CE_Failure) {
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
int len = image.width() * image.height();
|
||||
for (int i = 0; i < len; ++i)
|
||||
unsigned int* row = image.get_row(y);
|
||||
for (unsigned x = 0; x < image.width(); ++x)
|
||||
{
|
||||
if (std::fabs(apply_nodata - imageData[i]) < nodata_tolerance_)
|
||||
unsigned value = row[x] & 0xff;
|
||||
const GDALColorEntry *ce = color_table->GetColorEntry(value);
|
||||
if (ce)
|
||||
{
|
||||
*reinterpret_cast<unsigned *>(&imageData[i]) = 0;
|
||||
row[x] = (ce->c4 << 24)| (ce->c3 << 16) | (ce->c2 << 8) | (ce->c1) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
*reinterpret_cast<unsigned *>(&imageData[i]) = 0xFFFFFFFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Use dataset RasterIO in priority in 99.9% of the cases */
|
||||
if( red->GetBand() == 1 && green->GetBand() == 2 && blue->GetBand() == 3 )
|
||||
{
|
||||
int nBandsToRead = 3;
|
||||
if( alpha != nullptr && alpha->GetBand() == 4 && !raster_has_nodata )
|
||||
{
|
||||
nBandsToRead = 4;
|
||||
alpha = nullptr; // to avoid reading it again afterwards
|
||||
}
|
||||
raster_io_error = dataset_.RasterIO(GF_Read, x_off, y_off, width, height,
|
||||
image.bytes(),
|
||||
image.width(), image.height(), GDT_Byte,
|
||||
nBandsToRead, nullptr,
|
||||
4, 4 * image.width(), 1);
|
||||
if (raster_io_error == CE_Failure) {
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
raster_io_error = red->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 0,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
if (raster_io_error == CE_Failure) {
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
raster_io_error = green->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 1,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
if (raster_io_error == CE_Failure) {
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
raster_io_error = blue->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 2,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
if (raster_io_error == CE_Failure) {
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
}
|
||||
|
||||
// In the case we skipped initializing the alpha channel
|
||||
if (has_nodata && !color_table && red->GetRasterDataType() == GDT_Byte)
|
||||
{
|
||||
double apply_nodata = nodata_value_ ? *nodata_value_ : raster_nodata;
|
||||
if( apply_nodata >= 0 && apply_nodata <= 255 )
|
||||
{
|
||||
int len = image.width() * image.height();
|
||||
GByte* pabyBytes = (GByte*) image.bytes();
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
// TODO - we assume here the nodata value for the red band applies to all bands
|
||||
// more details about this at http://trac.osgeo.org/gdal/ticket/2734
|
||||
if (std::fabs(apply_nodata - pabyBytes[4*i]) < nodata_tolerance_)
|
||||
pabyBytes[4*i + 3] = 0;
|
||||
else
|
||||
pabyBytes[4*i + 3] = 255;
|
||||
// make lacking color entry fully alpha
|
||||
// note - gdal_translate makes black
|
||||
row[x] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (grey)
|
||||
}
|
||||
if (alpha)
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: processing alpha band...";
|
||||
if (!raster_has_nodata)
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Processing gray band...";
|
||||
raster_nodata = grey->GetNoDataValue(&raster_has_nodata);
|
||||
GDALColorTable* color_table = grey->GetColorTable();
|
||||
bool has_nodata = nodata_value_ || raster_has_nodata;
|
||||
if (!color_table && has_nodata)
|
||||
{
|
||||
double apply_nodata = nodata_value_ ? *nodata_value_ : raster_nodata;
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: applying nodata value for layer=" << apply_nodata;
|
||||
// first read the data in and create an alpha channel from the nodata values
|
||||
float* imageData = (float*)image.bytes();
|
||||
raster_io_error = grey->RasterIO(GF_Read, x_off, y_off, width, height,
|
||||
imageData, image.width(), image.height(),
|
||||
GDT_Float32, 0, 0);
|
||||
if (raster_io_error == CE_Failure)
|
||||
{
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
int len = image.width() * image.height();
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
if (std::fabs(apply_nodata - imageData[i]) < nodata_tolerance_)
|
||||
{
|
||||
*reinterpret_cast<unsigned *>(&imageData[i]) = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*reinterpret_cast<unsigned *>(&imageData[i]) = 0xFFFFFFFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
raster_io_error = grey->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 0,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
if (raster_io_error == CE_Failure)
|
||||
{
|
||||
raster_io_error = alpha->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 3,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
if (raster_io_error == CE_Failure) {
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
|
||||
raster_io_error = grey->RasterIO(GF_Read,x_off, y_off, width, height, image.bytes() + 1,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
if (raster_io_error == CE_Failure)
|
||||
{
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
|
||||
raster_io_error = grey->RasterIO(GF_Read,x_off, y_off, width, height, image.bytes() + 2,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
|
||||
if (raster_io_error == CE_Failure)
|
||||
{
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
|
||||
if (color_table)
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Loading color table...";
|
||||
for (unsigned y = 0; y < image.height(); ++y)
|
||||
{
|
||||
unsigned int* row = image.get_row(y);
|
||||
for (unsigned x = 0; x < image.width(); ++x)
|
||||
{
|
||||
unsigned value = row[x] & 0xff;
|
||||
const GDALColorEntry *ce = color_table->GetColorEntry(value);
|
||||
if (ce)
|
||||
{
|
||||
row[x] = (ce->c4 << 24)| (ce->c3 << 16) | (ce->c2 << 8) | (ce->c1) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// make lacking color entry fully alpha
|
||||
// note - gdal_translate makes black
|
||||
row[x] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (alpha)
|
||||
else
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: processing alpha band...";
|
||||
MAPNIK_LOG_WARN(gdal) << "warning: nodata value (" << raster_nodata << ") used to set transparency instead of alpha band";
|
||||
}
|
||||
}
|
||||
else if( dataset_.GetRasterCount() > 0 && dataset_.GetRasterBand(1) )
|
||||
{
|
||||
// Check if we have a non-alpha mask band (for example a TIFF internal mask)
|
||||
int flags = dataset_.GetRasterBand(1)->GetMaskFlags();
|
||||
GDALRasterBand* mask = 0;
|
||||
if (flags == GMF_PER_DATASET)
|
||||
{
|
||||
mask = dataset_.GetRasterBand(1)->GetMaskBand();
|
||||
}
|
||||
if (mask)
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: found and processing mask band...";
|
||||
if (!raster_has_nodata)
|
||||
{
|
||||
raster_io_error = alpha->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 3,
|
||||
raster_io_error = mask->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 3,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
if (raster_io_error == CE_Failure) {
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
|
@ -583,48 +579,22 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
}
|
||||
else
|
||||
{
|
||||
MAPNIK_LOG_WARN(gdal) << "warning: nodata value (" << raster_nodata << ") used to set transparency instead of alpha band";
|
||||
MAPNIK_LOG_WARN(gdal) << "warning: nodata value (" << raster_nodata << ") used to set transparency instead of mask band";
|
||||
}
|
||||
}
|
||||
else if( dataset_.GetRasterCount() > 0 && dataset_.GetRasterBand(1) )
|
||||
{
|
||||
// Check if we have a non-alpha mask band (for example a TIFF internal mask)
|
||||
int flags = dataset_.GetRasterBand(1)->GetMaskFlags();
|
||||
GDALRasterBand* mask = 0;
|
||||
if (flags == GMF_PER_DATASET)
|
||||
{
|
||||
mask = dataset_.GetRasterBand(1)->GetMaskBand();
|
||||
}
|
||||
if (mask)
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: found and processing mask band...";
|
||||
if (!raster_has_nodata)
|
||||
{
|
||||
raster_io_error = mask->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 3,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
if (raster_io_error == CE_Failure) {
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MAPNIK_LOG_WARN(gdal) << "warning: nodata value (" << raster_nodata << ") used to set transparency instead of mask band";
|
||||
}
|
||||
}
|
||||
}
|
||||
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(intersect, image, filter_factor);
|
||||
// set nodata value to be used in raster colorizer
|
||||
if (nodata_value_) raster->set_nodata(*nodata_value_);
|
||||
else raster->set_nodata(raster_nodata);
|
||||
feature->set_raster(raster);
|
||||
}
|
||||
// report actual/original source nodata in feature attributes
|
||||
if (raster_has_nodata)
|
||||
{
|
||||
feature->put("nodata",raster_nodata);
|
||||
}
|
||||
return feature;
|
||||
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(feature_raster_extent, intersect, image, 0.0);
|
||||
// set nodata value to be used in raster colorizer
|
||||
if (nodata_value_) raster->set_nodata(*nodata_value_);
|
||||
else raster->set_nodata(raster_nodata);
|
||||
feature->set_raster(raster);
|
||||
}
|
||||
// report actual/original source nodata in feature attributes
|
||||
if (raster_has_nodata)
|
||||
{
|
||||
feature->put("nodata",raster_nodata);
|
||||
}
|
||||
return feature;
|
||||
}
|
||||
return feature_ptr();
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ raster_datasource::raster_datasource(parameters const& params)
|
|||
filename_ = *file;
|
||||
|
||||
multi_tiles_ = *params.get<mapnik::boolean_type>("multi", false);
|
||||
tile_size_ = *params.get<mapnik::value_integer>("tile_size", 256);
|
||||
tile_size_ = *params.get<mapnik::value_integer>("tile_size", 1024);
|
||||
tile_stride_ = *params.get<mapnik::value_integer>("tile_stride", 1);
|
||||
|
||||
boost::optional<std::string> format_from_filename = mapnik::type_from_filename(*file);
|
||||
|
|
|
@ -89,33 +89,34 @@ feature_ptr raster_featureset<LookupPolicy>::next()
|
|||
box2d<double> intersect = bbox_.intersect(curIter_->envelope());
|
||||
box2d<double> ext = t.forward(intersect);
|
||||
box2d<double> rem = policy_.transform(ext);
|
||||
if (ext.width() > 0.5 && ext.height() > 0.5 )
|
||||
{
|
||||
// select minimum raster containing whole ext
|
||||
int x_off = static_cast<int>(std::floor(ext.minx()));
|
||||
int y_off = static_cast<int>(std::floor(ext.miny()));
|
||||
int end_x = static_cast<int>(std::ceil(ext.maxx()));
|
||||
int end_y = static_cast<int>(std::ceil(ext.maxy()));
|
||||
// select minimum raster containing whole ext
|
||||
int x_off = static_cast<int>(std::floor(ext.minx()));
|
||||
int y_off = static_cast<int>(std::floor(ext.miny()));
|
||||
int end_x = static_cast<int>(std::ceil(ext.maxx()));
|
||||
int end_y = static_cast<int>(std::ceil(ext.maxy()));
|
||||
|
||||
// clip to available data
|
||||
if (x_off < 0) x_off = 0;
|
||||
if (y_off < 0) y_off = 0;
|
||||
if (end_x > image_width) end_x = image_width;
|
||||
if (end_y > image_height) end_y = image_height;
|
||||
// clip to available data
|
||||
if (x_off >= image_width) x_off = image_width - 1;
|
||||
if (y_off >= image_width) y_off = image_width - 1;
|
||||
if (x_off < 0) x_off = 0;
|
||||
if (y_off < 0) y_off = 0;
|
||||
if (end_x > image_width) end_x = image_width;
|
||||
if (end_y > image_height) end_y = image_height;
|
||||
|
||||
int width = end_x - x_off;
|
||||
int height = end_y - y_off;
|
||||
int width = end_x - x_off;
|
||||
int height = end_y - y_off;
|
||||
if (width < 1) width = 1;
|
||||
if (height < 1) height = 1;
|
||||
|
||||
// calculate actual box2d of returned raster
|
||||
box2d<double> feature_raster_extent(rem.minx() + x_off,
|
||||
rem.miny() + y_off,
|
||||
rem.maxx() + x_off + width,
|
||||
rem.maxy() + y_off + height);
|
||||
intersect = t.backward(feature_raster_extent);
|
||||
mapnik::image_any data = reader->read(x_off, y_off, width, height);
|
||||
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(intersect, std::move(data), 1.0);
|
||||
feature->set_raster(raster);
|
||||
}
|
||||
// calculate actual box2d of returned raster
|
||||
box2d<double> feature_raster_extent(rem.minx() + x_off,
|
||||
rem.miny() + y_off,
|
||||
rem.maxx() + x_off + width,
|
||||
rem.maxy() + y_off + height);
|
||||
feature_raster_extent = t.backward(feature_raster_extent);
|
||||
mapnik::image_any data = reader->read(x_off, y_off, width, height);
|
||||
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(feature_raster_extent, intersect, std::move(data), 1.0);
|
||||
feature->set_raster(raster);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,6 +133,7 @@ void scale_image_agg(T & target, T const& source, scaling_method_e scaling_metho
|
|||
|
||||
// create a scaling matrix
|
||||
agg::trans_affine img_mtx;
|
||||
img_mtx *= agg::trans_affine_translation(x_off_f, y_off_f);
|
||||
img_mtx /= agg::trans_affine_scaling(image_ratio_x, image_ratio_y);
|
||||
|
||||
// create a linear interpolator for our scaling matrix
|
||||
|
@ -141,11 +142,10 @@ void scale_image_agg(T & target, T const& source, scaling_method_e scaling_metho
|
|||
double scaled_width = target.width();
|
||||
double scaled_height = target.height();
|
||||
ras.reset();
|
||||
ras.move_to_d(x_off_f, y_off_f);
|
||||
ras.line_to_d(x_off_f + scaled_width, y_off_f);
|
||||
ras.line_to_d(x_off_f + scaled_width, y_off_f + scaled_height);
|
||||
ras.line_to_d(x_off_f, y_off_f + scaled_height);
|
||||
|
||||
ras.move_to_d(0.0, 0.0);
|
||||
ras.line_to_d(scaled_width, 0.0);
|
||||
ras.line_to_d(scaled_width, scaled_height);
|
||||
ras.line_to_d(0.0, scaled_height);
|
||||
if (scaling_method == SCALING_NEAR)
|
||||
{
|
||||
using span_gen_type = typename detail::agg_scaling_traits<image_type>::span_image_filter;
|
||||
|
|
|
@ -162,8 +162,12 @@ private:
|
|||
tiff_reader(const tiff_reader&);
|
||||
tiff_reader& operator=(const tiff_reader&);
|
||||
void init();
|
||||
void read_generic(std::size_t x,std::size_t y,image_rgba8& image);
|
||||
void read_stripped(std::size_t x,std::size_t y,image_rgba8& image);
|
||||
|
||||
template <typename ImageData>
|
||||
void read_generic(std::size_t x,std::size_t y, ImageData & image);
|
||||
|
||||
template <typename ImageData>
|
||||
void read_stripped(std::size_t x,std::size_t y, ImageData & image);
|
||||
|
||||
template <typename ImageData>
|
||||
void read_tiled(std::size_t x,std::size_t y, ImageData & image);
|
||||
|
@ -257,25 +261,24 @@ void tiff_reader<T>::init()
|
|||
TIFFGetField(tif,TIFFTAG_PHOTOMETRIC,&photometric_);
|
||||
TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &bands_);
|
||||
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "bits per sample: " << bps_;
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "sample format: " << sample_format_;
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "photometric: " << photometric_;
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "bands: " << bands_;
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "bits per sample: " << bps_ ;
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "sample format: " << sample_format_ ;
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "photometric: " << photometric_ ;
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "bands: " << bands_ ;
|
||||
|
||||
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width_);
|
||||
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height_);
|
||||
|
||||
TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &planar_config_);
|
||||
TIFFGetField(tif, TIFFTAG_COMPRESSION, &compression_ );
|
||||
TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rows_per_strip_);
|
||||
|
||||
std::uint16_t orientation;
|
||||
if (TIFFGetField(tif, TIFFTAG_ORIENTATION, &orientation) == 0)
|
||||
{
|
||||
orientation = 1;
|
||||
}
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "orientation: " << orientation;
|
||||
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "orientation: " << orientation ;
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "planar-config: " << planar_config_ ;
|
||||
is_tiled_ = TIFFIsTiled(tif);
|
||||
|
||||
if (is_tiled_)
|
||||
|
@ -285,7 +288,7 @@ void tiff_reader<T>::init()
|
|||
MAPNIK_LOG_DEBUG(tiff_reader) << "tiff is tiled";
|
||||
read_method_ = tiled;
|
||||
}
|
||||
else if (TIFFGetField(tif,TIFFTAG_ROWSPERSTRIP,&rows_per_strip_)!=0)
|
||||
else if (TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rows_per_strip_) != 0)
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "tiff is stripped";
|
||||
read_method_ = stripped;
|
||||
|
@ -311,9 +314,9 @@ void tiff_reader<T>::init()
|
|||
if (TIFFGetField(tif, 33550, &count, &pixelscale) == 1 && count == 3
|
||||
&& TIFFGetField(tif, 33922 , &count, &tilepoint) == 1 && count == 6)
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "PixelScale:" << pixelscale[0] << "," << pixelscale[1] << "," << pixelscale[2];
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "TilePoint:" << tilepoint[0] << "," << tilepoint[1] << "," << tilepoint[2];
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << " " << tilepoint[3] << "," << tilepoint[4] << "," << tilepoint[5];
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "PixelScale:" << pixelscale[0] << "," << pixelscale[1] << "," << pixelscale[2] ;
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "TilePoint:" << tilepoint[0] << "," << tilepoint[1] << "," << tilepoint[2] ;
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << " " << tilepoint[3] << "," << tilepoint[4] << "," << tilepoint[5] ;
|
||||
|
||||
// assuming upper-left
|
||||
double lox = tilepoint[3];
|
||||
|
@ -321,7 +324,7 @@ void tiff_reader<T>::init()
|
|||
double hix = lox + pixelscale[0] * width_;
|
||||
double hiy = loy - pixelscale[1] * height_;
|
||||
bbox_.reset(box2d<double>(lox, loy, hix, hiy));
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "Bounding Box:" << *bbox_;
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "Bounding Box:" << *bbox_ ;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -391,10 +394,17 @@ image_any tiff_reader<T>::read_any_gray(std::size_t x0, std::size_t y0, std::siz
|
|||
using pixel_type = typename image_type::pixel_type;
|
||||
if (read_method_ == tiled)
|
||||
{
|
||||
image_type data(width,height);
|
||||
image_type data(width, height);
|
||||
read_tiled<image_type>(x0, y0, data);
|
||||
return image_any(std::move(data));
|
||||
}
|
||||
// TODO: temp disable and default to `scanline` method for stripped images.
|
||||
else if (read_method_ == stripped)
|
||||
{
|
||||
image_type data(width, height);
|
||||
read_stripped<image_type>(x0, y0, data);
|
||||
return image_any(std::move(data));
|
||||
}
|
||||
else
|
||||
{
|
||||
TIFF* tif = open(stream_);
|
||||
|
@ -407,14 +417,52 @@ image_any tiff_reader<T>::read_any_gray(std::size_t x0, std::size_t y0, std::siz
|
|||
std::size_t start_x = x0;
|
||||
std::size_t end_x = std::min(x0 + width, width_);
|
||||
std::size_t element_size = sizeof(pixel_type);
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "SCANLINE SIZE=" << TIFFScanlineSize(tif);
|
||||
std::size_t size_to_allocate = (TIFFScanlineSize(tif) + element_size - 1)/element_size;
|
||||
const std::unique_ptr<pixel_type[]> scanline(new pixel_type[size_to_allocate]);
|
||||
for (std::size_t y = start_y; y < end_y; ++y)
|
||||
std::unique_ptr<pixel_type[]> const scanline(new pixel_type[size_to_allocate]);
|
||||
if (planar_config_ == PLANARCONFIG_CONTIG)
|
||||
{
|
||||
if (-1 != TIFFReadScanline(tif, scanline.get(), y) && (y >= y0))
|
||||
for (std::size_t y = start_y; y < end_y; ++y)
|
||||
{
|
||||
pixel_type * row = data.get_row(y - y0);
|
||||
std::transform(scanline.get() + start_x, scanline.get() + end_x, row, [](pixel_type const& p) { return p;});
|
||||
// we have to read all scanlines sequentially from start_y
|
||||
// to be able to use scanline interface with compressed blocks.
|
||||
if (-1 != TIFFReadScanline(tif, scanline.get(), y) && (y >= y0))
|
||||
{
|
||||
pixel_type * row = data.get_row(y - y0);
|
||||
if (bands_ == 1)
|
||||
{
|
||||
std::transform(scanline.get() + start_x, scanline.get() + end_x, row, [](pixel_type const& p) { return p;});
|
||||
}
|
||||
else if (size_to_allocate == bands_ * width_)
|
||||
{
|
||||
// bands_ > 1 => packed bands in grayscale image e.g an extra alpha channel.
|
||||
// Just pick first one for now.
|
||||
pixel_type * buf = scanline.get() + start_x * bands_;
|
||||
std::size_t x_index = 0;
|
||||
for (std::size_t j = 0; j < end_x * bands_; ++j)
|
||||
{
|
||||
if (x_index >= width) break;
|
||||
if (j % bands_ == 0)
|
||||
{
|
||||
row[x_index++] = buf[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (planar_config_ == PLANARCONFIG_SEPARATE)
|
||||
{
|
||||
for (std::size_t s = 0 ; s < bands_ ; ++s)
|
||||
{
|
||||
for (std::size_t y = start_y; y < end_y; ++y)
|
||||
{
|
||||
if (-1 != TIFFReadScanline(tif, scanline.get(), y) && (y >= y0))
|
||||
{
|
||||
pixel_type * row = data.get_row(y - y0);
|
||||
std::transform(scanline.get() + start_x, scanline.get() + end_x, row, [](pixel_type const& p) { return p;});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return image_any(std::move(data));
|
||||
|
@ -446,9 +494,17 @@ struct tiff_reader_traits
|
|||
{
|
||||
using image_type = T;
|
||||
using pixel_type = typename image_type::pixel_type;
|
||||
|
||||
constexpr static bool reverse = false;
|
||||
static bool read_tile(TIFF * tif, std::size_t x, std::size_t y, pixel_type* buf, std::size_t tile_width, std::size_t tile_height)
|
||||
{
|
||||
return (TIFFReadEncodedTile(tif, TIFFComputeTile(tif, x,y,0,0), buf, tile_width * tile_height * sizeof(pixel_type)) != -1);
|
||||
std::uint32_t tile_size = TIFFTileSize(tif);
|
||||
return (TIFFReadEncodedTile(tif, TIFFComputeTile(tif, x, y, 0, 0), buf, tile_size) != -1);
|
||||
}
|
||||
|
||||
static bool read_strip(TIFF * tif, std::size_t y, std::size_t rows_per_strip, std::size_t strip_width, pixel_type * buf)
|
||||
{
|
||||
return (TIFFReadEncodedStrip(tif, y/rows_per_strip, buf, -1) != -1);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -456,18 +512,17 @@ struct tiff_reader_traits
|
|||
template <>
|
||||
struct tiff_reader_traits<image_rgba8>
|
||||
{
|
||||
using image_type = image_rgba8;
|
||||
using pixel_type = std::uint32_t;
|
||||
constexpr static bool reverse = true;
|
||||
static bool read_tile(TIFF * tif, std::size_t x0, std::size_t y0, pixel_type* buf, std::size_t tile_width, std::size_t tile_height)
|
||||
{
|
||||
if (TIFFReadRGBATile(tif, x0, y0, buf) != -1)
|
||||
{
|
||||
for (std::size_t y = 0; y < tile_height/2; ++y)
|
||||
{
|
||||
std::swap_ranges(buf + y * tile_width, buf + (y + 1) * tile_width, buf + (tile_height - y - 1) * tile_width);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return (TIFFReadRGBATile(tif, x0, y0, buf) != 0);
|
||||
}
|
||||
|
||||
static bool read_strip(TIFF * tif, std::size_t y, std::size_t rows_per_strip, std::size_t strip_width, pixel_type * buf)
|
||||
{
|
||||
return (TIFFReadRGBAStrip(tif, y, buf) != 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -591,7 +646,8 @@ image_any tiff_reader<T>::read(unsigned x, unsigned y, unsigned width, unsigned
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
void tiff_reader<T>::read_generic(std::size_t, std::size_t, image_rgba8&)
|
||||
template <typename ImageData>
|
||||
void tiff_reader<T>::read_generic(std::size_t, std::size_t, ImageData &)
|
||||
{
|
||||
throw std::runtime_error("tiff_reader: TODO - tiff is not stripped or tiled");
|
||||
}
|
||||
|
@ -605,7 +661,8 @@ void tiff_reader<T>::read_tiled(std::size_t x0,std::size_t y0, ImageData & image
|
|||
TIFF* tif = open(stream_);
|
||||
if (tif)
|
||||
{
|
||||
std::unique_ptr<pixel_type[]> buf(new pixel_type[tile_width_*tile_height_]);
|
||||
std::uint32_t tile_size = TIFFTileSize(tif);
|
||||
std::unique_ptr<pixel_type[]> tile(new pixel_type[tile_size]);
|
||||
std::size_t width = image.width();
|
||||
std::size_t height = image.height();
|
||||
std::size_t start_y = (y0 / tile_height_) * tile_height_;
|
||||
|
@ -614,7 +671,7 @@ void tiff_reader<T>::read_tiled(std::size_t x0,std::size_t y0, ImageData & image
|
|||
std::size_t end_x = ((x0 + width) / tile_width_ + 1) * tile_width_;
|
||||
end_y = std::min(end_y, height_);
|
||||
end_x = std::min(end_x, width_);
|
||||
|
||||
bool pick_first_band = (bands_ > 1) && (tile_size / (tile_width_ * tile_height_ * sizeof(pixel_type)) == bands_);
|
||||
for (std::size_t y = start_y; y < end_y; y += tile_height_)
|
||||
{
|
||||
std::size_t ty0 = std::max(y0, y) - y;
|
||||
|
@ -622,56 +679,98 @@ void tiff_reader<T>::read_tiled(std::size_t x0,std::size_t y0, ImageData & image
|
|||
|
||||
for (std::size_t x = start_x; x < end_x; x += tile_width_)
|
||||
{
|
||||
if (!detail::tiff_reader_traits<ImageData>::read_tile(tif, x, y, buf.get(), tile_width_, tile_height_))
|
||||
if (!detail::tiff_reader_traits<ImageData>::read_tile(tif, x, y, tile.get(), tile_width_, tile_height_))
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "read_tile(...) failed at " << x << "/" << y << " for " << width_ << "/" << height_ << "\n";
|
||||
break;
|
||||
}
|
||||
if (pick_first_band)
|
||||
{
|
||||
std::uint32_t size = tile_width_ * tile_height_ * sizeof(pixel_type);
|
||||
for (std::uint32_t n = 0; n < size; ++n)
|
||||
{
|
||||
tile[n] = tile[n * bands_];
|
||||
}
|
||||
}
|
||||
std::size_t tx0 = std::max(x0, x);
|
||||
std::size_t tx1 = std::min(width + x0, x + tile_width_);
|
||||
std::size_t row = y + ty0 - y0;
|
||||
for (std::size_t ty = ty0; ty < ty1; ++ty, ++row)
|
||||
std::size_t row_index = y + ty0 - y0;
|
||||
|
||||
if (detail::tiff_reader_traits<ImageData>::reverse)
|
||||
{
|
||||
image.set_row(row, tx0 - x0, tx1 - x0, &buf[ty * tile_width_ + tx0 - x]);
|
||||
for (std::size_t ty = ty0; ty < ty1; ++ty, ++row_index)
|
||||
{
|
||||
// This is in reverse because the TIFFReadRGBATile reads are inverted
|
||||
image.set_row(row_index, tx0 - x0, tx1 - x0, &tile[(tile_height_ - ty - 1) * tile_width_ + tx0 - x]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (std::size_t ty = ty0; ty < ty1; ++ty, ++row_index)
|
||||
{
|
||||
image.set_row(row_index, tx0 - x0, tx1 - x0, &tile[ty * tile_width_ + tx0 - x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void tiff_reader<T>::read_stripped(std::size_t x0,std::size_t y0,image_rgba8& image)
|
||||
template <typename ImageData>
|
||||
void tiff_reader<T>::read_stripped(std::size_t x0, std::size_t y0, ImageData & image)
|
||||
{
|
||||
using pixel_type = typename detail::tiff_reader_traits<ImageData>::pixel_type;
|
||||
TIFF* tif = open(stream_);
|
||||
if (tif)
|
||||
{
|
||||
image_rgba8 strip(width_,rows_per_strip_,false);
|
||||
std::size_t width=image.width();
|
||||
std::size_t height=image.height();
|
||||
std::uint32_t strip_size = TIFFStripSize(tif);
|
||||
std::unique_ptr<pixel_type[]> strip(new pixel_type[strip_size]);
|
||||
std::size_t width = image.width();
|
||||
std::size_t height = image.height();
|
||||
|
||||
std::size_t start_y=(y0/rows_per_strip_)*rows_per_strip_;
|
||||
std::size_t end_y=std::min(y0+height, height_);
|
||||
std::size_t tx0,tx1,ty0,ty1;
|
||||
std::size_t start_y = (y0 / rows_per_strip_) * rows_per_strip_;
|
||||
std::size_t end_y = std::min(y0 + height, height_);
|
||||
std::size_t tx0, tx1, ty0, ty1;
|
||||
|
||||
tx0=x0;
|
||||
tx1=std::min(width+x0,width_);
|
||||
tx0 = x0;
|
||||
tx1 = std::min(width + x0, width_);
|
||||
std::size_t row = 0;
|
||||
for (std::size_t y=start_y; y < end_y; y+=rows_per_strip_)
|
||||
bool pick_first_band = (bands_ > 1) && (strip_size / (width_ * rows_per_strip_ * sizeof(pixel_type)) == bands_);
|
||||
for (std::size_t y = start_y; y < end_y; y += rows_per_strip_)
|
||||
{
|
||||
ty0 = std::max(y0,y)-y;
|
||||
ty1 = std::min(end_y,y+rows_per_strip_)-y;
|
||||
ty0 = std::max(y0, y) - y;
|
||||
ty1 = std::min(end_y, y + rows_per_strip_) - y;
|
||||
|
||||
if (!TIFFReadRGBAStrip(tif,y,strip.data()))
|
||||
if (!detail::tiff_reader_traits<ImageData>::read_strip(tif, y, rows_per_strip_, width_, strip.get()))
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "TIFFReadRGBAStrip failed at " << y << " for " << width_ << "/" << height_ << "\n";
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "TIFFRead(Encoded|RGBA)Strip failed at " << y << " for " << width_ << "/" << height_ << "\n";
|
||||
break;
|
||||
}
|
||||
// This is in reverse because the TIFFReadRGBAStrip reads inverted
|
||||
for (std::size_t ty = ty1; ty > ty0; --ty)
|
||||
if (pick_first_band)
|
||||
{
|
||||
image.set_row(row,tx0-x0,tx1-x0,&strip.data()[(ty-1)*width_+tx0]);
|
||||
++row;
|
||||
std::uint32_t size = width_ * rows_per_strip_ * sizeof(pixel_type);
|
||||
for (std::uint32_t n = 0; n < size; ++n)
|
||||
{
|
||||
strip[n] = strip[bands_ * n];
|
||||
}
|
||||
}
|
||||
|
||||
if (detail::tiff_reader_traits<ImageData>::reverse)
|
||||
{
|
||||
std::size_t num_rows = std::min(end_y - y, static_cast<std::size_t>(rows_per_strip_));
|
||||
for (std::size_t ty = ty0; ty < ty1; ++ty)
|
||||
{
|
||||
// This is in reverse because the TIFFReadRGBAStrip reads are inverted
|
||||
image.set_row(row++, tx0 - x0, tx1 - x0, &strip[(num_rows - ty - 1) * width_ + tx0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (std::size_t ty = ty0; ty < ty1; ++ty)
|
||||
{
|
||||
image.set_row(row++, tx0 - x0, tx1 - x0, &strip[ty * width_ + tx0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit dac50a321bdcc92c6183ded08200eb8fa117532c
|
||||
Subproject commit 0d8620374bf61163872acce03f2620acee8da65e
|
|
@ -1 +1 @@
|
|||
Subproject commit 13680134c5d43c457dce3163b045b6ab70423a6b
|
||||
Subproject commit 75ecac5c3bd44f1c9111d9b3fba785a1713f2444
|
|
@ -5,280 +5,398 @@
|
|||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <mapnik/color.hpp>
|
||||
#include <mapnik/image_util.hpp>
|
||||
#include <mapnik/image_view.hpp>
|
||||
#include <mapnik/image_reader.hpp>
|
||||
#include <mapnik/util/file_io.hpp>
|
||||
#include <mapnik/util/fs.hpp>
|
||||
|
||||
#include "../../../src/tiff_reader.cpp"
|
||||
|
||||
#define TIFF_ASSERT(filename) \
|
||||
mapnik::tiff_reader<std::filebuf> tiff_reader(filename); \
|
||||
REQUIRE( tiff_reader.width() == 256 ); \
|
||||
REQUIRE( tiff_reader.height() == 256 ); \
|
||||
REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG ); \
|
||||
#define TIFF_ASSERT(filename) \
|
||||
mapnik::tiff_reader<std::filebuf> tiff_reader(filename); \
|
||||
REQUIRE( tiff_reader.width() == 256 ); \
|
||||
REQUIRE( tiff_reader.height() == 256 ); \
|
||||
REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG ); \
|
||||
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename,"tiff")); \
|
||||
REQUIRE( reader->width() == 256 ); \
|
||||
REQUIRE( reader->height() == 256 ); \
|
||||
mapnik::util::file file(filename); \
|
||||
REQUIRE( reader->width() == 256 ); \
|
||||
REQUIRE( reader->height() == 256 ); \
|
||||
mapnik::util::file file(filename); \
|
||||
mapnik::tiff_reader<mapnik::util::char_array_buffer> tiff_reader2(file.data().get(),file.size()); \
|
||||
REQUIRE( tiff_reader2.width() == 256 ); \
|
||||
REQUIRE( tiff_reader2.height() == 256 ); \
|
||||
REQUIRE( tiff_reader2.width() == 256 ); \
|
||||
REQUIRE( tiff_reader2.height() == 256 ); \
|
||||
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(file.data().get(),file.size())); \
|
||||
REQUIRE( reader2->width() == 256 ); \
|
||||
REQUIRE( reader2->height() == 256 ); \
|
||||
REQUIRE( reader2->width() == 256 ); \
|
||||
REQUIRE( reader2->height() == 256 ); \
|
||||
|
||||
#define TIFF_ASSERT_ALPHA( data ) \
|
||||
REQUIRE( tiff_reader.has_alpha() == true ); \
|
||||
REQUIRE( reader->has_alpha() == true ); \
|
||||
REQUIRE( tiff_reader2.has_alpha() == true ); \
|
||||
REQUIRE( reader2->has_alpha() == true ); \
|
||||
REQUIRE( data.get_premultiplied() == true ); \
|
||||
#define TIFF_ASSERT_ALPHA( data ) \
|
||||
REQUIRE( tiff_reader.has_alpha() == true ); \
|
||||
REQUIRE( reader->has_alpha() == true ); \
|
||||
REQUIRE( tiff_reader2.has_alpha() == true ); \
|
||||
REQUIRE( reader2->has_alpha() == true ); \
|
||||
REQUIRE( data.get_premultiplied() == true ); \
|
||||
|
||||
#define TIFF_ASSERT_NO_ALPHA_RGB( data ) \
|
||||
REQUIRE( tiff_reader.has_alpha() == false ); \
|
||||
REQUIRE( reader->has_alpha() == false ); \
|
||||
REQUIRE( tiff_reader2.has_alpha() == false ); \
|
||||
REQUIRE( reader2->has_alpha() == false ); \
|
||||
REQUIRE( data.get_premultiplied() == true ); \
|
||||
#define TIFF_ASSERT_NO_ALPHA_RGB( data ) \
|
||||
REQUIRE( tiff_reader.has_alpha() == false ); \
|
||||
REQUIRE( reader->has_alpha() == false ); \
|
||||
REQUIRE( tiff_reader2.has_alpha() == false ); \
|
||||
REQUIRE( reader2->has_alpha() == false ); \
|
||||
REQUIRE( data.get_premultiplied() == true ); \
|
||||
|
||||
#define TIFF_ASSERT_NO_ALPHA_GRAY( data ) \
|
||||
REQUIRE( tiff_reader.has_alpha() == false ); \
|
||||
REQUIRE( reader->has_alpha() == false ); \
|
||||
REQUIRE( tiff_reader2.has_alpha() == false ); \
|
||||
REQUIRE( reader2->has_alpha() == false ); \
|
||||
REQUIRE( data.get_premultiplied() == false ); \
|
||||
#define TIFF_ASSERT_NO_ALPHA_GRAY( data ) \
|
||||
REQUIRE( tiff_reader.has_alpha() == false ); \
|
||||
REQUIRE( reader->has_alpha() == false ); \
|
||||
REQUIRE( tiff_reader2.has_alpha() == false ); \
|
||||
REQUIRE( reader2->has_alpha() == false ); \
|
||||
REQUIRE( data.get_premultiplied() == false ); \
|
||||
|
||||
#define TIFF_ASSERT_SIZE( data,reader ) \
|
||||
REQUIRE( data.width() == reader->width() ); \
|
||||
REQUIRE( data.height() == reader->height() ); \
|
||||
#define TIFF_ASSERT_SIZE( data,reader ) \
|
||||
REQUIRE( data.width() == reader->width() ); \
|
||||
REQUIRE( data.height() == reader->height() ); \
|
||||
|
||||
#define TIFF_READ_ONE_PIXEL \
|
||||
mapnik::image_any subimage = reader->read(1, 1, 1, 1); \
|
||||
REQUIRE( subimage.width() == 1 ); \
|
||||
REQUIRE( subimage.height() == 1 ); \
|
||||
#define TIFF_READ_ONE_PIXEL \
|
||||
mapnik::image_any subimage = reader->read(1, 1, 1, 1); \
|
||||
REQUIRE( subimage.width() == 1 ); \
|
||||
REQUIRE( subimage.height() == 1 ); \
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename Image>
|
||||
struct test_image_traits
|
||||
{
|
||||
using value_type = mapnik::color;
|
||||
static value_type const& get_value(mapnik::color const& c)
|
||||
{
|
||||
return c;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct test_image_traits<mapnik::image_gray8>
|
||||
{
|
||||
using value_type = std::uint8_t;
|
||||
static value_type get_value(mapnik::color const& c)
|
||||
{
|
||||
return c.green(); // use green channel for gray scale images
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename Image>
|
||||
Image generate_test_image()
|
||||
{
|
||||
|
||||
std::size_t tile_size = 16;
|
||||
Image im(64, 64);
|
||||
mapnik::color colors[] = {{mapnik::color("red")},
|
||||
{mapnik::color("blue")},
|
||||
{mapnik::color("green")},
|
||||
{mapnik::color("yellow")}};
|
||||
std::size_t index = 0;
|
||||
for (std::size_t j = 0; j < im.height()/tile_size; ++j)
|
||||
{
|
||||
++index;
|
||||
for (std::size_t i = 0; i < im.width()/tile_size; ++i)
|
||||
{
|
||||
++index;
|
||||
for (std::size_t x = 0; x < tile_size; ++x)
|
||||
{
|
||||
for (std::size_t y = 0; y < tile_size; ++y)
|
||||
{
|
||||
auto value = test_image_traits<Image>::get_value(colors[index % 4]);
|
||||
mapnik::set_pixel(im, i * tile_size + x, j * tile_size + y, value );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return im;
|
||||
}
|
||||
|
||||
template <typename Image1, typename Image2>
|
||||
bool identical(Image1 const& im1, Image2 const& im2)
|
||||
{
|
||||
if ((im1.width() != im2.width()) || (im1.height() != im2.height()))
|
||||
return false;
|
||||
|
||||
for (std::size_t i = 0; i < im1.width(); ++i)
|
||||
{
|
||||
for (std::size_t j = 0; j < im1.height(); ++j)
|
||||
{
|
||||
if (im1(i,j) != im2(i,j)) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename Image>
|
||||
void test_tiff_reader(std::string const& pattern)
|
||||
{
|
||||
// generate expected image (rgba8 or gray8)
|
||||
auto im = generate_test_image<Image>();
|
||||
|
||||
for (auto const& path : mapnik::util::list_directory("test/data/tiff/"))
|
||||
{
|
||||
if (boost::iends_with(path,".tif")
|
||||
&& boost::istarts_with(mapnik::util::basename(path), pattern))
|
||||
{
|
||||
mapnik::tiff_reader<std::filebuf> tiff_reader(path);
|
||||
auto width = tiff_reader.width();
|
||||
auto height = tiff_reader.height();
|
||||
{
|
||||
// whole image
|
||||
auto tiff = tiff_reader.read(0, 0, width, height);
|
||||
CHECK(tiff.is<Image>());
|
||||
auto im2 = tiff.get<Image>();
|
||||
REQUIRE(identical(im, im2));
|
||||
}
|
||||
{
|
||||
// portion
|
||||
auto tiff = tiff_reader.read(11, 13, width - 11, height - 13);
|
||||
CHECK(tiff.is<Image>());
|
||||
auto im2 = tiff.get<Image>();
|
||||
auto view = mapnik::image_view<Image>(11, 13, width, height, im);
|
||||
REQUIRE(identical(view, im2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("tiff io")
|
||||
{
|
||||
SECTION("tiff-reader rgb8+rgba8")
|
||||
{
|
||||
test_tiff_reader<mapnik::image_rgba8>("tiff_rgb");
|
||||
}
|
||||
|
||||
SECTION("scan rgb8 striped")
|
||||
{
|
||||
std::string filename("./test/data/tiff/scan_512x512_rgb8_striped.tif");
|
||||
mapnik::tiff_reader<std::filebuf> tiff_reader(filename);
|
||||
REQUIRE( tiff_reader.width() == 512 );
|
||||
REQUIRE( tiff_reader.height() == 512 );
|
||||
REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG );
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 16 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||
REQUIRE( tiff_reader.is_tiled() == false );
|
||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_PALETTE );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
||||
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename,"tiff"));
|
||||
REQUIRE( reader->width() == 512 );
|
||||
REQUIRE( reader->height() == 512 );
|
||||
mapnik::util::file file(filename);
|
||||
mapnik::tiff_reader<mapnik::util::char_array_buffer> tiff_reader2(file.data().get(),file.size());
|
||||
REQUIRE( tiff_reader2.width() == 512 );
|
||||
REQUIRE( tiff_reader2.height() == 512 );
|
||||
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(file.data().get(),file.size()));
|
||||
REQUIRE( reader2->width() == 512 );
|
||||
REQUIRE( reader2->height() == 512 );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
SECTION("tiff-reader gray8")
|
||||
{
|
||||
test_tiff_reader<mapnik::image_gray8>("tiff_gray");
|
||||
}
|
||||
|
||||
SECTION("scan rgb8 tiled") {
|
||||
std::string filename("./test/data/tiff/scan_512x512_rgb8_tiled.tif");
|
||||
mapnik::tiff_reader<std::filebuf> tiff_reader(filename);
|
||||
REQUIRE( tiff_reader.width() == 512 );
|
||||
REQUIRE( tiff_reader.height() == 512 );
|
||||
REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG );
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||
REQUIRE( tiff_reader.is_tiled() == true );
|
||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_PALETTE );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename,"tiff"));
|
||||
REQUIRE( reader->width() == 512 );
|
||||
REQUIRE( reader->height() == 512 );
|
||||
mapnik::util::file file(filename);
|
||||
mapnik::tiff_reader<mapnik::util::char_array_buffer> tiff_reader2(file.data().get(),file.size());
|
||||
REQUIRE( tiff_reader2.width() == 512 );
|
||||
REQUIRE( tiff_reader2.height() == 512 );
|
||||
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(file.data().get(),file.size()));
|
||||
REQUIRE( reader2->width() == 512 );
|
||||
REQUIRE( reader2->height() == 512 );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
SECTION("scan rgb8 striped")
|
||||
{
|
||||
std::string filename("./test/data/tiff/scan_512x512_rgb8_striped.tif");
|
||||
mapnik::tiff_reader<std::filebuf> tiff_reader(filename);
|
||||
REQUIRE( tiff_reader.width() == 512 );
|
||||
REQUIRE( tiff_reader.height() == 512 );
|
||||
REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG );
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 16 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||
REQUIRE( tiff_reader.is_tiled() == false );
|
||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_PALETTE );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
||||
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename,"tiff"));
|
||||
REQUIRE( reader->width() == 512 );
|
||||
REQUIRE( reader->height() == 512 );
|
||||
mapnik::util::file file(filename);
|
||||
mapnik::tiff_reader<mapnik::util::char_array_buffer> tiff_reader2(file.data().get(),file.size());
|
||||
REQUIRE( tiff_reader2.width() == 512 );
|
||||
REQUIRE( tiff_reader2.height() == 512 );
|
||||
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(file.data().get(),file.size()));
|
||||
REQUIRE( reader2->width() == 512 );
|
||||
REQUIRE( reader2->height() == 512 );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
SECTION("rgba8 striped") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_rgba8_striped.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 1 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||
REQUIRE( tiff_reader.is_tiled() == false );
|
||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_RGB );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_ADOBE_DEFLATE );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_ALPHA( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
SECTION("scan rgb8 tiled") {
|
||||
std::string filename("./test/data/tiff/scan_512x512_rgb8_tiled.tif");
|
||||
mapnik::tiff_reader<std::filebuf> tiff_reader(filename);
|
||||
REQUIRE( tiff_reader.width() == 512 );
|
||||
REQUIRE( tiff_reader.height() == 512 );
|
||||
REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG );
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||
REQUIRE( tiff_reader.is_tiled() == true );
|
||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_PALETTE );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename,"tiff"));
|
||||
REQUIRE( reader->width() == 512 );
|
||||
REQUIRE( reader->height() == 512 );
|
||||
mapnik::util::file file(filename);
|
||||
mapnik::tiff_reader<mapnik::util::char_array_buffer> tiff_reader2(file.data().get(),file.size());
|
||||
REQUIRE( tiff_reader2.width() == 512 );
|
||||
REQUIRE( tiff_reader2.height() == 512 );
|
||||
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(file.data().get(),file.size()));
|
||||
REQUIRE( reader2->width() == 512 );
|
||||
REQUIRE( reader2->height() == 512 );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
SECTION("rgba8 tiled") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_rgba8_tiled.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||
REQUIRE( tiff_reader.is_tiled() == true );
|
||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_RGB );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_ALPHA( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
SECTION("rgba8 striped") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_rgba8_striped.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 1 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||
REQUIRE( tiff_reader.is_tiled() == false );
|
||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_RGB );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_ADOBE_DEFLATE );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_ALPHA( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
SECTION("rgb8 striped") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_rgb8_striped.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 10 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||
REQUIRE( tiff_reader.is_tiled() == false );
|
||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_RGB );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
SECTION("rgba8 tiled") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_rgba8_tiled.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||
REQUIRE( tiff_reader.is_tiled() == true );
|
||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_RGB );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_ALPHA( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
SECTION("rgb8 tiled") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_rgb8_tiled.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||
REQUIRE( tiff_reader.is_tiled() == true );
|
||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_RGB );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
SECTION("rgb8 striped") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_rgb8_striped.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 10 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||
REQUIRE( tiff_reader.is_tiled() == false );
|
||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_RGB );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
SECTION("gray8 striped") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray8_striped.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 32 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||
REQUIRE( tiff_reader.is_tiled() == false );
|
||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_gray8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
SECTION("rgb8 tiled") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_rgb8_tiled.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||
REQUIRE( tiff_reader.is_tiled() == true );
|
||||
REQUIRE( tiff_reader.tile_width() == 32 );
|
||||
REQUIRE( tiff_reader.tile_height() == 32 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_RGB );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
SECTION("gray8 tiled") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray8_tiled.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||
REQUIRE( tiff_reader.is_tiled() == true );
|
||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_gray8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
SECTION("gray8 striped") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray8_striped.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 32 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||
REQUIRE( tiff_reader.is_tiled() == false );
|
||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_gray8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
SECTION("gray16 striped") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray16_striped.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 16 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 16 );
|
||||
REQUIRE( tiff_reader.is_tiled() == false );
|
||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_gray16>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
SECTION("gray8 tiled") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray8_tiled.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||
REQUIRE( tiff_reader.is_tiled() == true );
|
||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_gray8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
SECTION("gray16 tiled") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray16_tiled.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 16 );
|
||||
REQUIRE( tiff_reader.is_tiled() == true );
|
||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_gray16>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
SECTION("gray16 striped") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray16_striped.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 16 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 16 );
|
||||
REQUIRE( tiff_reader.is_tiled() == false );
|
||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_gray16>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
SECTION("gray32f striped") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray32f_striped.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 8 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 32 );
|
||||
REQUIRE( tiff_reader.is_tiled() == false );
|
||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_gray32f>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
SECTION("gray16 tiled") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray16_tiled.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 16 );
|
||||
REQUIRE( tiff_reader.is_tiled() == true );
|
||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_gray16>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
SECTION("gray32f tiled") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray32f_tiled.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 32 );
|
||||
REQUIRE( tiff_reader.is_tiled() == true );
|
||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_gray32f>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
SECTION("gray32f striped") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray32f_striped.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 8 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 32 );
|
||||
REQUIRE( tiff_reader.is_tiled() == false );
|
||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_gray32f>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
SECTION("gray32f tiled") {
|
||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray32f_tiled.tif")
|
||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||
REQUIRE( tiff_reader.bits_per_sample() == 32 );
|
||||
REQUIRE( tiff_reader.is_tiled() == true );
|
||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_gray32f>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue