From 6391ef85bec64ea539e50f4f0b826e431b24039d Mon Sep 17 00:00:00 2001 From: Francois Andriot Date: Fri, 24 May 2013 01:37:29 +0200 Subject: Fix saving display config when Gamma is not supported by xrandr This resolves Bug 1506 (cherry picked from commit 90c0f26c7c977c52e78246db83906807e0a109f5) --- krandr/libkrandr.cc | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/krandr/libkrandr.cc b/krandr/libkrandr.cc index 06a242101..01aeb7d3f 100644 --- a/krandr/libkrandr.cc +++ b/krandr/libkrandr.cc @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -624,7 +625,16 @@ bool KRandrSimpleAPI::applySystemwideDisplayConfiguration(TQPtrList KRandrSimpleAPI::readCurrentDisplayConfiguration() { // It may not always be 100% correct, or even anywhere close... // Essentially it "undoes" the LUT gamma calculation from xrandr // lut_gamma->green[i] = (pow(i/(size - 1), desired_gamma.green) * (size - 1) * 256); + screendata->gamma_red = 2.2; + screendata->gamma_green = 2.2; + screendata->gamma_blue = 2.2; if (current_crtc) { //int slot = 127; int slot = 7; int size = XRRGetCrtcGammaSize(randr_display, current_crtc->id); - XRRCrtcGamma *gammastruct = XRRGetCrtcGamma (randr_display, current_crtc->id); - screendata->gamma_red = log(gammastruct->red[slot]/((size-1.0)*256.0))/log(slot/(size-1.0)); - screendata->gamma_green = log(gammastruct->green[slot]/((size-1.0)*256.0))/log(slot/(size-1.0)); - screendata->gamma_blue = log(gammastruct->blue[slot]/((size-1.0)*256.0))/log(slot/(size-1.0)); - } - else { - screendata->gamma_red = 2.2; - screendata->gamma_green = 2.2; - screendata->gamma_blue = 2.2; + if(size>0) { + XRRCrtcGamma *gammastruct = XRRGetCrtcGamma (randr_display, current_crtc->id); + screendata->gamma_red = log(gammastruct->red[slot]/((size-1.0)*256.0))/log(slot/(size-1.0)); + screendata->gamma_green = log(gammastruct->green[slot]/((size-1.0)*256.0))/log(slot/(size-1.0)); + screendata->gamma_blue = log(gammastruct->blue[slot]/((size-1.0)*256.0))/log(slot/(size-1.0)); + } } // Round off the gamma to one decimal place screendata->gamma_red = floorf(screendata->gamma_red * 10 + 0.5) / 10; -- cgit v1.2.1