From b608cd59604e0a0370c5e2625c43518d6314f410 Mon Sep 17 00:00:00 2001 From: o9000 Date: Mon, 21 Mar 2016 23:01:43 +0100 Subject: [PATCH] Use a better algorithm for brightness adjustment --- src/util/common.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/util/common.c b/src/util/common.c index 997d959..6d036e6 100644 --- a/src/util/common.c +++ b/src/util/common.c @@ -241,7 +241,8 @@ void extract_values(const char *value, char **value1, char **value2, char **valu void adjust_asb(DATA32 *data, int w, int h, int alpha, float satur, float bright) { unsigned int x, y; - unsigned int a, r, g, b, argb; + unsigned int argb; + int a, r, g, b; unsigned long id; int cmax, cmin; float h2, f, p, q, t; @@ -294,7 +295,7 @@ void adjust_asb(DATA32 *data, int w, int h, int alpha, float satur, float bright saturation = 0.0; if (saturation > 1.0) saturation = 1.0; - brightness += bright; + //brightness += bright; if (brightness < 0.0) brightness = 0.0; if (brightness > 1.0) @@ -345,6 +346,14 @@ void adjust_asb(DATA32 *data, int w, int h, int alpha, float satur, float bright } } + r += bright * 255; + g += bright * 255; + b += bright * 255; + + r = MAX(0, MIN(255, r)); + g = MAX(0, MIN(255, g)); + b = MAX(0, MIN(255, b)); + argb = a; argb = (argb << 8) + r; argb = (argb << 8) + g; @@ -503,8 +512,8 @@ Imlib_Image adjust_icon(Imlib_Image original, int alpha, int saturation, int bri imlib_image_get_width(), imlib_image_get_height(), alpha, - (float)saturation / 100, - (float)brightness / 100); + saturation / 100.0, + brightness / 100.0); imlib_image_put_back_data(data); return copy; }