From 2fc458479e289e5157864f3ed817bba179461e2d Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 22 Dec 2015 11:07:33 +0100 Subject: [Avatars] Calculate 'sane' hue precissions We used to get the numeric value of the entrire md5 string which is a 128bit integer. We would then devide this by the maxval of a 128bit int. There is no need for such huge computations. As we just require a value between 0 and 255. Thus using two 16 bit values is more than enough to get the precision we need. By just taking the MSB we get nearly identical results. --- core/js/placeholder.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/js/placeholder.js b/core/js/placeholder.js index 26eb3507d7b..5fb5b5b8f80 100644 --- a/core/js/placeholder.js +++ b/core/js/placeholder.js @@ -51,8 +51,8 @@ // set optional argument "text" to value of "seed" if undefined text = text || seed; - var hash = md5(seed), - maxRange = parseInt('ffffffffffffffffffffffffffffffff', 16), + var hash = md5(seed).substring(0, 4), + maxRange = parseInt('ffff', 16), hue = parseInt(hash, 16) / maxRange * 256, height = this.height() || size || 32; this.css('background-color', 'hsl(' + hue + ', 90%, 65%)'); -- cgit v1.2.3