From c98d92a4c4d97e8118bc3ad122b500e16aefa5f2 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Sun, 6 Mar 2022 13:35:19 +0100 Subject: [PATCH] Implement `-C` --- src/gfx/rgba.cpp | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/gfx/rgba.cpp b/src/gfx/rgba.cpp index 63b5b5aa..0902ebd5 100644 --- a/src/gfx/rgba.cpp +++ b/src/gfx/rgba.cpp @@ -6,15 +6,43 @@ #include "gfx/main.hpp" // options +/* + * based on the Gaussian-like curve used by SameBoy since commit + * 65dd02cc52f531dbbd3a7e6014e99d5b24e71a4c (Oct 2017) + * with ties resolved by comparing the difference of the squares. + */ +static std::array reverse_curve{ + 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, // These + 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, // comments + 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, // prevent + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, // clang-format + 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, // from + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, // reflowing + 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, // these + 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, // 16 + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, // 16-iterm + 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, // lines, + 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, // which, + 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, // in + 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, // my + 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, // opinion, + 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, // help + 26, 27, 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 30, 30, 31, // visualization! +}; + uint16_t Rgba::cgbColor() const { if (isTransparent()) { return transparent; } + + uint8_t r = red, g = green, b = blue; if (options.useColorCurve) { - assert(!"TODO"); - } else { - return (red >> 3) | (green >> 3) << 5 | (blue >> 3) << 10; + g = g * 4 < b ? 0 : (g * 4 - b) / 3; + r = reverse_curve[r]; + g = reverse_curve[g]; + b = reverse_curve[b]; } + return (r >> 3) | (g >> 3) << 5 | (b >> 3) << 10; } uint8_t Rgba::grayIndex() const {