From c9dffc64dcd355a0ec7ae3bedb76e142a89a73f9 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sun, 5 Jan 2020 22:40:51 +0800 Subject: [PATCH] Fix the compile issue on macOS. Fix the animated frame force decode issue on macOS --- SDWebImage/Core/SDImageCacheDefine.m | 2 ++ SDWebImage/Core/SDImageIOAnimatedCoder.m | 15 ++++++++++++--- SDWebImage/Core/SDImageLoader.m | 4 ++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/SDWebImage/Core/SDImageCacheDefine.m b/SDWebImage/Core/SDImageCacheDefine.m index 0a3afbe5..d13c3c39 100644 --- a/SDWebImage/Core/SDImageCacheDefine.m +++ b/SDWebImage/Core/SDImageCacheDefine.m @@ -20,12 +20,14 @@ UIImage * _Nullable SDImageCacheDecodeImageData(NSData * _Nonnull imageData, NSS CGFloat scale = scaleValue.doubleValue >= 1 ? scaleValue.doubleValue : SDImageScaleFactorForKey(cacheKey); NSNumber *preserveAspectRatioValue = context[SDWebImageContextImagePreserveAspectRatio]; NSValue *thumbnailSizeValue; +#if SD_UIKIT || SD_WATCH BOOL shouldScaleDown = SD_OPTIONS_CONTAINS(options, SDWebImageScaleDownLargeImages); if (shouldScaleDown) { CGFloat thumbnailPixels = SDImageCoderHelper.defaultScaleDownLimitBytes / 4; CGFloat dimension = ceil(sqrt(thumbnailPixels)); thumbnailSizeValue = @(CGSizeMake(dimension, dimension)); } +#endif if (context[SDWebImageContextImageThumbnailPixelSize]) { thumbnailSizeValue = context[SDWebImageContextImageThumbnailPixelSize]; } diff --git a/SDWebImage/Core/SDImageIOAnimatedCoder.m b/SDWebImage/Core/SDImageIOAnimatedCoder.m index eaa42688..ea9a7c25 100644 --- a/SDWebImage/Core/SDImageIOAnimatedCoder.m +++ b/SDWebImage/Core/SDImageIOAnimatedCoder.m @@ -12,6 +12,7 @@ #import "NSData+ImageContentType.h" #import "SDImageCoderHelper.h" #import "SDAnimatedImageRep.h" +#import "UIImage+ForceDecode.h" @interface SDImageIOCoderFrame : NSObject @@ -502,11 +503,19 @@ if (!image) { return nil; } + image.sd_imageFormat = self.class.imageFormat; // Image/IO create CGImage does not decode, so we do this because this is called background queue, this can avoid main queue block when rendering(especially when one more imageViews use the same image instance) - UIImage *decodedImage = [SDImageCoderHelper decodedImageWithImage:image]; - if (decodedImage) { - image = decodedImage; + CGImageRef imageRef = [SDImageCoderHelper CGImageCreateDecoded:image.CGImage]; + if (!imageRef) { + return image; } +#if SD_MAC + image = [[UIImage alloc] initWithCGImage:imageRef scale:_scale orientation:kCGImagePropertyOrientationUp]; +#else + image = [[UIImage alloc] initWithCGImage:imageRef scale:_scale orientation:image.imageOrientation]; +#endif + CGImageRelease(imageRef); + image.sd_isDecoded = YES; image.sd_imageFormat = self.class.imageFormat; return image; } diff --git a/SDWebImage/Core/SDImageLoader.m b/SDWebImage/Core/SDImageLoader.m index 4c831c59..2bd48b15 100644 --- a/SDWebImage/Core/SDImageLoader.m +++ b/SDWebImage/Core/SDImageLoader.m @@ -34,12 +34,14 @@ UIImage * _Nullable SDImageLoaderDecodeImageData(NSData * _Nonnull imageData, NS CGFloat scale = scaleValue.doubleValue >= 1 ? scaleValue.doubleValue : SDImageScaleFactorForKey(cacheKey); NSNumber *preserveAspectRatioValue = context[SDWebImageContextImagePreserveAspectRatio]; NSValue *thumbnailSizeValue; +#if SD_UIKIT || SD_WATCH BOOL shouldScaleDown = SD_OPTIONS_CONTAINS(options, SDWebImageScaleDownLargeImages); if (shouldScaleDown) { CGFloat thumbnailPixels = SDImageCoderHelper.defaultScaleDownLimitBytes / 4; CGFloat dimension = ceil(sqrt(thumbnailPixels)); thumbnailSizeValue = @(CGSizeMake(dimension, dimension)); } +#endif if (context[SDWebImageContextImageThumbnailPixelSize]) { thumbnailSizeValue = context[SDWebImageContextImageThumbnailPixelSize]; } @@ -109,12 +111,14 @@ UIImage * _Nullable SDImageLoaderDecodeProgressiveImageData(NSData * _Nonnull im CGFloat scale = scaleValue.doubleValue >= 1 ? scaleValue.doubleValue : SDImageScaleFactorForKey(cacheKey); NSNumber *preserveAspectRatioValue = context[SDWebImageContextImagePreserveAspectRatio]; NSValue *thumbnailSizeValue; +#if SD_UIKIT || SD_WATCH BOOL shouldScaleDown = SD_OPTIONS_CONTAINS(options, SDWebImageScaleDownLargeImages); if (shouldScaleDown) { CGFloat thumbnailPixels = SDImageCoderHelper.defaultScaleDownLimitBytes / 4; CGFloat dimension = ceil(sqrt(thumbnailPixels)); thumbnailSizeValue = @(CGSizeMake(dimension, dimension)); } +#endif if (context[SDWebImageContextImageThumbnailPixelSize]) { thumbnailSizeValue = context[SDWebImageContextImageThumbnailPixelSize]; }