mactype icon indicating copy to clipboard operation
mactype copied to clipboard

Gray-scale rendering setting is not applied to Microsoft Edge, Chrome, etc.

Open wmjordan opened this issue 1 year ago • 33 comments

I am using gray-scale anti-alias mode with MacType, which works on most applications. But on Edge, Chrome and other Chromium-based browsers., the setting is not applied.

Those browsers use sub-pixel rendering despite of the setting. Other settings such as hinting appear to be working--I verified that by using an image processor to XOR pixels from two screenshots taken before and after MacType was enabled.

Screenshot with MacType on (enlarged by 400%) 1

Screenshot with MacType off (enlarged by 400%) 1

XOR result of content part in the browser (enlarged by 400%) 1

ini file: DeepGrayNoHinting.zip

wmjordan avatar Jul 21 '22 07:07 wmjordan

I am using the rc2 released yesterday.

wmjordan avatar Jul 21 '22 07:07 wmjordan

DirectWrite support is still in its very early stage, there are a lot of settings that don't work properly in some applications. And I don't know how to make it run in pentile mode either.

snowie2000 avatar Jul 21 '22 08:07 snowie2000

The Windows Console cmd.exe also has this problem. Hinting, font weight, etc are applied to the font, but anti-alias mode is not.

400% enlarged screenshot: image

wmjordan avatar Aug 05 '22 02:08 wmjordan

Windows console cmd.exe is not a GUI application. MacType doesn't work with it at all.

However, mactype does work with the UWP App, the Windows terminal.

snowie2000 avatar Aug 05 '22 02:08 snowie2000

Oops, you are right. I disabled MacType and the console looked just the same.

wmjordan avatar Aug 05 '22 02:08 wmjordan

I opened the ClearType Tuner (cttune.exe) and unchecked the "Turn On ClearType" checkbox there.

Now the Windows Console is using gray-scale rendering fonts in it, furthermore, amazingly, Microsoft Edge is changed to use gray-scale rendering too. It looks great with MacType on my computer now.

wmjordan avatar Aug 05 '22 03:08 wmjordan

You're such a fan of gray-scale rendering. Is there anything the gray-scale is superior to subpixel rendering?

snowie2000 avatar Aug 05 '22 03:08 snowie2000

At the years when Windows XP/2003 was running on my computer with a LCD monitor, characters were crisp. I tried all sub-pixel presets provided by MacType and some other MacType fans' presets, I felt my eyes quite hard to focus on the screen with those red and blue pixels around all characters. I could not work with sub-pixel rendering for more than an hour. Eventually I settled down to my gray-scale profile and my eyes finally feel at ease.

wmjordan avatar Aug 05 '22 04:08 wmjordan

wait, i thought ClearType had to be enabled for MacType to work?

sammilucia avatar Aug 05 '22 05:08 sammilucia

(i also prefer greyscale rendering... in fact, LCD rendering is now disabled by default in Gnome on Linux)

sammilucia avatar Aug 05 '22 05:08 sammilucia

wait, i thought ClearType had to be enabled for MacType to work?

You're right, ClearType has to be enabled to make MacType work "in more situations". MacType can work without ClearType, but some APIs calls will not be intercepted.

If you have a fancy display, like 4K or 8K, gray-scale is very ideal and sharpness is never a problem. Like in recent versions of Macbooks, gray-scale rendering is by default. The same goes for iPhones and iPads.

snowie2000 avatar Aug 05 '22 05:08 snowie2000

Is there anything the gray-scale is superior to subpixel rendering?

I even deployed MacType on some server machines running Windows Server editions. The gray-scale rendering is a must-have when I use remote desktop to log onto those machines. Some programmers in Microsoft have strange faith in ClearType and have it enabled even on remote desktop sessions. Sub-pixel rendering hereby looks horribly spotty from the Remote Desktop client side, since the remote screens are usually scaled on my machine.

Another reason why gray-scale rendering is preferred is that some applications nowadays, including the mmc.exe produced by Microsoft themselves, still lacks high DPI awareness. Those application windows are scaled by the system and the text on them looks spotty subsequently.

wmjordan avatar Aug 05 '22 07:08 wmjordan

in Edge, try going to the URL edge://flags/#edge-enhance-text-contrast > and change it Enabled and click restart. please let us know how you go

