Automatic switch based on white detection
Comawhite54 opened this issue · 8 comments
Hello, would there be a way to read the current display and analyze it this way:
If the center of the screen is white/bright, then switch ON, toggle /OFF/ON.
Or if more than 50% of the screen is bright colored.
(maybe not scan the whole screen but just a large square in the center would be more relevant I think).
This is because some apps are already in Dark mode.
I experimented with something like this in the past.
It worked, but was very CPU hungry and had several shortcomings, so I decided not to release it.
Maybe I should give it another try...
Very funny, I did try indeed today after my post and went to the exact same result 😁, It is behaving exactly as I want, but takes about 100ms at least to analyze, and cpu loaded at 25%. I trigger the scan every 500ms.
I was able to make it all in a distinct C# file so I think I will post my source here in comments soon. I already have several ideas to reduce the load:
- use a different method (now it is reading pixels from a bitmap copy)
- read 1 pixel over 10 instead of reading all pixels
- and more...
But anyway the system reacts very well as it is and responds to my need.
Hello,
I attach my source file here. It is only good for testing purpose, not fully integrated (no menu etc..)
I do not know much about namespace/naming standards in C#, so, take this as a draft...
To activate it, just call the function "BrightnessDetection.Start();" in the Main() program.
If you like this function maybe I will spend some time to improve it, and can propose a pull request maybe (but would prefer if someone else take care of it to make a cleaner work).
Also see my old branch brightness_detection.
@Comawhite54 such thing exists in https://github.com/Fushko/gammy
@mlaily I hugely support such functionality, I suffer from bright flashes which occur across OS and applications (example here https://github.com/Fushko/gammy/issues/130 ). Simple solution for this is to turn pure white color into black or gray but I don't think NegativeScreen can do that using color matrices. Smarter solution is to limit pixel brightness rise speed. Even smarter solution is to analyze screen smart way and apply this limitation only to big white areas. There is no problem with white, there is problem with it appearing too fast (or being too bright especially on new HDR extra bright monitors). I don't care about cpu usage - health is more important.
As current solution I close my eyes whenever I know there will be white flash (including IRL like turning on lightbulbs).
UPD: just tried filter which overwrites white with black - very bad, unreadable. So limiting speed of reaching white is the only way.
@Devocub an automatic switch in NegativeScreen (or any other program that detects lightness thresholds with screenshots) will never be instant: there is always some lag between the moment the screen turns black or white and the moment it's detected and the color inversion can occur.
Until the automatic inversion kicks in, this detection lag translates into bright flashes of several dozens of milliseconds, which is exactly what we would like to avoid!
I'm sorry but I don't see good solutions to this problem that could be implemented in NegativeScreen.
@mlaily of course it should be blocking way. Actually it is quite possible to do.
-
https://github.com/mausimus/ShaderGlass Overlay for running GPU shaders on top of Windows desktop. Strange but it doesn't support custom shaders but since it's open source such ability can be added.
-
Hacking into DWM and doing whatever we want, maybe with customizations like applying effect only to certain type of windows. I prefer this way.
-
Support in GPU driver for shaders, it is up to Nvidia, AMD and Intel.
I created shader for Reshade which does desired thing. Video, you can see dark things update instantly and bright ones slowly:
2023-03-27.06-06-38.mp4
I didn't know about ShaderGlass. That's impressive, and an interesting idea if it doesn't add too much lag.
It would completely change the way NegativeScreen is working though. You might as well start from scratch!