Skip to content

Commit

Permalink
Light clean-up, and finialized bundle loader
Browse files Browse the repository at this point in the history
  • Loading branch information
emcconville committed Jul 1, 2015
1 parent 8023161 commit 4a0bb61
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions cif/cifio.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "CIColor+X11ColorName.h"
#include "CIImage+PatternName.h"

#pragma mark Convert helpers
#pragma mark - Convert helpers

NSURL * toURL(NSString * filename)
{
Expand Down Expand Up @@ -45,7 +45,7 @@
};


#pragma mark Input
#pragma mark - Input

NSMutableArray * parseArguments(const char * argv[], int argc)
{
Expand Down Expand Up @@ -290,13 +290,14 @@ CGRect readInputSize(NSString * size)
};


#pragma mark Output
#pragma mark - Output

void dumpToFile(CIImage * source, NSURL * uri)
{
NSData * blob;
NSBitmapImageRep * rep = [[NSBitmapImageRep alloc] initWithCIImage:source];
NSString * ext = [uri pathExtension];
NSString * message;
if ([ext caseInsensitiveCompare:@"PNG"] == NSOrderedSame) {
blob = [rep representationUsingType:NSPNGFileType properties:nil];
} else if ([ext caseInsensitiveCompare:@"JPG"] == NSOrderedSame
Expand All @@ -314,13 +315,13 @@ void dumpToFile(CIImage * source, NSURL * uri)
// handle anonymous formats. PNG being the correct OS default.
blob = [rep representationUsingType:NSPNGFileType properties:nil];
} else {
NSString * message = [NSString stringWithFormat:@"Don't know how to write to %@ format", [ext uppercaseString]];
message = [NSString stringWithFormat:@"Don't know how to write to %@ format", [ext uppercaseString]];
throwException(message);
}
if (blob) {
BOOL okay = [blob writeToURL:uri atomically:NO];
if (!okay) {
NSString * message = [NSString stringWithFormat:@"Unable to write to %@", uri];
message = [NSString stringWithFormat:@"Unable to write to %@", uri];
throwException(message);
}
}
Expand Down Expand Up @@ -348,6 +349,9 @@ void listFilters()
void listFilterArgumentsFor(NSString * filterName)
{
CIFilter * f = [CIFilter filterWithName:filterName];
if (f == nil) {
throwException([filterName stringByAppendingString:@": Unkown filter"]);
}
NSString * padding = [[[NSString alloc] init] stringByPaddingToLength:[filterName length] withString:@"-" startingAtIndex:0];
NSString * message = [NSString stringWithFormat:@"\n%@\n%@\n%@\n\n", filterName, padding, [CIFilter localizedDescriptionForFilterName:filterName]];
dumpToSTDOUT(message);
Expand Down Expand Up @@ -441,10 +445,9 @@ void loadCifBundles()
package = [NSBundle bundleWithPath:currentPath];
if ([package load]) {
// Initialize principal class (if given)
// This will call +initialize on main class, but not create
// run-time instance.
principalClass = [package principalClass];
if (principalClass) {
(void)[[principalClass alloc] init];
} // principalClass
} // package load
} // SomeName.bundle
} // In Filters
Expand Down

0 comments on commit 4a0bb61

Please sign in to comment.