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

Automatic switch based on white detection #25

Open
Comawhite54 opened this issue Oct 14, 2021 · 8 comments
Open

Automatic switch based on white detection #25

Comawhite54 opened this issue Oct 14, 2021 · 8 comments

Comments

@Comawhite54
Copy link

Comawhite54 commented Oct 14, 2021

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.

@mlaily
Copy link
Owner

mlaily commented Oct 14, 2021

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...

@Comawhite54
Copy link
Author

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.

@Comawhite54
Copy link
Author

Comawhite54 commented Oct 18, 2021

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).

BrightnessDetection.cs.txt

![image](https://user-images.githubusercontent.com/37051210/137723096-6495f996-d687-4c81-9ddb-e2c56181b1c2.png

@mlaily
Copy link
Owner

mlaily commented Oct 18, 2021

Also see my old branch brightness_detection.

@Devocub
Copy link

Devocub commented Mar 24, 2023

@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.

@mlaily
Copy link
Owner

mlaily commented Mar 26, 2023

@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.

@Devocub
Copy link

Devocub commented Mar 27, 2023

@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

@mlaily
Copy link
Owner

mlaily commented Mar 27, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants