-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerateThumbnailForURL.m
executable file
·54 lines (41 loc) · 1.77 KB
/
GenerateThumbnailForURL.m
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
51
52
53
54
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#include <QuickLook/QuickLook.h>
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
#include "Video.h"
/* -----------------------------------------------------------------------------
Generate a thumbnail for file
This function's job is to create thumbnail for designated file as fast as
possible
-----------------------------------------------------------------------------
*/
OSStatus GenerateThumbnailForURL(void *thisInterface,
QLThumbnailRequestRef thumbnail, CFURLRef url,
CFStringRef contentTypeUTI,
CFDictionaryRef options, CGSize maxSize) {
NSData *imageData = [Video dataFromVideoFile:(__bridge NSURL *)url];
NSImage *imageThumbnail = [[NSImage alloc] initWithData:imageData];
if (QLThumbnailRequestIsCancelled(thumbnail)) {
return noErr;
}
NSSize canvasSize = imageThumbnail.size;
NSRect renderRect = NSMakeRect(0.0, 0.0, imageThumbnail.size.width,
imageThumbnail.size.height);
CGContextRef _context =
QLThumbnailRequestCreateContext(thumbnail, canvasSize, false, NULL);
if (_context) {
NSGraphicsContext *_graphicsContext =
[NSGraphicsContext graphicsContextWithGraphicsPort:(void *)_context
flipped:NO];
[NSGraphicsContext setCurrentContext:_graphicsContext];
[imageThumbnail drawInRect:renderRect];
QLThumbnailRequestFlushContext(thumbnail, _context);
CFRelease(_context);
}
return noErr;
}
void CancelThumbnailGeneration(void *thisInterface,
QLThumbnailRequestRef thumbnail) {
// implement only if supported
}