Changeset View
Changeset View
Standalone View
Standalone View
colorcorrection/manager.cpp
Show All 14 Lines | |||||
15 | GNU General Public License for more details. | 15 | GNU General Public License for more details. | ||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "manager.h" | 20 | #include "manager.h" | ||
21 | #include "colorcorrectdbusinterface.h" | 21 | #include "colorcorrectdbusinterface.h" | ||
22 | #include "suncalc.h" | 22 | #include "suncalc.h" | ||
23 | #include "gammaramp.h" | | |||
24 | #include <colorcorrect_logging.h> | 23 | #include <colorcorrect_logging.h> | ||
25 | 24 | | |||
26 | #include <main.h> | 25 | #include <main.h> | ||
27 | #include <platform.h> | 26 | #include <platform.h> | ||
28 | #include <abstract_output.h> | 27 | #include <abstract_output.h> | ||
29 | #include <screens.h> | 28 | #include <screens.h> | ||
30 | #include <workspace.h> | 29 | #include <workspace.h> | ||
31 | #include <logind.h> | 30 | #include <logind.h> | ||
▲ Show 20 Lines • Show All 476 Lines • ▼ Show 20 Line(s) | 483 | { | |||
508 | } | 507 | } | ||
509 | } | 508 | } | ||
510 | 509 | | |||
511 | void Manager::commitGammaRamps(int temperature) | 510 | void Manager::commitGammaRamps(int temperature) | ||
512 | { | 511 | { | ||
513 | const auto outs = kwinApp()->platform()->outputs(); | 512 | const auto outs = kwinApp()->platform()->outputs(); | ||
514 | 513 | | |||
515 | for (auto *o : outs) { | 514 | for (auto *o : outs) { | ||
516 | int rampsize = o->getGammaRampSize(); | 515 | int rampsize = o->gammaRampSize(); | ||
517 | GammaRamp ramp(rampsize); | 516 | GammaRamp ramp(rampsize); | ||
518 | 517 | | |||
519 | /* | 518 | /* | ||
520 | * The gamma calculation below is based on the Redshift app: | 519 | * The gamma calculation below is based on the Redshift app: | ||
521 | * https://github.com/jonls/redshift | 520 | * https://github.com/jonls/redshift | ||
522 | */ | 521 | */ | ||
522 | uint16_t *red = ramp.red(); | ||||
523 | uint16_t *green = ramp.green(); | ||||
524 | uint16_t *blue = ramp.blue(); | ||||
523 | 525 | | |||
524 | // linear default state | 526 | // linear default state | ||
525 | for (int i = 0; i < rampsize; i++) { | 527 | for (int i = 0; i < rampsize; i++) { | ||
526 | uint16_t value = (double)i / rampsize * (UINT16_MAX + 1); | 528 | uint16_t value = (double)i / rampsize * (UINT16_MAX + 1); | ||
527 | ramp.red[i] = value; | 529 | red[i] = value; | ||
528 | ramp.green[i] = value; | 530 | green[i] = value; | ||
529 | ramp.blue[i] = value; | 531 | blue[i] = value; | ||
530 | } | 532 | } | ||
531 | 533 | | |||
532 | // approximate white point | 534 | // approximate white point | ||
533 | float whitePoint[3]; | 535 | float whitePoint[3]; | ||
534 | float alpha = (temperature % 100) / 100.; | 536 | float alpha = (temperature % 100) / 100.; | ||
535 | int bbCIndex = ((temperature - 1000) / 100) * 3; | 537 | int bbCIndex = ((temperature - 1000) / 100) * 3; | ||
536 | whitePoint[0] = (1. - alpha) * blackbodyColor[bbCIndex] + alpha * blackbodyColor[bbCIndex + 3]; | 538 | whitePoint[0] = (1. - alpha) * blackbodyColor[bbCIndex] + alpha * blackbodyColor[bbCIndex + 3]; | ||
537 | whitePoint[1] = (1. - alpha) * blackbodyColor[bbCIndex + 1] + alpha * blackbodyColor[bbCIndex + 4]; | 539 | whitePoint[1] = (1. - alpha) * blackbodyColor[bbCIndex + 1] + alpha * blackbodyColor[bbCIndex + 4]; | ||
538 | whitePoint[2] = (1. - alpha) * blackbodyColor[bbCIndex + 2] + alpha * blackbodyColor[bbCIndex + 5]; | 540 | whitePoint[2] = (1. - alpha) * blackbodyColor[bbCIndex + 2] + alpha * blackbodyColor[bbCIndex + 5]; | ||
539 | 541 | | |||
540 | for (int i = 0; i < rampsize; i++) { | 542 | for (int i = 0; i < rampsize; i++) { | ||
541 | ramp.red[i] = (double)ramp.red[i] / (UINT16_MAX+1) * whitePoint[0] * (UINT16_MAX+1); | 543 | red[i] = qreal(red[i]) / (UINT16_MAX+1) * whitePoint[0] * (UINT16_MAX+1); | ||
542 | ramp.green[i] = (double)ramp.green[i] / (UINT16_MAX+1) * whitePoint[1] * (UINT16_MAX+1); | 544 | green[i] = qreal(green[i]) / (UINT16_MAX+1) * whitePoint[1] * (UINT16_MAX+1); | ||
543 | ramp.blue[i] = (double)ramp.blue[i] / (UINT16_MAX+1) * whitePoint[2] * (UINT16_MAX+1); | 545 | blue[i] = qreal(blue[i]) / (UINT16_MAX+1) * whitePoint[2] * (UINT16_MAX+1); | ||
544 | } | 546 | } | ||
545 | 547 | | |||
546 | if (o->setGammaRamp(ramp)) { | 548 | if (o->setGammaRamp(ramp)) { | ||
547 | m_currentTemp = temperature; | 549 | m_currentTemp = temperature; | ||
548 | m_failedCommitAttempts = 0; | 550 | m_failedCommitAttempts = 0; | ||
549 | } else { | 551 | } else { | ||
550 | m_failedCommitAttempts++; | 552 | m_failedCommitAttempts++; | ||
551 | if (m_failedCommitAttempts < 10) { | 553 | if (m_failedCommitAttempts < 10) { | ||
▲ Show 20 Lines • Show All 228 Lines • Show Last 20 Lines |