Skip to content

Commit

Permalink
o Proper brightness clipping and documentation added.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzeller committed Aug 15, 2015
1 parent 55ff266 commit cf252fb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/led-matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 5 additions & 1 deletion lib/framebuffer-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/framebuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cf252fb

Please sign in to comment.