@octane-xplat/nativescript-mason-core 0.0.1 → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +198 -2
  3. package/artifact-inventory.json +774 -0
  4. package/box-shadow.d.ts +10 -0
  5. package/box-shadow.js +48 -0
  6. package/common.d.ts +485 -0
  7. package/common.js +2659 -0
  8. package/css-colors.d.ts +17 -0
  9. package/css-colors.js +54 -0
  10. package/css-environment.d.ts +49 -0
  11. package/css-environment.js +309 -0
  12. package/css-filter.d.ts +17 -0
  13. package/css-filter.js +140 -0
  14. package/css-keyframes.d.ts +41 -0
  15. package/css-keyframes.js +437 -0
  16. package/css-math.d.ts +34 -0
  17. package/css-math.js +300 -0
  18. package/css-shorthands.d.ts +65 -0
  19. package/css-shorthands.js +673 -0
  20. package/css-transform.d.ts +6 -0
  21. package/css-transform.js +100 -0
  22. package/diagnostics.d.ts +51 -0
  23. package/diagnostics.js +52 -0
  24. package/display-density.d.ts +9 -0
  25. package/display-density.js +20 -0
  26. package/fonts.d.ts +20 -0
  27. package/fonts.js +88 -0
  28. package/foreign-layout.d.ts +6 -0
  29. package/foreign-layout.js +151 -0
  30. package/gradient-stops.d.ts +25 -0
  31. package/gradient-stops.js +112 -0
  32. package/index.android.d.ts +11 -0
  33. package/index.android.js +9 -0
  34. package/index.d.ts +12 -0
  35. package/index.ios.d.ts +11 -0
  36. package/index.ios.js +9 -0
  37. package/ios-host-README.md +124 -0
  38. package/layout-types.d.ts +192 -0
  39. package/mask.d.ts +54 -0
  40. package/mask.js +26 -0
  41. package/native-environment.android.d.ts +3 -0
  42. package/native-environment.android.js +69 -0
  43. package/native-environment.d.ts +3 -0
  44. package/native-environment.ios.d.ts +3 -0
  45. package/native-environment.ios.js +65 -0
  46. package/native-types-README.md +51 -0
  47. package/package.json +47 -6
  48. package/panel-helpers.d.ts +3 -0
  49. package/panel-helpers.js +8 -0
  50. package/platforms/android/MasonCore.aar +0 -0
  51. package/platforms/android/include.gradle +6 -0
  52. package/platforms/android/manifest.json +73 -0
  53. package/platforms/ios/FontManager.LICENSE +201 -0
  54. package/platforms/ios/MasonCore.xcframework/Info.plist +43 -0
  55. package/platforms/ios/MasonCore.xcframework/ios-arm64/MasonCore.framework/Headers/Mason.h +25 -0
  56. package/platforms/ios/MasonCore.xcframework/ios-arm64/MasonCore.framework/Headers/MasonCore-Swift.h +1739 -0
  57. package/platforms/ios/MasonCore.xcframework/ios-arm64/MasonCore.framework/Headers/mason_native.h +601 -0
  58. package/platforms/ios/MasonCore.xcframework/ios-arm64/MasonCore.framework/Info.plist +0 -0
  59. package/platforms/ios/MasonCore.xcframework/ios-arm64/MasonCore.framework/MasonCore +0 -0
  60. package/platforms/ios/MasonCore.xcframework/ios-arm64/MasonCore.framework/Modules/MasonCore.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
  61. package/platforms/ios/MasonCore.xcframework/ios-arm64/MasonCore.framework/Modules/MasonCore.swiftmodule/arm64-apple-ios.abi.json +100095 -0
  62. package/platforms/ios/MasonCore.xcframework/ios-arm64/MasonCore.framework/Modules/MasonCore.swiftmodule/arm64-apple-ios.private.swiftinterface +3174 -0
  63. package/platforms/ios/MasonCore.xcframework/ios-arm64/MasonCore.framework/Modules/MasonCore.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  64. package/platforms/ios/MasonCore.xcframework/ios-arm64/MasonCore.framework/Modules/MasonCore.swiftmodule/arm64-apple-ios.swiftinterface +3174 -0
  65. package/platforms/ios/MasonCore.xcframework/ios-arm64/MasonCore.framework/Modules/module.modulemap +9 -0
  66. package/platforms/ios/MasonCore.xcframework/ios-arm64/MasonCore.framework/SDWebImage_SDWebImage.bundle/Info.plist +0 -0
  67. package/platforms/ios/MasonCore.xcframework/ios-arm64/MasonCore.framework/SDWebImage_SDWebImage.bundle/PrivacyInfo.xcprivacy +23 -0
  68. package/platforms/ios/MasonCore.xcframework/ios-arm64-simulator/MasonCore.framework/Headers/Mason.h +25 -0
  69. package/platforms/ios/MasonCore.xcframework/ios-arm64-simulator/MasonCore.framework/Headers/MasonCore-Swift.h +1739 -0
  70. package/platforms/ios/MasonCore.xcframework/ios-arm64-simulator/MasonCore.framework/Headers/mason_native.h +601 -0
  71. package/platforms/ios/MasonCore.xcframework/ios-arm64-simulator/MasonCore.framework/Info.plist +0 -0
  72. package/platforms/ios/MasonCore.xcframework/ios-arm64-simulator/MasonCore.framework/MasonCore +0 -0
  73. package/platforms/ios/MasonCore.xcframework/ios-arm64-simulator/MasonCore.framework/Modules/MasonCore.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
  74. package/platforms/ios/MasonCore.xcframework/ios-arm64-simulator/MasonCore.framework/Modules/MasonCore.swiftmodule/arm64-apple-ios-simulator.abi.json +100095 -0
  75. package/platforms/ios/MasonCore.xcframework/ios-arm64-simulator/MasonCore.framework/Modules/MasonCore.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +3174 -0
  76. package/platforms/ios/MasonCore.xcframework/ios-arm64-simulator/MasonCore.framework/Modules/MasonCore.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  77. package/platforms/ios/MasonCore.xcframework/ios-arm64-simulator/MasonCore.framework/Modules/MasonCore.swiftmodule/arm64-apple-ios-simulator.swiftinterface +3174 -0
  78. package/platforms/ios/MasonCore.xcframework/ios-arm64-simulator/MasonCore.framework/Modules/module.modulemap +9 -0
  79. package/platforms/ios/MasonCore.xcframework/ios-arm64-simulator/MasonCore.framework/SDWebImage_SDWebImage.bundle/Info.plist +0 -0
  80. package/platforms/ios/MasonCore.xcframework/ios-arm64-simulator/MasonCore.framework/SDWebImage_SDWebImage.bundle/PrivacyInfo.xcprivacy +23 -0
  81. package/platforms/ios/Package.resolved +24 -0
  82. package/platforms/ios/SDWebImage.LICENSE +20 -0
  83. package/platforms/ios/build.xcconfig +4 -0
  84. package/platforms/ios/device-manifest.json +213 -0
  85. package/platforms/ios/include/FontManager/NSCFontDescriptors.h +36 -0
  86. package/platforms/ios/include/FontManager/NSCFontFace.h +98 -0
  87. package/platforms/ios/include/FontManager/NSCFontFaceSet.h +73 -0
  88. package/platforms/ios/include/FontManager/NSCFontManagerUmbrella.h +7 -0
  89. package/platforms/ios/include/FontManager/NSCFontParser.h +22 -0
  90. package/platforms/ios/include/FontManager/NSCFontRegex.h +4 -0
  91. package/platforms/ios/include/FontManager/NSCFontResolver.h +43 -0
  92. package/platforms/ios/include/FontManager/NSCFontStyle.h +27 -0
  93. package/platforms/ios/include/FontManager/NSCFontTypes.h +41 -0
  94. package/platforms/ios/include/SDWebImage/NSButton+WebCache.h +340 -0
  95. package/platforms/ios/include/SDWebImage/NSData+ImageContentType.h +63 -0
  96. package/platforms/ios/include/SDWebImage/NSImage+Compatibility.h +67 -0
  97. package/platforms/ios/include/SDWebImage/SDAnimatedImage.h +136 -0
  98. package/platforms/ios/include/SDWebImage/SDAnimatedImagePlayer.h +113 -0
  99. package/platforms/ios/include/SDWebImage/SDAnimatedImageRep.h +33 -0
  100. package/platforms/ios/include/SDWebImage/SDAnimatedImageView+WebCache.h +168 -0
  101. package/platforms/ios/include/SDWebImage/SDAnimatedImageView.h +125 -0
  102. package/platforms/ios/include/SDWebImage/SDCallbackQueue.h +59 -0
  103. package/platforms/ios/include/SDWebImage/SDDiskCache.h +146 -0
  104. package/platforms/ios/include/SDWebImage/SDGraphicsImageRenderer.h +84 -0
  105. package/platforms/ios/include/SDWebImage/SDImageAPNGCoder.h +19 -0
  106. package/platforms/ios/include/SDWebImage/SDImageAWebPCoder.h +23 -0
  107. package/platforms/ios/include/SDWebImage/SDImageCache.h +482 -0
  108. package/platforms/ios/include/SDWebImage/SDImageCacheConfig.h +153 -0
  109. package/platforms/ios/include/SDWebImage/SDImageCacheDefine.h +179 -0
  110. package/platforms/ios/include/SDWebImage/SDImageCachesManager.h +81 -0
  111. package/platforms/ios/include/SDWebImage/SDImageCoder.h +347 -0
  112. package/platforms/ios/include/SDWebImage/SDImageCoderHelper.h +251 -0
  113. package/platforms/ios/include/SDWebImage/SDImageCodersManager.h +58 -0
  114. package/platforms/ios/include/SDWebImage/SDImageFrame.h +44 -0
  115. package/platforms/ios/include/SDWebImage/SDImageGIFCoder.h +22 -0
  116. package/platforms/ios/include/SDWebImage/SDImageGraphics.h +28 -0
  117. package/platforms/ios/include/SDWebImage/SDImageHEICCoder.h +25 -0
  118. package/platforms/ios/include/SDWebImage/SDImageIOAnimatedCoder.h +65 -0
  119. package/platforms/ios/include/SDWebImage/SDImageIOCoder.h +30 -0
  120. package/platforms/ios/include/SDWebImage/SDImageLoader.h +146 -0
  121. package/platforms/ios/include/SDWebImage/SDImageLoadersManager.h +40 -0
  122. package/platforms/ios/include/SDWebImage/SDImageTransformer.h +283 -0
  123. package/platforms/ios/include/SDWebImage/SDMemoryCache.h +78 -0
  124. package/platforms/ios/include/SDWebImage/SDWebImage.h +91 -0
  125. package/platforms/ios/include/SDWebImage/SDWebImageCacheKeyFilter.h +35 -0
  126. package/platforms/ios/include/SDWebImage/SDWebImageCacheSerializer.h +39 -0
  127. package/platforms/ios/include/SDWebImage/SDWebImageCompat.h +102 -0
  128. package/platforms/ios/include/SDWebImage/SDWebImageDefine.h +420 -0
  129. package/platforms/ios/include/SDWebImage/SDWebImageDownloader.h +320 -0
  130. package/platforms/ios/include/SDWebImage/SDWebImageDownloaderConfig.h +113 -0
  131. package/platforms/ios/include/SDWebImage/SDWebImageDownloaderDecryptor.h +52 -0
  132. package/platforms/ios/include/SDWebImage/SDWebImageDownloaderOperation.h +191 -0
  133. package/platforms/ios/include/SDWebImage/SDWebImageDownloaderRequestModifier.h +72 -0
  134. package/platforms/ios/include/SDWebImage/SDWebImageDownloaderResponseModifier.h +72 -0
  135. package/platforms/ios/include/SDWebImage/SDWebImageError.h +33 -0
  136. package/platforms/ios/include/SDWebImage/SDWebImageIndicator.h +119 -0
  137. package/platforms/ios/include/SDWebImage/SDWebImageManager.h +290 -0
  138. package/platforms/ios/include/SDWebImage/SDWebImageOperation.h +27 -0
  139. package/platforms/ios/include/SDWebImage/SDWebImageOptionsProcessor.h +78 -0
  140. package/platforms/ios/include/SDWebImage/SDWebImagePrefetcher.h +168 -0
  141. package/platforms/ios/include/SDWebImage/SDWebImageTransition.h +131 -0
  142. package/platforms/ios/include/SDWebImage/UIButton+WebCache.h +402 -0
  143. package/platforms/ios/include/SDWebImage/UIImage+ExtendedCacheData.h +24 -0
  144. package/platforms/ios/include/SDWebImage/UIImage+ForceDecode.h +52 -0
  145. package/platforms/ios/include/SDWebImage/UIImage+GIF.h +26 -0
  146. package/platforms/ios/include/SDWebImage/UIImage+MemoryCacheCost.h +27 -0
  147. package/platforms/ios/include/SDWebImage/UIImage+Metadata.h +104 -0
  148. package/platforms/ios/include/SDWebImage/UIImage+MultiFormat.h +81 -0
  149. package/platforms/ios/include/SDWebImage/UIImage+Transform.h +164 -0
  150. package/platforms/ios/include/SDWebImage/UIImageView+HighlightedWebCache.h +142 -0
  151. package/platforms/ios/include/SDWebImage/UIImageView+WebCache.h +209 -0
  152. package/platforms/ios/include/SDWebImage/UIView+WebCache.h +131 -0
  153. package/platforms/ios/include/SDWebImage/UIView+WebCacheOperation.h +52 -0
  154. package/platforms/ios/include/SDWebImage/UIView+WebCacheState.h +63 -0
  155. package/platforms/ios/include/module.modulemap +2 -0
  156. package/platforms/ios/manifest.json +132 -0
  157. package/platforms/ios/simulator-manifest.json +213 -0
  158. package/plugin-README.md +234 -0
  159. package/properties.d.ts +154 -0
  160. package/properties.js +2456 -0
  161. package/pseudo.d.ts +9 -0
  162. package/pseudo.js +57 -0
  163. package/scroll/index.android.d.ts +15 -0
  164. package/scroll/index.android.js +72 -0
  165. package/scroll/index.d.ts +5 -0
  166. package/scroll/index.ios.d.ts +18 -0
  167. package/scroll/index.ios.js +106 -0
  168. package/style.d.ts +768 -0
  169. package/style.js +7167 -0
  170. package/symbols.d.ts +25 -0
  171. package/symbols.js +41 -0
  172. package/tree/index.android.d.ts +11 -0
  173. package/tree/index.android.js +42 -0
  174. package/tree/index.d.ts +15 -0
  175. package/tree/index.ios.d.ts +26 -0
  176. package/tree/index.ios.js +53 -0
  177. package/typings/android-declarations.d.ts +4 -0
  178. package/typings/android.d.ts +9730 -0
  179. package/typings/manifest.json +45 -0
  180. package/typings/native.d.ts +5 -0
  181. package/typings/objc!FontManager.d.ts +389 -0
  182. package/typings/objc!MasonCore.d.ts +2472 -0
  183. package/typings/objc!SDWebImage.d.ts +3378 -0
  184. package/units.d.ts +29 -0
  185. package/units.js +44 -0
  186. package/utils/index.android.d.ts +211 -0
  187. package/utils/index.android.js +595 -0
  188. package/utils/index.ios.d.ts +222 -0
  189. package/utils/index.ios.js +790 -0
  190. package/view/index.android.d.ts +13 -0
  191. package/view/index.android.js +74 -0
  192. package/view/index.d.ts +2 -0
  193. package/view/index.ios.d.ts +24 -0
  194. package/view/index.ios.js +157 -0
