From d521ef5d7e429f3367853d2c3de65862b798b387 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Fri, 29 Nov 2024 17:07:30 +0900 Subject: tderandrtray: prevent division-by-zero corner case Signed-off-by: Michele Calgaro --- tderandr/libtderandr.cpp | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) (limited to 'tderandr') 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 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 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)); -- cgit v1.2.1