|
|
@@ -1734,6 +1734,14 @@ bool Adafruit_GFX_Button::justReleased() { return (!currstate && laststate); }
|
|
|
// scanline pad).
|
|
|
// NOT EXTENSIVELY TESTED YET. MAY CONTAIN WORST BUGS KNOWN TO HUMANKIND.
|
|
|
|
|
|
+#ifdef __AVR__
|
|
|
+// Bitmask tables of 0x80>>X and ~(0x80>>X), because X>>Y is slow on AVR
|
|
|
+const uint8_t PROGMEM GFXcanvas1::GFXsetBit[] = {0x80, 0x40, 0x20, 0x10,
|
|
|
+ 0x08, 0x04, 0x02, 0x01};
|
|
|
+const uint8_t PROGMEM GFXcanvas1::GFXclrBit[] = {0x7F, 0xBF, 0xDF, 0xEF,
|
|
|
+ 0xF7, 0xFB, 0xFD, 0xFE};
|
|
|
+#endif
|
|
|
+
|
|
|
/**************************************************************************/
|
|
|
/*!
|
|
|
@brief Instatiate a GFX 1-bit canvas context for graphics
|
|
|
@@ -1763,18 +1771,10 @@ GFXcanvas1::~GFXcanvas1(void) {
|
|
|
@brief Draw a pixel to the canvas framebuffer
|
|
|
@param x x coordinate
|
|
|
@param y y coordinate
|
|
|
- @param color 16-bit 5-6-5 Color to fill with
|
|
|
+ @param color Binary (on or off) color to fill with
|
|
|
*/
|
|
|
/**************************************************************************/
|
|
|
void GFXcanvas1::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
|
|
-#ifdef __AVR__
|
|
|
- // Bitmask tables of 0x80>>X and ~(0x80>>X), because X>>Y is slow on AVR
|
|
|
- static const uint8_t PROGMEM GFXsetBit[] = {0x80, 0x40, 0x20, 0x10,
|
|
|
- 0x08, 0x04, 0x02, 0x01},
|
|
|
- GFXclrBit[] = {0x7F, 0xBF, 0xDF, 0xEF,
|
|
|
- 0xF7, 0xFB, 0xFD, 0xFE};
|
|
|
-#endif
|
|
|
-
|
|
|
if (buffer) {
|
|
|
if ((x < 0) || (y < 0) || (x >= _width) || (y >= _height))
|
|
|
return;
|
|
|
@@ -1812,10 +1812,67 @@ void GFXcanvas1::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/**********************************************************************/
|
|
|
+/*!
|
|
|
+ @brief Get the pixel color value at a given coordinate
|
|
|
+ @param x x coordinate
|
|
|
+ @param y y coordinate
|
|
|
+ @returns The desired pixel's binary color value, either 0x1 (on) or 0x0
|
|
|
+ (off)
|
|
|
+*/
|
|
|
+/**********************************************************************/
|
|
|
+bool GFXcanvas1::getPixel(int16_t x, int16_t y) const {
|
|
|
+ int16_t t;
|
|
|
+ switch (rotation) {
|
|
|
+ case 1:
|
|
|
+ t = x;
|
|
|
+ x = WIDTH - 1 - y;
|
|
|
+ y = t;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ x = WIDTH - 1 - x;
|
|
|
+ y = HEIGHT - 1 - y;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ t = x;
|
|
|
+ x = y;
|
|
|
+ y = HEIGHT - 1 - t;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return getRawPixel(x, y);
|
|
|
+}
|
|
|
+
|
|
|
+/**********************************************************************/
|
|
|
+/*!
|
|
|
+ @brief Get the pixel color value at a given, unrotated coordinate.
|
|
|
+ This method is intended for hardware drivers to get pixel value
|
|
|
+ in physical coordinates.
|
|
|
+ @param x x coordinate
|
|
|
+ @param y y coordinate
|
|
|
+ @returns The desired pixel's binary color value, either 0x1 (on) or 0x0
|
|
|
+ (off)
|
|
|
+*/
|
|
|
+/**********************************************************************/
|
|
|
+bool GFXcanvas1::getRawPixel(int16_t x, int16_t y) const {
|
|
|
+ if ((x < 0) || (y < 0) || (x >= WIDTH) || (y >= HEIGHT))
|
|
|
+ return 0;
|
|
|
+ if (this->getBuffer()) {
|
|
|
+ uint8_t *buffer = this->getBuffer();
|
|
|
+ uint8_t *ptr = &buffer[(x / 8) + y * ((WIDTH + 7) / 8)];
|
|
|
+
|
|
|
+#ifdef __AVR__
|
|
|
+ return ((*ptr) & pgm_read_byte(&GFXsetBit[x & 7])) != 0;
|
|
|
+#else
|
|
|
+ return ((*ptr) & (0x80 >> (x & 7))) != 0;
|
|
|
+#endif
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
/**************************************************************************/
|
|
|
/*!
|
|
|
@brief Fill the framebuffer completely with one color
|
|
|
- @param color 16-bit 5-6-5 Color to fill with
|
|
|
+ @param color Binary (on or off) color to fill with
|
|
|
*/
|
|
|
/**************************************************************************/
|
|
|
void GFXcanvas1::fillScreen(uint16_t color) {
|
|
|
@@ -1854,7 +1911,7 @@ GFXcanvas8::~GFXcanvas8(void) {
|
|
|
@brief Draw a pixel to the canvas framebuffer
|
|
|
@param x x coordinate
|
|
|
@param y y coordinate
|
|
|
- @param color 16-bit 5-6-5 Color to fill with
|
|
|
+ @param color 8-bit Color to fill with. Only lower byte of uint16_t is used.
|
|
|
*/
|
|
|
/**************************************************************************/
|
|
|
void GFXcanvas8::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
|
|
@@ -1884,10 +1941,58 @@ void GFXcanvas8::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/**********************************************************************/
|
|
|
+/*!
|
|
|
+ @brief Get the pixel color value at a given coordinate
|
|
|
+ @param x x coordinate
|
|
|
+ @param y y coordinate
|
|
|
+ @returns The desired pixel's 8-bit color value
|
|
|
+*/
|
|
|
+/**********************************************************************/
|
|
|
+uint8_t GFXcanvas8::getPixel(int16_t x, int16_t y) const {
|
|
|
+ int16_t t;
|
|
|
+ switch (rotation) {
|
|
|
+ case 1:
|
|
|
+ t = x;
|
|
|
+ x = WIDTH - 1 - y;
|
|
|
+ y = t;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ x = WIDTH - 1 - x;
|
|
|
+ y = HEIGHT - 1 - y;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ t = x;
|
|
|
+ x = y;
|
|
|
+ y = HEIGHT - 1 - t;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return getRawPixel(x, y);
|
|
|
+}
|
|
|
+
|
|
|
+/**********************************************************************/
|
|
|
+/*!
|
|
|
+ @brief Get the pixel color value at a given, unrotated coordinate.
|
|
|
+ This method is intended for hardware drivers to get pixel value
|
|
|
+ in physical coordinates.
|
|
|
+ @param x x coordinate
|
|
|
+ @param y y coordinate
|
|
|
+ @returns The desired pixel's 8-bit color value
|
|
|
+*/
|
|
|
+/**********************************************************************/
|
|
|
+uint8_t GFXcanvas8::getRawPixel(int16_t x, int16_t y) const {
|
|
|
+ if ((x < 0) || (y < 0) || (x >= WIDTH) || (y >= HEIGHT))
|
|
|
+ return 0;
|
|
|
+ if (buffer) {
|
|
|
+ return buffer[x + y * WIDTH];
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
/**************************************************************************/
|
|
|
/*!
|
|
|
@brief Fill the framebuffer completely with one color
|
|
|
- @param color 16-bit 5-6-5 Color to fill with
|
|
|
+ @param color 8-bit Color to fill with. Only lower byte of uint16_t is used.
|
|
|
*/
|
|
|
/**************************************************************************/
|
|
|
void GFXcanvas8::fillScreen(uint16_t color) {
|
|
|
@@ -1993,6 +2098,54 @@ void GFXcanvas16::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/**********************************************************************/
|
|
|
+/*!
|
|
|
+ @brief Get the pixel color value at a given coordinate
|
|
|
+ @param x x coordinate
|
|
|
+ @param y y coordinate
|
|
|
+ @returns The desired pixel's 16-bit 5-6-5 color value
|
|
|
+*/
|
|
|
+/**********************************************************************/
|
|
|
+uint16_t GFXcanvas16::getPixel(int16_t x, int16_t y) const {
|
|
|
+ int16_t t;
|
|
|
+ switch (rotation) {
|
|
|
+ case 1:
|
|
|
+ t = x;
|
|
|
+ x = WIDTH - 1 - y;
|
|
|
+ y = t;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ x = WIDTH - 1 - x;
|
|
|
+ y = HEIGHT - 1 - y;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ t = x;
|
|
|
+ x = y;
|
|
|
+ y = HEIGHT - 1 - t;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return getRawPixel(x, y);
|
|
|
+}
|
|
|
+
|
|
|
+/**********************************************************************/
|
|
|
+/*!
|
|
|
+ @brief Get the pixel color value at a given, unrotated coordinate.
|
|
|
+ This method is intended for hardware drivers to get pixel value
|
|
|
+ in physical coordinates.
|
|
|
+ @param x x coordinate
|
|
|
+ @param y y coordinate
|
|
|
+ @returns The desired pixel's 16-bit 5-6-5 color value
|
|
|
+*/
|
|
|
+/**********************************************************************/
|
|
|
+uint16_t GFXcanvas16::getRawPixel(int16_t x, int16_t y) const {
|
|
|
+ if ((x < 0) || (y < 0) || (x >= WIDTH) || (y >= HEIGHT))
|
|
|
+ return 0;
|
|
|
+ if (buffer) {
|
|
|
+ return buffer[x + y * WIDTH];
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
/**************************************************************************/
|
|
|
/*!
|
|
|
@brief Fill the framebuffer completely with one color
|