LCD Graphics Cont'd, C structs and include files 10:10 C structs (slides) Example: msp432-graphics4 demonstrates the use of circle 10:25 LCD Graphics Recap: - LCD Graphics, 128*128 pels, 64K colors, SPI interface - Driven through MSP graphics library - "context" = foreground, background color + font + clipregion + (..) - Displaying shapes (circles, lines) - Displaying fonts (text) - A Minimal Program for Graphics main.c Low level graphics driver (LcdDriver) - Crystalfontz128x128_ST7735.c // MSP GRLIb interface - HAL_MSPEXP432P401R_Crystalfontz128x128_ST7735.c // SPI driver fontcmtt16.c // and any other fonts you need ========================================================================== 10:30 Bitmap Images In a bitmap image, you specify the area of the display by means of a bitmap. This can be a photo, or a complex graphics design. A bitmap is described as follows: - a width (of X pixels) - a height (of Y pixels) - a pixel encoding - a palette, which maps pixel codes to 24-bit colors The MSP GRLIB supports several different types of pixel encoding 1 bit per pixel = 2 colors 2 bit per pixel = 4 colors 4 bit per pixel = 16 colors 8 bit per pixel = 256 colors The palette is a table that describes how to map pixel codes to colors. bpp palette size ------------------------ 1 bpp 8 bytes = 2 integers 2 bpp 16 bytes 4 bpp 64 bytes 8 bpp 1024 bytes To display a picture, the graphics library needs to translate every pixel code to a color. At 8bpp, this is a standard memory lookup. However, at less than 8bpp, this requires bit masking and bit manipulation. Hence, 8bpp per pixel are faster to display. bpp display speed ------------------------- 8bpp fastest 4bpp slower 1bpp slowest The most important reason for storing images at low bpp value is storage space. At fewer bpp, more pixels can be stored in a confined memory area. Example. Assume a 128*128 pixel image. At 1bpp, the storage requirements are how much? 128 * 128 bits / 8 bits / bytes = 2Kbyte pixel data + 8 bytes palette A 4bpp, the storage requirements are how much? 128 * 128 * 4 bits / 8 bits / bytes = 8Kbyte pixel data + 64 bytes palette To save more space, bitmaps can be stored in compressed format. The graphics library for MSP uses two different compression formats: RLE8 and RLE4 RLE stands for 'run length encoding'. It means that the following string of pixel codes: 05 05 05 05 05 05 05 06 07 can also be represented as follows: 07 05 01 06 01 07 namely: 7 '05', followed by 1 '06', followed by 1 '07'. The net effect is that less space is needed (especially for figures with large areas of homogeneous color), while the display of images will now take even longer. Thus, for the same X x Y size image, both the storage space and the display speed can be traded against each other: Most compact to store, and slowest to decode and display: 1bpp, RLE8 or RLE4 compression Least compact to store, and fastest to decode and display: 8bpp, uncompressed 10:35 Creating Bitmap Images To create the bitmap data structure from an image, TI provides a tool called imagereformer. The tool is part of the TI graphics library http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/Graphics_Library/latest/index_FDS.html The tool reads in a graphics format (eg PNG) and produces a C file which contains - pixel data - palette (at a chosen bits-per-pixel format) - image data structure The resulting C file can be directly imported into the program. Caveat: 1/ At the top of the program, replace #include "grlib.h" with #include 2/ At the bottom of the program, replace const tImage ... with const Graphics_Image ... * Demonstration msp432-graphics-3 1/ Convert max.png in image reformer to max.c 2/ Compile max.c together with rest of program ========================================================================== 10:45 Include files (slides) 10:59 Conclusions