Improve selection tools performance

This commit reduce the number of computations needed to calculate the new
mask bounds. (E.g. avoiding get pixel calls in Mask::shrink().)
This commit is contained in:
David Capello 2015-06-25 17:53:11 -03:00
parent 3159acdc5c
commit 4b213f3039
2 changed files with 10 additions and 1 deletions

View File

@ -254,6 +254,7 @@ public:
class SelectionInk : public Ink {
bool m_modify_selection;
Mask m_mask;
Rect m_maxBounds;
public:
SelectionInk() { m_modify_selection = false; }
@ -274,6 +275,8 @@ public:
m_mask.subtract(gfx::Rect(x1-offset.x, y-offset.y, x2-x1+1, 1));
break;
}
m_maxBounds |= gfx::Rect(x1-offset.x, y-offset.y, x2-x1+1, 1);
}
// TODO show the selection-preview with a XOR color or something like that
else {
@ -287,11 +290,17 @@ public:
m_modify_selection = state;
if (state) {
m_maxBounds = gfx::Rect(0, 0, 0, 0);
m_mask.copyFrom(loop->getMask());
m_mask.freeze();
m_mask.reserve(loop->sprite()->bounds());
}
else {
// We can intersect the used bounds in inkHline() calls to
// reduce the shrink computation.
m_mask.intersect(m_maxBounds);
m_mask.unfreeze();
loop->setMask(&m_mask);

View File

@ -385,7 +385,7 @@ void Mask::shrink()
{ \
for (u = u_begin; u u_op u_final; u u_add) { \
for (v = v_begin; v v_op v_final; v v_add) { \
if (m_bitmap->getPixel(U, V)) \
if (get_pixel_fast<BitmapTraits>(m_bitmap.get(), U, V)) \
break; \
} \
if (v == v_final) \