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:
Sun May 15 18:57:36 2016 +0000
Revision:
1:84fb3e9adaaf
Working JPEG decoder using c functions external to the graphics library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 1:84fb3e9adaaf 1 /*----------------------------------------------------------------------------/
WiredHome 1:84fb3e9adaaf 2 / TJpgDec - Tiny JPEG Decompressor include file (C)ChaN, 2012
WiredHome 1:84fb3e9adaaf 3 /----------------------------------------------------------------------------*/
WiredHome 1:84fb3e9adaaf 4 #ifndef _TJPGDEC
WiredHome 1:84fb3e9adaaf 5 #define _TJPGDEC
WiredHome 1:84fb3e9adaaf 6 /*---------------------------------------------------------------------------*/
WiredHome 1:84fb3e9adaaf 7 /* System Configurations */
WiredHome 1:84fb3e9adaaf 8
WiredHome 1:84fb3e9adaaf 9 #define JD_SZBUF 512 /* Size of stream input buffer */
WiredHome 1:84fb3e9adaaf 10 #define JD_FORMAT 1 /* Output pixel format 0:RGB888 (3 BYTE/pix), 1:RGB565 (1 WORD/pix) */
WiredHome 1:84fb3e9adaaf 11 #define JD_USE_SCALE 1 /* Use descaling feature for output */
WiredHome 1:84fb3e9adaaf 12 #define JD_TBLCLIP 1 /* Use table for saturation (might be a bit faster but increases 1K bytes of code size) */
WiredHome 1:84fb3e9adaaf 13
WiredHome 1:84fb3e9adaaf 14 /*---------------------------------------------------------------------------*/
WiredHome 1:84fb3e9adaaf 15
WiredHome 1:84fb3e9adaaf 16 #ifdef __cplusplus
WiredHome 1:84fb3e9adaaf 17 extern "C" {
WiredHome 1:84fb3e9adaaf 18 #endif
WiredHome 1:84fb3e9adaaf 19
WiredHome 1:84fb3e9adaaf 20 //#include "integer.h"
WiredHome 1:84fb3e9adaaf 21 #include "DisplayDefs.h"
WiredHome 1:84fb3e9adaaf 22
WiredHome 1:84fb3e9adaaf 23
WiredHome 1:84fb3e9adaaf 24 /* Error code */
WiredHome 1:84fb3e9adaaf 25 typedef enum {
WiredHome 1:84fb3e9adaaf 26 JDR_OK = 0, /* 0: Succeeded */
WiredHome 1:84fb3e9adaaf 27 JDR_INTR, /* 1: Interrupted by output function */
WiredHome 1:84fb3e9adaaf 28 JDR_INP, /* 2: Device error or wrong termination of input stream */
WiredHome 1:84fb3e9adaaf 29 JDR_MEM1, /* 3: Insufficient memory pool for the image */
WiredHome 1:84fb3e9adaaf 30 JDR_MEM2, /* 4: Insufficient stream input buffer */
WiredHome 1:84fb3e9adaaf 31 JDR_PAR, /* 5: Parameter error */
WiredHome 1:84fb3e9adaaf 32 JDR_FMT1, /* 6: Data format error (may be damaged data) */
WiredHome 1:84fb3e9adaaf 33 JDR_FMT2, /* 7: Right format but not supported */
WiredHome 1:84fb3e9adaaf 34 JDR_FMT3 /* 8: Not supported JPEG standard */
WiredHome 1:84fb3e9adaaf 35 } JRESULT;
WiredHome 1:84fb3e9adaaf 36
WiredHome 1:84fb3e9adaaf 37
WiredHome 1:84fb3e9adaaf 38
WiredHome 1:84fb3e9adaaf 39 /* Rectangular structure */
WiredHome 1:84fb3e9adaaf 40 typedef struct {
WiredHome 1:84fb3e9adaaf 41 loc_t left, right, top, bottom;
WiredHome 1:84fb3e9adaaf 42 } JRECT;
WiredHome 1:84fb3e9adaaf 43
WiredHome 1:84fb3e9adaaf 44
WiredHome 1:84fb3e9adaaf 45
WiredHome 1:84fb3e9adaaf 46 /* Decompressor object structure */
WiredHome 1:84fb3e9adaaf 47 typedef struct JDEC JDEC;
WiredHome 1:84fb3e9adaaf 48 struct JDEC {
WiredHome 1:84fb3e9adaaf 49 uint16_t dctr; /* Number of bytes available in the input buffer */
WiredHome 1:84fb3e9adaaf 50 uint8_t * dptr; /* Current data read ptr */
WiredHome 1:84fb3e9adaaf 51 uint8_t * inbuf; /* Bit stream input buffer */
WiredHome 1:84fb3e9adaaf 52 uint8_t dmsk; /* Current bit in the current read byte */
WiredHome 1:84fb3e9adaaf 53 uint8_t scale; /* Output scaling ratio */
WiredHome 1:84fb3e9adaaf 54 uint8_t msx, msy; /* MCU size in unit of block (width, height) */
WiredHome 1:84fb3e9adaaf 55 uint8_t qtid[3]; /* Quantization table ID of each component */
WiredHome 1:84fb3e9adaaf 56 int16_t dcv[3]; /* Previous DC element of each component */
WiredHome 1:84fb3e9adaaf 57 uint16_t nrst; /* Restart inverval */
WiredHome 1:84fb3e9adaaf 58 uint16_t width, height; /* Size of the input image (pixel) */
WiredHome 1:84fb3e9adaaf 59 uint8_t * huffbits[2][2]; /* Huffman bit distribution tables [id][dcac] */
WiredHome 1:84fb3e9adaaf 60 uint16_t * huffcode[2][2]; /* Huffman code word tables [id][dcac] */
WiredHome 1:84fb3e9adaaf 61 uint8_t * huffdata[2][2]; /* Huffman decoded data tables [id][dcac] */
WiredHome 1:84fb3e9adaaf 62 int32_t * qttbl[4]; /* Dequaitizer tables [id] */
WiredHome 1:84fb3e9adaaf 63 void * workbuf; /* Working buffer for IDCT and RGB output */
WiredHome 1:84fb3e9adaaf 64 uint8_t * mcubuf; /* Working buffer for the MCU */
WiredHome 1:84fb3e9adaaf 65 void * pool; /* Pointer to available memory pool */
WiredHome 1:84fb3e9adaaf 66 uint16_t sz_pool; /* Size of momory pool (bytes available) */
WiredHome 1:84fb3e9adaaf 67 uint16_t (*infunc)(JDEC*, uint8_t *, uint16_t);/* Pointer to jpeg stream input function */
WiredHome 1:84fb3e9adaaf 68 void * device; /* Pointer to I/O device identifiler for the session */
WiredHome 1:84fb3e9adaaf 69 };
WiredHome 1:84fb3e9adaaf 70
WiredHome 1:84fb3e9adaaf 71
WiredHome 1:84fb3e9adaaf 72
WiredHome 1:84fb3e9adaaf 73 /* TJpgDec API functions */
WiredHome 1:84fb3e9adaaf 74 JRESULT jd_prepare (JDEC*, uint16_t(*)(JDEC*,uint8_t *,uint16_t), void*, uint16_t, void*);
WiredHome 1:84fb3e9adaaf 75 JRESULT jd_decomp (JDEC*, uint16_t(*)(JDEC*,void*,JRECT*), uint8_t);
WiredHome 1:84fb3e9adaaf 76
WiredHome 1:84fb3e9adaaf 77
WiredHome 1:84fb3e9adaaf 78 #ifdef __cplusplus
WiredHome 1:84fb3e9adaaf 79 }
WiredHome 1:84fb3e9adaaf 80 #endif
WiredHome 1:84fb3e9adaaf 81
WiredHome 1:84fb3e9adaaf 82 #endif /* _TJPGDEC */