ref: c98d92a4c4d97e8118bc3ad122b500e16aefa5f2
parent: d438838db4ce2aabc6d9c18526f8c1009ef4e8bc
author: ISSOtm <eldredhabert0@gmail.com>
date: Sun Mar 6 08:35:19 EST 2022
Implement `-C`
--- 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<uint8_t, 256> 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 {