-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGeneratePreviewForURL.m
More file actions
executable file
·50 lines (38 loc) · 1.71 KB
/
GeneratePreviewForURL.m
File metadata and controls
executable file
·50 lines (38 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#include <QuickLook/QuickLook.h>
#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
#include "Video.h"
/* -----------------------------------------------------------------------------
Generate a preview for file
This function's job is to create preview for designated file
-----------------------------------------------------------------------------
*/
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
CFURLRef url, CFStringRef contentTypeUTI,
CFDictionaryRef options) {
NSData *imageData = [Video dataFromVideoFile:(__bridge NSURL *)url];
NSImage *imageForSize = [[NSImage alloc] initWithData:imageData];
CGSize canvasSize =
CGSizeMake(imageForSize.size.width, imageForSize.size.height);
// Preview will be drawn in a vectorized context
CGContextRef cgContext = QLPreviewRequestCreateContext(
preview, *(CGSize *)&canvasSize, true, NULL);
if (cgContext) {
CGDataProviderRef imgDataProvider =
CGDataProviderCreateWithCFData((__bridge CFDataRef)imageData);
CGImageRef image = CGImageCreateWithJPEGDataProvider(
imgDataProvider, NULL, true, kCGRenderingIntentDefault);
CGContextDrawImage(cgContext, CGRectMake(0, 0, imageForSize.size.width,
imageForSize.size.height),
image);
QLPreviewRequestFlushContext(preview, cgContext);
CFRelease(cgContext);
CFRelease(image);
}
return noErr;
}
void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview) {
// implement only if supported
}