Demonstration of the Bitmap rendering - reads BMP and JPG files in many format variants and renders to the screen.

Dependencies:   FlashFileSystem mbed RA8875

Bitmap and JPEG Demo

This demo publishes each graphic file from a list of files to the display. The graphic files can be BMP, JPG, or ICO. On the terminal it displays the filename and the return-code (in case of an error). This demo works as intended on the 480x272 display in either 8 or 16 bit per pixel mode and it should work on larger displays.

Items of interest to change and rebuild/test:

// Not all systems have the LocalFileSystem. Plug in the library and driver for yours.
LocalFileSystem local("local");             // Image source

TestImage_T TestImage[] = {
    { 0, 0, "/local/01601602.bmp"},
    { 0, 0, "/local/48027202.bmp"},
    { 0, 0, "/local/48027204.bmp"},
    { 0, 0, "/local/48027208.bmp"},
    { 0, 0, "/local/48027224.bmp"},
    { 0, 0, "/local/p480272.jpg"},
    { 0, 0, "/local/p480272.bmp"}
};

// deefine your screen size and color depth. 
#define SCREEN_W 480
#define SCREEN_H 272
#define SCREEN_BPP 16

LocalFileSystem may need to be altered to SDFileSystem (for example) and the corresponding paths in the TestImage array.

Also, the Screen size and bit per pixel color depth.

Images

The following image files are saved in different resolution and color depth. The first, and smallest, was simply for developing the monochrome support. Others are 4-bit color, 8-bit color, 24-bit color, and a mislabeled 1-bit color (shown as 02).

/media/uploads/WiredHome/testimages.zip