sammilucia avatar Aug 07 '22 02:08 sammilucia

never mind, that doesn't help... i was trying to work out how you got Edge to render in greyscale mode... (i realise now - by disabling ClearType)

@snowie2000 i wonder how edge reads the ClearType settings ... i wonder if when MacType is in greyscale mode, MacType can trick Edge (when it opens) into thinking ClearType is disabled.

the problem with this kind of approach is, the next time Microsoft changes their mind, it breaks...

sammilucia avatar Aug 07 '22 03:08 sammilucia

i wonder how edge reads the ClearType settings ... i wonder if when MacType is in greyscale mode, MacType can trick Edge (when it opens) into thinking ClearType is disabled.

The same thought came to my mind.

I just realized that it is not only Edge which depends on the setting of ClearType, but also some applications mentioned in https://github.com/snowie2000/mactype/issues/683. Once ClearType is disabled, their interfaces can be rendered in gray-scale.

wmjordan avatar Aug 07 '22 03:08 wmjordan

so the cleartype settings seem to be in Computer\HKEY_CURRENT_USER\Software\Microsoft\Avalon.Graphics\<displaynumber>

i changed PixelStructure to 0 which means 'greyscale', but it didn't affect how Edge renders (tried rebooting, no change).

the only thing that puts Edge into greyscale for me is completely disabling ClearType... which kind of sucks. so everything is in greyscale due to my MacType settings, except Edge, which does its own thing.

it's weird because not everyone has RGB pixels. i find it very strange Microsoft do not cater to BGR screens...

sammilucia avatar Aug 07 '22 04:08 sammilucia

Displays report they attributes back to windows so in theory Windows the layout is of the display and switch to the correct layout. That's the theory, I never had a chance to prove it.

snowie2000 avatar Aug 07 '22 05:08 snowie2000

I used the ProcMon to monitor the activity of cttune.exe and found that:

  1. While I toggled "Turn on ClearType" checkbox in the first screen of cttune, no registry value was written.
  2. I observed the display of Windows Console changed accordingly.
  3. I observed that the display of Edge had not changed.
  4. I restarted Edge with "Turn on ClearType" checkbox on or off (cttune was kept at its first screen), the display of Edge had no difference.
  5. I clicked the"Next" button in the cttune thru the last screen and found that some values were written to \HKEY_CURRENT_USER\SOFTWARE\Microsoft\Avalon.Graphics\DISPLAY1 (my primary display) and some values were written to \HKEY_CURRENT_USER\Control Panel\Desktop\Font* (FontSmoothing, FontSmoothingGamma, FontSmoothingOrientation and FontSmoothingOrientation)
  6. The display of Edge changed after ending changes in cttune and restarted Edge.

wmjordan avatar Aug 07 '22 12:08 wmjordan

okay i think i've worked some stuff out

Computer\HKEY_CURRENT_USER\Control Panel\Desktop\Font
FontSmoothing
    0 = ClearType OFF
    1 = ClearType ON (CRT) ?
    2 = ClearType ON (LCD)
FontSmoothingOrientation
    0 = BGR
    1 = RGB
FontSmoothingGamma
    Default = 4b0 (1200)
    Minimum = 3e8 (1000)
    Maximum = 7d0 (2000)
FontSmoothingType
    0 = Unknown
    1 = Standard (CRT)
    2 = ClearType (LCD)
    3 = Unknown

Computer\HKEY_CURRENT_USER\Software\Microsoft\Avalon.Graphics\DISPLAY1
ClearTypeLevel
EnhancedContrastLevel
GammaLevel
GrayscaleEnhancedContrastLevel
PixelStructure
    0 = None (CRT)
    1 = BGR
    2 = RGB
TextContrastLevel

i've set both FontSmoothing=1 and FontSmoothingType= and rebooted, and that seems to have set ClearType to ON, and to greyscale.

I've tested and everything seems to be rendering as MacType, except for VSCodium and Edge which are using DirectWrite but in grayscale only mode.

sammilucia avatar Aug 08 '22 02:08 sammilucia

I set FontSmoothing=1 and after reboot, neither Windows Console or Edge was antialiased. I found someone on the web said either FontSmoothing = 0 or 1 would disable font smoothing, FontSmoothingType=3 would produce gray-scale rendering.

