From 5dab8f0973e7e54633c7b2f91101f7979666e8ca Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Tue, 29 Jan 2019 18:17:49 +0800 Subject: [PATCH 1/2] Fix wrong decompression scale calculation --- SDWebImage/SDWebImageImageIOCoder.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SDWebImage/SDWebImageImageIOCoder.m b/SDWebImage/SDWebImageImageIOCoder.m index 95b25b08..f1fdfd8a 100644 --- a/SDWebImage/SDWebImageImageIOCoder.m +++ b/SDWebImage/SDWebImageImageIOCoder.m @@ -267,14 +267,14 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over CGSize sourceResolution = CGSizeZero; sourceResolution.width = CGImageGetWidth(sourceImageRef); sourceResolution.height = CGImageGetHeight(sourceImageRef); - float sourceTotalPixels = sourceResolution.width * sourceResolution.height; + CGFloat sourceTotalPixels = sourceResolution.width * sourceResolution.height * image.scale * image.scale; // Determine the scale ratio to apply to the input image // that results in an output image of the defined size. // see kDestImageSizeMB, and how it relates to destTotalPixels. - float imageScale = kDestTotalPixels / sourceTotalPixels; + CGFloat imageScale = sqrt(kDestTotalPixels / sourceTotalPixels); CGSize destResolution = CGSizeZero; - destResolution.width = (int)(sourceResolution.width*imageScale); - destResolution.height = (int)(sourceResolution.height*imageScale); + destResolution.width = (int)(sourceResolution.width * imageScale); + destResolution.height = (int)(sourceResolution.height * imageScale); // device color space CGColorSpaceRef colorspaceRef = SDCGColorSpaceGetDeviceRGB(); From ed8c80551ad111d24e29409bf4192f8115d180a2 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Tue, 29 Jan 2019 19:42:09 +0800 Subject: [PATCH 2/2] Remove redundancy scale calculation --- SDWebImage/SDWebImageImageIOCoder.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDWebImage/SDWebImageImageIOCoder.m b/SDWebImage/SDWebImageImageIOCoder.m index f1fdfd8a..8f31e974 100644 --- a/SDWebImage/SDWebImageImageIOCoder.m +++ b/SDWebImage/SDWebImageImageIOCoder.m @@ -267,7 +267,7 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over CGSize sourceResolution = CGSizeZero; sourceResolution.width = CGImageGetWidth(sourceImageRef); sourceResolution.height = CGImageGetHeight(sourceImageRef); - CGFloat sourceTotalPixels = sourceResolution.width * sourceResolution.height * image.scale * image.scale; + CGFloat sourceTotalPixels = sourceResolution.width * sourceResolution.height; // Determine the scale ratio to apply to the input image // that results in an output image of the defined size. // see kDestImageSizeMB, and how it relates to destTotalPixels.