diff options
author | Mavridis Philippe <mavridisf@gmail.com> | 2024-11-24 20:47:11 +0200 |
---|---|---|
committer | Mavridis Philippe <mavridisf@gmail.com> | 2024-12-05 11:22:47 +0200 |
commit | 2766540313b901cbf9384863f61f50460e833d3c (patch) | |
tree | 2eeadb8f834a0723ff779e47f688ea44aff6c976 | |
parent | fa29eceb5f8cb1e8c105cf1a5e9e22fcc2b38cbd (diff) | |
download | tdelibs-2766540313b901cbf9384863f61f50460e833d3c.tar.gz tdelibs-2766540313b901cbf9384863f61f50460e833d3c.zip |
libtderandr: update gamma setting code
This fixes TDE/tdebase#163.
Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
(cherry picked from commit 61b9e1c9019822a6e4bfcbfbded46c48c4d4446d)
-rw-r--r-- | tderandr/libtderandr.cpp | 33 |
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); |