Thus I set FontSmoothing=2 and FontSmoothingType=3 then rebooted.

Edge was rendered in gray-scale, antialiased. But Windows Console was rendered in sub-pixel clear type, anti-aliased. image

I opened cttune and it had "Turn On ClearType" unchecked.

wmjordan avatar Aug 08 '22 02:08 wmjordan

hmm, well that's odd. here are all my settings, everything is greyscale for me 🤔.

actually i haven't checked terminal, i'll do that now (but everything else is in greyscale)

ClearType set Grayscale.zip

sammilucia avatar Aug 09 '22 00:08 sammilucia

The following is mine:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Avalon.Graphics\DISPLAY1]
"PixelStructure"=dword:00000001
"GammaLevel"=dword:00000898
"ClearTypeLevel"=dword:00000000
"EnhancedContrastLevel"=dword:00000190
"GrayscaleEnhancedContrastLevel"=dword:00000190
"TextContrastLevel"=dword:00000002

[HKEY_CURRENT_USER\Control Panel\Desktop]
"FontSmoothing"="2"
"FontSmoothingGamma"=dword:000007d0
"FontSmoothingOrientation"=dword:00000001
"FontSmoothingType"=dword:00000003

I will try yours and report later.

wmjordan avatar Aug 09 '22 01:08 wmjordan

I imported ClearType set Grayscale.zip and nothing in Windows Console and Edge was antialiased. "FontSmoothing"="1" had no magic on my side.

image

wmjordan avatar Aug 09 '22 01:08 wmjordan

well this just gets stranger and stranger

this is what those settings get me 😜 image

sammilucia avatar Aug 09 '22 01:08 sammilucia

Eventually I set the following values:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Control Panel\Desktop]
"FontSmoothing"="2"
"FontSmoothingType"=dword:00000001

Both Windows Console and Microsoft Edge are now rendered with gray-scale antialias.

wmjordan avatar Aug 09 '22 12:08 wmjordan

that's so bizarre. that was where I started, but I could only get LCD smoothing with those settings (which is why I changed to FontSmoothing=1 ... what windows are you on? I'm on 11

sammilucia avatar Aug 09 '22 19:08 sammilucia

I am on Win 10. Maybe some guys in Microsoft had already "changed their mind", while Win 11 was being developed.

wmjordan avatar Aug 10 '22 00:08 wmjordan

First, I would like to say thank you all for the effort. I suffer migraines that are very severe, and have recently discovered that one of the greatest 'triggers' for them is broken subpixel rendering. I have been doing a lot of research into trying to get it to work. This issue thread in particular, has a lot of useful research, so thanks for the app and all of your time.

You're such a fan of gray-scale rendering. Is there anything the gray-scale is superior to subpixel rendering?

I can think of three which have applied to me specifically, and two which I learned from the comments by a MS developer's comment

This gets a little nerdy, sorry it is a long story with lots of technical details. Since this thread is a gold mine for me, hopefully there are a few flecks in here for others. I will put a TL;DR at the bottom.

For me: I have a Sony TV I use as my main display - that is, I use it the most, but it is not windows' "primary" display. This is because I also have a gaming monitor which uses Nvidia GSync, and is 165Hz refresh rate, and GSync displays should be configured as your primary monitor and besides, Windows' desktop (DWM.exe) will render frames of your windowed applications, at a single refresh rate, of the primary display, so to really get the full 165Hz (outside of fullscreen exclusive mode apps like the games themselves), it must be the primary.

Slightly offtopic, but related; Linux's X11 renders frames like this too, and Linux's almost-ready Wayland renders each display's frames separately at the full refresh rate of each display. Windows recently worked around a bug in late stage Win10, previously the default behaviour was to render at the lowest frame rate of any visible application. This caused problems when the low-refresh monitor animated anything, and forced the high refresh monitor to render at the lower framerate. Lots of tearing, ruined gaming, etc. Sooo... The high refresh rate monitor must be primary, because DWM sucks and GSync rules.

