summaryrefslogtreecommitdiffstats
path: root/tderandr
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2024-11-29 17:07:30 +0900
committerTDE Gitea <gitea@mirror.git.trinitydesktop.org>2024-12-05 09:20:41 +0000
commitd521ef5d7e429f3367853d2c3de65862b798b387 (patch)
treed257cf1b3a2a0874c4b5cc12f3823959685c94b9 /tderandr
parent96114858d884974d9c704f79fb7ba61a0d52ab21 (diff)
downloadtdelibs-d521ef5d7e429f3367853d2c3de65862b798b387.tar.gz
tdelibs-d521ef5d7e429f3367853d2c3de65862b798b387.zip
tderandrtray: prevent division-by-zero corner case
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'tderandr')
-rw-r--r--tderandr/libtderandr.cpp41
1 files changed, 15 insertions, 26 deletions
diff --git a/tderandr/libtderandr.cpp b/tderandr/libtderandr.cpp
index a0b8158ab..f510ca8ab 100644
--- a/tderandr/libtderandr.cpp
+++ b/tderandr/libtderandr.cpp
@@ -1126,31 +1126,15 @@ void KRandrSimpleAPI::applyDisplayGamma(TQPtrList<SingleScreenData> screenInfoAr
continue;
}
for (int j = 0; j < size; j++) {
- if (screendata->gamma_red == 1.0)
- {
- gamma->red[j] = (double)j / (double)(size - 1) * 65530.0;
+ if (size == 1) {
+ gamma->red[j] = 0.0;
+ gamma->green[j] = 0.0;
+ gamma->blue[j] = 0.0;
}
- else
- {
- gamma->red[j] = fmin(pow((double)j / (double)(size - 1), screendata->gamma_red), 1.0) * 65530.0;
- }
-
- if (screendata->gamma_green == 1.0)
- {
- gamma->green[j] = (double)j / (double)(size - 1) * 65530.0;
- }
- else
- {
- gamma->green[j] = fmin(pow((double)j / (double)(size - 1), screendata->gamma_green), 1.0) * 65530.0;
- }
-
- if (screendata->gamma_blue == 1.0)
- {
- gamma->blue[j] = (double)j / (double)(size - 1) * 65530.0;
- }
- else
- {
- gamma->blue[j] = fmin(pow((double)j / (double)(size - 1), screendata->gamma_blue), 1.0) * 65530.0;
+ else {
+ gamma->red[j] = fmin(pow((double)j / (double)(size - 1), screendata->gamma_red), 1.0) * 65535.0;
+ gamma->green[j] = fmin(pow((double)j / (double)(size - 1), screendata->gamma_green), 1.0) * 65535.0;
+ gamma->blue[j] = fmin(pow((double)j / (double)(size - 1), screendata->gamma_blue), 1.0) * 65535.0;
}
}
XRRSetCrtcGamma(randr_display, current_crtc->id, gamma);
@@ -1395,8 +1379,13 @@ TQPtrList<SingleScreenData> KRandrSimpleAPI::readCurrentDisplayConfiguration() {
//int slot = 127;
int slot = 7;
int size = XRRGetCrtcGammaSize(randr_display, current_crtc->id);
- if(size>0) {
- XRRCrtcGamma *gammastruct = XRRGetCrtcGamma (randr_display, current_crtc->id);
+ XRRCrtcGamma *gammastruct = XRRGetCrtcGamma (randr_display, current_crtc->id);
+ if (size == 1) {
+ screendata->gamma_red = 0.0;
+ screendata->gamma_green = 0.0;
+ screendata->gamma_blue = 0.0;
+ }
+ else if (size > 1) {
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));