Migrated composite_pixel out of image_32, it is now in image_utils. Ref #2633

This commit is contained in:
Blake Thompson 2015-01-16 16:48:43 -06:00
parent 0b2c4e57cf
commit 1470bea9cb
5 changed files with 90 additions and 34 deletions

View file

@ -105,8 +105,6 @@ public:
}
}
void composite_pixel(unsigned op, int x,int y,unsigned c, unsigned cover, double opacity);
inline unsigned width() const
{
return data_.width();

View file

@ -138,6 +138,15 @@ MAPNIK_DECL void fill (T1 & data, T2 const& c);
template <typename T>
MAPNIK_DECL void set_rectangle (T & dst, T const& src, int x = 0, int y = 0);
template <typename T>
MAPNIK_DECL bool check_bounds (T const& data, int x, int y)
{
return (x >= 0 && x < static_cast<int>(data.width()) && y >= 0 && y < static_cast<int>(data.height()));
}
template <typename T>
MAPNIK_DECL void composite_pixel(T & data, unsigned op, int x, int y, unsigned c, unsigned cover, double opacity );
inline bool is_png(std::string const& filename)
{
return boost::algorithm::iends_with(filename,std::string(".png"));

View file

@ -53,23 +53,4 @@ image_32::image_32(image_data_rgba8 && data)
image_32::~image_32() {}
void image_32::composite_pixel(unsigned op, int x,int y, unsigned c, unsigned cover, double opacity)
{
using color_type = agg::rgba8;
using value_type = color_type::value_type;
using order_type = agg::order_rgba;
using blender_type = agg::comp_op_adaptor_rgba<color_type,order_type>;
if (checkBounds(x,y))
{
unsigned rgba = data_(x,y);
unsigned ca = (unsigned)(((c >> 24) & 0xff) * opacity);
unsigned cb = (c >> 16 ) & 0xff;
unsigned cg = (c >> 8) & 0xff;
unsigned cr = (c & 0xff);
blender_type::blend_pix(op, (value_type*)&rgba, cr, cg, cb, ca, cover);
data_(x,y) = rgba;
}
}
}

View file

@ -935,16 +935,83 @@ void visitor_set_rectangle::operator()<image_data_null> (image_data_null &)
} // end detail ns
template <typename T>
void set_rectangle (T & dst, T const& src, int x, int y)
MAPNIK_DECL void set_rectangle (T & dst, T const& src, int x, int y)
{
detail::visitor_set_rectangle visit(src, x, y);
visit(dst);
}
template <>
void set_rectangle<image_data_any> (image_data_any & dst, image_data_any const& src, int x, int y)
MAPNIK_DECL void set_rectangle<image_data_any> (image_data_any & dst, image_data_any const& src, int x, int y)
{
util::apply_visitor(detail::visitor_set_rectangle(src, x, y), dst);
}
namespace detail
{
struct visitor_composite_pixel
{
// Obviously c variable would only work for rgba8 currently, but didn't want to
// make this a template class until new rgba types exist.
visitor_composite_pixel(unsigned op, int x,int y, unsigned c, unsigned cover, double opacity)
: opacity_(opacity),
op_(op),
x_(x),
y_(y),
c_(c),
cover_(cover) {}
template <typename T>
void operator() (T & data)
{
throw std::runtime_error("Composite pixel is not supported for this data type");
}
private:
double opacity_;
unsigned op_;
int x_;
int y_;
int c_;
unsigned cover_;
};
template<>
void visitor_composite_pixel::operator()<image_data_rgba8> (image_data_rgba8 & data)
{
using color_type = agg::rgba8;
using value_type = color_type::value_type;
using order_type = agg::order_rgba;
using blender_type = agg::comp_op_adaptor_rgba<color_type,order_type>;
if (mapnik::check_bounds(data, x_, y_))
{
unsigned rgba = data(x_,y_);
unsigned ca = (unsigned)(((c_ >> 24) & 0xff) * opacity_);
unsigned cb = (c_ >> 16 ) & 0xff;
unsigned cg = (c_ >> 8) & 0xff;
unsigned cr = (c_ & 0xff);
blender_type::blend_pix(op_, (value_type*)&rgba, cr, cg, cb, ca, cover_);
data(x_,y_) = rgba;
}
}
} // end detail ns
template <typename T>
MAPNIK_DECL void composite_pixel(T & data, unsigned op, int x, int y, unsigned c, unsigned cover, double opacity )
{
util::apply_visitor(detail::visitor_composite_pixel(op, x, y, c, cover, opacity), data);
}
// Temporary delete later
template <>
MAPNIK_DECL void composite_pixel<image_data_rgba8>(image_data_rgba8 & data, unsigned op, int x, int y, unsigned c, unsigned cover, double opacity )
{
detail::visitor_composite_pixel visitor(op, x, y, c, cover, opacity);
visitor(data);
}
} // end ns

