Forráskód Böngészése

Merge pull request #39 from marcmerlin/drawrgb

Added support for multicolor pixmaps in drawRGBBitmap.
Paint Your Dragon 8 éve
szülő
commit
4b1a8a6850
2 módosított fájl, 23 hozzáadás és 0 törlés
  1. 21 0
      Adafruit_GFX.cpp
  2. 2 0
      Adafruit_GFX.h

+ 21 - 0
Adafruit_GFX.cpp

@@ -649,6 +649,27 @@ void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c,
     } // End classic vs custom font
 }
 
+// Draw colored bitmap (each pixel is a uint16_t, with colors defined by
+// Draw colored bitmap (each pixel is a uint16_t, with colors defined by
+// the drawpixel method of your graphical backend.
+// progmem defaults to true for bitmaps defined as static const uint16_t PROGMEM
+// but you can set it to false to send a bitmap array in RAM.
+void Adafruit_GFX::drawRGBBitmap(int16_t x, int16_t y,
+		const uint16_t *bitmap, int16_t w, int16_t h, bool progmem) {
+  int16_t i, j;
+
+  for(j=0; j<h; j++) {
+    for(i=0; i<w; i++ ) {
+	if (progmem) {
+	  drawPixel(x+i, y+j, pgm_read_word(bitmap + j * w + i));
+	} else {
+	  drawPixel(x+i, y+j, (uint16_t) *(bitmap + j * w + i));
+	}
+    }
+  }
+}
+
+
 #if ARDUINO >= 100
 size_t Adafruit_GFX::write(uint8_t c) {
 #else

+ 2 - 0
Adafruit_GFX.h

@@ -74,6 +74,8 @@ class Adafruit_GFX : public Print {
       int16_t w, int16_t h, uint16_t color, uint16_t bg),
     drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
       int16_t w, int16_t h, uint16_t color),
+    drawRGBBitmap(int16_t x, int16_t y, const uint16_t *bitmap,
+      int16_t w, int16_t h,bool progmem=true),
     drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
       uint16_t bg, uint8_t size),
     setCursor(int16_t x, int16_t y),