Tag Archives: image

About GLCD Data Compression

Bitmap2LCD is a tool for programming small Graphic LCDs in embedded systems.

 Update V3.9H

A simple data compression feature, for the output of GLCD data arrays is implemented in Bitmap2LCD

This function is only available for monochrome mode and 8 bit output format.

The 8 bit microcontrollers for price sensitive projects are circuits with often less onchip memory space than most of the 16 or 32 bit devices.

The target is to save as many as microcontroller flash memory as possible. As tables for full display patterns of for example a 128 x 64 dot matrix LCD need 1024 bytes each, the goal of this function was to save flash space for more code or graphics or just to reduce the overall flash capacity and therefore to sink the price of the MCU chip.

The microcontroller firmware has to be able to handle these tables with a special code, which decodes the compressed data. Processing time for decompression has to be allowed.

 

How does it work ?

Instead of only converting the black and white pixels found in the work canvas to a linear list of n bytes, with the data compression method explained here, the data array is split into two separate arrays in one single output file : one as usual for the data stream and another for the pointers of each data groups.

Compr1

The basic concept of this compression is based on making groups of consecutive identical data bytes in the data array.

 

Consecutive identical byte chains, and consecutive different byte chains are handled, the goal here is to save data bytes when a consecutive identical byte chain is found. While the first pointer of a consecutive different bytes chain is a loss of one data byte stored as a pointer, a consecutive identical byte chain of 10 bytes is a win of 8 bytes, the data being written only once in the data array. The count of them is then stored in the pointer byte array part.

The maximum count of consecutive data, identical or different is limited to 127 ( pointer bits 6 to 0 ). If a data count in a group reaches 127, a new group is encoded.

compr2

The bit 7 of the pointer byte is the flag for the compression decoder. A 1 (high) is for a chain of identical data bytes, and a 0 (low) is for an chain of different data.

 

When data compression is active, Bitmap2LCD converts all data and shows the compression rate in the compression statistics at the end of the output file.

 

This method of compression shows different results in vertical or horizontal orientation conversion, it depends of the LCD graphic !

If possible, before to choose the LCD controller and its specific data orientation in Display RAM , you could try both orientations and compare the possible compression ratios.

 

In the Header Include file, the example script below shows how to setup the compression table information.

( It is an example for a GNU-C compiler for ATMEL AVR family )

Everything after the tag [&COMPRESSION] is a script information for the data compression function.

The tag [&CNAME] is replaced in the output table name, by the data array name

with an additional suffix _x ( For example : Newfile_x )

The tag [&CSIZE] is not used yet (v2.3)

In the Header Include file :

