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

Transparent background doesn't become transparent foreground when rendered in reverse video #7014

Open
PhMajerus opened this issue Jul 22, 2020 · 25 comments
Labels
Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues Help Wanted We encourage anyone to jump in on these. Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.
Milestone

Comments

@PhMajerus
Copy link

The new Preview 1.2.2022.0 seems to fix all the VT colors issues I observed before, except one last case:

When the background color is the default (49), it is correctly kept transparent, but if the foreground color is transparent, which is possible when the background is 49 and then the colors are reversed using 7, it is rendered as black instead of transparent.

image
echo -e "\e[31m\u2580\e[7m\u2580\e[m"
echo -e "\e[31m\u2590\e[7m\u25A0\e[27m\u258C\e[m"

In both cases, there should be no black square, the acrylic transparency should show through instead.

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Jul 22, 2020
@DHowett
Copy link
Member

DHowett commented Jul 22, 2020

Oh yeah, we need to do an inverse alpha mask with the shaped text. It's expensive and something we chose to not to.

@PhMajerus
Copy link
Author

Could we get that behavior through an optional flag ?
I understand your performance goal, but for some ANSI-art effects, the only solution is to use an existing character reversed, such as for the 3-cells square above. Would be nice to be able to turn it on for specific profiles.

@DHowett
Copy link
Member

DHowett commented Jul 22, 2020

Meh, I'd be inclined to implement it and not make it configurable -- it's more expensive on the engineering side than it is on the runtime side, I expect. 😄

@PhMajerus
Copy link
Author

@DHowett 👍 Great, can't wait to see it implemented then 😁

Especially since you can use it only when you have that specific attributes combination, the current code can be used for faster rendering in every other case, and that combination would definitely look more correct taking advantage of the acrylic effect.

@DHowett DHowett changed the title One last VT color issue in 1.2 - transparent foreground (default background while reversed) Transparent background doesn't become transparent foreground when rendered in reverse video Jul 23, 2020
@DHowett DHowett added Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Jul 23, 2020
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Jul 23, 2020
@DHowett DHowett added this to the Terminal Backlog milestone Jul 23, 2020
@DHowett DHowett added the Help Wanted We encourage anyone to jump in on these. label Jul 23, 2020
@DHowett
Copy link
Member

DHowett commented Jul 23, 2020

Notes:

We can't use a geometry mask based on the glyph run, because we want to fill outside of the geometry and not touch inside the geometry[1].

We may need to use an alpha bitmap (1bpp black and white, converted to an alpha mask) like we did in Islandwood's CGImage and push a layer whose opacity bitmap is this guy.

[1]: Nevermind, I just saw ID2D1Geometry::CombineWithGeometry; perhaps we can just create a Rectangle geometry, combine EXCLUDE the glyph geometries, and fill that...

@thanhph111

This comment has been minimized.

@DHowett

This comment has been minimized.

@thanhph111

This comment has been minimized.

@DHowett

This comment has been minimized.

@DHowett
Copy link
Member

DHowett commented Jul 23, 2020

Hey @PhMajerus,

image

image

@PhMajerus
Copy link
Author

PhMajerus commented Jul 23, 2020

That was fast, thank you @DHowett \(^_^)/

@DHowett
Copy link
Member

DHowett commented Jul 24, 2020

So, it's still got some issues. I want to make sure it works on non-native-scale displays, and follows the antialiasing mode set for the font, and uh it completely breaks hinting (because we're just getting the text geometry and not letting the rasterizer at it)

@thanhph111
Copy link

@DHowett Sorry to bother you again and mess up this issue.

image
image

How can you do that? I try to use Write-Host to write the same but it didn't work. I spent all night to read #6810 as you mention but also have no clue. I did:

  • Run on Windows Terminal 1.2.2022.0
  • Run with PSReadline 2.0.3
  • Run on PowerShell Core 7.0.3

The test below I use black as the same as the background color (#000000) and the white color as the same as the foreground color (#FFFFFF) but it seems that abc is not transparent at all. I hope if text works, glyph should work also.
image

@PhMajerus
Copy link
Author

@thanhph111 Write-Host arguments were designed for the Console API, they do not translate to the VT sequences we're using here.
You need to generate your VT control sequences manually, for example :
PowerShell 7 and later:
Write-Output "`e[97;7m Transparent on white `e[m"
Windows PowerShell:
Write-Output "$([char]27)[97;7m Transparent on white $([char]27)[m"
Or you can use some other cmdlet or component that can generate strings with proper escape sequences.

Of course these will show black on white in the current 1.2 preview build of Windows Terminal, which is the topic of this issue thread.

image
VT and ANSI-art in Windows PowerShell 5.1.19041.1 within Windows Terminal 1.2.2022.0.

@PhMajerus
Copy link
Author

So, it's still got some issues. I want to make sure it works on non-native-scale displays, and follows the antialiasing mode set for the font, and uh it completely breaks hinting (because we're just getting the text geometry and not letting the rasterizer at it)

