summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMavridis Philippe <mavridisf@gmail.com>2024-11-24 20:47:11 +0200
committerTDE Gitea <gitea@mirror.git.trinitydesktop.org>2024-12-05 09:20:41 +0000
commit61b9e1c9019822a6e4bfcbfbded46c48c4d4446d (patch)
tree93af3e9661fd9f8e2fcac5b5fa0acc6a7a3cf773
parent027072b75993d23fd7ca2235ba575c4a6bb358f2 (diff)
downloadtdelibs-61b9e1c9019822a6e4bfcbfbded46c48c4d4446d.tar.gz
tdelibs-61b9e1c9019822a6e4bfcbfbded46c48c4d4446d.zip
libtderandr: update gamma setting code
This fixes TDE/tdebase#163. Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
-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);