Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
9fd88196 by Philipp Hörist at 2019-06-11T22:03:02Z
ConsistentColors: Adjust for background
- Rename method
- add LRU maxsize
- - - - -
1 changed file:
- nbxmpp/util.py
Changes:
=====================================
nbxmpp/util.py
=====================================
@@ -233,11 +233,23 @@ def clip_rgb(red, green, blue):
)
-@lru_cache()
-def text_to_colour(text):
+@lru_cache(maxsize=1024)
+def text_to_color(text, background_color):
+ # background color = (rb, gb, bb)
hash_ = hashlib.sha1()
hash_.update(text.encode())
- hue = (int.from_bytes(hash_.digest()[:2], 'little') & 0xffff) / 0xffff
+ hue = int.from_bytes(hash_.digest()[:2], 'little') / 65536
red, green, blue = clip_rgb(*hsluv_to_rgb((hue * 360, 100, 50)))
- return red * 0.8, green * 0.8, blue * 0.8
+
+ rb, gb, bb = background_color
+
+ rb_inv = 1 - rb
+ gb_inv = 1 - gb
+ bb_inv = 1 - bb
+
+ rc = 0.2 * rb_inv + 0.8 * red
+ gc = 0.2 * gb_inv + 0.8 * green
+ bc = 0.2 * bb_inv + 0.8 * blue
+
+ return rc, gc, bc
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/commit/9fd88196a947d24149927952f5e2ada80ad81225
--
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/commit/9fd88196a947d24149927952f5e2ada80ad81225
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits