Merge_rectangle has met the wood chipper. Ref #2633
This commit is contained in:
parent
a7b8ca2888
commit
0b2c4e57cf
1 changed files with 0 additions and 41 deletions
|
@ -117,47 +117,6 @@ public:
|
|||
return data_.height();
|
||||
}
|
||||
|
||||
template <typename MergeMethod>
|
||||
inline void merge_rectangle(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;
|
||||
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 a = (a1 * 255 + (255 - a1) * a0 + 127)/255;
|
||||
|
||||
MergeMethod::mergeRGB(r0,g0,b0,r1,g1,b1);
|
||||
|
||||
r0 = (r1*a1 + (((255 - a1) * a0 + 127)/255) * r0 + 127)/a;
|
||||
g0 = (g1*a1 + (((255 - a1) * a0 + 127)/255) * g0 + 127)/a;
|
||||
b0 = (b1*a1 + (((255 - a1) * a0 + 127)/255) * b0 + 127)/a;
|
||||
|
||||
row_to[x] = (a << 24)| (b0 << 16) | (g0 << 8) | (r0) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue