From f629ca7098a057086b1a15df93f3fc58b058c4b8 Mon Sep 17 00:00:00 2001 From: "SND\\MaddTheSane_cp" Date: Wed, 6 Aug 2014 19:02:00 +0000 Subject: [PATCH] OS X: QuickLook: use animated gifs to show the memory card image. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@91191 e17a0e51-4ae3-4d35-97c3-1a29b211df97 --- macosx/Pcsxr-QL/GeneratePreviewForURL.m | 37 ++++++++++++++++++++----- macosx/Source/PcsxrMemoryObject.h | 2 ++ macosx/Source/PcsxrMemoryObject.m | 8 ++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/macosx/Pcsxr-QL/GeneratePreviewForURL.m b/macosx/Pcsxr-QL/GeneratePreviewForURL.m index c13a3e04..164d6cfc 100644 --- a/macosx/Pcsxr-QL/GeneratePreviewForURL.m +++ b/macosx/Pcsxr-QL/GeneratePreviewForURL.m @@ -98,14 +98,37 @@ static OSStatus GeneratePreviewForMemCard(void *thisInterface, QLPreviewRequestR Bundle = [[NSBundle alloc] initWithURL:bundURL]; } int i = 0; + + NSDictionary *prep = @{(NSString *) kCGImagePropertyGIFDictionary: @{(NSString *) kCGImagePropertyGIFDelayTime: @0.2}}; + for (PcsxrMemoryObject *obj in memCards) { - NSImage *theImage = [obj firstMemImage]; - NSData *tiffData = [theImage TIFFRepresentation]; - NSBitmapImageRep *bmImg = [NSBitmapImageRep imageRepWithData:tiffData]; - NSData *pngData = [bmImg representationUsingType:NSPNGFileType properties:nil]; - NSDictionary *imgProps = @{(NSString *)kQLPreviewPropertyAttachmentDataKey: pngData, - (NSString *)kQLPreviewPropertyMIMETypeKey: @"image/png"}; - NSString *imgName = [[@(i++) stringValue] stringByAppendingPathExtension:@"png"]; + if (obj.memIconCount == -1 || obj.memIconCount == 1) { + NSImage *theImage = [obj firstMemImage]; + NSData *tiffData = [theImage TIFFRepresentation]; + NSBitmapImageRep *bmImg = [NSBitmapImageRep imageRepWithData:tiffData]; + NSData *pngData = [bmImg representationUsingType:NSPNGFileType properties:nil]; + NSDictionary *imgProps = @{(NSString *)kQLPreviewPropertyAttachmentDataKey: pngData, + (NSString *)kQLPreviewPropertyMIMETypeKey: @"image/png"}; + NSString *imgName = [[@(i++) stringValue] stringByAppendingPathExtension:@"png"]; + [htmlStr appendFormat:@"\t\t\t %@ %i\n", imgName, obj.sjisName, obj.blockSize]; + htmlDict[imgName] = imgProps; + continue; + } + NSMutableData *gifData = [NSMutableData new]; + + CGImageDestinationRef dst = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)gifData, kUTTypeGIF, obj.memIconCount, NULL); + for (NSInteger j = 0; j < obj.memIconCount; j++) { + NSImage *theImage = [obj memoryImageAtIndex:j]; + + CGImageRef imageRef=[theImage CGImageForProposedRect:nil context:nil hints:nil]; + CGImageDestinationAddImage(dst, imageRef,(__bridge CFDictionaryRef)(prep)); + } + CGImageDestinationFinalize(dst); + CFRelease(dst); + + NSDictionary *imgProps = @{(NSString *)kQLPreviewPropertyAttachmentDataKey: gifData, + (NSString *)kQLPreviewPropertyMIMETypeKey: @"image/gif"}; + NSString *imgName = [[@(i++) stringValue] stringByAppendingPathExtension:@"gif"]; [htmlStr appendFormat:@"\t\t\t %@ %i\n", imgName, obj.sjisName, obj.blockSize]; htmlDict[imgName] = imgProps; } diff --git a/macosx/Source/PcsxrMemoryObject.h b/macosx/Source/PcsxrMemoryObject.h index 215b948b..c22c6971 100644 --- a/macosx/Source/PcsxrMemoryObject.h +++ b/macosx/Source/PcsxrMemoryObject.h @@ -28,6 +28,8 @@ typedef NS_ENUM(char, PCSXRMemFlags) { - (instancetype)initWithMcdBlock:(McdBlock *)infoBlockc startingIndex:(uint8_t)startIdx size:(uint8_t)memSize NS_DESIGNATED_INITIALIZER; +- (NSImage*)memoryImageAtIndex:(NSInteger)idx; + @property (readonly, strong) NSString *englishName; @property (readonly, strong) NSString *sjisName; @property (readonly, strong) NSString *memName; diff --git a/macosx/Source/PcsxrMemoryObject.m b/macosx/Source/PcsxrMemoryObject.m index db5dac65..aa5f2068 100644 --- a/macosx/Source/PcsxrMemoryObject.m +++ b/macosx/Source/PcsxrMemoryObject.m @@ -74,6 +74,14 @@ static NSString *MemLabelEndLink; }); } +- (NSImage*)memoryImageAtIndex:(NSInteger)idx +{ + if (memImageIndex == -1 || idx > self.memIconCount) { + return nil; + } + return memImages[idx]; +} + + (NSString*)memoryLabelFromFlag:(PCSXRMemFlags)flagNameIndex { switch (flagNameIndex) {