LPC1343 Graphics Sub-System: Bitmap Images (bmp.c)
Loading and saving of bitmap images in the LPC1343 Code Base
The following functions can be used to work with bitmap images. CFG_SDCARD must be enabled in projectconfig.h for this function to work.
bmp_error_t bmpDrawBitmap(uint16_t x, uint16_t y, const char* filename)
Renders a bitmap image on the screen starting at the specified X,Y location
#include "drivers/displays/tft/bmp.h"
// Draw image.bmp (from the root folder) starting at pixel 0,0
bmp_error_t error = bmpDrawBitmap(0, 0, "/image.bmp");
if (error)
{
switch (error)
{
case BMP_ERROR_SDINITFAIL:
break;
case BMP_ERROR_FILENOTFOUND:
break;
case BMP_ERROR_NOTABITMAP:
// First two bytes of image not 'BM'
break;
case BMP_ERROR_INVALIDBITDEPTH:
// Image is not 24-bits
break;
case BMP_ERROR_COMPRESSEDDATA:
// Image contains compressed data
break;
case BMP_ERROR_INVALIDDIMENSIONS:
// Width or Height is > LCD size
break;
case BMP_ERROR_PREMATUREEOF:
// EOF unexpectedly reached in pixel data
break;
}
}
If CFG_SDCARD_READONLY is set to '0' in projectconfig.h (to also enable writing to SD cards), you can also save screenshots of the LCD to a bitmap image on the SD card. The image writing process is quite slow because reading pixel data from the LCD is a very expensive process (saving a bitmap tales several seconds on larger displays), but this can be a useful feature to send UI mockups to people and for documentation purposes.
Warning: Make sure to keep the filename fo 8.3 if you are only using short filenames with the FAT32 stack!
bmp_error_t bmpSaveScreenshot(const char* filename)
Saves the LCD screen contents to a bitmap image
#include "drivers/displays/tft/bmp.h"
bmp_error_t error;
// Turn the LED on to signal busy state (since this takes a while)
gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON);
// Write the screen contents to a bitmap image
error = bmpSaveScreenshot("test.bmp");
// ToDo: Check error state
// Turn the LED off to indicate that the capture is complete
gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF);