From 6a3eb64bd1dd2c8ebcd31436876e0ff66d921507 Mon Sep 17 00:00:00 2001 From: Jonas Wielicki Date: Wed, 29 Nov 2017 11:55:45 +0100 Subject: [PATCH] XEP-0392: version 0.4 --- xep-0392.xml | 105 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 35 deletions(-) diff --git a/xep-0392.xml b/xep-0392.xml index 27c86721..161afc60 100644 --- a/xep-0392.xml +++ b/xep-0392.xml @@ -28,6 +28,18 @@ jonas@wielicki.name jonas@wielicki.name + + 0.4 + 2017-11-29 + jwi + +

Use different formulas for Color Vision Deficiency correction, as suggested by Marcus Waldvogel.

+

Update test vectors.

+

Clarify generation of the angle.

+

Prioritize nicknames over bare JIDs.

+

Add rationale for new palette mapping algorithm introduced in 0.3.

+
+
0.3 2017-11-13 @@ -96,7 +108,7 @@

Implementations may want to show a picture in connection with a contact even if the contact does not have an avatar defined (e.g. via &xep0084;).

In such cases, auto-generating an avatar SHOULD happen as follows:

    -
  1. Obtain a name for the contact, in descending order of preference, (a) by using the actual bare JID of the contact (not the bare JID of the conference in case of a XEP-0045 MUC), (b) by using the nickname from the conversation.
  2. +
  3. Obtain a name for the contact, in descending order of preference, (a) the nickname from the conversation, (b) the bare JID of the contact (not the bare JID of the conference in case of a &xep0045; room).
  4. Generate a color as described in the Generating a color section.
  5. Fill an implementation-defined background shape with that color.
  6. Render the first character of the name in white or black centered on the shape.
  7. @@ -116,9 +128,9 @@

    Output: Angle in the CbCr plane.

    Note: The goal of this algorithm is to convert arbitrary text into a scalar value which can then be used to calculate a color. As it happens, the CbCr plane of the YCbCr space determines the color (while Y merely defines the lightness); thus, an angle in the CbCr plane serves as a good scalar value to select a color.

      -
    1. Run the input through SHA-1 (&rfc3174;) as defined by zlib (TODO: add citation).
    2. -
    3. Extract the first 16 bits.
    4. -
    5. Divide the value by 65535 (use float division) and multiply it by 2π (two Pi).
    6. +
    7. Run the input through SHA-1 (&rfc3174;).
    8. +
    9. Treat the output as little endian and extract the last-significant 16 bits. (These are the first two bytes of the output, with the second byte being the most significant one.)
    10. +
    11. Divide the value by 65536 (use float division) and multiply it by 2π (two Pi).
    @@ -126,10 +138,12 @@

    Output: Angle in the CbCr plane.

    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;.

    -

    Divide the angle by two.

    +

    Take the angle modulo π.

    +

    Note: the same effect can be achieved by forcing the most-significant bit of the angle to zero before converting to a float in Angle generation. This avoids having to perform a floating-point modulo operation.

    -

    Divide the angle by two and add π/2 (half Pi).

    +

    Subtract π/2 from the angle, take the result modulo π and add π/2.

    +

    Note: the same effect can be achieved by setting the most-significant bit of the angle to the inverse of the second-most-significant bit before conversion to floating point in Angle generation. This avoids having to perform a floating-point modulo operation.

    @@ -196,6 +210,7 @@ cr = (r - y) / (1 - KR) / 2
  8. Create an empty mapping M which maps from pairs of CbCr values to quadruples of Y, R, G and B.
  9. For each color R, G, B from the input palette:
      +
    1. If the R, G and B values are equal, skip the color and continue with the next.
    2. Calculate Y, Cb and Cr from R, G, B as described in RGB to YCbCr.
    3. Convert Cb and Cr to an angle:

      An implementation may choose a different value for Y depending on whether the sink for the R, G and B values expects Gamma Encoded or Gamma Decoded values. The recommended default of 0.732 is 0.5 to the power of 0.45, that is, a Gamma Encoded 0.5.

      Modifications to Y SHOULD NOT be used to correct for bright/dark backgrounds. Implementations SHOULD instead use the algorithm described in Adapting the Color for specific Background Colors for that.

      + +

      An implementation which shows the generated colors on a colored background SHOULD apply Adapting the Color for specific Background Colors. If the background is not uniformly colored, it is up to the implementation to determine an appropriate surrogate background color to correct against.

      +

      If an implementation shows the generated colors on a grayscale (including white and black) background, it MAY apply the background color correction algorithm. It is RECOMMENDED to always apply the algorithm if the background color is changed dynamically, to avoid discontinuities between grayscale and colored backgrounds.

      +

      Implementations SHOULD use the same background color for all generated colors. If this is not feasible, implementations SHOULD use the same background color for all generated colors within the same GUI control (for example, within a conversation and within the roster).

      +

      As outlined above, implementations SHOULD offer the &rgblind; and &bblind; corrections as defined in the Corrections for &cvds; section. Users SHOULD be allowed to choose between:

      @@ -241,7 +261,7 @@ angle = atan2(cr, cb) % (2*pi)
    4. applying one of the &cvd; correction profiles and
    5. disabling colorization altogether.
    6. -

      The last option is important for users with monochromatic view.

      +

      The last option is useful for users with monochromatic view or who find colors distracting.

      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.

      @@ -271,6 +291,15 @@ angle = atan2(cr, cb) % (2*pi)

      SHA-1 is widely available. From a security point of view, the exact choice of hash function does not matter here, since it is truncated to 16 bits. At this length, any cryptographic hash function is weak.

      + +

      The palette-mapping algorithm operates on angles only and disregards the Y value except if the angles match. This has the downside that the brightness is not equal over the range of the palette mapped colors.

      +

      The alternative would be to require Y to be close to the target Y. This has several issues:

      +
        +
      • We cannot know if a palette can satisfy the given Y at all.
      • +
      • Many colors from e.g. the "Web Safe" palette (used in 256 color terminals and the test vectors) will not satisfy any given Y, reducing the size of the effective palette drastically.
      • +
      +

      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.

      +

      This document requires no interaction with &IANA;.

      @@ -279,7 +308,7 @@ angle = atan2(cr, cb) % (2*pi)

      This document requires no interaction with the ®ISTRAR;.

      -

      Thanks to Daniel Gultsch, Georg Lukas, and Tobias Markmann.

      +

      Thanks to Klaus Herberth, Daniel Gultsch, Georg Lukas, Tobias Markmann, Christian Schudt, and Marcus Waldvogel for their input and feedback on this document.

      @@ -294,43 +323,49 @@ KB = 0.114

      This section holds test vectors for the different configurations. The test vectors are provided as Comma Separated Values. Strings are enclosed by single quotes ('). 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 radians, and the Cb, Cr, Red, Green, and Blue values.

      +'Romeo','526f6d656f',5.711682,0.500000,-0.321546,0.281,0.790,1.000 +'juliet@capulet.lit','6a756c69657440636170756c65742e6c6974',3.654901,-0.500000,-0.281855,0.337,1.000,0.000 +'😺','f09f98ba',5.780519,0.500000,-0.274885,0.347,0.756,1.000 +'council','636f756e63696c',6.283089,0.500000,-0.000048,0.732,0.560,1.000]]>
      - + +'Romeo','526f6d656f',2.570089,-0.500000,0.321546,1.000,0.674,0.000 +'juliet@capulet.lit','6a756c69657440636170756c65742e6c6974',0.513308,0.500000,0.281855,1.000,0.359,1.000 +'😺','f09f98ba',2.638926,-0.500000,0.274885,1.000,0.708,0.000 +'council','636f756e63696c',3.141497,-0.500000,0.000048,0.732,0.904,0.000]]> - + +'Romeo','526f6d656f',2.570089,-0.500000,0.321546,1.000,0.674,0.000 +'juliet@capulet.lit','6a756c69657440636170756c65742e6c6974',3.654901,-0.500000,-0.281855,0.337,1.000,0.000 +'😺','f09f98ba',2.638926,-0.500000,0.274885,1.000,0.708,0.000 +'council','636f756e63696c',3.141497,-0.500000,0.000048,0.732,0.904,0.000]]> -

      The used palette can be generated by sampling the RGB cube evenly with six samples on each axis (resulting in 216 colors). The resulting palette is commonly known as the palette of so-called "Web Safe" colors.

      -

      The format of the test vectors is the same as in the full range case above.

      +

      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.

      +

      Instead of the cb and cr values, the test vectors contain the best_angle as found in the palette.

      - + - - + + - - + +