Rename `SDWebImageCoder` to `SDImageCoder`.

Rename `SDWebImageProgressiveCoder` to `SDProgressiveImageCoder`
Rename `SDWebImageAnimatedCoder` to `SDAnimatedImageCoder`
This commit is contained in:
DreamPiggy 2018-04-26 22:39:52 +08:00
parent 5d7625f567
commit 15bceab71c
24 changed files with 196 additions and 196 deletions

View File

@ -75,18 +75,18 @@
321B37982083290E00C0EA77 /* SDWebImageLoadersManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 321B37802083290E00C0EA77 /* SDWebImageLoadersManager.m */; };
321DB3612011D4D70015D2CB /* NSButton+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 321DB35F2011D4D60015D2CB /* NSButton+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; };
321DB3622011D4D70015D2CB /* NSButton+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 321DB3602011D4D60015D2CB /* NSButton+WebCache.m */; };
321E60861F38E8C800405457 /* SDWebImageCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 321E60841F38E8C800405457 /* SDWebImageCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
321E60871F38E8C800405457 /* SDWebImageCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 321E60841F38E8C800405457 /* SDWebImageCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
321E60881F38E8C800405457 /* SDWebImageCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 321E60841F38E8C800405457 /* SDWebImageCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
321E60891F38E8C800405457 /* SDWebImageCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 321E60841F38E8C800405457 /* SDWebImageCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
321E608A1F38E8C800405457 /* SDWebImageCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 321E60841F38E8C800405457 /* SDWebImageCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
321E608B1F38E8C800405457 /* SDWebImageCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 321E60841F38E8C800405457 /* SDWebImageCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
321E608C1F38E8C800405457 /* SDWebImageCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60851F38E8C800405457 /* SDWebImageCoder.m */; };
321E608D1F38E8C800405457 /* SDWebImageCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60851F38E8C800405457 /* SDWebImageCoder.m */; };
321E608E1F38E8C800405457 /* SDWebImageCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60851F38E8C800405457 /* SDWebImageCoder.m */; };
321E608F1F38E8C800405457 /* SDWebImageCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60851F38E8C800405457 /* SDWebImageCoder.m */; };
321E60901F38E8C800405457 /* SDWebImageCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60851F38E8C800405457 /* SDWebImageCoder.m */; };
321E60911F38E8C800405457 /* SDWebImageCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60851F38E8C800405457 /* SDWebImageCoder.m */; };
321E60861F38E8C800405457 /* SDImageCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 321E60841F38E8C800405457 /* SDImageCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
321E60871F38E8C800405457 /* SDImageCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 321E60841F38E8C800405457 /* SDImageCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
321E60881F38E8C800405457 /* SDImageCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 321E60841F38E8C800405457 /* SDImageCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
321E60891F38E8C800405457 /* SDImageCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 321E60841F38E8C800405457 /* SDImageCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
321E608A1F38E8C800405457 /* SDImageCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 321E60841F38E8C800405457 /* SDImageCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
321E608B1F38E8C800405457 /* SDImageCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 321E60841F38E8C800405457 /* SDImageCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
321E608C1F38E8C800405457 /* SDImageCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60851F38E8C800405457 /* SDImageCoder.m */; };
321E608D1F38E8C800405457 /* SDImageCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60851F38E8C800405457 /* SDImageCoder.m */; };
321E608E1F38E8C800405457 /* SDImageCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60851F38E8C800405457 /* SDImageCoder.m */; };
321E608F1F38E8C800405457 /* SDImageCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60851F38E8C800405457 /* SDImageCoder.m */; };
321E60901F38E8C800405457 /* SDImageCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60851F38E8C800405457 /* SDImageCoder.m */; };
321E60911F38E8C800405457 /* SDImageCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60851F38E8C800405457 /* SDImageCoder.m */; };
321E60941F38E8ED00405457 /* SDWebImageImageIOCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 321E60921F38E8ED00405457 /* SDWebImageImageIOCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
321E60951F38E8ED00405457 /* SDWebImageImageIOCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 321E60921F38E8ED00405457 /* SDWebImageImageIOCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
321E60961F38E8ED00405457 /* SDWebImageImageIOCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 321E60921F38E8ED00405457 /* SDWebImageImageIOCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -1551,8 +1551,8 @@
321B37802083290E00C0EA77 /* SDWebImageLoadersManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageLoadersManager.m; sourceTree = "<group>"; };
321DB35F2011D4D60015D2CB /* NSButton+WebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSButton+WebCache.h"; path = "SDWebImage/NSButton+WebCache.h"; sourceTree = "<group>"; };
321DB3602011D4D60015D2CB /* NSButton+WebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSButton+WebCache.m"; path = "SDWebImage/NSButton+WebCache.m"; sourceTree = "<group>"; };
321E60841F38E8C800405457 /* SDWebImageCoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageCoder.h; sourceTree = "<group>"; };
321E60851F38E8C800405457 /* SDWebImageCoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageCoder.m; sourceTree = "<group>"; };
321E60841F38E8C800405457 /* SDImageCoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDImageCoder.h; sourceTree = "<group>"; };
321E60851F38E8C800405457 /* SDImageCoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDImageCoder.m; sourceTree = "<group>"; };
321E60921F38E8ED00405457 /* SDWebImageImageIOCoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageImageIOCoder.h; sourceTree = "<group>"; };
321E60931F38E8ED00405457 /* SDWebImageImageIOCoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageImageIOCoder.m; sourceTree = "<group>"; };
321E60A01F38E8F600405457 /* SDWebImageGIFCoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageGIFCoder.h; sourceTree = "<group>"; };
@ -1871,8 +1871,8 @@
children = (
807A12261F89636300EC2A9B /* SDWebImageCodersManager.h */,
807A12271F89636300EC2A9B /* SDWebImageCodersManager.m */,
321E60841F38E8C800405457 /* SDWebImageCoder.h */,
321E60851F38E8C800405457 /* SDWebImageCoder.m */,
321E60841F38E8C800405457 /* SDImageCoder.h */,
321E60851F38E8C800405457 /* SDImageCoder.m */,
321E60921F38E8ED00405457 /* SDWebImageImageIOCoder.h */,
321E60931F38E8ED00405457 /* SDWebImageImageIOCoder.m */,
321E60A01F38E8F600405457 /* SDWebImageGIFCoder.h */,
@ -2439,7 +2439,7 @@
00733A661BC4880E00A5A117 /* SDWebImageDownloaderOperation.h in Headers */,
80377C5D1F2F666300F89830 /* thread_utils.h in Headers */,
328BB6D02082581100760D6C /* SDMemoryCache.h in Headers */,
321E60891F38E8C800405457 /* SDWebImageCoder.h in Headers */,
321E60891F38E8C800405457 /* SDImageCoder.h in Headers */,
00733A721BC4880E00A5A117 /* UIView+WebCacheOperation.h in Headers */,
321B37842083290E00C0EA77 /* SDWebImageLoader.h in Headers */,
80377C481F2F666300F89830 /* bit_reader_utils.h in Headers */,
@ -2521,7 +2521,7 @@
80377C121F2F666300F89830 /* bit_reader_inl_utils.h in Headers */,
4314D1701D0E0E3B004B36C9 /* mux.h in Headers */,
321B378E2083290E00C0EA77 /* SDWebImageLoadersManager.h in Headers */,
321E60871F38E8C800405457 /* SDWebImageCoder.h in Headers */,
321E60871F38E8C800405457 /* SDImageCoder.h in Headers */,
80377EA21F2F66D400F89830 /* vp8i_dec.h in Headers */,
320CAE162086F50500CFFC80 /* SDWebImageError.h in Headers */,
3248476A201775F600AF9E5A /* SDAnimatedImageView.h in Headers */,
@ -2594,7 +2594,7 @@
80377C691F2F666400F89830 /* filters_utils.h in Headers */,
80377EC81F2F66D500F89830 /* alphai_dec.h in Headers */,
43A62A1B1D0E0A800089D7DD /* decode.h in Headers */,
321E608A1F38E8C800405457 /* SDWebImageCoder.h in Headers */,
321E608A1F38E8C800405457 /* SDImageCoder.h in Headers */,
32484767201775F600AF9E5A /* SDAnimatedImageView+WebCache.h in Headers */,
80377C601F2F666400F89830 /* bit_reader_inl_utils.h in Headers */,
32FDE89920888726008D7530 /* UIImage+WebP.h in Headers */,
@ -2760,7 +2760,7 @@
4397D2E61D0DDD8C00BB2784 /* encode.h in Headers */,
32FDE89A20888726008D7530 /* UIImage+WebP.h in Headers */,
80377C7C1F2F666400F89830 /* bit_reader_utils.h in Headers */,
321E608B1F38E8C800405457 /* SDWebImageCoder.h in Headers */,
321E608B1F38E8C800405457 /* SDImageCoder.h in Headers */,
323F8B731F38EF770092B609 /* delta_palettization_enc.h in Headers */,
321E60C31F38E91700405457 /* UIImage+ForceDecode.h in Headers */,
32D122352080B2EB003685A3 /* SDImageCachesManager.h in Headers */,
@ -2837,7 +2837,7 @@
4A2CAE251AB4BB7000B6BC39 /* SDWebImagePrefetcher.h in Headers */,
80377C431F2F666300F89830 /* thread_utils.h in Headers */,
328BB6CF2082581100760D6C /* SDMemoryCache.h in Headers */,
321E60881F38E8C800405457 /* SDWebImageCoder.h in Headers */,
321E60881F38E8C800405457 /* SDImageCoder.h in Headers */,
4A2CAE371AB4BB7500B6BC39 /* UIView+WebCacheOperation.h in Headers */,
321B37832083290E00C0EA77 /* SDWebImageLoader.h in Headers */,
80377C2E1F2F666300F89830 /* bit_reader_utils.h in Headers */,
@ -2960,7 +2960,7 @@
323F8B861F38EF770092B609 /* histogram_enc.h in Headers */,
321B37812083290E00C0EA77 /* SDWebImageLoader.h in Headers */,
323F8BF61F38EF770092B609 /* animi.h in Headers */,
321E60861F38E8C800405457 /* SDWebImageCoder.h in Headers */,
321E60861F38E8C800405457 /* SDImageCoder.h in Headers */,
80377C0D1F2F665300F89830 /* rescaler_utils.h in Headers */,
32484763201775F600AF9E5A /* SDAnimatedImageView+WebCache.h in Headers */,
80377E911F2F66D000F89830 /* vp8_dec.h in Headers */,
@ -3302,7 +3302,7 @@
323F8BD51F38EF770092B609 /* tree_enc.c in Sources */,
80377DBB1F2F66A700F89830 /* dec_sse2.c in Sources */,
323F8B831F38EF770092B609 /* histogram_enc.c in Sources */,
321E608F1F38E8C800405457 /* SDWebImageCoder.m in Sources */,
321E608F1F38E8C800405457 /* SDImageCoder.m in Sources */,
00733A581BC4880000A5A117 /* SDWebImageManager.m in Sources */,
323F8B411F38EF770092B609 /* alpha_enc.c in Sources */,
323F8BC31F38EF770092B609 /* quant_enc.c in Sources */,
@ -3399,7 +3399,7 @@
80377D4B1F2F66A700F89830 /* lossless_msa.c in Sources */,
323F8B5D1F38EF770092B609 /* cost_enc.c in Sources */,
80377D3B1F2F66A700F89830 /* enc_sse41.c in Sources */,
321E608D1F38E8C800405457 /* SDWebImageCoder.m in Sources */,
321E608D1F38E8C800405457 /* SDImageCoder.m in Sources */,
80377D3A1F2F66A700F89830 /* enc_sse2.c in Sources */,
80377D381F2F66A700F89830 /* enc_msa.c in Sources */,
4314D1311D0E0E3B004B36C9 /* SDWebImageDownloader.m in Sources */,
@ -3566,7 +3566,7 @@
80377E1A1F2F66A800F89830 /* lossless_msa.c in Sources */,
323F8B601F38EF770092B609 /* cost_enc.c in Sources */,
80377E0A1F2F66A800F89830 /* enc_sse41.c in Sources */,
321E60901F38E8C800405457 /* SDWebImageCoder.m in Sources */,
321E60901F38E8C800405457 /* SDImageCoder.m in Sources */,
80377E091F2F66A800F89830 /* enc_sse2.c in Sources */,
431BB6921D06D2C1006A3455 /* NSData+ImageContentType.m in Sources */,
80377E071F2F66A800F89830 /* enc_msa.c in Sources */,
@ -3706,7 +3706,7 @@
80377E471F2F66A800F89830 /* dec.c in Sources */,
80377C921F2F666400F89830 /* utils.c in Sources */,
4397D27E1D0DDD8C00BB2784 /* UIImage+GIF.m in Sources */,
321E60911F38E8C800405457 /* SDWebImageCoder.m in Sources */,
321E60911F38E8C800405457 /* SDImageCoder.m in Sources */,
80377C8A1F2F666400F89830 /* quant_levels_utils.c in Sources */,
4397D2F71D0DE2DF00BB2784 /* NSImage+Compatibility.m in Sources */,
80377E751F2F66A800F89830 /* yuv.c in Sources */,
@ -3970,7 +3970,7 @@
323F8BD41F38EF770092B609 /* tree_enc.c in Sources */,
80377D651F2F66A700F89830 /* alpha_processing_sse2.c in Sources */,
323F8B821F38EF770092B609 /* histogram_enc.c in Sources */,
321E608E1F38E8C800405457 /* SDWebImageCoder.m in Sources */,
321E608E1F38E8C800405457 /* SDImageCoder.m in Sources */,
4A2CAE301AB4BB7500B6BC39 /* UIImage+MultiFormat.m in Sources */,
323F8B401F38EF770092B609 /* alpha_enc.c in Sources */,
80377C2D1F2F666300F89830 /* bit_reader_utils.c in Sources */,
@ -4140,7 +4140,7 @@
323F8BD21F38EF770092B609 /* tree_enc.c in Sources */,
80377CDB1F2F66A100F89830 /* alpha_processing_sse2.c in Sources */,
323F8B801F38EF770092B609 /* histogram_enc.c in Sources */,
321E608C1F38E8C800405457 /* SDWebImageCoder.m in Sources */,
321E608C1F38E8C800405457 /* SDImageCoder.m in Sources */,
5376130E155AD0D5005750A4 /* UIButton+WebCache.m in Sources */,
323F8B3E1F38EF770092B609 /* alpha_enc.c in Sources */,
80377BF91F2F665300F89830 /* bit_reader_utils.c in Sources */,

