|
12 | 12 |
|
13 | 13 | static NSData * SDYYPluginCacheDataWithImageData(UIImage *image, NSData *imageData) {
|
14 | 14 | NSData *data = imageData;
|
| 15 | + if (!data && [image conformsToProtocol:@protocol(SDAnimatedImage)]) { |
| 16 | + // If image is custom animated image class, prefer its original animated data |
| 17 | + data = [((id<SDAnimatedImage>)image) animatedImageData]; |
| 18 | + } |
15 | 19 | if (!data && image) {
|
16 |
| - // If we do not have any data to detect image format, check whether it contains alpha channel to use PNG or JPEG format |
17 |
| - SDImageFormat format; |
18 |
| - if ([SDImageCoderHelper CGImageContainsAlpha:image.CGImage]) { |
19 |
| - format = SDImageFormatPNG; |
20 |
| - } else { |
21 |
| - format = SDImageFormatJPEG; |
| 20 | + // Check image's associated image format, may return .undefined |
| 21 | + SDImageFormat format = image.sd_imageFormat; |
| 22 | + if (format == SDImageFormatUndefined) { |
| 23 | + // If image is animated, use GIF (APNG may be better, but has bugs before macOS 10.14) |
| 24 | + if (image.sd_isAnimated) { |
| 25 | + format = SDImageFormatGIF; |
| 26 | + } else { |
| 27 | + // If we do not have any data to detect image format, check whether it contains alpha channel to use PNG or JPEG format |
| 28 | + if ([SDImageCoderHelper CGImageContainsAlpha:image.CGImage]) { |
| 29 | + format = SDImageFormatPNG; |
| 30 | + } else { |
| 31 | + format = SDImageFormatJPEG; |
| 32 | + } |
| 33 | + } |
22 | 34 | }
|
23 | 35 | data = [[SDImageCodersManager sharedManager] encodedDataWithImage:image format:format options:nil];
|
24 | 36 | }
|
@@ -116,7 +128,10 @@ @implementation YYCache (SDAdditions)
|
116 | 128 | }
|
117 | 129 | } else {
|
118 | 130 | @try {
|
| 131 | +#pragma clang diagnostic push |
| 132 | +#pragma clang diagnostic ignored "-Wdeprecated-declarations" |
119 | 133 | extendedObject = [NSKeyedUnarchiver unarchiveObjectWithData:extendedData];
|
| 134 | +#pragma clang diagnostic pop |
120 | 135 | } @catch (NSException *exception) {
|
121 | 136 | NSLog(@"NSKeyedUnarchiver unarchive failed with exception: %@", exception);
|
122 | 137 | }
|
@@ -183,7 +198,10 @@ - (void)storeImageToDisk:(UIImage *)image imageData:(NSData *)imageData forKey:(
|
183 | 198 | }
|
184 | 199 | } else {
|
185 | 200 | @try {
|
| 201 | +#pragma clang diagnostic push |
| 202 | +#pragma clang diagnostic ignored "-Wdeprecated-declarations" |
186 | 203 | extendedData = [NSKeyedArchiver archivedDataWithRootObject:extendedObject];
|
| 204 | +#pragma clang diagnostic pop |
187 | 205 | } @catch (NSException *exception) {
|
188 | 206 | NSLog(@"NSKeyedArchiver archive failed with exception: %@", exception);
|
189 | 207 | }
|
|
0 commit comments