Skip to content

Commit

Permalink
Added category to NSKeyedArchiver/NSKeyedUnarchiver so that we can se…
Browse files Browse the repository at this point in the history
…nd image across the XPC connection
  • Loading branch information
peterb180369 committed Mar 23, 2012
1 parent b7f7b11 commit cf22885
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 0 deletions.
89 changes: 89 additions & 0 deletions NSKeyedArchiver+iMedia.h
@@ -0,0 +1,89 @@
/*
iMedia Browser Framework <http://karelia.com/imedia/>
Copyright (c) 2005-2012 by Karelia Software et al.
iMedia Browser is based on code originally developed by Jason Terhorst,
further developed for Sandvox by Greg Hulands, Dan Wood, and Terrence Talbot.
The new architecture for version 2.0 was developed by Peter Baumgartner.
Contributions have also been made by Matt Gough, Martin Wennerberg and others
as indicated in source files.
The iMedia Browser Framework is licensed under the following terms:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in all or substantial portions of the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following
conditions:
Redistributions of source code must retain the original terms stated here,
including this list of conditions, the disclaimer noted below, and the
following copyright notice: Copyright (c) 2005-2012 by Karelia Software et al.
Redistributions in binary form must include, in an end-user-visible manner,
e.g., About window, Acknowledgments window, or similar, either a) the original
terms stated here, including this list of conditions, the disclaimer noted
below, and the aforementioned copyright notice, or b) the aforementioned
copyright notice and a link to karelia.com/imedia.
Neither the name of Karelia Software, nor Sandvox, nor the names of
contributors to iMedia Browser may be used to endorse or promote products
derived from the Software without prior and express written permission from
Karelia Software or individual contributors, as appropriate.
Disclaimer: THE SOFTWARE IS PROVIDED BY THE COPYRIGHT OWNER AND CONTRIBUTORS
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH, THE
SOFTWARE OR THE USE OF, OR OTHER DEALINGS IN, THE SOFTWARE.
*/


//----------------------------------------------------------------------------------------------------------------------


// Author: Peter Baumgartner


//----------------------------------------------------------------------------------------------------------------------


#pragma mark HEADERS

#import <Cocoa/Cocoa.h>


//----------------------------------------------------------------------------------------------------------------------


#pragma mark

@interface NSKeyedArchiver (iMedia)

- (void) encodeCGImage:(CGImageRef)inImage forKey:(NSString*)inKey;
- (void) encodeNSImage:(NSImage*)inImage forKey:(NSString*)inKey;

@end


//----------------------------------------------------------------------------------------------------------------------


#pragma mark

@interface NSKeyedUnarchiver (iMedia)

- (CGImageRef) decodeCGImageForKey:(NSString*)inKey;
- (NSImage*) decodeNSImageForKey:(NSString*)inKey;

@end


//----------------------------------------------------------------------------------------------------------------------


146 changes: 146 additions & 0 deletions NSKeyedArchiver+iMedia.m
@@ -0,0 +1,146 @@
/*
iMedia Browser Framework <http://karelia.com/imedia/>
Copyright (c) 2005-2012 by Karelia Software et al.
iMedia Browser is based on code originally developed by Jason Terhorst,
further developed for Sandvox by Greg Hulands, Dan Wood, and Terrence Talbot.
The new architecture for version 2.0 was developed by Peter Baumgartner.
Contributions have also been made by Matt Gough, Martin Wennerberg and others
as indicated in source files.
The iMedia Browser Framework is licensed under the following terms:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in all or substantial portions of the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following
conditions:
Redistributions of source code must retain the original terms stated here,
including this list of conditions, the disclaimer noted below, and the
following copyright notice: Copyright (c) 2005-2012 by Karelia Software et al.
Redistributions in binary form must include, in an end-user-visible manner,
e.g., About window, Acknowledgments window, or similar, either a) the original
terms stated here, including this list of conditions, the disclaimer noted
below, and the aforementioned copyright notice, or b) the aforementioned
copyright notice and a link to karelia.com/imedia.
Neither the name of Karelia Software, nor Sandvox, nor the names of
contributors to iMedia Browser may be used to endorse or promote products
derived from the Software without prior and express written permission from
Karelia Software or individual contributors, as appropriate.
Disclaimer: THE SOFTWARE IS PROVIDED BY THE COPYRIGHT OWNER AND CONTRIBUTORS
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH, THE
SOFTWARE OR THE USE OF, OR OTHER DEALINGS IN, THE SOFTWARE.
*/


