This is a complete removal of code that utilizes image_32 in the library. It is a sweeping change that does some of the following:
* Changes all agg_renderers to use a image_data_any variant (only image_data_rgba8 is implemented currently) * Changes the marker and marker_cache to use image_data_any images * Changes the symbolizers so that they must be aware of the source data type they are attempting to render and the render type that is expected to be rendered into. * Moves many utilities into image_utils, that were previously in image_32. The kicker is that this still isn't working perfectly yet, but I am commiting so I don't have tears in case everything is lost on my computer. Ref #2633
This commit is contained in:
parent
2439f1b298
commit
badb0c9a97
40 changed files with 415 additions and 267 deletions
|
@ -17,19 +17,15 @@ namespace benchmark {
|
|||
{
|
||||
throw mapnik::image_reader_exception("Failed to load: " + dest_fn);
|
||||
}
|
||||
std::shared_ptr<image_32> image_ptr1 = std::make_shared<image_32>(reader1->width(),reader1->height());
|
||||
reader1->read(0,0,image_ptr1->data());
|
||||
|
||||
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(src_fn,"png"));
|
||||
if (!reader2.get())
|
||||
{
|
||||
throw mapnik::image_reader_exception("Failed to load: " + src_fn);
|
||||
}
|
||||
std::shared_ptr<image_32> image_ptr2 = std::make_shared<image_32>(reader2->width(),reader2->height());
|
||||
reader2->read(0,0,image_ptr2->data());
|
||||
|
||||
image_data_rgba8 const& dest = image_ptr1->data();
|
||||
image_data_rgba8 const& src = image_ptr2->data();
|
||||
image_data_rgba8 const& dest = util::get<image_data_rgba8>(reader1->read(0,0,reader1->width(), reader1->height()));
|
||||
image_data_rgba8 const& src = util::get<image_data_rgba8>(reader1->read(0,0,reader1->width(), reader1->height()));
|
||||
|
||||
unsigned int width = src.width();
|
||||
unsigned int height = src.height();
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
class test : public benchmark::test_case
|
||||
{
|
||||
std::shared_ptr<image_32> im_;
|
||||
std::shared_ptr<image_data_rgba8> im_;
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params) {
|
||||
|
@ -13,14 +13,14 @@ public:
|
|||
{
|
||||
throw mapnik::image_reader_exception("Failed to load: " + filename);
|
||||
}
|
||||
im_ = std::make_shared<image_32>(reader->width(),reader->height());
|
||||
reader->read(0,0,im_->data());
|
||||
im_ = std::make_shared<image_rgba8>(reader->width(),reader->height());
|
||||
reader->read(0,0,*im_);
|
||||
}
|
||||
bool validate() const
|
||||
{
|
||||
std::string expected("./benchmark/data/multicolor-hextree-expected.png");
|
||||
std::string actual("./benchmark/data/multicolor-hextree-actual.png");
|
||||
mapnik::save_to_file(im_->data(),actual, "png8:m=h:z=1");
|
||||
mapnik::save_to_file(*im_,actual, "png8:m=h:z=1");
|
||||
return benchmark::compare_images(actual,expected);
|
||||
}
|
||||
bool operator()() const
|
||||
|
@ -28,7 +28,7 @@ public:
|
|||
std::string out;
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
out.clear();
|
||||
out = mapnik::save_to_string(im_->data(),"png8:m=h:z=1");
|
||||
out = mapnik::save_to_string(*im_,"png8:m=h:z=1");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -37,12 +37,12 @@ void render(mapnik::geometry_type & geom,
|
|||
using path_type = mapnik::transform_path_adapter<mapnik::view_transform,mapnik::geometry_type>;
|
||||
using ren_base = agg::renderer_base<agg::pixfmt_rgba32_plain>;
|
||||
using renderer = agg::renderer_scanline_aa_solid<ren_base>;
|
||||
mapnik::image_32 im(256,256);
|
||||
im.set_background(mapnik::color("white"));
|
||||
mapnik::image_data_rgba8 im(256,256);
|
||||
mapnik::fill(im, mapnik::color("white"));
|
||||
mapnik::box2d<double> padded_extent = extent;
|
||||
padded_extent.pad(10);
|
||||
mapnik::view_transform tr(im.width(),im.height(),padded_extent,0,0);
|
||||
agg::rendering_buffer buf(im.raw_data(),im.width(),im.height(), im.width() * 4);
|
||||
agg::rendering_buffer buf(im.getBytes(),im.width(),im.height(), im.width() * 4);
|
||||
agg::pixfmt_rgba32_plain pixf(buf);
|
||||
ren_base renb(pixf);
|
||||
renderer ren(renb);
|
||||
|
@ -54,7 +54,7 @@ void render(mapnik::geometry_type & geom,
|
|||
ras.add_path(path);
|
||||
agg::scanline_u8 sl;
|
||||
agg::render_scanlines(ras, sl, ren);
|
||||
mapnik::save_to_file(im.data(),name);
|
||||
mapnik::save_to_file(im,name);
|
||||
geom.rewind(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ public:
|
|||
mapnik::Map m(256,256);
|
||||
mapnik::load_map(m,xml_);
|
||||
m.zoom_to_box(extent_);
|
||||
mapnik::image_32 im(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_32> ren(m,im);
|
||||
mapnik::image_data_rgba8 im(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_data_rgba8> ren(m,im);
|
||||
ren.apply();
|
||||
//mapnik::save_to_file(im.data(),"test.png");
|
||||
return true;
|
||||
|
@ -35,8 +35,8 @@ public:
|
|||
m.zoom_to_box(extent_);
|
||||
for (unsigned i=0;i<iterations_;++i)
|
||||
{
|
||||
mapnik::image_32 im(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_32> ren(m,im);
|
||||
mapnik::image_data_rgba8 im(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_data_rgba8> ren(m,im);
|
||||
ren.apply();
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -55,8 +55,8 @@ public:
|
|||
} else {
|
||||
m.zoom_all();
|
||||
}
|
||||
mapnik::image_32 im(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_32> ren(m,im,scale_factor_);
|
||||
mapnik::image_data_rgba8 im(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_data_rgba8> ren(m,im,scale_factor_);
|
||||
ren.apply();
|
||||
if (!preview_.empty()) {
|
||||
std::clog << "preview available at " << preview_ << "\n";
|
||||
|
@ -78,8 +78,8 @@ public:
|
|||
}
|
||||
for (unsigned i=0;i<iterations_;++i)
|
||||
{
|
||||
mapnik::image_32 im(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_32> ren(m,im,scale_factor_);
|
||||
mapnik::image_data_rgba8 im(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_data_rgba8> ren(m,im,scale_factor_);
|
||||
ren.apply();
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -50,7 +50,7 @@ class test : public benchmark::test_case
|
|||
std::shared_ptr<mapnik::Map> m_;
|
||||
double scale_factor_;
|
||||
std::string preview_;
|
||||
mutable mapnik::image_32 im_;
|
||||
mutable mapnik::image_data_rgba8 im_;
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
|
@ -94,14 +94,14 @@ public:
|
|||
mapnik::projection map_proj(m_->srs(),true);
|
||||
double scale_denom = mapnik::scale_denominator(m_req.scale(),map_proj.is_geographic());
|
||||
scale_denom *= scale_factor_;
|
||||
mapnik::agg_renderer<mapnik::image_32> ren(*m_,m_req,variables,im_,scale_factor_);
|
||||
mapnik::agg_renderer<mapnik::image_data_rgba8> ren(*m_,m_req,variables,im_,scale_factor_);
|
||||
ren.start_map_processing(*m_);
|
||||
std::vector<mapnik::layer> const& layers = m_->layers();
|
||||
process_layers(ren,m_req,map_proj,layers,scale_denom);
|
||||
ren.end_map_processing(*m_);
|
||||
if (!preview_.empty()) {
|
||||
std::clog << "preview available at " << preview_ << "\n";
|
||||
mapnik::save_to_file(im_.data(),preview_);
|
||||
mapnik::save_to_file(im_,preview_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -114,20 +114,20 @@ public:
|
|||
for (unsigned i=0;i<iterations_;++i)
|
||||
{
|
||||
mapnik::request m_req(width_,height_,extent_);
|
||||
mapnik::image_32 im(m_->width(),m_->height());
|
||||
mapnik::image_data_rgba8 im(m_->width(),m_->height());
|
||||
mapnik::attributes variables;
|
||||
m_req.set_buffer_size(m_->buffer_size());
|
||||
mapnik::projection map_proj(m_->srs(),true);
|
||||
double scale_denom = mapnik::scale_denominator(m_req.scale(),map_proj.is_geographic());
|
||||
scale_denom *= scale_factor_;
|
||||
mapnik::agg_renderer<mapnik::image_32> ren(*m_,m_req,variables,im,scale_factor_);
|
||||
mapnik::agg_renderer<mapnik::image_data_rgba8> ren(*m_,m_req,variables,im,scale_factor_);
|
||||
ren.start_map_processing(*m_);
|
||||
std::vector<mapnik::layer> const& layers = m_->layers();
|
||||
process_layers(ren,m_req,map_proj,layers,scale_denom);
|
||||
ren.end_map_processing(*m_);
|
||||
bool diff = false;
|
||||
mapnik::image_data_rgba8 const& dest = im.data();
|
||||
mapnik::image_data_rgba8 const& src = im_.data();
|
||||
mapnik::image_data_rgba8 const& dest = im;
|
||||
mapnik::image_data_rgba8 const& src = im_;
|
||||
for (unsigned int y = 0; y < height_; ++y)
|
||||
{
|
||||
const unsigned int* row_from = src.getRow(y);
|
||||
|
|
|
@ -190,6 +190,117 @@ bool python_thread::thread_support = true;
|
|||
#endif
|
||||
boost::thread_specific_ptr<PyThreadState> python_thread::state;
|
||||
|
||||
struct agg_renderer_visitor_1
|
||||
{
|
||||
agg_renderer_visitor_1(mapnik::Map const& m, double scale_factor, unsigned offset_x, unsigned offset_y)
|
||||
: m_(m), scale_factor_(scale_factor), offset_x_(offset_x), offset_y_(offset_y) {}
|
||||
|
||||
template <typename T>
|
||||
void operator() (T & pixmap)
|
||||
{
|
||||
throw std::runtime_error("This image type is not currently supported for rendering.");
|
||||
}
|
||||
|
||||
private:
|
||||
mapnik::Map const& m_;
|
||||
double scale_factor_;
|
||||
unsigned offset_x_;
|
||||
unsigned offset_y_;
|
||||
};
|
||||
|
||||
template <>
|
||||
void agg_renderer_visitor_1::operator()<mapnik::image_data_rgba8> (mapnik::image_data_rgba8 & pixmap)
|
||||
{
|
||||
mapnik::agg_renderer<mapnik::image_data_rgba8> ren(m_,pixmap,scale_factor_,offset_x_, offset_y_);
|
||||
ren.apply();
|
||||
}
|
||||
|
||||
struct agg_renderer_visitor_2
|
||||
{
|
||||
agg_renderer_visitor_2(mapnik::Map const &m, std::shared_ptr<mapnik::label_collision_detector4> detector,
|
||||
double scale_factor, unsigned offset_x, unsigned offset_y)
|
||||
: m_(m), detector_(detector), scale_factor_(scale_factor), offset_x_(offset_x), offset_y_(offset_y) {}
|
||||
|
||||
template <typename T>
|
||||
void operator() (T & pixmap)
|
||||
{
|
||||
throw std::runtime_error("This image type is not currently supported for rendering.");
|
||||
}
|
||||
|
||||
private:
|
||||
mapnik::Map const& m_;
|
||||
std::shared_ptr<mapnik::label_collision_detector4> detector_;
|
||||
double scale_factor_;
|
||||
unsigned offset_x_;
|
||||
unsigned offset_y_;
|
||||
};
|
||||
|
||||
template <>
|
||||
void agg_renderer_visitor_2::operator()<mapnik::image_data_rgba8> (mapnik::image_data_rgba8 & pixmap)
|
||||
{
|
||||
mapnik::agg_renderer<mapnik::image_data_rgba8> ren(m_,pixmap,detector_, scale_factor_,offset_x_, offset_y_);
|
||||
ren.apply();
|
||||
}
|
||||
|
||||
struct agg_renderer_visitor_3
|
||||
{
|
||||
agg_renderer_visitor_3(mapnik::Map const& m, mapnik::request const& req, mapnik::attributes const& vars,
|
||||
double scale_factor, unsigned offset_x, unsigned offset_y)
|
||||
: m_(m), req_(req), vars_(vars), scale_factor_(scale_factor), offset_x_(offset_x), offset_y_(offset_y) {}
|
||||
|
||||
template <typename T>
|
||||
void operator() (T & pixmap)
|
||||
{
|
||||
throw std::runtime_error("This image type is not currently supported for rendering.");
|
||||
}
|
||||
|
||||
private:
|
||||
mapnik::Map const& m_;
|
||||
mapnik::request const& req_;
|
||||
mapnik::attributes const& vars_;
|
||||
double scale_factor_;
|
||||
unsigned offset_x_;
|
||||
unsigned offset_y_;
|
||||
|
||||
};
|
||||
|
||||
template <>
|
||||
void agg_renderer_visitor_3::operator()<mapnik::image_data_rgba8> (mapnik::image_data_rgba8 & pixmap)
|
||||
{
|
||||
mapnik::agg_renderer<mapnik::image_data_rgba8> ren(m_,req_, vars_, pixmap, scale_factor_, offset_x_, offset_y_);
|
||||
ren.apply();
|
||||
}
|
||||
|
||||
struct agg_renderer_visitor_4
|
||||
{
|
||||
agg_renderer_visitor_4(mapnik::Map const& m, double scale_factor, unsigned offset_x, unsigned offset_y,
|
||||
mapnik::layer const& layer, std::set<std::string>& names)
|
||||
: m_(m), scale_factor_(scale_factor), offset_x_(offset_x), offset_y_(offset_y),
|
||||
layer_(layer), names_(names) {}
|
||||
|
||||
template <typename T>
|
||||
void operator() (T & pixmap)
|
||||
{
|
||||
throw std::runtime_error("This image type is not currently supported for rendering.");
|
||||
}
|
||||
|
||||
private:
|
||||
mapnik::Map const& m_;
|
||||
double scale_factor_;
|
||||
unsigned offset_x_;
|
||||
unsigned offset_y_;
|
||||
mapnik::layer const& layer_;
|
||||
std::set<std::string> & names_;
|
||||
};
|
||||
|
||||
template <>
|
||||
void agg_renderer_visitor_4::operator()<mapnik::image_data_rgba8> (mapnik::image_data_rgba8 & pixmap)
|
||||
{
|
||||
mapnik::agg_renderer<mapnik::image_data_rgba8> ren(m_,pixmap,scale_factor_,offset_x_, offset_y_);
|
||||
ren.apply(layer_, names_);
|
||||
}
|
||||
|
||||
|
||||
void render(mapnik::Map const& map,
|
||||
mapnik::image_data_any& image,
|
||||
double scale_factor = 1.0,
|
||||
|
@ -197,8 +308,7 @@ void render(mapnik::Map const& map,
|
|||
unsigned offset_y = 0u)
|
||||
{
|
||||
python_unblock_auto_block b;
|
||||
mapnik::agg_renderer<mapnik::image_data_any> ren(map,image,scale_factor,offset_x, offset_y);
|
||||
ren.apply();
|
||||
mapnik::util::apply_visitor(agg_renderer_visitor_1(map, scale_factor, offset_x, offset_y), image);
|
||||
}
|
||||
|
||||
void render_with_vars(mapnik::Map const& map,
|
||||
|
@ -212,8 +322,7 @@ void render_with_vars(mapnik::Map const& map,
|
|||
mapnik::request req(map.width(),map.height(),map.get_current_extent());
|
||||
req.set_buffer_size(map.buffer_size());
|
||||
python_unblock_auto_block b;
|
||||
mapnik::agg_renderer<mapnik::image_data_any> ren(map,req,vars,image,scale_factor,offset_x,offset_y);
|
||||
ren.apply();
|
||||
mapnik::util::apply_visitor(agg_renderer_visitor_3(map, req, vars, scale_factor, offset_x, offset_y), image);
|
||||
}
|
||||
|
||||
void render_with_detector(
|
||||
|
@ -225,8 +334,7 @@ void render_with_detector(
|
|||
unsigned offset_y = 0u)
|
||||
{
|
||||
python_unblock_auto_block b;
|
||||
mapnik::agg_renderer<mapnik::image_data_any> ren(map,image,detector,scale_factor,offset_x,offset_y);
|
||||
ren.apply();
|
||||
mapnik::util::apply_visitor(agg_renderer_visitor_2(map, detector, scale_factor, offset_x, offset_y), image);
|
||||
}
|
||||
|
||||
void render_layer2(mapnik::Map const& map,
|
||||
|
@ -247,9 +355,8 @@ void render_layer2(mapnik::Map const& map,
|
|||
|
||||
python_unblock_auto_block b;
|
||||
mapnik::layer const& layer = layers[layer_idx];
|
||||
mapnik::agg_renderer<mapnik::image_data_any> ren(map,image,scale_factor,offset_x,offset_y);
|
||||
std::set<std::string> names;
|
||||
ren.apply(layer,names);
|
||||
mapnik::util::apply_visitor(agg_renderer_visitor_4(map, scale_factor, offset_x, offset_y, layer, names), image);
|
||||
}
|
||||
|
||||
#if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO)
|
||||
|
|
|
@ -306,8 +306,8 @@ int main ( int, char** )
|
|||
|
||||
m.zoom_to_box(box2d<double>(-8024477.28459,5445190.38849,-7381388.20071,5662941.44855));
|
||||
|
||||
image_32 buf(m.width(),m.height());
|
||||
agg_renderer<image_32> ren(m,buf);
|
||||
image_data_rgba8 buf(m.width(),m.height());
|
||||
agg_renderer<image_data_rgba8> ren(m,buf);
|
||||
ren.apply();
|
||||
std::string msg("These maps have been rendered using AGG in the current directory:\n");
|
||||
#ifdef HAVE_JPEG
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
#include "mapwidget.hpp"
|
||||
#include "info_dialog.hpp"
|
||||
|
||||
using mapnik::image_32;
|
||||
using mapnik::image_data_rgba8;
|
||||
using mapnik::Map;
|
||||
using mapnik::layer;
|
||||
using mapnik::box2d;
|
||||
|
@ -479,7 +479,7 @@ void MapWidget::zoomToLevel(int level)
|
|||
|
||||
void MapWidget::export_to_file(unsigned ,unsigned ,std::string const&,std::string const&)
|
||||
{
|
||||
//image_32 image(width,height);
|
||||
//image_data_rgba8 image(width,height);
|
||||
//agg_renderer renderer(map,image);
|
||||
//renderer.apply();
|
||||
//image.saveToFile(filename,type);
|
||||
|
@ -496,8 +496,8 @@ void render_agg(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
|||
unsigned width=map.width();
|
||||
unsigned height=map.height();
|
||||
|
||||
image_32 buf(width,height);
|
||||
mapnik::agg_renderer<image_32> ren(map,buf,scaling_factor);
|
||||
image_data_rgba8 buf(width,height);
|
||||
mapnik::agg_renderer<image_data_rgba8> ren(map,buf,scaling_factor);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -542,8 +542,7 @@ void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
|||
}
|
||||
mapnik::image_data_rgba8 data(map.width(), map.height());
|
||||
mapnik::cairo_image_to_rgba8(data, image_surface);
|
||||
image_32 buf(std::move(data));
|
||||
QImage image((uchar*)buf.raw_data(),buf.width(),buf.height(),QImage::Format_ARGB32);
|
||||
QImage image((uchar*)data.getBytes(),data.width(),data.height(),QImage::Format_ARGB32);
|
||||
pix = QPixmap::fromImage(image.rgbSwapped());
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -172,9 +172,6 @@ private:
|
|||
};
|
||||
|
||||
extern template class MAPNIK_DECL agg_renderer<image_data_rgba8>;
|
||||
//extern template class MAPNIK_DECL agg_renderer<image_data_gray8>;
|
||||
//extern template class MAPNIK_DECL agg_renderer<image_data_gray16>;
|
||||
//extern template class MAPNIK_DECL agg_renderer<image_data_gray32f>;
|
||||
|
||||
} // namespace mapnik
|
||||
|
||||
|
|
36
include/mapnik/image_convert.hpp
Normal file
36
include/mapnik/image_convert.hpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2014 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef MAPNIK_IMAGE_CONVERT_HPP
|
||||
#define MAPNIK_IMAGE_CONVERT_HPP
|
||||
|
||||
#include <mapnik/config.hpp>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
||||
template <typename T1, typename T2>
|
||||
MAPNIK_DECL T2 convert_image(T1 const& data);
|
||||
|
||||
} // end mapnik ns
|
||||
|
||||
#endif // MAPNIK_IMAGE_CONVERT_HPP
|
|
@ -128,15 +128,16 @@ struct vector_marker_render_thunk : util::noncopyable
|
|||
snap_to_pixels_(std::move(rhs.snap_to_pixels_)) {}
|
||||
};
|
||||
|
||||
template <typename BufferType>
|
||||
struct raster_marker_render_thunk : util::noncopyable
|
||||
{
|
||||
image_data_any & src_;
|
||||
BufferType & src_;
|
||||
agg::trans_affine tr_;
|
||||
double opacity_;
|
||||
composite_mode_e comp_op_;
|
||||
bool snap_to_pixels_;
|
||||
|
||||
raster_marker_render_thunk(image_data_any & src,
|
||||
raster_marker_render_thunk(BufferType & src,
|
||||
agg::trans_affine const& marker_trans,
|
||||
double opacity,
|
||||
composite_mode_e comp_op,
|
||||
|
@ -150,6 +151,11 @@ struct raster_marker_render_thunk : util::noncopyable
|
|||
snap_to_pixels_(std::move(rhs.snap_to_pixels_)) {}
|
||||
};
|
||||
|
||||
template struct raster_marker_render_thunk<image_data_rgba8>;
|
||||
template struct raster_marker_render_thunk<image_data_gray8>;
|
||||
template struct raster_marker_render_thunk<image_data_gray16>;
|
||||
template struct raster_marker_render_thunk<image_data_gray32f>;
|
||||
|
||||
using helper_ptr = std::unique_ptr<text_symbolizer_helper>;
|
||||
|
||||
struct text_render_thunk : util::noncopyable
|
||||
|
@ -179,7 +185,10 @@ struct text_render_thunk : util::noncopyable
|
|||
// via a static visitor later.
|
||||
|
||||
using render_thunk = util::variant<vector_marker_render_thunk,
|
||||
raster_marker_render_thunk,
|
||||
raster_marker_render_thunk<image_data_rgba8>,
|
||||
raster_marker_render_thunk<image_data_gray8>,
|
||||
raster_marker_render_thunk<image_data_gray16>,
|
||||
raster_marker_render_thunk<image_data_gray32f>,
|
||||
text_render_thunk>;
|
||||
using render_thunk_ptr = std::unique_ptr<render_thunk>;
|
||||
using render_thunk_list = std::list<render_thunk_ptr>;
|
||||
|
|
|
@ -43,6 +43,7 @@ void render_markers_symbolizer(markers_symbolizer const& sym,
|
|||
using namespace mapnik::svg;
|
||||
using vector_dispatch_type = VD;
|
||||
using raster_dispatch_type = RD;
|
||||
using buffer_type = typename std::tuple_element<0,ContextType>::type;
|
||||
|
||||
std::string filename = get<std::string>(sym, keys::file, feature, common.vars_, "shape://ellipse");
|
||||
bool clip = get<value_bool, keys::clip>(sym, feature, common.vars_);
|
||||
|
|
|
@ -523,19 +523,4 @@ template void agg_renderer<image_data_rgba8>::debug_draw_box<agg::rendering_buff
|
|||
agg::rendering_buffer& buf,
|
||||
box2d<double> const& box,
|
||||
double x, double y, double angle);
|
||||
template class agg_renderer<image_data_gray8>;
|
||||
template void agg_renderer<image_data_gray8>::debug_draw_box<agg::rendering_buffer>(
|
||||
agg::rendering_buffer& buf,
|
||||
box2d<double> const& box,
|
||||
double x, double y, double angle);
|
||||
template class agg_renderer<image_data_gray16>;
|
||||
template void agg_renderer<image_data_gray16>::debug_draw_box<agg::rendering_buffer>(
|
||||
agg::rendering_buffer& buf,
|
||||
box2d<double> const& box,
|
||||
double x, double y, double angle);
|
||||
template class agg_renderer<image_data_gray32f>;
|
||||
template void agg_renderer<image_data_gray32f>::debug_draw_box<agg::rendering_buffer>(
|
||||
agg::rendering_buffer& buf,
|
||||
box2d<double> const& box,
|
||||
double x, double y, double angle);
|
||||
}
|
||||
} // end ns
|
||||
|
|
|
@ -113,14 +113,4 @@ void agg_renderer<T0,T1>::process(building_symbolizer const& sym,
|
|||
template void agg_renderer<image_data_rgba8>::process(building_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
template void agg_renderer<image_data_gray8>::process(building_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
template void agg_renderer<image_data_gray16>::process(building_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
template void agg_renderer<image_data_gray32f>::process(building_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
|
||||
}
|
||||
|
|
|
@ -95,13 +95,4 @@ void agg_renderer<T0,T1>::process(debug_symbolizer const& sym,
|
|||
template void agg_renderer<image_data_rgba8>::process(debug_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
template void agg_renderer<image_data_gray8>::process(debug_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
template void agg_renderer<image_data_gray16>::process(debug_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
template void agg_renderer<image_data_gray32f>::process(debug_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
}
|
||||
|
|
|
@ -102,14 +102,5 @@ void agg_renderer<T0,T1>::process(dot_symbolizer const& sym,
|
|||
template void agg_renderer<image_data_rgba8>::process(dot_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
template void agg_renderer<image_data_gray8>::process(dot_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
template void agg_renderer<image_data_gray16>::process(dot_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
template void agg_renderer<image_data_gray32f>::process(dot_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
|
||||
}
|
||||
|
|
|
@ -49,99 +49,9 @@ namespace mapnik {
|
|||
* to render it, and the boxes themselves should already be
|
||||
* in the detector from the placement_finder.
|
||||
*/
|
||||
template <typename T0>
|
||||
struct thunk_renderer
|
||||
{
|
||||
using renderer_type = agg_renderer<T0>;
|
||||
using buffer_type = typename renderer_type::buffer_type;
|
||||
using text_renderer_type = agg_text_renderer<buffer_type>;
|
||||
|
||||
thunk_renderer(renderer_type &ren,
|
||||
std::unique_ptr<rasterizer> const& ras_ptr,
|
||||
buffer_type *buf,
|
||||
renderer_common &common,
|
||||
pixel_position const &offset)
|
||||
: ren_(ren), ras_ptr_(ras_ptr), buf_(buf), common_(common), offset_(offset)
|
||||
{}
|
||||
|
||||
void operator()(vector_marker_render_thunk const &thunk) const
|
||||
{
|
||||
using blender_type = agg::comp_op_adaptor_rgba_pre<agg::rgba8, agg::order_rgba>; // comp blender
|
||||
using buf_type = agg::rendering_buffer;
|
||||
using pixfmt_comp_type = agg::pixfmt_custom_blend_rgba<blender_type, buf_type>;
|
||||
using renderer_base = agg::renderer_base<pixfmt_comp_type>;
|
||||
using renderer_type = agg::renderer_scanline_aa_solid<renderer_base>;
|
||||
using svg_attribute_type = agg::pod_bvector<svg::path_attributes>;
|
||||
using svg_renderer_type = svg::svg_renderer_agg<svg_path_adapter,
|
||||
svg_attribute_type,
|
||||
renderer_type,
|
||||
pixfmt_comp_type>;
|
||||
ras_ptr_->reset();
|
||||
buf_type render_buffer(buf_->getBytes(), buf_->width(), buf_->height(), buf_->width() * 4);
|
||||
pixfmt_comp_type pixf(render_buffer);
|
||||
pixf.comp_op(static_cast<agg::comp_op_e>(thunk.comp_op_));
|
||||
renderer_base renb(pixf);
|
||||
svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(thunk.src_->source());
|
||||
svg_path_adapter svg_path(stl_storage);
|
||||
svg_renderer_type svg_renderer(svg_path, thunk.attrs_);
|
||||
|
||||
agg::trans_affine offset_tr = thunk.tr_;
|
||||
offset_tr.translate(offset_.x, offset_.y);
|
||||
render_vector_marker(svg_renderer, *ras_ptr_, renb, thunk.src_->bounding_box(), offset_tr, thunk.opacity_, thunk.snap_to_pixels_);
|
||||
}
|
||||
|
||||
void operator()(raster_marker_render_thunk const &thunk) const
|
||||
{
|
||||
using blender_type = agg::comp_op_adaptor_rgba_pre<agg::rgba8, agg::order_rgba>; // comp blender
|
||||
using buf_type = agg::rendering_buffer;
|
||||
using pixfmt_comp_type = agg::pixfmt_custom_blend_rgba<blender_type, buf_type>;
|
||||
using renderer_base = agg::renderer_base<pixfmt_comp_type>;
|
||||
|
||||
ras_ptr_->reset();
|
||||
buf_type render_buffer(buf_->getBytes(), buf_->width(), buf_->height(), buf_->width() * 4);
|
||||
pixfmt_comp_type pixf(render_buffer);
|
||||
pixf.comp_op(static_cast<agg::comp_op_e>(thunk.comp_op_));
|
||||
renderer_base renb(pixf);
|
||||
|
||||
agg::trans_affine offset_tr = thunk.tr_;
|
||||
offset_tr.translate(offset_.x, offset_.y);
|
||||
render_raster_marker(renb, *ras_ptr_, thunk.src_, offset_tr, thunk.opacity_, common_.scale_factor_, thunk.snap_to_pixels_);
|
||||
}
|
||||
|
||||
void operator()(text_render_thunk const &thunk) const
|
||||
{
|
||||
text_renderer_type ren(*buf_, thunk.halo_rasterizer_, thunk.comp_op_, thunk.comp_op_,
|
||||
common_.scale_factor_, common_.font_manager_.get_stroker());
|
||||
|
||||
render_offset_placements(
|
||||
thunk.placements_,
|
||||
offset_,
|
||||
[&] (glyph_positions_ptr glyphs)
|
||||
{
|
||||
if (glyphs->marker())
|
||||
{
|
||||
ren_.render_marker(glyphs->marker_pos(),
|
||||
*(glyphs->marker()->marker),
|
||||
glyphs->marker()->transform,
|
||||
thunk.opacity_, thunk.comp_op_);
|
||||
}
|
||||
ren.render(*glyphs);
|
||||
});
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator()(T const &) const
|
||||
{
|
||||
// TODO: warning if unimplemented?
|
||||
}
|
||||
|
||||
private:
|
||||
renderer_type &ren_;
|
||||
std::unique_ptr<rasterizer> const& ras_ptr_;
|
||||
buffer_type *buf_;
|
||||
renderer_common &common_;
|
||||
pixel_position offset_;
|
||||
};
|
||||
template <typename T>
|
||||
struct thunk_renderer;
|
||||
|
||||
template <>
|
||||
struct thunk_renderer<image_data_rgba8>
|
||||
|
@ -184,7 +94,7 @@ struct thunk_renderer<image_data_rgba8>
|
|||
render_vector_marker(svg_renderer, *ras_ptr_, renb, thunk.src_->bounding_box(), offset_tr, thunk.opacity_, thunk.snap_to_pixels_);
|
||||
}
|
||||
|
||||
void operator()(raster_marker_render_thunk const &thunk) const
|
||||
void operator()(raster_marker_render_thunk<image_data_rgba8> const &thunk) const
|
||||
{
|
||||
using blender_type = agg::comp_op_adaptor_rgba_pre<agg::rgba8, agg::order_rgba>; // comp blender
|
||||
using buf_type = agg::rendering_buffer;
|
||||
|
@ -199,7 +109,22 @@ struct thunk_renderer<image_data_rgba8>
|
|||
|
||||
agg::trans_affine offset_tr = thunk.tr_;
|
||||
offset_tr.translate(offset_.x, offset_.y);
|
||||
render_raster_marker(renb, *ras_ptr_, util::get<image_data_rgba8>(thunk.src_), offset_tr, thunk.opacity_, common_.scale_factor_, thunk.snap_to_pixels_);
|
||||
render_raster_marker(renb, *ras_ptr_, thunk.src_, offset_tr, thunk.opacity_, common_.scale_factor_, thunk.snap_to_pixels_);
|
||||
}
|
||||
|
||||
void operator()(raster_marker_render_thunk<image_data_gray8> const &thunk) const
|
||||
{
|
||||
throw std::runtime_error("Rendering of this image_data_gray8 type is not supported currently by the image_data_rgba8 renderer");
|
||||
}
|
||||
|
||||
void operator()(raster_marker_render_thunk<image_data_gray16> const &thunk) const
|
||||
{
|
||||
throw std::runtime_error("Rendering of this image_data_gray16 type is not supported currently by the image_data_rgba8 renderer");
|
||||
}
|
||||
|
||||
void operator()(raster_marker_render_thunk<image_data_gray32f> const &thunk) const
|
||||
{
|
||||
throw std::runtime_error("Rendering of this image_data_gray32f type is not supported currently by the image_data_rgba8 renderer");
|
||||
}
|
||||
|
||||
void operator()(text_render_thunk const &thunk) const
|
||||
|
@ -226,7 +151,7 @@ struct thunk_renderer<image_data_rgba8>
|
|||
template <typename T>
|
||||
void operator()(T const &) const
|
||||
{
|
||||
// TODO: warning if unimplemented?
|
||||
throw std::runtime_error("Rendering of this data type is not supported currently by the renderer");
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -257,14 +182,5 @@ void agg_renderer<T0,T1>::process(group_symbolizer const& sym,
|
|||
template void agg_renderer<image_data_rgba8>::process(group_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
//template void agg_renderer<image_data_gray8>::process(group_symbolizer const&,
|
||||
// mapnik::feature_impl &,
|
||||
// proj_transform const&);
|
||||
//template void agg_renderer<image_data_gray16>::process(group_symbolizer const&,
|
||||
// mapnik::feature_impl &,
|
||||
// proj_transform const&);
|
||||
//template void agg_renderer<image_data_gray32f>::process(group_symbolizer const&,
|
||||
// mapnik::feature_impl &,
|
||||
// proj_transform const&);
|
||||
|
||||
}
|
||||
|
|
|
@ -224,7 +224,7 @@ void agg_renderer<T0,T1>::process(line_symbolizer const& sym,
|
|||
}
|
||||
|
||||
|
||||
template void agg_renderer<image_data_any>::process(line_symbolizer const&,
|
||||
template void agg_renderer<image_data_rgba8>::process(line_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ struct raster_markers_rasterizer_dispatch : public raster_markers_dispatch<Detec
|
|||
using pixfmt_comp_type = agg::pixfmt_custom_blend_rgba<blender_type, BufferType>;
|
||||
using renderer_base = agg::renderer_base<pixfmt_comp_type>;
|
||||
|
||||
raster_markers_rasterizer_dispatch(image_data_rgba8 & src,
|
||||
raster_markers_rasterizer_dispatch(image_data_any & src,
|
||||
agg::trans_affine const& marker_trans,
|
||||
symbolizer_base const& sym,
|
||||
Detector & detector,
|
||||
|
@ -148,7 +148,9 @@ struct raster_markers_rasterizer_dispatch : public raster_markers_dispatch<Detec
|
|||
|
||||
void render_marker(agg::trans_affine const& marker_tr, double opacity)
|
||||
{
|
||||
render_raster_marker(renb_, ras_, this->src_, marker_tr, opacity, this->scale_factor_, snap_to_pixels_);
|
||||
// In the long term this should be a visitor pattern based on the type of render this->src_ provided that converts
|
||||
// the destination pixel type required.
|
||||
render_raster_marker(renb_, ras_, util::get<image_data_rgba8>(this->src_), marker_tr, opacity, this->scale_factor_, snap_to_pixels_);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -60,7 +60,7 @@ void agg_renderer<T0,T1>::process(point_symbolizer const& sym,
|
|||
});
|
||||
}
|
||||
|
||||
template void agg_renderer<image_data_any>::process(point_symbolizer const&,
|
||||
template void agg_renderer<image_data_rgba8>::process(point_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ void agg_renderer<T0,T1>::process(polygon_symbolizer const& sym,
|
|||
}
|
||||
|
||||
box2d<double> clip_box = clipping_extent(common_);
|
||||
agg::rendering_buffer buf(current_buffer_->raw_data(),current_buffer_->width(),current_buffer_->height(), current_buffer_->width() * 4);
|
||||
agg::rendering_buffer buf(current_buffer_->getBytes(),current_buffer_->width(),current_buffer_->height(), current_buffer_->width() * 4);
|
||||
|
||||
render_polygon_symbolizer<vertex_converter_type>(
|
||||
sym, feature, prj_trans, common_, clip_box, *ras_ptr,
|
||||
|
@ -88,7 +88,7 @@ void agg_renderer<T0,T1>::process(polygon_symbolizer const& sym,
|
|||
});
|
||||
}
|
||||
|
||||
template void agg_renderer<image_32>::process(polygon_symbolizer const&,
|
||||
template void agg_renderer<image_data_rgba8>::process(polygon_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
|
||||
|
|
|
@ -54,13 +54,13 @@ void agg_renderer<T0,T1>::process(raster_symbolizer const& sym,
|
|||
sym, feature, prj_trans, common_,
|
||||
[&](image_data_rgba8 & target, composite_mode_e comp_op, double opacity,
|
||||
int start_x, int start_y) {
|
||||
composite(current_buffer_->data(), target,
|
||||
composite(*current_buffer_, target,
|
||||
comp_op, opacity, start_x, start_y);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
template void agg_renderer<image_32>::process(raster_symbolizer const&,
|
||||
template void agg_renderer<image_data_rgba8>::process(raster_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ void agg_renderer<T0,T1>::process(shield_symbolizer const& sym,
|
|||
}
|
||||
|
||||
|
||||
template void agg_renderer<image_32>::process(shield_symbolizer const&,
|
||||
template void agg_renderer<image_data_rgba8>::process(shield_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
|
||||
|
|
|
@ -76,12 +76,8 @@ void agg_renderer<T0,T1>::process(text_symbolizer const& sym,
|
|||
}
|
||||
}
|
||||
|
||||
template void agg_renderer<image_data_any>::process(text_symbolizer const&,
|
||||
template void agg_renderer<image_data_rgba8>::process(text_symbolizer const&,
|
||||
mapnik::feature_impl &,
|
||||
proj_transform const&);
|
||||
|
||||
//template void agg_renderer<image_32>::process(text_symbolizer const&,
|
||||
// mapnik::feature_impl &,
|
||||
// proj_transform const&);
|
||||
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ struct thunk_renderer
|
|||
thunk.opacity_);
|
||||
}
|
||||
|
||||
void operator()(raster_marker_render_thunk const &thunk) const
|
||||
void operator()(raster_marker_render_thunk<image_data_rgba8> const &thunk) const
|
||||
{
|
||||
cairo_save_restore guard(context_);
|
||||
context_.set_operator(thunk.comp_op_);
|
||||
|
@ -111,7 +111,7 @@ struct thunk_renderer
|
|||
template <typename T0>
|
||||
void operator()(T0 const &) const
|
||||
{
|
||||
// TODO: warning if unimplemented?
|
||||
throw std::runtime_error("Rendering of this type is not supported by the cairo renderer.");
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -86,7 +86,7 @@ private:
|
|||
template <typename RendererContext, typename Detector>
|
||||
struct raster_markers_dispatch_cairo : public raster_markers_dispatch<Detector>
|
||||
{
|
||||
raster_markers_dispatch_cairo(mapnik::image_data_any & src,
|
||||
raster_markers_dispatch_cairo(image_data_any & src,
|
||||
agg::trans_affine const& marker_trans,
|
||||
markers_symbolizer const& sym,
|
||||
Detector & detector,
|
||||
|
|
|
@ -56,6 +56,6 @@ template class feature_style_processor<svg_renderer<std::ostream_iterator<char>
|
|||
template class feature_style_processor<grid_renderer<grid> >;
|
||||
#endif
|
||||
|
||||
template class feature_style_processor<agg_renderer<image_data_any> >;
|
||||
template class feature_style_processor<agg_renderer<image_data_rgba8> >;
|
||||
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ struct thunk_renderer
|
|||
pixmap_.add_feature(feature_);
|
||||
}
|
||||
|
||||
void operator()(raster_marker_render_thunk const &thunk) const
|
||||
void operator()(raster_marker_render_thunk<image_data_rgba8> const &thunk) const
|
||||
{
|
||||
using buf_type = grid_rendering_buffer;
|
||||
using pixfmt_type = typename grid_renderer_base_type::pixfmt_type;
|
||||
|
@ -115,10 +115,25 @@ struct thunk_renderer
|
|||
renderer_type ren(renb);
|
||||
agg::trans_affine offset_tr = thunk.tr_;
|
||||
offset_tr.translate(offset_.x, offset_.y);
|
||||
render_raster_marker(ren, ras_, util::get<buffer_type>(thunk.src_), feature_, offset_tr, thunk.opacity_);
|
||||
render_raster_marker(ren, ras_, thunk.src_, feature_, offset_tr, thunk.opacity_);
|
||||
pixmap_.add_feature(feature_);
|
||||
}
|
||||
|
||||
void operator()(raster_marker_render_thunk<image_data_gray8> const &thunk) const
|
||||
{
|
||||
throw std::runtime_error("Rendering of this image_data_gray8 type is not supported currently by the image_data_rgba8 renderer");
|
||||
}
|
||||
|
||||
void operator()(raster_marker_render_thunk<image_data_gray16> const &thunk) const
|
||||
{
|
||||
throw std::runtime_error("Rendering of this image_data_gray16 type is not supported currently by the image_data_rgba8 renderer");
|
||||
}
|
||||
|
||||
void operator()(raster_marker_render_thunk<image_data_gray32f> const &thunk) const
|
||||
{
|
||||
throw std::runtime_error("Rendering of this image_data_gray32f type is not supported currently by the image_data_rgba8 renderer");
|
||||
}
|
||||
|
||||
void operator()(text_render_thunk const &thunk) const
|
||||
{
|
||||
text_renderer_type ren(pixmap_, thunk.comp_op_, common_.scale_factor_);
|
||||
|
|
|
@ -146,7 +146,7 @@ struct raster_markers_rasterizer_dispatch : public raster_markers_dispatch<Detec
|
|||
using RasterizerType = typename std::tuple_element<1,RendererContext>::type;
|
||||
using PixMapType = typename std::tuple_element<2,RendererContext>::type;
|
||||
|
||||
raster_markers_rasterizer_dispatch(image_data_rgba8 & src,
|
||||
raster_markers_rasterizer_dispatch(image_data_any & src,
|
||||
agg::trans_affine const& marker_trans,
|
||||
markers_symbolizer const& sym,
|
||||
Detector & detector,
|
||||
|
@ -165,7 +165,9 @@ struct raster_markers_rasterizer_dispatch : public raster_markers_dispatch<Detec
|
|||
|
||||
void render_marker(agg::trans_affine const& marker_tr, double opacity)
|
||||
{
|
||||
render_raster_marker(RendererType(renb_), ras_, this->src_, this->feature_, marker_tr, opacity);
|
||||
// In the long term this should be a visitor pattern based on the type of render this->src_ provided that converts
|
||||
// the destination pixel type required.
|
||||
render_raster_marker(RendererType(renb_), ras_, util::get<image_data_rgba8>(this->src_), this->feature_, marker_tr, opacity);
|
||||
if (!placed_)
|
||||
{
|
||||
pixmap_.add_feature(this->feature_);
|
||||
|
|
62
src/image_convert.cpp
Normal file
62
src/image_convert.cpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2014 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/image_convert.hpp>
|
||||
#include <mapnik/image_data.hpp>
|
||||
#include <mapnik/image_data_any.hpp>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template <typename T0>
|
||||
struct visitor_convert
|
||||
{
|
||||
using dst_type = typename T0::pixel_type;
|
||||
template <typename T1>
|
||||
T0 operator() (T1 const& src)
|
||||
{
|
||||
T0 dst(src.width(), src.height());
|
||||
for (unsigned y = 0; y < dst.height(); ++y)
|
||||
{
|
||||
for (unsigned x = 0; x < dst.width(); ++x)
|
||||
{
|
||||
dst(x,y) = static_cast<dst_type>(src(x,y));
|
||||
}
|
||||
}
|
||||
return T0(std::move(dst));
|
||||
}
|
||||
};
|
||||
|
||||
} // end detail ns
|
||||
|
||||
template <typename T1, typename T2>
|
||||
MAPNIK_DECL T2 convert_image(T1 const& data)
|
||||
{
|
||||
detail::visitor_convert<T2> visit;
|
||||
return visit(data);
|
||||
}
|
||||
|
||||
} // end mapnik ns
|
|
@ -39,7 +39,38 @@ vector_marker_render_thunk::vector_marker_render_thunk(svg_path_ptr const& src,
|
|||
comp_op_(comp_op), snap_to_pixels_(snap_to_pixels)
|
||||
{}
|
||||
|
||||
raster_marker_render_thunk::raster_marker_render_thunk(image_data_any & src,
|
||||
template <>
|
||||
raster_marker_render_thunk<image_data_rgba8>::raster_marker_render_thunk(image_data_rgba8 & src,
|
||||
agg::trans_affine const& marker_trans,
|
||||
double opacity,
|
||||
composite_mode_e comp_op,
|
||||
bool snap_to_pixels)
|
||||
: src_(src), tr_(marker_trans), opacity_(opacity), comp_op_(comp_op),
|
||||
snap_to_pixels_(snap_to_pixels)
|
||||
{}
|
||||
|
||||
template <>
|
||||
raster_marker_render_thunk<image_data_gray8>::raster_marker_render_thunk(image_data_gray8 & src,
|
||||
agg::trans_affine const& marker_trans,
|
||||
double opacity,
|
||||
composite_mode_e comp_op,
|
||||
bool snap_to_pixels)
|
||||
: src_(src), tr_(marker_trans), opacity_(opacity), comp_op_(comp_op),
|
||||
snap_to_pixels_(snap_to_pixels)
|
||||
{}
|
||||
|
||||
template <>
|
||||
raster_marker_render_thunk<image_data_gray16>::raster_marker_render_thunk(image_data_gray16 & src,
|
||||
agg::trans_affine const& marker_trans,
|
||||
double opacity,
|
||||
composite_mode_e comp_op,
|
||||
bool snap_to_pixels)
|
||||
: src_(src), tr_(marker_trans), opacity_(opacity), comp_op_(comp_op),
|
||||
snap_to_pixels_(snap_to_pixels)
|
||||
{}
|
||||
|
||||
template <>
|
||||
raster_marker_render_thunk<image_data_gray32f>::raster_marker_render_thunk(image_data_gray32f & src,
|
||||
agg::trans_affine const& marker_trans,
|
||||
double opacity,
|
||||
composite_mode_e comp_op,
|
||||
|
@ -94,6 +125,40 @@ private:
|
|||
render_thunk_list & thunks_;
|
||||
};
|
||||
|
||||
struct visitor_push_thunk
|
||||
{
|
||||
visitor_push_thunk(render_thunk_list & thunks,
|
||||
agg::trans_affine const& marker_tr,
|
||||
double opacity,
|
||||
composite_mode_e comp_op,
|
||||
bool snap_to_pixels)
|
||||
: thunks_(thunks),
|
||||
marker_tr_(marker_tr),
|
||||
opacity_(opacity),
|
||||
comp_op_(comp_op),
|
||||
snap_to_pixels_(snap_to_pixels) {}
|
||||
|
||||
template <typename T>
|
||||
void operator() (T & data)
|
||||
{
|
||||
raster_marker_render_thunk<T> thunk(data, marker_tr_, opacity_, comp_op_, snap_to_pixels_);
|
||||
thunks_.push_back(std::make_unique<render_thunk>(std::move(thunk)));
|
||||
}
|
||||
|
||||
private:
|
||||
render_thunk_list & thunks_;
|
||||
agg::trans_affine const& marker_tr_;
|
||||
double opacity_;
|
||||
composite_mode_e comp_op_;
|
||||
bool snap_to_pixels_;
|
||||
};
|
||||
|
||||
template <>
|
||||
void visitor_push_thunk::operator()<image_data_null> (image_data_null &)
|
||||
{
|
||||
throw std::runtime_error("Push thunk does not support null images");
|
||||
}
|
||||
|
||||
template <typename Detector, typename RendererContext>
|
||||
struct raster_marker_thunk_dispatch : public raster_markers_dispatch<Detector>
|
||||
{
|
||||
|
@ -115,8 +180,7 @@ struct raster_marker_thunk_dispatch : public raster_markers_dispatch<Detector>
|
|||
|
||||
void render_marker(agg::trans_affine const& marker_tr, double opacity)
|
||||
{
|
||||
raster_marker_render_thunk thunk(this->src_, marker_tr, opacity, comp_op_, snap_to_pixels_);
|
||||
thunks_.push_back(std::make_unique<render_thunk>(std::move(thunk)));
|
||||
util::apply_visitor(visitor_push_thunk(thunks_, marker_tr, opacity, comp_op_, snap_to_pixels_), this->src_);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -125,7 +189,7 @@ private:
|
|||
render_thunk_list & thunks_;
|
||||
};
|
||||
|
||||
}
|
||||
} // end detail ns
|
||||
|
||||
render_thunk_extractor::render_thunk_extractor(box2d<double> & box,
|
||||
render_thunk_list & thunks,
|
||||
|
|
|
@ -359,8 +359,7 @@ grid_text_renderer<T>::grid_text_renderer(pixmap_type &pixmap,
|
|||
: text_renderer(HALO_RASTERIZER_FAST, comp_op, src_over, scale_factor),
|
||||
pixmap_(pixmap) {}
|
||||
|
||||
template class agg_text_renderer<image_data_any>;
|
||||
//template class agg_text_renderer<image_32>;
|
||||
template class agg_text_renderer<image_data_rgba8>;
|
||||
template class grid_text_renderer<grid>;
|
||||
|
||||
} // namespace mapnik
|
||||
|
|
|
@ -83,8 +83,8 @@ int main(int argc, char** argv)
|
|||
mapnik::Map m = map;
|
||||
m.add_layer(l);
|
||||
m.zoom_all();
|
||||
mapnik::image_32 im(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_32> ren(m,im);
|
||||
mapnik::image_data_rgba8 im(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_data_rgba8> ren(m,im);
|
||||
//std::clog << mapnik::save_map_to_string(m) << "\n";
|
||||
BOOST_TEST(true);
|
||||
// should throw here with "CSV Plugin: no attribute 'foo'. Valid attributes are: x,y."
|
||||
|
|
|
@ -82,8 +82,8 @@ int main(int argc, char** argv)
|
|||
m.insert_style("style", std::move(the_style) );
|
||||
m.zoom_to_box(mapnik::box2d<double>(-256,-256,
|
||||
256,256));
|
||||
mapnik::image_32 buf(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_32> ren(m,buf);
|
||||
mapnik::image_data_rgba8 buf(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_data_rgba8> ren(m,buf);
|
||||
ren.apply();
|
||||
} catch (std::exception const& ex) {
|
||||
BOOST_TEST_EQ(std::string(ex.what()),std::string("Unable to find specified font face 'DejaVu Sans Book' in font set: 'fontset'"));
|
||||
|
|
|
@ -44,16 +44,6 @@ int main(int argc, char** argv)
|
|||
}
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
mapnik::image_32 im(-10,-10); // should throw rather than overflow
|
||||
BOOST_TEST( im.width() < 10 ); // should not get here, but if we did this test should fail
|
||||
}
|
||||
catch (std::exception const& ex)
|
||||
{
|
||||
BOOST_TEST( true ); // should hit bad alloc here
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
mapnik::image_data_rgba8 im(-10,-10); // should throw rather than overflow
|
||||
|
|
|
@ -60,8 +60,8 @@ int main(int argc, char** argv)
|
|||
|
||||
m.zoom_all();
|
||||
|
||||
image_32 image(m.width(), m.height());
|
||||
agg_renderer<image_32> ren(m, image);
|
||||
image_data_rgba8 image(m.width(), m.height());
|
||||
agg_renderer<image_data_rgba8> ren(m, image);
|
||||
ren.apply();
|
||||
|
||||
BOOST_TEST_EQ(image.painted(), true);
|
||||
|
|
|
@ -30,19 +30,19 @@ bool compare_images(std::string const& src_fn,std::string const& dest_fn)
|
|||
{
|
||||
throw mapnik::image_reader_exception("Failed to load: " + dest_fn);
|
||||
}
|
||||
std::shared_ptr<image_32> image_ptr1 = std::make_shared<image_32>(reader1->width(),reader1->height());
|
||||
reader1->read(0,0,image_ptr1->data());
|
||||
std::shared_ptr<image_data_rgba8> image_ptr1 = std::make_shared<image_data_rgba8>(reader1->width(),reader1->height());
|
||||
reader1->read(0,0,*image_ptr1);
|
||||
|
||||
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(src_fn,"png"));
|
||||
if (!reader2.get())
|
||||
{
|
||||
throw mapnik::image_reader_exception("Failed to load: " + src_fn);
|
||||
}
|
||||
std::shared_ptr<image_32> image_ptr2 = std::make_shared<image_32>(reader2->width(),reader2->height());
|
||||
reader2->read(0,0,image_ptr2->data());
|
||||
std::shared_ptr<image_data_rgba8> image_ptr2 = std::make_shared<image_data_rgba8>(reader2->width(),reader2->height());
|
||||
reader2->read(0,0,*image_ptr2);
|
||||
|
||||
image_data_rgba8 const& dest = image_ptr1->data();
|
||||
image_data_rgba8 const& src = image_ptr2->data();
|
||||
image_data_rgba8 const& dest = *image_ptr1;
|
||||
image_data_rgba8 const& src = *image_ptr2;
|
||||
|
||||
unsigned int width = src.width();
|
||||
unsigned int height = src.height();
|
||||
|
@ -78,21 +78,21 @@ int main(int argc, char** argv)
|
|||
mapnik::Map m(256,256);
|
||||
mapnik::load_map(m,"./tests/data/good_maps/marker-text-line.xml",false);
|
||||
m.zoom_all();
|
||||
mapnik::image_32 im(m.width(),m.height());
|
||||
mapnik::image_data_rgba8 im(m.width(),m.height());
|
||||
double scale_factor = 1.2;
|
||||
|
||||
// render normally with apply() and just map and image
|
||||
mapnik::agg_renderer<mapnik::image_32> renderer1(m,im,scale_factor);
|
||||
mapnik::agg_renderer<mapnik::image_data_rgba8> renderer1(m,im,scale_factor);
|
||||
renderer1.apply();
|
||||
std::string actual1("/tmp/map-request-marker-text-line-actual1.png");
|
||||
//mapnik::save_to_file(im.data(),expected);
|
||||
mapnik::save_to_file(im.data(),actual1);
|
||||
//mapnik::save_to_file(im,expected);
|
||||
mapnik::save_to_file(im,actual1);
|
||||
// TODO - re-enable if we can control the freetype/cairo versions used
|
||||
// https://github.com/mapnik/mapnik/issues/1868
|
||||
//BOOST_TEST(compare_images(actual1,expected));
|
||||
|
||||
// reset image
|
||||
mapnik::fill(im.data(), 0);
|
||||
mapnik::fill(im, 0);
|
||||
|
||||
// set up a mapnik::request object
|
||||
mapnik::request req(m.width(),m.height(),m.get_current_extent());
|
||||
|
@ -100,19 +100,19 @@ int main(int argc, char** argv)
|
|||
|
||||
// render using apply() and mapnik::request
|
||||
mapnik::attributes vars;
|
||||
mapnik::agg_renderer<mapnik::image_32> renderer2(m,req,vars,im,scale_factor);
|
||||
mapnik::agg_renderer<mapnik::image_data_rgba8> renderer2(m,req,vars,im,scale_factor);
|
||||
renderer2.apply();
|
||||
std::string actual2("/tmp/map-request-marker-text-line-actual2.png");
|
||||
mapnik::save_to_file(im.data(),actual2);
|
||||
mapnik::save_to_file(im,actual2);
|
||||
// TODO - re-enable if we can control the freetype/cairo versions used
|
||||
// https://github.com/mapnik/mapnik/issues/1868
|
||||
//BOOST_TEST(compare_images(actual2,expected));
|
||||
|
||||
// reset image
|
||||
mapnik::fill(im.data(), 0);
|
||||
mapnik::fill(im, 0);
|
||||
|
||||
// render with apply_to_layer api and mapnik::request params passed to apply_to_layer
|
||||
mapnik::agg_renderer<mapnik::image_32> renderer3(m,req,vars,im,scale_factor);
|
||||
mapnik::agg_renderer<mapnik::image_data_rgba8> renderer3(m,req,vars,im,scale_factor);
|
||||
renderer3.start_map_processing(m);
|
||||
mapnik::projection map_proj(m.srs(),true);
|
||||
double scale_denom = mapnik::scale_denominator(req.scale(),map_proj.is_geographic());
|
||||
|
@ -137,7 +137,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
renderer3.end_map_processing(m);
|
||||
std::string actual3("/tmp/map-request-marker-text-line-actual3.png");
|
||||
mapnik::save_to_file(im.data(),actual3);
|
||||
mapnik::save_to_file(im,actual3);
|
||||
// TODO - re-enable if we can control the freetype/cairo versions used
|
||||
// https://github.com/mapnik/mapnik/issues/1868
|
||||
//BOOST_TEST(compare_images(actual3,expected));
|
||||
|
|
|
@ -111,7 +111,7 @@ int main (int argc,char** argv)
|
|||
mapnik::Map map(600,400);
|
||||
mapnik::load_map(map,xml_file,true);
|
||||
map.zoom_all();
|
||||
mapnik::image_32 im(map.width(),map.height());
|
||||
mapnik::image_data_rgba8 im(map.width(),map.height());
|
||||
mapnik::request req(map.width(),map.height(),map.get_current_extent());
|
||||
req.set_buffer_size(map.buffer_size());
|
||||
mapnik::attributes vars;
|
||||
|
@ -138,9 +138,9 @@ int main (int argc,char** argv)
|
|||
}
|
||||
}
|
||||
}
|
||||
mapnik::agg_renderer<mapnik::image_32> ren(map,req,vars,im,scale_factor,0,0);
|
||||
mapnik::agg_renderer<mapnik::image_data_rgba8> ren(map,req,vars,im,scale_factor,0,0);
|
||||
ren.apply();
|
||||
mapnik::save_to_file(im.data(),img_file);
|
||||
mapnik::save_to_file(im,img_file);
|
||||
if (auto_open)
|
||||
{
|
||||
std::ostringstream s;
|
||||
|
|
|
@ -158,8 +158,8 @@ int main (int argc,char** argv)
|
|||
std::clog << "found width of '" << w << "' and height of '" << h << "'\n";
|
||||
}
|
||||
// 10 pixel buffer to avoid edge clipping of 100% svg's
|
||||
mapnik::image_32 im(w+0,h+0);
|
||||
agg::rendering_buffer buf(im.raw_data(), im.width(), im.height(), im.width() * 4);
|
||||
mapnik::image_data_rgba8 im(w+0,h+0);
|
||||
agg::rendering_buffer buf(im.getBytes(), im.width(), im.height(), im.width() * 4);
|
||||
pixfmt pixf(buf);
|
||||
renderer_base renb(pixf);
|
||||
|
||||
|
@ -181,8 +181,8 @@ int main (int argc,char** argv)
|
|||
svg_renderer_this.render(ras_ptr, sl, renb, mtx, opacity, bbox);
|
||||
|
||||
boost::algorithm::ireplace_last(svg_name,".svg",".png");
|
||||
demultiply_alpha(im.data());
|
||||
mapnik::save_to_file<mapnik::image_data_rgba8>(im.data(),svg_name,"png");
|
||||
demultiply_alpha(im);
|
||||
mapnik::save_to_file<mapnik::image_data_rgba8>(im,svg_name,"png");
|
||||
if (auto_open)
|
||||
{
|
||||
std::ostringstream s;
|
||||
|
|
Loading…
Reference in a new issue