summaryrefslogtreecommitdiffstats
path: root/tderandr
diff options
context:
space:
mode:
Diffstat (limited to 'tderandr')
-rw-r--r--tderandr/libtderandr.cpp33
1 files changed, 25 insertions, 8 deletions
diff --git a/tderandr/libtderandr.cpp b/tderandr/libtderandr.cpp
index 50c7a1673..412ead858 100644
--- a/tderandr/libtderandr.cpp
+++ b/tderandr/libtderandr.cpp
@@ -31,6 +31,8 @@
#include <tdemessagebox.h>
#include <tdeapplication.h>
+#include <kdebug.h>
+
#include <stdlib.h>
#include <unistd.h>
#include <cmath>
@@ -1113,30 +1115,45 @@ void KRandrSimpleAPI::applyDisplayGamma(TQPtrList<SingleScreenData> screenInfoAr
if (!current_crtc) {
continue;
}
- // vvvvvvvvv This chunk of code is borrowed from xrandr vvvvvvvvvv
+ // vvvvvvvvv This chunk of code is based on code from the function set_gamma() of xrandr vvvvvvvvvv
int size = XRRGetCrtcGammaSize(randr_display, current_crtc->id);
- if (!size) {
+ if (!size || size > 65536) {
+ kdWarning() << "Gamma correction table has wrong size." << endl;
continue;
}
gamma = XRRAllocGamma(size);
if (!gamma) {
+ kdWarning() << "Gamma allocation failed." << endl;
continue;
}
for (i = 0; i < size; i++) {
if (screendata->gamma_red == 1.0)
- gamma->red[i] = i << 8;
+ {
+ gamma->red[i] = (double)i / (double)(size - 1) * 65530.0;
+ }
else
- gamma->red[i] = (pow((double)i/(double)(size-1), (double)screendata->gamma_red) * (double)(size-1)*256);
+ {
+ gamma->red[i] = fmin(pow((double)i / (double)(size - 1), screendata->gamma_red), 1.0) * 65530.0;
+ }
if (screendata->gamma_green == 1.0)
- gamma->green[i] = i << 8;
+ {
+ gamma->green[i] = (double)i / (double)(size - 1) * 65530.0;
+ }
else
- gamma->green[i] = (pow((double)i/(double)(size-1), (double)screendata->gamma_green) * (double)(size-1)*256);
+ {
+ gamma->green[i] = fmin(pow((double)i / (double)(size - 1), screendata->gamma_green), 1.0) * 65530.0;
+ }
if (screendata->gamma_blue == 1.0)
- gamma->blue[i] = i << 8;
+ {
+ gamma->blue[i] = (double)i / (double)(size - 1) * 65530.0;
+ }
else
- gamma->blue[i] = (pow((double)i/(double)(size-1), (double)screendata->gamma_blue) * (double)(size-1)*256);
+ {
+ gamma->blue[i] = fmin(pow((double)i / (double)(size - 1), screendata->gamma_blue), 1.0) * 65530.0;
+ }
+
}
XRRSetCrtcGamma(randr_display, current_crtc->id, gamma);
free(gamma);