Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions WebpQuickLook/GeneratePreviewForURL.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
// get posix path and convert it to C string then we can get data from file with simple C operation.
// Sometimes CoreFoundation is pain in the ass. I don't want to use it to get byte data

CFStringRef path = CFURLCopyPath(url);
path = CFURLCreateStringByReplacingPercentEscapes(kCFAllocatorDefault, path, CFSTR(""));
CFStringRef rawPath = CFURLCopyPath(url);
CFStringRef path = CFURLCreateStringByReplacingPercentEscapes(kCFAllocatorDefault, rawPath, CFSTR(""));
CFRelease(rawPath);
CFIndex length = CFStringGetLength(path);
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);

char* c_path = (char*)malloc(maxSize);
CFStringGetCString(path, c_path, maxSize, kCFStringEncodingUTF8);
CFRelease(path);

// let 's do the reading and decoding with libwebp

FILE *file = fopen(c_path, "r");
free(c_path);

if (file != NULL) {

Expand Down Expand Up @@ -121,11 +124,15 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,

CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, rgbData, width*height*samples, NULL);

CGImageRef image = CGImageCreate(width, height, 8, 8 * samples, width * samples, CGColorSpaceCreateDeviceRGB(), bitmapInfo, provider, NULL, false, kCGRenderingIntentDefault);

CGColorSpaceRef deviceRGBColorSpace = CGColorSpaceCreateDeviceRGB();
CGImageRef image = CGImageCreate(width, height, 8, 8 * samples, width * samples, deviceRGBColorSpace, bitmapInfo, provider, NULL, false, kCGRenderingIntentDefault);

CGContextDrawImage(ctx, CGRectMake(0, 0, width, height), image);

CGDataProviderRelease(provider);
CGColorSpaceRelease(deviceRGBColorSpace);
CGImageRelease(image);

CGContextFlush(ctx);

QLPreviewRequestFlushContext(preview, ctx);
Expand Down
15 changes: 11 additions & 4 deletions WebpQuickLook/GenerateThumbnailForURL.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
// get posix path and convert it to C string then we can get data from file with simple C operation.
// Sometimes CoreFoundation is pain in the ass. I don't want to use it to get byte data

CFStringRef path = CFURLCopyPath(url);
path = CFURLCreateStringByReplacingPercentEscapes(kCFAllocatorDefault, path, CFSTR(""));
CFStringRef rawPath = CFURLCopyPath(url);
CFStringRef path = CFURLCreateStringByReplacingPercentEscapes(kCFAllocatorDefault, rawPath, CFSTR(""));
CFRelease(rawPath);
CFIndex length = CFStringGetLength(path);
CFIndex max = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);

char* c_path = (char*)malloc(max);
CFStringGetCString(path, c_path, max, kCFStringEncodingUTF8);
CFRelease(path);

// let 's do the reading and decoding with libwebp

FILE *file = fopen(c_path, "r");
free(c_path);

if (file != NULL) {

Expand Down Expand Up @@ -128,11 +131,15 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum

CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, rgbData, width*height*4, NULL);

CGImageRef image = CGImageCreate(width, height, 8, 32, width * 4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaLast, provider, NULL, false, kCGRenderingIntentDefault);

CGColorSpaceRef deviceRGBColorSpace = CGColorSpaceCreateDeviceRGB();
CGImageRef image = CGImageCreate(width, height, 8, 32, width * 4, deviceRGBColorSpace, kCGImageAlphaLast, provider, NULL, false, kCGRenderingIntentDefault);

CGContextDrawImage(ctx, CGRectMake(0, 0, width, height), image);

CGDataProviderRelease(provider);
CGColorSpaceRelease(deviceRGBColorSpace);
CGImageRelease(image);

CGContextFlush(ctx);

QLThumbnailRequestFlushContext(thumbnail, ctx);
Expand Down