Skip to content

Commit

Permalink
Add brightness setting to gamma calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
penfold42 committed Nov 15, 2017
1 parent 61a65b4 commit 5ab8a2f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions ESPixelStick.h
Expand Up @@ -145,6 +145,7 @@ typedef struct {
PixelColor pixel_color; /* Pixel color order */
bool gamma; /* Use gamma map? */
float gammaVal; /* gamma value to use */
float briteVal; /* brightness lto use */
#elif defined(ESPS_MODE_SERIAL)
/* Serial */
SerialType serial_type; /* Serial type */
Expand Down
8 changes: 7 additions & 1 deletion ESPixelStick.ino
Expand Up @@ -587,6 +587,10 @@ void validateConfig() {
if (config.gammaVal <= 0) {
config.gammaVal = 2.2;
}
// default gamma value
if (config.briteVal <= 0) {
config.briteVal = 1.0;
}
#elif defined(ESPS_MODE_SERIAL)
// Set Mode
// config.devmode = DevMode::MSERIAL;
Expand Down Expand Up @@ -639,7 +643,7 @@ void updateConfig() {
#if defined(ESPS_MODE_PIXEL)
pixels.begin(config.pixel_type, config.pixel_color, config.channel_count / 3);
pixels.setGamma(config.gamma);
updateGammaTable(config.gammaVal);
updateGammaTable(config.gammaVal, config.briteVal);

#elif defined(ESPS_MODE_SERIAL)
serial.begin(&SEROUT_PORT, config.serial_type, config.channel_count, config.baudrate);
Expand Down Expand Up @@ -711,6 +715,7 @@ void dsDeviceConfig(JsonObject &json) {
config.pixel_color = PixelColor(static_cast<uint8_t>(json["pixel"]["color"]));
config.gamma = json["pixel"]["gamma"];
config.gammaVal = json["pixel"]["gammaVal"];
config.briteVal = json["pixel"]["briteVal"];

#elif defined(ESPS_MODE_SERIAL)
/* Serial */
Expand Down Expand Up @@ -831,6 +836,7 @@ void serializeConfig(String &jsonString, bool pretty, bool creds) {
pixel["color"] = static_cast<uint8_t>(config.pixel_color);
pixel["gamma"] = config.gamma;
pixel["gammaVal"] = config.gammaVal;
pixel["briteVal"] = config.briteVal;

#elif defined(ESPS_MODE_SERIAL)
// Serial
Expand Down
4 changes: 2 additions & 2 deletions gamma.cpp
Expand Up @@ -20,9 +20,9 @@ uint8_t GAMMA_TABLE[] = {
222,224,227,229,231,233,235,237,239,241,244,246,248,250,252,255
};

void updateGammaTable(float gammaVal) {
void updateGammaTable(float gammaVal, float briteVal) {
for (int i=0; i<256; i++) {
GAMMA_TABLE[i] = (uint8_t) 255.0 * pow(i/255.0, gammaVal) + 0.5;
GAMMA_TABLE[i] = min( (uint8_t) 255.0 * pow(i*briteVal/255.0, gammaVal) + 0.5, 255);
}
}

2 changes: 1 addition & 1 deletion gamma.h
Expand Up @@ -4,6 +4,6 @@
/* Gamma correction table */
extern uint8_t GAMMA_TABLE[];

void updateGammaTable(float gammaVal);
void updateGammaTable(float gammaVal, float briteVal);

#endif /* GAMMA_H_ */
6 changes: 4 additions & 2 deletions html/index.html
Expand Up @@ -170,8 +170,10 @@
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="p_gammaVal">Gamma Value</label>
<div class="col-sm-5"><input type="text" class="form-control" id="p_gammaVal" name="p_gammaVal" placeholder="Gamma Value" onchange="refreshPixel()"></div>
<div class="col-sm-5"><a target="_gamma" href="/gamma.html">View Graph</a></div>
<div class="col-sm-3"><input type="text" class="form-control" id="p_gammaVal" name="p_gammaVal" placeholder="Gamma Value" onchange="refreshPixel()"></div>
<label class="control-label col-sm-2" for="p_briteVal">Brightness</label>
<div class="col-sm-3"><input type="text" class="form-control" id="p_briteVal" name="p_briteVal" placeholder="Brightness" onchange="refreshPixel()"></div>
<div class="col-sm-2"><a target="_gamma" href="/gamma.html">View Graph</a></div>
</div>
</div>

Expand Down
4 changes: 3 additions & 1 deletion html/script.js
Expand Up @@ -489,6 +489,7 @@ function getConfig(data) {
$('#p_color').val(config.pixel.color);
$('#p_gamma').prop('checked', config.pixel.gamma);
$('#p_gammaVal').val(config.pixel.gammaVal);
$('#p_briteVal').val(config.pixel.briteVal);

if(config.e131.channel_count / 3 <8 ) {
$('#v_columns').val(config.e131.channel_count / 3);
Expand Down Expand Up @@ -674,7 +675,8 @@ function submitConfig() {
'type': parseInt($('#p_type').val()),
'color': parseInt($('#p_color').val()),
'gamma': $('#p_gamma').prop('checked'),
'gammaVal': parseFloat($('#p_gammaVal').val())
'gammaVal': parseFloat($('#p_gammaVal').val()),
'briteVal': parseFloat($('#p_briteVal').val())
},
'serial': {
'type': parseInt($('#s_proto').val()),
Expand Down

0 comments on commit 5ab8a2f

Please sign in to comment.