View File

@ -7,7 +7,7 @@
*/
#import "SDWebImageCompat.h"
#import "SDWebImageCoder.h"
#import "SDImageCoder.h"
/**
@ -18,13 +18,13 @@
@required
/**
Initializes the image with an animated coder. You can use the coder to decode the image frame later.
@note Normally we use `initWithData:scale:` to create custom animated image class. However, for progressive image decoding, we will use this with animated coder which conforms to `SDWebImageProgressiveCoder` as well instead.
@note Normally we use `initWithData:scale:` to create custom animated image class. However, for progressive image decoding, we will use this with animated coder which conforms to `SDProgressiveImageCoder` as well instead.
@param animatedCoder An animated coder which conform `SDWebImageAnimatedCoder` protocol
@param scale The scale factor to assume when interpreting the image data. Applying a scale factor of 1.0 results in an image whose size matches the pixel-based dimensions of the image. Applying a different scale factor changes the size of the image as reported by the `size` property.
@return An initialized object
*/
- (nullable instancetype)initWithAnimatedCoder:(nonnull id<SDWebImageAnimatedCoder>)animatedCoder scale:(CGFloat)scale;
- (nullable instancetype)initWithAnimatedCoder:(nonnull id<SDAnimatedImageCoder>)animatedCoder scale:(CGFloat)scale;
@optional
/**
@ -63,7 +63,7 @@
- (nullable instancetype)initWithContentsOfFile:(nonnull NSString *)path;
- (nullable instancetype)initWithData:(nonnull NSData *)data;
- (nullable instancetype)initWithData:(nonnull NSData *)data scale:(CGFloat)scale;
- (nullable instancetype)initWithAnimatedCoder:(nonnull id<SDWebImageAnimatedCoder>)animatedCoder scale:(CGFloat)scale;
- (nullable instancetype)initWithAnimatedCoder:(nonnull id<SDAnimatedImageCoder>)animatedCoder scale:(CGFloat)scale;
/**
Current animated image format.

View File

@ -9,7 +9,7 @@
#import "SDAnimatedImage.h"
#import "NSImage+Compatibility.h"
#import "UIImage+WebCache.h"
#import "SDWebImageCoder.h"
#import "SDImageCoder.h"
#import "SDWebImageCodersManager.h"
#import "SDWebImageFrame.h"
@ -197,7 +197,7 @@ static NSArray *SDBundlePreferredScales() {
@interface SDAnimatedImage ()
@property (nonatomic, strong) id<SDWebImageAnimatedCoder> coder;
@property (nonatomic, strong) id<SDAnimatedImageCoder> coder;
@property (nonatomic, assign, readwrite) SDImageFormat animatedImageFormat;
@property (atomic, copy) NSArray<SDWebImageFrame *> *loadedAnimatedImageFrames; // Mark as atomic to keep thread-safe
@property (nonatomic, assign, getter=isAllFramesLoaded) BOOL allFramesLoaded;
@ -285,11 +285,11 @@ static NSArray *SDBundlePreferredScales() {
return nil;
}
data = [data copy]; // avoid mutable data
id<SDWebImageAnimatedCoder> animatedCoder = nil;
for (id<SDWebImageCoder>coder in [SDWebImageCodersManager sharedManager].coders) {
if ([coder conformsToProtocol:@protocol(SDWebImageAnimatedCoder)]) {
id<SDAnimatedImageCoder> animatedCoder = nil;
for (id<SDImageCoder>coder in [SDWebImageCodersManager sharedManager].coders) {
if ([coder conformsToProtocol:@protocol(SDAnimatedImageCoder)]) {
if ([coder canDecodeFromData:data]) {
animatedCoder = [[[coder class] alloc] initWithAnimatedImageData:data options:@{SDWebImageCoderDecodeScaleFactor : @(scale)}];
animatedCoder = [[[coder class] alloc] initWithAnimatedImageData:data options:@{SDImageCoderDecodeScaleFactor : @(scale)}];
break;
}
}
@ -300,7 +300,7 @@ static NSArray *SDBundlePreferredScales() {
return [self initWithAnimatedCoder:animatedCoder scale:scale];
}
- (instancetype)initWithAnimatedCoder:(id<SDWebImageAnimatedCoder>)animatedCoder scale:(CGFloat)scale {
- (instancetype)initWithAnimatedCoder:(id<SDAnimatedImageCoder>)animatedCoder scale:(CGFloat)scale {
if (!animatedCoder) {
return nil;
}
@ -356,11 +356,11 @@ static NSArray *SDBundlePreferredScales() {
if (!animatedImageData) {
return self;
}
id<SDWebImageAnimatedCoder> animatedCoder = nil;
for (id<SDWebImageCoder>coder in [SDWebImageCodersManager sharedManager].coders) {
if ([coder conformsToProtocol:@protocol(SDWebImageAnimatedCoder)]) {
id<SDAnimatedImageCoder> animatedCoder = nil;
for (id<SDImageCoder>coder in [SDWebImageCodersManager sharedManager].coders) {
if ([coder conformsToProtocol:@protocol(SDAnimatedImageCoder)]) {
if ([coder canDecodeFromData:animatedImageData]) {
animatedCoder = [[[coder class] alloc] initWithAnimatedImageData:animatedImageData options:@{SDWebImageCoderDecodeScaleFactor : @(scale)}];
animatedCoder = [[[coder class] alloc] initWithAnimatedImageData:animatedImageData options:@{SDImageCoderDecodeScaleFactor : @(scale)}];
break;
}
}

View File

@ -53,7 +53,7 @@
/**
Whehter or not to enable incremental image load for animated image. This is for the animated image which `sd_isIncremental` is YES (See `UIImage+WebCache.h`). If enable, animated image rendering will stop at the last frame available currently, and continue when another `setImage:` trigger, where the new animated image's `animatedImageData` should be updated from the previous one. If the `sd_isIncremental` is NO. The incremental image load stop.
@note If you are confused about this description, open Chrome browser to view some large GIF images with low network speed to see the animation behavior.
@note The best practice to use incremental load is using `initWithAnimatedCoder:scale` in `SDAnimatedImage` with animated coder which conform to `SDWebImageProgressiveCoder` as well. Then call incremental update and incremental decode method to produce the image.
@note The best practice to use incremental load is using `initWithAnimatedCoder:scale` in `SDAnimatedImage` with animated coder which conform to `SDProgressiveImageCoder` as well. Then call incremental update and incremental decode method to produce the image.
Default is YES. Set to NO to only render the static poster for incremental animated image.
*/
@property (nonatomic, assign) BOOL shouldIncrementalLoad;

