-
Hi, This is not explicitly about the avif-coder but maybe somebody here has solved this problem already. I've managed to create wide gamut bitmaps with this library, but how can I actually render them in wide gamut? I'm able to create a FP16 SurfaceView but how can I render the bitmap into it? I tried using the Holder.lockHardwareCanvas + canvas.drawBitmap() but the end result is an RGBA8888 SurfaceView. And if I create GLSurfaceView, all the EGLConfigs are only 8 bit even though the device supports wide gamut surfaces (at least for native code). I initially thought that using something like Image widget from the Jetpack Compose would automatically give me wide gamut surfaces but that doesn't seem to be the case. |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 20 replies
-
Hi! Library itself make a cheat because android directly do not support HDR bitmap library does tone mapping using Logarithmic tone mapper or Rec2408 at your choice. That means after tone mapping curve your image already SDR not HDR. Straight to your question: I don't know very well OpenGL api however I know familiar with Vulkan/Metal if you wish to render HDR, yes, you have to use wide gamut surface.
Hope, that helps :) |
Beta Was this translation helpful? Give feedback.
-
Thanks for the explanation. I'm using an Android TV device and my final goal is to get real HDR images to a HDR10 capable TV. HDR movies has been common for years but I didn't find any apps that would show photos in HDR. Is there a way to avoid that "cheat" you mentioned? |
Beta Was this translation helpful? Give feedback.
-
Some progress. I'm now using EGL/GL more directly instead of trying to use GLSurfaceView etc. I'm able to use FP16 buffers and I can additionally force BT2020_PQ gamut and get the TV in the HDR mode! I'm still trying to figure out if I'm able to set the HDR metadata so that it's actually passed through the stacks. Hopefully at some point I get those from the avif-coder :) Btw, I'm using PreferredColorConfig.RGBA_F16 with HeifCoder().decodeSampled() and that works but with PreferredColorConfig.HARDWARE I get just black. What does the HARDWARE config do in practice? |
Beta Was this translation helpful? Give feedback.
-
I noticed that bitmap.getHardwareBuffer was introduced in API 31 while I have API 30. But I think the RGBA_F16 does everything I need on my device. I'm creating my BT2020_PQ AVIF photos from Canon CR2 with Darktable. I don't have any HDR devices to verify that they look correct but at least importing it to GIMP produces somewhat correct looking image. But if I open them with my avif-coder code on my Android TV device they are overly bright (only the dark colors are visible, everything else is white). Attaching one file here. Any idea of the file is "broken" or if there's perhaps something not supported by the avif-coder? |
Beta Was this translation helpful? Give feedback.
-
I'm new to Darktable so it's definitely possible that I'm doing something wrong there. Chrome shows the AVIF in the same way I see it in Darktable. So somewhat correctly, even though it's darker that the attached JPG. But maybe that's just because of my Darktable settings. Here's the JPG from the camera for the same image (it stores both JPG and CR2). |
Beta Was this translation helpful? Give feedback.
-
On this Android TV I need to provide both the SMPTE 2086 and CTA 861 metadata to enable the HDR mode. I.e. these:
Would perhaps the first 8 be something that could be retrieved from the photo's metadata? What about the last 4? |
Beta Was this translation helpful? Give feedback.
-
I'm actually using those primaries and white point already. But it's unclear to me if those should be somehow coming from the camera? Or are they always exactly those after because Darktable outputs BT.2020 PQ? IMG_0199_rr.avif looks on Chrome much brighter than my original IMG_0199.avif. I modified your code for the "transfer_characteristics == heif_transfer_characteristic_ITU_R_BT_2100_0_PQ" check as you explained earlier and now I get much better image on my Android TV but it's actually much more brighter than your IMG_0199_rr.avif in my Chrome. But I can see some shades of white there in the sky and in the mountains so it's not completely white. And both the IMG_0199_rr.avif and the IMG_0199.avif looks exactly the same in HDR through my Android TV. Tuning the following values don't seem to make any difference:
Although I did have first the mix/max reverted so maybe the TVs got confused or something. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for your help. I think I'm now getting PQ through avif-coder and I'll focus next on how to get a good CR2 to AVIF conversion in Darktable. Any chance to get some extra API/configuration to a future avif-coder release to get that PQ out without modifying the source code? :) Btw, from https://www.darktable.org/2023/12/darktable-4.6.0-released/ :
I was originally using 4.2.1 version and have now moved to that 4.6.0. But I didn't notice any difference in practice. |
Beta Was this translation helpful? Give feedback.
Yes, that's because now Chrome consider it as HDR photo not an ICC based.
To properly display an image using your approach, please, ensure that code in gamut transfer block is not executed, for testing you may just comment this out ( lanes 174 - 261) and check it on the phone, or your TV that bitmap from avif-coder is dark and not an overbright. You should probably see it a VERY dark.
If you already did so, and the library do not applying tone mapping nor ICC and you see a dark photo as an output then it is misconfiguration on your behalf
There is a photo that you have to see before sending it to your PQ surface