forked from jlamarche/Tile-Cutter
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved tile cutting into an NSOperation to leverage all computing core…
…s. Still somewhat inefficient for large images, but should be faster.
- Loading branch information
jlamarche
committed
Oct 30, 2010
1 parent
7205fa4
commit 1c5e66f
Showing
11 changed files
with
492 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// NSInvocation-MCUtilities.h | ||
// Visioneer | ||
// | ||
// Created by jeff on 7/26/10. | ||
// Copyright 2010 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
|
||
@interface NSInvocation(MCUtilities) | ||
-(void)invokeOnMainThreadWaitUntilDone:(BOOL)wait; | ||
+(NSInvocation*)invocationWithTarget:(id)target | ||
selector:(SEL)aSelector | ||
retainArguments:(BOOL)retainArguments, ...; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// NSInvocation-MCUtilities.m | ||
// Visioneer | ||
// | ||
|
||
// | ||
// Source: http://blog.jayway.com/2010/03/30/performing-any-selector-on-the-main-thread/ | ||
// | ||
#import "NSInvocation-MCUtilities.h" | ||
|
||
|
||
@implementation NSInvocation(MCUtilities) | ||
-(void)invokeOnMainThreadWaitUntilDone:(BOOL)wait | ||
{ | ||
[self performSelectorOnMainThread:@selector(invoke) | ||
withObject:nil | ||
waitUntilDone:wait]; | ||
} | ||
+(NSInvocation*)invocationWithTarget:(id)target | ||
selector:(SEL)aSelector | ||
retainArguments:(BOOL)retainArguments, ... | ||
{ | ||
va_list ap; | ||
va_start(ap, retainArguments); | ||
char* args = (char*)ap; | ||
NSMethodSignature* signature = [target methodSignatureForSelector:aSelector]; | ||
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature]; | ||
if (retainArguments) { | ||
[invocation retainArguments]; | ||
} | ||
[invocation setTarget:target]; | ||
[invocation setSelector:aSelector]; | ||
for (int index = 2; index < [signature numberOfArguments]; index++) { | ||
const char *type = [signature getArgumentTypeAtIndex:index]; | ||
NSUInteger size, align; | ||
NSGetSizeAndAlignment(type, &size, &align); | ||
NSUInteger mod = (NSUInteger)args % align; | ||
if (mod != 0) { | ||
args += (align - mod); | ||
} | ||
[invocation setArgument:args atIndex:index]; | ||
args += size; | ||
} | ||
va_end(ap); | ||
return invocation; | ||
} | ||
@end |
Oops, something went wrong.