@@ -1736,6 +1736,12 @@ boolean Adafruit_GFX_Button::justReleased() {
17361736// scanline pad).
17371737// NOT EXTENSIVELY TESTED YET. MAY CONTAIN WORST BUGS KNOWN TO HUMANKIND.
17381738
1739+ #ifdef __AVR__
1740+ // Bitmask tables of 0x80>>X and ~(0x80>>X), because X>>Y is slow on AVR
1741+ const uint8_t PROGMEM GFXcanvas1::GFXsetBit[] = { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 };
1742+ const uint8_t PROGMEM GFXcanvas1::GFXclrBit[] = { 0x7F , 0xBF , 0xDF , 0xEF , 0xF7 , 0xFB , 0xFD , 0xFE };
1743+ #endif
1744+
17391745/* *************************************************************************/
17401746/* !
17411747 @brief Instatiate a GFX 1-bit canvas context for graphics
@@ -1765,18 +1771,10 @@ GFXcanvas1::~GFXcanvas1(void) {
17651771 @brief Draw a pixel to the canvas framebuffer
17661772 @param x x coordinate
17671773 @param y y coordinate
1768- @param color 16-bit 5-6-5 Color to fill with
1774+ @param color Binary (on or off) color to fill with
17691775*/
17701776/* *************************************************************************/
17711777void GFXcanvas1::drawPixel (int16_t x, int16_t y, uint16_t color) {
1772- #ifdef __AVR__
1773- // Bitmask tables of 0x80>>X and ~(0x80>>X), because X>>Y is slow on AVR
1774- static const uint8_t PROGMEM GFXsetBit[] = {0x80 , 0x40 , 0x20 , 0x10 ,
1775- 0x08 , 0x04 , 0x02 , 0x01 },
1776- GFXclrBit[] = {0x7F , 0xBF , 0xDF , 0xEF ,
1777- 0xF7 , 0xFB , 0xFD , 0xFE };
1778- #endif
1779-
17801778 if (buffer) {
17811779 if ((x < 0 ) || (y < 0 ) || (x >= _width) || (y >= _height))
17821780 return ;
@@ -1814,10 +1812,66 @@ void GFXcanvas1::drawPixel(int16_t x, int16_t y, uint16_t color) {
18141812 }
18151813}
18161814
1815+ /* *********************************************************************/
1816+ /* !
1817+ @brief Get the pixel color value at a given coordinate
1818+ @param x x coordinate
1819+ @param y y coordinate
1820+ @returns The desired pixel's binary color value, either 0x1 (on) or 0x0 (off)
1821+ */
1822+ /* *********************************************************************/
1823+ bool GFXcanvas1::getPixel (int16_t x, int16_t y) const {
1824+ int16_t t;
1825+ switch (rotation) {
1826+ case 1 :
1827+ t = x;
1828+ x = WIDTH - 1 - y;
1829+ y = t;
1830+ break ;
1831+ case 2 :
1832+ x = WIDTH - 1 - x;
1833+ y = HEIGHT - 1 - y;
1834+ break ;
1835+ case 3 :
1836+ t = x;
1837+ x = y;
1838+ y = HEIGHT - 1 - t;
1839+ break ;
1840+ }
1841+ return getRawPixel (x, y);
1842+ }
1843+
1844+ /* *********************************************************************/
1845+ /* !
1846+ @brief Get the pixel color value at a given, unrotated coordinate.
1847+ This method is intended for hardware drivers to get pixel value
1848+ in physical coordinates.
1849+ @param x x coordinate
1850+ @param y y coordinate
1851+ @returns The desired pixel's binary color value, either 0x1 (on) or 0x0 (off)
1852+ */
1853+ /* *********************************************************************/
1854+ bool GFXcanvas1::getRawPixel (int16_t x, int16_t y) const {
1855+ if ((x < 0 ) || (y < 0 ) || (x >= WIDTH) || (y >= HEIGHT)) return 0 ;
1856+ if (this ->getBuffer ()) {
1857+ uint8_t *buffer = this ->getBuffer ();
1858+ uint8_t *ptr = &buffer[(x / 8 ) + y * ((WIDTH + 7 ) / 8 )];
1859+
1860+ #ifdef __AVR__
1861+ return ((*ptr) & pgm_read_byte (&GFXsetBit[x & 7 ])) != 0 ;
1862+ #else
1863+ return ((*ptr) & (0x80 >> (x & 7 ))) != 0 ;
1864+ #endif
1865+ }
1866+ return 0 ;
1867+ }
1868+
1869+
1870+
18171871/* *************************************************************************/
18181872/* !
18191873 @brief Fill the framebuffer completely with one color
1820- @param color 16-bit 5-6-5 Color to fill with
1874+ @param color Binary (on or off) color to fill with
18211875*/
18221876/* *************************************************************************/
18231877void GFXcanvas1::fillScreen (uint16_t color) {
@@ -1856,7 +1910,7 @@ GFXcanvas8::~GFXcanvas8(void) {
18561910 @brief Draw a pixel to the canvas framebuffer
18571911 @param x x coordinate
18581912 @param y y coordinate
1859- @param color 16 -bit 5-6-5 Color to fill with
1913+ @param color 8 -bit Color to fill with. Only lower byte of uint16_t is used.
18601914*/
18611915/* *************************************************************************/
18621916void GFXcanvas8::drawPixel (int16_t x, int16_t y, uint16_t color) {
@@ -1886,10 +1940,58 @@ void GFXcanvas8::drawPixel(int16_t x, int16_t y, uint16_t color) {
18861940 }
18871941}
18881942
1943+ /* *********************************************************************/
1944+ /* !
1945+ @brief Get the pixel color value at a given coordinate
1946+ @param x x coordinate
1947+ @param y y coordinate
1948+ @returns The desired pixel's 8-bit color value
1949+ */
1950+ /* *********************************************************************/
1951+ uint8_t GFXcanvas8::getPixel (int16_t x, int16_t y) const {
1952+ int16_t t;
1953+ switch (rotation) {
1954+ case 1 :
1955+ t = x;
1956+ x = WIDTH - 1 - y;
1957+ y = t;
1958+ break ;
1959+ case 2 :
1960+ x = WIDTH - 1 - x;
1961+ y = HEIGHT - 1 - y;
1962+ break ;
1963+ case 3 :
1964+ t = x;
1965+ x = y;
1966+ y = HEIGHT - 1 - t;
1967+ break ;
1968+ }
1969+ return getRawPixel (x, y);
1970+ }
1971+
1972+ /* *********************************************************************/
1973+ /* !
1974+ @brief Get the pixel color value at a given, unrotated coordinate.
1975+ This method is intended for hardware drivers to get pixel value
1976+ in physical coordinates.
1977+ @param x x coordinate
1978+ @param y y coordinate
1979+ @returns The desired pixel's 8-bit color value
1980+ */
1981+ /* *********************************************************************/
1982+ uint8_t GFXcanvas8::getRawPixel (int16_t x, int16_t y) const {
1983+ if ((x < 0 ) || (y < 0 ) || (x >= WIDTH) || (y >= HEIGHT)) return 0 ;
1984+ if (buffer) {
1985+ return buffer[x + y * WIDTH];
1986+ }
1987+ return 0 ;
1988+ }
1989+
1990+
18891991/* *************************************************************************/
18901992/* !
18911993 @brief Fill the framebuffer completely with one color
1892- @param color 16 -bit 5-6-5 Color to fill with
1994+ @param color 8 -bit Color to fill with. Only lower byte of uint16_t is used.
18931995*/
18941996/* *************************************************************************/
18951997void GFXcanvas8::fillScreen (uint16_t color) {
@@ -1995,6 +2097,54 @@ void GFXcanvas16::drawPixel(int16_t x, int16_t y, uint16_t color) {
19952097 }
19962098}
19972099
2100+ /* *********************************************************************/
2101+ /* !
2102+ @brief Get the pixel color value at a given coordinate
2103+ @param x x coordinate
2104+ @param y y coordinate
2105+ @returns The desired pixel's 16-bit 5-6-5 color value
2106+ */
2107+ /* *********************************************************************/
2108+ uint16_t GFXcanvas16::getPixel (int16_t x, int16_t y) const {
2109+ int16_t t;
2110+ switch (rotation) {
2111+ case 1 :
2112+ t = x;
2113+ x = WIDTH - 1 - y;
2114+ y = t;
2115+ break ;
2116+ case 2 :
2117+ x = WIDTH - 1 - x;
2118+ y = HEIGHT - 1 - y;
2119+ break ;
2120+ case 3 :
2121+ t = x;
2122+ x = y;
2123+ y = HEIGHT - 1 - t;
2124+ break ;
2125+ }
2126+ return getRawPixel (x, y);
2127+ }
2128+
2129+ /* *********************************************************************/
2130+ /* !
2131+ @brief Get the pixel color value at a given, unrotated coordinate.
2132+ This method is intended for hardware drivers to get pixel value
2133+ in physical coordinates.
2134+ @param x x coordinate
2135+ @param y y coordinate
2136+ @returns The desired pixel's 16-bit 5-6-5 color value
2137+ */
2138+ /* *********************************************************************/
2139+ uint16_t GFXcanvas16::getRawPixel (int16_t x, int16_t y) const {
2140+ if ((x < 0 ) || (y < 0 ) || (x >= WIDTH) || (y >= HEIGHT)) return 0 ;
2141+ if (buffer) {
2142+ return buffer[x + y * WIDTH];
2143+ }
2144+ return 0 ;
2145+ }
2146+
2147+
19982148/* *************************************************************************/
19992149/* !
20002150 @brief Fill the framebuffer completely with one color
0 commit comments