Switch to full style
Libraries, utilities, bootloaders...
Post a reply

Loading bitmaps from SD card

Tue Jun 17, 2014 7:16 pm

Has anyone thought of adding a function to library that loads bitmaps from an SD card?

Re: Loading bitmaps from SD card

Wed Jun 18, 2014 7:12 am

I've thought about it too, and I'm sure also others.

The Buinomon crew will definitely need this feature to support the huge number of monster graphics they have in mind.
On Arduino forums, there seems to be consensus that 300KB/s 'should' be possible out of an SD card. The problem is the parsing speed, not the actual reading. Let's give a fairly conservative estimate of 50 KB/s, means 6250 bytes/sec = ~12 84x48 1-bit frames per second.

So in any case, should be doable and would be a very useful feature indeed.

EDIT: TYPO: Meant 50 KB/s not 50000 KB per sec

Re: Loading bitmaps from SD card

Wed Jun 18, 2014 10:10 am

interesting any example code we can try out
apart from buinomon project it be awsome for "full motion video" stuff

Re: Loading bitmaps from SD card

Wed Jun 18, 2014 10:49 am

For better performance i think a SRAM Extention module is needed to load all the Sprites to the module, so we can read faster

Re: Loading bitmaps from SD card

Wed Jun 18, 2014 11:47 am

ok, how would i make one of those?

Re: Loading bitmaps from SD card

Wed Jun 18, 2014 12:18 pm

Like this:
http://arduino-related.livejournal.com/1414.html
ore use a eeprom
http://www.emartee.com/product/41949/Ar ... K-AT24C512

SPI Versions 1Kb - 1Mb:
http://www.atmel.com/products/memories/serial/spi.aspx

I2C Versions 1Kb - 1Mb:
http://www.atmel.com/products/memories/serial/i2c.aspx

Re: Loading bitmaps from SD card

Wed Jun 18, 2014 2:03 pm

Wait a moment... we were talking about a simple addition to the Gamebuino library that will work with any Gamebuino.

Now we're talking about serial SRAM.

One is a software modification, the other requires hardware changes to the Gamebuino / a hardware module.

While both are a solution to memory limitations, they are answers to 2 totally different questions.

Re: Loading bitmaps from SD card

Thu Jun 19, 2014 1:07 pm

Youtube finally processed my video. It took more than 24 hours ... I do not know whats wrong with YT nowadays.

This is a short clip from a tech demo I did in 2011, 128x64 1bit streaming video on Arduino over serial link.

Sd card streaming video should therefore be very doable on Gamebuino.

The serial link baud rate was 57.6 KB/s or 115.2 KB/s. I can't remember. Frames per second was around 8-10 fps. I remember though that I had to limit the speed due to serial comms errors, so possibly it was as low as 57.6 KB/s.

Re: Loading bitmaps from SD card

Sun Jun 22, 2014 9:57 am

Take a look at this :)

Re: Loading bitmaps from SD card

Sat Sep 26, 2015 7:45 am

This is an old topic, but I found it while looking for a code example to load a bitmap from SD (adekto asked it in the comments but there was no answer).

It happens I just wrote my own routine, to be used with petitFatFs. It is specific to my gamebook engine because the bitmap data is in the middle of a big file on SD (the book itself) and I use 0xff as marker to tell my engine there's a bitmap and not a text paragraph.

I'll write a dedicated sketch for loading a single bitmap file from SD. But the basics are here:
Code:
    Serial.begin(9600); PFFS.begin(10, rx, tx); // initialize petit_fatfs
    pf_open("test.bmp");
    char bmp[13]; // 1 byte for width + 1 byte for height + 11 bytes for 1 line of bitmap data (84/8 rounded-up)
    gb.display.persistence=true; // stop clearing screen at every gb.update()
    gb.display.clear();
    bmp[0]=84; bmp[1]=1; // get bitmap data line by line i.e. bmp dimension is 84x1
    WORD br;
    for(byte y=0; y<48; y++) {
      pf_lseek(y*11);
      pf_read((void*)&bmp[2], 11, &br);
      gb.display.drawBitmap(0, y, bmp); // and draw it!
    }


Note that in any way the bitmap needs to be converted first (Paintuino will soon be able to do that via an export button).

For this to work you'll also need an enhanced drawBitmap function inside "Display.cpp" (and declare it in "Display.h"), to be able to draw a bitmap from a (variable) char array:

Display.h addition:
Code:
void drawBitmap(int8_t x, int8_t y, char *bitmap);


Display.cpp addition:
Code:
void Display::drawBitmap(int8_t x, int8_t y, char *bitmap) {
   byte w = bitmap[0];
   byte h = bitmap[1];
#if (ENABLE_BITMAPS > 0)
    int8_t i, j, byteNum, bitNum, byteWidth = (w + 7) >> 3;
    for (i = 0; i < w; i++) {
        byteNum = i / 8;
        bitNum = i % 8;
        for (j = 0; j < h; j++) {
            if ((bitmap[2 + j * byteWidth + byteNum]) & (B10000000 >> bitNum)) {
                drawPixel(x + i, y + j);
            }
        }
    }
#else
   drawRect(x, y, w, h);
#endif
}


Nicolas
Post a reply