Skip to content

Instantly share code, notes, and snippets.

@dennda
Created October 7, 2011 22:41
Show Gist options
  • Save dennda/1271506 to your computer and use it in GitHub Desktop.
Save dennda/1271506 to your computer and use it in GitHub Desktop.
- (IBAction)selectDataset:(id)sender {
NSLog(@"Presenting picker");
NSArray *files = [self presentPicker];
NSLog(@"User picked %lu files.", files.count);
self.progressBar.maxValue = files.count;
// For every .dcm file, create a thread and convert it to a PVRTC texture
dispatch_queue_t queue = dispatch_queue_create("org.denter.DICOM2PVR", NULL);
for (NSString *fn in files) {
dispatch_async(queue, ^{
// Create separate process to convert the specific file. PVRTexLib
// is not thread-safe.
NSString *executable = [[NSBundle mainBundle] pathForAuxiliaryExecutable:@"compress"];
assert(executable != nil);
NSString *dest = [NSString stringWithFormat:@"%@.pvr", fn];
NSArray *args = [NSArray arrayWithObjects:fn, dest, nil];
NSTask *task = [NSTask launchedTaskWithLaunchPath:executable arguments:args];
// [task launch];
[task waitUntilExit];
// This instead of waitUntilExit doesn't work either
// while ([task isRunning]) {
// ;
// }
// Inform main thread that we're done
dispatch_sync(dispatch_get_main_queue(), ^{
[self.progressBar incrementBy:1.];
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment