Merge pull request #2602 from dreampiggy/bugfix_encoding_options

Bugfix encoding options
This commit is contained in:
DreamPiggy 2019-01-28 20:26:02 +08:00 committed by GitHub
commit b8bb954213
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 3 deletions

View File

@ -208,7 +208,8 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
BOOL encodeFirstFrame = [options[SDImageCoderEncodeFirstFrameOnly] boolValue]; BOOL encodeFirstFrame = [options[SDImageCoderEncodeFirstFrameOnly] boolValue];
if (encodeFirstFrame || frames.count == 0) { if (encodeFirstFrame || frames.count == 0) {
// for static single PNG images // for static single PNG images
CGImageDestinationAddImage(imageDestination, image.CGImage, (__bridge CFDictionaryRef)properties); CGImageRef imageRef = frames.firstObject.image.CGImage ?: image.CGImage;
CGImageDestinationAddImage(imageDestination, imageRef, (__bridge CFDictionaryRef)properties);
} else { } else {
// for animated APNG images // for animated APNG images
NSUInteger loopCount = image.sd_imageLoopCount; NSUInteger loopCount = image.sd_imageLoopCount;

View File

@ -117,7 +117,7 @@
SD_UNLOCK(self.codersLock); SD_UNLOCK(self.codersLock);
for (id<SDImageCoder> coder in coders.reverseObjectEnumerator) { for (id<SDImageCoder> coder in coders.reverseObjectEnumerator) {
if ([coder canEncodeToFormat:format]) { if ([coder canEncodeToFormat:format]) {
return [coder encodedDataWithImage:image format:format options:nil]; return [coder encodedDataWithImage:image format:format options:options];
} }
} }
return nil; return nil;

View File

@ -293,7 +293,8 @@
BOOL encodeFirstFrame = [options[SDImageCoderEncodeFirstFrameOnly] boolValue]; BOOL encodeFirstFrame = [options[SDImageCoderEncodeFirstFrameOnly] boolValue];
if (encodeFirstFrame || frames.count == 0) { if (encodeFirstFrame || frames.count == 0) {
// for static single GIF images // for static single GIF images
CGImageDestinationAddImage(imageDestination, image.CGImage, (__bridge CFDictionaryRef)properties); CGImageRef imageRef = frames.firstObject.image.CGImage ?: image.CGImage;
CGImageDestinationAddImage(imageDestination, imageRef, (__bridge CFDictionaryRef)properties);
} else { } else {
// for animated GIF images // for animated GIF images
NSUInteger loopCount = image.sd_imageLoopCount; NSUInteger loopCount = image.sd_imageLoopCount;

View File

@ -39,6 +39,12 @@
// Test image encode PNG // Test image encode PNG
data = [image sd_imageDataAsFormat:SDImageFormatPNG]; data = [image sd_imageDataAsFormat:SDImageFormatPNG];
expect(data).notTo.beNil(); expect(data).notTo.beNil();
// Test image encode JPEG with compressionQuality
NSData *jpegData1 = [image sd_imageDataAsFormat:SDImageFormatJPEG compressionQuality:1];
NSData *jpegData2 = [image sd_imageDataAsFormat:SDImageFormatJPEG compressionQuality:0.5];
expect(jpegData1).notTo.beNil();
expect(jpegData2).notTo.beNil();
expect(jpegData1.length).notTo.equal(jpegData2.length);
} }
- (void)test03UIImageGIFCategory { - (void)test03UIImageGIFCategory {
@ -49,6 +55,7 @@
NSData *data = [NSData dataWithContentsOfFile:[self testGIFPath]]; NSData *data = [NSData dataWithContentsOfFile:[self testGIFPath]];
image = [UIImage sd_imageWithGIFData:data]; image = [UIImage sd_imageWithGIFData:data];
expect(image).notTo.beNil(); expect(image).notTo.beNil();
expect(image.sd_isAnimated).beTruthy();
} }
#pragma mark - Helper #pragma mark - Helper