implement save request on OSX, add Quick Look extentions

This commit is contained in:
2018-07-31 00:38:10 +02:00
parent 87fcea61b8
commit 5a37f578cb
18 changed files with 814 additions and 20 deletions

38
PanoThumb/Info.plist Normal file
View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>PanoThumb</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>QLSupportedContentTypes</key>
<array>
<string>com.panopainter.image</string>
</array>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.quicklook.thumbnail</string>
<key>NSExtensionPrincipalClass</key>
<string>ThumbnailProvider</string>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,13 @@
//
// ThumbnailProvider.h
// PanoThumb
//
// Created by Omar Mohamed Ali Mudhir on 15/06/18.
// Copyright © 2018 OmixLab ltd. All rights reserved.
//
#import <QuickLook/QuickLook.h>
@interface ThumbnailProvider : QLThumbnailProvider
@end

View File

@@ -0,0 +1,63 @@
//
// ThumbnailProvider.m
// PanoThumb
//
// Created by Omar Mohamed Ali Mudhir on 15/06/18.
// Copyright © 2018 OmixLab ltd. All rights reserved.
//
#import "ThumbnailProvider.h"
@implementation ThumbnailProvider
- (void)provideThumbnailForFileRequest:(QLFileThumbnailRequest *)request completionHandler:(void (^)(QLThumbnailReply * _Nullable, NSError * _Nullable))handler {
// There are three ways to provide a thumbnail through a QLThumbnailReply. Only one of them should be used.
/*
// First way: Draw the thumbnail into the current context, set up with UIKit's coordinate system.
handler([QLThumbnailReply replyWithContextSize:request.maximumSize currentContextDrawingBlock:^BOOL {
// Draw the thumbnail here.
// Return YES if the thumbnail was successfully drawn inside this block.
return YES;
}], nil);
*/
// Second way: Draw the thumbnail into a context passed to your block, set up with Core Graphics' coordinate system.
CGRect r = CGRectMake(0, 0, 128, 128);
handler([QLThumbnailReply replyWithContextSize:r.size drawingBlock:^BOOL(CGContextRef _Nonnull context) {
// Draw the thumbnail here.
NSLog(@"thumbnail generated");
NSURL* u = [request fileURL];
FILE* fp = fopen([u fileSystemRepresentation], "rb");
if (fp)
{
int h[3];
fread(h, sizeof(int), 3, fp);
//uint8_t* data = (uint8_t*)malloc(h[0]*h[1]*h[2]);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef bmp = CGBitmapContextCreate(NULL, h[0], h[1], 8, h[0]*h[2], colorSpace, kCGImageAlphaPremultipliedLast);
uint8_t* data = CGBitmapContextGetData(bmp);
fread(data, h[0]*h[1]*h[2], 1, fp);
fclose(fp);
CGImageRef img = CGBitmapContextCreateImage(bmp);
CGRect r2 = CGRectMake(0, 0, 128*request.scale, 128*request.scale);
CGContextDrawImage(context, r2, img);
}
// Return YES if the thumbnail was successfully drawn inside this block.
return YES;
}], nil);
/*
// Third way: Set an image file URL.
handler([QLThumbnailReply replyWithImageFileURL:[NSBundle.mainBundle URLForResource:@"fileThumbnail" withExtension:@"jpg"]], nil);
*/
}
@end