I didn't go see your code, but since there are only two colors, and in this scenario one of them is transparent, wouldn't bit-fiddling from the positive rendering be enough (and fast if you can run that in a GPU shader) ?

It seems like your final pixels can be taken from the positive rendered cell: the positive rendered alpha reversed (A2 = 255-A1) and RGB fixed to the non transparent color for the whole cell. The alpha should be all that is needed to recover the exact opposite of the shape and RGB values of transparent pixels colors won't matter, so fixing the color for all pixels except for their alpha values should be faster and more reliable than trying to reverse the RGB values.

@DHowett
Copy link
Member

DHowett commented Jul 24, 2020

So for efficiency's sake, I'm trying to avoid capturing the positive render as an image and then inverting it before it goes out.

There's a world where we could easily render the text in black with grayscale AA on white to a temporary bitmap target then draw through that as an alpha mask (ala CGCreateMaskImage from WinObjC above^), but going there would slay performance and introduce a lot of buffer/target churn.

We're also not set up to apply pixel shaders generically, and for doing it off the GPU I'm not sure we can easily grab the backing buffer and alpha-invert just the region we care about without jumping through rather a couple hoops, either.

For the best bang-for-your-buck tradeoff I'm most comfortable with the negative geometry solution... even if it does break hinting.

DHowett added a commit that referenced this issue Jul 27, 2020
This is a trick that makes the text transparent when the _background_
would have been transparent.

Fixes #7014
@jales
Copy link

jales commented Dec 18, 2020

@DHowett Are there any plans to merge your changes in a future version?

@DHowett
Copy link
Member

DHowett commented Dec 18, 2020

@jales not as yet; they are insufficient right now

JanDeDobbeleer added a commit to JanDeDobbeleer/oh-my-posh that referenced this issue Mar 14, 2021
relates to #529
relates to #322
relates to #497

Windors terminal and Visual Studio Code do not work well with inversted
ANSI sequences. This weak allows users to override the Tranparency to
the terminal background color removing black elements in their prompt.

Ideally we remove this once they are on par with other terminals, but
that could take a while.

See microsoft/vscode#111762
and microsoft/terminal#7014
JanDeDobbeleer added a commit to JanDeDobbeleer/oh-my-posh that referenced this issue Mar 14, 2021
relates to #529
relates to #322
relates to #497

Windors terminal and Visual Studio Code do not work well with inversted
ANSI sequences. This weak allows users to override the Tranparency to
the terminal background color removing black elements in their prompt.

Ideally we remove this once they are on par with other terminals, but
that could take a while.

See microsoft/vscode#111762
and microsoft/terminal#7014
@zadjii-msft zadjii-msft modified the milestones: Terminal Backlog, Backlog Jan 4, 2022
@carpet92
Copy link

carpet92 commented Jul 21, 2022

@DHowett

There is info about fix this bug in 1.15.18620 changelog:

We no longer suppress black blackground or gray foreground for PowerShell (#13352)

  • We have chosen to remove this workaround as newer versions of PowerShell's PSReadline component contain a fix for the issue.
  • This was a compatibility band-aid that was impacting the capabilities of great projects such as Oh My Posh.
  • ❗ If you see unexpected black backgrounds appearing behind text while typing a command in PowerShell, make sure your PSReadline version is up to date. You can update your version of PSReadline by running the command, Update-Module PSReadline.

I have installed PSReadline 2.2.6 by Install-Module -Name PSReadline -Force for PS 7.2.5. But for me the issue is still reproduces on the latest 1.15.18620.

Related discussion: JanDeDobbeleer/oh-my-posh#2555

How to fix the issue as it done in this comment?: #7014 (comment)

@zeratax
Copy link

zeratax commented Mar 14, 2023

I can still reproduce this as well on 1.17.1023

@DHowett
Copy link
Member

DHowett commented Mar 14, 2023

Thanks for the report! That would be because it has not yet been fixed.

@FrostKiwi
Copy link

Want to confirm it being broken on my machine as well with ver 1.17.11461.0, as reported in #15491 and #15491
image

@DHowett
Copy link
Member

DHowett commented Jul 14, 2023

Thanks for the report! Yes, this is not machine-specific and requires explicit work in the renderer. We recently put a lot of effort into the new rendering engine, and we think that it should be possible to do this properly.

@silkfire
Copy link

What's the status on this? Still present in 1.18.3181.0

image

@zadjii-msft
Copy link
Member

Yep. We'll make sure to update this thread when there are updates. If someone's interested in trying to fix this themselves, we'd be more than happy to point in the right direction!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues Help Wanted We encourage anyone to jump in on these. Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

No branches or pull requests

9 participants