diff --git a/include/led-matrix.h b/include/led-matrix.h index 637b98033..8b853678c 100644 --- a/include/led-matrix.h +++ b/include/led-matrix.h @@ -85,6 +85,8 @@ class RGBMatrix : public Canvas { void set_luminance_correct(bool on); bool luminance_correct() const; + // Set brightness in percent. 1%..100%. + // This will only affect newly set pixels. void SetBrightness(uint8_t brightness); uint8_t brightness(); diff --git a/lib/framebuffer-internal.h b/lib/framebuffer-internal.h index 0b77d79ab..7937b611c 100644 --- a/lib/framebuffer-internal.h +++ b/lib/framebuffer-internal.h @@ -43,7 +43,11 @@ class Framebuffer { void set_luminance_correct(bool on) { do_luminance_correct_ = on; } bool luminance_correct() const { return do_luminance_correct_; } - void SetBrightness(uint8_t brightness) { brightness_ = brightness; } + // Set brightness in percent; range=1..100 + // This will only affect newly set pixels. + void SetBrightness(uint8_t b) { + brightness_ = (b <= 100 ? (b != 0 ? b : 1) : 100); + } uint8_t brightness() { return brightness_; } void DumpToMatrix(GPIO *io); diff --git a/lib/framebuffer.cc b/lib/framebuffer.cc index 6f20966d0..5eabeabb1 100644 --- a/lib/framebuffer.cc +++ b/lib/framebuffer.cc @@ -162,7 +162,7 @@ inline uint16_t Framebuffer::MapColor(uint8_t c) { if (do_luminance_correct_) { static uint16_t *luminance_lookup = CreateLuminanceCIE1931LookupTable(); - return COLOR_OUT_BITS(luminance_lookup[c * 100 + brightness_ - 1]); + return COLOR_OUT_BITS(luminance_lookup[c * 100 + (brightness_ - 1)]); } else { // simple scale down the color value c = c * brightness_ / 100;