Bitmap Parser

A class to read bitmaps from a file and display them on a screen. Bitmaps are loaded through the constructor.

Library availiable at http://mbed.co.uk/projects/cookbook/svn/BitmapFile/trunk

Example code:

#include "mbed.h"
#include "BitmapFile.h"
#include "MobileLCD.h"

LocalFileSystem local("local");
MobileLCD lcd(5, 6, 7, 8, 9);

int main()
{
    BitmapFile MyBitmap("/local/test.bmp");
    lcd.background(0x8f8f8f);
    lcd.cls();
    
    for(int row = 0; row < MyBitmap.getHeight(); row++)
    {
        
        int *colors = MyBitmap.getRow(row,false);
        lcd.blit(0,MyBitmap.getHeight()-row-1,MyBitmap.getWidth(),1,colors);
        delete [] colors;
    }
    MyBitmap.close();
}

Top Tip!!!

When loading bitmaps from the LocalFileSystem it can take quite a long time because accessing files on the MBED isn't a quick process. What is a lot quicker, is to use an SD Card which you can set to 2GHz spi clock frequency and also, when using the MobileLcd set the spi frequency to 25MHz. Using an SD Card has the added bonus that the MBED does not disconnect from the computer when in use. To use the SD Card "Superquick" system, download these files along with this library and here is an example code, which is virtually the same as the one before, but it is just useful to have it here.

#include "mbed.h"
#include "BitmapFile.h"
#include "MobileLCD.h"
#include "SDFileSystem.h"

SDFileSystem sd(5, 6, 7, 8, "sd");
MobileLCD lcd(11, 12, 13, 16, 15);
int main()
{
    BitmapFile MyBitmap("/sd/Bitmap.bmp");
    lcd.background(0x8f8f8f);
    lcd.cls();
    for(int row = 0; row < MyBitmap.getHeight(); row++)
    {
        int *colors = MyBitmap.getRow(row,false);
        lcd.blit(0,MyBitmap.getHeight()-row-1,MyBitmap.getWidth(),1,colors);
        delete [] colors;
    }
    MyBitmap.close();
}

BitmapFileA parser for bitmap files.
BMPHeaderThe BMP header of the bitmap is read into this.
DIBHeaderThe DIB header of the bitmap is read into this.
Functions
BitmapFileCreate the BitmapFile class, and call Initialize
InitializeParses the headers of the bitmap.
openOpens the bitmap for reading, if not already open.
closeCloses the bitmap.
getPixelGets the color of a pixel
getRowGets the colors of a row
class BitmapFile
A parser for bitmap files.
BitmapFile(char *fname)
Create the BitmapFile class, and call Initialize
bool Initialize()
Parses the headers of the bitmap.
void open()
Opens the bitmap for reading, if not already open.
void close()
Closes the bitmap.
int getPixel(int x,  
int y,  
bool closefile =  true)
Gets the color of a pixel
int *getRow(int row,  
bool closefile =  true)
Gets the colors of a row