This article describes how to configure applications to run in monochrome mode.
The default behavior of TouchGFX is to represent graphics in 16 bit RGB565 format. It does, however, come with built in support for monochrome, 1 bit per pixel user interfaces. When running in this mode, the frame buffer(s) only take up one sixteenth of the space required for the RGB565 color format. Likewise, all the generated image data also only take up one bit per pixel.
Therefore it is quite likely that 1BPP applications can run on devices with no external memories by having the frame buffer in internal RAM and the image data in internal flash. In order to configure TouchGFX for 1BPP operation, the following needs to be done
See for yourself: Check out the Monochrome Example in the TouchGFX distribution.
1BPP Asset Generation
Both image data and fonts must be generated in a 1BPP format in order to be displayed properly when running in 1BPP mode.
In order to make the image converter output data in 1BPP format, simply modify the
config/gcc/app.mk file in your application to specify BW opaque and non-opaque image formats:
opaque_image_format := BW non_opaque_image_format := BW
And likewise for Visual Studio in the
config/msvs/Application.props file, if using Visual Studio to generate assets.
This will cause the image converter to output image data in 1BPP. The .png/.bmp image files used as input for the converter must still be in regular 24bpp format. The image converter itself will do the downscaling to monochrome. If the bitmap contains colored pixels (not just black or white), the resulting output will be based on the luminance of the pixel.
Monochrome images can alternatively be stored in a horizontal run-length encoded format. This will in many cases substantially reduce the amount of flash memory each image takes up, and is therefore worth investigating if flash memory is scarce. If compression is enabled, the imageconverter will automatically calculate the resulting size for each bitmap and only use the run-length encoded format if the size is smaller than the normal unpacked format. Therefore, run-length encoding has a worst case size equal to that of uncompressed bitmaps. The drawback to using compression is that the rendering speed will decrease somewhat for compressed bitmaps because the format must be decoded by TouchGFX before drawing. You must therefore decide this tradeoff for your specific application based on your requirements. In order to enable bitmap compression, use the image format BW_RLE instead of BW:
opaque_image_format := BW_RLE non_opaque_image_format := BW_RLE
In order to specify the use of 1BPP fonts, simply modify all typographies used in the Texts.xlsx Excel sheet to use 1 bit per pixel.
The BoardConfiguration.cpp for the appropriate target hardware (or simulator/main.cpp for PC simulator) file must be changed to use a 1-bit LCD object instead of the standard 16-bit type:
//LCD16bpp display; //Monochrome 1BPP mode LCD1bpp display;
Finally, on target only, the setFrameBufferStartAddress function must be modified to inform the framework that the frame buffer(s) should use a bit depth of 1:
With the changes above, your application now runs in 1BPP mode. This does not impact the API or features of TouchGFX compared to 16bit mode except in one area: alpha blending is ignored since it does not really make sense in a 1BPP context. There are some instances where colors are expressed in uint16_t (for instance in
Box widgets). In those cases, a value of zero is interpreted as black, where as any other value is interpreted as white.
Warning: The use of DMA to transfer graphics data is not supported in 1BPP mode. You can change your DMA object in BoardConfiguration to be of type NoDMA for clarity, but the DMA object is ignored entirely in 1BPP mode.