From 657295d0c5d2a01b51f78e0907e7cd0b71259b32 Mon Sep 17 00:00:00 2001 From: dP Date: Wed, 13 Dec 2023 19:56:00 +0530 Subject: [PATCH] Use redmean color distance for 32bpp to 8 conversion --- src/blitter/32bpp_base.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/blitter/32bpp_base.hpp b/src/blitter/32bpp_base.hpp index f683c78e..122deb22 100644 --- a/src/blitter/32bpp_base.hpp +++ b/src/blitter/32bpp_base.hpp @@ -188,7 +188,12 @@ class Blitter_32bppBase : public Blitter { uint md = UINT_MAX; for (uint8 i = 1; i < 0xc0; i++) { auto c = this->LookupColourInPalette(i); - auto dist = ((uint)c.r - r) * ((uint)c.r - r) + ((uint)c.g - g) * ((uint)c.g - g) + ((uint)c.b - b) * ((uint)c.b - b); + auto rmean = ((uint)c.r + (uint)r) / 2; + auto dr = (uint)c.r - (uint)r; + auto dg = (uint)c.g - (uint)g; + auto db = (uint)c.b - (uint)b; + auto dist = (512 + rmean) * dr * dr + 1024 * dg * dg + (767 - rmean) * db * db; + // auto dist = r * r + g * g + b * b; if (dist < md) { md = dist; m = i;