c++arraysarduinogfxprogmem

Adafruit gfx library drawBitmap without PROGMEM


So im trying to put byte array of image in external eeprom (c24LC16B) and use drawBitmap() function in Adafruit gfx library to draw it on Nokia 3310 LCD (with Adafruit PCD8544 library). But the problem is, that the drawBitmap() can use only static byte PROGMEM array. With is bad, I need to read the img array from eeprom to buffer (byte buf[504]{}; ) and then draw it on display.

i tried some modifications, that i found online, like add this to the Adafruit_GFX.ccp:

void Adafruit_GFX::drawBitmap(int16_t x, int16_t y,
                  uint8_t *bitmap, int16_t w, int16_t h,
                  uint16_t color) {

  int16_t i, j, byteWidth = (w + 7) / 8;

  for(j=0; j<h; j++) {
    for(i=0; i<w; i++ ) {
      if(bitRead(bitmap[j], 7-i))  
        drawPixel(x+i, y+j, color);
    }
  }
}

but it still only displayed rubbish

So why is there such big deal about PROGMEM and normal arrays ? Isnt byte from PROGMEM and from SRAM the same ? Also sorry for my grammar.


Solution

  • i did it ! All i have to do it was to write my own function ! =D

    just add this to the Adafruit_GFX.ccp

    void Adafruit_GFX::drawRamBitmap(int pozXi, int pozYi, int h, int w, byte color, byte bg, byte bitmap[], int mapSize) {
      int pozX = pozXi;
      int pozY = pozYi;
    
      for (int x = 0; x < mapSize; x++) {
        for (byte y = 0; y < 8; y++) {
          byte dummy = bitmap[x] << y;
          if (dummy >= 128) {
            drawPixel(pozX, pozY, color);
          }
          else {
            drawPixel(pozX, pozY, bg);
          }
          pozX++;
          if (pozX == w + pozXi) {
            pozX = pozXi;
            pozY++;
          }
        }
      }
    }
    
    void Adafruit_GFX::drawRamBitmap(int pozXi, int pozYi, int h, int w, byte color, byte bitmap[], int mapSize) {
      int pozX = pozXi;
      int pozY = pozYi;
    
      for (int x = 0; x < mapSize; x++) {
        for (byte y = 0; y < 8; y++) {
          byte dummy = bitmap[x] << y;
          if (dummy >= 128) {
            drawPixel(pozX, pozY, color);
          }
          pozX++;
          if (pozX == w + pozXi) {
            pozX = pozXi;
            pozY++;
          }
        }
      }
    }
    

    and this for Adafruit_GFX.h

    drawRamBitmap(int pozXi, int pozYi, int h, int w, byte color, byte bg, byte bitmap[], int mapSize),
    drawRamBitmap(int pozXi, int pozYi, int h, int w, byte color, byte bitmap[], int mapSize),
    

    usage:

    drawRambitmap(x,y,h,w,color,byte_array_of_img, size_of_array);
    

    or

    drawRambitmap(x,y,h,w,color,background_color,byte_array_of_img, size_of_array);