Skip to content

Commit 391f6e8

Browse files
Robert WinslowRobert Winslow
authored andcommitted
Added a function to allow a user to set a gamma correction factor.
This will generate and apply this correction table to the led gamma setting.
1 parent 31f668c commit 391f6e8

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

SConstruct

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ platforms = [
4848
],
4949
'LINKFLAGS' : [
5050
"-lrt",
51+
"-lm",
5152
],
5253
},
5354
],

ws2811.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include <linux/types.h>
4242
#include <linux/spi/spidev.h>
4343
#include <time.h>
44-
44+
#include <math.h>
4545
#include "mailbox.h"
4646
#include "clk.h"
4747
#include "gpio.h"
@@ -1282,3 +1282,23 @@ const char * ws2811_get_return_t_str(const ws2811_return_t state)
12821282

12831283
return "";
12841284
}
1285+
1286+
1287+
void setCustomGammaFactor(ws2811_t *ws2811, double gammaFactor)
1288+
{
1289+
for (int chan = 0; chan < RPI_PWM_CHANNELS; chan++)
1290+
{
1291+
ws2811_channel_t *channel = &ws2811->channel[chan];
1292+
1293+
if (channel->gamma)
1294+
{
1295+
for(int counter = 0; counter < 256; counter++)
1296+
{
1297+
1298+
channel->gamma[counter] = (gammaFactor > 0)? (int)(pow((float)counter / (float)255.00, gammaFactor) * 255.00 + 0.5) : counter;
1299+
1300+
}
1301+
}
1302+
1303+
}
1304+
}

ws2811.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ void ws2811_fini(ws2811_t *ws2811); //< Tear
122122
ws2811_return_t ws2811_render(ws2811_t *ws2811); //< Send LEDs off to hardware
123123
ws2811_return_t ws2811_wait(ws2811_t *ws2811); //< Wait for DMA completion
124124
const char * ws2811_get_return_t_str(const ws2811_return_t state); //< Get string representation of the given return state
125+
void setCustomGammaFactor(ws2811_t *ws2811, double gammaFactor); //Set a custom Gamma correction array based on a gamma correction factor
125126

126127
#ifdef __cplusplus
127128
}

0 commit comments

Comments
 (0)