@@ -94,6 +94,13 @@ static inline BOOL SDImageSupportsHardwareHEVCDecoder(void) {
94
94
95
95
static const CGFloat kDestSeemOverlap = 2 .0f ; // the numbers of pixels to overlap the seems where tiles meet.
96
96
97
+ #if SD_MAC
98
+ @interface SDAnimatedImageRep (Private)
99
+ // / This wrap the animated image frames for legacy animated image coder API (`encodedDataWithImage:`).
100
+ @property (nonatomic , readwrite , weak ) NSArray <SDImageFrame *> *frames;
101
+ @end
102
+ #endif
103
+
97
104
@implementation SDImageCoderHelper
98
105
99
106
+ (UIImage *)animatedImageWithFrames : (NSArray <SDImageFrame *> *)frames {
@@ -159,6 +166,7 @@ + (UIImage *)animatedImageWithFrames:(NSArray<SDImageFrame *> *)frames {
159
166
SDAnimatedImageRep *imageRep = [[SDAnimatedImageRep alloc ] initWithData: imageData];
160
167
NSSize size = NSMakeSize (imageRep.pixelsWide / scale, imageRep.pixelsHigh / scale);
161
168
imageRep.size = size;
169
+ imageRep.frames = frames; // Weak assign to avoid effect lazy semantic of NSBitmapImageRep
162
170
animatedImage = [[NSImage alloc ] initWithSize: size];
163
171
[animatedImage addRepresentation: imageRep];
164
172
#endif
@@ -211,6 +219,14 @@ + (UIImage *)animatedImageWithFrames:(NSArray<SDImageFrame *> *)frames {
211
219
212
220
NSRect imageRect = NSMakeRect (0 , 0 , animatedImage.size .width , animatedImage.size .height );
213
221
NSImageRep *imageRep = [animatedImage bestRepresentationForRect: imageRect context: nil hints: nil ];
222
+ // Check weak assigned frames firstly
223
+ if ([imageRep isKindOfClass: [SDAnimatedImageRep class ]]) {
224
+ SDAnimatedImageRep *animatedImageRep = (SDAnimatedImageRep *)imageRep;
225
+ if (animatedImageRep.frames ) {
226
+ return animatedImageRep.frames ;
227
+ }
228
+ }
229
+
214
230
NSBitmapImageRep *bitmapImageRep;
215
231
if ([imageRep isKindOfClass: [NSBitmapImageRep class ]]) {
216
232
bitmapImageRep = (NSBitmapImageRep *)imageRep;
0 commit comments