summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2024-11-29 17:07:30 +0900
committerMavridis Philippe <mavridisf@gmail.com>2024-12-05 11:22:49 +0200
commit226e5aa1552ce0a4207638cb492cc6498cbc7d80 (patch)
tree42fb019136f2bd6d6c53b8ae4f6617f263fcd4d5
parenta5b57afdd26d51873a8e87de2ba0e631d08ded99 (diff)
downloadtdelibs-226e5aa1552ce0a4207638cb492cc6498cbc7d80.tar.gz
tdelibs-226e5aa1552ce0a4207638cb492cc6498cbc7d80.zip
tderandrtray: prevent division-by-zero corner caser14.1.x
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it> (cherry picked from commit d521ef5d7e429f3367853d2c3de65862b798b387)
-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));