add 'premultiplied' property on raster symbolizer to allow user to control (in rare cases) the premultiplied status of images in cases where tiffs mis-report it - closes #1512

This commit is contained in:
Dane Springmeyer 2012-10-01 16:14:41 -07:00
parent acaee09598
commit 09726626cf
5 changed files with 48 additions and 1 deletions

View file

@ -28,6 +28,18 @@
#include <mapnik/raster_colorizer.hpp>
#include <mapnik/image_scaling.hpp>
namespace {
// https://github.com/mapnik/mapnik/issues/1367
PyObject* get_premultiplied_impl(mapnik::raster_symbolizer & sym)
{
boost::optional<bool> premultiplied = sym.premultiplied();
if (premultiplied)
return ::PyBool_FromLong(*premultiplied);
Py_RETURN_NONE;
}
}
using mapnik::raster_symbolizer;
void export_raster_symbolizer()
@ -119,5 +131,17 @@ void export_raster_symbolizer()
">>> r = RasterSymbolizer()\n"
">>> r.mesh_size = 32\n"
)
.add_property("premultiplied",
&get_premultiplied_impl,
&raster_symbolizer::set_premultiplied,
"Get/Set premultiplied status of the source image.\n"
"Can be used to override what the source data reports (when in error)\n"
"\n"
"Usage:\n"
"\n"
">>> from mapnik import RasterSymbolizer\n"
">>> r = RasterSymbolizer()\n"
">>> r.premultiplied = False\n"
)
;
}

View file

@ -52,6 +52,8 @@ struct MAPNIK_DECL raster_symbolizer : public symbolizer_base
double calculate_filter_factor() const;
unsigned get_mesh_size() const;
void set_mesh_size(unsigned mesh_size);
boost::optional<bool> premultiplied() const;
void set_premultiplied(bool premultiplied);
private:
std::string mode_;
@ -60,6 +62,7 @@ private:
raster_colorizer_ptr colorizer_;
double filter_factor_;
unsigned mesh_size_;
boost::optional<bool> premultiplied_;
};
}

View file

@ -1490,6 +1490,9 @@ void map_parser::parse_raster_symbolizer(rule & rule, xml_node const & sym)
optional<unsigned> mesh_size = sym.get_opt_attr<unsigned>("mesh-size");
if (mesh_size) raster_sym.set_mesh_size(*mesh_size);
// premultiplied status of image
optional<boolean> premultiplied = sym.get_opt_attr<boolean>("premultiplied");
if (premultiplied) raster_sym.set_premultiplied(*premultiplied);
xml_node::const_iterator cssIter = sym.begin();
xml_node::const_iterator endCss = sym.end();

View file

@ -177,6 +177,15 @@ void raster_symbolizer::set_mesh_size(unsigned mesh_size)
mesh_size_=mesh_size;
}
void raster_symbolizer::set_premultiplied(bool premultiplied)
{
premultiplied_=premultiplied;
}
boost::optional<bool> raster_symbolizer::premultiplied() const
{
return premultiplied_;
}
}

View file

@ -180,10 +180,18 @@ public:
set_attr( sym_node, "mesh-size", sym.get_mesh_size() );
}
if (sym.get_colorizer()) {
if (sym.get_colorizer())
{
serialize_raster_colorizer(sym_node, sym.get_colorizer(),
explicit_defaults_);
}
boost::optional<bool> premultiplied = sym.premultiplied();
if (premultiplied)
{
set_attr( sym_node, "premultiplied", *sym.premultiplied());
}
serialize_symbolizer_base(sym_node, sym);
}