• humorlessrepost@lemmy.world
    link
    fedilink
    English
    arrow-up
    6
    ·
    13 hours ago

    It goes against the spirit of the post, but there was a very detailed system for converting invalid colors to valid ones!

    1. If it exactly matches a recognized named color, use that color.

    2. If it is a valid three-digit legacy hex form such as #abc, expand each digit:

      • a → aa
      • b → bb
      • c → cc
    3. Replace non-BMP characters with 00.

    4. Truncate the value to 128 characters.

    5. Remove a leading #, if present.

    6. Replace every character that is not an ASCII hex digit with 0.

    7. Append 0s until the length is a multiple of three.

    8. Split the result into three equal components for red, green, and blue.

    9. If each component is longer than eight characters, keep only its last eight characters.

    10. Remove leading zeroes from all three components while they remain longer than two characters.

    11. If they are still longer than two characters, truncate each to two characters.

    12. Interpret the three components as hexadecimal numbers and use them as RGB values.