Generate header file from image¶
The procedure to generate header file from image relies on two external utilities: GraphicsMagick and binary-to-header converter.
It is available on the Evaluation and Commercial editions.
Configure¶
The GraphicsMagick website provides the source code and the installation procedure.
The Binary-to-header GitHub repository provides the source code and the installation procedure.
Use¶
Initial image¶
Multiple options are possible for the initial image.
-
The initial image could be generated with PDLS, displayed on the screen and then saved as a BMP file on SD-card.
-
The initial image could be generated directly on the main computer with a paint utility.
As only requirement, the initial image should have the exact dimensions of the targeted screen, 264x176 in this example.
Image converter¶
$ |
|
gm
stands for GraphicsMagick and converts the BMP image into a pixmap.
The parameters are
-
-resize 264x176
sets the size of the image, here for the 2.71” panel; -
-rotate 90
turns the image to the orientation of the screen; -
The format of the input and output images are mentioned
- as a prefix
BMP:
orPBM:
; or - as a suffix
.BMP
or.PBM
; or - both.
- as a prefix
Binary-to-header utility¶
$ |
|
bin2header
converts the pixmap image into a header file.
The resulting file IMAGE1.PBM.h
contains the pixmap table.
#ifndef IMAGE1_PBM_H
#define IMAGE1_PBM_H
static const unsigned char IMAGE1_PBM[] =
{
0x50, 0x34, 0x0a,
0x31, 0x37, 0x36, 0x20, 0x32, 0x36, 0x34, 0x0a,
0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// ...
}
#endif // IMAGE1_PBM_H
The array starts with P4.264 176.
:
-
P4
is the identifier for pixmap; -
264
horizontal size in pixels; -
176
vertical size in pixels; -
separator
.
for0x0A
.
Then come the 274 x 176 = 46464 pixels grouped 8 pixels per byte, or 5808 bytes.
Rename IMAGE1.PBM.h
to IMAGE1.h
.
Edit the IMAGE1.h
file and add at the beginning
// SDK
#include "hV_HAL_Peripherals.h"
#include "hV_Image.h"
Replace
static const unsigned char IMAGE1_PBM[] =
by
static const uint8_t IMAGE1_PBM[] =
Main project¶
#include "hV_Serial_P4.h"
#include "IMAGE1.h"
Serial_P4 myFile(&myScreen);
myFile.readScreen(IMAGE1_PBM);
myScreen.flushFast();
Refer to the Display section of Pixmap on serial console page.