MCPcopy Create free account
hub / github.com/RobTillaart/Arduino / setGamma

Method setGamma

libraries/GAMMA/gamma.cpp:48–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46
47
48bool GAMMA::setGamma(float gamma)
49{
50 if (_table == NULL) return false;
51 if (gamma <= 0) return false;
52 if (_gamma != gamma)
53 {
54 yield(); // try to keep ESP happy
55 _gamma = gamma;
56#if defined(ESP32)
57 // confirmed faster for ESP32.
58 float tmp = log(_interval / 255.0);
59 for (uint16_t i = 1; i < _size; i++)
60 {
61 float x = log(i) + tmp;
62 _table[i] = exp(x * _gamma) * 255 + 0.444;
63 }
64#else
65 // REFERENCE
66 // rounding factor 0.444 optimized with error example.
67 float tmp = (_interval / 255.0);
68 for (uint16_t i = 1; i < _size; i++)
69 {
70 _table[i] = pow(i * tmp, _gamma) * 255 + 0.444;
71 }
72#endif
73 _table[0] = 0;
74 _table[_size] = 255; // anchor for interpolation.
75 }
76 return true;
77};
78
79
80float GAMMA::getGamma()

Callers 1

unittestFunction · 0.80

Calls

no outgoing calls

Tested by 1

unittestFunction · 0.64