Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better colour approximation #202

Closed
wants to merge 3 commits into from
Closed

Better colour approximation #202

wants to merge 3 commits into from

Commits on Aug 19, 2018

  1. Test error made when mapping RGB colours into 256-colour palette

    Add measure of error introduced when mapping 24-bit colours into
    8-bit ANSI palette.  Having such measure makes it possible to
    benchmark any further changes meant to improve the approximation.
    mina86 committed Aug 19, 2018
    Configuration menu
    Copy the full SHA
    001a784 View commit details
    Browse the repository at this point in the history
  2. Improve RGB→256-colour palette interpolation by better maths

    Improve the way 24-bit colours are mapped to 8-bit ANSI palette by
    observing that neither grayscale ramp nor 6×6×6 colour cube have
    linear staps throughout.
    
    For example, sequence of values in the cube is: 0, 95, 135, 175, 215
    and 255.  The first step is 95 colours while the rest are only 40
    colours.  Similarly, grayscale ramp (plus black and white) create
    a sequence 0, 8, 18, 28, …, 228, 238, 255.  Here, the first step is
    8, the next ones are 10 until final one which is 17.
    
    Assuming the mapping is linear causes wrong results.  For example,
    colour #1C1C1C is at index 234 but the code incorrectly mapped it
    to index 233 (which is 0x121212).
    
    To further improve the approximation, the new code shifts values
    to use rounding during division rather than truncating them.  This
    leads #070707 to be approximated by #080808 rather than #000000.
    mina86 committed Aug 19, 2018
    Configuration menu
    Copy the full SHA
    f578c4d View commit details
    Browse the repository at this point in the history
  3. Improve RGB→256-colour palette interpolation by trying cueb for greys

    The 6×6×6 colour cube includes gray colours.  Black and white are
    already used but the cube also includes other greys such as #5f5f5f
    or #d7d7d7.  For those colours it’s better to use colour from the
    cube rather than from the grayscale ramp.
    
    Change rgb2ansi_grey to try approximation using coulours in either
    section in the pallette and choose the best one.
    
    This only affects 20 colours in total.
    mina86 committed Aug 19, 2018
    Configuration menu
    Copy the full SHA
    6cd511d View commit details
    Browse the repository at this point in the history