From 2863112f258b1c3618d0b454cff96d81a4dc618d Mon Sep 17 00:00:00 2001 From: "SND\\MaddTheSane_cp" Date: Wed, 6 Aug 2014 19:39:04 +0000 Subject: [PATCH] OS X: QuickLook: some minor tweaking. The generator will use the same APIs as the gif generator if there is only one image. It will still generate a PNG file. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@91192 e17a0e51-4ae3-4d35-97c3-1a29b211df97 --- macosx/Pcsxr-QL/GeneratePreviewForURL.m | 29 +++++++++++++++---------- macosx/Source/PcsxrMemoryObject.h | 4 +++- macosx/Source/PcsxrMemoryObject.m | 18 +++++++-------- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/macosx/Pcsxr-QL/GeneratePreviewForURL.m b/macosx/Pcsxr-QL/GeneratePreviewForURL.m index 164d6cfc..ae58b002 100644 --- a/macosx/Pcsxr-QL/GeneratePreviewForURL.m +++ b/macosx/Pcsxr-QL/GeneratePreviewForURL.m @@ -98,15 +98,22 @@ static OSStatus GeneratePreviewForMemCard(void *thisInterface, QLPreviewRequestR Bundle = [[NSBundle alloc] initWithURL:bundURL]; } int i = 0; - - NSDictionary *prep = @{(NSString *) kCGImagePropertyGIFDictionary: @{(NSString *) kCGImagePropertyGIFDelayTime: @0.2}}; - + + NSDictionary *gifPrep = @{(NSString *) kCGImagePropertyGIFDictionary: @{(NSString *) kCGImagePropertyGIFDelayTime: @0.30f}}; + for (PcsxrMemoryObject *obj in memCards) { - if (obj.memIconCount == -1 || obj.memIconCount == 1) { + if (obj.memImageIndex == -1 || obj.memIconCount == 1) { + NSMutableData *pngData = [NSMutableData new]; + CGImageDestinationRef dst = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)pngData, kUTTypePNG, 1, NULL); NSImage *theImage = [obj firstMemImage]; - NSData *tiffData = [theImage TIFFRepresentation]; - NSBitmapImageRep *bmImg = [NSBitmapImageRep imageRepWithData:tiffData]; - NSData *pngData = [bmImg representationUsingType:NSPNGFileType properties:nil]; + NSRect smallRect = NSMakeRect(0, 0, 16, 16); + + CGImageRef imageRef = [theImage CGImageForProposedRect:&smallRect context:nil hints:nil]; + CGImageDestinationAddImage(dst, imageRef, NULL); + + CGImageDestinationFinalize(dst); + CFRelease(dst); + NSDictionary *imgProps = @{(NSString *)kQLPreviewPropertyAttachmentDataKey: pngData, (NSString *)kQLPreviewPropertyMIMETypeKey: @"image/png"}; NSString *imgName = [[@(i++) stringValue] stringByAppendingPathExtension:@"png"]; @@ -117,11 +124,9 @@ static OSStatus GeneratePreviewForMemCard(void *thisInterface, QLPreviewRequestR 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)); + for (NSImage *theImage in obj.memoryCardImages) { + CGImageRef imageRef = [theImage CGImageForProposedRect:NULL context:nil hints:nil]; + CGImageDestinationAddImage(dst, imageRef,(__bridge CFDictionaryRef)(gifPrep)); } CGImageDestinationFinalize(dst); CFRelease(dst); diff --git a/macosx/Source/PcsxrMemoryObject.h b/macosx/Source/PcsxrMemoryObject.h index c22c6971..9ae756b2 100644 --- a/macosx/Source/PcsxrMemoryObject.h +++ b/macosx/Source/PcsxrMemoryObject.h @@ -34,13 +34,15 @@ typedef NS_ENUM(char, PCSXRMemFlags) { @property (readonly, strong) NSString *sjisName; @property (readonly, strong) NSString *memName; @property (readonly, strong) NSString *memID; +@property (readonly, strong) NSArray *memoryCardImages; +@property (readonly, nonatomic) NSInteger memImageIndex; @property (readonly) PCSXRMemFlags flagNameIndex; @property (readonly) uint8_t startingIndex; @property (readonly) uint8_t blockSize; @property (readonly, copy) NSImage *firstMemImage; @property (readonly, unsafe_unretained, nonatomic) NSImage *memImage; -@property (readonly, nonatomic) unsigned memIconCount; +@property (readonly, nonatomic) NSUInteger memIconCount; @property (readonly, unsafe_unretained, nonatomic) NSString *flagName; @property (readonly, unsafe_unretained, nonatomic) NSAttributedString *attributedFlagName; @property (readonly, nonatomic) BOOL isBiggerThanOne; diff --git a/macosx/Source/PcsxrMemoryObject.m b/macosx/Source/PcsxrMemoryObject.m index aa5f2068..53a37b36 100644 --- a/macosx/Source/PcsxrMemoryObject.m +++ b/macosx/Source/PcsxrMemoryObject.m @@ -19,8 +19,8 @@ NSString *const memoryAnimateTimerKey = @"PCSXR Memory Card Image Animate"; @property (readwrite) uint8_t startingIndex; @property (readwrite) uint8_t blockSize; -@property (nonatomic) NSInteger memImageIndex; -@property (strong) NSArray *memImages; +@property (readwrite, nonatomic) NSInteger memImageIndex; +@property (readwrite, strong) NSArray *memoryCardImages; @property (readwrite) PCSXRMemFlags flagNameIndex; @end @@ -77,7 +77,7 @@ static NSString *MemLabelEndLink; - (NSImage*)memoryImageAtIndex:(NSInteger)idx { if (memImageIndex == -1 || idx > self.memIconCount) { - return nil; + return [PcsxrMemoryObject blankImage]; } return memImages[idx]; } @@ -119,7 +119,7 @@ static NSString *MemLabelEndLink; [NSBezierPath fillRect:imageRect]; [imageBlank unlockFocus]; } - return imageBlank; + return [imageBlank copy]; } + (PCSXRMemFlags)memFlagsFromBlockFlags:(unsigned char)blockFlags @@ -151,7 +151,7 @@ static NSString *MemLabelEndLink; self.blockSize = memSize; self.flagNameIndex = [PcsxrMemoryObject memFlagsFromBlockFlags:infoBlock->Flags]; if (self.flagNameIndex == memFlagFree) { - self.memImages = @[]; + self.memoryCardImages = @[]; self.memImageIndex = -1; self.englishName = self.sjisName = @"Free block"; self.memID = self.memName = @""; @@ -167,7 +167,7 @@ static NSString *MemLabelEndLink; self.sjisName = self.englishName; } @autoreleasepool { - self.memImages = [PcsxrMemoryObject imagesFromMcd:infoBlock]; + self.memoryCardImages = [PcsxrMemoryObject imagesFromMcd:infoBlock]; } if ([memImages count] == 0) { @@ -204,15 +204,15 @@ static NSString *MemLabelEndLink; @synthesize memName; @synthesize memID; -@synthesize memImages; +@synthesize memoryCardImages = memImages; @synthesize flagNameIndex; @synthesize blockSize; @synthesize startingIndex; #pragma mark Non-synthesized Properties -- (unsigned)memIconCount +- (NSUInteger)memIconCount { - return (unsigned)[memImages count]; + return [memImages count]; } - (NSImage*)firstMemImage