kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Unicorn: Move gamma LUTs to pimoroni_common.
rodzic
19c57ebb20
commit
bff6bd023e
|
@ -78,7 +78,7 @@ namespace pimoroni {
|
||||||
return to_ms_since_boot(get_absolute_time());
|
return to_ms_since_boot(get_absolute_time());
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr uint8_t GAMMA_8BIT[256] = {
|
inline constexpr uint8_t GAMMA_8BIT[256] = {
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
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,
|
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,
|
2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5,
|
||||||
|
@ -98,7 +98,7 @@ namespace pimoroni {
|
||||||
|
|
||||||
/* Moved from pico_unicorn.cpp
|
/* Moved from pico_unicorn.cpp
|
||||||
v = (uint16_t)(powf((float)(n) / 255.0f, 2.2) * 16383.0f + 0.5f) */
|
v = (uint16_t)(powf((float)(n) / 255.0f, 2.2) * 16383.0f + 0.5f) */
|
||||||
constexpr uint16_t GAMMA_14BIT[256] = {
|
inline constexpr uint16_t GAMMA_14BIT[256] = {
|
||||||
0, 0, 0, 1, 2, 3, 4, 6, 8, 10, 13, 16, 20, 23, 28, 32,
|
0, 0, 0, 1, 2, 3, 4, 6, 8, 10, 13, 16, 20, 23, 28, 32,
|
||||||
37, 42, 48, 54, 61, 67, 75, 82, 90, 99, 108, 117, 127, 137, 148, 159,
|
37, 42, 48, 54, 61, 67, 75, 82, 90, 99, 108, 117, 127, 137, 148, 159,
|
||||||
170, 182, 195, 207, 221, 234, 249, 263, 278, 294, 310, 326, 343, 361, 379, 397,
|
170, 182, 195, 207, 221, 234, 249, 263, 278, 294, 310, 326, 343, 361, 379, 397,
|
||||||
|
|
|
@ -7,4 +7,4 @@ target_sources(rgbled INTERFACE
|
||||||
target_include_directories(rgbled INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
target_include_directories(rgbled INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||||
|
|
||||||
# Pull in pico libraries that we need
|
# Pull in pico libraries that we need
|
||||||
target_link_libraries(rgbled INTERFACE pico_stdlib hardware_pwm)
|
target_link_libraries(rgbled INTERFACE pico_stdlib hardware_pwm)
|
||||||
|
|
|
@ -38,10 +38,6 @@
|
||||||
//
|
//
|
||||||
// .. and back to the start
|
// .. and back to the start
|
||||||
|
|
||||||
static uint16_t r_gamma_lut[256] = {0};
|
|
||||||
static uint16_t g_gamma_lut[256] = {0};
|
|
||||||
static uint16_t b_gamma_lut[256] = {0};
|
|
||||||
|
|
||||||
static uint32_t dma_channel;
|
static uint32_t dma_channel;
|
||||||
static uint32_t dma_ctrl_channel;
|
static uint32_t dma_ctrl_channel;
|
||||||
static uint32_t audio_dma_channel;
|
static uint32_t audio_dma_channel;
|
||||||
|
@ -122,19 +118,6 @@ namespace pimoroni {
|
||||||
// Tear down the old GU instance's hardware resources
|
// Tear down the old GU instance's hardware resources
|
||||||
partial_teardown();
|
partial_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// create 14-bit gamma luts
|
|
||||||
for(uint16_t v = 0; v < 256; v++) {
|
|
||||||
// gamma correct the provided 0-255 brightness value onto a
|
|
||||||
// 0-65535 range for the pwm counter
|
|
||||||
float r_gamma = 1.8f;
|
|
||||||
r_gamma_lut[v] = (uint16_t)(powf((float)(v) / 255.0f, r_gamma) * (float(1U << (BCD_FRAME_COUNT)) - 1.0f) + 0.5f);
|
|
||||||
float g_gamma = 1.8f;
|
|
||||||
g_gamma_lut[v] = (uint16_t)(powf((float)(v) / 255.0f, g_gamma) * (float(1U << (BCD_FRAME_COUNT)) - 1.0f) + 0.5f);
|
|
||||||
float b_gamma = 1.8f;
|
|
||||||
b_gamma_lut[v] = (uint16_t)(powf((float)(v) / 255.0f, b_gamma) * (float(1U << (BCD_FRAME_COUNT)) - 1.0f) + 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
// for each row:
|
// for each row:
|
||||||
// for each bcd frame:
|
// for each bcd frame:
|
||||||
|
@ -476,9 +459,9 @@ namespace pimoroni {
|
||||||
g = (g * this->brightness) >> 8;
|
g = (g * this->brightness) >> 8;
|
||||||
b = (b * this->brightness) >> 8;
|
b = (b * this->brightness) >> 8;
|
||||||
|
|
||||||
uint16_t gamma_r = r_gamma_lut[r];
|
uint16_t gamma_r = GAMMA_14BIT[r];
|
||||||
uint16_t gamma_g = g_gamma_lut[g];
|
uint16_t gamma_g = GAMMA_14BIT[g];
|
||||||
uint16_t gamma_b = b_gamma_lut[b];
|
uint16_t gamma_b = GAMMA_14BIT[b];
|
||||||
|
|
||||||
// for each row:
|
// for each row:
|
||||||
// for each bcd frame:
|
// for each bcd frame:
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "hardware/pio.h"
|
#include "hardware/pio.h"
|
||||||
#include "pico_graphics.hpp"
|
#include "pico_graphics.hpp"
|
||||||
|
#include "common/pimoroni_common.hpp"
|
||||||
#include "../pico_synth/pico_synth.hpp"
|
#include "../pico_synth/pico_synth.hpp"
|
||||||
|
|
||||||
namespace pimoroni {
|
namespace pimoroni {
|
||||||
|
|
|
@ -38,10 +38,6 @@
|
||||||
//
|
//
|
||||||
// .. and back to the start
|
// .. and back to the start
|
||||||
|
|
||||||
static uint16_t r_gamma_lut[256] = {0};
|
|
||||||
static uint16_t g_gamma_lut[256] = {0};
|
|
||||||
static uint16_t b_gamma_lut[256] = {0};
|
|
||||||
|
|
||||||
static uint32_t dma_channel;
|
static uint32_t dma_channel;
|
||||||
static uint32_t dma_ctrl_channel;
|
static uint32_t dma_ctrl_channel;
|
||||||
static uint32_t audio_dma_channel;
|
static uint32_t audio_dma_channel;
|
||||||
|
@ -122,19 +118,6 @@ namespace pimoroni {
|
||||||
// Tear down the old GU instance's hardware resources
|
// Tear down the old GU instance's hardware resources
|
||||||
partial_teardown();
|
partial_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// create 14-bit gamma luts
|
|
||||||
for(uint16_t v = 0; v < 256; v++) {
|
|
||||||
// gamma correct the provided 0-255 brightness value onto a
|
|
||||||
// 0-65535 range for the pwm counter
|
|
||||||
float r_gamma = 1.8f;
|
|
||||||
r_gamma_lut[v] = (uint16_t)(powf((float)(v) / 255.0f, r_gamma) * (float(1U << (BCD_FRAME_COUNT)) - 1.0f) + 0.5f);
|
|
||||||
float g_gamma = 1.8f;
|
|
||||||
g_gamma_lut[v] = (uint16_t)(powf((float)(v) / 255.0f, g_gamma) * (float(1U << (BCD_FRAME_COUNT)) - 1.0f) + 0.5f);
|
|
||||||
float b_gamma = 1.8f;
|
|
||||||
b_gamma_lut[v] = (uint16_t)(powf((float)(v) / 255.0f, b_gamma) * (float(1U << (BCD_FRAME_COUNT)) - 1.0f) + 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
// for each row:
|
// for each row:
|
||||||
// for each bcd frame:
|
// for each bcd frame:
|
||||||
|
@ -470,9 +453,9 @@ namespace pimoroni {
|
||||||
g = (g * this->brightness) >> 8;
|
g = (g * this->brightness) >> 8;
|
||||||
b = (b * this->brightness) >> 8;
|
b = (b * this->brightness) >> 8;
|
||||||
|
|
||||||
uint16_t gamma_r = r_gamma_lut[r];
|
uint16_t gamma_r = GAMMA_14BIT[r];
|
||||||
uint16_t gamma_g = g_gamma_lut[g];
|
uint16_t gamma_g = GAMMA_14BIT[g];
|
||||||
uint16_t gamma_b = b_gamma_lut[b];
|
uint16_t gamma_b = GAMMA_14BIT[b];
|
||||||
|
|
||||||
// for each row:
|
// for each row:
|
||||||
// for each bcd frame:
|
// for each bcd frame:
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "hardware/pio.h"
|
#include "hardware/pio.h"
|
||||||
#include "pico_graphics.hpp"
|
#include "pico_graphics.hpp"
|
||||||
|
#include "common/pimoroni_common.hpp"
|
||||||
#include "../pico_synth/pico_synth.hpp"
|
#include "../pico_synth/pico_synth.hpp"
|
||||||
|
|
||||||
namespace pimoroni {
|
namespace pimoroni {
|
||||||
|
|
|
@ -38,10 +38,6 @@
|
||||||
//
|
//
|
||||||
// .. and back to the start
|
// .. and back to the start
|
||||||
|
|
||||||
static uint16_t r_gamma_lut[256] = {0};
|
|
||||||
static uint16_t g_gamma_lut[256] = {0};
|
|
||||||
static uint16_t b_gamma_lut[256] = {0};
|
|
||||||
|
|
||||||
static uint32_t dma_channel;
|
static uint32_t dma_channel;
|
||||||
static uint32_t dma_ctrl_channel;
|
static uint32_t dma_ctrl_channel;
|
||||||
static uint32_t audio_dma_channel;
|
static uint32_t audio_dma_channel;
|
||||||
|
@ -122,19 +118,6 @@ namespace pimoroni {
|
||||||
// Tear down the old GU instance's hardware resources
|
// Tear down the old GU instance's hardware resources
|
||||||
partial_teardown();
|
partial_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// create 14-bit gamma luts
|
|
||||||
for(uint16_t v = 0; v < 256; v++) {
|
|
||||||
// gamma correct the provided 0-255 brightness value onto a
|
|
||||||
// 0-65535 range for the pwm counter
|
|
||||||
float r_gamma = 1.8f;
|
|
||||||
r_gamma_lut[v] = (uint16_t)(powf((float)(v) / 255.0f, r_gamma) * (float(1U << (BCD_FRAME_COUNT)) - 1.0f) + 0.5f);
|
|
||||||
float g_gamma = 1.8f;
|
|
||||||
g_gamma_lut[v] = (uint16_t)(powf((float)(v) / 255.0f, g_gamma) * (float(1U << (BCD_FRAME_COUNT)) - 1.0f) + 0.5f);
|
|
||||||
float b_gamma = 1.8f;
|
|
||||||
b_gamma_lut[v] = (uint16_t)(powf((float)(v) / 255.0f, b_gamma) * (float(1U << (BCD_FRAME_COUNT)) - 1.0f) + 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
// for each row:
|
// for each row:
|
||||||
// for each bcd frame:
|
// for each bcd frame:
|
||||||
|
@ -467,9 +450,9 @@ namespace pimoroni {
|
||||||
g = (g * this->brightness) >> 8;
|
g = (g * this->brightness) >> 8;
|
||||||
b = (b * this->brightness) >> 8;
|
b = (b * this->brightness) >> 8;
|
||||||
|
|
||||||
uint16_t gamma_r = r_gamma_lut[r];
|
uint16_t gamma_r = GAMMA_14BIT[r];
|
||||||
uint16_t gamma_g = g_gamma_lut[g];
|
uint16_t gamma_g = GAMMA_14BIT[g];
|
||||||
uint16_t gamma_b = b_gamma_lut[b];
|
uint16_t gamma_b = GAMMA_14BIT[b];
|
||||||
|
|
||||||
// for each row:
|
// for each row:
|
||||||
// for each bcd frame:
|
// for each bcd frame:
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "hardware/pio.h"
|
#include "hardware/pio.h"
|
||||||
#include "pico_graphics.hpp"
|
#include "pico_graphics.hpp"
|
||||||
|
#include "common/pimoroni_common.hpp"
|
||||||
#include "../pico_synth/pico_synth.hpp"
|
#include "../pico_synth/pico_synth.hpp"
|
||||||
|
|
||||||
namespace pimoroni {
|
namespace pimoroni {
|
||||||
|
|
Ładowanie…
Reference in New Issue