//----------------------------------------------------------------------------------------------------------------------


// Author: Peter Baumgartner


//----------------------------------------------------------------------------------------------------------------------


#pragma mark HEADERS

#import "NSKeyedArchiver+iMedia.h"


//----------------------------------------------------------------------------------------------------------------------


#pragma mark

@implementation NSKeyedArchiver (iMedia)


// Convert the image to NSData and encode that as an object...

- (void) encodeCGImage:(CGImageRef)inImage forKey:(NSString*)inKey
{
if (inImage != nil && inKey != nil)
{
NSMutableData* data = [NSMutableData data];
CGImageDestinationRef dest = CGImageDestinationCreateWithData((CFMutableDataRef)data,kUTTypePNG,1,NULL);

if (dest)
{
CGImageDestinationAddImage(dest,inImage,NULL);
CGImageDestinationFinalize(dest);
CFRelease(dest);
}

[self encodeObject:data forKey:inKey];
}
}


// If we do not have any representations, then add one before archiving the image...

- (void) encodeNSImage:(NSImage*)inImage forKey:(NSString*)inKey
{
if ([[inImage representations] count] == 0)
{
NSData* tiff = [inImage TIFFRepresentation];
NSBitmapImageRep* bitmap = [NSBitmapImageRep imageRepWithData:tiff];
[inImage addRepresentation:bitmap];
}

[self encodeObject:inImage forKey:inKey];
}

@end


//----------------------------------------------------------------------------------------------------------------------


#pragma mark

@implementation NSKeyedUnarchiver (iMedia)


// Decode data blob and convert it to a CGImageRef...

- (CGImageRef) decodeCGImageForKey:(NSString*)inKey
{
CGImageRef image = NULL;
CGImageSourceRef source = NULL;
NSData* data = [self decodeObjectForKey:inKey];

if (data)
{
if ((source = CGImageSourceCreateWithData((CFDataRef)data,NULL)))
{
image = CGImageSourceCreateImageAtIndex(source,0,NULL);
CFRelease(source);
}
}

return image;
}


// Decode NSImage (as generic object) and typecast it...

- (NSImage*) decodeNSImageForKey:(NSString*)inKey
{
return (NSImage*)[self decodeObjectForKey:inKey];
}

@end


//----------------------------------------------------------------------------------------------------------------------
1 change: 1 addition & 0 deletions iMedia.h
Expand Up @@ -109,6 +109,7 @@
//#import <iMedia/NSDictionary+iMedia.h>
//#import <iMedia/NSView+iMedia.h>
#import <iMedia/NSURL+iMedia.h>
#import <iMedia/NSKeyedArchiver+iMedia.h>


//----------------------------------------------------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions iMedia.xcodeproj/project.pbxproj
Expand Up @@ -290,6 +290,10 @@
D0D635EC1035B4C500FF8631 /* IMBLightroomParser.h in Headers */ = {isa = PBXBuildFile; fileRef = D0D635E81035B4C500FF8631 /* IMBLightroomParser.h */; settings = {ATTRIBUTES = (Public, ); }; };
D0D635EE1035B4C500FF8631 /* IMBApertureParser.h in Headers */ = {isa = PBXBuildFile; fileRef = D0D635EA1035B4C500FF8631 /* IMBApertureParser.h */; settings = {ATTRIBUTES = (Public, ); }; };
D0DA9AE1102EB7BD008EC9F9 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D0DA9AE0102EB7BD008EC9F9 /* Carbon.framework */; };
D0E69CD0151C5576002FE181 /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D09930FC1010FF9700C527B7 /* Quartz.framework */; };
D0E69CD2151C5581002FE181 /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D09930FC1010FF9700C527B7 /* Quartz.framework */; };
D0E69CD5151C5989002FE181 /* NSKeyedArchiver+iMedia.h in Headers */ = {isa = PBXBuildFile; fileRef = D0E69CD3151C5989002FE181 /* NSKeyedArchiver+iMedia.h */; settings = {ATTRIBUTES = (Public, ); }; };
D0E69CD6151C5989002FE181 /* NSKeyedArchiver+iMedia.m in Sources */ = {isa = PBXBuildFile; fileRef = D0E69CD4151C5989002FE181 /* NSKeyedArchiver+iMedia.m */; };
D0E96BCA151104B8004F3EE7 /* XPCKit.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = D0F207C5150A23AA007E6FA2 /* XPCKit.framework */; };
D0E96C2B15122F86004F3EE7 /* IMBAppleMediaParser.m in Sources */ = {isa = PBXBuildFile; fileRef = D0E96C2A15122F86004F3EE7 /* IMBAppleMediaParser.m */; };
D0E96C2C151243D2004F3EE7 /* IMBiPhotoParser.m in Sources */ = {isa = PBXBuildFile; fileRef = D0CB9175150F7753007716FA /* IMBiPhotoParser.m */; };
Expand Down Expand Up @@ -753,6 +757,8 @@
D0D635EA1035B4C500FF8631 /* IMBApertureParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IMBApertureParser.h; sourceTree = "<group>"; };
D0D635EB1035B4C500FF8631 /* IMBApertureParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IMBApertureParser.m; sourceTree = "<group>"; };
D0DA9AE0102EB7BD008EC9F9 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; };
D0E69CD3151C5989002FE181 /* NSKeyedArchiver+iMedia.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSKeyedArchiver+iMedia.h"; sourceTree = "<group>"; };
D0E69CD4151C5989002FE181 /* NSKeyedArchiver+iMedia.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSKeyedArchiver+iMedia.m"; sourceTree = "<group>"; };
D0E96BCB15110535004F3EE7 /* iMediaTester.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = iMediaTester.entitlements; sourceTree = "<group>"; };
D0E96C2915122F86004F3EE7 /* IMBAppleMediaParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IMBAppleMediaParser.h; sourceTree = "<group>"; };
D0E96C2A15122F86004F3EE7 /* IMBAppleMediaParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IMBAppleMediaParser.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -798,6 +804,7 @@
30FFEBEF150A08DB0009C1D0 /* Foundation.framework in Frameworks */,
D0E96C3215124CE4004F3EE7 /* AppKit.framework in Frameworks */,
30E777241511E83800413AEF /* Security.framework in Frameworks */,
D0E69CD0151C5576002FE181 /* Quartz.framework in Frameworks */,
D0F207C7150A23BA007E6FA2 /* iMedia.framework in Frameworks */,
D0F207C6150A23AA007E6FA2 /* XPCKit.framework in Frameworks */,
);
Expand Down Expand Up @@ -840,6 +847,7 @@
D0E96CF71518C9BF004F3EE7 /* Foundation.framework in Frameworks */,
D0E96CF81518C9BF004F3EE7 /* AppKit.framework in Frameworks */,
D0E96CF91518C9BF004F3EE7 /* Security.framework in Frameworks */,
D0E69CD2151C5581002FE181 /* Quartz.framework in Frameworks */,
D0E96CFA1518C9BF004F3EE7 /* iMedia.framework in Frameworks */,
D0E96CFB1518C9BF004F3EE7 /* XPCKit.framework in Frameworks */,
);
Expand Down Expand Up @@ -1361,6 +1369,8 @@
D0363E7B11D3787800E0579F /* NSView+iMedia.m */,
CE3EC9A0124AAC0700D8435B /* NSURL+iMedia.h */,
CE3EC9A1124AAC0700D8435B /* NSURL+iMedia.m */,
D0E69CD3151C5989002FE181 /* NSKeyedArchiver+iMedia.h */,
D0E69CD4151C5989002FE181 /* NSKeyedArchiver+iMedia.m */,
);
name = Categories;
sourceTree = "<group>";
Expand Down Expand Up @@ -1630,6 +1640,7 @@
D0E96CE61518A297004F3EE7 /* IMBImageFolderParserMessenger.h in Headers */,
D081099D1519AF3B00201850 /* IMBAudioFolderParserMessenger.h in Headers */,
D08109A5151A03E700201850 /* IMBMovieFolderParserMessenger.h in Headers */,
D0E69CD5151C5989002FE181 /* NSKeyedArchiver+iMedia.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1976,6 +1987,7 @@
D0E96CE71518A297004F3EE7 /* IMBImageFolderParserMessenger.m in Sources */,
D081099E1519AF3B00201850 /* IMBAudioFolderParserMessenger.m in Sources */,
D08109A4151A03E300201850 /* IMBMovieFolderParserMessenger.m in Sources */,
D0E69CD6151C5989002FE181 /* NSKeyedArchiver+iMedia.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit cf22885

Please sign in to comment.