Skip to content

Jackylwl/Image-To-RGB565

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Image-To-RGB565

A simple command-line tool to convert PNG/JPG images into C headers containing RGB565 pixel arrays for embedded LCDs.

Requirements

  • Python 3
  • Pillow (already installed):
    python3 -m pip install --upgrade pillow

Usage

From any directory, run:

python3 ~/Documents/lcd_rgb565_converter/rgb565_convert.py /path/to/image.png --name MYIMG

This creates MYIMG.h in your current directory, defining:

  • MYIMG_WIDTH, MYIMG_HEIGHT
  • static const uint16_t g_myimg_rgb565[WIDTH*HEIGHT]

Resize (optional)

python3 ~/Documents/lcd_rgb565_converter/rgb565_convert.py /path/to/image.jpg --name LOGO --width 120 --height 120

Custom output path (optional)

python3 ~/Documents/lcd_rgb565_converter/rgb565_convert.py /path/to/image.png --name PIC --out /some/dir/PIC.h

Integrate into your STM32 project

  1. Copy the generated header into your project (e.g., Core/Inc/).
  2. Include the header in your source:
    #include "PIC.h"
  3. 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);

Notes

  • 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.

About

Convert PNG/JPG images to RGB565 C header files for embedded LCD displays (STM32, Arduino, etc.)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages