sibbl / hass-lovelace-kindle-screensaver

This tool generates a png from a Home Assistant Lovelace view, which can be displayed on a Kindle device which has the Online Screensaver plugin installed.
MIT License
311 stars 71 forks source link

Add option to remove Gamma correction from image. #88

Closed jaenis closed 8 months ago

jaenis commented 8 months ago

Computer images are normally gamma corrected since monitors expect it. However some E-Ink displays expect linear instead gamma corrected image data.

Added new option REMOVE_GAMMA that will remove gamma correction from the image when it is set to true.

This can improve image readability on some E-Ink displays.

sibbl commented 8 months ago

Thanks for the addition. 👍

Maybe one question before merging: do you think it would make sense to make the gamma correction value of 2.2 configurable or is this the most common practice out there?

Sure, it would increase the complexity of the configuration, but I'd like to avoid more config parameters in the future by allowing the best flexibility right away.

As I'm mostly familiar with Kindle displays and initially started this project specifically for them, I just learned what "wild" eink setups might be out there.

jaenis commented 8 months ago

I thought about this exact issue when making the change.

When removing gamma correction, we need to call gm.gamma(1.0/2.2). And my first version was just to provide a GAMMA_CORRECTION value from configuration. It was bit odd to write GAMMA_CORRECTION=0,0454545454545455 in to the configuration field.

Of course I could add a GAMMA value, that user could change, it would default to this 2.2.

Maybe I could add that GAMMA configuration value, then user can set gamma they want and use REMOVE_GAMMA=true to get inverse of it when needed.

jaenis commented 8 months ago

Hmm, I investigated this a bit more.

When capturing browser contents with Puppeteer, it creates screenshot into a PNG file. This PNG internally has fixed gamma of 2.2. There might be a way to tell Puppeteer to use some different color profile, but I am not familiar about that stuff.

sibbl commented 8 months ago

Then I'd suggest to go with it in the way you implemented it. I also just found that Puppeteer and Playwright all use sRGB color space and I couldn't find an option to change this. sRGB has 2.2 default gamma, which seems to be the default for web stuff. As this project will keep taking screenshots from a web page, the 2.2 default gamma will stay.

Thanks again!