From 205e84eae699965ce885bbaf574d7919a9436902 Mon Sep 17 00:00:00 2001 From: Scott Allen Date: Tue, 23 Jun 2020 14:40:30 -0400 Subject: [PATCH] Fix off screen tests for bitmap functions Issue reported by @MrBlinky For drawBitmap(), drawSlowXYBitmap() and drawCompressed() the initial check for the bitmap being entirely off screen would sometimes consider a bitmap to be partially on screen when it is only one pixel above or to the left of the screen. This would result in unnecessarily doing the work to draw the bitmap when none of it would be visible. --- src/Arduboy2.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Arduboy2.cpp b/src/Arduboy2.cpp index d21c7ec..772af5c 100644 --- a/src/Arduboy2.cpp +++ b/src/Arduboy2.cpp @@ -819,7 +819,7 @@ void Arduboy2Base::drawBitmap uint8_t color) { // no need to draw at all if we're offscreen - if (x+w < 0 || x > WIDTH-1 || y+h < 0 || y > HEIGHT-1) + if (x + w <= 0 || x > WIDTH - 1 || y + h <= 0 || y > HEIGHT - 1) return; int yOffset = abs(y) % 8; @@ -864,7 +864,7 @@ void Arduboy2Base::drawSlowXYBitmap (int16_t x, int16_t y, const uint8_t *bitmap, uint8_t w, uint8_t h, uint8_t color) { // no need to draw at all of we're offscreen - if (x+w < 0 || x > WIDTH-1 || y+h < 0 || y > HEIGHT-1) + if (x + w <= 0 || x > WIDTH - 1 || y + h <= 0 || y > HEIGHT - 1) return; int16_t xi, yi, byteWidth = (w + 7) / 8; @@ -923,7 +923,7 @@ void Arduboy2Base::drawCompressed(int16_t sx, int16_t sy, const uint8_t *bitmap, uint8_t spanColour = (uint8_t)cs.readBits(1); // starting colour // no need to draw at all if we're offscreen - if ((sx + width < 0) || (sx > WIDTH - 1) || (sy + height < 0) || (sy > HEIGHT - 1)) + if ((sx + width <= 0) || (sx > WIDTH - 1) || (sy + height <= 0) || (sy > HEIGHT - 1)) return; // sy = sy - (frame * height);