View file

@ -27,6 +27,7 @@
#include <mapnik/text/text_properties.hpp>
#include <mapnik/font_engine_freetype.hpp>
#include <mapnik/text/face.hpp>
#include <mapnik/image_util.hpp>
namespace mapnik
{
@ -102,7 +103,7 @@ void composite_bitmap(T & pixmap, FT_Bitmap *bitmap, unsigned rgba, int x, int y
unsigned gray=bitmap->buffer[q*bitmap->width+p];
if (gray)
{
pixmap.composite_pixel(comp_op, i, j, rgba, gray, opacity);
mapnik::composite_pixel(pixmap.data(), comp_op, i, j, rgba, gray, opacity);
}
}
}
@ -291,17 +292,17 @@ void agg_text_renderer<T>::render_halo(FT_Bitmap *bitmap,
int gray = bitmap->buffer[y*bitmap->width+x];
if (gray)
{
pixmap_.composite_pixel(comp_op, x+x1-1, y+y1-1, rgba, gray*halo_radius*halo_radius, opacity);
pixmap_.composite_pixel(comp_op, x+x1, y+y1-1, rgba, gray*halo_radius, opacity);
pixmap_.composite_pixel(comp_op, x+x1+1, y+y1-1, rgba, gray*halo_radius*halo_radius, opacity);
mapnik::composite_pixel(pixmap_.data(), comp_op, x+x1-1, y+y1-1, rgba, gray*halo_radius*halo_radius, opacity);
mapnik::composite_pixel(pixmap_.data(), comp_op, x+x1, y+y1-1, rgba, gray*halo_radius, opacity);
mapnik::composite_pixel(pixmap_.data(), comp_op, x+x1+1, y+y1-1, rgba, gray*halo_radius*halo_radius, opacity);
pixmap_.composite_pixel(comp_op, x+x1-1, y+y1, rgba, gray*halo_radius, opacity);
pixmap_.composite_pixel(comp_op, x+x1, y+y1, rgba, gray, opacity);
pixmap_.composite_pixel(comp_op, x+x1+1, y+y1, rgba, gray*halo_radius, opacity);
mapnik::composite_pixel(pixmap_.data(), comp_op, x+x1-1, y+y1, rgba, gray*halo_radius, opacity);
mapnik::composite_pixel(pixmap_.data(), comp_op, x+x1, y+y1, rgba, gray, opacity);
mapnik::composite_pixel(pixmap_.data(), comp_op, x+x1+1, y+y1, rgba, gray*halo_radius, opacity);
pixmap_.composite_pixel(comp_op, x+x1-1, y+y1+1, rgba, gray*halo_radius*halo_radius, opacity);
pixmap_.composite_pixel(comp_op, x+x1, y+y1+1, rgba, gray*halo_radius, opacity);
pixmap_.composite_pixel(comp_op, x+x1+1, y+y1+1, rgba, gray*halo_radius*halo_radius, opacity);
mapnik::composite_pixel(pixmap_.data(), comp_op, x+x1-1, y+y1+1, rgba, gray*halo_radius*halo_radius, opacity);
mapnik::composite_pixel(pixmap_.data(), comp_op, x+x1, y+y1+1, rgba, gray*halo_radius, opacity);
mapnik::composite_pixel(pixmap_.data(), comp_op, x+x1+1, y+y1+1, rgba, gray*halo_radius*halo_radius, opacity);
}
}
}
@ -317,7 +318,7 @@ void agg_text_renderer<T>::render_halo(FT_Bitmap *bitmap,
{
for (int n=-halo_radius; n <=halo_radius; ++n)
for (int m=-halo_radius; m <= halo_radius; ++m)
pixmap_.composite_pixel(comp_op, x+x1+m, y+y1+n, rgba, gray, opacity);
mapnik::composite_pixel(pixmap_.data(), comp_op, x+x1+m, y+y1+n, rgba, gray, opacity);
}
}
}