Loading bitmaps from SD card

Libraries, utilities, bootloaders...

Loading bitmaps from SD card

Postby albertinjo » Tue Jun 17, 2014 7:16 pm

Has anyone thought of adding a function to library that loads bitmaps from an SD card?
User avatar
albertinjo
 
Posts: 98
Joined: Wed Mar 26, 2014 2:26 pm

Re: Loading bitmaps from SD card

Postby jonnection » 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
User avatar
jonnection
 
Posts: 317
Joined: Sun May 04, 2014 8:21 pm

Re: Loading bitmaps from SD card

Postby adekto » 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
User avatar
adekto
 
Posts: 448
Joined: Tue Feb 25, 2014 9:47 pm
Location: belgium

Re: Loading bitmaps from SD card

Postby ripper121 » 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
User avatar
ripper121
 
Posts: 224
Joined: Fri Apr 04, 2014 2:02 pm
Location: Germany

Re: Loading bitmaps from SD card

Postby adekto » Wed Jun 18, 2014 11:47 am

ok, how would i make one of those?
User avatar
adekto
 
Posts: 448
Joined: Tue Feb 25, 2014 9:47 pm
Location: belgium


Re: Loading bitmaps from SD card

Postby jonnection » 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.
User avatar
jonnection
 
Posts: 317
Joined: Sun May 04, 2014 8:21 pm

Re: Loading bitmaps from SD card

Postby jonnection » 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.

User avatar
jonnection
 
Posts: 317
Joined: Sun May 04, 2014 8:21 pm

Re: Loading bitmaps from SD card

Postby rodot » Sun Jun 22, 2014 9:57 am

Take a look at this :)
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Loading bitmaps from SD card

Postby mougino » 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: Select all
    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: Select all
void drawBitmap(int8_t x, int8_t y, char *bitmap);


Display.cpp addition:
Code: Select all
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
User avatar
mougino
 
Posts: 75
Joined: Sat Jul 25, 2015 8:15 am
Location: Paris, France

Next

Return to Software Development

Who is online

Users browsing this forum: No registered users and 2 guests

cron