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

Add import/export support for AVIF image format #3749

Merged
merged 5 commits into from
Dec 27, 2019

Conversation

cryptomilk
Copy link
Contributor

This adds support to import and export images in the AVIF image format. As the format is really new, it is not widely supported yet. However as most of the big players like (Google, Mozilla, Amazon, Netflix, ...) are investing in AV1. We will see support for it in Android, Firefox, Chrome etc. sooner or
later. exiv2 also doesn't have support for it yet.

To fully support this, we need to also solve #3719

More details are at:
https://blog.cryptomilk.org/2019/11/26/avif-image-support-for-darktable/

@TurboGit TurboGit self-requested a review December 14, 2019 11:21
@TurboGit TurboGit self-assigned this Dec 14, 2019
@TurboGit TurboGit added the feature: enhancement current features to improve label Dec 14, 2019
@TurboGit
Copy link
Member

I can probably take care of the wide gamut colorspace support. I need to find the proper primaries matrix and transfer functions for each of them. From there is should be easy.

@cryptomilk
Copy link
Contributor Author

That would be awesome. Maybe @joedrago can help, he might have the primaries and transfer functions already in https://github.com/joedrago/colorist/ which also uses lcms2.

@TurboGit
Copy link
Member

Ok, primaries for 2020 we already have. For P3 I have just added them, trivial to find. Now I just need a clear description of what is the PQ and HLG transfer functions.

@cryptomilk
Copy link
Contributor Author

cryptomilk commented Dec 14, 2019

I think PQ is described here: https://www.itu.int/rec/R-REC-BT.2100-2-201807-I/en

@TurboGit TurboGit added this to the 3.0.1 milestone Dec 14, 2019
TurboGit added a commit to TurboGit/darktable that referenced this pull request Dec 14, 2019
TurboGit added a commit to TurboGit/darktable that referenced this pull request Dec 14, 2019
TurboGit added a commit to TurboGit/darktable that referenced this pull request Dec 14, 2019
TurboGit added a commit to TurboGit/darktable that referenced this pull request Dec 14, 2019
@TurboGit
Copy link
Member

Please can you test with #3752.

I have the four new color spaces, but they are giving very bright images, maybe expected when not using a HDR image? Not sure... maybe something wrong in may code.

@cryptomilk
Copy link
Contributor Author

Awesome thanks, I will rebase this on your branch.

I think it is normal that they are too bright as we don't have the display to show them. A lot of example images are at:

https://github.com/AOMediaCodec/av1-avif/tree/master/testFiles/Netflix/avif

@cryptomilk
Copy link
Contributor Author

cryptomilk commented Dec 14, 2019

For me, they are very dark, at least the test files which are 10bit rec2020 hlg compared to those which are 8bit bt709 gamma 22.

cryptomilk pushed a commit to cryptomilk/darktable that referenced this pull request Dec 14, 2019
cryptomilk pushed a commit to cryptomilk/darktable that referenced this pull request Dec 14, 2019
cryptomilk pushed a commit to cryptomilk/darktable that referenced this pull request Dec 14, 2019
cryptomilk pushed a commit to cryptomilk/darktable that referenced this pull request Dec 14, 2019
@TurboGit
Copy link
Member

When I said "too light" it was when using the new profiles as "input color profile" for a standard RAW. So probably expected.

You're speaking about the export ? When using one of the new profiles as output profile ?

@TurboGit
Copy link
Member

You forced pushed your changes with mine :) When (if) I update my branch you'll have to properly rebase by grafting your changes on top of mine. You can handle this case ?

@cryptomilk
Copy link
Contributor Author

cryptomilk commented Dec 14, 2019

I'm often handling 100+ patches in a working branch for month or even years :-) I guess I can deal with it. I've pushed an additional patch which also adds the missing profiles names.

@TurboGit
Copy link
Member

@cryptomilk : noted, sorry for asking but I had to deal with some mess sometime :)

@TurboGit
Copy link
Member

I've seen you message on pixls.us, so my wide-gamut are ok ?

@cryptomilk
Copy link
Contributor Author

I guess they are correct, but I'm not 100% sure.

@joedrago
Copy link

Hi all, I got an email ping from @cryptomilk on this thread, and I just wanted to mention that you can use my colorist tool to make really basic PQ test images to verify your pipeline. For example:

