A simple command-line tool to convert PNG/JPG images into C headers containing RGB565 pixel arrays for embedded LCDs.
- Python 3
- Pillow (already installed):
python3 -m pip install --upgrade pillow
From any directory, run:
python3 ~/Documents/lcd_rgb565_converter/rgb565_convert.py /path/to/image.png --name MYIMGThis creates MYIMG.h in your current directory, defining:
MYIMG_WIDTH,MYIMG_HEIGHTstatic const uint16_t g_myimg_rgb565[WIDTH*HEIGHT]
python3 ~/Documents/lcd_rgb565_converter/rgb565_convert.py /path/to/image.jpg --name LOGO --width 120 --height 120python3 ~/Documents/lcd_rgb565_converter/rgb565_convert.py /path/to/image.png --name PIC --out /some/dir/PIC.h- Copy the generated header into your project (e.g.,
Core/Inc/). - Include the header in your source:
#include "PIC.h"
- Push pixels to the LCD (example using your API):
// Provide a helper that writes an RGB565 buffer to a window static void LCD_DrawRGBImage(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint16_t *px) { if (!px || w == 0 || h == 0) return; if (x >= LCD_DispWindow_COLUMN || y >= LCD_DispWindow_PAGE) return; if (w > (LCD_DispWindow_COLUMN - x)) w = LCD_DispWindow_COLUMN - x; if (h > (LCD_DispWindow_PAGE - y)) h = LCD_DispWindow_PAGE - y; LCD_OpenWindow(x, y, w, h); LCD_Write_Cmd(CMD_SetPixel); for (uint32_t i = 0, n = (uint32_t)w * (uint32_t)h; i < n; i++) { LCD_Write_Data(px[i]); } } // Draw it LCD_DrawRGBImage(0, 0, PIC_WIDTH, PIC_HEIGHT, g_pic_rgb565);
- Flash cost = width × height × 2 bytes.
- Data is generated row-major (top-to-bottom, left-to-right).
- Ensure your LCD expects RGB565 and the draw routine writes raw pixel data.