Fix the pixel ratio calculation for thumbnail decoding
This commit is contained in:
parent
894f061acc
commit
8a13cbb68c
|
@ -35,8 +35,8 @@
|
||||||
NSImageRep *imageRep = [self bestRepresentationForRect:imageRect context:nil hints:nil];
|
NSImageRep *imageRep = [self bestRepresentationForRect:imageRect context:nil hints:nil];
|
||||||
CGFloat width = imageRep.size.width;
|
CGFloat width = imageRep.size.width;
|
||||||
CGFloat height = imageRep.size.height;
|
CGFloat height = imageRep.size.height;
|
||||||
NSUInteger pixelWidth = imageRep.pixelsWide;
|
CGFloat pixelWidth = (CGFloat)imageRep.pixelsWide;
|
||||||
NSUInteger pixelHeight = imageRep.pixelsHigh;
|
CGFloat pixelHeight = (CGFloat)imageRep.pixelsHigh;
|
||||||
if (width > 0 && height > 0) {
|
if (width > 0 && height > 0) {
|
||||||
CGFloat widthScale = pixelWidth / width;
|
CGFloat widthScale = pixelWidth / width;
|
||||||
CGFloat heightScale = pixelHeight / height;
|
CGFloat heightScale = pixelHeight / height;
|
||||||
|
|
|
@ -191,8 +191,8 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
|
||||||
// Some options need to pass to `CGImageSourceCopyPropertiesAtIndex` before `CGImageSourceCreateImageAtIndex`, or ImageIO will ignore them because they parse once :)
|
// Some options need to pass to `CGImageSourceCopyPropertiesAtIndex` before `CGImageSourceCreateImageAtIndex`, or ImageIO will ignore them because they parse once :)
|
||||||
// Parse the image properties
|
// Parse the image properties
|
||||||
NSDictionary *properties = (__bridge_transfer NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source, index, (__bridge CFDictionaryRef)options);
|
NSDictionary *properties = (__bridge_transfer NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source, index, (__bridge CFDictionaryRef)options);
|
||||||
NSUInteger pixelWidth = [properties[(__bridge NSString *)kCGImagePropertyPixelWidth] unsignedIntegerValue];
|
CGFloat pixelWidth = [properties[(__bridge NSString *)kCGImagePropertyPixelWidth] doubleValue];
|
||||||
NSUInteger pixelHeight = [properties[(__bridge NSString *)kCGImagePropertyPixelHeight] unsignedIntegerValue];
|
CGFloat pixelHeight = [properties[(__bridge NSString *)kCGImagePropertyPixelHeight] doubleValue];
|
||||||
CGImagePropertyOrientation exifOrientation = (CGImagePropertyOrientation)[properties[(__bridge NSString *)kCGImagePropertyOrientation] unsignedIntegerValue];
|
CGImagePropertyOrientation exifOrientation = (CGImagePropertyOrientation)[properties[(__bridge NSString *)kCGImagePropertyOrientation] unsignedIntegerValue];
|
||||||
if (!exifOrientation) {
|
if (!exifOrientation) {
|
||||||
exifOrientation = kCGImagePropertyOrientationUp;
|
exifOrientation = kCGImagePropertyOrientationUp;
|
||||||
|
@ -503,8 +503,8 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
|
||||||
maxPixelSize = maxPixelSizeValue.CGSizeValue;
|
maxPixelSize = maxPixelSizeValue.CGSizeValue;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
NSUInteger pixelWidth = CGImageGetWidth(imageRef);
|
CGFloat pixelWidth = (CGFloat)CGImageGetWidth(imageRef);
|
||||||
NSUInteger pixelHeight = CGImageGetHeight(imageRef);
|
CGFloat pixelHeight = (CGFloat)CGImageGetHeight(imageRef);
|
||||||
CGFloat finalPixelSize = 0;
|
CGFloat finalPixelSize = 0;
|
||||||
if (maxPixelSize.width > 0 && maxPixelSize.height > 0 && pixelWidth > maxPixelSize.width && pixelHeight > maxPixelSize.height) {
|
if (maxPixelSize.width > 0 && maxPixelSize.height > 0 && pixelWidth > maxPixelSize.width && pixelHeight > maxPixelSize.height) {
|
||||||
CGFloat pixelRatio = pixelWidth / pixelHeight;
|
CGFloat pixelRatio = pixelWidth / pixelHeight;
|
||||||
|
|
|
@ -250,8 +250,8 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
|
||||||
maxPixelSize = maxPixelSizeValue.CGSizeValue;
|
maxPixelSize = maxPixelSizeValue.CGSizeValue;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
NSUInteger pixelWidth = CGImageGetWidth(imageRef);
|
CGFloat pixelWidth = (CGFloat)CGImageGetWidth(imageRef);
|
||||||
NSUInteger pixelHeight = CGImageGetHeight(imageRef);
|
CGFloat pixelHeight = (CGFloat)CGImageGetHeight(imageRef);
|
||||||
if (maxPixelSize.width > 0 && maxPixelSize.height > 0 && pixelWidth > maxPixelSize.width && pixelHeight > maxPixelSize.height) {
|
if (maxPixelSize.width > 0 && maxPixelSize.height > 0 && pixelWidth > maxPixelSize.width && pixelHeight > maxPixelSize.height) {
|
||||||
CGFloat pixelRatio = pixelWidth / pixelHeight;
|
CGFloat pixelRatio = pixelWidth / pixelHeight;
|
||||||
CGFloat maxPixelSizeRatio = maxPixelSize.width / maxPixelSize.height;
|
CGFloat maxPixelSizeRatio = maxPixelSize.width / maxPixelSize.height;
|
||||||
|
|
Loading…
Reference in New Issue