View File

@ -33,7 +33,7 @@ UIImage * _Nullable SDImageCacheDecodeImageData(NSData * _Nonnull imageData, NSS
}
}
if (!image) {
image = [[SDWebImageCodersManager sharedManager] decodedImageWithData:imageData options:@{SDWebImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDWebImageCoderDecodeScaleFactor : @(scale)}];
image = [[SDWebImageCodersManager sharedManager] decodedImageWithData:imageData options:@{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)}];
}
if (image) {
BOOL shouldDecode = (options & SDWebImageAvoidDecodeImage) == 0;

View File

@ -10,33 +10,33 @@
#import "SDWebImageCompat.h"
#import "NSData+ImageContentType.h"
typedef NSString * SDWebImageCoderOption NS_STRING_ENUM;
typedef NSDictionary<SDWebImageCoderOption, id> SDWebImageCoderOptions;
typedef NSString * SDImageCoderOption NS_STRING_ENUM;
typedef NSDictionary<SDImageCoderOption, id> SDImageCoderOptions;
#pragma mark - Coder Options
// These options are for image decoding
/**
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.
@note works for `SDWebImageCoder`.
@note works for `SDImageCoder`.
*/
FOUNDATION_EXPORT SDWebImageCoderOption _Nonnull const SDWebImageCoderDecodeFirstFrameOnly;
FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderDecodeFirstFrameOnly;
/**
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)
@note works for `SDWebImageCoder`, `SDWebImageProgressiveCoder`, `SDWebImageAnimatedCoder`.
@note works for `SDImageCoder`, `SDProgressiveImageCoder`, `SDWebImageAnimatedCoder`.
*/
FOUNDATION_EXPORT SDWebImageCoderOption _Nonnull const SDWebImageCoderDecodeScaleFactor;
FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderDecodeScaleFactor;
// These options are for image encoding
/**
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.
@note works for `SDWebImageCoder`.
@note works for `SDImageCoder`.
*/
FOUNDATION_EXPORT SDWebImageCoderOption _Nonnull const SDWebImageCoderEncodeFirstFrameOnly;
FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderEncodeFirstFrameOnly;
/**
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)
@note works for `SDWebImageCoder`
@note works for `SDImageCoder`
*/
FOUNDATION_EXPORT SDWebImageCoderOption _Nonnull const SDWebImageCoderEncodeCompressionQuality;
FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderEncodeCompressionQuality;
#pragma mark - Coder
/**
@ -45,7 +45,7 @@ FOUNDATION_EXPORT SDWebImageCoderOption _Nonnull const SDWebImageCoderEncodeComp
You do not need to specify image scale during decoding because we may scale image later.
@note Pay attention that these methods are not called from main queue.
*/
@protocol SDWebImageCoder <NSObject>
@protocol SDImageCoder <NSObject>
@required
#pragma mark - Decoding
@ -59,14 +59,14 @@ FOUNDATION_EXPORT SDWebImageCoderOption _Nonnull const SDWebImageCoderEncodeComp
/**
Decode the image data to image.
@note This protocol may supports decode animated image frames. You can use `+[SDWebImageCoderHelper animatedImageWithFrames:]` to produce an animated image with frames.
@note This protocol may supports decode animated image frames. You can use `+[SDImageCoderHelper animatedImageWithFrames:]` to produce an animated image with frames.
@param data The image data to be decoded
@param options A dictionary containing any decoding options. Pass @{SDWebImageCoderDecodeFirstFrameOnly: @(YES)} to decode the first frame only.
@param options A dictionary containing any decoding options. Pass @{SDImageCoderDecodeFirstFrameOnly: @(YES)} to decode the first frame only.
@return The decoded image from data
*/
- (nullable UIImage *)decodedImageWithData:(nullable NSData *)data
options:(nullable SDWebImageCoderOptions *)options;
options:(nullable SDImageCoderOptions *)options;
#pragma mark - Encoding
@ -80,16 +80,16 @@ FOUNDATION_EXPORT SDWebImageCoderOption _Nonnull const SDWebImageCoderEncodeComp
/**
Encode the image to image data.
@note This protocol may supports encode animated image frames. You can use `+[SDWebImageCoderHelper framesFromAnimatedImage:]` to assemble an animated image with frames.
@note This protocol may supports encode animated image frames. You can use `+[SDImageCoderHelper framesFromAnimatedImage:]` to assemble an animated image with frames.
@param image The image to be encoded
@param format The image format to encode, you should note `SDImageFormatUndefined` format is also possible
@param options A dictionary containing any encoding options. Pass @{SDWebImageCoderEncodeCompressionQuality: @(1)} to specify compression quality.
@param options A dictionary containing any encoding options. Pass @{SDImageCoderEncodeCompressionQuality: @(1)} to specify compression quality.
@return The encoded image data
*/
- (nullable NSData *)encodedDataWithImage:(nullable UIImage *)image
format:(SDImageFormat)format
options:(nullable SDWebImageCoderOptions *)options;
options:(nullable SDImageCoderOptions *)options;
@end
@ -99,7 +99,7 @@ FOUNDATION_EXPORT SDWebImageCoderOption _Nonnull const SDWebImageCoderEncodeComp
These methods are all required to implement.
@note Pay attention that these methods are not called from main queue.
*/
@protocol SDWebImageProgressiveCoder <SDWebImageCoder>
@protocol SDProgressiveImageCoder <SDImageCoder>
@required
/**
@ -114,10 +114,10 @@ FOUNDATION_EXPORT SDWebImageCoderOption _Nonnull const SDWebImageCoderEncodeComp
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
This init method should not return nil
@param options A dictionary containing any progressive decoding options (instance-level). Pass @{SDWebImageCoderDecodeScaleFactor: @(1.0)} to specify scale factor for progressive animated image (each frames should use the same scale).
@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).
@return A new instance to do incremental decoding for the specify image format
*/
- (nonnull instancetype)initIncrementalWithOptions:(nullable SDWebImageCoderOptions *)options;
- (nonnull instancetype)initIncrementalWithOptions:(nullable SDImageCoderOptions *)options;
/**
Update the incremental decoding when new image data available
@ -131,10 +131,10 @@ FOUNDATION_EXPORT SDWebImageCoderOption _Nonnull const SDWebImageCoderEncodeComp
Incremental decode the current image data to image.
@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 `SDWebImageAnimatedCoder` protocol as well and use `animatedImageFrameAtIndex:` instead.
@param options A dictionary containing any progressive decoding options. Pass @{SDWebImageCoderDecodeScaleFactor: @(1.0)} to specify scale factor for progressive image
@param options A dictionary containing any progressive decoding options. Pass @{SDImageCoderDecodeScaleFactor: @(1.0)} to specify scale factor for progressive image
@return The decoded image from current data
*/
- (nullable UIImage *)incrementalDecodedImageWithOptions:(nullable SDWebImageCoderOptions *)options;
- (nullable UIImage *)incrementalDecodedImageWithOptions:(nullable SDImageCoderOptions *)options;
@end
@ -187,9 +187,9 @@ FOUNDATION_EXPORT SDWebImageCoderOption _Nonnull const SDWebImageCoderEncodeComp
#pragma mark - Animated Coder
/**
This is the animated image coder protocol for custom animated image class like `SDAnimatedImage`. Through it inherit from `SDWebImageCoder`. We currentlly only use the method `canDecodeFromData:` to detect the proper coder for specify animated image format.
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.
*/
@protocol SDWebImageAnimatedCoder <SDWebImageCoder, SDAnimatedImageProvider>
@protocol SDAnimatedImageCoder <SDImageCoder, SDAnimatedImageProvider>
@required
/**
@ -198,9 +198,9 @@ FOUNDATION_EXPORT SDWebImageCoderOption _Nonnull const SDWebImageCoderEncodeComp
After the instance created, we may call methods in `SDAnimatedImageProvider` to produce animated image frame.
@param data The animated image data to be decode
@param options A dictionary containing any animated decoding options (instance-level). Pass @{SDWebImageCoderDecodeScaleFactor: @(1.0)} to specify scale factor for animated image (each frames should use the same scale).
@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).
@return A new instance to do animated decoding for specify image data
*/
- (nullable instancetype)initWithAnimatedImageData:(nullable NSData *)data options:(nullable SDWebImageCoderOptions *)options;
- (nullable instancetype)initWithAnimatedImageData:(nullable NSData *)data options:(nullable SDImageCoderOptions *)options;
@end

15
SDWebImage/SDImageCoder.m Normal file
View File

@ -0,0 +1,15 @@
/*
* This file is part of the SDWebImage package.
* (c) Olivier Poitrey <rs@dailymotion.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
#import "SDImageCoder.h"
SDImageCoderOption const SDImageCoderDecodeFirstFrameOnly = @"decodeFirstFrameOnly";
SDImageCoderOption const SDImageCoderDecodeScaleFactor = @"decodeScaleFactor";
SDImageCoderOption const SDImageCoderEncodeFirstFrameOnly = @"encodeFirstFrameOnly";
SDImageCoderOption const SDImageCoderEncodeCompressionQuality = @"encodeCompressionQuality";

View File

@ -7,12 +7,12 @@
*/
#import <Foundation/Foundation.h>
#import "SDWebImageCoder.h"
#import "SDImageCoder.h"
/**
Built in coder using ImageIO that supports APNG encoding/decoding
*/
@interface SDWebImageAPNGCoder : NSObject <SDWebImageProgressiveCoder, SDWebImageAnimatedCoder>
@interface SDWebImageAPNGCoder : NSObject <SDProgressiveImageCoder, SDAnimatedImageCoder>
@property (nonatomic, class, readonly, nonnull) SDWebImageAPNGCoder *sharedCoder;

View File

@ -76,13 +76,13 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
return ([NSData sd_imageFormatForImageData:data] == SDImageFormatPNG);
}
- (UIImage *)decodedImageWithData:(NSData *)data options:(nullable SDWebImageCoderOptions *)options {
- (UIImage *)decodedImageWithData:(NSData *)data options:(nullable SDImageCoderOptions *)options {
if (!data) {
return nil;
}
CGFloat scale = 1;
if ([options valueForKey:SDWebImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDWebImageCoderDecodeScaleFactor] doubleValue];
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
if (scale < 1) {
scale = 1;
}
@ -104,7 +104,7 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
size_t count = CGImageSourceGetCount(source);
UIImage *animatedImage;
BOOL decodeFirstFrame = [options[SDWebImageCoderDecodeFirstFrameOnly] boolValue];
BOOL decodeFirstFrame = [options[SDImageCoderDecodeFirstFrameOnly] boolValue];
if (decodeFirstFrame || count <= 1) {
animatedImage = [[UIImage alloc] initWithData:data scale:scale];
} else {
@ -178,7 +178,7 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
return (format == SDImageFormatPNG);
}
- (NSData *)encodedDataWithImage:(UIImage *)image format:(SDImageFormat)format options:(nullable SDWebImageCoderOptions *)options {
- (NSData *)encodedDataWithImage:(UIImage *)image format:(SDImageFormat)format options:(nullable SDImageCoderOptions *)options {
if (!image) {
return nil;
}
@ -199,12 +199,12 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
}
NSMutableDictionary *properties = [NSMutableDictionary dictionary];
double compressionQuality = 1;
if ([options valueForKey:SDWebImageCoderEncodeCompressionQuality]) {
compressionQuality = [[options valueForKey:SDWebImageCoderEncodeCompressionQuality] doubleValue];
if ([options valueForKey:SDImageCoderEncodeCompressionQuality]) {
compressionQuality = [[options valueForKey:SDImageCoderEncodeCompressionQuality] doubleValue];
}
[properties setValue:@(compressionQuality) forKey:(__bridge_transfer NSString *)kCGImageDestinationLossyCompressionQuality];
BOOL encodeFirstFrame = [options[SDWebImageCoderEncodeFirstFrameOnly] boolValue];
BOOL encodeFirstFrame = [options[SDImageCoderEncodeFirstFrameOnly] boolValue];
if (encodeFirstFrame || frames.count == 0) {
// for static single PNG images
CGImageDestinationAddImage(imageDestination, image.CGImage, (__bridge CFDictionaryRef)properties);
@ -240,14 +240,14 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
return ([NSData sd_imageFormatForImageData:data] == SDImageFormatPNG);
}
- (instancetype)initIncrementalWithOptions:(nullable SDWebImageCoderOptions *)options {
- (instancetype)initIncrementalWithOptions:(nullable SDImageCoderOptions *)options {
self = [super init];
if (self) {
CFStringRef imageUTType = [NSData sd_UTTypeFromSDImageFormat:SDImageFormatPNG];
_imageSource = CGImageSourceCreateIncremental((__bridge CFDictionaryRef)@{(__bridge_transfer NSString *)kCGImageSourceTypeIdentifierHint : (__bridge_transfer NSString *)imageUTType});
CGFloat scale = 1;
if ([options valueForKey:SDWebImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDWebImageCoderDecodeScaleFactor] doubleValue];
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
if (scale < 1) {
scale = 1;
}
@ -288,7 +288,7 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
[self scanAndCheckFramesValidWithImageSource:_imageSource];
}
- (UIImage *)incrementalDecodedImageWithOptions:(SDWebImageCoderOptions *)options {
- (UIImage *)incrementalDecodedImageWithOptions:(SDImageCoderOptions *)options {
UIImage *image;
if (_width + _height > 0) {
@ -297,8 +297,8 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
if (partialImageRef) {
CGFloat scale = _scale;
if ([options valueForKey:SDWebImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDWebImageCoderDecodeScaleFactor] doubleValue];
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
if (scale < 1) {
scale = 1;
}
@ -316,7 +316,7 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
}
#pragma mark - SDWebImageAnimatedCoder
- (nullable instancetype)initWithAnimatedImageData:(nullable NSData *)data options:(nullable SDWebImageCoderOptions *)options {
- (nullable instancetype)initWithAnimatedImageData:(nullable NSData *)data options:(nullable SDImageCoderOptions *)options {
if (!data) {
return nil;
}
@ -333,8 +333,8 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
return nil;
}
CGFloat scale = 1;
if ([options valueForKey:SDWebImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDWebImageCoderDecodeScaleFactor] doubleValue];
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
if (scale < 1) {
scale = 1;
}

View File

@ -1,15 +0,0 @@
/*
* This file is part of the SDWebImage package.
* (c) Olivier Poitrey <rs@dailymotion.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
#import "SDWebImageCoder.h"
SDWebImageCoderOption const SDWebImageCoderDecodeFirstFrameOnly = @"decodeFirstFrameOnly";
SDWebImageCoderOption const SDWebImageCoderDecodeScaleFactor = @"decodeScaleFactor";
SDWebImageCoderOption const SDWebImageCoderEncodeFirstFrameOnly = @"encodeFirstFrameOnly";
SDWebImageCoderOption const SDWebImageCoderEncodeCompressionQuality = @"encodeCompressionQuality";

View File

@ -7,7 +7,7 @@
*/
#import <Foundation/Foundation.h>
#import "SDWebImageCoder.h"
#import "SDImageCoder.h"
/**
Global object holding the array of coders, so that we avoid passing them from object to object.
@ -24,12 +24,12 @@
Coders
------
A coder must conform to the `SDWebImageCoder` protocol or even to `SDWebImageProgressiveCoder` if it supports progressive decoding
A coder must conform to the `SDImageCoder` protocol or even to `SDProgressiveImageCoder` if it supports progressive decoding
Conformance is important because that way, they will implement `canDecodeFromData` or `canEncodeToFormat`
Those methods are called on each coder in the array (using the priority order) until one of them returns YES.
That means that coder can decode that data / encode to that format
*/
@interface SDWebImageCodersManager : NSObject<SDWebImageCoder>
@interface SDWebImageCodersManager : NSObject<SDImageCoder>
/**
Returns the global shared coders manager instance.
@ -39,20 +39,20 @@
/**
All coders in coders manager. The coders array is a priority queue, which means the later added coder will have the highest priority
*/
@property (nonatomic, copy, readwrite, nullable) NSArray<id<SDWebImageCoder>> *coders;
@property (nonatomic, copy, readwrite, nullable) NSArray<id<SDImageCoder>> *coders;
/**
Add a new coder to the end of coders array. Which has the highest priority.
@param coder coder
*/
- (void)addCoder:(nonnull id<SDWebImageCoder>)coder;
- (void)addCoder:(nonnull id<SDImageCoder>)coder;
/**
Remove a coder in the coders array.
@param coder coder
*/
- (void)removeCoder:(nonnull id<SDWebImageCoder>)coder;
- (void)removeCoder:(nonnull id<SDImageCoder>)coder;
@end

View File

@ -40,7 +40,7 @@
- (instancetype)init {
if (self = [super init]) {
// initialize with default coders
NSMutableArray<id<SDWebImageCoder>> *mutableCoders = [@[[SDWebImageImageIOCoder sharedCoder], [SDWebImageGIFCoder sharedCoder], [SDWebImageAPNGCoder sharedCoder]] mutableCopy];
NSMutableArray<id<SDImageCoder>> *mutableCoders = [@[[SDWebImageImageIOCoder sharedCoder], [SDWebImageGIFCoder sharedCoder], [SDWebImageAPNGCoder sharedCoder]] mutableCopy];
#ifdef SD_WEBP
[mutableCoders addObject:[SDWebImageWebPCoder sharedCoder]];
#endif
@ -52,12 +52,12 @@
#pragma mark - Coder IO operations
- (void)addCoder:(nonnull id<SDWebImageCoder>)coder {
if (![coder conformsToProtocol:@protocol(SDWebImageCoder)]) {
- (void)addCoder:(nonnull id<SDImageCoder>)coder {
if (![coder conformsToProtocol:@protocol(SDImageCoder)]) {
return;
}
LOCK(self.codersLock);
NSMutableArray<id<SDWebImageCoder>> *mutableCoders = [self.coders mutableCopy];
NSMutableArray<id<SDImageCoder>> *mutableCoders = [self.coders mutableCopy];
if (!mutableCoders) {
mutableCoders = [NSMutableArray array];
}
@ -66,23 +66,23 @@
UNLOCK(self.codersLock);
}
- (void)removeCoder:(nonnull id<SDWebImageCoder>)coder {
if (![coder conformsToProtocol:@protocol(SDWebImageCoder)]) {
- (void)removeCoder:(nonnull id<SDImageCoder>)coder {
if (![coder conformsToProtocol:@protocol(SDImageCoder)]) {
return;
}
LOCK(self.codersLock);
NSMutableArray<id<SDWebImageCoder>> *mutableCoders = [self.coders mutableCopy];
NSMutableArray<id<SDImageCoder>> *mutableCoders = [self.coders mutableCopy];
[mutableCoders removeObject:coder];
self.coders = [mutableCoders copy];
UNLOCK(self.codersLock);
}
#pragma mark - SDWebImageCoder
#pragma mark - SDImageCoder
- (BOOL)canDecodeFromData:(NSData *)data {
LOCK(self.codersLock);
NSArray<id<SDWebImageCoder>> *coders = self.coders;
NSArray<id<SDImageCoder>> *coders = self.coders;
UNLOCK(self.codersLock);
for (id<SDWebImageCoder> coder in coders.reverseObjectEnumerator) {
for (id<SDImageCoder> coder in coders.reverseObjectEnumerator) {
if ([coder canDecodeFromData:data]) {
return YES;
}
@ -92,9 +92,9 @@
- (BOOL)canEncodeToFormat:(SDImageFormat)format {
LOCK(self.codersLock);
NSArray<id<SDWebImageCoder>> *coders = self.coders;
NSArray<id<SDImageCoder>> *coders = self.coders;
UNLOCK(self.codersLock);
for (id<SDWebImageCoder> coder in coders.reverseObjectEnumerator) {
for (id<SDImageCoder> coder in coders.reverseObjectEnumerator) {
if ([coder canEncodeToFormat:format]) {
return YES;
}
@ -102,15 +102,15 @@
return NO;
}
- (UIImage *)decodedImageWithData:(NSData *)data options:(nullable SDWebImageCoderOptions *)options {
- (UIImage *)decodedImageWithData:(NSData *)data options:(nullable SDImageCoderOptions *)options {
if (!data) {
return nil;
}
UIImage *image;
LOCK(self.codersLock);
NSArray<id<SDWebImageCoder>> *coders = self.coders;
NSArray<id<SDImageCoder>> *coders = self.coders;
UNLOCK(self.codersLock);
for (id<SDWebImageCoder> coder in coders.reverseObjectEnumerator) {
for (id<SDImageCoder> coder in coders.reverseObjectEnumerator) {
if ([coder canDecodeFromData:data]) {
image = [coder decodedImageWithData:data options:options];
break;
@ -120,14 +120,14 @@
return image;
}
- (NSData *)encodedDataWithImage:(UIImage *)image format:(SDImageFormat)format options:(nullable SDWebImageCoderOptions *)options {
- (NSData *)encodedDataWithImage:(UIImage *)image format:(SDImageFormat)format options:(nullable SDImageCoderOptions *)options {
if (!image) {
return nil;
}
LOCK(self.codersLock);
NSArray<id<SDWebImageCoder>> *coders = self.coders;
NSArray<id<SDImageCoder>> *coders = self.coders;
UNLOCK(self.codersLock);
for (id<SDWebImageCoder> coder in coders.reverseObjectEnumerator) {
for (id<SDImageCoder> coder in coders.reverseObjectEnumerator) {
if ([coder canEncodeToFormat:format]) {
return [coder encodedDataWithImage:image format:format options:nil];
}

View File

@ -7,7 +7,7 @@
*/
#import <Foundation/Foundation.h>
#import "SDWebImageCoder.h"
#import "SDImageCoder.h"
/**
Built in coder using ImageIO that supports GIF encoding/decoding
@ -15,7 +15,7 @@
@note Use `SDWebImageGIFCoder` for fully animated GIFs. For `UIImageView`, it will produce animated `UIImage`(`NSImage` on macOS) for rendering. For `SDAnimatedImageView`, it will use `SDAnimatedImage` for rendering.
@note The recommended approach for animated GIFs is using `SDAnimatedImage` with `SDAnimatedImageView`. It's more performant than `UIImageView` for GIF displaying(especially on memory usage)
*/
@interface SDWebImageGIFCoder : NSObject <SDWebImageProgressiveCoder, SDWebImageAnimatedCoder>
@interface SDWebImageGIFCoder : NSObject <SDProgressiveImageCoder, SDAnimatedImageCoder>
@property (nonatomic, class, readonly, nonnull) SDWebImageGIFCoder *sharedCoder;

View File

@ -69,13 +69,13 @@
return ([NSData sd_imageFormatForImageData:data] == SDImageFormatGIF);
}
- (UIImage *)decodedImageWithData:(NSData *)data options:(nullable SDWebImageCoderOptions *)options {
- (UIImage *)decodedImageWithData:(NSData *)data options:(nullable SDImageCoderOptions *)options {
if (!data) {
return nil;
}
CGFloat scale = 1;
if ([options valueForKey:SDWebImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDWebImageCoderDecodeScaleFactor] doubleValue];
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
if (scale < 1) {
scale = 1;
}
@ -97,7 +97,7 @@
size_t count = CGImageSourceGetCount(source);
UIImage *animatedImage;
BOOL decodeFirstFrame = [options[SDWebImageCoderDecodeFirstFrameOnly] boolValue];
BOOL decodeFirstFrame = [options[SDImageCoderDecodeFirstFrameOnly] boolValue];
if (decodeFirstFrame || count <= 1) {
animatedImage = [[UIImage alloc] initWithData:data scale:scale];
} else {
@ -180,14 +180,14 @@
return ([NSData sd_imageFormatForImageData:data] == SDImageFormatGIF);
}
- (instancetype)initIncrementalWithOptions:(nullable SDWebImageCoderOptions *)options {
- (instancetype)initIncrementalWithOptions:(nullable SDImageCoderOptions *)options {
self = [super init];
if (self) {
CFStringRef imageUTType = [NSData sd_UTTypeFromSDImageFormat:SDImageFormatGIF];
_imageSource = CGImageSourceCreateIncremental((__bridge CFDictionaryRef)@{(__bridge_transfer NSString *)kCGImageSourceTypeIdentifierHint : (__bridge_transfer NSString *)imageUTType});
CGFloat scale = 1;
if ([options valueForKey:SDWebImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDWebImageCoderDecodeScaleFactor] doubleValue];
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
if (scale < 1) {
scale = 1;
}
@ -228,7 +228,7 @@
[self scanAndCheckFramesValidWithImageSource:_imageSource];
}
- (UIImage *)incrementalDecodedImageWithOptions:(SDWebImageCoderOptions *)options {
- (UIImage *)incrementalDecodedImageWithOptions:(SDImageCoderOptions *)options {
UIImage *image;
if (_width + _height > 0) {
@ -237,8 +237,8 @@
if (partialImageRef) {
CGFloat scale = _scale;
if ([options valueForKey:SDWebImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDWebImageCoderDecodeScaleFactor] doubleValue];
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
if (scale < 1) {
scale = 1;
}
@ -260,7 +260,7 @@
return (format == SDImageFormatGIF);
}
- (NSData *)encodedDataWithImage:(UIImage *)image format:(SDImageFormat)format options:(nullable SDWebImageCoderOptions *)options {
- (NSData *)encodedDataWithImage:(UIImage *)image format:(SDImageFormat)format options:(nullable SDImageCoderOptions *)options {
if (!image) {
return nil;
}
@ -281,12 +281,12 @@
}
NSMutableDictionary *properties = [NSMutableDictionary dictionary];
double compressionQuality = 1;
if ([options valueForKey:SDWebImageCoderEncodeCompressionQuality]) {
compressionQuality = [[options valueForKey:SDWebImageCoderEncodeCompressionQuality] doubleValue];
if ([options valueForKey:SDImageCoderEncodeCompressionQuality]) {
compressionQuality = [[options valueForKey:SDImageCoderEncodeCompressionQuality] doubleValue];
}
[properties setValue:@(compressionQuality) forKey:(__bridge_transfer NSString *)kCGImageDestinationLossyCompressionQuality];
BOOL encodeFirstFrame = [options[SDWebImageCoderEncodeFirstFrameOnly] boolValue];
BOOL encodeFirstFrame = [options[SDImageCoderEncodeFirstFrameOnly] boolValue];
if (encodeFirstFrame || frames.count == 0) {
// for static single GIF images
CGImageDestinationAddImage(imageDestination, image.CGImage, (__bridge CFDictionaryRef)properties);
@ -317,7 +317,7 @@
}
#pragma mark - SDWebImageAnimatedCoder
- (nullable instancetype)initWithAnimatedImageData:(nullable NSData *)data options:(nullable SDWebImageCoderOptions *)options {
- (nullable instancetype)initWithAnimatedImageData:(nullable NSData *)data options:(nullable SDImageCoderOptions *)options {
if (!data) {
return nil;
}
@ -334,8 +334,8 @@
return nil;
}
CGFloat scale = 1;
if ([options valueForKey:SDWebImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDWebImageCoderDecodeScaleFactor] doubleValue];
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
if (scale < 1) {
scale = 1;
}

View File

@ -7,7 +7,7 @@
*/
#import <Foundation/Foundation.h>
#import "SDWebImageCoder.h"
#import "SDImageCoder.h"
/**
Built in coder that supports PNG, JPEG, TIFF, includes support for progressive decoding.
@ -23,7 +23,7 @@
Encode(Software): macOS 10.13
Encode(Hardware): !Simulator && ((iOS 11 && A10FusionChip) || (macOS 10.13 && 6thGenerationIntelCPU))
*/
@interface SDWebImageImageIOCoder : NSObject <SDWebImageProgressiveCoder>
@interface SDWebImageImageIOCoder : NSObject <SDProgressiveImageCoder>
@property (nonatomic, class, readonly, nonnull) SDWebImageImageIOCoder *sharedCoder;

View File

@ -60,13 +60,13 @@
}
}
- (UIImage *)decodedImageWithData:(NSData *)data options:(nullable SDWebImageCoderOptions *)options {
- (UIImage *)decodedImageWithData:(NSData *)data options:(nullable SDImageCoderOptions *)options {
if (!data) {
return nil;
}
CGFloat scale = 1;
if ([options valueForKey:SDWebImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDWebImageCoderDecodeScaleFactor] doubleValue];
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
if (scale < 1) {
scale = 1;
}
@ -91,13 +91,13 @@
}
}
- (instancetype)initIncrementalWithOptions:(nullable SDWebImageCoderOptions *)options {
- (instancetype)initIncrementalWithOptions:(nullable SDImageCoderOptions *)options {
self = [super init];
if (self) {
_imageSource = CGImageSourceCreateIncremental(NULL);
CGFloat scale = 1;
if ([options valueForKey:SDWebImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDWebImageCoderDecodeScaleFactor] doubleValue];
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
if (scale < 1) {
scale = 1;
}
@ -143,7 +143,7 @@
}
}
- (UIImage *)incrementalDecodedImageWithOptions:(SDWebImageCoderOptions *)options {
- (UIImage *)incrementalDecodedImageWithOptions:(SDImageCoderOptions *)options {
UIImage *image;
if (_width + _height > 0) {
@ -152,8 +152,8 @@
if (partialImageRef) {
CGFloat scale = _scale;
if ([options valueForKey:SDWebImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDWebImageCoderDecodeScaleFactor] doubleValue];
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
if (scale < 1) {
scale = 1;
}
@ -185,7 +185,7 @@
}
}
- (NSData *)encodedDataWithImage:(UIImage *)image format:(SDImageFormat)format options:(nullable SDWebImageCoderOptions *)options {
- (NSData *)encodedDataWithImage:(UIImage *)image format:(SDImageFormat)format options:(nullable SDImageCoderOptions *)options {
if (!image) {
return nil;
}
@ -217,8 +217,8 @@
#endif
[properties setValue:@(exifOrientation) forKey:(__bridge_transfer NSString *)kCGImagePropertyOrientation];
double compressionQuality = 1;
if ([options valueForKey:SDWebImageCoderEncodeCompressionQuality]) {
compressionQuality = [[options valueForKey:SDWebImageCoderEncodeCompressionQuality] doubleValue];
if ([options valueForKey:SDImageCoderEncodeCompressionQuality]) {
compressionQuality = [[options valueForKey:SDImageCoderEncodeCompressionQuality] doubleValue];
}
[properties setValue:@(compressionQuality) forKey:(__bridge_transfer NSString *)kCGImageDestinationLossyCompressionQuality];

View File

@ -10,7 +10,7 @@
#import "SDWebImageDefine.h"
#import "SDWebImageOperation.h"
@protocol SDWebImageProgressiveCoder;
@protocol SDProgressiveImageCoder;
typedef void(^SDWebImageLoaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL);
typedef void(^SDWebImageLoaderCompletedBlock)(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished);

View File

@ -47,7 +47,7 @@ UIImage * _Nullable SDWebImageLoaderDecodeImageData(NSData * _Nonnull imageData,
}
}
if (!image) {
image = [[SDWebImageCodersManager sharedManager] decodedImageWithData:imageData options:@{SDWebImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDWebImageCoderDecodeScaleFactor : @(scale)}];
image = [[SDWebImageCodersManager sharedManager] decodedImageWithData:imageData options:@{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)}];
}
if (image) {
BOOL shouldDecode = (options & SDWebImageAvoidDecodeImage) == 0;
@ -91,13 +91,13 @@ UIImage * _Nullable SDWebImageLoaderDecodeProgressiveImageData(NSData * _Nonnull
if (scale < 1) {
scale = 1;
}
id<SDWebImageProgressiveCoder> progressiveCoder = objc_getAssociatedObject(operation, SDWebImageLoaderProgressiveCoderKey);
id<SDProgressiveImageCoder> progressiveCoder = objc_getAssociatedObject(operation, SDWebImageLoaderProgressiveCoderKey);
if (!progressiveCoder) {
// We need to create a new instance for progressive decoding to avoid conflicts
for (id<SDWebImageCoder>coder in [SDWebImageCodersManager sharedManager].coders.reverseObjectEnumerator) {
if ([coder conformsToProtocol:@protocol(SDWebImageProgressiveCoder)] &&
[((id<SDWebImageProgressiveCoder>)coder) canIncrementalDecodeFromData:imageData]) {
progressiveCoder = [[[coder class] alloc] initIncrementalWithOptions:@{SDWebImageCoderDecodeScaleFactor : @(scale)}];
for (id<SDImageCoder>coder in [SDWebImageCodersManager sharedManager].coders.reverseObjectEnumerator) {
if ([coder conformsToProtocol:@protocol(SDProgressiveImageCoder)] &&
[((id<SDProgressiveImageCoder>)coder) canIncrementalDecodeFromData:imageData]) {
progressiveCoder = [[[coder class] alloc] initIncrementalWithOptions:@{SDImageCoderDecodeScaleFactor : @(scale)}];
break;
}
}
@ -113,13 +113,13 @@ UIImage * _Nullable SDWebImageLoaderDecodeProgressiveImageData(NSData * _Nonnull
// check whether we should use `SDAnimatedImage`
if ([context valueForKey:SDWebImageContextAnimatedImageClass]) {
Class animatedImageClass = [context valueForKey:SDWebImageContextAnimatedImageClass];
if ([animatedImageClass isSubclassOfClass:[UIImage class]] && [animatedImageClass conformsToProtocol:@protocol(SDAnimatedImage)] && [progressiveCoder conformsToProtocol:@protocol(SDWebImageAnimatedCoder)]) {
image = [[animatedImageClass alloc] initWithAnimatedCoder:(id<SDWebImageAnimatedCoder>)progressiveCoder scale:scale];
if ([animatedImageClass isSubclassOfClass:[UIImage class]] && [animatedImageClass conformsToProtocol:@protocol(SDAnimatedImage)] && [progressiveCoder conformsToProtocol:@protocol(SDAnimatedImageCoder)]) {
image = [[animatedImageClass alloc] initWithAnimatedCoder:(id<SDAnimatedImageCoder>)progressiveCoder scale:scale];
}
}
}
if (!image) {
image = [progressiveCoder incrementalDecodedImageWithOptions:@{SDWebImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDWebImageCoderDecodeScaleFactor : @(scale)}];
image = [progressiveCoder incrementalDecodedImageWithOptions:@{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)}];
}
if (image) {
BOOL shouldDecode = (options & SDWebImageAvoidDecodeImage) == 0;

View File

@ -20,7 +20,7 @@
if (!data) {
return nil;
}
SDWebImageCoderOptions *options = @{SDWebImageCoderDecodeFirstFrameOnly : @(firstFrameOnly)};
SDImageCoderOptions *options = @{SDImageCoderDecodeFirstFrameOnly : @(firstFrameOnly)};
return [[SDWebImageGIFCoder sharedCoder] decodedImageWithData:data options:options];
}

View File

@ -22,7 +22,7 @@
if (scale < 1) {
scale = 1;
}
SDWebImageCoderOptions *options = @{SDWebImageCoderDecodeScaleFactor : @(scale)};
SDImageCoderOptions *options = @{SDImageCoderDecodeScaleFactor : @(scale)};
return [[SDWebImageCodersManager sharedManager] decodedImageWithData:data options:options];
}
@ -35,7 +35,7 @@
}
- (nullable NSData *)sd_imageDataAsFormat:(SDImageFormat)imageFormat compressionQuality:(double)compressionQuality {
SDWebImageCoderOptions *options = @{SDWebImageCoderEncodeCompressionQuality : @(compressionQuality)};
SDImageCoderOptions *options = @{SDImageCoderEncodeCompressionQuality : @(compressionQuality)};
return [[SDWebImageCodersManager sharedManager] encodedDataWithImage:self format:imageFormat options:options];
}

View File

@ -9,12 +9,12 @@
#ifdef SD_WEBP
#import <Foundation/Foundation.h>
#import "SDWebImageCoder.h"
#import "SDImageCoder.h"
/**
Built in coder that supports WebP and animated WebP
*/
@interface SDWebImageWebPCoder : NSObject <SDWebImageProgressiveCoder, SDWebImageAnimatedCoder>
@interface SDWebImageWebPCoder : NSObject <SDProgressiveImageCoder, SDAnimatedImageCoder>
@property (nonatomic, class, readonly, nonnull) SDWebImageWebPCoder *sharedCoder;

View File

@ -99,7 +99,7 @@ dispatch_semaphore_signal(self->_lock);
return ([NSData sd_imageFormatForImageData:data] == SDImageFormatWebP);
}
- (UIImage *)decodedImageWithData:(NSData *)data options:(nullable SDWebImageCoderOptions *)options {
- (UIImage *)decodedImageWithData:(NSData *)data options:(nullable SDImageCoderOptions *)options {
if (!data) {
return nil;
}
@ -115,10 +115,10 @@ dispatch_semaphore_signal(self->_lock);
uint32_t flags = WebPDemuxGetI(demuxer, WEBP_FF_FORMAT_FLAGS);
BOOL hasAnimation = flags & ANIMATION_FLAG;
BOOL decodeFirstFrame = [[options valueForKey:SDWebImageCoderDecodeFirstFrameOnly] boolValue];
BOOL decodeFirstFrame = [[options valueForKey:SDImageCoderDecodeFirstFrameOnly] boolValue];
CGFloat scale = 1;
if ([options valueForKey:SDWebImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDWebImageCoderDecodeScaleFactor] doubleValue];
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
if (scale < 1) {
scale = 1;
}
@ -207,14 +207,14 @@ dispatch_semaphore_signal(self->_lock);
}
#pragma mark - Progressive Decode
- (instancetype)initIncrementalWithOptions:(nullable SDWebImageCoderOptions *)options {
- (instancetype)initIncrementalWithOptions:(nullable SDImageCoderOptions *)options {
self = [super init];
if (self) {
// Progressive images need transparent, so always use premultiplied RGBA
_idec = WebPINewRGB(MODE_bgrA, NULL, 0, 0);
CGFloat scale = 1;
if ([options valueForKey:SDWebImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDWebImageCoderDecodeScaleFactor] doubleValue];
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
if (scale < 1) {
scale = 1;
}
@ -237,7 +237,7 @@ dispatch_semaphore_signal(self->_lock);
// libwebp current does not support progressive decoding for animated image, so no need to scan and update the frame information
}
- (UIImage *)incrementalDecodedImageWithOptions:(SDWebImageCoderOptions *)options {
- (UIImage *)incrementalDecodedImageWithOptions:(SDImageCoderOptions *)options {
UIImage *image;
int width = 0;
@ -285,8 +285,8 @@ dispatch_semaphore_signal(self->_lock);
return nil;
}
CGFloat scale = _scale;
if ([options valueForKey:SDWebImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDWebImageCoderDecodeScaleFactor] doubleValue];
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
if (scale < 1) {
scale = 1;
}
@ -417,7 +417,7 @@ dispatch_semaphore_signal(self->_lock);
return (format == SDImageFormatWebP);
}
- (NSData *)encodedDataWithImage:(UIImage *)image format:(SDImageFormat)format options:(nullable SDWebImageCoderOptions *)options {
- (NSData *)encodedDataWithImage:(UIImage *)image format:(SDImageFormat)format options:(nullable SDImageCoderOptions *)options {
if (!image) {
return nil;
}
@ -425,12 +425,12 @@ dispatch_semaphore_signal(self->_lock);
NSData *data;
double compressionQuality = 1;
if ([options valueForKey:SDWebImageCoderEncodeCompressionQuality]) {
compressionQuality = [[options valueForKey:SDWebImageCoderEncodeCompressionQuality] doubleValue];
if ([options valueForKey:SDImageCoderEncodeCompressionQuality]) {
compressionQuality = [[options valueForKey:SDImageCoderEncodeCompressionQuality] doubleValue];
}
NSArray<SDWebImageFrame *> *frames = [SDWebImageCoderHelper framesFromAnimatedImage:image];
BOOL encodeFirstFrame = [options[SDWebImageCoderEncodeFirstFrameOnly] boolValue];
BOOL encodeFirstFrame = [options[SDImageCoderEncodeFirstFrameOnly] boolValue];
if (encodeFirstFrame || frames.count == 0) {
// for static single webp image
data = [self sd_encodedWebpDataWithImage:image quality:compressionQuality];
@ -526,7 +526,7 @@ static void FreeImageData(void *info, const void *data, size_t size) {
}
#pragma mark - SDWebImageAnimatedCoder
- (instancetype)initWithAnimatedImageData:(NSData *)data options:(nullable SDWebImageCoderOptions *)options {
- (instancetype)initWithAnimatedImageData:(NSData *)data options:(nullable SDImageCoderOptions *)options {
if (!data) {
return nil;
}
@ -545,8 +545,8 @@ static void FreeImageData(void *info, const void *data, size_t size) {
return nil;
}
CGFloat scale = 1;
if ([options valueForKey:SDWebImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDWebImageCoderDecodeScaleFactor] doubleValue];
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
if (scale < 1) {
scale = 1;
}

View File

@ -21,7 +21,7 @@
if (!data) {
return nil;
}
SDWebImageCoderOptions *options = @{SDWebImageCoderDecodeFirstFrameOnly : @(firstFrameOnly)};
SDImageCoderOptions *options = @{SDImageCoderDecodeFirstFrameOnly : @(firstFrameOnly)};
return [[SDWebImageWebPCoder sharedCoder] decodedImageWithData:data options:options];
}

View File

@ -53,7 +53,7 @@ FOUNDATION_EXPORT const unsigned char WebImageVersionString[];
#import <SDWebImage/SDAnimatedImageView.h>
#import <SDWebImage/SDAnimatedImageView+WebCache.h>
#import <SDWebImage/SDWebImageCodersManager.h>
#import <SDWebImage/SDWebImageCoder.h>
#import <SDWebImage/SDImageCoder.h>
#import <SDWebImage/SDWebImageAPNGCoder.h>
#import <SDWebImage/SDWebImageGIFCoder.h>
#import <SDWebImage/SDWebImageImageIOCoder.h>