Skip to content

Commit fb9e169

Browse files
Manual merge of TheNotary's RAM-based bitmap functions.
1 parent e6a8c24 commit fb9e169

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Adafruit_GFX.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,34 @@ void Adafruit_GFX::drawBitmap(int16_t x, int16_t y,
388388
}
389389
}
390390

391+
void Adafruit_GFX::drawBitmap(int16_t x, int16_t y,
392+
uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) {
393+
394+
int16_t i, j, byteWidth = (w + 7) / 8;
395+
396+
for(j=0; j<h; j++) {
397+
for(i=0; i<w; i++ ) {
398+
if(bitRead(bitmap[j], 7-i)) drawPixel(x+i, y+j, color);
399+
}
400+
}
401+
}
402+
403+
// Draw a 1-bit color bitmap at the specified x, y position from the
404+
// provided bitmap buffer (NOT PROGMEM memory nor a const) using color
405+
// as the foreground color and bg as the background color.
406+
void Adafruit_GFX::drawBitmap(int16_t x, int16_t y,
407+
uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg) {
408+
409+
int16_t i, j, byteWidth = (w + 7) / 8;
410+
411+
for(j=0; j<h; j++) {
412+
for(i=0; i<w; i++ ) {
413+
if(bitRead(bitmap[j], 7-i)) drawPixel(x+i, y+j, color);
414+
else drawPixel(x+i, y+j, bg);
415+
}
416+
}
417+
}
418+
391419
//Draw XBitMap Files (*.xbm), exported from GIMP,
392420
//Usage: Export from GIMP to *.xbm, rename *.xbm to *.c and open in editor.
393421
//C Array can be directly used with this function

Adafruit_GFX.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class Adafruit_GFX : public Print {
5656
int16_t w, int16_t h, uint16_t color),
5757
drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
5858
int16_t w, int16_t h, uint16_t color, uint16_t bg),
59+
drawBitmap(int16_t x, int16_t y, uint8_t *bitmap,
60+
int16_t w, int16_t h, uint16_t color),
61+
drawBitmap(int16_t x, int16_t y, uint8_t *bitmap,
62+
int16_t w, int16_t h, uint16_t color, uint16_t bg),
5963
drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
6064
int16_t w, int16_t h, uint16_t color),
6165
drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,

0 commit comments

Comments
 (0)