Skip to content

Commit 5ab8a2f

Browse files
committed
Add brightness setting to gamma calculation
1 parent 61a65b4 commit 5ab8a2f

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

ESPixelStick.h

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ typedef struct {
145145
PixelColor pixel_color; /* Pixel color order */
146146
bool gamma; /* Use gamma map? */
147147
float gammaVal; /* gamma value to use */
148+
float briteVal; /* brightness lto use */
148149
#elif defined(ESPS_MODE_SERIAL)
149150
/* Serial */
150151
SerialType serial_type; /* Serial type */

ESPixelStick.ino

+7-1
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,10 @@ void validateConfig() {
587587
if (config.gammaVal <= 0) {
588588
config.gammaVal = 2.2;
589589
}
590+
// default gamma value
591+
if (config.briteVal <= 0) {
592+
config.briteVal = 1.0;
593+
}
590594
#elif defined(ESPS_MODE_SERIAL)
591595
// Set Mode
592596
// config.devmode = DevMode::MSERIAL;
@@ -639,7 +643,7 @@ void updateConfig() {
639643
#if defined(ESPS_MODE_PIXEL)
640644
pixels.begin(config.pixel_type, config.pixel_color, config.channel_count / 3);
641645
pixels.setGamma(config.gamma);
642-
updateGammaTable(config.gammaVal);
646+
updateGammaTable(config.gammaVal, config.briteVal);
643647

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

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

835841
#elif defined(ESPS_MODE_SERIAL)
836842
// Serial

gamma.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ uint8_t GAMMA_TABLE[] = {
2020
222,224,227,229,231,233,235,237,239,241,244,246,248,250,252,255
2121
};
2222

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

gamma.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
/* Gamma correction table */
55
extern uint8_t GAMMA_TABLE[];
66

7-
void updateGammaTable(float gammaVal);
7+
void updateGammaTable(float gammaVal, float briteVal);
88

99
#endif /* GAMMA_H_ */

html/index.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,10 @@
170170
</div>
171171
<div class="form-group">
172172
<label class="control-label col-sm-2" for="p_gammaVal">Gamma Value</label>
173-
<div class="col-sm-5"><input type="text" class="form-control" id="p_gammaVal" name="p_gammaVal" placeholder="Gamma Value" onchange="refreshPixel()"></div>
174-
<div class="col-sm-5"><a target="_gamma" href="/gamma.html">View Graph</a></div>
173+
<div class="col-sm-3"><input type="text" class="form-control" id="p_gammaVal" name="p_gammaVal" placeholder="Gamma Value" onchange="refreshPixel()"></div>
174+
<label class="control-label col-sm-2" for="p_briteVal">Brightness</label>
175+
<div class="col-sm-3"><input type="text" class="form-control" id="p_briteVal" name="p_briteVal" placeholder="Brightness" onchange="refreshPixel()"></div>
176+
<div class="col-sm-2"><a target="_gamma" href="/gamma.html">View Graph</a></div>
175177
</div>
176178
</div>
177179

html/script.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ function getConfig(data) {
489489
$('#p_color').val(config.pixel.color);
490490
$('#p_gamma').prop('checked', config.pixel.gamma);
491491
$('#p_gammaVal').val(config.pixel.gammaVal);
492+
$('#p_briteVal').val(config.pixel.briteVal);
492493

493494
if(config.e131.channel_count / 3 <8 ) {
494495
$('#v_columns').val(config.e131.channel_count / 3);
@@ -674,7 +675,8 @@ function submitConfig() {
674675
'type': parseInt($('#p_type').val()),
675676
'color': parseInt($('#p_color').val()),
676677
'gamma': $('#p_gamma').prop('checked'),
677-
'gammaVal': parseFloat($('#p_gammaVal').val())
678+
'gammaVal': parseFloat($('#p_gammaVal').val()),
679+
'briteVal': parseFloat($('#p_briteVal').val())
678680
},
679681
'serial': {
680682
'type': parseInt($('#s_proto').val()),

0 commit comments

Comments
 (0)