LibreShift / red-moon

Android screen filter app for night time phone use.
GNU General Public License v3.0
649 stars 81 forks source link

Auto pause while taking a screenshot #104

Open Sirove opened 7 years ago

Sirove commented 7 years ago

I'd love it if Red Moon would automatically pause itself while taking a screenshot. Just like when installing or updating an app.

NoahAndrews commented 7 years ago

Yes! That would be fantastic.

NoahAndrews commented 7 years ago

I think I'll play with it myself a bit. If I can get it to work well, I'll make a pull request.

NoahAndrews commented 7 years ago

After a little research, I found three ways of detecting a screenshot (monitoring the screenshot folder, monitoring the notifications, and monitoring the list of running services). All three of these will only notify us after the screenshot has been taken. This may not be possible.

matteofilia commented 7 years ago

Maybe it would be possible to apply a filter to the screenshot after it is taken?

smichel17 commented 7 years ago

@matteofilia Possible, but it would look pretty bad.

I wonder if there's a way to intercept the key combination for taking the screenshot (might require running as an accessibility service, like Torchie).

Even if we can't intercept it to pause the filter before passing it along, we could do something like:

matteofilia commented 7 years ago

Someone please correct me if I am incorrect, but let's say I am mixing 2 colours and one is opague. Wouldn't the equation be: ((1-opacity) (red, green, blue) + opacity (red, green, blue)) = (red, green, blue)?

We have the colour of the screen filter and the output image. If we applied the inverse of this equation on a per-pixel basis to the output image, and removed the colour of the screen filter wouldn't we be able to isolate the original image?

Example: (0.75 (???, ???, ???) + 0.25 (255, 0, 0)) = (126, 80, 60) We could isolate the unknown colour to (83, 107, 80) using the inverse of the equation.

I tested this in GIMP and it appears this equation works fine. screenshot from 2017-01-23 07-34-22 screenshot from 2017-01-23 07-34-40

smichel17 commented 7 years ago

When I've tried playing around with stuff like this in gimp I've never been able to get good results; it breaks down near the extremes.

For example, start with a gradient from white to red. Now apply a red filter to it. Now try to apply some filter to reverse the red filter. You can get a gradient back, but it's shifted, because some of the near-red pixels got turned into solid red and became indistinguishable from the actual solid red pixels.

That said, I've tried this mostly with photos, not screenshots, which tend to have more solid colors and fewer gradients, so maybe it'll work.

If you can find an actual screenshot, apply a red filter and export it, then open the new image and apply a new filter that restores the original image and looks good, I'll be impressed and we can try that.

matteofilia commented 7 years ago

You have to calculate it on a per-pixel basis using the inverse of the equation. GIMP can't do that, hence why I did not use an actual image, just a solid colour to represent what you'd do to a single pixel. I'm almost certain I can get something figured out once I have time after exams.

raatmarien commented 7 years ago

I honestly think that this is will be unfeasible to fix. It's my understanding that different android phones handle screen shots differently which makes it hard to detect a screenshot. Furthermore, because you can only detect a screenshot after it has been taken, which means we have to alter the screenshot after it is saved, which could be quite complicated.

Also, I think this behaviour (although undesirable) is to be expected for most users, and after they notice it, it is easy to fix by just turning Red Moon off temporarily and taking the screenshot again.

However, I do agree that it would be great if this could be fixed, so if anyone can find a solution, PR's are of course more than welcome :smile: