@@ -497,46 +497,19 @@ uint32_t BusPwm::getPixelColor(uint16_t pix) {
497497 return RGBW32 (_data[0 ], _data[0 ], _data[0 ], _data[0 ]);
498498}
499499
500- #ifndef ESP8266
501- static const uint16_t cieLUT[256 ] = {
502- 0 , 2 , 4 , 5 , 7 , 9 , 11 , 13 , 15 , 16 ,
503- 18 , 20 , 22 , 24 , 26 , 27 , 29 , 31 , 33 , 35 ,
504- 34 , 36 , 37 , 39 , 41 , 43 , 45 , 47 , 49 , 52 ,
505- 54 , 56 , 59 , 61 , 64 , 67 , 69 , 72 , 75 , 78 ,
506- 81 , 84 , 87 , 90 , 94 , 97 , 100 , 104 , 108 , 111 ,
507- 115 , 119 , 123 , 127 , 131 , 136 , 140 , 144 , 149 , 154 ,
508- 158 , 163 , 168 , 173 , 178 , 183 , 189 , 194 , 200 , 205 ,
509- 211 , 217 , 223 , 229 , 235 , 241 , 247 , 254 , 261 , 267 ,
510- 274 , 281 , 288 , 295 , 302 , 310 , 317 , 325 , 333 , 341 ,
511- 349 , 357 , 365 , 373 , 382 , 391 , 399 , 408 , 417 , 426 ,
512- 436 , 445 , 455 , 464 , 474 , 484 , 494 , 505 , 515 , 526 ,
513- 536 , 547 , 558 , 569 , 580 , 592 , 603 , 615 , 627 , 639 ,
514- 651 , 663 , 676 , 689 , 701 , 714 , 727 , 741 , 754 , 768 ,
515- 781 , 795 , 809 , 824 , 838 , 853 , 867 , 882 , 897 , 913 ,
516- 928 , 943 , 959 , 975 , 991 , 1008 , 1024 , 1041 , 1058 , 1075 ,
517- 1092 , 1109 , 1127 , 1144 , 1162 , 1180 , 1199 , 1217 , 1236 , 1255 ,
518- 1274 , 1293 , 1312 , 1332 , 1352 , 1372 , 1392 , 1412 , 1433 , 1454 ,
519- 1475 , 1496 , 1517 , 1539 , 1561 , 1583 , 1605 , 1628 , 1650 , 1673 ,
520- 1696 , 1719 , 1743 , 1767 , 1791 , 1815 , 1839 , 1864 , 1888 , 1913 ,
521- 1939 , 1964 , 1990 , 2016 , 2042 , 2068 , 2095 , 2121 , 2148 , 2176 ,
522- 2203 , 2231 , 2259 , 2287 , 2315 , 2344 , 2373 , 2402 , 2431 , 2461 ,
523- 2491 , 2521 , 2551 , 2581 , 2612 , 2643 , 2675 , 2706 , 2738 , 2770 ,
524- 2802 , 2835 , 2867 , 2900 , 2934 , 2967 , 3001 , 3035 , 3069 , 3104 ,
525- 3138 , 3174 , 3209 , 3244 , 3280 , 3316 , 3353 , 3389 , 3426 , 3463 ,
526- 3501 , 3539 , 3576 , 3615 , 3653 , 3692 , 3731 , 3770 , 3810 , 3850 ,
527- 3890 , 3930 , 3971 , 4012 , 4053 , 4095
528- };
529- #endif
530-
531500void BusPwm::show () {
532501 if (!_valid) return ;
533502 unsigned numPins = NUM_PWM_PINS (_type);
534503 unsigned maxBri = (1 <<_depth) - 1 ;
535- #ifdef ESP8266
536- unsigned pwmBri = (unsigned )(roundf (powf ((float )_bri / 255 .0f , 1 .7f ) * (float )maxBri)); // using gamma 1.7 to extrapolate PWM duty cycle
537- #else
538- unsigned pwmBri = cieLUT[_bri] >> (12 - _depth); // use CIE LUT
539- #endif
504+ // use CIE brightness formula
505+ unsigned pwmBri = (unsigned )_bri * 100 ;
506+ if (pwmBri < 2040 ) pwmBri = ((pwmBri << _depth) + 115043 ) / 230087 ; // adding '0.5' before division for correct rounding
507+ else {
508+ pwmBri += 4080 ;
509+ float temp = (float )pwmBri / 29580 ;
510+ temp = temp * temp * temp * (1 <<_depth) - 1 ;
511+ pwmBri = (unsigned )temp;
512+ }
540513 for (unsigned i = 0 ; i < numPins; i++) {
541514 unsigned scaled = (_data[i] * pwmBri) / 255 ;
542515 if (_reversed) scaled = maxBri - scaled;
0 commit comments