| 46 | |
| 47 | |
| 48 | bool 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 | |
| 80 | float GAMMA::getGamma() |