Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
Import latest changes from Fossil repository
Browse files Browse the repository at this point in the history
  • Loading branch information
dchest committed Oct 18, 2012
1 parent 5d5223e commit 87f3c28
Show file tree
Hide file tree
Showing 13 changed files with 1,402 additions and 228 deletions.
4 changes: 2 additions & 2 deletions GeneratePreviewForURL.m
Expand Up @@ -12,10 +12,10 @@

OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options)
{
CGImageRef image = GetImageForURL(url);
CGImageRef image = CreateImageForURL(url);
if (image == NULL) {
return -1;
}
}
CGFloat width = CGImageGetWidth(image);
CGFloat height = CGImageGetHeight(image);
NSDictionary *newOpt = [NSDictionary dictionaryWithObjectsAndKeys:(NSString *)[(NSDictionary *)options objectForKey:(NSString *)kQLPreviewPropertyDisplayNameKey], kQLPreviewPropertyDisplayNameKey, [NSNumber numberWithFloat:width], kQLPreviewPropertyWidthKey, [NSNumber numberWithFloat:height], kQLPreviewPropertyHeightKey, nil];
Expand Down
2 changes: 1 addition & 1 deletion GenerateThumbnailForURL.m
Expand Up @@ -15,7 +15,7 @@

OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize)
{
CGImageRef image = GetImageForURL(url);
CGImageRef image = CreateImageForURL(url);
if (image == NULL) {
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions Info.plist
Expand Up @@ -34,9 +34,9 @@
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleShortVersionString</key>
<string>1</string>
<string>2</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<string>2.1</string>
<key>CFPlugInDynamicRegisterFunction</key>
<string></string>
<key>CFPlugInDynamicRegistration</key>
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2011 Dmitry Chestnykh
Copyright (c) 2011, 2012 Dmitry Chestnykh

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 8 additions & 3 deletions WebP.xcodeproj/project.pbxproj
Expand Up @@ -216,6 +216,7 @@
2CA3261F0896AD4900168862 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "Developer ID Application: Dmitry Chestnykh";
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
Expand All @@ -229,15 +230,18 @@
"\"$(SRCROOT)/lib\"",
);
PRODUCT_NAME = WebP;
PROVISIONING_PROFILE = "";
WRAPPER_EXTENSION = qlgenerator;
};
name = Debug;
};
2CA326200896AD4900168862 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "Developer ID Application: Dmitry Chestnykh";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 3;
GCC_PRECOMPILE_PREFIX_HEADER = NO;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = /Library/QuickLook;
Expand All @@ -246,6 +250,7 @@
"\"$(SRCROOT)/lib\"",
);
PRODUCT_NAME = WebP;
PROVISIONING_PROFILE = "";
WRAPPER_EXTENSION = qlgenerator;
};
name = Release;
Expand All @@ -260,7 +265,7 @@
HEADER_SEARCH_PATHS = ./include;
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
SDKROOT = macosx10.5;
SDKROOT = macosx10.7;
};
name = Debug;
};
Expand All @@ -273,8 +278,8 @@
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = ./include;
PREBINDING = NO;
SDKROOT = macosx10.5;
VALID_ARCHS = "i386 ppc ppc7400 ppc970 x86_64";
SDKROOT = macosx10.7;
VALID_ARCHS = "i386 x86_64";
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion WebPImage.h
Expand Up @@ -8,4 +8,4 @@
#import <Foundation/Foundation.h>


CGImageRef GetImageForURL(CFURLRef url);
CGImageRef CreateImageForURL(CFURLRef url);
54 changes: 36 additions & 18 deletions WebPImage.m
Expand Up @@ -9,26 +9,44 @@
#import "WebPImage.h"
#import "webp/decode.h"

CGImageRef GetImageForURL(CFURLRef url)
CGImageRef CreateImageForURL(CFURLRef url)
{
NSData *fileData = [[NSData alloc] initWithContentsOfURL:(NSURL*)url];
int width, height;
uint8_t *buf = WebPDecodeRGBA([fileData bytes], [fileData length], &width, &height);
if (buf == NULL) {
NSLog(@"cannot get WebP image data for %@", url);
return NULL;
}
NSData *imageData = [NSData dataWithBytesNoCopy:buf length:width*height*4];
NSData *fileData = [[NSData alloc] initWithContentsOfURL:(NSURL*)url];

WebPDecoderConfig config;
if (!WebPInitDecoderConfig(&config)) {
NSLog(@"(WebPInitDecoderConfig) cannot get WebP image data for %@", url);
[fileData release];
return NULL;
}

if (WebPGetFeatures([fileData bytes], [fileData length], &config.input) != VP8_STATUS_OK) {
NSLog(@"(WebPGetFeatures) cannot get WebP image data for %@", url);
[fileData release];
return NULL;
}

config.output.colorspace = MODE_rgbA; // premultiplied alpha

if (WebPDecode([fileData bytes], [fileData length], &config) != VP8_STATUS_OK) {
NSLog(@"(WebPDecode) cannot get WebP image data for %@", url);
[fileData release];
return NULL;
}

CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
CGContextRef bitmapContext = CGBitmapContextCreate(
(void*)[imageData bytes],
width,
height,
CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
CGContextRef bitmapContext = CGBitmapContextCreate(
config.output.u.RGBA.rgba,
config.input.width,
config.input.height,
8, // bitsPerComponent
4*width, // bytesPerRow
4*config.input.width, // bytesPerRow
colorSpace,
kCGImageAlphaNoneSkipLast); //kCGImageAlphaLast is not supported
CGColorSpaceRelease(colorSpace);
return CGBitmapContextCreateImage(bitmapContext);
kCGImageAlphaPremultipliedLast);
WebPFreeDecBuffer(&config.output);
CGColorSpaceRelease(colorSpace);
[fileData release];
CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext);
CGContextRelease(bitmapContext);
return cgImage;
}

0 comments on commit 87f3c28

Please sign in to comment.