[&COMPRESSION]
const prog_uint8_t [&CNAME][&CSIZE] = {

 Please also check the online forum for other topics about this function

Compression Decoder Example

The below example of a function in C language, decodes compressed data arrays converted with bitmap2LCD.

It is for an Atmel AVR target MCU with GCC compiler, a T6963C LCD controller ( horizontal byte orientation from left to right )
No buffer RAM.

Note : For LCD module widths greater than 255 dots, x and width variables should be long integers

 

// T6963 function for uncompressed bitmaps
 
void GLCD_Bitmap(unsigned char *bitmap, unsigned char x, unsigned char y, unsigned char width, unsigned char height)
{
unsigned char val;
uint8_t LcdX,LcdY,EndX,EndY;
long ip = 0; // table byte counter
LcdX=x; // LCD dot adress X
LcdY=y; // LCD dot adress Y
EndY=y+height-1;
EndX=x+width;
 
while (LcdY < EndY || LcdX < EndX)
{
GLCD_GraphicGoTo(LcdX, LcdY);
GLCD_WriteDisplayData(pgm_read_byte(bitmap + ip));
ip ++;
LcdX=LcdX+8;
if (( LcdX == EndX ) && ( LcdY<EndY ))
{
LcdY++;
LcdX=x;
}
}
 
}
 
 
// T6963 function for Bitmap2LCD compressed bitmaps
 
void GLCD_xBitmap(unsigned char *bitmap, unsigned char *pointer, unsigned char x, unsigned char y, unsigned char width, unsigned char height)
{
 
unsigned char val;
uint8_t p,pv,nb,LcdX,LcdY,EndX,EndY;
long ip = 0; // table byte counter
p = 0; // pointer
LcdX=x; // LCD dot adress X
LcdY=y; // LCD dot adress Y
EndY=y+height-1; // End pixel in Y
EndX=x+width; // End Pixel in X
 
while (LcdY < EndY || LcdX < EndX)
 
{
pv = (int)(pgm_read_byte(pointer + p)); // read the pointer byte
p++;
 
if (pv > 128) // bit 7 is logical high when identical bytes chain, low when different
{
val = pgm_read_byte(bitmap + ip);
ip++;
nb = pv – 128;
 
while ( nb > 0 ) // substract bit 7 value for number of bytes in chain
{
GLCD_GraphicGoTo(LcdX, LcdY); // bytes in chain are identical
GLCD_WriteDisplayData(val);
LcdX=LcdX+8;
nb–;
if (( LcdX == EndX ) && ( LcdY<EndY ))
{
LcdY++;
LcdX =x;
}
}
}
else // bytes in chain are different
{
while ( pv > 0 )
{
GLCD_GraphicGoTo(LcdX, LcdY);
GLCD_WriteDisplayData(pgm_read_byte(bitmap + ip));
ip ++;
LcdX=LcdX+8;
pv–;
if (( LcdX == EndX ) && ( LcdY<EndY ))
{
LcdY++;
LcdX=x;
}
}
}
}
}
 
 
 
 
 

Bitmap to GLCD Hex file >> Output settings

Bitmap2LCD is a tool for programming small Graphic LCDs in embedded systems.

Go to the Main Settings (v2.5 +):

bitmap2lcd settings

From V2.5, the below settings can also be found on the file explorer window, outputs tab : there’s a button at the top right to hide or show this toolbar.


fig 1. Hex file output settings buttons [ Bitmap2LCD from V2.0 upwards ]

 

Bitmap2LCD is a universal programming tool for converting bitmaps/images to GLCD for most graphic LCD controllers. (Monochrome,Grayscale, and Color ->[Color from V2.0] )

The software converts the bitmap and generates a hexadecimal file according to the previously defined user settings.

Here’s a short description of the available settings :

The hexadecimal output format can be selected with a series of buttons located in the output panel (fig 1.)

Description of the settings:

  • The choice of 8 different vertical or horizontal pagings ( the buttons with the arrows ) , your choice depends of the GLCD controller which is built in your LCD module. ( Please refer to the GLCD controller datasheet )
  • Most significant bit is first or is last (Data bit 7) — or in other words the data endianness.
  • Byte nibble swap On/Off, for example for 16 gray level grayscale mode for Sitronix ST7528 controller compatibility. ( In the case of 2 pixel per data byte, 4 bit per pixel data, gray levels )
  • Negative or positive output setting
  • GLCD zero corner selection (Corner where the conversion starts)
  • Output File Header Editor , (A small script to configure Hex file header)
  • Enable/Disable of the Output Data for compression for monochrome GLCD.
  • Enable/Disable 6 or 8 bit Data byte wide output for T693C Controller

As the converted output can just contain a part of the display size, there are other selectable options (not on fig1.)

  • Enable/disable X,Y area coordinate data insertion in the Hex ouptut file
  • Enable/disable area size data insertion in the Hex output file

These configuration settings are saved when you quit the application and restored on application launch. These settings are also a part of the project specific configuration.

Find other available settings in this topic.

 

 

 

Color GLCD Displays

In color GLCDs, each individual pixel is divided into three cells, or subpixels, which are colored red (R), green (G), and blue (B).

In GLCDs, the most important thing in interfacing color GLCD is to know how color is defined to a given pixel. Available formats depends on the brand and type of GLCD controller built in the choosen module :

12 bit per pixel pixel format (12bpp)
RRRRGGGG  4 bits red and 4 bits green 1st pixel BBBBRRRR   4 bits blue 1st pixel and 4 bits red 2nd  pixel GGGGBBBB  4 bits  green and 4 bits blue 2nd pixel

8 bit per pixel pixel format (8bpp)
RRRGGGBB  3 bits red, 3 bits green and 2 bits blue

16 bit per pixel pixel format (16bpp)
RRRRRGGG  5 bits red and 3 bits green 1st pixel GGGBBBBB  3 bits red and 5 bits blue 1st pixel

The Bitmap2LCD programming tool supports these GLCD color formats from V2.0.