This section explains the use of dynamic L8 images and especially how to create the palette.
Dynamic L8 bitmaps are created like any other dynamic bitmap, except that we also have to specify the type of palette to create for the bitmap.
TouchGFX supports 3 types of palettes:
|CLUT_FORMAT_L8_ARGB8888||32-bit, 8 bits for each of red, green, blue and per pixel alpha channel|
|CLUT_FORMAT_L8_RGB888||24-bit, 8 bits for each of red, green and blue, no per pixel alpha channel|
|CLUT_FORMAT_L8_RGB565||16-bit, 5 bits for red, 6 bits for green, 5 bits for blue, no per pixel alpha channel|
Here we create a 100x100 pixels L8 bitmap with a 24-bit palette:
This call allocated a 100x100 L8 bitmap and a 24-bit palette in the bitmap cache. The palette always holds 256 colors for dynamic bitmaps.
The palette is located 4 bytes after the pixels (aligned on 32-bit). The bytes contains information about the palette type and length of the palette.
We can get a pointer to the (so far uninitialized) palette like this:
We will now go through an example of creating a dynamic L8 bitmap and manipulating the palette. Manipulating the palette if not a typical thing to do for a general application. The example serves the purpose of illustrating how to access and generate a palette.
First we create a Screen in TouchGFXDesigner and insert a white Box in the background and an Image at e.g. x=140, y=8:
Now generate the code and open the Screen1View.cpp file. We must insert code in setupScreen to initialize the bitmap cache and create a dynamic bitmap.
We create a bitmap of 200*256 pixels. Remember each pixel in an L8 bitmap is one byte. We color each row of the image with a different color. First row has color 0, last row has color 255.
Then we initialize the colors in the palette. We calculate the start address of the palette and set the RGB values of the 256 colors. Here we create colors that go from green to red and back to green again.
This gives us a Screen that looks like this:
Since we have access to the palette used for the dynamic L8 bitmap, we can easily manipulate it.
Here we cycle the colors one index down and force a redraw of the image in every frame:
This will move colors in the dynamic bitmap "upwards":