From ad2c40ed3931cf1c54d7f74ea6d08759cc8777b1 Mon Sep 17 00:00:00 2001 From: Stanislav N Mikhailov Date: Tue, 24 Mar 2026 21:18:10 +0300 Subject: [PATCH] Add RGB16 macro for RGB565 conversion with byte swap --- include/display/renderer.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/display/renderer.h b/include/display/renderer.h index f441308..18e222e 100644 --- a/include/display/renderer.h +++ b/include/display/renderer.h @@ -7,6 +7,18 @@ extern "C" { #endif +#define RGB565(R, G, B) \ + ((uint16_t)((((uint16_t)(R) & 0xF8u) << 8) | \ + (((uint16_t)(G) & 0xFCu) << 3) | \ + (((uint16_t)(B) & 0xF8u) >> 3))) + +#define BSWAP16(X) \ + ((uint16_t)((((uint16_t)(X) & 0x00FFu) << 8) | \ + (((uint16_t)(X) & 0xFF00u) >> 8))) + +/* RGB888 -> RGB565 with swapped byte order for ctx->buf */ +#define RGB16(R, G, B) BSWAP16(RGB565((R), (G), (B))) + typedef struct { uint16_t* buf; @@ -49,4 +61,3 @@ void render_bezier( #ifdef __cplusplus } #endif -