Terminal: Implement Delta E 2000 to correct color perception

Created on 2 Sep 2019  路  13Comments  路  Source: microsoft/terminal

Environment

Windows build number:  10.0.18362.0
Windows Terminal version : 0.4.2382.0
ConEmu version: 180626 

Steps to reproduce

  1. Copy the color palette for "
        {   
            "white" : "#fdf6e3",
            "blue" : "#073642",
            "green" : "#586e75",
            "cyan" : "#657b83",
            "red" : "#dc322f",
            "purple" : "#6c71c4",
            "yellow" : "#cb4b16",
            "brightWhite" : "#eee8d5",
            "brightBlack" : "#93a1a1",
            "brightBlue" : "#268bd2",
            "brightGreen" : "#859900",
            "brightCyan" : "#2aa198",
            "brightRed" : "#839496",
            "brightPurple" : "#d33682",
            "brightYellow" : "#b58900",
            "black" : "#002B36",
            "background" : "#002B36",
            "foreground" : "#fdf6e3",
            "name" : "Solarized (John Doe)"
        }
  1. Set powershell's color scheme to "Solarized (John Doe)"
  2. Run [enum]::GetValues([System.ConsoleColor]) | Foreach-Object {Write-Host $_ -ForegroundColor $_} to admire the colors

Expected behavior

Colors look as nice as ConEmu's

Actual behavior

Most colors look nice and similar but "DarkBlue" looks completely different and way worse. See screenshot.
image

To get a somewhat similar color you need to set blue (DarkBlue) to something like "blue" : "#0B5669"
image

Area-Accessibility Area-Rendering Issue-Feature Product-Terminal

Most helpful comment

It looks like ConEmu does some cool stuff to make sure that a color can always be _perceived_. It bumps colors that could be invisible on a certain background up in perceptibility using the deltaE 2000 algorithm.

All 13 comments

It looks to me like it's cmder that might be getting the color wrong. I suggest you try out those color values in an HTML document with a little test like this:

<body style="background:#002b36">
<div style="color:#073642">DarkBlue</div>
<div style="color:#586e75">DarkGreen</div>
<div style="color:#657b83">DarkCyan</div>
<div style="color:#dc322f">DarkRed</div>
<div style="color:#6c71c4">DarkMagenta</div>
</body>

As far as I can tell, that produces colors that exactly match what the Windows Terminal is showing.

It looks like ConEmu does some cool stuff to make sure that a color can always be _perceived_. It bumps colors that could be invisible on a certain background up in perceptibility using the deltaE 2000 algorithm.

It looks like ConEmu lets you configure that with its "Adjust lightness of indistinguishable text" option. I'm betting that if you turn it off, you'll see the same colors as in WT.

@DHowett fair enough! Should I then open a new issue to feature request the same in terminal or can we convert this one?

It would be pretty cool if we could do the same for Terminal. I had wondered why color output looked a bit different. Thanks for breaking it down @DHowett .

What would be needed/considered to implement this in Terminal?

All it would need is someone to do the work, and two people to review the pull request. :smile:

I'd prefer to see a specification to answer a couple questions: would this happen during rendering? Color scheme loading? Is there somewhere we could, should cache colors? How do we hook this setting up into the layer it needs to go into? Should we nudge rgb or 256-color entries the same way as user-specified ones?

Three very easy things 馃槄

I can't answer any of the specifics regarding how this or WT actually work.

This would only pertain to foreground/background compatibility right?

But I would happy be with just user-specified colors.

Nudging 256 color entries would be nice if it wasn't much more overhead, and was cached ahead of time. But looking beyond the scope of user-specified colors might cause this fix to grow too much.

For example, opacity or background images would mess up these adjustments, so I don't think that should be supported/fixed.

+1 on this. To avoid others wasting their time:

Solarized Dark is _not_ supported on Terminal today (assuming that most people like to see what they are typing).
@DHowett was kind enough to suggest workarounds in #6424 if you're hitting these issues.

@CIPop I've been quite successfully using my patched version of Solarized (John Doe) snatched from ConEmu ever since I filed this issue. It goes as follows:

        {   
            "white" : "#fdf6e3",
            "blue" : "#0B5669",
            "green" : "#586e75",
            "cyan" : "#657b83",
            "red" : "#dc322f",
            "purple" : "#6c71c4",
            "yellow" : "#cb4b16",
            "brightWhite" : "#eee8d5",
            "brightBlack" : "#93a1a1",
            "brightBlue" : "#268bd2",
            "brightGreen" : "#859900",
            "brightCyan" : "#2aa198",
            "brightRed" : "#839496",
            "brightPurple" : "#d33682",
            "brightYellow" : "#b58900",
            "black" : "#002B36",
            "background" : "#002B36",
            "foreground" : "#fdf6e3",
            "name" : "Solarized (John Doe with contrast blue)"
        }

As compared to the built-in Solarized, it never produces any unreadable results and has decent difference between colors.
image

@kojoru I suggest sending a PR updating the default with this instead.

Fair enough! Will do.

This may help for anyone trying to implement this: http://www.easyrgb.com/en/math.php#text6. I got this website from the answer in https://stackoverflow.com/questions/5774152/calculate-how-humans-perceive-similarity-between-different-colours. We use chromium math functions in C++ so it just needs conversion to use that instead.

Was this page helpful?
0 / 5 - 0 ratings