colorist generate "256x256,#ff0000..#000000" test.png

will make a really obvious red-to-black gradient image in rec709 with a 2.2 gamma, which you can then convert (any image) to a 10bpc rec2020 PQ lossless AVIF with:

colorist convert test.png test.avif -b 10 -p bt2020 -g pq -l 10000 -q 100

These pixels should have wildly different codepoints, but should represent the exact same xyY values when converted to darktable's rec2020-linear colorspace. You can also view them in Vantage if you have macOS or Windows handy and drag around with the right mouse button to see how I interpret the values.

I'll attach the files I explained above in case you don't want to bother getting any more tools.

testimages.zip

cryptomilk pushed a commit to cryptomilk/darktable that referenced this pull request Dec 15, 2019
@cryptomilk
Copy link
Contributor Author

The AVIF with PQ Rec2020 loads fine. It is completely black, but if I increase the exposure, then I start seeing the gradient. So I think this is fine.

I guess it would be interesting to test darktable on a HDR screen.

@joedrago
Copy link

joedrago commented Dec 15, 2019 via email

@TurboGit
Copy link
Member

@joedrago : I see, this means that our color spaces are OK but when we are using them for whatever image on SDR display we need to adjust the final image by multiplying the 3 RGB channels by around 80. Is that correct?

@joedrago
Copy link

No, you don't multiply by 80, you scale by the ratio of "source luminance" to "destination luminance" when going between overranged linear and PQ. Here's Chrome's implementations of FromLinear and ToLinear, for example:

https://cs.chromium.org/chromium/src/ui/gfx/color_transform.cc?l=97
https://cs.chromium.org/chromium/src/ui/gfx/color_transform.cc?l=177

The big question to ask yourself is "how bright, in nits, is (1.0, 1.0, 1.0, 1.0) when darktable is operating in rec2020 linear?" Chrome has locked in on 80 in their implementation (likely due to SRGB's semi-unused standard), macOS might think it is 100 nits, nominal HLG might prefer it was 203 nits, etc.

Does darktable offer a means to show how bright a pixel is already? If so, what math is it doing to calculate the value in nits? That should be the value you use in a ratio alongside 10000 when going to/from PQ.

cryptomilk pushed a commit to cryptomilk/darktable that referenced this pull request Dec 18, 2019
cryptomilk pushed a commit to cryptomilk/darktable that referenced this pull request Dec 18, 2019
cryptomilk pushed a commit to cryptomilk/darktable that referenced this pull request Dec 18, 2019
cryptomilk pushed a commit to cryptomilk/darktable that referenced this pull request Dec 18, 2019
@cryptomilk
Copy link
Contributor Author

@TurboGit so where should do that multiplication for each channel? When reading the AVIF file is probably wrong as we need to know the display profile?

@joedrago
Copy link

Scaling the channels like this only makes sense after converting to linear; scaling in PQ (or any other nonlinear TF) will do weird things.

In my opinion it should just be a part of the PQ->Linear and Linear->PQ conversions, assuming darktable's LinearRec2020 has a known luminance for (1.0,1.0,1.0) and does good things with overranging (channels > 1.0).

@TurboGit
Copy link
Member

@joedrago : Well sadly this is looking beyond my expertise :( Hopefully someone will shine in and help with the matter as to how best integrate this in dt.

This adds the .clangd directory, cscope and ctags file.
Pair-Programmed-With: Joe Drago <joedrago@gmail.com>
Pair-Programmed-With: Joe Drago <joedrago@gmail.com>
@cryptomilk
Copy link
Contributor Author

@TurboGit I've rebased this on master.

@TurboGit
Copy link
Member

@cryptomilk : is that still ok for merging given that we do not scale the luminance as discussed above? Or is that independent and workable after? Bear with me, I know next to nothing about wide-gamut images...

@cryptomilk
Copy link
Contributor Author

I've created a bug for the PQ to linear part. I think this is good to go. For the beginning AVIF 8bit is interesting as it gives better quality with reduced file size.

@TurboGit TurboGit modified the milestones: 3.0.1, 3.2 Dec 27, 2019
@TurboGit
Copy link
Member

Ok, I'll merge on master and we will merge this in 3.0.1 when luminance scaling is done.

Thanks for opening the issue.

@TurboGit TurboGit merged commit 9451955 into darktable-org:master Dec 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: enhancement current features to improve
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants