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

Revision:
16:987892bebe05
Parent:
15:f33dcd24d8d1
Child:
17:14385f75449d
--- a/main.cpp	Sat Aug 06 14:50:25 2016 +0000
+++ b/main.cpp	Tue Jul 17 23:23:00 2018 +0000
@@ -13,11 +13,14 @@
 #include "WebColors.h"
 #include <algorithm>
 
-//#define JPEG_TEST
+#include "FlashFileSystem.h"
+#include "fileimg.h"
 
 
+FlashFileSystem flash("flash");             // static files here for reliability and speed
+
 // These two defines can be enabled, or commented out
-//#define BIG_SCREEN
+#define BIG_SCREEN
 //#define CAP_TOUCH
 #define LCD_C 16         // color - bits per pixel
 
@@ -84,82 +87,19 @@
 } TestImage_T;
 
 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"}
+    { 0, 0, "/flash/RomeC.jpg"},
+    { 0, 0, "/local/desert.bmp"},
+    { 0, 0, "/local/Module.jpg"},
+//    { 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"},
 };
 
 
-#ifdef JPEG_TEST
-//#include "tjpgd.h"
-//JDEC jdec;
-//#define JPEG_WORK_SPACE_SIZE 3100
-//uint16_t work[JPEG_WORK_SPACE_SIZE/sizeof(uint16_t)];
-//FILE *fh;
-
-uint16_t jpeg_input_func(JDEC *jd, uint8_t *buff, uint16_t ndata)
-{
-    //INFO("Read in %p count %d", buff, ndata);
-    if (buff) {
-        size_t n = fread(buff, 1, ndata, (FILE *)jd->device);
-        //INFO("fread returned %d", n);
-        //HexDump("buf", buff, (ndata > 32) ? 32 : ndata);
-        return n == (size_t)-1 ? 0 : n;
-    } else {
-        off_t t = fseek((FILE *)jd->device, ndata, SEEK_CUR);
-        //INFO("Seek returned %d", t);
-        return t == (off_t)-1 ? 0 : ndata;
-    }
-}
-
-uint16_t jpeg_output_func(JDEC *jd, void *bitmap, JRECT *rect)
-{
-    #if JD_FORMAT == 1
-    uint16_t *src = (uint16_t *)bitmap;
-    #else
-    uint8_t *src = (uint8_t *)bitmap;
-    #endif
-    int x0 = rect->left;
-    int x1 = rect->right;
-    int y0 = rect->top;
-    int y1 = rect->bottom;
- 
-    if (y0 >= lcd.height() || x0 >= lcd.width())
-        return 1;
- 
-    if (x1 > lcd.width()-1) x1 = lcd.width() - 1;
-    if (y1 > lcd.height()-1) y1 = lcd.height() - 1;
- 
-    if (x0 == 0)
-        printf("\r %d", y0);
- 
-    int w = x1 - x0 + 1;
-    for (int y= y0; y <= y1; y++) {
-        lcd.SetGraphicsCursor(x0, y);
-        lcd._StartGraphicsStream();
-        #if JD_FORMAT == 1
-        uint16_t *p = src + w * (y - y0);
-        #else
-        uint8_t *p = src + 3 * (w * (y - y0));
-        #endif
-        for (int x=x0; x <= x1; x++) {
-            #if JD_FORMAT == 1
-            lcd._putp(*p++);
-            #else
-            lcd._putp(RGB(*p, *(p+1), *(p+2)));
-            p += 3;
-            #endif
-        }
-        lcd._EndGraphicsStream();
-    }
-    return 1;
-}
-#endif
-
 
 int main()
 {