-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Support decoding ISO HDR (avif/heic/jpeg-xl, etc) #3778
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
Conversation
…extImageDecodeToHDR, it will be decoded to HDR only when loading is complete.
… be decoded to HDR when it is not completed
2、add simulator log for HDR
|
Looks OK. I'll polish some details and push a fork branch, and merge it later this week. |
There are still some encode problems. For iOS 17, HDR of HEIC images, SDImageHEICCoder.imageUTType returns |
You seems use the HEICS animation image, you need to not use the animation, call |
You mean, JPEG-XL. JPEG2000 does not support HDR. And, we have custom coder for JPEG-XL: https://github.com/SDWebImage/SDWebImageJPEGXLCoder |
The code I submitted recently has been solved. I used Core Image and referred to the Apple developer documentation, https://developer.apple.com/documentation/uikit/supporting-hdr-images-in-your-app, erasing the CGImge type, it can encoded to JPEG/HEIC, next, I'll check for a memory leak, there should be no problem after that |
|
Found some strange code, maybe need your explaination.
|
|
From your description, it seems Apple do some Hack code, to only apply HDR color when JPEG with GainMap or HEIC with non-GainMap HDR image, was rendering on the screen. Maybe some logic inside CoreAnimation (not just ImageIO/CoreImage). It's Screen/hardware awareness decode, not a simple normal 10 bit image bitmap stored in the CGImageRef's buffer. This make me worries about the custom decoder (like libheif, libJPEG-XL) how to correctlly handle the HDR image. And this means, you can never get 10 bit bitmap buffer on iPhone 8 like non-HDR display hardware, even you really want to do so. |
It's OK to call Core Image's API. I'm just surprised to find that there are no ImageIO's related C API to replace it. Most of time, we do operate on In WWDC 23, seems they only mention the CoreImage to write 10 bit HDR into JPEG/HEIC (there are 16 bit PNG, but I'm not familiar with) ? |
iOS 18, imageIO has a new API, |
|
I think actually you don't need to considerate all things in single PR. For example, you can put This PR only focus on HEIC related HDR (HEIF standard) |
My idea is that this PR aims to implement HDR, including HEIC and JPEG. If it only implements HEIC, it will not be cross-platform. at present, through some of my tests, it should be fine. I hope it can be merged into the main branch and a version can be released. |
…ompatible with SDR displays while preserving HDR
* 'master' of https://github.com/SDWebImage/SDWebImage: Fix iOS unit test again Update the GitHub action for Demo build Update the test case `test15ThatQueryCacheTypeWork` to ensure the query from disk only semantic Fix the issue that previous optimization for special case (multiple same URL in prefetcher list) breaks the `queryCacheType` option sematic Add autoreleasepool to DisplayLinkCallback to release objects
SDWebImage/Core/SDImageCoderHelper.m
Outdated
| if (@available(macOS 10.15, iOS 13, watchOS 6.0, *)) { | ||
| CGColorSpaceRef colorSpace = CGImageGetColorSpace(cgImage); | ||
| if (colorSpace) { | ||
| return CGColorSpaceIsHDR(colorSpace); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里实现不正确,参考文档重新写一个,获取CGColorSpace检查CGColorSpaceUsesITUR_2100TF
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
然后macOS AppKit那个NSImage.sd_isHighDynamicRange实现,可以先拿到CGImage(放到UIImage+Compat.h/.m那里),然后调用这里的封装CGImageIsHDR,或者也可以copy代码过去,性能可能好一点?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CGColorSpaceIsHDR应该是包含了CGColorSpaceUsesITUR_2100TF、CGColorSpaceIsPQBased、CGColorSpaceIsHLGBased
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分你确认一下技术资料,我看这个API标记为deprecated,应该是有背景原因的。是不是会错判?还是ISO HDR本身一定是UsesITUR_2100TF+
Need actually check the HDR info of CGImage, or better, we can pre-decode to drop lazy HDR image
…ics renderer This can inherit the possible info like dynamic range
Tested on macOS 14.5 and iOS 18.0 behavior
* Support HDR * Support HDR * When using SDWebImageProgressiveLoad and setting it to SDWebImageContextImageDecodeToHDR, it will be decoded to HDR only when loading is complete. * When SDImageIOAnimatedCoder turns on incremental, it does not need to be decoded to HDR when it is not completed * Sample image to remove sensitive information * 1、use remote resources for HDR testing 2、add simulator log for HDR * Support HDR encode * Support HDR encode * imageRef release error * HDR Decoded is not required for decoding, otherwise the type will be lost * HDR encode format * hdrImageRef not released correctly * HDR image must be lazy decode * HDR image must be lazy decode * JEPG HDR image must be lazy decode, otherwise it will crash * HDR, encoding properties add kCGImageDestinationEncodeToISOGainmap, compatible with SDR displays while preserving HDR * 支持 decode to HDR * HDR encoding is not currently supported * add UIImage.sd_isHighDynamicRange, use check UIImage is HDR * refactor: Do not hack on HEICS and distinguish static/aniamted image encoding UTI * refactor: Move cross-platform screen info into SDDeviceHelper * change: Do not disable force decode when turn on decodeToHDR Need actually check the HDR info of CGImage, or better, we can pre-decode to drop lazy HDR image * change: use UIImage.imageRendererFormat when force decode using graphics renderer This can inherit the possible info like dynamic range * fix: When decode HDR image to SDR, need specify the decode request Tested on macOS 14.5 and iOS 18.0 behavior * test: Added unit test for HDR decoding * demo: Update the macOS demo to show the HDR image * test: workaround the SDR decode on Simulator environment * change: The `sd_isHighDynamicRange` should check CGImage as fallback as well * test: temp disable a unused test case --------- Co-authored-by: DreamPiggy <lizhuoli1126@126.com>
















For iOS 17, HDR for HEIC images is no longer a problem.
For iOS 18, HDR of JPG images is also fine, but the console reports the warn
cicp_tagFromColorSpace:54: Failed to get CICP info for space: <CGColorSpace 0x3009d6a60> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB Linearized)Use iOS 17+ real device debugging, as the simulator does not support HDR, and XCTest does not have a host app, it is not possible to add related tests.