diff --git a/arm9/source/common/ui.h b/arm9/source/common/ui.h index d7fdfae..a64f43c 100644 --- a/arm9/source/common/ui.h +++ b/arm9/source/common/ui.h @@ -87,3 +87,19 @@ bool ShowRtcSetterPrompt(void* time, const char *format, ...); bool ShowProgress(u64 current, u64 total, const char* opstr); int ShowBrightnessConfig(int set_brightness); + +static inline u16 rgb888_to_rgb565(u32 rgb) { + u8 r, g, b; + r = (rgb >> 16) & 0x1F; + g = (rgb >> 8) & 0x3F; + b = (rgb >> 0) & 0x1F; + return (r << 11) | (g << 5) | b; +} + +static inline u16 rgb888_buf_to_rgb565(u8 *rgb) { + u8 r, g, b; + r = (rgb[0] >> 3); + g = (rgb[1] >> 2); + b = (rgb[2] >> 3); + return (r << 11) | (g << 5) | b; +} diff --git a/arm9/source/utils/scripting.c b/arm9/source/utils/scripting.c index 842f1a9..0c3902c 100644 --- a/arm9/source/utils/scripting.c +++ b/arm9/source/utils/scripting.c @@ -342,17 +342,17 @@ void set_preview(const char* name, const char* content) { else if (strncasecmp(content, "full", _VAR_CNT_LEN) == 0) preview_mode = 2; else preview_mode = 0xFF; // unknown preview mode } else if (strncmp(name, "PREVIEW_COLOR_ACTIVE", _VAR_NAME_LEN) == 0) { - u8 rgb[4] = { 0 }; + u8 rgb[4]; if (strntohex(content, rgb, 3)) - script_color_active = getle32(rgb); + script_color_active = rgb888_buf_to_rgb565(rgb); } else if (strncmp(name, "PREVIEW_COLOR_COMMENT", _VAR_NAME_LEN) == 0) { - u8 rgb[4] = { 0 }; + u8 rgb[4]; if (strntohex(content, rgb, 3)) - script_color_comment = getle32(rgb); + script_color_comment = rgb888_buf_to_rgb565(rgb); } else if (strncmp(name, "PREVIEW_COLOR_CODE", _VAR_NAME_LEN) == 0) { - u8 rgb[4] = { 0 }; + u8 rgb[4]; if (strntohex(content, rgb, 3)) - script_color_code = getle32(rgb); + script_color_code = rgb888_buf_to_rgb565(rgb); } }