[meld] Fix icon colour tinting, and add luminance adjustments



commit 087dab6a586e91094408b1f4bd9aa67c1d64255a
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Jan 7 08:02:01 2012 +1000

    Fix icon colour tinting, and add luminance adjustments
    
    This commit fixes a bug where we didn't convert integer RGB values to
    Cairo floats before setting colours, and also introduces an adjustment
    for the perceived brightness of a tint colour. When adding a tint to an
    icon, we get very different resulting brightness depending on what tint
    colour was added. This adds some simple heuristics to try and determine
    the perceived luminance of the tint, and adjusts accordingly.

 meld/ui/emblemcellrenderer.py |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/meld/ui/emblemcellrenderer.py b/meld/ui/emblemcellrenderer.py
index 079ea7d..051dedb 100644
--- a/meld/ui/emblemcellrenderer.py
+++ b/meld/ui/emblemcellrenderer.py
@@ -91,7 +91,14 @@ class EmblemCellRenderer(gtk.GenericCellRenderer):
 
             if self._tint_color:
                 c = self._tint_color
-                context.set_source_rgba(c.red, c.green, c.blue, 0.2)
+                r, g, b = [x / 65535. for x in (c.red, c.green, c.blue)]
+                # Figure out the difference between our tint colour and an
+                # empirically determined (i.e., guessed) satisfying luma and
+                # adjust the base colours accordingly
+                luma = (r + r + b + g + g + g) / 6.
+                extra_luma = (1.2 - luma) / 3.
+                r, g, b = [min(x + extra_luma, 1.) for x in r, g, b]
+                context.set_source_rgba(r, g, b, 0.4)
                 context.set_operator(cairo.OPERATOR_ATOP)
                 context.paint()
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]