@@ -0,0 +1,347 @@
1
+ /*
2
+ * This file is part of the SDWebImage package.
3
+ * (c) Olivier Poitrey <rs@dailymotion.com>
4
+ *
5
+ * For the full copyright and license information, please view the LICENSE
6
+ * file that was distributed with this source code.
7
+ */
8
+
9
+ #import <Foundation/Foundation.h>
10
+ #import "SDWebImageCompat.h"
11
+ #import "NSData+ImageContentType.h"
12
+ #import "SDImageFrame.h"
13
+
14
+ /// Image Decoding/Encoding Options
15
+ typedef NSString * SDImageCoderOption NS_STRING_ENUM;
16
+ typedef NSDictionary<SDImageCoderOption, id> SDImageCoderOptions;
17
+ typedef NSMutableDictionary<SDImageCoderOption, id> SDImageCoderMutableOptions;
18
+
19
+ #pragma mark - Image Decoding Options
20
+ // These options are for image decoding
21
+ /**
22
+ A Boolean value indicating whether to decode the first frame only for animated image during decoding. (NSNumber). If not provide, decode animated image if need.
23
+ @note works for `SDImageCoder`.
24
+ */
25
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderDecodeFirstFrameOnly;
26
+
27
+ /**
28
+ A CGFloat value which is greater than or equal to 1.0. This value specify the image scale factor for decoding. If not provide, use 1.0. (NSNumber)
29
+ @note works for `SDImageCoder`, `SDProgressiveImageCoder`, `SDAnimatedImageCoder`.
30
+ */
31
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderDecodeScaleFactor;
32
+
33
+ /**
34
+ A Boolean value indicating whether to keep the original aspect ratio when generating thumbnail images (or bitmap images from vector format).
35
+ Defaults to YES.
36
+ @note works for `SDImageCoder`, `SDProgressiveImageCoder`, `SDAnimatedImageCoder`.
37
+ */
38
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderDecodePreserveAspectRatio;
39
+
40
+ /**
41
+ A CGSize value indicating whether or not to generate the thumbnail images (or bitmap images from vector format). When this value is provided, the decoder will generate a thumbnail image which pixel size is smaller than or equal to (depends the `.preserveAspectRatio`) the value size.
42
+ Defaults to CGSizeZero, which means no thumbnail generation at all.
43
+ @note Supports for animated image as well.
44
+ @note When you pass `.preserveAspectRatio == NO`, the thumbnail image is stretched to match each dimension. When `.preserveAspectRatio == YES`, the thumbnail image's width is limited to pixel size's width, the thumbnail image's height is limited to pixel size's height. For common cases, you can just pass a square size to limit both.
45
+ @note works for `SDImageCoder`, `SDProgressiveImageCoder`, `SDAnimatedImageCoder`.
46
+ */
47
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderDecodeThumbnailPixelSize;
48
+
49
+ /**
50
+ A NSString value indicating the source image's file extension. Example: "jpg", "nef", "tif", don't prefix the dot
51
+ Some image file format share the same data structure but has different tag explanation, like TIFF and NEF/SRW, see https://en.wikipedia.org/wiki/TIFF
52
+ Changing the file extension cause the different image result. The coder (like ImageIO) may use file extension to choose the correct parser
53
+ @note However, different UTType may share the same file extension, like `public.jpeg` and `public.jpeg-2000` both use `.jpg`. If you want detail control, use `TypeIdentifierHint` below
54
+ */
55
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderDecodeFileExtensionHint;
56
+
57
+ /**
58
+ A NSString value (UTI) indicating the source image's file extension. Example: "public.jpeg-2000", "com.nikon.raw-image", "public.tiff"
59
+ Some image file format share the same data structure but has different tag explanation, like TIFF and NEF/SRW, see https://en.wikipedia.org/wiki/TIFF
60
+ Changing the file extension cause the different image result. The coder (like ImageIO) may use file extension to choose the correct parser
61
+ @note If you provide `TypeIdentifierHint`, the `FileExtensionHint` option above will be ignored (because UTType has high priority)
62
+ @note If you really don't want any hint which effect the image result, pass `NSNull.null` instead
63
+ */
64
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderDecodeTypeIdentifierHint;
65
+
66
+ /**
67
+ A BOOL value indicating whether to use lazy-decoding. Defaults to NO on animated image coder, but defaults to YES on static image coder.
68
+ CGImageRef, this image object typically support lazy-decoding, via the `CGDataProviderCreateDirectAccess` or `CGDataProviderCreateSequential`
69
+ Which allows you to provide a lazy-called callback to access bitmap buffer, so that you can achieve lazy-decoding when consumer actually need bitmap buffer
70
+ UIKit on iOS use heavy on this and ImageIO codec prefers to lazy-decoding for common Hardware-Accelerate format like JPEG/PNG/HEIC
71
+ But however, the consumer may access bitmap buffer when running on main queue, like CoreAnimation layer render image. So this is a trade-off
72
+ You can force us to disable the lazy-decoding and always allocate bitmap buffer on RAM, but this may have higher ratio of OOM (out of memory)
73
+ @note The default value is NO for animated image coder (means `animatedImageFrameAtIndex:`)
74
+ @note The default value is YES for static image coder (means `decodedImageWithData:`)
75
+ @note works for `SDImageCoder`, `SDProgressiveImageCoder`, `SDAnimatedImageCoder`.
76
+ */
77
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderDecodeUseLazyDecoding;
78
+
79
+ /**
80
+ A NSUInteger value to provide the limit bytes during decoding. This can help to avoid OOM on large frame count animated image or large pixel static image when you don't know how much RAM it occupied before decoding
81
+ The decoder will do these logic based on limit bytes:
82
+ 1. Get the total frame count (static image means 1)
83
+ 2. Calculate the `framePixelSize` width/height to `sqrt(limitBytes / frameCount / bytesPerPixel)`, keeping aspect ratio (at least 1x1)
84
+ 3. If the `framePixelSize < originalImagePixelSize`, then do thumbnail decoding (see `SDImageCoderDecodeThumbnailPixelSize`) use the `framePixelSize` and `preseveAspectRatio = YES`
85
+ 4. Else, use the full pixel decoding (small than limit bytes)
86
+ 5. Whatever result, this does not effect the animated/static behavior of image. So even if you set `limitBytes = 1 && frameCount = 100`, we will stll create animated image with each frame `1x1` pixel size.
87
+ @note You can use the logic from `+[SDImageCoder scaledSizeWithImageSize:limitBytes:bytesPerPixel:frameCount:]`
88
+ @note This option has higher priority than `.decodeThumbnailPixelSize`
89
+ */
90
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderDecodeScaleDownLimitBytes;
91
+
92
+ /**
93
+ A Boolean (`SDImageHDRType.rawValue`) value (stored inside NSNumber) to provide converting to HDR during decoding. Currently if number is 0 (`SDImageHDRTypeSDR`), use SDR, else use HDR. But we may extend this option to represent `SDImageHDRType` all cases in the future (means, think this options as uint number, but not actual boolean)
94
+ @note Supported by iOS 17 and above when using ImageIO coder (third-party coder can support lower firmware)
95
+ Defaults to @(NO), decoder will automatically convert SDR.
96
+ @note works for `SDImageCoder`
97
+ */
98
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderDecodeToHDR;
99
+
100
+ #pragma mark - Image Encoding Options
101
+ /**
102
+ A NSUInteger (`SDImageHDRType.rawValue`) value (stored inside NSNumber) to provide converting to HDR during encoding. Read the below carefully to choose the value.
103
+ @note 0(`SDImageHDRTypeSDR`) means SDR; 1(`SDImageHDRTypeISOHDR`) means ISO HDR (at least using 10 bits per components or above, supported by AVIF/HEIF/JPEG-XL); 2(`SDImageHDRTypeISOGainMap`) means ISO Gain Map HDR (may use 8 bits per components, supported by AVIF/HEIF/JPEG-XL, as well as traditional JPEG)
104
+ @note Gain Map like a mask image with metadata, which contains the depth/bright information for pixels (1/4 resolution), which used to convert between HDR and SDR.
105
+ @note If you use CIImage as HDR pipeline, you can export as CGImage for encoding. (But it's also recommanded to use CIImage's `JPEGRepresentationOfImage` or `HEIFRepresentationOfImage`)
106
+ @note Supported by iOS 18 and above when using ImageIO coder (third-party coder can support lower firmware)
107
+ Defaults to @(0), encoder will automatically convert SDR.
108
+ @note works for `SDImageCoder`
109
+ */
110
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderEncodeToHDR;
111
+
112
+ /**
113
+ A Boolean value indicating whether to encode the first frame only for animated image during encoding. (NSNumber). If not provide, encode animated image if need.
114
+ @note works for `SDImageCoder`.
115
+ */
116
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderEncodeFirstFrameOnly;
117
+ /**
118
+ A double value between 0.0-1.0 indicating the encode compression quality to produce the image data. 1.0 resulting in no compression and 0.0 resulting in the maximum compression possible. If not provide, use 1.0. (NSNumber)
119
+ @note works for `SDImageCoder`
120
+ */
121
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderEncodeCompressionQuality;
122
+
123
+ /**
124
+ A UIColor(NSColor) value to used for non-alpha image encoding when the input image has alpha channel, the background color will be used to compose the alpha one. If not provide, use white color.
125
+ @note works for `SDImageCoder`
126
+ */
127
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderEncodeBackgroundColor;
128
+
129
+ /**
130
+ A CGSize value indicating the max image resolution in pixels during encoding. For vector image, this also effect the output vector data information about width and height. The encoder will not generate the encoded image larger than this limit. Note it always use the aspect ratio of input image..
131
+ Defaults to CGSizeZero, which means no max size limit at all.
132
+ @note Supports for animated image as well.
133
+ @note The output image's width is limited to pixel size's width, the output image's height is limited to pixel size's height. For common cases, you can just pass a square size to limit both.
134
+ @note works for `SDImageCoder`
135
+ */
136
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderEncodeMaxPixelSize;
137
+
138
+ /**
139
+ A NSUInteger value specify the max output data bytes size after encoding. Some lossy format like JPEG/HEIF supports the hint for codec to automatically reduce the quality and match the file size you want. Note this option will override the `SDImageCoderEncodeCompressionQuality`, because now the quality is decided by the encoder. (NSNumber)
140
+ @note This is a hint, no guarantee for output size because of compression algorithm limit. And this options does not works for vector images.
141
+ @note works for `SDImageCoder`
142
+ */
143
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderEncodeMaxFileSize;
144
+
145
+ /**
146
+ A Boolean value indicating the encoding format should contains a thumbnail image into the output data. Only some of image format (like JPEG/HEIF/AVIF) support this behavior. The embed thumbnail will be used during next time thumbnail decoding (provided `.thumbnailPixelSize`), which is faster than full image thumbnail decoding. (NSNumber)
147
+ Defaults to NO, which does not embed any thumbnail.
148
+ @note The thumbnail image's pixel size is not defined, the encoder can choose the proper pixel size which is suitable for encoding quality.
149
+ @note works for `SDImageCoder`
150
+ */
151
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderEncodeEmbedThumbnail;
152
+
153
+ /**
154
+ A SDWebImageContext object which hold the original context options from top-level API. (SDWebImageContext)
155
+ This option is ignored for all built-in coders and take no effect.
156
+ But this may be useful for some custom coders, because some business logic may dependent on things other than image or image data information only.
157
+ Only the unknown context from top-level API (See SDWebImageDefine.h) may be passed in during image loading.
158
+ See `SDWebImageContext` for more detailed information.
159
+ @warning Deprecated. This does nothing from 5.14.0. Use `SDWebImageContextImageDecodeOptions` to pass additional information in top-level API, and use `SDImageCoderOptions` to retrieve options from coder.
160
+ */
161
+ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderWebImageContext API_DEPRECATED("No longer supported. Use SDWebImageContextDecodeOptions in loader API to provide options. Use SDImageCoderOptions in coder API to retrieve options.", macos(10.10, 10.10), ios(8.0, 8.0), tvos(9.0, 9.0), watchos(2.0, 2.0));
162
+
163
+ #pragma mark - Coder
164
+ /**
165
+ This is the image coder protocol to provide custom image decoding/encoding.
166
+ These methods are all required to implement.
167
+ @note Pay attention that these methods are not called from main queue.
168
+ */
169
+ @protocol SDImageCoder <NSObject>
170
+
171
+ @required
172
+ #pragma mark - Decoding
173
+ /**
174
+ Returns YES if this coder can decode some data. Otherwise, the data should be passed to another coder.
175
+
176
+ @param data The image data so we can look at it
177
+ @return YES if this coder can decode the data, NO otherwise
178
+ */
179
+ - (BOOL)canDecodeFromData:(nullable NSData *)data;
180
+
181
+ /**
182
+ Decode the image data to image.
183
+ @note This protocol may supports decode animated image frames. You can use `+[SDImageCoderHelper animatedImageWithFrames:]` to produce an animated image with frames.
184
+
185
+ @param data The image data to be decoded
186
+ @param options A dictionary containing any decoding options. Pass @{SDImageCoderDecodeScaleFactor: @(1.0)} to specify scale factor for image. Pass @{SDImageCoderDecodeFirstFrameOnly: @(YES)} to decode the first frame only.
187
+ @return The decoded image from data
188
+ */
189
+ - (nullable UIImage *)decodedImageWithData:(nullable NSData *)data
190
+ options:(nullable SDImageCoderOptions *)options;
191
+
192
+ #pragma mark - Encoding
193
+
194
+ /**
195
+ Returns YES if this coder can encode some image. Otherwise, it should be passed to another coder.
196
+ For custom coder which introduce new image format, you'd better define a new `SDImageFormat` using like this. If you're creating public coder plugin for new image format, also update `https://github.com/rs/SDWebImage/wiki/Coder-Plugin-List` to avoid same value been defined twice.
197
+ * @code
198
+ static const SDImageFormat SDImageFormatHEIF = 10;
199
+ * @endcode
200
+
201
+ @param format The image format
202
+ @return YES if this coder can encode the image, NO otherwise
203
+ */
204
+ - (BOOL)canEncodeToFormat:(SDImageFormat)format NS_SWIFT_NAME(canEncode(to:));
205
+
206
+ /**
207
+ Encode the image to image data.
208
+ @note This protocol may supports encode animated image frames. You can use `+[SDImageCoderHelper framesFromAnimatedImage:]` to assemble an animated image with frames. But this consume time is not always reversible. In 5.15.0, we introduce `encodedDataWithFrames` API for better animated image encoding. Use that instead.
209
+ @note Which means, this just forward to `encodedDataWithFrames([SDImageFrame(image: image, duration: 0], image.sd_imageLoopCount))`
210
+
211
+ @param image The image to be encoded
212
+ @param format The image format to encode, you should note `SDImageFormatUndefined` format is also possible
213
+ @param options A dictionary containing any encoding options. Pass @{SDImageCoderEncodeCompressionQuality: @(1)} to specify compression quality.
214
+ @return The encoded image data
215
+ */
216
+ - (nullable NSData *)encodedDataWithImage:(nullable UIImage *)image
217
+ format:(SDImageFormat)format
218
+ options:(nullable SDImageCoderOptions *)options;
219
+
220
+ #pragma mark - Animated Encoding
221
+ @optional
222
+ /**
223
+ Encode the animated image frames to image data.
224
+
225
+ @param frames The animated image frames to be encoded, should be at least 1 element, or it will fallback to static image encode.
226
+ @param loopCount The final animated image loop count. 0 means infinity loop. This config ignore each frame's `sd_imageLoopCount`
227
+ @param format The image format to encode, you should note `SDImageFormatUndefined` format is also possible
228
+ @param options A dictionary containing any encoding options. Pass @{SDImageCoderEncodeCompressionQuality: @(1)} to specify compression quality.
229
+ @return The encoded image data
230
+ */
231
+ - (nullable NSData *)encodedDataWithFrames:(nonnull NSArray<SDImageFrame *>*)frames
232
+ loopCount:(NSUInteger)loopCount
233
+ format:(SDImageFormat)format
234
+ options:(nullable SDImageCoderOptions *)options;
235
+ @end
236
+
237
+ #pragma mark - Progressive Coder
238
+ /**
239
+ This is the image coder protocol to provide custom progressive image decoding.
240
+ These methods are all required to implement.
241
+ @note Pay attention that these methods are not called from main queue.
242
+ */
243
+ @protocol SDProgressiveImageCoder <SDImageCoder>
244
+
245
+ @required
246
+ /**
247
+ Returns YES if this coder can incremental decode some data. Otherwise, it should be passed to another coder.
248
+
249
+ @param data The image data so we can look at it
250
+ @return YES if this coder can decode the data, NO otherwise
251
+ */
252
+ - (BOOL)canIncrementalDecodeFromData:(nullable NSData *)data;
253
+
254
+ /**
255
+ Because incremental decoding need to keep the decoded context, we will alloc a new instance with the same class for each download operation to avoid conflicts
256
+ This init method should not return nil
257
+
258
+ @param options A dictionary containing any progressive decoding options (instance-level). Pass @{SDImageCoderDecodeScaleFactor: @(1.0)} to specify scale factor for progressive animated image (each frames should use the same scale).
259
+ @return A new instance to do incremental decoding for the specify image format
260
+ */
261
+ - (nonnull instancetype)initIncrementalWithOptions:(nullable SDImageCoderOptions *)options;
262
+
263
+ /**
264
+ Update the incremental decoding when new image data available
265
+
266
+ @param data The image data has been downloaded so far
267
+ @param finished Whether the download has finished
268
+ */
269
+ - (void)updateIncrementalData:(nullable NSData *)data finished:(BOOL)finished;
270
+
271
+ /**
272
+ Incremental decode the current image data to image.
273
+ @note Due to the performance issue for progressive decoding and the integration for image view. This method may only return the first frame image even if the image data is animated image. If you want progressive animated image decoding, conform to `SDAnimatedImageCoder` protocol as well and use `animatedImageFrameAtIndex:` instead.
274
+
275
+ @param options A dictionary containing any progressive decoding options. Pass @{SDImageCoderDecodeScaleFactor: @(1.0)} to specify scale factor for progressive image
276
+ @return The decoded image from current data
277
+ */
278
+ - (nullable UIImage *)incrementalDecodedImageWithOptions:(nullable SDImageCoderOptions *)options;
279
+
280
+ @end
281
+
282
+ #pragma mark - Animated Image Provider
283
+ /**
284
+ This is the animated image protocol to provide the basic function for animated image rendering. It's adopted by `SDAnimatedImage` and `SDAnimatedImageCoder`
285
+ */
286
+ @protocol SDAnimatedImageProvider <NSObject>
287
+
288
+ @required
289
+ /**
290
+ The original animated image data for current image. If current image is not an animated format, return nil.
291
+ We may use this method to grab back the original image data if need, such as NSCoding or compare.
292
+
293
+ @return The animated image data
294
+ */
295
+ @property (nonatomic, copy, readonly, nullable) NSData *animatedImageData;
296
+
297
+ /**
298
+ Total animated frame count.
299
+ If the frame count is less than 1, then the methods below will be ignored.
300
+
301
+ @return Total animated frame count.
302
+ */
303
+ @property (nonatomic, assign, readonly) NSUInteger animatedImageFrameCount;
304
+ /**
305
+ Animation loop count, 0 means infinite looping.
306
+
307
+ @return Animation loop count
308
+ */
309
+ @property (nonatomic, assign, readonly) NSUInteger animatedImageLoopCount;
310
+ /**
311
+ Returns the frame image from a specified index.
312
+ @note The index maybe randomly if one image was set to different imageViews, keep it re-entrant. (It's not recommend to store the images into array because it's memory consuming)
313
+
314
+ @param index Frame index (zero based).
315
+ @return Frame's image
316
+ */
317
+ - (nullable UIImage *)animatedImageFrameAtIndex:(NSUInteger)index;
318
+ /**
319
+ Returns the frames's duration from a specified index.
320
+ @note The index maybe randomly if one image was set to different imageViews, keep it re-entrant. (It's recommend to store the durations into array because it's not memory-consuming)
321
+
322
+ @param index Frame index (zero based).
323
+ @return Frame's duration
324
+ */
325
+ - (NSTimeInterval)animatedImageDurationAtIndex:(NSUInteger)index;
326
+
327
+ @end
328
+
329
+ #pragma mark - Animated Coder
330
+ /**
331
+ This is the animated image coder protocol for custom animated image class like `SDAnimatedImage`. Through it inherit from `SDImageCoder`. We currentlly only use the method `canDecodeFromData:` to detect the proper coder for specify animated image format.
332
+ */
333
+ @protocol SDAnimatedImageCoder <SDImageCoder, SDAnimatedImageProvider>
334
+
335
+ @required
336
+ /**
337
+ Because animated image coder should keep the original data, we will alloc a new instance with the same class for the specify animated image data
338
+ The init method should return nil if it can't decode the specify animated image data to produce any frame.
339
+ After the instance created, we may call methods in `SDAnimatedImageProvider` to produce animated image frame.
340
+
341
+ @param data The animated image data to be decode
342
+ @param options A dictionary containing any animated decoding options (instance-level). Pass @{SDImageCoderDecodeScaleFactor: @(1.0)} to specify scale factor for animated image (each frames should use the same scale).
343
+ @return A new instance to do animated decoding for specify image data
344
+ */
345
+ - (nullable instancetype)initWithAnimatedImageData:(nullable NSData *)data options:(nullable SDImageCoderOptions *)options;
346
+
347
+ @end
@@ -0,0 +1,251 @@
1
+ /*
2
+ * This file is part of the SDWebImage package.
3
+ * (c) Olivier Poitrey <rs@dailymotion.com>
4
+ *
5
+ * For the full copyright and license information, please view the LICENSE
6
+ * file that was distributed with this source code.
7
+ */
8
+
9
+ #import <ImageIO/ImageIO.h>
10
+ #import "SDWebImageCompat.h"
11
+ #import "SDImageFrame.h"
12
+
13
+ /// The options controls how we force pre-draw the image (to avoid lazy-decoding). Which need OS's framework compatibility
14
+ typedef NS_ENUM(NSUInteger, SDImageCoderDecodeSolution) {
15
+ /// automatically choose the solution based on image format, hardware, OS version. This keep balance for compatibility and performance. Default after SDWebImage 5.13.0
16
+ SDImageCoderDecodeSolutionAutomatic,
17
+ /// always use CoreGraphics to draw on bitmap context and trigger decode. Best compatibility. Default before SDWebImage 5.13.0
18
+ SDImageCoderDecodeSolutionCoreGraphics,
19
+ /// available on iOS/tvOS 15+, use UIKit's new CGImageDecompressor/CMPhoto to decode. Best performance. If failed, will fallback to CoreGraphics as well
20
+ SDImageCoderDecodeSolutionUIKit
21
+ };
22
+
23
+ /// The policy to force-decode the origin CGImage (produced by Image Coder Plugin)
24
+ /// Some CGImage may be lazy, or not lazy, but need extra copy to render on screen
25
+ /// The force-decode step help to `pre-process` to get the best suitable CGImage to render, which can increase frame rate
26
+ /// The downside is that force-decode may consume RAM and CPU, and may loss the `lazy` support (lazy CGImage can be purged when memory warning, and re-created if need), see more: `SDImageCoderDecodeUseLazyDecoding`
27
+ typedef NS_ENUM(NSUInteger, SDImageForceDecodePolicy) {
28
+ /// Based on input CGImage's colorspace, alignment, bitmapinfo, if it may trigger `CA::copy_image` extra copy, we will force-decode, else don't
29
+ SDImageForceDecodePolicyAutomatic,
30
+ /// Never force decode input CGImage
31
+ SDImageForceDecodePolicyNever,
32
+ /// Always force decode input CGImage (only once)
33
+ SDImageForceDecodePolicyAlways
34
+ };
35
+
36
+ /// These enum is used to represent the High Dynamic Range type during image encoding/decoding.
37
+ /// There are alao other HDR type in history before ISO Standard (ISO 21496-1), including Google and Apple's old OSs captured photos, but which is non-standard and we do not support.
38
+ typedef NS_ENUM(NSUInteger, SDImageHDRType) {
39
+ /// SDR, mostly only 8 bits color per components, RGBA8
40
+ SDImageHDRTypeSDR = 0,
41
+ /// ISO HDR (supported by modern format only, like HEIF/AVIF/JPEG-XL)
42
+ SDImageHDRTypeISOHDR = 1,
43
+ /// ISO Gain Map based HDR (supported by nearly all format, including tranditional JPEG, which stored the gain map into XMP)
44
+ SDImageHDRTypeISOGainMap = 2,
45
+ };
46
+
47
+ /// Byte alignment the bytes size with alignment
48
+ /// - Parameters:
49
+ /// - size: The bytes size
50
+ /// - alignment: The alignment, in bytes
51
+ static inline size_t SDByteAlign(size_t size, size_t alignment) {
52
+ return ((size + (alignment - 1)) / alignment) * alignment;
53
+ }
54
+
55
+ /// The pixel format about the information to call `CGImageCreate` suitable for current hardware rendering
56
+ typedef struct SDImagePixelFormat {
57
+ /// Typically is pre-multiplied RGBA8888 for alpha image, RGBX8888 for non-alpha image.
58
+ CGBitmapInfo bitmapInfo;
59
+ /// Typically is 32, the 8 pixels bytesPerRow.
60
+ size_t alignment;
61
+ } SDImagePixelFormat;
62
+
63
+ /**
64
+ Provide some common helper methods for building the image decoder/encoder.
65
+ */
66
+ @interface SDImageCoderHelper : NSObject
67
+
68
+ /**
69
+ Return an animated image with frames array.
70
+ For UIKit, this will apply the patch and then create animated UIImage. The patch is because that `+[UIImage animatedImageWithImages:duration:]` just use the average of duration for each image. So it will not work if different frame has different duration. Therefore we repeat the specify frame for specify times to let it work.
71
+ For AppKit before macOS 10.13, NSImage does not support animates other than GIF. This will try to encode the frames to GIF format and then create an animated NSImage for rendering. Attention the animated image may loss some detail if the input frames contain full alpha channel because GIF only supports 1 bit alpha channel. (For 1 pixel, either transparent or not)
72
+ For AppKit after macOS 10.14, use APNG format, which has a better render result.
73
+
74
+ @param frames The frames array. If no frames or frames is empty, return nil
75
+ @return A animated image for rendering on UIImageView(UIKit) or NSImageView(AppKit)
76
+ */
77
+ + (UIImage * _Nullable)animatedImageWithFrames:(NSArray<SDImageFrame *> * _Nullable)frames;
78
+
79
+ /**
80
+ Return frames array from an animated image.
81
+ For UIKit, this will unapply the patch for the description above and then create frames array. This will also work for normal animated UIImage.
82
+ For AppKit, NSImage does not support animates other than GIF. This will try to decode the GIF imageRep and then create frames array.
83
+
84
+ @param animatedImage A animated image. If it's not animated, return nil
85
+ @return The frames array
86
+ */
87
+ + (NSArray<SDImageFrame *> * _Nullable)framesFromAnimatedImage:(UIImage * _Nullable)animatedImage NS_SWIFT_NAME(frames(from:));
88
+
89
+ #pragma mark - Preferred Rendering Format
90
+ /// For coders who use `CGImageCreate`, use the information below to create an effient CGImage which can be render on GPU without Core Animation's extra copy (`CA::Render::copy_image`), which can be debugged using `Color Copied Image` in Xcode Instruments
91
+ /// `CGImageCreate`'s `bytesPerRow`, `space`, `bitmapInfo` params should use the information below.
92
+ /**
93
+ Return the shared device-dependent RGB color space. This follows The Get Rule.
94
+ Because it's shared, you should not retain or release this object.
95
+ Typically is sRGB for iOS, screen color space (like Color LCD) for macOS.
96
+
97
+ @return The device-dependent RGB color space
98
+ */
99
+ + (CGColorSpaceRef _Nonnull)colorSpaceGetDeviceRGB CF_RETURNS_NOT_RETAINED;
100
+
101
+ /**
102
+ Tthis returns the pixel format **Preferred from current hardward && OS using runtime detection**
103
+ @param containsAlpha Whether the image to render contains alpha channel
104
+ */
105
+ + (SDImagePixelFormat)preferredPixelFormat:(BOOL)containsAlpha;
106
+
107
+ /**
108
+ Check whether CGImage is hardware supported to rendering on screen, without the trigger of `CA::Render::copy_image`
109
+ You can debug the copied image by using Xcode's `Color Copied Image`, the copied image will turn Cyan and occupy double RAM for bitmap buffer.
110
+ Typically, when the CGImage's using the method above (`colorspace` / `alignment` / `bitmapInfo`) can render withtout the copy.
111
+ */
112
+ + (BOOL)CGImageIsHardwareSupported:(_Nonnull CGImageRef)cgImage;
113
+
114
+ /**
115
+ Check whether CGImage contains alpha channel.
116
+
117
+ @param cgImage The CGImage
118
+ @return Return YES if CGImage contains alpha channel, otherwise return NO
119
+ */
120
+ + (BOOL)CGImageContainsAlpha:(_Nonnull CGImageRef)cgImage;
121
+
122
+ /**
123
+ Detect whether the CGImage is lazy and not-yet decoded. (lazy means, only when the caller access the underlying bitmap buffer via provider like `CGDataProviderCopyData` or `CGDataProviderRetainBytePtr`, the decoder will allocate memory, it's a lazy allocation)
124
+ The implementation use the Core Graphics internal to check whether the CGImage is `CGImageProvider` based, or `CGDataProvider` based. The `CGDataProvider` based is treated as non-lazy.
125
+ */
126
+ + (BOOL)CGImageIsLazy:(_Nonnull CGImageRef)cgImage;
127
+
128
+ /**
129
+ Check if the CGImage is using HDR color space.
130
+ @note This use the same implementation like Apple, to checkl if color space uses transfer functions defined in ITU Rec.2100
131
+ */
132
+ + (BOOL)CGImageIsHDR:(_Nonnull CGImageRef)cgImage;
133
+
134
+ /**
135
+ Create a decoded CGImage by the provided CGImage. This follows The Create Rule and you are response to call release after usage.
136
+ It will detect whether image contains alpha channel, then create a new bitmap context with the same size of image, and draw it. This can ensure that the image do not need extra decoding after been set to the imageView.
137
+ @note This actually call `CGImageCreateDecoded:orientation:` with the Up orientation.
138
+
139
+ @param cgImage The CGImage
140
+ @return A new created decoded image
141
+ */
142
+ + (CGImageRef _Nullable)CGImageCreateDecoded:(_Nonnull CGImageRef)cgImage CF_RETURNS_RETAINED;
143
+
144
+ /**
145
+ Create a decoded CGImage by the provided CGImage and orientation. This follows The Create Rule and you are response to call release after usage.
146
+ It will detect whether image contains alpha channel, then create a new bitmap context with the same size of image, and draw it. This can ensure that the image do not need extra decoding after been set to the imageView.
147
+
148
+ @param cgImage The CGImage
149
+ @param orientation The EXIF image orientation.
150
+ @return A new created decoded image
151
+ */
152
+ + (CGImageRef _Nullable)CGImageCreateDecoded:(_Nonnull CGImageRef)cgImage orientation:(CGImagePropertyOrientation)orientation CF_RETURNS_RETAINED;
153
+
154
+ /**
155
+ Create a scaled CGImage by the provided CGImage and size. This follows The Create Rule and you are response to call release after usage.
156
+ It will detect whether the image size matching the scale size, if not, stretch the image to the target size.
157
+ @note If you need to keep aspect ratio, you can calculate the scale size by using `scaledSizeWithImageSize` first.
158
+ @note This scale does not change bits per components (which means RGB888 in, RGB888 out), supports 8/16/32(float) bpc. But the method in UIImage+Transform does not gurantee this.
159
+ @note All supported CGImage pixel format: https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_context/dq_context.html#//apple_ref/doc/uid/TP30001066-CH203-BCIBHHBB
160
+
161
+ @param cgImage The CGImage
162
+ @param size The scale size in pixel.
163
+ @return A new created scaled image
164
+ */
165
+ + (CGImageRef _Nullable)CGImageCreateScaled:(_Nonnull CGImageRef)cgImage size:(CGSize)size CF_RETURNS_RETAINED;
166
+
167
+ /** Scale the image size based on provided scale size, whether or not to preserve aspect ratio, whether or not to scale up.
168
+ @note For example, if you implements thumnail decoding, pass `shouldScaleUp` to NO to avoid the calculated size larger than image size.
169
+
170
+ @param imageSize The image size (in pixel or point defined by caller)
171
+ @param scaleSize The scale size (in pixel or point defined by caller)
172
+ @param preserveAspectRatio Whether or not to preserve aspect ratio
173
+ @param shouldScaleUp Whether or not to scale up (or scale down only)
174
+ */
175
+ + (CGSize)scaledSizeWithImageSize:(CGSize)imageSize scaleSize:(CGSize)scaleSize preserveAspectRatio:(BOOL)preserveAspectRatio shouldScaleUp:(BOOL)shouldScaleUp;
176
+
177
+ /// Calculate the limited image size with the bytes, when using `SDImageCoderDecodeScaleDownLimitBytes`. This preserve aspect ratio and never scale up
178
+ /// @param imageSize The image size (in pixel or point defined by caller)
179
+ /// @param limitBytes The limit bytes
180
+ /// @param bytesPerPixel The bytes per pixel
181
+ /// @param frameCount The image frame count, 0 means 1 frame as well
182
+ + (CGSize)scaledSizeWithImageSize:(CGSize)imageSize limitBytes:(NSUInteger)limitBytes bytesPerPixel:(NSUInteger)bytesPerPixel frameCount:(NSUInteger)frameCount;
183
+ /**
184
+ Return the decoded image by the provided image. This one unlike `CGImageCreateDecoded:`, will not decode the image which contains alpha channel or animated image. On iOS 15+, this may use `UIImage.preparingForDisplay()` to use CMPhoto for better performance than the old solution.
185
+ @param image The image to be decoded
186
+ @note This translate to `decodedImageWithImage:policy:` with automatic policy
187
+ @return The decoded image
188
+ */
189
+ + (UIImage * _Nullable)decodedImageWithImage:(UIImage * _Nullable)image;
190
+
191
+ /**
192
+ Return the decoded image by the provided image. This one unlike `CGImageCreateDecoded:`, will not decode the image which contains alpha channel or animated image. On iOS 15+, this may use `UIImage.preparingForDisplay()` to use CMPhoto for better performance than the old solution.
193
+ @param image The image to be decoded
194
+ @param policy The force decode policy to decode image, will effect the check whether input image need decode
195
+ @return The decoded image
196
+ */
197
+ + (UIImage * _Nullable)decodedImageWithImage:(UIImage * _Nullable)image policy:(SDImageForceDecodePolicy)policy;
198
+
199
+ /**
200
+ Return the decoded and probably scaled down image by the provided image. If the image pixels bytes size large than the limit bytes, will try to scale down. Or just works as `decodedImageWithImage:`, never scale up.
201
+ @warning You should not pass too small bytes, the suggestion value should be larger than 1MB. Even we use Tile Decoding to avoid OOM, however, small bytes will consume much more CPU time because we need to iterate more times to draw each tile.
202
+
203
+ @param image The image to be decoded and scaled down
204
+ @param bytes The limit bytes size. Provide 0 to use the build-in limit.
205
+ @note This translate to `decodedAndScaledDownImageWithImage:limitBytes:policy:` with automatic policy
206
+ @return The decoded and probably scaled down image
207
+ */
208
+ + (UIImage * _Nullable)decodedAndScaledDownImageWithImage:(UIImage * _Nullable)image limitBytes:(NSUInteger)bytes;
209
+
210
+ /**
211
+ Return the decoded and probably scaled down image by the provided image. If the image pixels bytes size large than the limit bytes, will try to scale down. Or just works as `decodedImageWithImage:`, never scale up.
212
+ @warning You should not pass too small bytes, the suggestion value should be larger than 1MB. Even we use Tile Decoding to avoid OOM, however, small bytes will consume much more CPU time because we need to iterate more times to draw each tile.
213
+
214
+ @param image The image to be decoded and scaled down
215
+ @param bytes The limit bytes size. Provide 0 to use the build-in limit.
216
+ @param policy The force decode policy to decode image, will effect the check whether input image need decode
217
+ @return The decoded and probably scaled down image
218
+ */
219
+ + (UIImage * _Nullable)decodedAndScaledDownImageWithImage:(UIImage * _Nullable)image limitBytes:(NSUInteger)bytes policy:(SDImageForceDecodePolicy)policy;
220
+
221
+ /**
222
+ Control the default force decode solution. Available solutions in `SDImageCoderDecodeSolution`.
223
+ @note Defaults to `SDImageCoderDecodeSolutionAutomatic`, which prefers to use UIKit for JPEG/HEIF, and fallback on CoreGraphics. If you want control on your hand, set the other solution.
224
+ */
225
+ @property (class, readwrite) SDImageCoderDecodeSolution defaultDecodeSolution;
226
+
227
+ /**
228
+ Control the default limit bytes to scale down largest images.
229
+ This value must be larger than 4 Bytes (at least 1x1 pixel). Defaults to 60MB on iOS/tvOS, 90MB on macOS, 30MB on watchOS.
230
+ */
231
+ @property (class, readwrite) NSUInteger defaultScaleDownLimitBytes;
232
+
233
+ #if SD_UIKIT || SD_WATCH
234
+ /**
235
+ Convert an EXIF image orientation to an iOS one.
236
+
237
+ @param exifOrientation EXIF orientation
238
+ @return iOS orientation
239
+ */
240
+ + (UIImageOrientation)imageOrientationFromEXIFOrientation:(CGImagePropertyOrientation)exifOrientation NS_SWIFT_NAME(imageOrientation(from:));
241
+
242
+ /**
243
+ Convert an iOS orientation to an EXIF image orientation.
244
+
245
+ @param imageOrientation iOS orientation
246
+ @return EXIF orientation
247
+ */
248
+ + (CGImagePropertyOrientation)exifOrientationFromImageOrientation:(UIImageOrientation)imageOrientation;
249
+ #endif
250
+
251
+ @end
@@ -0,0 +1,58 @@
1
+ /*
2
+ * This file is part of the SDWebImage package.
3
+ * (c) Olivier Poitrey <rs@dailymotion.com>
4
+ *
5
+ * For the full copyright and license information, please view the LICENSE
6
+ * file that was distributed with this source code.
7
+ */
8
+
9
+ #import <Foundation/Foundation.h>
10
+ #import "SDImageCoder.h"
11
+
12
+ /**
13
+ Global object holding the array of coders, so that we avoid passing them from object to object.
14
+ Uses a priority queue behind scenes, which means the latest added coders have the highest priority.
15
+ This is done so when encoding/decoding something, we go through the list and ask each coder if they can handle the current data.
16
+ That way, users can add their custom coders while preserving our existing prebuilt ones
17
+
18
+ Note: the `coders` getter will return the coders in their reversed order
19
+ Example:
20
+ - by default we internally set coders = `IOCoder`, `GIFCoder`, `APNGCoder`
21
+ - calling `coders` will return `@[IOCoder, GIFCoder, APNGCoder]`
22
+ - call `[addCoder:[MyCrazyCoder new]]`
23
+ - calling `coders` now returns `@[IOCoder, GIFCoder, APNGCoder, MyCrazyCoder]`
24
+
25
+ Coders
26
+ ------
27
+ A coder must conform to the `SDImageCoder` protocol or even to `SDProgressiveImageCoder` if it supports progressive decoding
28
+ Conformance is important because that way, they will implement `canDecodeFromData` or `canEncodeToFormat`
29
+ Those methods are called on each coder in the array (using the priority order) until one of them returns YES.
30
+ That means that coder can decode that data / encode to that format
31
+ */
32
+ @interface SDImageCodersManager : NSObject <SDImageCoder>
33
+
34
+ /**
35
+ Returns the global shared coders manager instance.
36
+ */
37
+ @property (nonatomic, class, readonly, nonnull) SDImageCodersManager *sharedManager;
38
+
39
+ /**
40
+ All coders in coders manager. The coders array is a priority queue, which means the later added coder will have the highest priority
41
+ */
42
+ @property (nonatomic, copy, nullable) NSArray<id<SDImageCoder>> *coders;
43
+
44
+ /**
45
+ Add a new coder to the end of coders array. Which has the highest priority.
46
+
47
+ @param coder coder
48
+ */
49
+ - (void)addCoder:(nonnull id<SDImageCoder>)coder;
50
+
51
+ /**
52
+ Remove a coder in the coders array.
53
+
54
+ @param coder coder
55
+ */
56
+ - (void)removeCoder:(nonnull id<SDImageCoder>)coder;
57
+
58
+ @end