Discover XEP-0392: Consistent Color Generation

This quest to discover XEP-0392 (Consistent Color Generation) was automagically added, to fulfill the quest at Discover XEPs. As of 2018-10-02 the status of this Standards Track XEP is Experimental. What does that even mean?! Check it out at XEP-0392: Consistent Color Generation :slight_smile:

This specification provides a set of algorithms to consistently generate colors given a string. The string can be a nickname, a JID or any other piece of information. All entities adhering to this specification generate the same color for the same string, which provides a consistent user experience across platforms.

I found this linked from User Interface - Modern XMPP, specifically:

3.1 Generating a color

To generate a color from a string of text, the following algorithms are applied in order:

  1. Generate a Hue value from the text.
  2. If enabled, apply configured corrections for Color Vision Deficiencies.
  3. If constraints mandate the use of only a small palette of colors, map the angle to the closest palette color. (Such situations could for example be a UI environment with guidelines to only use a specific set of colors or an output device which only supports a limited amount of colors.)
  4. If the output device supports RGB output, Convert the angle to a RGB.

Which bring me to XEP-0392: Consistent Color Generation

5.1 Angle generation

Input: An identifier, encoded as octets of UTF-8 (RFC 3269 [2]).

Output: Hue angle.

Note: The goal of this algorithm is to convert arbitrary text into a scalar value which can then be used to calculate a color.

  1. Run the input through SHA-1 (RFC 3174 [3]).
  2. Treat the output as little endian and extract the least-significant 16 bits. (These are the first two bytes of the output, with the second byte being the most significant one.)
  3. Divide the value by 65536 (use float division) and multiply it by 360 (to map it to degrees in a full circle).

Whoa, thatโ€™s cool! That creates a persistent experience across clients, which is pretty cool. So the avatar color for is the same for clients implementing this XEP, for instance. :slight_smile: