Skip to content

Commit 4b1a8a6

Browse files
Merge pull request #39 from marcmerlin/drawrgb
Added support for multicolor pixmaps in drawRGBBitmap.
2 parents cb95e03 + aad430d commit 4b1a8a6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Adafruit_GFX.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,27 @@ void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c,
649649
} // End classic vs custom font
650650
}
651651

652+
// Draw colored bitmap (each pixel is a uint16_t, with colors defined by
653+
// Draw colored bitmap (each pixel is a uint16_t, with colors defined by
654+
// the drawpixel method of your graphical backend.
655+
// progmem defaults to true for bitmaps defined as static const uint16_t PROGMEM
656+
// but you can set it to false to send a bitmap array in RAM.
657+
void Adafruit_GFX::drawRGBBitmap(int16_t x, int16_t y,
658+
const uint16_t *bitmap, int16_t w, int16_t h, bool progmem) {
659+
int16_t i, j;
660+
661+
for(j=0; j<h; j++) {
662+
for(i=0; i<w; i++ ) {
663+
if (progmem) {
664+
drawPixel(x+i, y+j, pgm_read_word(bitmap + j * w + i));
665+
} else {
666+
drawPixel(x+i, y+j, (uint16_t) *(bitmap + j * w + i));
667+
}
668+
}
669+
}
670+
}
671+
672+
652673
#if ARDUINO >= 100
653674
size_t Adafruit_GFX::write(uint8_t c) {
654675
#else

Adafruit_GFX.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class Adafruit_GFX : public Print {
7474
int16_t w, int16_t h, uint16_t color, uint16_t bg),
7575
drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
7676
int16_t w, int16_t h, uint16_t color),
77+
drawRGBBitmap(int16_t x, int16_t y, const uint16_t *bitmap,
78+
int16_t w, int16_t h,bool progmem=true),
7779
drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
7880
uint16_t bg, uint8_t size),
7981
setCursor(int16_t x, int16_t y),

0 commit comments

Comments
 (0)