@@ -149,6 +149,52 @@ SDImagePhotosLoader.shared.requestImageAssetOnly = false
149
149
150
150
Then just request the PHAssets or using the fetch options, which the media type is ` .video ` .
151
151
152
+ #### HDR Photo Rendering
153
+ To enable HDR decoding and rendering, upgrade SDWebImage to 5.21.0+, then, request the image data from Photos Library and turn on HDR decoding.
154
+
155
+ + Objective-C
156
+
157
+ ``` objective-c
158
+ #if TARGET_OS_OSX
159
+ BOOL supportsHDR = NSScreen.mainScreen.maximumPotentialExtendedDynamicRangeColorComponentValue > 1.0;
160
+ #else
161
+ #define NSImageDynamicRangeHigh UIImageDynamicRangeHigh
162
+ BOOL supportsHDR = UIScreen.mainScreen.potentialEDRHeadroom > 1.0;
163
+ #endif
164
+ SDWebImageMutableContext *context = [@{SDWebImageContextStoreCacheType: @(SDImageCacheTypeNone)} mutableCopy] ;
165
+ if (supportsHDR) {
166
+ if (@available (macOS 14.0, iOS 17, * )) {
167
+ cell.imageViewDisplay.preferredImageDynamicRange = NSImageDynamicRangeHigh; // Enable Image View Level control for HDR
168
+ }
169
+ context[ SDWebImageContextPhotosRequestImageData] = @(YES); // Photos Library only load HDR info when requestImageData
170
+ context[ SDWebImageContextImageDecodeToHDR] = @(YES); // When decoding HDR data, we need explicit enable HDR decoding
171
+ }
172
+ // Then loading HDR assets with context option
173
+ [imageView sd_setImageWithURL: photosURL placeholderImage: nil context: context ] ;
174
+ ```
175
+
176
+ + Swift
177
+
178
+ ```swift
179
+ #if os(macOS)
180
+ let supportsHDR = NSScreen.main.maximumPotentialExtendedDynamicRangeColorComponentValue > 1.0
181
+ #else
182
+ let supportsHDR = UIScreen.main.potentialEDRHeadroom > 1.0
183
+ #endif
184
+ var context = [
185
+ SDWebImageContextStoreCacheType: SDImageCacheType.none.rawValue
186
+ ]
187
+ if supportsHDR {
188
+ if #available(macOS 14.0, iOS 17, *) {
189
+ cell.imageViewDisplay.preferredImageDynamicRange = .high // Enable Image View Level control for HDR
190
+ }
191
+ context[.photosRequestImageData] = true // Photos Library only load HDR info when requestImageData
192
+ context[.imageDecodeToHDR] = true // When decoding HDR data, we need explicit enable HDR decoding
193
+ }
194
+ // Then loading HDR assets with context option
195
+ imageView.sd_setImage(with: photosURL, placeholderImage: nil, context:context)
196
+ ```
197
+
152
198
#### Fetch/Request Options
153
199
To specify options like ` PHFetchOptions ` or ` PHImageRequestOptions ` for Photos Library. Either to change the correspond properties in loader, or provide a context options for each image request.
154
200
0 commit comments