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

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Tue May 17 10:45:59 2016 +0000
Parent:
9:092f7ac73c03
Commit message:
working - adding instrumentation

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
tjpgd.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon May 16 22:06:18 2016 +0000
+++ b/main.cpp	Tue May 17 10:45:59 2016 +0000
@@ -90,12 +90,12 @@
     //INFO("Read in %p count %d", buff, ndata);
     if (buff) {
         size_t n = fread(buff, 1, ndata, fh);
-        //INFO("fread returned %d", n);
-        //HexDump("buf", buff, (ndata > 32) ? 32 : ndata);
+        INFO("fread returned %d of %d", n, ndata);
+        HexDump("buf", buff, (ndata > 32) ? 32 : ndata);
         return n == (size_t)-1 ? 0 : n;
     } else {
         off_t t = fseek(fh, ndata, SEEK_CUR);
-        //INFO("Seek returned %d", t);
+        INFO("Seek returned %d", t);
         return t == (off_t)-1 ? 0 : ndata;
     }
 }
--- a/tjpgd.cpp	Mon May 16 22:06:18 2016 +0000
+++ b/tjpgd.cpp	Tue May 17 10:45:59 2016 +0000
@@ -258,12 +258,14 @@
 
         ph = (uint16_t *)alloc_pool(jd, np * sizeof (uint16_t));/* Allocate a memory block for the code word table */
         if (!ph) return JDR_MEM1;           /* Err: not enough memory */
+        
         jd->huffcode[num][cls] = ph;
         hc = 0;
         for (j = i = 0; i < 16; i++) {      /* Re-build huffman code word table */
             b = pb[i];
             while (b--) ph[j++] = hc++;
             hc <<= 1;
+            INFO("jd->pool: %d: %p, %p", i, jd->pool, ph);
         }
 
         if (ndata < np) return JDR_FMT1;    /* Err: wrong data size */
@@ -817,7 +819,7 @@
     JRESULT rc;
 
     INFO("jd_prepare(%p,%p,%p,%d,%p)", jd, infunc, pool, sz_pool, dev);
-    HexDump("JDEC", (uint8_t *)jd, sizeof(JDEC));
+    HexDump("JDEC 1", (uint8_t *)jd, sizeof(JDEC));
 
     if (!pool) return JDR_PAR;
 
@@ -835,10 +837,12 @@
         }
     }
     for (i = 0; i < 4; i++) jd->qttbl[i] = 0;
+    HexDump("JDEC 2", (uint8_t *)jd, sizeof(JDEC));
 
     jd->inbuf = seg = (uint8_t *)alloc_pool(jd, JD_SZBUF);     /* Allocate stream input buffer */
     if (!seg) return JDR_MEM1;
 
+    HexDump("JDEC 3", (uint8_t *)jd, sizeof(JDEC));
     if (jd->infunc(jd, seg, 2) != 2) {
         HexDump("SOI marker", seg, 2);
         return JDR_INP;/* Check SOI marker */
@@ -851,12 +855,15 @@
     for (;;) {
         /* Get a JPEG marker */
         if (jd->infunc(jd, seg, 4) != 4) {
-            INFO("JPEG marker");
+            ERR("JDR_INP");
             return JDR_INP;
         }
         marker = LDB_WORD(seg);     /* Marker */
         len = LDB_WORD(seg + 2);    /* Length field */
-        if (len <= 2 || (marker >> 8) != 0xFF) return JDR_FMT1;
+        if (len <= 2 || (marker >> 8) != 0xFF) {
+            ERR("JDR_FMT1");
+            return JDR_FMT1;
+        }
         len -= 2;       /* Content size excluding length field */
         ofs += 4 + len; /* Number of bytes loaded */
 
@@ -865,7 +872,7 @@
             /* Load segment data */
             if (len > JD_SZBUF) return JDR_MEM2;
             if (jd->infunc(jd, seg, len) != len) {
-                INFO("SOF0");
+                ERR("JDR_INP");
                 return JDR_INP;
             }
 
@@ -873,6 +880,8 @@
             jd->height = LDB_WORD(seg+1);       /* Image height in unit of pixel */
             if (seg[5] != 3) return JDR_FMT3;   /* Err: Supports only Y/Cb/Cr format */
 
+            INFO("Image size(%d,%d)", jd->width, jd->height);
+            
             /* Check three image components */
             for (i = 0; i < 3; i++) {   
                 b = seg[7 + 3 * i];                         /* Get sampling factor */
@@ -893,7 +902,7 @@
             /* Load segment data */
             if (len > JD_SZBUF) return JDR_MEM2;
             if (jd->infunc(jd, seg, len) != len) {
-                INFO("DRI");
+                ERR("JDR_INP");
                 return JDR_INP;
             }
 
@@ -905,11 +914,12 @@
             /* Load segment data */
             if (len > JD_SZBUF) return JDR_MEM2;
             if (jd->infunc(jd, seg, len) != len) {
-                INFO("DHT");
+                ERR("JDR_INP");
                 return JDR_INP;
             }
 
             /* Create huffman tables */
+            INFO("next - create_huffman_tbl()");
             rc = (JRESULT)create_huffman_tbl(jd, seg, len);
             if (rc) return rc;
             break;
@@ -918,7 +928,7 @@
             /* Load segment data */
             if (len > JD_SZBUF) return JDR_MEM2;
             if (jd->infunc(jd, seg, len) != len) {
-                INFO("DQT");
+                ERR("JDR_INP");
                 return JDR_INP;
             }
 
@@ -931,7 +941,7 @@
             /* Load segment data */
             if (len > JD_SZBUF) return JDR_MEM2;
             if (jd->infunc(jd, seg, len) != len) {
-                INFO("SOS");
+                ERR("JDR_INP");
                 return JDR_INP;
             }