Skip to content

Commit

Permalink
Use redmean color distance for 32bpp to 8 conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
ldpl committed Dec 13, 2023
1 parent 39a0401 commit 657295d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/blitter/32bpp_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 657295d

Please sign in to comment.