Merge pull request #205 from pimoroni/patch-plasma-gamma

plasma: add gamma correction
pull/214/head
Philip Howard 2021-10-06 11:17:38 +01:00 zatwierdzone przez GitHub
commit ff9dcca91b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
7 zmienionych plików z 37 dodań i 40 usunięć

Wyświetl plik

@ -49,4 +49,22 @@ namespace pimoroni {
inline uint32_t millis() {
return to_ms_since_boot(get_absolute_time());
}
constexpr uint8_t GAMMA[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5,
6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11,
11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18,
19, 19, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, 27, 27, 28,
29, 29, 30, 31, 31, 32, 33, 34, 34, 35, 36, 37, 37, 38, 39, 40,
40, 41, 42, 43, 44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 76, 77, 78, 79, 80, 81, 83, 84, 85, 86, 88, 89,
90, 91, 93, 94, 95, 96, 98, 99, 100, 102, 103, 104, 106, 107, 109, 110,
111, 113, 114, 116, 117, 119, 120, 121, 123, 124, 126, 128, 129, 131, 132, 134,
135, 137, 138, 140, 142, 143, 145, 146, 148, 150, 151, 153, 155, 157, 158, 160,
162, 163, 165, 167, 169, 170, 172, 174, 176, 178, 179, 181, 183, 185, 187, 189,
191, 193, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220,
222, 224, 227, 229, 231, 233, 235, 237, 239, 241, 244, 246, 248, 250, 252, 255};
}

Wyświetl plik

@ -4,6 +4,7 @@
#include <vector>
#include "is31fl3731.hpp"
#include "common/pimoroni_common.hpp"
namespace pimoroni {
@ -13,24 +14,6 @@ namespace pimoroni {
constexpr uint8_t ENABLE_OFFSET = 0x00;
constexpr uint8_t COLOR_OFFSET = 0x24;
constexpr uint8_t GAMMA[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5,
6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11,
11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18,
19, 19, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, 27, 27, 28,
29, 29, 30, 31, 31, 32, 33, 34, 34, 35, 36, 37, 37, 38, 39, 40,
40, 41, 42, 43, 44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 76, 77, 78, 79, 80, 81, 83, 84, 85, 86, 88, 89,
90, 91, 93, 94, 95, 96, 98, 99, 100, 102, 103, 104, 106, 107, 109, 110,
111, 113, 114, 116, 117, 119, 120, 121, 123, 124, 126, 128, 129, 131, 132, 134,
135, 137, 138, 140, 142, 143, 145, 146, 148, 150, 151, 153, 155, 157, 158, 160,
162, 163, 165, 167, 169, 170, 172, 174, 176, 178, 179, 181, 183, 185, 187, 189,
191, 193, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220,
222, 224, 227, 229, 231, 233, 235, 237, 239, 241, 244, 246, 248, 250, 252, 255};
enum mode {
PICTURE = 0x00,
@ -105,7 +88,7 @@ namespace pimoroni {
}
void IS31FL3731::set(uint8_t index, uint8_t brightness) {
buf[index + 1] = GAMMA[brightness];
buf[index + 1] = pimoroni::GAMMA[brightness];
}
void IS31FL3731::update(uint8_t frame) {

Wyświetl plik

@ -1,4 +1,5 @@
#include "apa102.hpp"
#include "common/pimoroni_common.hpp"
namespace plasma {
@ -96,7 +97,12 @@ void APA102::set_hsv(uint32_t index, float h, float s, float v) {
}
}
void APA102::set_rgb(uint32_t index, uint8_t r, uint8_t g, uint8_t b) {
void APA102::set_rgb(uint32_t index, uint8_t r, uint8_t g, uint8_t b, bool gamma) {
if(gamma) {
r = pimoroni::GAMMA[r];
g = pimoroni::GAMMA[g];
b = pimoroni::GAMMA[b];
}
buffer[index].rgb(r, g, b);
}

Wyświetl plik

@ -76,7 +76,7 @@ namespace plasma {
void update(bool blocking=false);
void clear();
void set_hsv(uint32_t index, float h, float s, float v);
void set_rgb(uint32_t index, uint8_t r, uint8_t g, uint8_t b);
void set_rgb(uint32_t index, uint8_t r, uint8_t g, uint8_t b, bool gamma=true);
void set_brightness(uint8_t b);
RGB get(uint32_t index) {return buffer[index];};

Wyświetl plik

@ -1,4 +1,5 @@
#include "ws2812.hpp"
#include "common/pimoroni_common.hpp"
namespace plasma {
@ -84,7 +85,13 @@ void WS2812::set_hsv(uint32_t index, float h, float s, float v) {
}
}
void WS2812::set_rgb(uint32_t index, uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
void WS2812::set_rgb(uint32_t index, uint8_t r, uint8_t g, uint8_t b, uint8_t w, bool gamma) {
if(gamma) {
r = pimoroni::GAMMA[r];
g = pimoroni::GAMMA[g];
b = pimoroni::GAMMA[b];
w = pimoroni::GAMMA[w];
}
switch(color_order) {
case COLOR_ORDER::RGB:
buffer[index].rgb(r, g, b, w);

Wyświetl plik

@ -85,7 +85,7 @@ namespace plasma {
void update(bool blocking=false);
void clear();
void set_hsv(uint32_t index, float h, float s, float v);
void set_rgb(uint32_t index, uint8_t r, uint8_t g, uint8_t b, uint8_t w=0);
void set_rgb(uint32_t index, uint8_t r, uint8_t g, uint8_t b, uint8_t w=0, bool gamma=true);
void set_brightness(uint8_t b);
RGB get(uint32_t index) {return buffer[index];};

Wyświetl plik

@ -44,23 +44,6 @@ namespace pimoroni {
uint8_t led_g;
uint8_t led_b;
uint8_t led_brightness = 255;
const uint8_t GAMMA[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5,
6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11,
11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18,
19, 19, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, 27, 27, 28,
29, 29, 30, 31, 31, 32, 33, 34, 34, 35, 36, 37, 37, 38, 39, 40,
40, 41, 42, 43, 44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 76, 77, 78, 79, 80, 81, 83, 84, 85, 86, 88, 89,
90, 91, 93, 94, 95, 96, 98, 99, 100, 102, 103, 104, 106, 107, 109, 110,
111, 113, 114, 116, 117, 119, 120, 121, 123, 124, 126, 128, 129, 131, 132, 134,
135, 137, 138, 140, 142, 143, 145, 146, 148, 150, 151, 153, 155, 157, 158, 160,
162, 163, 165, 167, 169, 170, 172, 174, 176, 178, 179, 181, 183, 185, 187, 189,
191, 193, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220,
222, 224, 227, 229, 231, 233, 235, 237, 239, 241, 244, 246, 248, 250, 252, 255};
void update_pwm();
};