I’m going to add a command to load bitmaps onto the display. To kind of ease my way back into firmware, I’ve been writing Python and Typescript for a few weeks
Not sure this is the final choice, but I read through this MIT licensed bitmap manipulation code and it should get it started with the basics. I prefer to wrap everything in a nice struct though, let’s boil a bath tub of water and see what Chad comes up with:
BITMAPFILEHEADER
This header contains general information about the BMP file.
BITMAPINFOHEADER
This header contains detailed information about the image, such as its dimensions and color format.
Here’s how you can define these structs:
#include <stdint.h>
// BITMAPFILEHEADER structure
typedef struct {
uint16_t bfType; // Specifies the file type, must be 'BM'
uint32_t bfSize; // Specifies the size of the file in bytes
uint16_t bfReserved1; // Reserved, must be 0
uint16_t bfReserved2; // Reserved, must be 0
uint32_t bfOffBits; // Specifies the offset from the beginning of the file to the bitmap data
} BITMAPFILEHEADER;
// BITMAPINFOHEADER structure
typedef struct {
uint32_t biSize; // Specifies the number of bytes required by the structure
int32_t biWidth; // Specifies the width of the image, in pixels
int32_t biHeight; // Specifies the height of the image, in pixels
uint16_t biPlanes; // Specifies the number of color planes, must be 1
uint16_t biBitCount; // Specifies the number of bits per pixel
uint32_t biCompression; // Specifies the type of compression
uint32_t biSizeImage; // Specifies the size of the image data, in bytes
int32_t biXPelsPerMeter; // Specifies the horizontal resolution, in pixels per meter
int32_t biYPelsPerMeter; // Specifies the vertical resolution, in pixels per meter
uint32_t biClrUsed; // Specifies the number of colors used in the bitmap
uint32_t biClrImportant; // Specifies the number of important colors
} BITMAPINFOHEADER;
BITMAPFILEHEADER
: This struct represents the file header of a BMP file.
bfType
: Should be ‘BM’ (0x4D42) for bitmap files.
bfSize
: Size of the file in bytes.
bfReserved1
and bfReserved2
: Reserved fields, must be 0.
bfOffBits
: Offset from the beginning of the file to the bitmap data.
BITMAPINFOHEADER
: This struct represents the information header of a BMP file.
biSize
: Size of this header (40 bytes for BITMAPINFOHEADER).
biWidth
and biHeight
: Width and height of the image in pixels.
biPlanes
: Number of color planes, must be 1.
biBitCount
: Number of bits per pixel (e.g., 24 for 24-bit RGB).
biCompression
: Type of compression (0 for no compression).
biSizeImage
: Size of the image data in bytes.
biXPelsPerMeter
and biYPelsPerMeter
: Horizontal and vertical resolution in pixels per meter.
biClrUsed
: Number of colors used in the bitmap.
biClrImportant
: Number of important colors.
Example:
BITMAPFILEHEADER fileHeader;
BITMAPINFOHEADER infoHeader;
fread(&fileHeader, sizeof(BITMAPFILEHEADER), 1, file);
fread(&infoHeader, sizeof(BITMAPINFOHEADER), 1, file);
printf("File size: %u bytes\n", fileHeader.bfSize);
printf("Image width: %d pixels\n", infoHeader.biWidth);
printf("Image height: %d pixels\n", infoHeader.biHeight);
That’s how I like to do it.