Update the behavior that SDAnimatedImage should pass the path and scale to coder as well
This metadata information is important for some edge cases decoding
This commit is contained in:
parent
42f35ca3f6
commit
0a0f7e10f6
|
@ -114,7 +114,19 @@ static CGFloat SDImageScaleFromPath(NSString *string) {
|
||||||
|
|
||||||
- (instancetype)initWithContentsOfFile:(NSString *)path {
|
- (instancetype)initWithContentsOfFile:(NSString *)path {
|
||||||
NSData *data = [NSData dataWithContentsOfFile:path];
|
NSData *data = [NSData dataWithContentsOfFile:path];
|
||||||
return [self initWithData:data scale:SDImageScaleFromPath(path)];
|
if (!data) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
CGFloat scale = SDImageScaleFromPath(path);
|
||||||
|
// path extension may be useful for coder like raw-image
|
||||||
|
NSString *fileExtensionHint = path.pathExtension; // without dot
|
||||||
|
if (fileExtensionHint.length == 0) {
|
||||||
|
// Ignore file extension which is empty
|
||||||
|
fileExtensionHint = nil;
|
||||||
|
}
|
||||||
|
SDImageCoderMutableOptions *mutableCoderOptions = [NSMutableDictionary dictionaryWithCapacity:1];
|
||||||
|
mutableCoderOptions[SDImageCoderDecodeFileExtensionHint] = fileExtensionHint;
|
||||||
|
return [self initWithData:data scale:scale options:[mutableCoderOptions copy]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithData:(NSData *)data {
|
- (instancetype)initWithData:(NSData *)data {
|
||||||
|
@ -130,12 +142,17 @@ static CGFloat SDImageScaleFromPath(NSString *string) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
id<SDAnimatedImageCoder> animatedCoder = nil;
|
id<SDAnimatedImageCoder> animatedCoder = nil;
|
||||||
|
SDImageCoderMutableOptions *mutableCoderOptions;
|
||||||
|
if (options != nil) {
|
||||||
|
mutableCoderOptions = [NSMutableDictionary dictionaryWithDictionary:options];
|
||||||
|
} else {
|
||||||
|
mutableCoderOptions = [NSMutableDictionary dictionaryWithCapacity:1];
|
||||||
|
}
|
||||||
|
mutableCoderOptions[SDImageCoderDecodeScaleFactor] = @(scale);
|
||||||
|
options = [mutableCoderOptions copy];
|
||||||
for (id<SDImageCoder>coder in [SDImageCodersManager sharedManager].coders.reverseObjectEnumerator) {
|
for (id<SDImageCoder>coder in [SDImageCodersManager sharedManager].coders.reverseObjectEnumerator) {
|
||||||
if ([coder conformsToProtocol:@protocol(SDAnimatedImageCoder)]) {
|
if ([coder conformsToProtocol:@protocol(SDAnimatedImageCoder)]) {
|
||||||
if ([coder canDecodeFromData:data]) {
|
if ([coder canDecodeFromData:data]) {
|
||||||
if (!options) {
|
|
||||||
options = @{SDImageCoderDecodeScaleFactor : @(scale)};
|
|
||||||
}
|
|
||||||
animatedCoder = [[[coder class] alloc] initWithAnimatedImageData:data options:options];
|
animatedCoder = [[[coder class] alloc] initWithAnimatedImageData:data options:options];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue