diff --git a/kandinsky/include/kandinsky/rect.h b/kandinsky/include/kandinsky/rect.h index fc3fe47af..afaa34bba 100644 --- a/kandinsky/include/kandinsky/rect.h +++ b/kandinsky/include/kandinsky/rect.h @@ -64,6 +64,7 @@ public: KDRect unionedWith(const KDRect & other) const; // Returns the smallest rectangle containing r1 and r2 KDRect differencedWith(const KDRect & other) const; // Returns the smallest rectangle containing r1\r2 bool contains(KDPoint p) const; + bool containsRect(const KDRect & other) const; bool isAbove(KDPoint p) const; bool isUnder(KDPoint p) const; bool isEmpty() const; diff --git a/kandinsky/src/context_pixel.cpp b/kandinsky/src/context_pixel.cpp index 25ac75896..dceb85ff9 100644 --- a/kandinsky/src/context_pixel.cpp +++ b/kandinsky/src/context_pixel.cpp @@ -19,5 +19,16 @@ KDColor KDContext::getPixel(KDPoint p) { void KDContext::getPixels(KDRect r, KDColor * pixels) { KDRect rect = r.translatedBy(m_origin); - pullRect(rect, pixels); + if (m_clippingRect.containsRect(rect)) { + pullRect(rect, pixels); + return; + } + int i = 0; + KDCoordinate yMax = r.y()+r.height(); + KDCoordinate xMax = r.x()+r.width(); + for (int y = r.y(); y < yMax; y++) { + for (int x = r.x(); x < xMax; x++) { + pixels[i++] = getPixel(KDPoint(x, y)); + } + } } diff --git a/kandinsky/src/rect.cpp b/kandinsky/src/rect.cpp index 4373d4f93..483821670 100644 --- a/kandinsky/src/rect.cpp +++ b/kandinsky/src/rect.cpp @@ -146,6 +146,16 @@ bool KDRect::contains(KDPoint p) const { return (p.x() >= x() && p.x() <= right() && p.y() >= y() && p.y() <= bottom()); } +bool KDRect::containsRect(const KDRect & other) const { + if (other.isEmpty()) { + return true; + } + if (isEmpty()) { + return false; + } + return contains(other.topLeft()) && contains(other.bottomRight()); +} + bool KDRect::isAbove(KDPoint p) const { return (p.y() >= y()); }