Merge pull request #2989 from dreampiggy/bugfix_encoding_options_imageio
Fix the encoding options which does not passthrough the correct value to ImageIO
This commit is contained in:
commit
8d1d0b0802
|
@ -476,6 +476,7 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
|
||||||
} else {
|
} else {
|
||||||
finalPixelSize = maxPixelSize.height;
|
finalPixelSize = maxPixelSize.height;
|
||||||
}
|
}
|
||||||
|
properties[(__bridge NSString *)kCGImageDestinationImageMaxPixelSize] = @(finalPixelSize);
|
||||||
}
|
}
|
||||||
NSUInteger maxFileSize = [options[SDImageCoderEncodeMaxFileSize] unsignedIntegerValue];
|
NSUInteger maxFileSize = [options[SDImageCoderEncodeMaxFileSize] unsignedIntegerValue];
|
||||||
if (maxFileSize > 0) {
|
if (maxFileSize > 0) {
|
||||||
|
@ -487,27 +488,22 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
|
||||||
BOOL encodeFirstFrame = [options[SDImageCoderEncodeFirstFrameOnly] boolValue];
|
BOOL encodeFirstFrame = [options[SDImageCoderEncodeFirstFrameOnly] boolValue];
|
||||||
if (encodeFirstFrame || frames.count == 0) {
|
if (encodeFirstFrame || frames.count == 0) {
|
||||||
// for static single images
|
// for static single images
|
||||||
if (finalPixelSize > 0) {
|
|
||||||
properties[(__bridge NSString *)kCGImageDestinationImageMaxPixelSize] = @(finalPixelSize);
|
|
||||||
}
|
|
||||||
CGImageDestinationAddImage(imageDestination, imageRef, (__bridge CFDictionaryRef)properties);
|
CGImageDestinationAddImage(imageDestination, imageRef, (__bridge CFDictionaryRef)properties);
|
||||||
} else {
|
} else {
|
||||||
// for animated images
|
// for animated images
|
||||||
NSUInteger loopCount = image.sd_imageLoopCount;
|
NSUInteger loopCount = image.sd_imageLoopCount;
|
||||||
NSDictionary *containerProperties = @{self.class.loopCountProperty : @(loopCount)};
|
NSDictionary *containerProperties = @{
|
||||||
properties[self.class.dictionaryProperty] = containerProperties;
|
self.class.dictionaryProperty: @{self.class.loopCountProperty : @(loopCount)}
|
||||||
CGImageDestinationSetProperties(imageDestination, (__bridge CFDictionaryRef)properties);
|
};
|
||||||
|
// container level properties (applies for `CGImageDestinationSetProperties`, not individual frames)
|
||||||
|
CGImageDestinationSetProperties(imageDestination, (__bridge CFDictionaryRef)containerProperties);
|
||||||
|
|
||||||
for (size_t i = 0; i < frames.count; i++) {
|
for (size_t i = 0; i < frames.count; i++) {
|
||||||
SDImageFrame *frame = frames[i];
|
SDImageFrame *frame = frames[i];
|
||||||
NSTimeInterval frameDuration = frame.duration;
|
NSTimeInterval frameDuration = frame.duration;
|
||||||
CGImageRef frameImageRef = frame.image.CGImage;
|
CGImageRef frameImageRef = frame.image.CGImage;
|
||||||
NSMutableDictionary *frameProperties = [NSMutableDictionary dictionary];
|
properties[self.class.dictionaryProperty] = @{self.class.delayTimeProperty : @(frameDuration)};
|
||||||
frameProperties[self.class.dictionaryProperty] = @{self.class.delayTimeProperty : @(frameDuration)};
|
CGImageDestinationAddImage(imageDestination, frameImageRef, (__bridge CFDictionaryRef)properties);
|
||||||
if (finalPixelSize > 0) {
|
|
||||||
frameProperties[(__bridge NSString *)kCGImageDestinationImageMaxPixelSize] = @(finalPixelSize);
|
|
||||||
}
|
|
||||||
CGImageDestinationAddImage(imageDestination, frameImageRef, (__bridge CFDictionaryRef)frameProperties);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Finalize the destination.
|
// Finalize the destination.
|
||||||
|
|
Loading…
Reference in New Issue