From 9c124435b69c0b384aa1ad6f780d32cb7173196f Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Thu, 4 Jan 2018 20:59:21 +0800 Subject: [PATCH 01/10] Move the imageLoopCount and isAnimated into UIImage+WebCache file, removed the outdated methods --- SDWebImage.xcodeproj/project.pbxproj | 28 +++++++++++ SDWebImage/NSImage+WebCache.h | 9 ++-- SDWebImage/NSImage+WebCache.m | 15 +----- SDWebImage/SDWebImageCompat.m | 2 +- SDWebImage/SDWebImageFrame.h | 2 +- SDWebImage/SDWebImageGIFCoder.m | 2 +- SDWebImage/SDWebImageWebPCoder.m | 2 +- SDWebImage/UIImage+GIF.h | 7 +-- SDWebImage/UIImage+GIF.m | 5 -- SDWebImage/UIImage+MultiFormat.h | 12 ----- SDWebImage/UIImage+MultiFormat.m | 42 ---------------- SDWebImage/UIImage+WebCache.h | 32 +++++++++++++ SDWebImage/UIImage+WebCache.m | 71 ++++++++++++++++++++++++++++ SDWebImage/UIImage+WebP.h | 11 ----- SDWebImage/UIImage+WebP.m | 5 -- WebImage/SDWebImage.h | 1 + 16 files changed, 141 insertions(+), 105 deletions(-) create mode 100644 SDWebImage/UIImage+WebCache.h create mode 100644 SDWebImage/UIImage+WebCache.m diff --git a/SDWebImage.xcodeproj/project.pbxproj b/SDWebImage.xcodeproj/project.pbxproj index e9f68f23..4618c0bb 100644 --- a/SDWebImage.xcodeproj/project.pbxproj +++ b/SDWebImage.xcodeproj/project.pbxproj @@ -319,6 +319,18 @@ 3290FA0D1FA478AF0047D20C /* SDWebImageFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 3290FA031FA478AF0047D20C /* SDWebImageFrame.m */; }; 3290FA0E1FA478AF0047D20C /* SDWebImageFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 3290FA031FA478AF0047D20C /* SDWebImageFrame.m */; }; 3290FA0F1FA478AF0047D20C /* SDWebImageFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 3290FA031FA478AF0047D20C /* SDWebImageFrame.m */; }; + 329A18591FFF5DFD008C9A2F /* UIImage+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 329A18571FFF5DFD008C9A2F /* UIImage+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 329A185A1FFF5DFD008C9A2F /* UIImage+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 329A18571FFF5DFD008C9A2F /* UIImage+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 329A185B1FFF5DFD008C9A2F /* UIImage+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 329A18571FFF5DFD008C9A2F /* UIImage+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 329A185C1FFF5DFD008C9A2F /* UIImage+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 329A18571FFF5DFD008C9A2F /* UIImage+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 329A185D1FFF5DFD008C9A2F /* UIImage+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 329A18571FFF5DFD008C9A2F /* UIImage+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 329A185E1FFF5DFD008C9A2F /* UIImage+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 329A18571FFF5DFD008C9A2F /* UIImage+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 329A185F1FFF5DFD008C9A2F /* UIImage+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 329A18581FFF5DFD008C9A2F /* UIImage+WebCache.m */; }; + 329A18601FFF5DFD008C9A2F /* UIImage+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 329A18581FFF5DFD008C9A2F /* UIImage+WebCache.m */; }; + 329A18611FFF5DFD008C9A2F /* UIImage+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 329A18581FFF5DFD008C9A2F /* UIImage+WebCache.m */; }; + 329A18621FFF5DFD008C9A2F /* UIImage+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 329A18581FFF5DFD008C9A2F /* UIImage+WebCache.m */; }; + 329A18631FFF5DFD008C9A2F /* UIImage+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 329A18581FFF5DFD008C9A2F /* UIImage+WebCache.m */; }; + 329A18641FFF5DFD008C9A2F /* UIImage+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 329A18581FFF5DFD008C9A2F /* UIImage+WebCache.m */; }; 32CF1C071FA496B000004BD1 /* SDWebImageCoderHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 32CF1C051FA496B000004BD1 /* SDWebImageCoderHelper.h */; settings = {ATTRIBUTES = (Public, ); }; }; 32CF1C081FA496B000004BD1 /* SDWebImageCoderHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 32CF1C051FA496B000004BD1 /* SDWebImageCoderHelper.h */; settings = {ATTRIBUTES = (Public, ); }; }; 32CF1C091FA496B000004BD1 /* SDWebImageCoderHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 32CF1C051FA496B000004BD1 /* SDWebImageCoderHelper.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -1320,6 +1332,8 @@ 323F8B3D1F38EF770092B609 /* muxread.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = muxread.c; sourceTree = ""; }; 3290FA021FA478AF0047D20C /* SDWebImageFrame.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDWebImageFrame.h; sourceTree = ""; }; 3290FA031FA478AF0047D20C /* SDWebImageFrame.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDWebImageFrame.m; sourceTree = ""; }; + 329A18571FFF5DFD008C9A2F /* UIImage+WebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIImage+WebCache.h"; path = "SDWebImage/UIImage+WebCache.h"; sourceTree = ""; }; + 329A18581FFF5DFD008C9A2F /* UIImage+WebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIImage+WebCache.m"; path = "SDWebImage/UIImage+WebCache.m"; sourceTree = ""; }; 32CF1C051FA496B000004BD1 /* SDWebImageCoderHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDWebImageCoderHelper.h; sourceTree = ""; }; 32CF1C061FA496B000004BD1 /* SDWebImageCoderHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDWebImageCoderHelper.m; sourceTree = ""; }; 4314D1991D0E0E3B004B36C9 /* libSDWebImage watchOS static.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libSDWebImage watchOS static.a"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1624,6 +1638,8 @@ 4369C2851D9811BB007E863A /* WebCache Categories */ = { isa = PBXGroup; children = ( + 329A18571FFF5DFD008C9A2F /* UIImage+WebCache.h */, + 329A18581FFF5DFD008C9A2F /* UIImage+WebCache.m */, 4397D2F41D0DE2DF00BB2784 /* NSImage+WebCache.h */, 4397D2F51D0DE2DF00BB2784 /* NSImage+WebCache.m */, 535699B415113E7300A4C397 /* MKAnnotationView+WebCache.h */, @@ -1987,6 +2003,7 @@ 80377C4A1F2F666300F89830 /* bit_writer_utils.h in Headers */, 4397D2F81D0DF44200BB2784 /* MKAnnotationView+WebCache.h in Headers */, 323F8BE71F38EF770092B609 /* vp8li_enc.h in Headers */, + 329A185C1FFF5DFD008C9A2F /* UIImage+WebCache.h in Headers */, 4369C27A1D9807EC007E863A /* UIView+WebCache.h in Headers */, 80377DCC1F2F66A700F89830 /* lossless_common.h in Headers */, 321E60971F38E8ED00405457 /* SDWebImageImageIOCoder.h in Headers */, @@ -2078,6 +2095,7 @@ 80377D501F2F66A700F89830 /* mips_macro.h in Headers */, 80377C291F2F666300F89830 /* thread_utils.h in Headers */, 4314D16D1D0E0E3B004B36C9 /* SDImageCache.h in Headers */, + 329A185A1FFF5DFD008C9A2F /* UIImage+WebCache.h in Headers */, 4314D16F1D0E0E3B004B36C9 /* NSData+ImageContentType.h in Headers */, 80377C121F2F666300F89830 /* bit_reader_inl_utils.h in Headers */, 4314D1701D0E0E3B004B36C9 /* mux.h in Headers */, @@ -2142,6 +2160,7 @@ 43A62A1B1D0E0A800089D7DD /* decode.h in Headers */, 321E608A1F38E8C800405457 /* SDWebImageCoder.h in Headers */, 80377C601F2F666400F89830 /* bit_reader_inl_utils.h in Headers */, + 329A185D1FFF5DFD008C9A2F /* UIImage+WebCache.h in Headers */, 431BB6DC1D06D2C1006A3455 /* UIButton+WebCache.h in Headers */, 431BB6E11D06D2C1006A3455 /* SDWebImage.h in Headers */, 80377E311F2F66A800F89830 /* yuv.h in Headers */, @@ -2238,6 +2257,7 @@ 4397D2D11D0DDD8C00BB2784 /* decode.h in Headers */, 80377E481F2F66A800F89830 /* dsp.h in Headers */, 323F8BE91F38EF770092B609 /* vp8li_enc.h in Headers */, + 329A185E1FFF5DFD008C9A2F /* UIImage+WebCache.h in Headers */, 80377E761F2F66A800F89830 /* yuv.h in Headers */, 80377C7A1F2F666400F89830 /* bit_reader_inl_utils.h in Headers */, 80377E631F2F66A800F89830 /* lossless.h in Headers */, @@ -2296,6 +2316,7 @@ 80377C301F2F666300F89830 /* bit_writer_utils.h in Headers */, 431739541CDFC8B70008FEB9 /* types.h in Headers */, 323F8BE61F38EF770092B609 /* vp8li_enc.h in Headers */, + 329A185B1FFF5DFD008C9A2F /* UIImage+WebCache.h in Headers */, 4369C2791D9807EC007E863A /* UIView+WebCache.h in Headers */, 80377D871F2F66A700F89830 /* lossless_common.h in Headers */, 321E60961F38E8ED00405457 /* SDWebImageImageIOCoder.h in Headers */, @@ -2391,6 +2412,7 @@ 321E60941F38E8ED00405457 /* SDWebImageImageIOCoder.h in Headers */, 431738BD1CDFC2660008FEB9 /* decode.h in Headers */, 80377D0B1F2F66A100F89830 /* mips_macro.h in Headers */, + 329A18591FFF5DFD008C9A2F /* UIImage+WebCache.h in Headers */, 5376131A155AD0D5005750A4 /* SDWebImageDownloader.h in Headers */, 4369C2771D9807EC007E863A /* UIView+WebCache.h in Headers */, 80377CEF1F2F66A100F89830 /* dsp.h in Headers */, @@ -2794,6 +2816,7 @@ 00733A5E1BC4880000A5A117 /* UIImage+MultiFormat.m in Sources */, 80377DD01F2F66A700F89830 /* lossless_enc_neon.c in Sources */, 80377DE21F2F66A700F89830 /* rescaler.c in Sources */, + 329A18621FFF5DFD008C9A2F /* UIImage+WebCache.m in Sources */, 80377DAD1F2F66A700F89830 /* argb_mips_dsp_r2.c in Sources */, 00733A601BC4880000A5A117 /* UIImageView+HighlightedWebCache.m in Sources */, 323F8BAB1F38EF770092B609 /* picture_psnr_enc.c in Sources */, @@ -2817,6 +2840,7 @@ 80377EA01F2F66D400F89830 /* vp8_dec.c in Sources */, 80377EA31F2F66D400F89830 /* vp8l_dec.c in Sources */, 80377E9D1F2F66D400F89830 /* io_dec.c in Sources */, + 329A18601FFF5DFD008C9A2F /* UIImage+WebCache.m in Sources */, 80377D541F2F66A700F89830 /* rescaler_mips32.c in Sources */, 80377D331F2F66A700F89830 /* dec.c in Sources */, 323F8BAF1F38EF770092B609 /* picture_rescale_enc.c in Sources */, @@ -2960,6 +2984,7 @@ 80377ED01F2F66D500F89830 /* vp8_dec.c in Sources */, 80377ED31F2F66D500F89830 /* vp8l_dec.c in Sources */, 80377ECD1F2F66D500F89830 /* io_dec.c in Sources */, + 329A18631FFF5DFD008C9A2F /* UIImage+WebCache.m in Sources */, 80377E231F2F66A800F89830 /* rescaler_mips32.c in Sources */, 80377E021F2F66A800F89830 /* dec.c in Sources */, 323F8BB21F38EF770092B609 /* picture_rescale_enc.c in Sources */, @@ -3124,6 +3149,7 @@ 80377EE01F2F66D500F89830 /* vp8_dec.c in Sources */, 32CF1C121FA496B000004BD1 /* SDWebImageCoderHelper.m in Sources */, 80377E521F2F66A800F89830 /* filters_msa.c in Sources */, + 329A18641FFF5DFD008C9A2F /* UIImage+WebCache.m in Sources */, 80377C821F2F666400F89830 /* filters_utils.c in Sources */, 4397D28C1D0DDD8C00BB2784 /* UIImageView+WebCache.m in Sources */, 80377E581F2F66A800F89830 /* lossless_enc_mips32.c in Sources */, @@ -3372,6 +3398,7 @@ 43CE75801CFE9427006C64D0 /* FLAnimatedImageView.m in Sources */, 4369C2801D9807EC007E863A /* UIView+WebCache.m in Sources */, 80377D8B1F2F66A700F89830 /* lossless_enc_neon.c in Sources */, + 329A18611FFF5DFD008C9A2F /* UIImage+WebCache.m in Sources */, 80377D9D1F2F66A700F89830 /* rescaler.c in Sources */, 80377D681F2F66A700F89830 /* argb_mips_dsp_r2.c in Sources */, 323F8BAA1F38EF770092B609 /* picture_psnr_enc.c in Sources */, @@ -3519,6 +3546,7 @@ 43CE757F1CFE9427006C64D0 /* FLAnimatedImageView.m in Sources */, 4369C27E1D9807EC007E863A /* UIView+WebCache.m in Sources */, 80377D011F2F66A100F89830 /* lossless_enc_neon.c in Sources */, + 329A185F1FFF5DFD008C9A2F /* UIImage+WebCache.m in Sources */, 80377D131F2F66A100F89830 /* rescaler.c in Sources */, 80377CDE1F2F66A100F89830 /* argb_mips_dsp_r2.c in Sources */, 323F8BA81F38EF770092B609 /* picture_psnr_enc.c in Sources */, diff --git a/SDWebImage/NSImage+WebCache.h b/SDWebImage/NSImage+WebCache.h index 7515d407..1f7b888d 100644 --- a/SDWebImage/NSImage+WebCache.h +++ b/SDWebImage/NSImage+WebCache.h @@ -10,13 +10,10 @@ #if SD_MAC -#import +@interface NSImage (Additions) -@interface NSImage (WebCache) - -- (CGImageRef)CGImage; -- (NSArray *)images; -- (BOOL)isGIF; +- (nullable CGImageRef)CGImage; +- (nullable NSArray *)images; @end diff --git a/SDWebImage/NSImage+WebCache.m b/SDWebImage/NSImage+WebCache.m index 140ed6ce..b42785ea 100644 --- a/SDWebImage/NSImage+WebCache.m +++ b/SDWebImage/NSImage+WebCache.m @@ -10,7 +10,7 @@ #if SD_MAC -@implementation NSImage (WebCache) +@implementation NSImage (Additions) - (CGImageRef)CGImage { NSRect imageRect = NSMakeRect(0, 0, self.size.width, self.size.height); @@ -22,19 +22,6 @@ return nil; } -- (BOOL)isGIF { - BOOL isGIF = NO; - for (NSImageRep *rep in self.representations) { - if ([rep isKindOfClass:[NSBitmapImageRep class]]) { - NSBitmapImageRep *bitmapRep = (NSBitmapImageRep *)rep; - NSUInteger frameCount = [[bitmapRep valueForProperty:NSImageFrameCount] unsignedIntegerValue]; - isGIF = frameCount > 1 ? YES : NO; - break; - } - } - return isGIF; -} - @end #endif diff --git a/SDWebImage/SDWebImageCompat.m b/SDWebImage/SDWebImageCompat.m index bb53495e..eff574ac 100644 --- a/SDWebImage/SDWebImageCompat.m +++ b/SDWebImage/SDWebImageCompat.m @@ -7,7 +7,7 @@ */ #import "SDWebImageCompat.h" -#import "UIImage+MultiFormat.h" +#import "UIImage+WebCache.h" #if !__has_feature(objc_arc) #error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag diff --git a/SDWebImage/SDWebImageFrame.h b/SDWebImage/SDWebImageFrame.h index d8ba1812..0dc2eeda 100644 --- a/SDWebImage/SDWebImageFrame.h +++ b/SDWebImage/SDWebImageFrame.h @@ -11,7 +11,7 @@ @interface SDWebImageFrame : NSObject -// This class is used for creating animated images via `animatedImageWithFrames` in `SDWebImageCoderHelper`. Attension if you need animated images loop count, use `sd_imageLoopCount` property in `UIImage+MultiFormat` +// This class is used for creating animated images via `animatedImageWithFrames` in `SDWebImageCoderHelper`. Attension if you need animated images loop count, use `sd_imageLoopCount` property in `UIImage+WebCache.h` /** The image of current frame. You should not set an animated image. diff --git a/SDWebImage/SDWebImageGIFCoder.m b/SDWebImage/SDWebImageGIFCoder.m index e05d1c0b..e2705f87 100644 --- a/SDWebImage/SDWebImageGIFCoder.m +++ b/SDWebImage/SDWebImageGIFCoder.m @@ -8,9 +8,9 @@ #import "SDWebImageGIFCoder.h" #import "NSImage+WebCache.h" +#import "UIImage+WebCache.h" #import #import "NSData+ImageContentType.h" -#import "UIImage+MultiFormat.h" #import "SDWebImageCoderHelper.h" @implementation SDWebImageGIFCoder diff --git a/SDWebImage/SDWebImageWebPCoder.m b/SDWebImage/SDWebImageWebPCoder.m index 2821c47b..d80ff445 100644 --- a/SDWebImage/SDWebImageWebPCoder.m +++ b/SDWebImage/SDWebImageWebPCoder.m @@ -11,7 +11,7 @@ #import "SDWebImageWebPCoder.h" #import "SDWebImageCoderHelper.h" #import "NSImage+WebCache.h" -#import "UIImage+MultiFormat.h" +#import "UIImage+WebCache.h" #if __has_include() && __has_include() && __has_include() && __has_include() #import #import diff --git a/SDWebImage/UIImage+GIF.h b/SDWebImage/UIImage+GIF.h index a3a66465..5748b948 100644 --- a/SDWebImage/UIImage+GIF.h +++ b/SDWebImage/UIImage+GIF.h @@ -15,11 +15,6 @@ * Creates an animated UIImage from an NSData. * For static GIF, will create an UIImage with `images` array set to nil. For animated GIF, will create an UIImage with valid `images` array. */ -+ (UIImage *)sd_animatedGIFWithData:(NSData *)data; - -/** - * Checks if an UIImage instance is a GIF. Will use the `images` array. - */ -- (BOOL)isGIF; ++ (nullable UIImage *)sd_animatedGIFWithData:(nullable NSData *)data; @end diff --git a/SDWebImage/UIImage+GIF.m b/SDWebImage/UIImage+GIF.m index 6fbca7ae..0af2ba84 100644 --- a/SDWebImage/UIImage+GIF.m +++ b/SDWebImage/UIImage+GIF.m @@ -9,7 +9,6 @@ #import "UIImage+GIF.h" #import "SDWebImageGIFCoder.h" -#import "NSImage+WebCache.h" @implementation UIImage (GIF) @@ -20,8 +19,4 @@ return [[SDWebImageGIFCoder sharedCoder] decodedImageWithData:data]; } -- (BOOL)isGIF { - return (self.images != nil); -} - @end diff --git a/SDWebImage/UIImage+MultiFormat.h b/SDWebImage/UIImage+MultiFormat.h index c0792d1b..bec411e0 100644 --- a/SDWebImage/UIImage+MultiFormat.h +++ b/SDWebImage/UIImage+MultiFormat.h @@ -11,18 +11,6 @@ @interface UIImage (MultiFormat) -/** - * UIKit: - * For static image format, this value is always 0. - * For animated image format, 0 means infinite looping. - * Note that because of the limitations of categories this property can get out of sync if you create another instance with CGImage or other methods. - * AppKit: - * NSImage currently only support animated via GIF imageRep unlike UIImage. - * The getter of this property will get the loop count from GIF imageRep - * The setter of this property will set the loop count from GIF imageRep - */ -@property (nonatomic, assign) NSUInteger sd_imageLoopCount; - + (nullable UIImage *)sd_imageWithData:(nullable NSData *)data; - (nullable NSData *)sd_imageData; - (nullable NSData *)sd_imageDataAsFormat:(SDImageFormat)imageFormat; diff --git a/SDWebImage/UIImage+MultiFormat.m b/SDWebImage/UIImage+MultiFormat.m index 664e0969..8abe595b 100644 --- a/SDWebImage/UIImage+MultiFormat.m +++ b/SDWebImage/UIImage+MultiFormat.m @@ -7,52 +7,10 @@ */ #import "UIImage+MultiFormat.h" - -#import "objc/runtime.h" #import "SDWebImageCodersManager.h" @implementation UIImage (MultiFormat) -#if SD_MAC -- (NSUInteger)sd_imageLoopCount { - NSUInteger imageLoopCount = 0; - for (NSImageRep *rep in self.representations) { - if ([rep isKindOfClass:[NSBitmapImageRep class]]) { - NSBitmapImageRep *bitmapRep = (NSBitmapImageRep *)rep; - imageLoopCount = [[bitmapRep valueForProperty:NSImageLoopCount] unsignedIntegerValue]; - break; - } - } - return imageLoopCount; -} - -- (void)setSd_imageLoopCount:(NSUInteger)sd_imageLoopCount { - for (NSImageRep *rep in self.representations) { - if ([rep isKindOfClass:[NSBitmapImageRep class]]) { - NSBitmapImageRep *bitmapRep = (NSBitmapImageRep *)rep; - [bitmapRep setProperty:NSImageLoopCount withValue:@(sd_imageLoopCount)]; - break; - } - } -} - -#else - -- (NSUInteger)sd_imageLoopCount { - NSUInteger imageLoopCount = 0; - NSNumber *value = objc_getAssociatedObject(self, @selector(sd_imageLoopCount)); - if ([value isKindOfClass:[NSNumber class]]) { - imageLoopCount = value.unsignedIntegerValue; - } - return imageLoopCount; -} - -- (void)setSd_imageLoopCount:(NSUInteger)sd_imageLoopCount { - NSNumber *value = @(sd_imageLoopCount); - objc_setAssociatedObject(self, @selector(sd_imageLoopCount), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} -#endif - + (nullable UIImage *)sd_imageWithData:(nullable NSData *)data { return [[SDWebImageCodersManager sharedInstance] decodedImageWithData:data]; } diff --git a/SDWebImage/UIImage+WebCache.h b/SDWebImage/UIImage+WebCache.h new file mode 100644 index 00000000..efa1c4c6 --- /dev/null +++ b/SDWebImage/UIImage+WebCache.h @@ -0,0 +1,32 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageCompat.h" + +@interface UIImage (WebCache) + +/** + * UIKit: + * For static image format, this value is always 0. + * For animated image format, 0 means infinite looping. + * Note that because of the limitations of categories this property can get out of sync if you create another instance with CGImage or other methods. + * AppKit: + * NSImage currently only support animated via GIF imageRep unlike UIImage. + * The getter of this property will get the loop count from GIF imageRep + * The setter of this property will set the loop count from GIF imageRep + */ +@property (nonatomic, assign) NSUInteger sd_imageLoopCount; +/** + * UIKit: + * Check the `images` array property + * AppKit: + * NSImage currently only support animated via GIF imageRep unlike UIImage. It will check all the imageRef + */ +@property (nonatomic, assign, readonly) BOOL sd_isAnimated; + +@end diff --git a/SDWebImage/UIImage+WebCache.m b/SDWebImage/UIImage+WebCache.m new file mode 100644 index 00000000..ed5c337f --- /dev/null +++ b/SDWebImage/UIImage+WebCache.m @@ -0,0 +1,71 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "UIImage+WebCache.h" +#import "objc/runtime.h" + +@implementation UIImage (WebCache) + +#if SD_MAC +- (NSUInteger)sd_imageLoopCount { + NSUInteger imageLoopCount = 0; + for (NSImageRep *rep in self.representations) { + if ([rep isKindOfClass:[NSBitmapImageRep class]]) { + NSBitmapImageRep *bitmapRep = (NSBitmapImageRep *)rep; + imageLoopCount = [[bitmapRep valueForProperty:NSImageLoopCount] unsignedIntegerValue]; + break; + } + } + return imageLoopCount; +} + +- (void)setSd_imageLoopCount:(NSUInteger)sd_imageLoopCount { + for (NSImageRep *rep in self.representations) { + if ([rep isKindOfClass:[NSBitmapImageRep class]]) { + NSBitmapImageRep *bitmapRep = (NSBitmapImageRep *)rep; + [bitmapRep setProperty:NSImageLoopCount withValue:@(sd_imageLoopCount)]; + break; + } + } +} + +- (BOOL)sd_isAnimated { + BOOL isGIF = NO; + for (NSImageRep *rep in self.representations) { + if ([rep isKindOfClass:[NSBitmapImageRep class]]) { + NSBitmapImageRep *bitmapRep = (NSBitmapImageRep *)rep; + NSUInteger frameCount = [[bitmapRep valueForProperty:NSImageFrameCount] unsignedIntegerValue]; + isGIF = frameCount > 1 ? YES : NO; + break; + } + } + return isGIF; +} + +#else + +- (NSUInteger)sd_imageLoopCount { + NSUInteger imageLoopCount = 0; + NSNumber *value = objc_getAssociatedObject(self, @selector(sd_imageLoopCount)); + if ([value isKindOfClass:[NSNumber class]]) { + imageLoopCount = value.unsignedIntegerValue; + } + return imageLoopCount; +} + +- (void)setSd_imageLoopCount:(NSUInteger)sd_imageLoopCount { + NSNumber *value = @(sd_imageLoopCount); + objc_setAssociatedObject(self, @selector(sd_imageLoopCount), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (BOOL)sd_isAnimated { + return (self.images != nil); +} +#endif + +@end diff --git a/SDWebImage/UIImage+WebP.h b/SDWebImage/UIImage+WebP.h index 139eebd3..cd9f27b1 100644 --- a/SDWebImage/UIImage+WebP.h +++ b/SDWebImage/UIImage+WebP.h @@ -12,17 +12,6 @@ @interface UIImage (WebP) -/** - * Get the current WebP image loop count, the default value is 0. - * For static WebP image, the value is 0. - * For animated WebP image, 0 means repeat the animation indefinitely. - * Note that because of the limitations of categories this property can get out of sync - * if you create another instance with CGImage or other methods. - * @return WebP image loop count - * @deprecated use `sd_imageLoopCount` instead. - */ -- (NSInteger)sd_webpLoopCount __deprecated_msg("Method deprecated. Use `sd_imageLoopCount` in `UIImage+MultiFormat.h`"); - + (nullable UIImage *)sd_imageWithWebPData:(nullable NSData *)data; @end diff --git a/SDWebImage/UIImage+WebP.m b/SDWebImage/UIImage+WebP.m index 0c4a9c5c..8329d0d4 100644 --- a/SDWebImage/UIImage+WebP.m +++ b/SDWebImage/UIImage+WebP.m @@ -10,14 +10,9 @@ #import "UIImage+WebP.h" #import "SDWebImageWebPCoder.h" -#import "UIImage+MultiFormat.h" @implementation UIImage (WebP) -- (NSInteger)sd_webpLoopCount { - return self.sd_imageLoopCount; -} - + (nullable UIImage *)sd_imageWithWebPData:(nullable NSData *)data { if (!data) { return nil; diff --git a/WebImage/SDWebImage.h b/WebImage/SDWebImage.h index df3d176d..dd6f8190 100644 --- a/WebImage/SDWebImage.h +++ b/WebImage/SDWebImage.h @@ -31,6 +31,7 @@ FOUNDATION_EXPORT const unsigned char WebImageVersionString[]; #import #import #import +#import #import #import #import From c3a35ea247d97eb139fd8c3e1fb0c9333b1e6600 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Fri, 29 Dec 2017 23:16:55 +0800 Subject: [PATCH 02/10] Remove one deprecated property `shouldUseCredentialStorage` which not used for a long time --- SDWebImage/SDWebImageDownloaderOperation.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/SDWebImage/SDWebImageDownloaderOperation.h b/SDWebImage/SDWebImageDownloaderOperation.h index bb2dc7e3..a21d02ea 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.h +++ b/SDWebImage/SDWebImageDownloaderOperation.h @@ -53,14 +53,11 @@ FOUNDATION_EXPORT NSString * _Nonnull const SDWebImageDownloadFinishNotification */ @property (strong, nonatomic, readonly, nullable) NSURLSessionTask *dataTask; - -@property (assign, nonatomic) BOOL shouldDecompressImages; - /** - * Was used to determine whether the URL connection should consult the credential storage for authenticating the connection. - * @deprecated Not used for a couple of versions + * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory. + * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption. */ -@property (nonatomic, assign) BOOL shouldUseCredentialStorage __deprecated_msg("Property deprecated. Does nothing. Kept only for backwards compatibility"); +@property (assign, nonatomic) BOOL shouldDecompressImages; /** * The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`. From c90e100d55f37f4531df522055104fa12e0a6cbe Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sat, 13 Jan 2018 17:11:15 +0800 Subject: [PATCH 03/10] Add missing nullability annotations --- SDWebImage/SDWebImageCompat.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SDWebImage/SDWebImageCompat.h b/SDWebImage/SDWebImageCompat.h index ce068071..58f443cd 100644 --- a/SDWebImage/SDWebImageCompat.h +++ b/SDWebImage/SDWebImageCompat.h @@ -81,11 +81,11 @@ #define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type #endif -FOUNDATION_EXPORT UIImage *SDScaledImageForKey(NSString *key, UIImage *image); +FOUNDATION_EXPORT UIImage * _Nullable SDScaledImageForKey(NSString * _Nullable key, UIImage * _Nullable image); typedef void(^SDWebImageNoParamsBlock)(void); -FOUNDATION_EXPORT NSString *const SDWebImageErrorDomain; +FOUNDATION_EXPORT NSString *const _Nonnull SDWebImageErrorDomain; #ifndef dispatch_queue_async_safe #define dispatch_queue_async_safe(queue, block)\ From 6797ed8be63e17d6e715d2630c718648516cab8f Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sat, 13 Jan 2018 17:14:28 +0800 Subject: [PATCH 04/10] Update the SD_MAC define --- SDWebImage/SDWebImageCompat.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/SDWebImage/SDWebImageCompat.h b/SDWebImage/SDWebImageCompat.h index 58f443cd..629db1bc 100644 --- a/SDWebImage/SDWebImageCompat.h +++ b/SDWebImage/SDWebImageCompat.h @@ -13,10 +13,9 @@ #error SDWebImage does not support Objective-C Garbage Collection #endif -// Apple's defines from TargetConditionals.h are a bit weird. // Seems like TARGET_OS_MAC is always defined (on all platforms). -// To determine if we are running on OSX, we can only rely on TARGET_OS_IPHONE=0 and all the other platforms -#if !TARGET_OS_IPHONE && !TARGET_OS_IOS && !TARGET_OS_TV && !TARGET_OS_WATCH +// To determine if we are running on macOS, use TARGET_OS_OSX in Xcode 8 +#if TARGET_OS_OSX #define SD_MAC 1 #else #define SD_MAC 0 From b6e108a5b18bc877bee0b01eabb270505f7e2554 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sat, 13 Jan 2018 17:27:42 +0800 Subject: [PATCH 05/10] Rename `NSImage+WebCache` to `NSImage+Addtions`. Add helper methods, use property based API, which more suitable for Swift --- SDWebImage.xcodeproj/project.pbxproj | 26 +++++++---- SDWebImage/NSImage+Additions.h | 25 ++++++++++ SDWebImage/NSImage+Additions.m | 53 ++++++++++++++++++++++ SDWebImage/NSImage+WebCache.h | 20 -------- SDWebImage/NSImage+WebCache.m | 28 ------------ SDWebImage/SDImageCache.m | 2 +- SDWebImage/SDWebImageCoderHelper.m | 4 +- SDWebImage/SDWebImageCompat.m | 1 + SDWebImage/SDWebImageDownloaderOperation.m | 2 +- SDWebImage/SDWebImageGIFCoder.m | 2 +- SDWebImage/SDWebImageImageIOCoder.m | 2 +- SDWebImage/SDWebImageManager.m | 2 +- SDWebImage/SDWebImageWebPCoder.m | 2 +- SDWebImage/UIImage+WebCache.m | 51 ++++++++++++--------- WebImage/SDWebImage.h | 2 +- 15 files changed, 136 insertions(+), 86 deletions(-) create mode 100644 SDWebImage/NSImage+Additions.h create mode 100644 SDWebImage/NSImage+Additions.m delete mode 100644 SDWebImage/NSImage+WebCache.h delete mode 100644 SDWebImage/NSImage+WebCache.m diff --git a/SDWebImage.xcodeproj/project.pbxproj b/SDWebImage.xcodeproj/project.pbxproj index 4618c0bb..98fce072 100644 --- a/SDWebImage.xcodeproj/project.pbxproj +++ b/SDWebImage.xcodeproj/project.pbxproj @@ -97,6 +97,11 @@ 321E60C71F38E91700405457 /* UIImage+ForceDecode.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60BD1F38E91700405457 /* UIImage+ForceDecode.m */; }; 321E60C81F38E91700405457 /* UIImage+ForceDecode.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60BD1F38E91700405457 /* UIImage+ForceDecode.m */; }; 321E60C91F38E91700405457 /* UIImage+ForceDecode.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60BD1F38E91700405457 /* UIImage+ForceDecode.m */; }; + 3237F9E820161AE000A88143 /* NSImage+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4397D2F51D0DE2DF00BB2784 /* NSImage+Additions.m */; }; + 3237F9E920161AE000A88143 /* NSImage+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4397D2F51D0DE2DF00BB2784 /* NSImage+Additions.m */; }; + 3237F9EA20161AE000A88143 /* NSImage+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4397D2F51D0DE2DF00BB2784 /* NSImage+Additions.m */; }; + 3237F9EB20161AE000A88143 /* NSImage+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4397D2F51D0DE2DF00BB2784 /* NSImage+Additions.m */; }; + 3237F9EC20161AE000A88143 /* NSImage+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4397D2F51D0DE2DF00BB2784 /* NSImage+Additions.m */; }; 323F8B3E1F38EF770092B609 /* alpha_enc.c in Sources */ = {isa = PBXBuildFile; fileRef = 323F8B131F38EF770092B609 /* alpha_enc.c */; }; 323F8B3F1F38EF770092B609 /* alpha_enc.c in Sources */ = {isa = PBXBuildFile; fileRef = 323F8B131F38EF770092B609 /* alpha_enc.c */; }; 323F8B401F38EF770092B609 /* alpha_enc.c in Sources */ = {isa = PBXBuildFile; fileRef = 323F8B131F38EF770092B609 /* alpha_enc.c */; }; @@ -488,8 +493,8 @@ 4397D2EA1D0DDD8C00BB2784 /* UIImage+GIF.h in Headers */ = {isa = PBXBuildFile; fileRef = A18A6CC5172DC28500419892 /* UIImage+GIF.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4397D2EB1D0DDD8C00BB2784 /* NSData+ImageContentType.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D5B9140188EE8DD006D06BD /* NSData+ImageContentType.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4397D2ED1D0DDD8C00BB2784 /* mux_types.h in Headers */ = {isa = PBXBuildFile; fileRef = DA577CC91998E60B007367ED /* mux_types.h */; }; - 4397D2F61D0DE2DF00BB2784 /* NSImage+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 4397D2F41D0DE2DF00BB2784 /* NSImage+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 4397D2F71D0DE2DF00BB2784 /* NSImage+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 4397D2F51D0DE2DF00BB2784 /* NSImage+WebCache.m */; }; + 4397D2F61D0DE2DF00BB2784 /* NSImage+Additions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4397D2F41D0DE2DF00BB2784 /* NSImage+Additions.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4397D2F71D0DE2DF00BB2784 /* NSImage+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4397D2F51D0DE2DF00BB2784 /* NSImage+Additions.m */; }; 4397D2F81D0DF44200BB2784 /* MKAnnotationView+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 535699B415113E7300A4C397 /* MKAnnotationView+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4397D2F91D0DF44A00BB2784 /* MKAnnotationView+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 535699B515113E7300A4C397 /* MKAnnotationView+WebCache.m */; }; 43A62A1B1D0E0A800089D7DD /* decode.h in Headers */ = {isa = PBXBuildFile; fileRef = DA577CC41998E60B007367ED /* decode.h */; }; @@ -1341,8 +1346,8 @@ 4369C2751D9807EC007E863A /* UIView+WebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIView+WebCache.h"; path = "SDWebImage/UIView+WebCache.h"; sourceTree = ""; }; 4369C2761D9807EC007E863A /* UIView+WebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIView+WebCache.m"; path = "SDWebImage/UIView+WebCache.m"; sourceTree = ""; }; 4397D2F21D0DDD8C00BB2784 /* SDWebImage.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SDWebImage.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 4397D2F41D0DE2DF00BB2784 /* NSImage+WebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSImage+WebCache.h"; path = "SDWebImage/NSImage+WebCache.h"; sourceTree = ""; }; - 4397D2F51D0DE2DF00BB2784 /* NSImage+WebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSImage+WebCache.m"; path = "SDWebImage/NSImage+WebCache.m"; sourceTree = ""; }; + 4397D2F41D0DE2DF00BB2784 /* NSImage+Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImage+Additions.h"; sourceTree = ""; }; + 4397D2F51D0DE2DF00BB2784 /* NSImage+Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSImage+Additions.m"; sourceTree = ""; }; 43A918621D8308FE00B3925F /* SDImageCacheConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDImageCacheConfig.h; sourceTree = ""; }; 43A918631D8308FE00B3925F /* SDImageCacheConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDImageCacheConfig.m; sourceTree = ""; }; 43C892981D9D6DD70022038D /* anim_decode.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = anim_decode.c; sourceTree = ""; }; @@ -1640,8 +1645,6 @@ children = ( 329A18571FFF5DFD008C9A2F /* UIImage+WebCache.h */, 329A18581FFF5DFD008C9A2F /* UIImage+WebCache.m */, - 4397D2F41D0DE2DF00BB2784 /* NSImage+WebCache.h */, - 4397D2F51D0DE2DF00BB2784 /* NSImage+WebCache.m */, 535699B415113E7300A4C397 /* MKAnnotationView+WebCache.h */, 535699B515113E7300A4C397 /* MKAnnotationView+WebCache.m */, 53922D93148C56230056699D /* UIButton+WebCache.h */, @@ -1778,6 +1781,8 @@ 53EDFB921762547C00698166 /* UIImage+WebP.m */, 321E60BC1F38E91700405457 /* UIImage+ForceDecode.h */, 321E60BD1F38E91700405457 /* UIImage+ForceDecode.m */, + 4397D2F41D0DE2DF00BB2784 /* NSImage+Additions.h */, + 4397D2F51D0DE2DF00BB2784 /* NSImage+Additions.m */, AB615301192DA24600A2D8E9 /* UIView+WebCacheOperation.h */, AB615302192DA24600A2D8E9 /* UIView+WebCacheOperation.m */, ); @@ -2280,7 +2285,7 @@ 80377E661F2F66A800F89830 /* neon.h in Headers */, 4397D2DB1D0DDD8C00BB2784 /* UIImage+MultiFormat.h in Headers */, 4397D2DC1D0DDD8C00BB2784 /* SDWebImageOperation.h in Headers */, - 4397D2F61D0DE2DF00BB2784 /* NSImage+WebCache.h in Headers */, + 4397D2F61D0DE2DF00BB2784 /* NSImage+Additions.h in Headers */, 4397D2E11D0DDD8C00BB2784 /* SDWebImageDownloader.h in Headers */, 323F8BFB1F38EF770092B609 /* animi.h in Headers */, 4397D2E31D0DDD8C00BB2784 /* MKAnnotationView+WebCache.h in Headers */, @@ -2722,6 +2727,7 @@ 80377C4E1F2F666300F89830 /* filters_utils.c in Sources */, 321E60B91F38E90100405457 /* SDWebImageWebPCoder.m in Sources */, 80377DEB1F2F66A700F89830 /* yuv.c in Sources */, + 3237F9E920161AE000A88143 /* NSImage+Additions.m in Sources */, 00733A551BC4880000A5A117 /* SDWebImageDownloader.m in Sources */, 80377EB71F2F66D400F89830 /* alpha_dec.c in Sources */, 80377DC61F2F66A700F89830 /* enc.c in Sources */, @@ -2922,6 +2928,7 @@ 80377D1F1F2F66A700F89830 /* alpha_processing_neon.c in Sources */, 4314D1401D0E0E3B004B36C9 /* UIImageView+WebCache.m in Sources */, 43A9186C1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */, + 3237F9EC20161AE000A88143 /* NSImage+Additions.m in Sources */, 4314D1411D0E0E3B004B36C9 /* SDWebImageDownloaderOperation.m in Sources */, 80377D561F2F66A700F89830 /* rescaler_neon.c in Sources */, 80377D551F2F66A700F89830 /* rescaler_msa.c in Sources */, @@ -3066,6 +3073,7 @@ 323F8C0C1F38EF770092B609 /* muxedit.c in Sources */, 80377DEE1F2F66A800F89830 /* alpha_processing_neon.c in Sources */, 43C892A41D9D6DDD0022038D /* demux.c in Sources */, + 3237F9EA20161AE000A88143 /* NSImage+Additions.m in Sources */, 431BB6B61D06D2C1006A3455 /* UIImage+WebP.m in Sources */, 80377E251F2F66A800F89830 /* rescaler_neon.c in Sources */, 80377E241F2F66A800F89830 /* rescaler_msa.c in Sources */, @@ -3125,7 +3133,7 @@ 321E60911F38E8C800405457 /* SDWebImageCoder.m in Sources */, 80377C8A1F2F666400F89830 /* quant_levels_utils.c in Sources */, 4397D27F1D0DDD8C00BB2784 /* UIImage+WebP.m in Sources */, - 4397D2F71D0DE2DF00BB2784 /* NSImage+WebCache.m in Sources */, + 4397D2F71D0DE2DF00BB2784 /* NSImage+Additions.m in Sources */, 80377E751F2F66A800F89830 /* yuv.c in Sources */, 43C892A01D9D6DDA0022038D /* anim_decode.c in Sources */, 80377E4A1F2F66A800F89830 /* enc_mips_dsp_r2.c in Sources */, @@ -3304,6 +3312,7 @@ 80377DA61F2F66A700F89830 /* yuv.c in Sources */, 321E60B81F38E90100405457 /* SDWebImageWebPCoder.m in Sources */, 43CE757A1CFE9427006C64D0 /* FLAnimatedImage.m in Sources */, + 3237F9E820161AE000A88143 /* NSImage+Additions.m in Sources */, 80377D811F2F66A700F89830 /* enc.c in Sources */, 80377EA71F2F66D400F89830 /* alpha_dec.c in Sources */, 80377D8F1F2F66A700F89830 /* lossless_mips_dsp_r2.c in Sources */, @@ -3452,6 +3461,7 @@ 321E60B61F38E90100405457 /* SDWebImageWebPCoder.m in Sources */, 43CE75791CFE9427006C64D0 /* FLAnimatedImage.m in Sources */, 80377CF71F2F66A100F89830 /* enc.c in Sources */, + 3237F9EB20161AE000A88143 /* NSImage+Additions.m in Sources */, 80377E871F2F66D000F89830 /* alpha_dec.c in Sources */, 80377D051F2F66A100F89830 /* lossless_mips_dsp_r2.c in Sources */, 80377C0A1F2F665300F89830 /* random_utils.c in Sources */, diff --git a/SDWebImage/NSImage+Additions.h b/SDWebImage/NSImage+Additions.h new file mode 100644 index 00000000..3a78ce91 --- /dev/null +++ b/SDWebImage/NSImage+Additions.h @@ -0,0 +1,25 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageCompat.h" + +// This category is provided to easily write cross-platform code. For common usage, see `UIImage+WebCache`. + +#if SD_MAC + +@interface NSImage (Additions) + +@property (nonatomic, readonly, nullable) CGImageRef CGImage; +@property (nonatomic, readonly, nullable) NSArray *images; +@property (nonatomic, readonly) CGFloat scale; + +- (nonnull instancetype)initWithCGImage:(nonnull CGImageRef)cgImage scale:(CGFloat)scale; + +@end + +#endif diff --git a/SDWebImage/NSImage+Additions.m b/SDWebImage/NSImage+Additions.m new file mode 100644 index 00000000..466a9444 --- /dev/null +++ b/SDWebImage/NSImage+Additions.m @@ -0,0 +1,53 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "NSImage+Additions.h" + +#if SD_MAC + +@implementation NSImage (Additions) + +- (CGImageRef)CGImage { + NSRect imageRect = NSMakeRect(0, 0, self.size.width, self.size.height); + CGImageRef cgImage = [self CGImageForProposedRect:&imageRect context:NULL hints:nil]; + return cgImage; +} + +- (NSArray *)images { + return nil; +} + +- (CGFloat)scale { + CGFloat scale = 1; + NSRect imageRect = NSMakeRect(0, 0, self.size.width, self.size.height); + NSImageRep *rep = [self bestRepresentationForRect:imageRect context:NULL hints:nil]; + NSInteger pixelsWide = rep.pixelsWide; + CGFloat width = rep.size.width; + if (width > 0) { + scale = pixelsWide / width; + } + return scale; +} + +- (instancetype)initWithCGImage:(CGImageRef)cgImage scale:(CGFloat)scale { + NSSize size; + if (cgImage && scale > 0) { + NSInteger pixelsWide = CGImageGetWidth(cgImage); + NSInteger pixelsHigh = CGImageGetHeight(cgImage); + CGFloat width = pixelsWide / scale; + CGFloat height = pixelsHigh / scale; + size = NSMakeSize(width, height); + } else { + size = NSZeroSize; + } + return [self initWithCGImage:cgImage size:size]; +} + +@end + +#endif diff --git a/SDWebImage/NSImage+WebCache.h b/SDWebImage/NSImage+WebCache.h deleted file mode 100644 index 1f7b888d..00000000 --- a/SDWebImage/NSImage+WebCache.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * This file is part of the SDWebImage package. - * (c) Olivier Poitrey - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -#import "SDWebImageCompat.h" - -#if SD_MAC - -@interface NSImage (Additions) - -- (nullable CGImageRef)CGImage; -- (nullable NSArray *)images; - -@end - -#endif diff --git a/SDWebImage/NSImage+WebCache.m b/SDWebImage/NSImage+WebCache.m deleted file mode 100644 index b42785ea..00000000 --- a/SDWebImage/NSImage+WebCache.m +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This file is part of the SDWebImage package. - * (c) Olivier Poitrey - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -#import "NSImage+WebCache.h" - -#if SD_MAC - -@implementation NSImage (Additions) - -- (CGImageRef)CGImage { - NSRect imageRect = NSMakeRect(0, 0, self.size.width, self.size.height); - CGImageRef cgImage = [self CGImageForProposedRect:&imageRect context:NULL hints:nil]; - return cgImage; -} - -- (NSArray *)images { - return nil; -} - -@end - -#endif - diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index 42335732..4c027083 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -8,7 +8,7 @@ #import "SDImageCache.h" #import -#import "NSImage+WebCache.h" +#import "NSImage+Additions.h" #import "SDWebImageCodersManager.h" static void * SDImageCacheContext = &SDImageCacheContext; diff --git a/SDWebImage/SDWebImageCoderHelper.m b/SDWebImage/SDWebImageCoderHelper.m index b2b651a2..2ffcfd9a 100644 --- a/SDWebImage/SDWebImageCoderHelper.m +++ b/SDWebImage/SDWebImageCoderHelper.m @@ -8,8 +8,8 @@ #import "SDWebImageCoderHelper.h" #import "SDWebImageFrame.h" -#import "UIImage+MultiFormat.h" -#import "NSImage+WebCache.h" +#import "NSImage+Additions.h" +#import "NSData+ImageContentType.h" #import @implementation SDWebImageCoderHelper diff --git a/SDWebImage/SDWebImageCompat.m b/SDWebImage/SDWebImageCompat.m index eff574ac..b3377e6a 100644 --- a/SDWebImage/SDWebImageCompat.m +++ b/SDWebImage/SDWebImageCompat.m @@ -8,6 +8,7 @@ #import "SDWebImageCompat.h" #import "UIImage+WebCache.h" +#import "NSImage+Additions.h" #if !__has_feature(objc_arc) #error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index 553b0e95..cffb1a86 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -8,7 +8,7 @@ #import "SDWebImageDownloaderOperation.h" #import "SDWebImageManager.h" -#import "NSImage+WebCache.h" +#import "NSImage+Additions.h" #import "SDWebImageCodersManager.h" NSString *const SDWebImageDownloadStartNotification = @"SDWebImageDownloadStartNotification"; diff --git a/SDWebImage/SDWebImageGIFCoder.m b/SDWebImage/SDWebImageGIFCoder.m index e2705f87..b8c9c4b2 100644 --- a/SDWebImage/SDWebImageGIFCoder.m +++ b/SDWebImage/SDWebImageGIFCoder.m @@ -7,7 +7,7 @@ */ #import "SDWebImageGIFCoder.h" -#import "NSImage+WebCache.h" +#import "NSImage+Additions.h" #import "UIImage+WebCache.h" #import #import "NSData+ImageContentType.h" diff --git a/SDWebImage/SDWebImageImageIOCoder.m b/SDWebImage/SDWebImageImageIOCoder.m index baf3cfdf..570e2a11 100644 --- a/SDWebImage/SDWebImageImageIOCoder.m +++ b/SDWebImage/SDWebImageImageIOCoder.m @@ -8,7 +8,7 @@ #import "SDWebImageImageIOCoder.h" #import "SDWebImageCoderHelper.h" -#import "NSImage+WebCache.h" +#import "NSImage+Additions.h" #import #import "NSData+ImageContentType.h" diff --git a/SDWebImage/SDWebImageManager.m b/SDWebImage/SDWebImageManager.m index 36ab073b..645bf506 100644 --- a/SDWebImage/SDWebImageManager.m +++ b/SDWebImage/SDWebImageManager.m @@ -7,7 +7,7 @@ */ #import "SDWebImageManager.h" -#import "NSImage+WebCache.h" +#import "NSImage+Additions.h" #import @interface SDWebImageCombinedOperation : NSObject diff --git a/SDWebImage/SDWebImageWebPCoder.m b/SDWebImage/SDWebImageWebPCoder.m index d80ff445..3f68c1c5 100644 --- a/SDWebImage/SDWebImageWebPCoder.m +++ b/SDWebImage/SDWebImageWebPCoder.m @@ -10,7 +10,7 @@ #import "SDWebImageWebPCoder.h" #import "SDWebImageCoderHelper.h" -#import "NSImage+WebCache.h" +#import "NSImage+Additions.h" #import "UIImage+WebCache.h" #if __has_include() && __has_include() && __has_include() && __has_include() #import diff --git a/SDWebImage/UIImage+WebCache.m b/SDWebImage/UIImage+WebCache.m index ed5c337f..60d3e2f7 100644 --- a/SDWebImage/UIImage+WebCache.m +++ b/SDWebImage/UIImage+WebCache.m @@ -7,11 +7,39 @@ */ #import "UIImage+WebCache.h" + +#if SD_UIKIT + #import "objc/runtime.h" @implementation UIImage (WebCache) +- (NSUInteger)sd_imageLoopCount { + NSUInteger imageLoopCount = 0; + NSNumber *value = objc_getAssociatedObject(self, @selector(sd_imageLoopCount)); + if ([value isKindOfClass:[NSNumber class]]) { + imageLoopCount = value.unsignedIntegerValue; + } + return imageLoopCount; +} + +- (void)setSd_imageLoopCount:(NSUInteger)sd_imageLoopCount { + NSNumber *value = @(sd_imageLoopCount); + objc_setAssociatedObject(self, @selector(sd_imageLoopCount), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (BOOL)sd_isAnimated { + return (self.images != nil); +} + +@end + +#endif + #if SD_MAC + +@implementation NSImage (WebCache) + - (NSUInteger)sd_imageLoopCount { NSUInteger imageLoopCount = 0; for (NSImageRep *rep in self.representations) { @@ -47,25 +75,6 @@ return isGIF; } -#else - -- (NSUInteger)sd_imageLoopCount { - NSUInteger imageLoopCount = 0; - NSNumber *value = objc_getAssociatedObject(self, @selector(sd_imageLoopCount)); - if ([value isKindOfClass:[NSNumber class]]) { - imageLoopCount = value.unsignedIntegerValue; - } - return imageLoopCount; -} - -- (void)setSd_imageLoopCount:(NSUInteger)sd_imageLoopCount { - NSNumber *value = @(sd_imageLoopCount); - objc_setAssociatedObject(self, @selector(sd_imageLoopCount), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} - -- (BOOL)sd_isAnimated { - return (self.images != nil); -} -#endif - @end + +#endif diff --git a/WebImage/SDWebImage.h b/WebImage/SDWebImage.h index dd6f8190..22258eba 100644 --- a/WebImage/SDWebImage.h +++ b/WebImage/SDWebImage.h @@ -53,7 +53,7 @@ FOUNDATION_EXPORT const unsigned char WebImageVersionString[]; #import #if SD_MAC - #import + #import #endif #if SD_UIKIT From dc5d7d189d44c57c929cb878129943dddb3dbd8a Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Thu, 28 Dec 2017 16:06:37 +0800 Subject: [PATCH 06/10] Rename UIImage+ForceDecode method with sd prefix to avoid name conflict --- SDWebImage/UIImage+ForceDecode.h | 4 ++-- SDWebImage/UIImage+ForceDecode.m | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SDWebImage/UIImage+ForceDecode.h b/SDWebImage/UIImage+ForceDecode.h index 708c37b0..e8ef5340 100644 --- a/SDWebImage/UIImage+ForceDecode.h +++ b/SDWebImage/UIImage+ForceDecode.h @@ -10,8 +10,8 @@ @interface UIImage (ForceDecode) -+ (nullable UIImage *)decodedImageWithImage:(nullable UIImage *)image; ++ (nullable UIImage *)sd_decodedImageWithImage:(nullable UIImage *)image; -+ (nullable UIImage *)decodedAndScaledDownImageWithImage:(nullable UIImage *)image; ++ (nullable UIImage *)sd_decodedAndScaledDownImageWithImage:(nullable UIImage *)image; @end diff --git a/SDWebImage/UIImage+ForceDecode.m b/SDWebImage/UIImage+ForceDecode.m index ee55aee7..2f25f047 100644 --- a/SDWebImage/UIImage+ForceDecode.m +++ b/SDWebImage/UIImage+ForceDecode.m @@ -11,7 +11,7 @@ @implementation UIImage (ForceDecode) -+ (UIImage *)decodedImageWithImage:(UIImage *)image { ++ (UIImage *)sd_decodedImageWithImage:(UIImage *)image { if (!image) { return nil; } @@ -19,7 +19,7 @@ return [[SDWebImageCodersManager sharedInstance] decompressedImageWithImage:image data:&tempData options:@{SDWebImageCoderScaleDownLargeImagesKey: @(NO)}]; } -+ (UIImage *)decodedAndScaledDownImageWithImage:(UIImage *)image { ++ (UIImage *)sd_decodedAndScaledDownImageWithImage:(UIImage *)image { if (!image) { return nil; } From 82c44e275a6d33010ca0a87dd3c867e749e91e0a Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sat, 13 Jan 2018 17:38:29 +0800 Subject: [PATCH 07/10] Update the test --- Tests/Tests/SDWebImageDecoderTests.m | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Tests/Tests/SDWebImageDecoderTests.m b/Tests/Tests/SDWebImageDecoderTests.m index 0ceaff3d..947548c8 100644 --- a/Tests/Tests/SDWebImageDecoderTests.m +++ b/Tests/Tests/SDWebImageDecoderTests.m @@ -21,13 +21,13 @@ @implementation SDWebImageDecoderTests - (void)test01ThatDecodedImageWithNilImageReturnsNil { - expect([UIImage decodedImageWithImage:nil]).to.beNil(); + expect([UIImage sd_decodedImageWithImage:nil]).to.beNil(); } - (void)test02ThatDecodedImageWithImageWorksWithARegularJPGImage { NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"jpg"]; UIImage *image = [UIImage imageWithContentsOfFile:testImagePath]; - UIImage *decodedImage = [UIImage decodedImageWithImage:image]; + UIImage *decodedImage = [UIImage sd_decodedImageWithImage:image]; expect(decodedImage).toNot.beNil(); expect(decodedImage).toNot.equal(image); expect(decodedImage.size.width).to.equal(image.size.width); @@ -38,7 +38,7 @@ NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"gif"]; UIImage *image = [UIImage imageWithContentsOfFile:testImagePath]; UIImage *animatedImage = [UIImage animatedImageWithImages:@[image] duration:0]; - UIImage *decodedImage = [UIImage decodedImageWithImage:animatedImage]; + UIImage *decodedImage = [UIImage sd_decodedImageWithImage:animatedImage]; expect(decodedImage).toNot.beNil(); expect(decodedImage).to.equal(animatedImage); } @@ -46,7 +46,7 @@ - (void)test04ThatDecodedImageWithImageDoesNotDecodeImagesWithAlpha { NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"png"]; UIImage *image = [UIImage imageWithContentsOfFile:testImagePath]; - UIImage *decodedImage = [UIImage decodedImageWithImage:image]; + UIImage *decodedImage = [UIImage sd_decodedImageWithImage:image]; expect(decodedImage).toNot.beNil(); expect(decodedImage).to.equal(image); } @@ -54,7 +54,7 @@ - (void)test05ThatDecodedImageWithImageWorksEvenWithMonochromeImage { NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"MonochromeTestImage" ofType:@"jpg"]; UIImage *image = [UIImage imageWithContentsOfFile:testImagePath]; - UIImage *decodedImage = [UIImage decodedImageWithImage:image]; + UIImage *decodedImage = [UIImage sd_decodedImageWithImage:image]; expect(decodedImage).toNot.beNil(); expect(decodedImage).toNot.equal(image); expect(decodedImage.size.width).to.equal(image.size.width); @@ -64,7 +64,7 @@ - (void)test06ThatDecodeAndScaleDownImageWorks { NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImageLarge" ofType:@"jpg"]; UIImage *image = [UIImage imageWithContentsOfFile:testImagePath]; - UIImage *decodedImage = [UIImage decodedAndScaledDownImageWithImage:image]; + UIImage *decodedImage = [UIImage sd_decodedAndScaledDownImageWithImage:image]; expect(decodedImage).toNot.beNil(); expect(decodedImage).toNot.equal(image); expect(decodedImage.size.width).toNot.equal(image.size.width); @@ -75,7 +75,7 @@ - (void)test07ThatDecodeAndScaleDownImageDoesNotScaleSmallerImage { NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"jpg"]; UIImage *image = [UIImage imageWithContentsOfFile:testImagePath]; - UIImage *decodedImage = [UIImage decodedAndScaledDownImageWithImage:image]; + UIImage *decodedImage = [UIImage sd_decodedAndScaledDownImageWithImage:image]; expect(decodedImage).toNot.beNil(); expect(decodedImage).toNot.equal(image); expect(decodedImage.size.width).to.equal(image.size.width); From 6f6f54e6c55154ae69e8d835ff2eba1ba590b2d4 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Tue, 16 Jan 2018 00:06:18 +0800 Subject: [PATCH 08/10] Mark one function which return value should follow the GET rule --- SDWebImage/NSData+ImageContentType.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDWebImage/NSData+ImageContentType.h b/SDWebImage/NSData+ImageContentType.h index 0ca226d8..1eaab8dc 100644 --- a/SDWebImage/NSData+ImageContentType.h +++ b/SDWebImage/NSData+ImageContentType.h @@ -37,6 +37,6 @@ typedef NS_ENUM(NSInteger, SDImageFormat) { @param format Format as SDImageFormat @return The UTType as CFStringRef */ -+ (nonnull CFStringRef)sd_UTTypeFromSDImageFormat:(SDImageFormat)format; ++ (nonnull CFStringRef)sd_UTTypeFromSDImageFormat:(SDImageFormat)format CF_RETURNS_NOT_RETAINED; @end From 9e48da8a8a747ab24b162d0361bad422b63c27f0 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Tue, 16 Jan 2018 00:15:15 +0800 Subject: [PATCH 09/10] Update and remove the deprecated method. Add some documents for un-documented methods --- SDWebImage/UIImage+ForceDecode.h | 12 ++++++++++++ SDWebImage/UIImage+MultiFormat.h | 19 +++++++++++++++++++ SDWebImage/UIImageView+WebCache.h | 28 +++------------------------- SDWebImage/UIImageView+WebCache.m | 11 ----------- SDWebImage/UIView+WebCache.h | 2 +- SDWebImage/UIView+WebCache.m | 6 +++++- 6 files changed, 40 insertions(+), 38 deletions(-) diff --git a/SDWebImage/UIImage+ForceDecode.h b/SDWebImage/UIImage+ForceDecode.h index e8ef5340..ae85114b 100644 --- a/SDWebImage/UIImage+ForceDecode.h +++ b/SDWebImage/UIImage+ForceDecode.h @@ -10,8 +10,20 @@ @interface UIImage (ForceDecode) +/** + Decompress (force decode before rendering) the provided image + + @param image The image to be decompressed + @return The decompressed image + */ + (nullable UIImage *)sd_decodedImageWithImage:(nullable UIImage *)image; +/** + Decompress and scale down the provided image + + @param image The image to be decompressed + @return The decompressed and scaled down image + */ + (nullable UIImage *)sd_decodedAndScaledDownImageWithImage:(nullable UIImage *)image; @end diff --git a/SDWebImage/UIImage+MultiFormat.h b/SDWebImage/UIImage+MultiFormat.h index bec411e0..f316fe96 100644 --- a/SDWebImage/UIImage+MultiFormat.h +++ b/SDWebImage/UIImage+MultiFormat.h @@ -11,8 +11,27 @@ @interface UIImage (MultiFormat) +/** + Create and decode a image with the specify image data + + @param data The image data + @return The created image + */ + (nullable UIImage *)sd_imageWithData:(nullable NSData *)data; + +/** + Encode the current image to the data, the image format is unspecified + + @return The encoded data. If can't encode, return nil + */ - (nullable NSData *)sd_imageData; + +/** + Encode the current image to data with the specify image format + + @param imageFormat The specify image format + @return The encoded data. If can't encode, return nil + */ - (nullable NSData *)sd_imageDataAsFormat:(SDImageFormat)imageFormat; @end diff --git a/SDWebImage/UIImageView+WebCache.h b/SDWebImage/UIImageView+WebCache.h index ef2eacfd..7b7d530d 100644 --- a/SDWebImage/UIImageView+WebCache.h +++ b/SDWebImage/UIImageView+WebCache.h @@ -154,31 +154,6 @@ progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock completed:(nullable SDExternalCompletionBlock)completedBlock; -/** - * Set the imageView `image` with an `url` and custom options. The placeholder image is from previous cached image and will use the provided one instead if the query failed. - * This method was designed to ensure that placeholder and query cache process happened in the same runloop to avoid flashing on cell during two `setImage:` call. But it's really misunderstanding and deprecated. - * This can be done by using `sd_setImageWithURL:` with `SDWebImageQueryDiskSync`. But take care that if the memory cache missed, query disk cache synchronously may reduce the frame rate - * - * The download is asynchronous and cached. - * - * @param url The url for the image. - * @param placeholder The image to be set initially, until the image request finishes. - * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. - * @param progressBlock A block called while image is downloading - * @note the progress block is executed on a background queue - * @param completedBlock A block called when operation has been completed. This block has no return value - * and takes the requested UIImage as first parameter. In case of error the image parameter - * is nil and the second parameter may contain an NSError. The third parameter is a Boolean - * indicating if the image was retrieved from the local cache or from the network. - * The fourth parameter is the original image url. - * @deprecated consider using `SDWebImageQueryDiskSync` options with `sd_setImageWithURL:` instead - */ -- (void)sd_setImageWithPreviousCachedImageWithURL:(nullable NSURL *)url - placeholderImage:(nullable UIImage *)placeholder - options:(SDWebImageOptions)options - progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock - completed:(nullable SDExternalCompletionBlock)completedBlock __deprecated_msg("This method is misunderstanding and deprecated, consider using `SDWebImageQueryDiskSync` options with `sd_setImageWithURL:` instead"); - #if SD_UIKIT #pragma mark - Animation of multiple images @@ -190,6 +165,9 @@ */ - (void)sd_setAnimationImagesWithURLs:(nonnull NSArray *)arrayOfURLs; +/** + * Cancel the current animation images load + */ - (void)sd_cancelCurrentAnimationImagesLoad; #endif diff --git a/SDWebImage/UIImageView+WebCache.m b/SDWebImage/UIImageView+WebCache.m index aa8ce431..cc9b476d 100644 --- a/SDWebImage/UIImageView+WebCache.m +++ b/SDWebImage/UIImageView+WebCache.m @@ -54,17 +54,6 @@ completed:completedBlock]; } -- (void)sd_setImageWithPreviousCachedImageWithURL:(nullable NSURL *)url - placeholderImage:(nullable UIImage *)placeholder - options:(SDWebImageOptions)options - progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock - completed:(nullable SDExternalCompletionBlock)completedBlock { - NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url]; - UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromCacheForKey:key]; - - [self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock]; -} - #if SD_UIKIT #pragma mark - Animation of multiple images diff --git a/SDWebImage/UIView+WebCache.h b/SDWebImage/UIView+WebCache.h index 941d0f3a..dea29aa9 100644 --- a/SDWebImage/UIView+WebCache.h +++ b/SDWebImage/UIView+WebCache.h @@ -34,7 +34,7 @@ typedef void(^SDSetImageBlock)(UIImage * _Nullable image, NSData * _Nullable ima * * @note Note that because of the limitations of categories this property can get out of sync if you use setImage: directly. */ -- (nullable NSURL *)sd_imageURL; +@property (nonatomic, strong, readonly, nullable) NSURL *sd_imageURL; /** * The current image loading progress associated to the view. The unit count is the received size and excepted size of download. diff --git a/SDWebImage/UIView+WebCache.m b/SDWebImage/UIView+WebCache.m index d4cc8984..c12baeaa 100644 --- a/SDWebImage/UIView+WebCache.m +++ b/SDWebImage/UIView+WebCache.m @@ -32,6 +32,10 @@ static char TAG_ACTIVITY_SHOW; return objc_getAssociatedObject(self, &imageURLKey); } +- (void)setSd_imageURL:(NSURL * _Nullable)sd_imageURL { + objc_setAssociatedObject(self, &imageURLKey, sd_imageURL, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + - (NSProgress *)sd_imageProgress { NSProgress *progress = objc_getAssociatedObject(self, @selector(sd_imageProgress)); if (!progress) { @@ -65,7 +69,7 @@ static char TAG_ACTIVITY_SHOW; context:(nullable NSDictionary *)context { NSString *validOperationKey = operationKey ?: NSStringFromClass([self class]); [self sd_cancelImageLoadOperationWithKey:validOperationKey]; - objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + self.sd_imageURL = url; if (!(options & SDWebImageDelayPlaceholder)) { if ([context valueForKey:SDWebImageInternalSetImageGroupKey]) { From d4daca3c1271b768c2dd4b4a212872f10711a407 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sun, 21 Jan 2018 23:26:47 +0800 Subject: [PATCH 10/10] Change our SDScaledImageForKey to use scale on macOS --- SDWebImage/SDWebImageCompat.m | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/SDWebImage/SDWebImageCompat.m b/SDWebImage/SDWebImageCompat.m index b3377e6a..35dedc42 100644 --- a/SDWebImage/SDWebImageCompat.m +++ b/SDWebImage/SDWebImageCompat.m @@ -23,9 +23,7 @@ inline UIImage *SDScaledImageForKey(NSString * _Nullable key, UIImage * _Nullabl return nil; } -#if SD_MAC - return image; -#elif SD_UIKIT || SD_WATCH +#if SD_UIKIT || SD_WATCH if ((image.images).count > 0) { NSMutableArray *scaledImages = [NSMutableArray array]; @@ -39,10 +37,13 @@ inline UIImage *SDScaledImageForKey(NSString * _Nullable key, UIImage * _Nullabl } return animatedImage; } else { +#endif #if SD_WATCH if ([[WKInterfaceDevice currentDevice] respondsToSelector:@selector(screenScale)]) { #elif SD_UIKIT if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { +#elif SD_MAC + if ([[NSScreen mainScreen] respondsToSelector:@selector(backingScaleFactor)]) { #endif CGFloat scale = 1; if (key.length >= 8) { @@ -56,11 +57,17 @@ inline UIImage *SDScaledImageForKey(NSString * _Nullable key, UIImage * _Nullabl scale = 3.0; } } - - UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation]; - image = scaledImage; + if (scale > 1) { +#if SD_UIKIT || SD_WATCH + UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation]; +#else + UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale]; +#endif + image = scaledImage; + } } return image; +#if SD_UIKIT || SD_WATCH } #endif }