Merge pull request #2643 from mapnik/feature/blend_cleanup

Removed the set_rectangle_alpha code from image_32. Added new blend usin...
This commit is contained in:
Blake Thompson 2015-01-15 15:11:44 -06:00
commit c74df56200
2 changed files with 4 additions and 93 deletions

View file

@ -189,9 +189,11 @@ std::shared_ptr<image_32> frombuffer(PyObject * obj)
}
void blend (image_32 & im, unsigned x, unsigned y, image_32 const& im2, float opacity)
void blend (image_32 & im, unsigned x, unsigned y, image_32 & im2, float opacity)
{
im.set_rectangle_alpha2(im2.data(),x,y,opacity);
mapnik::premultiply_alpha(im.data());
mapnik::premultiply_alpha(im2.data());
mapnik::composite(im.data(),im2.data(),mapnik::src_over,opacity,x,y);
}
bool premultiplied(image_32 &im)

View file

@ -157,97 +157,6 @@ public:
}
}
inline void set_rectangle_alpha(int x0,int y0,const image_data_rgba8& data)
{
box2d<int> ext0(0,0,data_.width(),data_.height());
box2d<int> ext1(x0,y0,x0 + data.width(),y0 + data.height());
if (ext0.intersects(ext1))
{
box2d<int> box = ext0.intersect(ext1);
for (int y = box.miny(); y < box.maxy(); ++y)
{
unsigned int* row_to = data_.getRow(y);
unsigned int const * row_from = data.getRow(y-y0);
for (int x = box.minx(); x < box.maxx(); ++x)
{
unsigned rgba0 = row_to[x];
unsigned rgba1 = row_from[x-x0];
unsigned a1 = (rgba1 >> 24) & 0xff;
if (a1 == 0) continue;
if (a1 == 0xff)
{
row_to[x] = rgba1;
continue;
}
unsigned r1 = rgba1 & 0xff;
unsigned g1 = (rgba1 >> 8 ) & 0xff;
unsigned b1 = (rgba1 >> 16) & 0xff;
unsigned a0 = (rgba0 >> 24) & 0xff;
unsigned r0 = (rgba0 & 0xff) * a0;
unsigned g0 = ((rgba0 >> 8 ) & 0xff) * a0;
unsigned b0 = ((rgba0 >> 16) & 0xff) * a0;
a0 = ((a1 + a0) << 8) - a0*a1;
r0 = ((((r1 << 8) - r0) * a1 + (r0 << 8)) / a0);
g0 = ((((g1 << 8) - g0) * a1 + (g0 << 8)) / a0);
b0 = ((((b1 << 8) - b0) * a1 + (b0 << 8)) / a0);
a0 = a0 >> 8;
row_to[x] = (a0 << 24)| (b0 << 16) | (g0 << 8) | (r0) ;
}
}
}
}
inline void set_rectangle_alpha2(image_data_rgba8 const& data, unsigned x0, unsigned y0, float opacity)
{
box2d<int> ext0(0,0,data_.width(),data_.height());
box2d<int> ext1(x0,y0,x0 + data.width(),y0 + data.height());
if (ext0.intersects(ext1))
{
box2d<int> box = ext0.intersect(ext1);
for (int y = box.miny(); y < box.maxy(); ++y)
{
unsigned int* row_to = data_.getRow(y);
unsigned int const * row_from = data.getRow(y-y0);
for (int x = box.minx(); x < box.maxx(); ++x)
{
unsigned rgba0 = row_to[x];
unsigned rgba1 = row_from[x-x0];
unsigned a1 = int( ((rgba1 >> 24) & 0xff) * opacity );
if (a1 == 0) continue;
if (a1 == 0xff)
{
row_to[x] = rgba1;
continue;
}
unsigned r1 = rgba1 & 0xff;
unsigned g1 = (rgba1 >> 8 ) & 0xff;
unsigned b1 = (rgba1 >> 16) & 0xff;
unsigned a0 = (rgba0 >> 24) & 0xff;
unsigned r0 = rgba0 & 0xff ;
unsigned g0 = (rgba0 >> 8 ) & 0xff;
unsigned b0 = (rgba0 >> 16) & 0xff;
unsigned atmp = a1 + a0 - ((a1 * a0 + 255) >> 8);
if (atmp)
{
r0 = byte((r1 * a1 + (r0 * a0) - ((r0 * a0 * a1 + 255) >> 8)) / atmp);
g0 = byte((g1 * a1 + (g0 * a0) - ((g0 * a0 * a1 + 255) >> 8)) / atmp);
b0 = byte((b1 * a1 + (b0 * a0) - ((b0 * a0 * a1 + 255) >> 8)) / atmp);
}
a0 = byte(atmp);
row_to[x] = (a0 << 24)| (b0 << 16) | (g0 << 8) | (r0) ;
}
}
}
}
template <typename MergeMethod>
inline void merge_rectangle(image_data_rgba8 const& data, unsigned x0, unsigned y0, float opacity)
{