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

Linear scaling for HDR content should not be disabled #281

Open
jan2000 opened this issue Jul 21, 2024 · 5 comments
Open

Linear scaling for HDR content should not be disabled #281

jan2000 opened this issue Jul 21, 2024 · 5 comments

Comments

@jan2000
Copy link

jan2000 commented Jul 21, 2024

For correct results resampling should always be done in linear color space. Otherwise problems will be introduced: a too dark image, stair-stepping along edges, stars start to twinkle in panning shots, etc...

https://x.com/ID_AA_Carmack/status/1654528504724062217
https://petewarden.com/2008/08/02/why-fonts-need/
http://www.ericbrasseur.org/gamma.html

Unfortunately in libplacebo linear resampling is currently always disabled for HDR content. This leads to errors when downscaling.

See this example clip. It was created by taking screenshot of the output of mpv of HDR content rescaled from 2160p to 1080p. On the left with libplacebo as is, on the right libplacebo patched to allow linear scaling with HDR content.
(please view images in original size with 100% zoom on monitor with 1:1 pixel mapping)

compare
Notice on the left the stair-stepping along the edges of the A and V. Also notice the wobbling between the T and the O and the T and wings of the logo (simular problem as twinkling stars described by Carmack). Compare to the correct linear resampling on the right.

Here another shot:

compare-text
Again the stair-stepping / aliasing on the left, the text is also too slim. The linear resampling on the right looks way better.

Please do not disable linear scaling for HDR content so we can get correctly scaled video.

@haasn
Copy link
Owner

haasn commented Jul 22, 2024

This was repeatedly enabled and disabled again in the past, because of other issues with nasty ringing artifacts around bright edges when scaling HDR sources in linear light.

Maybe you can take a look:

@jan2000
Copy link
Author

jan2000 commented Jul 23, 2024

Looking at those github issues the nasty ringing artifacts are there because lanczos resampling is used, which is known to introduce ringing/clipping artifacts!

Using the incorrect colorspace for all resampling methods in order to work around an issue caused by a single method is of course not the way to go. What would be is to look at the problematic method lanczos separately.

https://en.wikipedia.org/wiki/Lanczos_resampling#Limitations

In some applications, the low-end clipping artifacts can be ameliorated by transforming the data to a logarithmic domain prior to filtering. In this case the interpolated values will be a weighted geometric mean, rather than an arithmetic mean, of the input samples.

So a solution to mitigate the ringing artifacts caused by the lancoz filter is to do the resampling in log-space just for lancoz. (This could be maybe be controlled by an option, say something like "lancoz-log-scaling", maybe enabled by default.) As this is basically similar to disabling linear scaling a quick fix would be to just in that case disable linear scaling.

Then for all other resampling methods linear scaling does not have to be disabled, and we can have correctly scaled HDR video.

@natural-harmonia-gropius
Copy link

natural-harmonia-gropius commented Jul 24, 2024

something like "lancoz-log-scaling"

What if we do every thing (deband, scale) in Iab (currently using in tone map and gamut map)?

@emotion3459
Copy link

After 75b3947 there should be no downsides to re-enabling linear light downscaling on HDR content.

@norinoriko
Copy link

norinoriko commented Sep 2, 2024

The original user's issue (mpv-player/mpv#11036) with the dark halos on negative lobe filters is also very easily solvable nowadays since EWA antiringing has been implemented. If they wanted to keep using ewa_lanczos, they would just need to add this to their mpv config:

libplacebo-opts=downscaler=custom,downscaler_preset=ewa_lanczos,downscaler_antiring=1

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

5 participants