From 4b213f3039d9d2ea08ce4388ecb837e2f10cb1b1 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 25 Jun 2015 17:53:11 -0300 Subject: [PATCH] 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().) --- src/app/tools/inks.h | 9 +++++++++ src/doc/mask.cpp | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/app/tools/inks.h b/src/app/tools/inks.h index 126e717c4..af66d9f3c 100644 --- a/src/app/tools/inks.h +++ b/src/app/tools/inks.h @@ -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); diff --git a/src/doc/mask.cpp b/src/doc/mask.cpp index fc1136d13..4225b4f08 100644 --- a/src/doc/mask.cpp +++ b/src/doc/mask.cpp @@ -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(m_bitmap.get(), U, V)) \ break; \ } \ if (v == v_final) \