Skip to content

Commit

Permalink
Moved tile cutting into an NSOperation to leverage all computing core…
Browse files Browse the repository at this point in the history
…s. Still somewhat inefficient for large images, but should be faster.
  • Loading branch information
jlamarche committed Oct 30, 2010
1 parent 7205fa4 commit 1c5e66f
Show file tree
Hide file tree
Showing 11 changed files with 492 additions and 136 deletions.
Binary file modified .DS_Store
Binary file not shown.
17 changes: 17 additions & 0 deletions NSInvocation-MCUtilities.h
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
47 changes: 47 additions & 0 deletions NSInvocation-MCUtilities.m
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
Loading

0 comments on commit 1c5e66f

Please sign in to comment.