forked from Bodmer/TFT_eSPI
Add drawXBitmap() function and example
Example is in Generic folder, draw the Espressif logo on the screen.
This commit is contained in:
+50
-2
@@ -1764,8 +1764,8 @@ void TFT_eSPI::fillTriangle ( int32_t x0, int32_t y0, int32_t x1, int32_t y1, in
|
||||
** Function name: drawBitmap
|
||||
** Description: Draw an image stored in an array on the TFT
|
||||
***************************************************************************************/
|
||||
void TFT_eSPI::drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) {
|
||||
|
||||
void TFT_eSPI::drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)
|
||||
{
|
||||
spi_begin();
|
||||
inTransaction = true;
|
||||
|
||||
@@ -1784,6 +1784,54 @@ void TFT_eSPI::drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************
|
||||
** Function name: drawXBitmap
|
||||
** Description: Draw an image stored in an XBM array onto the TFT
|
||||
***************************************************************************************/
|
||||
void TFT_eSPI::drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)
|
||||
{
|
||||
spi_begin();
|
||||
inTransaction = true;
|
||||
|
||||
int32_t i, j, byteWidth = (w + 7) / 8;
|
||||
|
||||
for (j = 0; j < h; j++) {
|
||||
for (i = 0; i < w; i++ ) {
|
||||
if (pgm_read_byte(bitmap + j * byteWidth + i / 8) & (1 << (i & 7))) {
|
||||
drawPixel(x + i, y + j, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inTransaction = false;
|
||||
spi_end();
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************
|
||||
** Function name: drawXBitmap
|
||||
** Description: Draw an XBM image with foreground and background colors
|
||||
***************************************************************************************/
|
||||
void TFT_eSPI::drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bgcolor)
|
||||
{
|
||||
spi_begin();
|
||||
inTransaction = true;
|
||||
|
||||
int32_t i, j, byteWidth = (w + 7) / 8;
|
||||
|
||||
for (j = 0; j < h; j++) {
|
||||
for (i = 0; i < w; i++ ) {
|
||||
if (pgm_read_byte(bitmap + j * byteWidth + i / 8) & (1 << (i & 7)))
|
||||
drawPixel(x + i, y + j, color);
|
||||
else drawPixel(x + i, y + j, bgcolor);
|
||||
}
|
||||
}
|
||||
|
||||
inTransaction = false;
|
||||
spi_end();
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************
|
||||
** Function name: setCursor
|
||||
** Description: Set the text cursor x,y position
|
||||
|
||||
Reference in New Issue
Block a user