diff options
| author | SND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2014-03-29 20:11:02 +0000 |
|---|---|---|
| committer | SND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2014-03-29 20:11:02 +0000 |
| commit | 4f3311553ff259813ca26105f82f5b17af7db03e (patch) | |
| tree | 382673c781ee70d4bf2aaaaa7e4217142ea77fcf | |
| parent | 97bb0560b9d2e2ef44e86bde2d52cf9093b0c0da (diff) | |
| download | pcsxr-4f3311553ff259813ca26105f82f5b17af7db03e.tar.gz | |
OS X: More work on the QuickLook importer.
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@89716 e17a0e51-4ae3-4d35-97c3-1a29b211df97
| -rw-r--r-- | macosx/Pcsxr-QL/GeneratePreviewForURL.m | 88 | ||||
| -rw-r--r-- | macosx/Pcsxr-QL/GenerateThumbnailForURL.m | 62 | ||||
| -rw-r--r-- | macosx/Pcsxr-QL/nopic.h | 2 |
3 files changed, 117 insertions, 35 deletions
diff --git a/macosx/Pcsxr-QL/GeneratePreviewForURL.m b/macosx/Pcsxr-QL/GeneratePreviewForURL.m index 20cee6ba..df16a80f 100644 --- a/macosx/Pcsxr-QL/GeneratePreviewForURL.m +++ b/macosx/Pcsxr-QL/GeneratePreviewForURL.m @@ -12,45 +12,71 @@ This function's job is to create preview for designated file ----------------------------------------------------------------------------- */ +static OSStatus GeneratePreviewForFreeze(void *thisInterface, QLPreviewRequestRef preview, NSURL *url, NSDictionary *options); +static OSStatus GeneratePreviewForMemCard(void *thisInterface, QLPreviewRequestRef preview, NSURL *url, NSDictionary *options); + OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options) { + OSStatus theStatus = noErr; @autoreleasepool { - NSData *data; - NSURL *urlNS = (__bridge NSURL *)(url); - gzFile f; - const char* state_filename; - if ([urlNS respondsToSelector:@selector(fileSystemRepresentation)]) { - state_filename = [urlNS fileSystemRepresentation]; - } else { - state_filename = [[urlNS path] fileSystemRepresentation]; - } - - unsigned char *pMem = (unsigned char *) malloc(128*96*3); - if (pMem == NULL) - return mFulErr; - - f = gzopen(state_filename, "rb"); - if (f != NULL) { - gzseek(f, 32, SEEK_SET); // skip header - gzseek(f, sizeof(uint32_t), SEEK_CUR); - gzseek(f, sizeof(uint8_t), SEEK_CUR); - gzread(f, pMem, 128*96*3); - gzclose(f); - } else { - memcpy(pMem, NoPic_Image.pixel_data, 128*96*3); + NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; + NSURL *urlNS = (__bridge NSURL*)url; + NSString *uti = (__bridge NSString*)contentTypeUTI; + NSDictionary *optionsNS = (__bridge NSDictionary*)options; + if ([workspace type:uti conformsToType:@"com.codeplex.pcsxr.freeze"]) { + theStatus = GeneratePreviewForFreeze(thisInterface, preview, urlNS, optionsNS); + } else if ([workspace type:uti conformsToType:@"com.codeplex.pcsxr.memcard"]) { + theStatus = GeneratePreviewForMemCard(thisInterface, preview, urlNS, optionsNS); } - - NSBitmapImageRep *imRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&pMem pixelsWide:NoPic_Image.width pixelsHigh:NoPic_Image.height bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bitmapFormat:0 bytesPerRow:NoPic_Image.width * NoPic_Image.bytes_per_pixel bitsPerPixel:24]; - if (imRep) { - data = [imRep TIFFRepresentation]; - QLPreviewRequestSetDataRepresentation(preview, (__bridge CFDataRef)(data), kUTTypeImage, NULL); - } - free(pMem); } - return noErr; + return theStatus; } void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview) { // Implement only if supported } + +OSStatus GeneratePreviewForFreeze(void *thisInterface, QLPreviewRequestRef preview, NSURL *url, NSDictionary *options) +{ + NSData *data; + gzFile f; + const char* state_filename; + if ([url respondsToSelector:@selector(fileSystemRepresentation)]) { + state_filename = [url fileSystemRepresentation]; + } else { + state_filename = [[url path] fileSystemRepresentation]; + } + + if (!state_filename) { + return fnfErr; + } + + unsigned char *pMem = (unsigned char *) malloc(128*96*3); + if (pMem == NULL) + return mFulErr; + + f = gzopen(state_filename, "rb"); + if (f != NULL) { + gzseek(f, 32, SEEK_SET); // skip header + gzseek(f, sizeof(uint32_t), SEEK_CUR); + gzseek(f, sizeof(uint8_t), SEEK_CUR); + gzread(f, pMem, 128*96*3); + gzclose(f); + } else { + memcpy(pMem, NoPic_Image.pixel_data, 128*96*3); + } + + NSBitmapImageRep *imRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&pMem pixelsWide:NoPic_Image.width pixelsHigh:NoPic_Image.height bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bitmapFormat:0 bytesPerRow:NoPic_Image.width * NoPic_Image.bytes_per_pixel bitsPerPixel:24]; + if (imRep) { + data = [imRep TIFFRepresentation]; + QLPreviewRequestSetDataRepresentation(preview, (__bridge CFDataRef)(data), kUTTypeImage, NULL); + } + free(pMem); + return noErr; +} + +static OSStatus GeneratePreviewForMemCard(void *thisInterface, QLPreviewRequestRef preview, NSURL *url, NSDictionary *options) +{ + return unimpErr; +} diff --git a/macosx/Pcsxr-QL/GenerateThumbnailForURL.m b/macosx/Pcsxr-QL/GenerateThumbnailForURL.m index 0befeefb..30922bac 100644 --- a/macosx/Pcsxr-QL/GenerateThumbnailForURL.m +++ b/macosx/Pcsxr-QL/GenerateThumbnailForURL.m @@ -2,6 +2,9 @@ #include <CoreServices/CoreServices.h> #include <QuickLook/QuickLook.h> #include "MyQuickLook.h" +#include <zlib.h> +#import <Cocoa/Cocoa.h> +#include "nopic.h" /* ----------------------------------------------------------------------------- Generate a thumbnail for file @@ -9,18 +12,71 @@ This function's job is to create thumbnail for designated file as fast as possible ----------------------------------------------------------------------------- */ +static OSStatus GenerateThumbnailForFreeze(void *thisInterface, QLThumbnailRequestRef preview, NSURL *url, NSDictionary *options, CGSize maxSize); +static OSStatus GenerateThumbnailForMemCard(void *thisInterface, QLThumbnailRequestRef preview, NSURL *url, NSDictionary *options, CGSize maxSize); + OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize) { + OSStatus theErr = noErr; @autoreleasepool { NSURL *urlNS = (__bridge NSURL*)url; - //NSString *UTI = (__bridge NSString*)contentTypeUTI; - //NSDictionary *optionsNS = (__bridge NSDictionary*)options; + NSString *UTI = (__bridge NSString*)contentTypeUTI; + NSDictionary *optionsNS = (__bridge NSDictionary*)options; + NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; + if ([workspace type:UTI conformsToType:@"com.codeplex.pcsxr.freeze"]) { + theErr = GenerateThumbnailForFreeze(thisInterface, thumbnail, urlNS, optionsNS, maxSize); + } else if ([workspace type:UTI conformsToType:@"com.codeplex.pcsxr.memcard"]) { + theErr = GenerateThumbnailForMemCard(thisInterface, thumbnail, urlNS, optionsNS, maxSize); + } - return noErr; } + return theErr; } void CancelThumbnailGeneration(void *thisInterface, QLThumbnailRequestRef thumbnail) { // Implement only if supported } + +OSStatus GenerateThumbnailForFreeze(void *thisInterface, QLThumbnailRequestRef thumbnail, NSURL *url, NSDictionary *options, CGSize maxSize) +{ + NSData *data; + gzFile f; + const char* state_filename; + if ([url respondsToSelector:@selector(fileSystemRepresentation)]) { + state_filename = [url fileSystemRepresentation]; + } else { + state_filename = [[url path] fileSystemRepresentation]; + } + if (!state_filename) { + return fnfErr; + } + + unsigned char *pMem = (unsigned char *) malloc(128*96*3); + if (pMem == NULL) + return mFulErr; + + f = gzopen(state_filename, "rb"); + if (f != NULL) { + gzseek(f, 32, SEEK_SET); // skip header + gzseek(f, sizeof(uint32_t), SEEK_CUR); + gzseek(f, sizeof(uint8_t), SEEK_CUR); + gzread(f, pMem, 128*96*3); + gzclose(f); + } else { + memcpy(pMem, NoPic_Image.pixel_data, 128*96*3); + } + + NSBitmapImageRep *imRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&pMem pixelsWide:NoPic_Image.width pixelsHigh:NoPic_Image.height bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bitmapFormat:0 bytesPerRow:NoPic_Image.width * NoPic_Image.bytes_per_pixel bitsPerPixel:24]; + if (imRep) { + data = [imRep TIFFRepresentation]; + QLThumbnailRequestSetImageWithData(thumbnail, (__bridge CFDataRef)(data), NULL); + } + free(pMem); + return noErr; +} + +OSStatus GenerateThumbnailForMemCard(void *thisInterface, QLThumbnailRequestRef thumbnail, NSURL *url, NSDictionary *options, CGSize maxSize) +{ + return unimpErr; +} diff --git a/macosx/Pcsxr-QL/nopic.h b/macosx/Pcsxr-QL/nopic.h index c1dc1609..d7cf59ab 100644 --- a/macosx/Pcsxr-QL/nopic.h +++ b/macosx/Pcsxr-QL/nopic.h @@ -234,7 +234,7 @@ static unsigned char const cFont[10][120]= //////////////////////////////////////////////////////////////////////// -static void PaintPicDot(unsigned char * p,unsigned char c) +static inline void PaintPicDot(unsigned char * p,unsigned char c) { if(c==0) {*p++=0x00;*p++=0x00;*p=0x00;return;} // black |
