From b4b511a4594ceb6bb49f7996be582a5b3673911a Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Sat, 3 Sep 2016 17:52:54 -0700 Subject: [PATCH] o Make brightness-lookup less expensive. --- lib/framebuffer.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/framebuffer.cc b/lib/framebuffer.cc index 326c8bb..31462ff 100644 --- a/lib/framebuffer.cc +++ b/lib/framebuffer.cc @@ -206,20 +206,23 @@ static uint16_t luminance_cie1931(uint8_t c, uint8_t brightness) { return out_factor * ((v <= 8) ? v / 902.3 : pow((v + 16) / 116.0, 3)); } -static uint16_t *CreateLuminanceCIE1931LookupTable() { - uint16_t *result = new uint16_t[256 * 100]; - for (int i = 0; i < 256; ++i) - for (int j = 0; j < 100; ++j) - result[i * 100 + j] = luminance_cie1931(i, j + 1); +struct ColorLookup { + uint16_t color[256]; +}; +static ColorLookup *CreateLuminanceCIE1931LookupTable() { + ColorLookup *for_brightness = new ColorLookup[100]; + for (int c = 0; c < 256; ++c) + for (int b = 0; b < 100; ++b) + for_brightness[b].color[c] = luminance_cie1931(c, b + 1); - return result; + return for_brightness; } inline uint16_t Framebuffer::MapColor(uint8_t c) { uint16_t result; if (do_luminance_correct_) { - static uint16_t *luminance_lookup = CreateLuminanceCIE1931LookupTable(); - result = luminance_lookup[c * 100 + (brightness_ - 1)]; + static ColorLookup *luminance_lookup = CreateLuminanceCIE1931LookupTable(); + result = luminance_lookup[brightness_ - 1].color[c]; } else { // simple scale down the color value c = c * brightness_ / 100;