libplacebo icon indicating copy to clipboard operation
libplacebo copied to clipboard

Linear scaling for HDR content should not be disabled

Open jan2000 opened this issue 1 year ago • 7 comments

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.

jan2000 avatar Jul 21 '24 22:07 jan2000

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:

  • https://github.com/mpv-player/mpv/issues/11036
  • https://github.com/mpv-player/mpv/issues/4631

haasn avatar Jul 22 '24 23:07 haasn

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.

jan2000 avatar Jul 23 '24 06:07 jan2000

something like "lancoz-log-scaling"

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

After https://github.com/haasn/libplacebo/commit/75b3947b2c07803456483ec6976c037bad91b5dd there should be no downsides to re-enabling linear light downscaling on HDR content.

emotion3459 avatar Aug 31 '24 05:08 emotion3459

The original user's issue (https://github.com/mpv-player/mpv/issues/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

ghost avatar Sep 02 '24 03:09 ghost

To create 'conditioned' for sinc-based workflow digital moving pictures data we have special downsampling kernels (with internal LPF) https://github.com/haasn/libplacebo/issues/312 . They allow to create non-ringed with sinc-based upsamplers content. But it still only work in a 'perfect world' of 4:4:4 sampled colour systems. Unfortunately the 4:2:x old poorly designed colour subsampling systems stlll widely used even with HDR/WCG/HFR era and still bugs images. So with resizing of 4:2:x when upsampling chroma to 4:4:4 it is recommended to wait to some AI-aided neural-networks trained on typical distortions and able to correct them better. Linear data processing can not help in non-linear environments like 4:2:x chroma subsampled systems.

DTL2020 avatar Mar 25 '25 20:03 DTL2020

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

@haasn Since we have the solution for ring effect, can we revert the previous commit that disables linear scaling?(maybe also enable antiring by default?)

Headcrabed avatar May 26 '25 05:05 Headcrabed