From 0bfe178650db439b575cc83aad81598ed40d8dc3 Mon Sep 17 00:00:00 2001 From: TiKevin83 <38826675+TiKevin83@users.noreply.github.com> Date: Wed, 8 Apr 2020 19:19:18 -0400 Subject: [PATCH] New GBC LCD correction for Gambatte palette from documented shader research https://forums.libretro.com/t/real-gba-and-ds-phat-colors/1540 (#1917) --- .../Consoles/Nintendo/Gameboy/GBColors.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GBColors.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GBColors.cs index c44dab34c2..e262387370 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GBColors.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GBColors.cs @@ -51,9 +51,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy public static Triple GambatteColor(Triple c) { Triple ret; - ret.r = (c.r * 13 + c.g * 2 + c.b) >> 1; - ret.g = (c.g * 3 + c.b) << 1; - ret.b = (c.r * 3 + c.g * 2 + c.b * 11) >> 1; + double gammaR = Math.Pow((double)c.r / 31, 2.2); + double gammaG = Math.Pow((double)c.g / 31, 2.2); + double gammaB = Math.Pow((double)c.b / 31, 2.2); + ret.r = (int)(Math.Pow(gammaR * .87 + gammaG * .18 - gammaB * .05, 1/ 2.2) * 255 + .5); + ret.g = (int)(Math.Pow(gammaG * .66 + gammaR * .115 + gammaB * .225, 1/ 2.2) * 255 + .5); + ret.b = (int)(Math.Pow(gammaB * .79 + gammaR * .14 + gammaG * .07, 1/ 2.2) * 255 + .5); + ret.r = Math.Max(0, Math.Min(255, ret.r)); + ret.g = Math.Max(0, Math.Min(255, ret.g)); + ret.b = Math.Max(0, Math.Min(255, ret.b)); return ret; }