FastLED 3.10.6
Loading...
Searching...
No Matches
transfer.cpp.hpp
Go to the documentation of this file.
1// ok no header - implementation for fl/gfx/transfer.h
2
3#include "fl/gfx/transfer.h"
4
5#include "fastled_progmem.h"
6#include "fl/stl/align.h"
7
8namespace fl {
9
10// Inverse sRGB transfer, 8-bit code -> u16 linear.
11// Generated by: round(f(i / 255.0) * 65535.0) for i in 0..255, where
12// f(n) = n / 12.92 if n <= 0.04045
13// = ((n + 0.055) / 1.055) ** 2.4 otherwise
14// This is the piecewise sRGB function, not the BT.709 OETF -- the spec keeps
15// them distinct, and the two differ by more than a rounding step at low codes
16// (code 1 decodes to 20 here and 57 under BT.709). Matches the P5 float64
17// reference `ci/color_reference.py::decode_rgb8` by construction; a Python
18// test regenerates this table and fails on any drift.
19FL_ALIGN_PROGMEM(64) const u16 SRGB_DECODE_LUT[256] FL_PROGMEM = {
20 0, 20, 40, 60, 80, 99, 119, 139, 159, 179,
21 199, 219, 241, 264, 288, 313, 340, 367, 396, 427,
22 458, 491, 526, 562, 599, 637, 677, 718, 761, 805,
23 851, 898, 947, 997, 1048, 1101, 1156, 1212, 1270, 1330,
24 1391, 1453, 1517, 1583, 1651, 1720, 1790, 1863, 1937, 2013,
25 2090, 2170, 2250, 2333, 2418, 2504, 2592, 2681, 2773, 2866,
26 2961, 3058, 3157, 3258, 3360, 3464, 3570, 3678, 3788, 3900,
27 4014, 4129, 4247, 4366, 4488, 4611, 4736, 4864, 4993, 5124,
28 5257, 5392, 5530, 5669, 5810, 5953, 6099, 6246, 6395, 6547,
29 6700, 6856, 7014, 7174, 7335, 7500, 7666, 7834, 8004, 8177,
30 8352, 8528, 8708, 8889, 9072, 9258, 9445, 9635, 9828, 10022,
31 10219, 10417, 10619, 10822, 11028, 11235, 11446, 11658, 11873, 12090,
32 12309, 12530, 12754, 12980, 13209, 13440, 13673, 13909, 14146, 14387,
33 14629, 14874, 15122, 15371, 15623, 15878, 16135, 16394, 16656, 16920,
34 17187, 17456, 17727, 18001, 18277, 18556, 18837, 19121, 19407, 19696,
35 19987, 20281, 20577, 20876, 21177, 21481, 21787, 22096, 22407, 22721,
36 23038, 23357, 23678, 24002, 24329, 24658, 24990, 25325, 25662, 26001,
37 26344, 26688, 27036, 27386, 27739, 28094, 28452, 28813, 29176, 29542,
38 29911, 30282, 30656, 31033, 31412, 31794, 32179, 32567, 32957, 33350,
39 33745, 34143, 34544, 34948, 35355, 35764, 36176, 36591, 37008, 37429,
40 37852, 38278, 38706, 39138, 39572, 40009, 40449, 40891, 41337, 41785,
41 42236, 42690, 43147, 43606, 44069, 44534, 45002, 45473, 45947, 46423,
42 46903, 47385, 47871, 48359, 48850, 49344, 49841, 50341, 50844, 51349,
43 51858, 52369, 52884, 53401, 53921, 54445, 54971, 55500, 56032, 56567,
44 57105, 57646, 58190, 58737, 59287, 59840, 60396, 60955, 61517, 62082,
45 62650, 63221, 63795, 64372, 64952, 65535};
46
47// Inverse BT.709 transfer, 8-bit code -> u16 linear.
48// Generated by: round(f(i / 255.0) * 65535.0) for i in 0..255, where
49// f(n) = n / 4.5 if n < 0.081
50// = ((n + 0.099) / 1.099) ** (1 / 0.45) otherwise
51FL_ALIGN_PROGMEM(64) const u16 BT709_DECODE_LUT[256] FL_PROGMEM = {
52 0, 57, 114, 171, 228, 286, 343, 400, 457, 514,
53 571, 628, 685, 742, 800, 857, 914, 971, 1028, 1085,
54 1142, 1196, 1254, 1314, 1375, 1438, 1502, 1568, 1636, 1705,
55 1775, 1847, 1921, 1997, 2074, 2152, 2232, 2314, 2398, 2483,
56 2569, 2658, 2748, 2839, 2933, 3028, 3124, 3222, 3322, 3424,
57 3527, 3632, 3739, 3848, 3958, 4069, 4183, 4298, 4415, 4534,
58 4655, 4777, 4901, 5026, 5154, 5283, 5414, 5547, 5681, 5818,
59 5956, 6095, 6237, 6381, 6526, 6673, 6822, 6972, 7125, 7279,
60 7435, 7593, 7753, 7914, 8078, 8243, 8410, 8579, 8750, 8922,
61 9097, 9273, 9451, 9631, 9813, 9997, 10183, 10370, 10560, 10751,
62 10944, 11139, 11337, 11535, 11736, 11939, 12144, 12350, 12559, 12769,
63 12982, 13196, 13412, 13630, 13850, 14072, 14296, 14522, 14750, 14980,
64 15211, 15445, 15681, 15918, 16158, 16400, 16643, 16889, 17136, 17386,
65 17637, 17891, 18146, 18403, 18663, 18924, 19188, 19453, 19721, 19990,
66 20262, 20535, 20811, 21088, 21368, 21649, 21933, 22219, 22506, 22796,
67 23088, 23381, 23677, 23975, 24275, 24577, 24881, 25187, 25495, 25806,
68 26118, 26432, 26749, 27067, 27388, 27710, 28035, 28362, 28691, 29022,
69 29355, 29690, 30027, 30366, 30708, 31051, 31397, 31745, 32095, 32447,
70 32801, 33157, 33515, 33876, 34238, 34603, 34970, 35339, 35710, 36083,
71 36458, 36836, 37215, 37597, 37981, 38367, 38755, 39146, 39538, 39933,
72 40329, 40728, 41130, 41533, 41938, 42346, 42756, 43168, 43582, 43998,
73 44417, 44837, 45260, 45685, 46112, 46542, 46973, 47407, 47843, 48281,
74 48722, 49164, 49609, 50056, 50505, 50957, 51410, 51866, 52324, 52784,
75 53247, 53712, 54178, 54648, 55119, 55593, 56068, 56546, 57027, 57509,
76 57994, 58481, 58970, 59462, 59955, 60451, 60950, 61450, 61953, 62458,
77 62965, 63474, 63986, 64500, 65016, 65535};
78
80 switch (transfer) {
82 return FL_PGM_READ_WORD_ALIGNED(&SRGB_DECODE_LUT[code]);
84 return FL_PGM_READ_WORD_ALIGNED(&BT709_DECODE_LUT[code]);
86 break;
87 }
88 // Linear needs no table: 257 maps 0..255 onto 0..65535 exactly, so 0 and
89 // 255 land on the endpoints without a rounding step.
90 return static_cast<u16>(static_cast<u32>(code) * 257u);
91}
92
93} // namespace fl
Alignment macros and utilities for FastLED.
#define FL_ALIGN_PROGMEM(N)
Force N-byte alignment for platforms with unaligned access or cache-line optimization.
#define FL_PGM_READ_WORD_ALIGNED(addr)
Wrapper definitions to allow seamless use of PROGMEM in environments that have it.
#define FL_PROGMEM
PROGMEM keyword for storage.
unsigned char u8
Definition stdint.h:131
TransferFunction
InputGamut g FL_NO_EXCEPT
Definition rgbw.h:121
u16 decodeTransferU16(TransferFunction transfer, u8 code) FL_NO_EXCEPT
Decode one 8-bit source code to u16 linear light under transfer.
Base definition for an LED controller.
Definition crgb.hpp:179