From cc75a0ac498585371ec25faa405b7f88e3b4b247 Mon Sep 17 00:00:00 2001 From: PiezoU005F Date: Sun, 18 Feb 2018 21:58:10 -0800 Subject: [PATCH 1/3] Update iconfactory.py Allow saturation values of greater than 100, as there are legitimate reasons for super-saturating an image (for example, a background filled with icon_average could be made to show a more vibrant form of its color). --- dockbarx/iconfactory.py | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/dockbarx/iconfactory.py b/dockbarx/iconfactory.py index c0a97b0..918e7ab 100644 --- a/dockbarx/iconfactory.py +++ b/dockbarx/iconfactory.py @@ -697,28 +697,19 @@ def __command_transp_sat(self, surface, opacity="100", saturation="100"): alpha = self.__get_alpha(opacity) # Todo: Add error check for saturation sat = float(saturation) - if sat < 100: - im = self.__surface2pil(surface) - w, h = im.size - pixels = im.load() - for x in range(w): - for y in range(h): - r, g, b, a = pixels[x, y] - l = (r + g + b) / 3.0 * (100 - sat) / 100.0 - r = int(r * sat / 100.0 + l) - g = int(g * sat / 100.0 + l) - b = int(b * sat / 100.0 + l) - a = int(a * alpha) - pixels[x, y] = (r, g, b, a) - return self.__pil2surface(im) - else: - w = surface.get_width() - h = surface.get_height() - new = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h) - ctx = gtk.gdk.CairoContext(cairo.Context(new)) - ctx.set_source_surface(surface) - ctx.paint_with_alpha(alpha) - return new + im = self.__surface2pil(surface) + w, h = im.size + pixels = im.load() + for x in range(w): + for y in range(h): + r, g, b, a = pixels[x, y] + l = (r + g + b) / 3.0 * (100 - sat) / 100.0 + r = int(r * sat / 100.0 + l) + g = int(g * sat / 100.0 + l) + b = int(b * sat / 100.0 + l) + a = int(a * alpha) + pixels[x, y] = (r, g, b, a) + return self.__pil2surface(im) def __command_composite(self, surface, bg, fg, opacity="100", From 6a32da2658e56d9d300a7232277766492f28d6b2 Mon Sep 17 00:00:00 2001 From: PiezoU005F Date: Sun, 18 Feb 2018 22:16:41 -0800 Subject: [PATCH 2/3] Realized you did some optimization there... Used "!=" instead of deleting the whole if-statement. ..Sorry. --- dockbarx/iconfactory.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/dockbarx/iconfactory.py b/dockbarx/iconfactory.py index 918e7ab..1e8b5b4 100644 --- a/dockbarx/iconfactory.py +++ b/dockbarx/iconfactory.py @@ -697,19 +697,28 @@ def __command_transp_sat(self, surface, opacity="100", saturation="100"): alpha = self.__get_alpha(opacity) # Todo: Add error check for saturation sat = float(saturation) - im = self.__surface2pil(surface) - w, h = im.size - pixels = im.load() - for x in range(w): - for y in range(h): - r, g, b, a = pixels[x, y] - l = (r + g + b) / 3.0 * (100 - sat) / 100.0 - r = int(r * sat / 100.0 + l) - g = int(g * sat / 100.0 + l) - b = int(b * sat / 100.0 + l) - a = int(a * alpha) - pixels[x, y] = (r, g, b, a) - return self.__pil2surface(im) + if sat != 100: +- im = self.__surface2pil(surface) +- w, h = im.size +- pixels = im.load() +- for x in range(w): +- for y in range(h): +- r, g, b, a = pixels[x, y] +- l = (r + g + b) / 3.0 * (100 - sat) / 100.0 +- r = int(r * sat / 100.0 + l) +- g = int(g * sat / 100.0 + l) +- b = int(b * sat / 100.0 + l) +- a = int(a * alpha) +- pixels[x, y] = (r, g, b, a) +- return self.__pil2surface(im) +- else: +- w = surface.get_width() +- h = surface.get_height() +- new = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h) +- ctx = gtk.gdk.CairoContext(cairo.Context(new)) +- ctx.set_source_surface(surface) +- ctx.paint_with_alpha(alpha) +- return new def __command_composite(self, surface, bg, fg, opacity="100", From 904af11e5ab850955dc12b8e7346731f92959185 Mon Sep 17 00:00:00 2001 From: Piezo_ Date: Mon, 19 Feb 2018 14:32:28 -0800 Subject: [PATCH 3/3] I messed up the formatting. Whoops. --- dockbarx/iconfactory.py | 42 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/dockbarx/iconfactory.py b/dockbarx/iconfactory.py index 1e8b5b4..d471e18 100644 --- a/dockbarx/iconfactory.py +++ b/dockbarx/iconfactory.py @@ -698,27 +698,27 @@ def __command_transp_sat(self, surface, opacity="100", saturation="100"): # Todo: Add error check for saturation sat = float(saturation) if sat != 100: -- im = self.__surface2pil(surface) -- w, h = im.size -- pixels = im.load() -- for x in range(w): -- for y in range(h): -- r, g, b, a = pixels[x, y] -- l = (r + g + b) / 3.0 * (100 - sat) / 100.0 -- r = int(r * sat / 100.0 + l) -- g = int(g * sat / 100.0 + l) -- b = int(b * sat / 100.0 + l) -- a = int(a * alpha) -- pixels[x, y] = (r, g, b, a) -- return self.__pil2surface(im) -- else: -- w = surface.get_width() -- h = surface.get_height() -- new = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h) -- ctx = gtk.gdk.CairoContext(cairo.Context(new)) -- ctx.set_source_surface(surface) -- ctx.paint_with_alpha(alpha) -- return new + im = self.__surface2pil(surface) + w, h = im.size + pixels = im.load() + for x in range(w): + for y in range(h): + r, g, b, a = pixels[x, y] + l = (r + g + b) / 3.0 * (100 - sat) / 100.0 + r = int(r * sat / 100.0 + l) + g = int(g * sat / 100.0 + l) + b = int(b * sat / 100.0 + l) + a = int(a * alpha) + pixels[x, y] = (r, g, b, a) + return self.__pil2surface(im) + else: + w = surface.get_width() + h = surface.get_height() + new = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h) + ctx = gtk.gdk.CairoContext(cairo.Context(new)) + ctx.set_source_surface(surface) + ctx.paint_with_alpha(alpha) + return new def __command_composite(self, surface, bg, fg, opacity="100",