@@ -1734,6 +1734,14 @@ bool Adafruit_GFX_Button::justReleased() { return (!currstate && laststate); }
17341734// scanline pad).
17351735// NOT EXTENSIVELY TESTED YET. MAY CONTAIN WORST BUGS KNOWN TO HUMANKIND.
17361736
1737+ #ifdef __AVR__
1738+ // Bitmask tables of 0x80>>X and ~(0x80>>X), because X>>Y is slow on AVR
1739+ const uint8_t PROGMEM GFXcanvas1::GFXsetBit[] = {0x80 , 0x40 , 0x20 , 0x10 ,
1740+ 0x08 , 0x04 , 0x02 , 0x01 };
1741+ const uint8_t PROGMEM GFXcanvas1::GFXclrBit[] = {0x7F , 0xBF , 0xDF , 0xEF ,
1742+ 0xF7 , 0xFB , 0xFD , 0xFE };
1743+ #endif
1744+
17371745/* *************************************************************************/
17381746/* !
17391747 @brief Instatiate a GFX 1-bit canvas context for graphics
@@ -1763,18 +1771,10 @@ GFXcanvas1::~GFXcanvas1(void) {
17631771 @brief Draw a pixel to the canvas framebuffer
17641772 @param x x coordinate
17651773 @param y y coordinate
1766- @param color 16-bit 5-6-5 Color to fill with
1774+ @param color Binary (on or off) color to fill with
17671775*/
17681776/* *************************************************************************/
17691777void GFXcanvas1::drawPixel (int16_t x, int16_t y, uint16_t color) {
1770- #ifdef __AVR__
1771- // Bitmask tables of 0x80>>X and ~(0x80>>X), because X>>Y is slow on AVR
1772- static const uint8_t PROGMEM GFXsetBit[] = {0x80 , 0x40 , 0x20 , 0x10 ,
1773- 0x08 , 0x04 , 0x02 , 0x01 },
1774- GFXclrBit[] = {0x7F , 0xBF , 0xDF , 0xEF ,
1775- 0xF7 , 0xFB , 0xFD , 0xFE };
1776- #endif
1777-
17781778 if (buffer) {
17791779 if ((x < 0 ) || (y < 0 ) || (x >= _width) || (y >= _height))
17801780 return ;
@@ -1812,10 +1812,67 @@ void GFXcanvas1::drawPixel(int16_t x, int16_t y, uint16_t color) {
18121812 }
18131813}
18141814
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
1821+ (off)
1822+ */
1823+ /* *********************************************************************/
1824+ bool GFXcanvas1::getPixel (int16_t x, int16_t y) const {
1825+ int16_t t;
1826+ switch (rotation) {
1827+ case 1 :
1828+ t = x;
1829+ x = WIDTH - 1 - y;
1830+ y = t;
1831+ break ;
1832+ case 2 :
1833+ x = WIDTH - 1 - x;
1834+ y = HEIGHT - 1 - y;
1835+ break ;
1836+ case 3 :
1837+ t = x;
1838+ x = y;
1839+ y = HEIGHT - 1 - t;
1840+ break ;
1841+ }
1842+ return getRawPixel (x, y);
1843+ }
1844+
1845+ /* *********************************************************************/
1846+ /* !
1847+ @brief Get the pixel color value at a given, unrotated coordinate.
1848+ This method is intended for hardware drivers to get pixel value
1849+ in physical coordinates.
1850+ @param x x coordinate
1851+ @param y y coordinate
1852+ @returns The desired pixel's binary color value, either 0x1 (on) or 0x0
1853+ (off)
1854+ */
1855+ /* *********************************************************************/
1856+ bool GFXcanvas1::getRawPixel (int16_t x, int16_t y) const {
1857+ if ((x < 0 ) || (y < 0 ) || (x >= WIDTH) || (y >= HEIGHT))
1858+ return 0 ;
1859+ if (this ->getBuffer ()) {
1860+ uint8_t *buffer = this ->getBuffer ();
1861+ uint8_t *ptr = &buffer[(x / 8 ) + y * ((WIDTH + 7 ) / 8 )];
1862+
1863+ #ifdef __AVR__
1864+ return ((*ptr) & pgm_read_byte (&GFXsetBit[x & 7 ])) != 0 ;
1865+ #else
1866+ return ((*ptr) & (0x80 >> (x & 7 ))) != 0 ;
1867+ #endif
1868+ }
1869+ return 0 ;
1870+ }
1871+
18151872/* *************************************************************************/
18161873/* !
18171874 @brief Fill the framebuffer completely with one color
1818- @param color 16-bit 5-6-5 Color to fill with
1875+ @param color Binary (on or off) color to fill with
18191876*/
18201877/* *************************************************************************/
18211878void GFXcanvas1::fillScreen (uint16_t color) {
@@ -1854,7 +1911,7 @@ GFXcanvas8::~GFXcanvas8(void) {
18541911 @brief Draw a pixel to the canvas framebuffer
18551912 @param x x coordinate
18561913 @param y y coordinate
1857- @param color 16 -bit 5-6-5 Color to fill with
1914+ @param color 8 -bit Color to fill with. Only lower byte of uint16_t is used.
18581915*/
18591916/* *************************************************************************/
18601917void 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) {
18841941 }
18851942}
18861943
1944+ /* *********************************************************************/
1945+ /* !
1946+ @brief Get the pixel color value at a given coordinate
1947+ @param x x coordinate
1948+ @param y y coordinate
1949+ @returns The desired pixel's 8-bit color value
1950+ */
1951+ /* *********************************************************************/
1952+ uint8_t GFXcanvas8::getPixel (int16_t x, int16_t y) const {
1953+ int16_t t;
1954+ switch (rotation) {
1955+ case 1 :
1956+ t = x;
1957+ x = WIDTH - 1 - y;
1958+ y = t;
1959+ break ;
1960+ case 2 :
1961+ x = WIDTH - 1 - x;
1962+ y = HEIGHT - 1 - y;
1963+ break ;
1964+ case 3 :
1965+ t = x;
1966+ x = y;
1967+ y = HEIGHT - 1 - t;
1968+ break ;
1969+ }
1970+ return getRawPixel (x, y);
1971+ }
1972+
1973+ /* *********************************************************************/
1974+ /* !
1975+ @brief Get the pixel color value at a given, unrotated coordinate.
1976+ This method is intended for hardware drivers to get pixel value
1977+ in physical coordinates.
1978+ @param x x coordinate
1979+ @param y y coordinate
1980+ @returns The desired pixel's 8-bit color value
1981+ */
1982+ /* *********************************************************************/
1983+ uint8_t GFXcanvas8::getRawPixel (int16_t x, int16_t y) const {
1984+ if ((x < 0 ) || (y < 0 ) || (x >= WIDTH) || (y >= HEIGHT))
1985+ return 0 ;
1986+ if (buffer) {
1987+ return buffer[x + y * WIDTH];
1988+ }
1989+ return 0 ;
1990+ }
1991+
18871992/* *************************************************************************/
18881993/* !
18891994 @brief Fill the framebuffer completely with one color
1890- @param color 16 -bit 5-6-5 Color to fill with
1995+ @param color 8 -bit Color to fill with. Only lower byte of uint16_t is used.
18911996*/
18921997/* *************************************************************************/
18931998void GFXcanvas8::fillScreen (uint16_t color) {
@@ -1993,6 +2098,54 @@ void GFXcanvas16::drawPixel(int16_t x, int16_t y, uint16_t color) {
19932098 }
19942099}
19952100
2101+ /* *********************************************************************/
2102+ /* !
2103+ @brief Get the pixel color value at a given coordinate
2104+ @param x x coordinate
2105+ @param y y coordinate
2106+ @returns The desired pixel's 16-bit 5-6-5 color value
2107+ */
2108+ /* *********************************************************************/
2109+ uint16_t GFXcanvas16::getPixel (int16_t x, int16_t y) const {
2110+ int16_t t;
2111+ switch (rotation) {
2112+ case 1 :
2113+ t = x;
2114+ x = WIDTH - 1 - y;
2115+ y = t;
2116+ break ;
2117+ case 2 :
2118+ x = WIDTH - 1 - x;
2119+ y = HEIGHT - 1 - y;
2120+ break ;
2121+ case 3 :
2122+ t = x;
2123+ x = y;
2124+ y = HEIGHT - 1 - t;
2125+ break ;
2126+ }
2127+ return getRawPixel (x, y);
2128+ }
2129+
2130+ /* *********************************************************************/
2131+ /* !
2132+ @brief Get the pixel color value at a given, unrotated coordinate.
2133+ This method is intended for hardware drivers to get pixel value
2134+ in physical coordinates.
2135+ @param x x coordinate
2136+ @param y y coordinate
2137+ @returns The desired pixel's 16-bit 5-6-5 color value
2138+ */
2139+ /* *********************************************************************/
2140+ uint16_t GFXcanvas16::getRawPixel (int16_t x, int16_t y) const {
2141+ if ((x < 0 ) || (y < 0 ) || (x >= WIDTH) || (y >= HEIGHT))
2142+ return 0 ;
2143+ if (buffer) {
2144+ return buffer[x + y * WIDTH];
2145+ }
2146+ return 0 ;
2147+ }
2148+
19962149/* *************************************************************************/
19972150/* !
19982151 @brief Fill the framebuffer completely with one color
0 commit comments