Commit 2f00ea56 authored by Tobias's avatar Tobias

Use screen scale as image scale for thumbnailing

preferred thumbnail size is in points @1x not in pixels
parent 7d10a819
...@@ -107,8 +107,9 @@ ...@@ -107,8 +107,9 @@
MLThumbnailerQueue *thumbnailerQueue = [MLThumbnailerQueue sharedThumbnailerQueue]; MLThumbnailerQueue *thumbnailerQueue = [MLThumbnailerQueue sharedThumbnailerQueue];
CGSize thumbSize = [UIImage preferredThumbnailSizeForDevice]; CGSize thumbSize = [UIImage preferredThumbnailSizeForDevice];
thumbnailer.thumbnailWidth = thumbSize.width; CGFloat scale = [UIScreen mainScreen].scale;
thumbnailer.thumbnailHeight = thumbSize.height; thumbnailer.thumbnailWidth = thumbSize.width*scale;
thumbnailer.thumbnailHeight = thumbSize.height*scale;
[thumbnailer fetchThumbnail]; [thumbnailer fetchThumbnail];
[thumbnailerQueue.queue setSuspended:YES]; // Balanced in -mediaThumbnailer:didFinishThumbnail [thumbnailerQueue.queue setSuspended:YES]; // Balanced in -mediaThumbnailer:didFinishThumbnail
// Balanced in -mediaThumbnailer:didFinishThumbnail: // Balanced in -mediaThumbnailer:didFinishThumbnail:
...@@ -131,7 +132,7 @@ ...@@ -131,7 +132,7 @@
MLFile *file = self.file; MLFile *file = self.file;
APLog(@"Finished thumbnail for %@", file.title); APLog(@"Finished thumbnail for %@", file.title);
if (thumbnail) { if (thumbnail) {
UIImage *thumbnailImage = [UIImage imageWithCGImage:thumbnail]; UIImage *thumbnailImage = [UIImage imageWithCGImage:thumbnail scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp];
if (thumbnailImage) { if (thumbnailImage) {
file.computedThumbnail = [UIImage imageWithCGImage:thumbnail]; file.computedThumbnail = [UIImage imageWithCGImage:thumbnail];
#if TARGET_OS_IOS #if TARGET_OS_IOS
......
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
@interface UIImage (MLKit) @interface UIImage (MLKit)
+ (CGSize)preferredThumbnailSizeForDevice; + (CGSize)preferredThumbnailSizeForDevice;
// uses current screen scale as scale
+ (UIImage *)scaleImage:(UIImage *)image toFitRect:(CGRect)rect; + (UIImage *)scaleImage:(UIImage *)image toFitRect:(CGRect)rect;
+ (UIImage *)scaleImage:(UIImage *)image toFitRect:(CGRect)rect scale:(CGFloat) scale;
@end @end
...@@ -16,36 +16,20 @@ ...@@ -16,36 +16,20 @@
CGFloat thumbnailWidth, thumbnailHeight; CGFloat thumbnailWidth, thumbnailHeight;
/* optimize thumbnails for the device */ /* optimize thumbnails for the device */
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if ([UIScreen mainScreen].scale==2.0) { thumbnailWidth = 272.;
thumbnailWidth = 540.; thumbnailHeight = 204.;
thumbnailHeight = 405.;
} else {
thumbnailWidth = 272.;
thumbnailHeight = 204.;
}
} else { } else {
if (SYSTEM_RUNS_IOS7) { thumbnailWidth = 240.;
if ([UIScreen mainScreen].scale==2.0) { thumbnailHeight = 135.;
thumbnailWidth = 480.;
thumbnailHeight = 270.;
} else {
thumbnailWidth = 720.;
thumbnailHeight = 405.;
}
} else {
if ([UIScreen mainScreen].scale==2.0) {
thumbnailWidth = 480.;
thumbnailHeight = 270.;
} else {
thumbnailWidth = 240.;
thumbnailHeight = 135.;
}
}
} }
return CGSizeMake(thumbnailWidth, thumbnailHeight); return CGSizeMake(thumbnailWidth, thumbnailHeight);
} }
+ (UIImage *)scaleImage:(UIImage *)image toFitRect:(CGRect)rect + (UIImage *)scaleImage:(UIImage *)image toFitRect:(CGRect)rect {
return [self scaleImage:image toFitRect:rect scale:[UIScreen mainScreen].scale];
}
+ (UIImage *)scaleImage:(UIImage *)image toFitRect:(CGRect)rect scale:(CGFloat)scale
{ {
CGRect destinationRect = AVMakeRectWithAspectRatioInsideRect(image.size, rect); CGRect destinationRect = AVMakeRectWithAspectRatioInsideRect(image.size, rect);
...@@ -56,8 +40,8 @@ ...@@ -56,8 +40,8 @@
CGBitmapInfo bitmapInfoRef = CGImageGetBitmapInfo(cgImage); CGBitmapInfo bitmapInfoRef = CGImageGetBitmapInfo(cgImage);
CGContextRef contextRef = CGBitmapContextCreate(NULL, CGContextRef contextRef = CGBitmapContextCreate(NULL,
destinationRect.size.width, destinationRect.size.width*scale,
destinationRect.size.height, destinationRect.size.height*scale,
bitsPerComponent, bitsPerComponent,
bytesPerRow, bytesPerRow,
colorSpaceRef, colorSpaceRef,
...@@ -67,7 +51,7 @@ ...@@ -67,7 +51,7 @@
CGContextDrawImage(contextRef, (CGRect){CGPointZero, destinationRect.size}, cgImage); CGContextDrawImage(contextRef, (CGRect){CGPointZero, destinationRect.size}, cgImage);
CGImageRef imageRef = CGBitmapContextCreateImage(contextRef); CGImageRef imageRef = CGBitmapContextCreateImage(contextRef);
UIImage *scaledImage = [UIImage imageWithCGImage:imageRef]; UIImage *scaledImage = [UIImage imageWithCGImage:imageRef scale:scale orientation:UIImageOrientationUp];
CGImageRelease(imageRef); CGImageRelease(imageRef);
CGContextRelease(contextRef); CGContextRelease(contextRef);
return scaledImage; return scaledImage;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment