From f22711c9e699af4646a74680b753cafde1a3a797 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Sun, 10 Aug 2025 00:56:16 -0400 Subject: [PATCH 01/16] comments --- src/lua-engine.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index b337513b3..69d2541ac 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -3746,7 +3746,6 @@ enum */ static uint8 gui_colour_rgb(uint8 r, uint8 g, uint8 b) { static uint8 index_lookup[1 << (3+3+3)]; - int k; if (!gui_saw_current_palette) { @@ -3754,15 +3753,17 @@ static uint8 gui_colour_rgb(uint8 r, uint8 g, uint8 b) { gui_saw_current_palette = TRUE; } - k = ((r & 0xE0) << 1) | ((g & 0xE0) >> 2) | ((b & 0xE0) >> 5); + // Cache based on upper 3 bits of r, g, and b + int k = ((r & 0xE0) << 1) | ((g & 0xE0) >> 2) | ((b & 0xE0) >> 5); + if (index_lookup[k] != GUI_COLOUR_CLEAR) return index_lookup[k]; uint16 test, best = GUI_COLOUR_CLEAR; - uint32 best_score = 0xffffffffu, test_score; - if (index_lookup[k] != GUI_COLOUR_CLEAR) return index_lookup[k]; + uint32 test_score, best_score = 0xffffffffu; for (test = 0; test < 0xff; test++) { uint8 tr, tg, tb; if (test == GUI_COLOUR_CLEAR) continue; FCEUD_GetPalette(test, &tr, &tg, &tb); + // Weights based on luminance formula? test_score = abs(r - tr) * 66 + abs(g - tg) * 129 + abs(b - tb) * 25; From ecfc9987db57cd82c852ba3bc0d10deeb0ef211d Mon Sep 17 00:00:00 2001 From: warmCabin Date: Sun, 10 Aug 2025 00:58:43 -0400 Subject: [PATCH 02/16] comment out index_lookup (for now) Just want to see what happens. If the performance sucks, I'll try it with 5 or 6 bits. If the difference is negligible, I'll remove it properly. --- src/lua-engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 69d2541ac..001185935 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -3755,7 +3755,7 @@ static uint8 gui_colour_rgb(uint8 r, uint8 g, uint8 b) { // Cache based on upper 3 bits of r, g, and b int k = ((r & 0xE0) << 1) | ((g & 0xE0) >> 2) | ((b & 0xE0) >> 5); - if (index_lookup[k] != GUI_COLOUR_CLEAR) return index_lookup[k]; + // if (index_lookup[k] != GUI_COLOUR_CLEAR) return index_lookup[k]; uint16 test, best = GUI_COLOUR_CLEAR; uint32 test_score, best_score = 0xffffffffu; for (test = 0; test < 0xff; test++) From b8fdec1b29d9427ffbb5e90d03e1189602a7be0d Mon Sep 17 00:00:00 2001 From: warmCabin Date: Sun, 10 Aug 2025 01:22:05 -0400 Subject: [PATCH 03/16] change scoring to basic distance squared --- src/lua-engine.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 001185935..6c21f3887 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -3763,10 +3763,10 @@ static uint8 gui_colour_rgb(uint8 r, uint8 g, uint8 b) { uint8 tr, tg, tb; if (test == GUI_COLOUR_CLEAR) continue; FCEUD_GetPalette(test, &tr, &tg, &tb); - // Weights based on luminance formula? - test_score = abs(r - tr) * 66 + - abs(g - tg) * 129 + - abs(b - tb) * 25; + // Basic distance squared + test_score = (r - tr) * (r - tr) + + (g - tg) * (g - tg) + + (b - tb) * (b - tb); if (test_score < best_score) best_score = test_score, best = test; } index_lookup[k] = best; From 61bd1786da006dbd26f40b185db079fa4b9fcf32 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 11 Aug 2025 01:53:43 -0400 Subject: [PATCH 04/16] reenable index_lookup, for science --- src/lua-engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 6c21f3887..d94fc9d0a 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -3755,7 +3755,7 @@ static uint8 gui_colour_rgb(uint8 r, uint8 g, uint8 b) { // Cache based on upper 3 bits of r, g, and b int k = ((r & 0xE0) << 1) | ((g & 0xE0) >> 2) | ((b & 0xE0) >> 5); - // if (index_lookup[k] != GUI_COLOUR_CLEAR) return index_lookup[k]; + if (index_lookup[k] != GUI_COLOUR_CLEAR) return index_lookup[k]; uint16 test, best = GUI_COLOUR_CLEAR; uint32 test_score, best_score = 0xffffffffu; for (test = 0; test < 0xff; test++) From dccb54f46a347a9dbb158d9ce71ede5875708307 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Mon, 11 Aug 2025 02:22:39 -0400 Subject: [PATCH 05/16] do a 5-bit lookup table --- src/lua-engine.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index d94fc9d0a..44f88346e 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -3745,7 +3745,7 @@ enum * ourselves. */ static uint8 gui_colour_rgb(uint8 r, uint8 g, uint8 b) { - static uint8 index_lookup[1 << (3+3+3)]; + static uint8 index_lookup[1 << (5+5+5)]; if (!gui_saw_current_palette) { @@ -3753,8 +3753,8 @@ static uint8 gui_colour_rgb(uint8 r, uint8 g, uint8 b) { gui_saw_current_palette = TRUE; } - // Cache based on upper 3 bits of r, g, and b - int k = ((r & 0xE0) << 1) | ((g & 0xE0) >> 2) | ((b & 0xE0) >> 5); + // Cache based on upper 5 bits of r, g, and b + int k = ((r & 0xF8) << 7) | ((g & 0xF8) << 2) | ((b & 0xF8) >> 3); if (index_lookup[k] != GUI_COLOUR_CLEAR) return index_lookup[k]; uint16 test, best = GUI_COLOUR_CLEAR; uint32 test_score, best_score = 0xffffffffu; @@ -3769,8 +3769,7 @@ static uint8 gui_colour_rgb(uint8 r, uint8 g, uint8 b) { (b - tb) * (b - tb); if (test_score < best_score) best_score = test_score, best = test; } - index_lookup[k] = best; - return best; + return index_lookup[k] = best; } void FCEU_LuaUpdatePalette() From 29aa6863c1f687a950b6c9d8a7bb851ffc52abe0 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Sun, 17 May 2026 02:20:18 -0400 Subject: [PATCH 06/16] add gui.clearcolorcache --- src/lua-engine.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 44f88346e..853c87878 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -4136,6 +4136,17 @@ static int gui_parsecolor(lua_State *L) return 4; } +// gui.clearcolorcache() +// +// The color cache can get stale and make things look a little funny, especially when transparency is involved. +// This function queues up a reset of the cache (next time a color is requested) to hopefully mitigate that. +// This shouldn't be as much of an issue with the new caching logic, but you never know. +static int gui_clearcolorcache(lua_State *L) +{ + FCEU_LuaUpdatePalette(); + return 0; +} + // gui.savescreenshotas() // @@ -6384,6 +6395,7 @@ static const struct luaL_reg guilib[] = { {"text", gui_text}, {"parsecolor", gui_parsecolor}, + {"clearcolorcache", gui_clearcolorcache}, {"savescreenshot", gui_savescreenshot}, {"savescreenshotas", gui_savescreenshotas}, From ca7f5e8d358b4b015e9bc8e5df8478cfccd69c6a Mon Sep 17 00:00:00 2001 From: warmCabin Date: Sun, 17 May 2026 14:48:55 -0400 Subject: [PATCH 07/16] add gui.setcolormatchformula I added this for testing purposes; you might find it useful, too. I imagine I'm going to revert this before merging. --- src/lua-engine.cpp | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 853c87878..dfe72d4aa 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -3737,6 +3737,7 @@ enum , GUI_COLOUR_RED, GUI_COLOUR_GREEN, GUI_COLOUR_BLUE */ }; +static int colorMatchFormula = 3; /** * Returns an index approximating an RGB colour. * TODO: This is easily improvable in terms of speed and probably @@ -3763,10 +3764,33 @@ static uint8 gui_colour_rgb(uint8 r, uint8 g, uint8 b) { uint8 tr, tg, tb; if (test == GUI_COLOUR_CLEAR) continue; FCEUD_GetPalette(test, &tr, &tg, &tb); - // Basic distance squared - test_score = (r - tr) * (r - tr) + - (g - tg) * (g - tg) + - (b - tb) * (b - tb); + switch (colorMatchFormula) { + case 0: + // Original formula - weights based on luminance? + test_score = abs(r - tr) * 66 + + abs(g - tg) * 129 + + abs(b - tb) * 25; + break; + case 1: + // Original formula, but the deltas are squared. + test_score = abs(r - tr) * abs(r - tr) * 66 + + abs(g - tg) * abs(g - tg) * 129 + + abs(b - tb) * abs(b - tb) * 25; + break; + case 2: + // Basic distance squared + test_score = (r - tr) * (r - tr) + + (g - tg) * (g - tg) + + (b - tb) * (b - tb); + break; + case 3: + // Redmean + int red_mean = r / 2 + tr / 2, dr = tr - r, dg = tg - g, db = tb - b; + test_score = (2 + red_mean / 256) * dr * dr + + 4 * dg * dg + + (2 + (255 - red_mean) / 256) * db * db; + break; + } if (test_score < best_score) best_score = test_score, best = test; } return index_lookup[k] = best; @@ -4147,6 +4171,12 @@ static int gui_clearcolorcache(lua_State *L) return 0; } +static int gui_setcolormatchformula(lua_State *L) +{ + colorMatchFormula = luaL_checkint(L, 1); + return 0; +} + // gui.savescreenshotas() // @@ -6396,6 +6426,7 @@ static const struct luaL_reg guilib[] = { {"parsecolor", gui_parsecolor}, {"clearcolorcache", gui_clearcolorcache}, + {"setcolormatchformula", gui_setcolormatchformula}, {"savescreenshot", gui_savescreenshot}, {"savescreenshotas", gui_savescreenshotas}, From 5fecb6e45c79df95eb02a2350a1dfc379ca588b8 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Sun, 17 May 2026 23:18:57 -0400 Subject: [PATCH 08/16] rerun CI From 506795f3372eeee9dfd3a2468c745a6e0bfe2ae6 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 19 May 2026 10:41:54 -0400 Subject: [PATCH 09/16] rerun CI From 2c0003c68aa9997732cd2abf5d3d6cc5275bdf92 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Tue, 19 May 2026 23:26:01 -0400 Subject: [PATCH 10/16] rerun CI From c543eba1b2e170043133d1db6d0141ec21e9b1a8 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Thu, 28 May 2026 01:15:41 -0400 Subject: [PATCH 11/16] develop gui.setcolormatchformula() a bit --- src/lua-engine.cpp | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index dfe72d4aa..10ff893b8 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -3737,7 +3737,8 @@ enum , GUI_COLOUR_RED, GUI_COLOUR_GREEN, GUI_COLOUR_BLUE */ }; -static int colorMatchFormula = 3; +static enum { COLORMATCH_OLD, COLORMATCH_OLD2, COLORMATCH_EUCLIDIAN, COLORMATCH_REDMEAN } colorMatchFormula = COLORMATCH_REDMEAN; + /** * Returns an index approximating an RGB colour. * TODO: This is easily improvable in terms of speed and probably @@ -3765,25 +3766,25 @@ static uint8 gui_colour_rgb(uint8 r, uint8 g, uint8 b) { if (test == GUI_COLOUR_CLEAR) continue; FCEUD_GetPalette(test, &tr, &tg, &tb); switch (colorMatchFormula) { - case 0: + case COLORMATCH_OLD: // Original formula - weights based on luminance? test_score = abs(r - tr) * 66 + abs(g - tg) * 129 + abs(b - tb) * 25; break; - case 1: + case COLORMATCH_OLD2: // Original formula, but the deltas are squared. test_score = abs(r - tr) * abs(r - tr) * 66 + abs(g - tg) * abs(g - tg) * 129 + abs(b - tb) * abs(b - tb) * 25; break; - case 2: - // Basic distance squared + case COLORMATCH_EUCLIDIAN: + // Basic distance squared test_score = (r - tr) * (r - tr) + (g - tg) * (g - tg) + (b - tb) * (b - tb); break; - case 3: + case COLORMATCH_REDMEAN: // Redmean int red_mean = r / 2 + tr / 2, dr = tr - r, dg = tg - g, db = tb - b; test_score = (2 + red_mean / 256) * dr * dr @@ -4171,9 +4172,30 @@ static int gui_clearcolorcache(lua_State *L) return 0; } +// gui.setcolormatchformula() +// +// Selects one of several formulas for matching colors to the limited Lua palette. +// The default is "redmean", which seems to have the best results for alpha blending. +// Choices: +// "old" - Original formula that stood for years. Weights based on luminance? +// "old2" - Original formula, but the deltas are squared. Gives better results. +// "euclidian" - Basic distance squared. +// "redmean" - The "redmean" formula, which gives more weight to the red channel as the Euclidian mean gets redder. static int gui_setcolormatchformula(lua_State *L) { - colorMatchFormula = luaL_checkint(L, 1); + const char *formula = luaL_checkstring(L, 1); + if (strcmpi(formula, "old") == 0) + colorMatchFormula = COLORMATCH_OLD; + else if (strcmpi(formula, "old2") == 0) + colorMatchFormula = COLORMATCH_OLD2; + else if (strcmpi(formula, "euclidian") == 0) + colorMatchFormula = COLORMATCH_EUCLIDIAN; + else if (strcmpi(formula, "redmean") == 0) + colorMatchFormula = COLORMATCH_REDMEAN; + else + luaL_argerror(L, 1, "must be one of \"old\", \"old2\", \"euclidian\", or \"redmean\""); + + FCEU_LuaUpdatePalette(); // Need to clear color cache, otherwise this might not have the desired effect. return 0; } From 31f20cf9bbb3f3c343fbf3c366fd650ebd294fb2 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Sat, 30 May 2026 23:40:24 -0400 Subject: [PATCH 12/16] remove unnecessary abs from OLD2 Don't you know that a negative number squared is positive!? --- src/lua-engine.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 10ff893b8..603594c2b 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -3774,9 +3774,9 @@ static uint8 gui_colour_rgb(uint8 r, uint8 g, uint8 b) { break; case COLORMATCH_OLD2: // Original formula, but the deltas are squared. - test_score = abs(r - tr) * abs(r - tr) * 66 + - abs(g - tg) * abs(g - tg) * 129 + - abs(b - tb) * abs(b - tb) * 25; + test_score = (r - tr) * (r - tr) * 66 + + (g - tg) * (g - tg) * 129 + + (b - tb) * (b - tb) * 25; break; case COLORMATCH_EUCLIDIAN: // Basic distance squared From 0ee8caf29b6c31ba40a1305986143d9769c23d9d Mon Sep 17 00:00:00 2001 From: warmCabin Date: Sat, 30 May 2026 23:58:08 -0400 Subject: [PATCH 13/16] add gui.setcolorcachedepth --- src/lua-engine.cpp | 71 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 603594c2b..25b921a21 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -3739,6 +3739,16 @@ enum }; static enum { COLORMATCH_OLD, COLORMATCH_OLD2, COLORMATCH_EUCLIDIAN, COLORMATCH_REDMEAN } colorMatchFormula = COLORMATCH_REDMEAN; +static uint8 *palette_index_lookup = NULL; +static int cacheDepth = 5; + +// Bits per color channel +// 3 - 512 bytes +// 4 - 4 KB +// 5 - 32 KB +// 6 - 256 KB +#define CACHE_SIZE(bits) (1 << (3 * (bits))) + /** * Returns an index approximating an RGB colour. * TODO: This is easily improvable in terms of speed and probably @@ -3747,17 +3757,34 @@ static enum { COLORMATCH_OLD, COLORMATCH_OLD2, COLORMATCH_EUCLIDIAN, COLORMATCH_ * ourselves. */ static uint8 gui_colour_rgb(uint8 r, uint8 g, uint8 b) { - static uint8 index_lookup[1 << (5+5+5)]; - if (!gui_saw_current_palette) { - memset(index_lookup, GUI_COLOUR_CLEAR, sizeof(index_lookup)); + memset(palette_index_lookup, GUI_COLOUR_CLEAR, CACHE_SIZE(cacheDepth)); gui_saw_current_palette = TRUE; } - // Cache based on upper 5 bits of r, g, and b - int k = ((r & 0xF8) << 7) | ((g & 0xF8) << 2) | ((b & 0xF8) >> 3); - if (index_lookup[k] != GUI_COLOUR_CLEAR) return index_lookup[k]; + int k; // Cache index, based on upper bits of r, g, and b + switch (cacheDepth) + { + case 3: + // Upper 3 bits + k = ((r & 0xE0) << 1) | ((g & 0xE0) >> 2) | ((b & 0xE0) >> 5); + break; + case 4: + // Upper 4 bits + k = ((r & 0xF0) << 4) | (g & 0xF0) | ((b & 0xF0) >> 4); + break; + case 5: + // Upper 5 bits + k = ((r & 0xF8) << 7) | ((g & 0xF8) << 2) | ((b & 0xF8) >> 3); + break; + case 6: + // Upper 6 bits + k = ((r & 0xFC) << 10) | ((g & 0xFC) << 4) | ((b & 0xFC) >> 2); + break; + } + + if (palette_index_lookup[k] != GUI_COLOUR_CLEAR) return palette_index_lookup[k]; uint16 test, best = GUI_COLOUR_CLEAR; uint32 test_score, best_score = 0xffffffffu; for (test = 0; test < 0xff; test++) @@ -3794,7 +3821,7 @@ static uint8 gui_colour_rgb(uint8 r, uint8 g, uint8 b) { } if (test_score < best_score) best_score = test_score, best = test; } - return index_lookup[k] = best; + return palette_index_lookup[k] = best; } void FCEU_LuaUpdatePalette() @@ -4172,6 +4199,29 @@ static int gui_clearcolorcache(lua_State *L) return 0; } +// gui.setcolorcachedepth() +// +// Set the number of upper bits used per color channel by the color caching logic. +// Higher values result in higher color accuracy, but more cache misses and higher memory usage. +// This is only necessary because FCEUX uses an 8-bit palette for its screen buffer, +// which even Lua script GUIs are beholden to. +static int gui_setcolorcachedepth(lua_State *L) +{ + int depth = luaL_checkint(L, 1); + if (depth < 3 || depth > 6) + luaL_argerror(L, 1, "mode out of range"); + + cacheDepth = depth; + + void *palette_index_lookup_tmp = realloc(palette_index_lookup, CACHE_SIZE(cacheDepth)); + if (palette_index_lookup_tmp == NULL) + abort(); + palette_index_lookup = (uint8*)palette_index_lookup_tmp; + + FCEU_LuaUpdatePalette(); + return 0; +} + // gui.setcolormatchformula() // // Selects one of several formulas for matching colors to the limited Lua palette. @@ -6448,6 +6498,7 @@ static const struct luaL_reg guilib[] = { {"parsecolor", gui_parsecolor}, {"clearcolorcache", gui_clearcolorcache}, + {"setcolorcachedepth", gui_setcolorcachedepth}, {"setcolormatchformula", gui_setcolormatchformula}, {"savescreenshot", gui_savescreenshot}, @@ -6673,6 +6724,10 @@ int FCEU_LoadLuaCode(const char *filename, const char *arg) luaexiterrorcount = 8; luaCallbackErrorCounter = 0; + palette_index_lookup = (uint8*)malloc(CACHE_SIZE(cacheDepth)); + if (palette_index_lookup == NULL) + abort(); + if (!L) { L = lua_open(); @@ -6897,6 +6952,8 @@ void FCEU_LuaStop() { //lua_gc(L,LUA_GCCOLLECT,0); + free(palette_index_lookup); + palette_index_lookup = NULL; lua_close(L); // this invokes our garbage collectors for us L = NULL; From 14e7b6fefa742902e47affa799024823a88458e5 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Sun, 31 May 2026 00:11:43 -0400 Subject: [PATCH 14/16] fix loop bound --- src/lua-engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 25b921a21..2101fc26d 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -3787,7 +3787,7 @@ static uint8 gui_colour_rgb(uint8 r, uint8 g, uint8 b) { if (palette_index_lookup[k] != GUI_COLOUR_CLEAR) return palette_index_lookup[k]; uint16 test, best = GUI_COLOUR_CLEAR; uint32 test_score, best_score = 0xffffffffu; - for (test = 0; test < 0xff; test++) + for (test = 0; test < 0x100; test++) { uint8 tr, tg, tb; if (test == GUI_COLOUR_CLEAR) continue; From fe4432a738430c7ee82d94e828ae05865a7e3e86 Mon Sep 17 00:00:00 2001 From: warmCabin Date: Sun, 31 May 2026 00:13:53 -0400 Subject: [PATCH 15/16] comments --- src/lua-engine.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 2101fc26d..cd24aba89 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -4202,6 +4202,7 @@ static int gui_clearcolorcache(lua_State *L) // gui.setcolorcachedepth() // // Set the number of upper bits used per color channel by the color caching logic. +// Valid values: 3-6 // Higher values result in higher color accuracy, but more cache misses and higher memory usage. // This is only necessary because FCEUX uses an 8-bit palette for its screen buffer, // which even Lua script GUIs are beholden to. @@ -4209,7 +4210,7 @@ static int gui_setcolorcachedepth(lua_State *L) { int depth = luaL_checkint(L, 1); if (depth < 3 || depth > 6) - luaL_argerror(L, 1, "mode out of range"); + luaL_argerror(L, 1, "mode out of range (must be 3-6)"); cacheDepth = depth; From a2057ab7f771dd293e676630c9c6dbee7af6daad Mon Sep 17 00:00:00 2001 From: warmCabin Date: Sun, 31 May 2026 00:14:17 -0400 Subject: [PATCH 16/16] remove clearcolorcache --- src/lua-engine.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index cd24aba89..acf6f6786 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -4188,17 +4188,6 @@ static int gui_parsecolor(lua_State *L) return 4; } -// gui.clearcolorcache() -// -// The color cache can get stale and make things look a little funny, especially when transparency is involved. -// This function queues up a reset of the cache (next time a color is requested) to hopefully mitigate that. -// This shouldn't be as much of an issue with the new caching logic, but you never know. -static int gui_clearcolorcache(lua_State *L) -{ - FCEU_LuaUpdatePalette(); - return 0; -} - // gui.setcolorcachedepth() // // Set the number of upper bits used per color channel by the color caching logic. @@ -6498,7 +6487,6 @@ static const struct luaL_reg guilib[] = { {"text", gui_text}, {"parsecolor", gui_parsecolor}, - {"clearcolorcache", gui_clearcolorcache}, {"setcolorcachedepth", gui_setcolorcachedepth}, {"setcolormatchformula", gui_setcolormatchformula},