Read bmp from sd card?

I’m working on a 256 color 110x88 screen mode, which seems to be working OK, however I wanted to test it by loading a .bmp from the microsd card.

Is there anything wrong with the following code? I’m calling it simply with ReadBMP(“test.bmp”);
I have test.bmp in the root of the card.

There are a lot of assumptions made about the file being read, namely that it is a 110x88 8bit bitmap, so there is no error checking or anything like that.

unsigned char* ReadBMP(char* filename){
    unsigned char col[4]; // for reading palette
    unsigned short palette[256];
	FILE* testRead = fopen (filename, "rb"); //rb = read
	if(testRead){
		fseek(testRead, 54, SEEK_SET); // find palette
		for(int img_temp=0; img_temp<256; img_temp++){ // assume 8bit
			fread(col, sizeof(char), 4, testRead);
			col[0]>>3; // b
			col[1]>>2; // g
			col[2]>>3; // r
			palette[img_temp] = (col[0] << 11) | (col[1] << 5) | col[1];
		}
        game.display.load565Palette(palette);
        fread(game.display.screenbuffer, 1, 110*88, testRead);
		fclose(testRead);
	}else{
        for(int y=0; y<88; y++){
            for(int x=0; x<110; x++){
                game.display.screenbuffer[x+110*y]=1;
            }
        }
	}
}
2 Likes

thats not gonna work. stdlib fopen can’t be used. I will make modifications to show how it goes

1 Like