Committer:
WiredHome
Date:
Mon Mar 04 12:08:42 2019 +0000
Revision:
18:dafd8eb3cebf
Parent:
17:14385f75449d
Child:
19:853f3668db17
Update RA8875 Lib to add GSL1680 support.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 0:9ecf49d75058 1 // ______________ ______________ ______________ _______________
WiredHome 0:9ecf49d75058 2 // /_____ _____/ / ___________/ / ___________/ /_____ ______/
WiredHome 0:9ecf49d75058 3 // / / / / / / / /
WiredHome 0:9ecf49d75058 4 // / / / /___ / /__________ / /
WiredHome 0:9ecf49d75058 5 // / / / ____/ /__________ / / /
WiredHome 0:9ecf49d75058 6 // / / / / / / / /
WiredHome 0:9ecf49d75058 7 // / / / /__________ ___________/ / / /
WiredHome 0:9ecf49d75058 8 // /__/ /_____________/ /_____________/ /__/
WiredHome 0:9ecf49d75058 9 //
WiredHome 0:9ecf49d75058 10
WiredHome 14:694822610507 11 #include "mbed.h" // v122
WiredHome 14:694822610507 12 #include "RA8875.h" // v125
WiredHome 0:9ecf49d75058 13 #include "WebColors.h"
WiredHome 0:9ecf49d75058 14 #include <algorithm>
WiredHome 0:9ecf49d75058 15
WiredHome 16:987892bebe05 16 #include "FlashFileSystem.h"
WiredHome 16:987892bebe05 17 #include "fileimg.h"
WiredHome 15:f33dcd24d8d1 18
WiredHome 15:f33dcd24d8d1 19
WiredHome 16:987892bebe05 20 FlashFileSystem flash("flash"); // static files here for reliability and speed
WiredHome 16:987892bebe05 21
WiredHome 15:f33dcd24d8d1 22 // These two defines can be enabled, or commented out
WiredHome 16:987892bebe05 23 #define BIG_SCREEN
WiredHome 15:f33dcd24d8d1 24 //#define CAP_TOUCH
WiredHome 15:f33dcd24d8d1 25 #define LCD_C 16 // color - bits per pixel
WiredHome 15:f33dcd24d8d1 26
WiredHome 15:f33dcd24d8d1 27 #ifdef CAP_TOUCH
WiredHome 15:f33dcd24d8d1 28 RA8875 lcd(p5, p6, p7, p12, NC, p9,p10,p13, "tft"); // MOSI,MISO,SCK,/ChipSelect,/reset, SDA,SCL,/IRQ, name
WiredHome 15:f33dcd24d8d1 29 #else
WiredHome 15:f33dcd24d8d1 30 RA8875 lcd(p5, p6, p7, p12, NC, "tft"); //MOSI, MISO, SCK, /ChipSelect, /reset, name
WiredHome 15:f33dcd24d8d1 31 LocalFileSystem local("local"); // access to calibration file for resistive touch.
WiredHome 15:f33dcd24d8d1 32 #endif
WiredHome 15:f33dcd24d8d1 33
WiredHome 15:f33dcd24d8d1 34 #ifdef BIG_SCREEN
WiredHome 15:f33dcd24d8d1 35 #define LCD_W 800
WiredHome 15:f33dcd24d8d1 36 #define LCD_H 480
WiredHome 15:f33dcd24d8d1 37 #else
WiredHome 15:f33dcd24d8d1 38 #define LCD_W 480
WiredHome 15:f33dcd24d8d1 39 #define LCD_H 272
WiredHome 15:f33dcd24d8d1 40 #endif
WiredHome 15:f33dcd24d8d1 41
WiredHome 15:f33dcd24d8d1 42
WiredHome 1:84fb3e9adaaf 43
WiredHome 12:93adb3470150 44 //#define DEBUG "Main"
WiredHome 1:84fb3e9adaaf 45 // ...
WiredHome 1:84fb3e9adaaf 46 // INFO("Stuff to show %d", var); // new-line is automatically appended
WiredHome 1:84fb3e9adaaf 47 //
WiredHome 1:84fb3e9adaaf 48 #if (defined(DEBUG) && !defined(TARGET_LPC11U24))
WiredHome 1:84fb3e9adaaf 49 #define INFO(x, ...) std::printf("[INF %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 1:84fb3e9adaaf 50 #define WARN(x, ...) std::printf("[WRN %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 1:84fb3e9adaaf 51 #define ERR(x, ...) std::printf("[ERR %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 1:84fb3e9adaaf 52 static void HexDump(const char * title, const uint8_t * p, int count)
WiredHome 1:84fb3e9adaaf 53 {
WiredHome 1:84fb3e9adaaf 54 int i;
WiredHome 1:84fb3e9adaaf 55 char buf[100] = "0000: ";
WiredHome 1:84fb3e9adaaf 56
WiredHome 1:84fb3e9adaaf 57 if (*title)
WiredHome 1:84fb3e9adaaf 58 INFO("%s", title);
WiredHome 1:84fb3e9adaaf 59 for (i=0; i<count; ) {
WiredHome 1:84fb3e9adaaf 60 sprintf(buf + strlen(buf), "%02X ", *(p+i));
WiredHome 1:84fb3e9adaaf 61 if ((++i & 0x0F) == 0x00) {
WiredHome 1:84fb3e9adaaf 62 INFO("%s", buf);
WiredHome 1:84fb3e9adaaf 63 if (i < count)
WiredHome 1:84fb3e9adaaf 64 sprintf(buf, "%04X: ", i);
WiredHome 1:84fb3e9adaaf 65 else
WiredHome 1:84fb3e9adaaf 66 buf[0] = '\0';
WiredHome 1:84fb3e9adaaf 67 }
WiredHome 1:84fb3e9adaaf 68 }
WiredHome 1:84fb3e9adaaf 69 if (strlen(buf))
WiredHome 1:84fb3e9adaaf 70 INFO("%s", buf);
WiredHome 1:84fb3e9adaaf 71 }
WiredHome 1:84fb3e9adaaf 72 #else
WiredHome 1:84fb3e9adaaf 73 #define INFO(x, ...)
WiredHome 1:84fb3e9adaaf 74 #define WARN(x, ...)
WiredHome 1:84fb3e9adaaf 75 #define ERR(x, ...)
WiredHome 1:84fb3e9adaaf 76 #define HexDump(a, b, c)
WiredHome 1:84fb3e9adaaf 77 #endif
WiredHome 0:9ecf49d75058 78
WiredHome 0:9ecf49d75058 79 Serial pc(USBTX, USBRX);
WiredHome 0:9ecf49d75058 80 extern "C" void mbed_reset();
WiredHome 0:9ecf49d75058 81
WiredHome 0:9ecf49d75058 82
WiredHome 0:9ecf49d75058 83 typedef struct {
WiredHome 0:9ecf49d75058 84 loc_t x;
WiredHome 0:9ecf49d75058 85 loc_t y;
WiredHome 0:9ecf49d75058 86 char * filename;
WiredHome 0:9ecf49d75058 87 } TestImage_T;
WiredHome 0:9ecf49d75058 88
WiredHome 0:9ecf49d75058 89 TestImage_T TestImage[] = {
WiredHome 16:987892bebe05 90 { 0, 0, "/flash/RomeC.jpg"},
WiredHome 16:987892bebe05 91 { 0, 0, "/local/desert.bmp"},
WiredHome 16:987892bebe05 92 { 0, 0, "/local/Module.jpg"},
WiredHome 16:987892bebe05 93 // { 0, 0, "/local/01601602.bmp"},
WiredHome 16:987892bebe05 94 // { 0, 0, "/local/48027202.bmp"},
WiredHome 16:987892bebe05 95 // { 0, 0, "/local/48027204.bmp"},
WiredHome 16:987892bebe05 96 // { 0, 0, "/local/48027208.bmp"},
WiredHome 16:987892bebe05 97 // { 0, 0, "/local/48027224.bmp"},
WiredHome 16:987892bebe05 98 // { 0, 0, "/local/p480272.jpg"},
WiredHome 16:987892bebe05 99 // { 0, 0, "/local/p480272.bmp"},
WiredHome 0:9ecf49d75058 100 };
WiredHome 0:9ecf49d75058 101
WiredHome 0:9ecf49d75058 102
WiredHome 1:84fb3e9adaaf 103
WiredHome 0:9ecf49d75058 104 int main()
WiredHome 0:9ecf49d75058 105 {
WiredHome 0:9ecf49d75058 106 pc.baud(460800); // I like a snappy terminal, so crank it up!
WiredHome 0:9ecf49d75058 107 pc.printf("\r\nRA8875 Bitmap Test - Build " __DATE__ " " __TIME__ "\r\n");
WiredHome 0:9ecf49d75058 108
WiredHome 15:f33dcd24d8d1 109 lcd.init(LCD_W, LCD_H, LCD_C);
WiredHome 2:1e1dd697d12d 110 lcd.Backlight(0.5f);
WiredHome 2:1e1dd697d12d 111
WiredHome 0:9ecf49d75058 112 int count = sizeof(TestImage)/sizeof(TestImage[0]);
WiredHome 14:694822610507 113 while (1) {
WiredHome 14:694822610507 114 for (int i=0; i<count; i++) {
WiredHome 14:694822610507 115 lcd.cls();
WiredHome 14:694822610507 116 printf("RenderBitmapFile(%d, %d, %s) ", TestImage[i].x, TestImage[i].y, TestImage[i].filename);
WiredHome 17:14385f75449d 117 wait(2);
WiredHome 14:694822610507 118 RetCode_t r = lcd.RenderImageFile(TestImage[i].x, TestImage[i].y, TestImage[i].filename);
WiredHome 14:694822610507 119 printf("returned %d\r\n", r);
WiredHome 14:694822610507 120 wait(5);
WiredHome 14:694822610507 121 }
WiredHome 0:9ecf49d75058 122 }
WiredHome 0:9ecf49d75058 123 }