1
0
mirror of https://github.com/moparisthebest/xeps synced 2024-11-23 01:32:22 -05:00

Merge branch 'xep-0392' into premerge

This commit is contained in:
Jonas Schäfer 2021-10-26 16:35:01 +02:00
commit 87468c2344

View File

@ -14,7 +14,7 @@
<abstract>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.</abstract> <abstract>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.</abstract>
&LEGALNOTICE; &LEGALNOTICE;
<number>0392</number> <number>0392</number>
<status>Deferred</status> <status>Experimental</status>
<type>Standards Track</type> <type>Standards Track</type>
<sig>Standards</sig> <sig>Standards</sig>
<approver>Council</approver> <approver>Council</approver>
@ -23,6 +23,15 @@
<supersededby/> <supersededby/>
<shortname>colors</shortname> <shortname>colors</shortname>
&jonaswielicki; &jonaswielicki;
<revision>
<version>0.8.0</version>
<date>2021-10-26</date>
<initials>jsc</initials>
<remark>
<p>Remove Color Vision Deficiency correction algorithms and substitute
them with a better recommendation.</p>
</remark>
</revision>
<revision> <revision>
<version>0.7.0</version> <version>0.7.0</version>
<date>2019-10-16</date> <date>2019-10-16</date>
@ -128,7 +137,6 @@
<p>To generate a color from a string of text, the following algorithms are applied in order:</p> <p>To generate a color from a string of text, the following algorithms are applied in order:</p>
<ol> <ol>
<li><link url='#algorithm-angle'>Generate a Hue value from the text</link>.</li> <li><link url='#algorithm-angle'>Generate a Hue value from the text</link>.</li>
<li>If enabled, <link url='#algorithm-cvd'>apply configured corrections for &cvds;</link>.</li>
<li>If constraints mandate the use of only a small palette of colors, <link url='#algorithm-mappalette'>map the angle to the closest palette color</link>. (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.)</li> <li>If constraints mandate the use of only a small palette of colors, <link url='#algorithm-mappalette'>map the angle to the closest palette color</link>. (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.)</li>
<li>If the output device supports RGB output, <link url='#algorithm-rgb'>Convert the angle to a RGB</link>.</li> <li>If the output device supports RGB output, <link url='#algorithm-rgb'>Convert the angle to a RGB</link>.</li>
</ol> </ol>
@ -137,12 +145,10 @@
<section1 topic='Business Rules' anchor='rules'> <section1 topic='Business Rules' anchor='rules'>
<ul> <ul>
<li>Implementations SHOULD allow the user to turn off any colorization completely.</li> <li>Implementations SHOULD allow the user to turn off any colorization completely.</li>
<li>Implementations SHOULD implement the &cvd; profiles and SHOULD allow the user to choose any of these profiles or to disable the correction.</li>
<li>Implementations MUST NOT share the &cvd; correction settings with other entities.</li>
</ul> </ul>
</section1> </section1>
<section1 topic='Algorithms' anchor='algorithm'> <section1 topic='Algorithms' anchor='algorithm'>
<p>The algorithms in this document use the &hsluv; color space. It provides consistent brightness (for a given luminosity) across its entire definition space. There is also widespread library support.</p> <p>The algorithms in this document use the &hsluv; color space. It provides consistent brightness (for a given luminosity) across its entire definition space. There is also widespread library support.</p>
<section2 topic='Angle generation' anchor='algorithm-angle'> <section2 topic='Angle generation' anchor='algorithm-angle'>
<p>Input: An identifier, encoded as octets of UTF-8 (&rfc3269;).</p> <p>Input: An identifier, encoded as octets of UTF-8 (&rfc3269;).</p>
<p>Output: Hue angle.</p> <p>Output: Hue angle.</p>
@ -153,20 +159,6 @@
<li>Divide the value by 65536 (use float division) and multiply it by 360 (to map it to degrees in a full circle).</li> <li>Divide the value by 65536 (use float division) and multiply it by 360 (to map it to degrees in a full circle).</li>
</ol> </ol>
</section2> </section2>
<section2 topic='Corrections for &cvds;' anchor='algorithm-cvd'>
<p>Input: Hue angle.</p>
<p>Output: Hue angle.</p>
<p>Note: This algorithm will re-map the angle to map it away from ranges which can not be distinguished by people with the respective &cvds;.</p>
<p>Note: Some floating-point modulo implementations will return negative outputs for negative inputs. This algorithm assumes that your implementation returns <em>non-negative</em> outputs for all inputs.</p>
<section3 topic='Red/Green-blindness' anchor='algorithm-cvd-rg'>
<p>Add 90 to the angle, take it modulo 180 and subtract 90. Take the result modulo 360 to ensure that it's in the range from 0 to 360.</p>
<p>Note: the same effect can be achieved by forcing the two most-significant bits of the angle to be equal to the second-most-significant bit before converting to a float in <link url="#algorithm-angle">Angle generation</link>. This avoids having to perform a floating-point modulo operation.</p>
</section3>
<section3 topic='Blue-blindness' anchor='algorithm-cvd-b'>
<p>Take the angle modulo 180.</p>
<p>Note: the same effect can be achieved by setting the most-significant bit to zero before conversion to floating point in <link url="#algorithm-angle">Angle generation</link>. This avoids having to perform a floating-point modulo operation.</p>
</section3>
</section2>
<section2 topic='RGB generation' anchor='algorithm-rgb'> <section2 topic='RGB generation' anchor='algorithm-rgb'>
<p>Use the HSLuv operation <tt>hsluvToRgb</tt> to convert the Hue angle to a color. The saturation and lightness are to be defined by the implementation (see also the <link url="#accessibility-cr">Contrast Ratio considerations</link>).</p> <p>Use the HSLuv operation <tt>hsluvToRgb</tt> to convert the Hue angle to a color. The saturation and lightness are to be defined by the implementation (see also the <link url="#accessibility-cr">Contrast Ratio considerations</link>).</p>
</section2> </section2>
@ -210,19 +202,9 @@
</section2> </section2>
</section1> </section1>
<section1 topic='Accessibility Considerations' anchor='access'> <section1 topic='Accessibility Considerations' anchor='access'>
<section2 topic='Color Vision Deficiencies' anchor='access-cvds'> <p>This specification describes the generation of colors for strings. Users with color vision deficiencies may have a lower range of distinguishable colors. Implementations should observe the usual recommendations regarding the use of color in that regard.</p>
<p>As outlined above, implementations SHOULD offer the &rgblind; and &bblind; corrections as defined in the <link url='#algorithm-cvd'>Corrections for &cvds;</link> section. Users SHOULD be allowed to choose between:</p> <p>Some users may find a huge variety of colors on their screen distracting. Any implementation making use of this color generation algorithm should support replacing all generated colors with a static, potentially user-configurable, color.</p>
<ul> <p>Implementations should adapt the lightness value according to the background on which the color is rendered in order to achieve a good contrast ratio.</p>
<li>disabling all corrections (skip the Corrections for &cvds; step entirely),</li>
<li>applying one of the &cvd; correction profiles and</li>
<li>disabling colorization altogether.</li>
</ul>
<p>The last option is useful for users with monochromatic view or who find colors distracting.</p>
<p>Some sources on the internet indicate that people with &cvds; may profit from having larger areas of color to be able to recognize them. This should be taken into consideration when selecting font weights and line widths for colored parts.</p>
</section2>
<section2 topic='Contrast Ratio' anchor='access-cr'>
<p>Implementations should adapt the lightness value according to the background on which the color is rendered.</p>
</section2>
</section1> </section1>
<section1 topic='Security Considerations' anchor='security'> <section1 topic='Security Considerations' anchor='security'>
<p>This specification extracts a bit more information from an entity and shows it alongside the existing information to the user. As the algorithm is likely to produce different colors for look-alikes (see &xep0165; for examples) in JIDs, it may add additional protection against attacks based on those.</p> <p>This specification extracts a bit more information from an entity and shows it alongside the existing information to the user. As the algorithm is likely to produce different colors for look-alikes (see &xep0165; for examples) in JIDs, it may add additional protection against attacks based on those.</p>
@ -260,6 +242,15 @@
</ul> </ul>
<p>For the sake of having more colors available, the given algorithm was chosen which prefers many colors with hue conformance over fewer colors with hue and lightness conformance.</p> <p>For the sake of having more colors available, the given algorithm was chosen which prefers many colors with hue conformance over fewer colors with hue and lightness conformance.</p>
</section2> </section2>
<section2 topic='Color Vision Deficiency corrections' anchor='design-cvd-corr'>
<p>An earlier version of this spec included a makeshift algorithm to correct for &cvds;. However, this was considered suboptimal for the following reasons:</p>
<ul>
<li>Any operating system level &cvd; correction is likely to produce better results.</li>
<li>The actual benefit from an accessibility point of view is unclear, given that the &cvd; itself already reduces the dynamic range; if the &cvd; correction algorithm and the &cvd; are not fully in tune about the range reduction, unnecessary additional loss of information may occur.</li>
<li>The algorithms introduced significant complexity on some platforms.</li>
</ul>
<p>Future versions of this spec may re-introduce recommendations if especially the second point can be refuted by credible sources.</p>
</section2>
</section1> </section1>
<section1 topic='IANA Considerations' anchor='iana'> <section1 topic='IANA Considerations' anchor='iana'>
<p>This document requires no interaction with &IANA;. </p> <p>This document requires no interaction with &IANA;. </p>
@ -272,58 +263,22 @@
</section1> </section1>
<section1 topic='Test Vectors' anchor='vectors'> <section1 topic='Test Vectors' anchor='vectors'>
<section2 topic='Test Vectors' anchor='testvectors-fullrange'> <section2 topic='Test Vectors' anchor='testvectors-fullrange'>
<p>This section holds test vectors for the different configurations. The test vectors are provided as Comma Separated Values. Strings are enclosed by single quotes (&apos;). The first line contains a header. Each row contains, in that order, the original text, the text encoded as UTF-8 as hexadecimal octets, the angle in degrees, the calculated hue in degrees (differs from angle only for CVD-corrected rows), and the Red, Green, and Blue values.</p> <p>This section holds test vectors. The test vectors are provided as Comma Separated Values. Strings are enclosed by single quotes (&apos;). The first line contains a header. Each row contains, in that order, the original text, the text encoded as UTF-8 as hexadecimal octets, the angle in degrees, the calculated hue in degrees (hue and angle are the same as of version 0.8.0), and the Red, Green, and Blue values.</p>
<section3 topic='No &cvd; correction' anchor='testvectors-fullrange-no-cvd'> <code><![CDATA[text,hextext,angle,hue,r,g,b
<code><![CDATA[text,hextext,angle,hue,r,g,b
'Romeo','526f6d656f',327.255249,327.255249,0.865,0.000,0.686 'Romeo','526f6d656f',327.255249,327.255249,0.865,0.000,0.686
'juliet@capulet.lit','6a756c69657440636170756c65742e6c6974',209.410400,209.410400,0.000,0.515,0.573 'juliet@capulet.lit','6a756c69657440636170756c65742e6c6974',209.410400,209.410400,0.000,0.515,0.573
'😺','f09f98ba',331.199341,331.199341,0.872,0.000,0.659 '😺','f09f98ba',331.199341,331.199341,0.872,0.000,0.659
'council','636f756e63696c',359.994507,359.994507,0.918,0.000,0.394 'council','636f756e63696c',359.994507,359.994507,0.918,0.000,0.394
'Board','426f617264',171.430664,171.430664,0.000,0.527,0.457]]></code> 'Board','426f617264',171.430664,171.430664,0.000,0.527,0.457]]></code>
</section3>
<section3 topic='With Red/Green-blindness correction' anchor='testvectors-fullrange-cvd-redgreen'>
<code><![CDATA[text,hextext,angle,hue,r,g,b
'Romeo','526f6d656f',327.255249,327.255249,0.865,0.000,0.686
'juliet@capulet.lit','6a756c69657440636170756c65742e6c6974',209.410400,29.410400,0.742,0.359,0.000
'😺','f09f98ba',331.199341,331.199341,0.872,0.000,0.659
'council','636f756e63696c',359.994507,359.994507,0.918,0.000,0.394
'Board','426f617264',171.430664,351.430664,0.904,0.000,0.494]]></code>
</section3>
<section3 topic='With Blue-blindness correction' anchor='testvectors-fullrange-cvd-blue'>
<code><![CDATA[text,hextext,angle,hue,r,g,b
'Romeo','526f6d656f',327.255249,147.255249,0.000,0.535,0.350
'juliet@capulet.lit','6a756c69657440636170756c65742e6c6974',209.410400,29.410400,0.742,0.359,0.000
'😺','f09f98ba',331.199341,151.199341,0.000,0.533,0.373
'council','636f756e63696c',359.994507,179.994507,0.000,0.524,0.485
'Board','426f617264',171.430664,171.430664,0.000,0.527,0.457]]></code>
</section3>
</section2> </section2>
<section2 topic='Test Vectors for mapping to 216 color palette' anchor='testvectors-palette'> <section2 topic='Test Vectors for mapping to 216 color palette' anchor='testvectors-palette'>
<p>The used palette can be generated by sampling the RGB cube evenly with six samples on each axis (resulting in 210 colors (grayscales are excluded)). The resulting palette is commonly known as the palette of so-called "Web Safe" colors.</p> <p>The used palette can be generated by sampling the RGB cube evenly with six samples on each axis (resulting in 210 colors (grayscales are excluded)). The resulting palette is commonly known as the palette of so-called "Web Safe" colors.</p>
<section3 topic='No &cvd; correction' anchor='testvectors-palette-no-cvd'> <code><![CDATA[text,hextext,hue,best_hue,r,g,b
<code><![CDATA[text,hextext,hue,best_hue,r,g,b
'Romeo','526f6d656f',327.255249,327,1.000,0.000,0.800 'Romeo','526f6d656f',327.255249,327,1.000,0.000,0.800
'juliet@capulet.lit','6a756c69657440636170756c65742e6c6974',209.410400,226,0.000,0.800,1.000 'juliet@capulet.lit','6a756c69657440636170756c65742e6c6974',209.410400,226,0.000,0.800,1.000
'😺','f09f98ba',331.199341,331,1.000,0.400,0.800 '😺','f09f98ba',331.199341,331,1.000,0.400,0.800
'council','636f756e63696c',359.994507,359,0.800,0.200,0.400 'council','636f756e63696c',359.994507,359,0.800,0.200,0.400
'Board','426f617264',171.430664,161,0.000,1.000,0.800]]></code> 'Board','426f617264',171.430664,161,0.000,1.000,0.800]]></code>
</section3>
<section3 topic='With Red/Green-blindness correction' anchor='testvectors-palette-cvd-redgreen'>
<code><![CDATA[text,hextext,hue,best_hue,r,g,b
'Romeo','526f6d656f',327.255249,327,1.000,0.000,0.800
'juliet@capulet.lit','6a756c69657440636170756c65742e6c6974',29.410400,30,1.000,0.600,0.400
'😺','f09f98ba',331.199341,331,1.000,0.400,0.800
'council','636f756e63696c',359.994507,359,0.800,0.200,0.400
'Board','426f617264',351.430664,353,0.400,0.000,0.200]]></code>
</section3>
<section3 topic='With Blue-blindness correction' anchor='testvectors-palette-cvd-blue'>
<code><![CDATA[text,hextext,hue,best_hue,r,g,b
'Romeo','526f6d656f',147.255249,147,0.400,0.800,0.600
'juliet@capulet.lit','6a756c69657440636170756c65742e6c6974',29.410400,30,1.000,0.600,0.400
'😺','f09f98ba',151.199341,153,0.200,0.800,0.600
'council','636f756e63696c',179.994507,192,0.000,0.800,0.800
'Board','426f617264',171.430664,161,0.000,1.000,0.800]]></code>
</section3>
</section2> </section2>
</section1> </section1>
</xep> </xep>