The monitor is a normal RGB subpixel layout, but is 1440p and accordingly, the pixel density is such that subpixel rendering is not really a necessity or extremely noticable. The Sony is specified as BGR, common for many TVs recently, but in actual fact, they use what I've been referring to as bgrBGR layout, but in writing this post, I got out the magnifying loupe I use for soldering, and I notice it is in fact bgrBGRBGR. There are actually nine subpixels per pixel, arranged in three rows of three columns. The columns are BGR as expected, but the top row of bgr is lower in maximum brightness, than the bottom two rows. So, for about 0-20% brightness of a subpixel colour, the top, darker subpixel will be lit, but the bottom two will not. For 20-60%, the brighter middle pixel will also be lit. For 60-100%, all three subpixels of that colour will be lit. I suspect that this is intended to allow a greater dynamic range, the panel has a very high contrast ratio, because the blacks can be more black because of the dark pixel row at the top and the extreme brightness of all three LEDs together reducing the need for backlighting. I always considered it to be an exceptionally pretty monitor, and only a magnifying glass told me why ;) Recently I have been looking at new gaming OLEDs, and the subpixel layouts of those are often quite unusual too, so they suffer a similar issue of not being supported by either RGB or BGR subpixel rendering.

So, I would really need 'sub-sub-pixel' rendering, for sub-pixel rendering to work, because as the antialiasing demands varying brightness, it is actually changing the pixel's vertical position by up to 2/3 of the height of the pixel. I'm sure you all understand why this just doesn't work properly and even with BGR subpixel rendering, the fonts were not quite right, as the antialiasing shifted individual subpixels up and down. These sub-subpixels are tiny of course, so it is barely noticeable, but the distorted shape is .... some would say 'ugly', and for me, literally "dangerous".

But, even if BGR worked on that 'main' display, then Windows will not actually allow multiple displays to render in a different subpixel layout. Yes, I know the cttuner allows it, and the registry stores it, and my browser of choice (firefox) even reads those settings and attempts to apply them, but the reality is that only the primary display's settings - those in the registry under "DISPLAY1" are ever used, on all displays. I had noticed this and also BetterClearTypeTuner author had also made this observation and accordingly only allowed a single setting. The author also recommends MacType :) So, I would have to set my primary display to BGR, to get BGR on my 'main' display, but it is RGB....and now I have the same 'wrong layout' problem on a different screen.

TL;DR So, I need greyscale, because I have a display which is not RGB or BGR, but an unsupported strange 'bgrBGRBGR' layout - a problem not unlike the newest best OLED monitors; plus, it is not my primary display, which is a different subpixel layout.

Also in the past I have used my monitor in 90 degree rotated fashion, more height for text for coding... and that breaks all of the subpixel layouts!

So, that's my three, the other two from the MS dev were (briefly - see link above) that subpixel rendering can't be composited or animated properly.

And for a bonus, I will say, that since MS have determined that increasing pixel density will render subpixel rendering obsolete, their font rendering APIs have only supported greyscale antialiasing, and so any recent windows version will always contain greyscale AA'd elements, and I prefer whatever it uses, to be used uniformly across the entire workspace. I don't want forced greyscale in the titlebars, but subpixel in the window... So, greyscale everywhere is the only way forward for me. And Windows' greyscale font rendering is unacceptably bad and often simply does not antialias at all. So MacType in greyscale is my only hope until Wayland is ready so I can switch to linux.

Now, with the help of the advice in this thread, I think maybe I can get it to work. I will report my registry settings and results as per the above posts. I hope some of this information will serve useful to others.

ghost avatar Feb 28 '23 17:02 ghost

Thank you for your extraordinarily detailed explanation. That makes perfect sense for lots of things I had never thought of.

And I noticed one thing in Chrome recently:

When you apply a CSS opacity filter to the element, say filter: opacity(1); which basically has no effect on most visible elements, but it will make Chrome render the texts in that element grayscale.

So, you could apply a user css of html { filter: opacity(1); } to make every webpage grayscale.

PS: only opacity filter does the trick, opacity property doesn't. But opacity: 0.999999 does (sometimes).

@wmjordan

snowie2000 avatar Mar 01 '23 04:03 snowie2000

Hence, a stylus style like this does the thing:

/* ==UserStyle==
@name           01/03/2023, 12:41:38
@namespace      github.com/openstyles/stylus
@version        1.0.0
@description    A grayscale world
@author         Me
==/UserStyle== */


html  {
    filter: opacity(100%);
}

Important notice: this filter must be applied to the html tag instead of the body tag. It breaks some CSS effects if you do so.

snowie2000 avatar Mar 01 '23 04:03 snowie2000