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

Gamma-correct chroma subsampling #193

Open
kornelski opened this issue Dec 1, 2015 · 5 comments
Open

Gamma-correct chroma subsampling #193

kornelski opened this issue Dec 1, 2015 · 5 comments

Comments

@kornelski
Copy link
Member

kornelski commented Dec 1, 2015

This image (source) should show RULES on an sRGB-ish monitor and/or browser with a good color management.

and if it's resized with appropriate gamma should resize to:

gamma 2.2

However, libjpeg blends pixels in Cr/Cb color space, which has non-linear gamma, and chroma subsampling results in:

bad gamma

It could be better. I've prototyped a very slow and hacky chroma downsampling that generates:

gamma-1 0-or-2 2-red-trianglefilter

so there's definitely a room for improvement.

@kornelski
Copy link
Member Author

Coincidentally the next version of WebP will solve that too, by using an iterative algorithm:

https://chromium.googlesource.com/webm/libwebp/+/master/src/enc/picture_csp.c#487

@kornelski
Copy link
Member Author

@CoolOppo
Copy link

That prototype is pretty impressive. It's far better than the current subsampling.

Edit: I made a little comparison slider. The image on the right is the prototype:

https://visionless.me/u/subsample-comparison.html

@Artoria2e5
Copy link

Artoria2e5 commented Mar 22, 2020

The webp source code link moved to https://github.com/webmproject/libwebp/blob/master/src/enc/picture_csp_enc.c. Search PreprocessARGB for the iterative code. As Ser-Gen memntioned, sjpeg calls this scaling "sharp YUV". https://github.com/webmproject/sjpeg/blob/5ce9c14cceba85a83ac6efcef94658eb28e304ea/src/yuv_convert.cc#L101

The luma-scaled code is at https://github.com/kornelski/jpeg-compressor/blob/9eeb009fdb8673224de5be978574cb139e4b8bf6/jpge.cpp#L611.


sharp YUV is now a separate libsharpyuv in the webp project, with its own pkg-config file and everything. It is an optional choice in AVIF.

@Artoria2e5
Copy link

Artoria2e5 commented Apr 21, 2023

Huh, apparently there's yet another approach , the HDRTools way. Pic is from doi:10.5594/m001639. No idea how well it works in SDR, when "OETF" is just "gamma".
image

Oh god a google for "chroma subsampling" gave me some arxiv magic (possible published version) involving gradient descent in H.266. oh it's friendlier when you say "iterative" and it lists some prior work too. code's gone

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

No branches or pull requests

4 participants