couple optimizations
This commit is contained in:
parent
19daab2461
commit
b47bfa185a
2 changed files with 78 additions and 86 deletions
|
@ -104,8 +104,7 @@ namespace mapnik
|
|||
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);
|
||||
|
@ -133,39 +132,23 @@ namespace mapnik
|
|||
|
||||
if (ext0.intersects(ext1))
|
||||
{
|
||||
Envelope<int> box = ext0.intersect(ext1);
|
||||
for (int y = box.miny(); y < box.maxy(); ++y)
|
||||
{
|
||||
for (int x = box.minx(); x < box.maxx(); ++x)
|
||||
{
|
||||
if ((data(x-x0,y-y0) & 0xff000000))
|
||||
{
|
||||
data_(x,y)=data(x-x0,y-y0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Envelope<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)
|
||||
{
|
||||
if (row_to[x-x0] & 0xff000000)
|
||||
{
|
||||
row_to[x-x0] = row_from[x-x0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void set_alpha(float alpha) // 0...1
|
||||
{
|
||||
unsigned w = data_.width();
|
||||
unsigned h = data_.height();
|
||||
unsigned a = int(0xff * alpha) & 0xff;
|
||||
|
||||
for (unsigned y = 0; y < h ; ++y)
|
||||
{
|
||||
for (unsigned x = 0; x < w ; ++x)
|
||||
{
|
||||
unsigned rgba = data_(x,y);
|
||||
if (rgba > 0)
|
||||
{
|
||||
data_(x,y) = (rgba & 0x00ffffff) | (a << 24);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void set_rectangle_alpha(int x0,int y0,const ImageData32& data)
|
||||
{
|
||||
Envelope<int> ext0(0,0,width_,height_);
|
||||
|
@ -176,35 +159,36 @@ namespace mapnik
|
|||
Envelope<int> box = ext0.intersect(ext1);
|
||||
for (int y = box.miny(); y < box.maxy(); ++y)
|
||||
{
|
||||
for (int x = box.minx(); x < box.maxx(); ++x)
|
||||
{
|
||||
unsigned rgba0 = data_(x,y);
|
||||
unsigned rgba1 = data(x-x0,y-y0);
|
||||
|
||||
unsigned a1 = (rgba1 >> 24) & 0xff;
|
||||
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) * 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;
|
||||
data_(x,y)= (a0 << 24)| (b0 << 16) | (g0 << 8) | (r0) ;
|
||||
}
|
||||
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;
|
||||
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(ImageData32 const& data, unsigned x0, unsigned y0, float opacity)
|
||||
{
|
||||
Envelope<int> ext0(0,0,width_,height_);
|
||||
|
@ -216,28 +200,29 @@ namespace mapnik
|
|||
Envelope<int> box = ext0.intersect(ext1);
|
||||
for (int y = box.miny(); y < box.maxy(); ++y)
|
||||
{
|
||||
for (int x = box.minx(); x < box.maxx(); ++x)
|
||||
{
|
||||
unsigned rgba0 = data_(x,y);
|
||||
unsigned rgba1 = data(x-x0,y-y0);
|
||||
|
||||
if (((rgba1 >> 24) & 255)== 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;
|
||||
|
||||
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;
|
||||
|
||||
data_(x,y)= (a << 24)| (b0 << 16) | (g0 << 8) | (r0) ;
|
||||
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];
|
||||
if (((rgba1 >> 24) & 255)== 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;
|
||||
|
||||
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) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,12 +69,13 @@ namespace mapnik
|
|||
}
|
||||
inline void set(const T& t)
|
||||
{
|
||||
for (unsigned i=0;i<width_;++i)
|
||||
for (unsigned y = 0; y < height_; ++y)
|
||||
{
|
||||
for (unsigned j=0;j<height_;++j)
|
||||
{
|
||||
(*this)(i,j)=t;
|
||||
}
|
||||
T * row = getRow(y);
|
||||
for (unsigned x = 0; x < width_; ++x)
|
||||
{
|
||||
row[x] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,6 +103,12 @@ namespace mapnik
|
|||
{
|
||||
return pData_+row*width_;
|
||||
}
|
||||
|
||||
inline T* getRow(unsigned row)
|
||||
{
|
||||
return pData_+row*width_;
|
||||
}
|
||||
|
||||
inline void setRow(unsigned row,const T* buf,unsigned size)
|
||||
{
|
||||
assert(row<height_);
|
||||
|
|
Loading…
Add table
Reference in a new issue