-
Notifications
You must be signed in to change notification settings - Fork 0
/
TLImageCapturePhotoSource.m
119 lines (99 loc) · 3.38 KB
/
TLImageCapturePhotoSource.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// TLImageCapturePhotoSource.m
// Tagalog
//
// Created by Nathan Vander Wilt on 1/30/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "TLImageCapturePhotoSource.h"
#import "TLImageCaptureItem.h"
#include "TLImageCapture.h"
#import "TLPhoto.h"
#import "TLCocoaToolbag.h"
#import "TLMainThreadPerformer.h"
#import "TLLocation.h"
#import "TLTimestamp.h"
extern NSString* TLFileUniqueCachePath(void);
@interface TLImageCapturePhotoSource ()
@property (nonatomic, readonly) NSString* cacheFolder;
@property (nonatomic, assign) ICASessionID sessionID;
@end
@implementation TLImageCapturePhotoSource
@synthesize icao;
@synthesize sessionID;
@synthesize name;
@synthesize icon;
@synthesize cacheFolder;
@synthesize items = mutableItems;
#pragma mark Lifecycle
// this method must be background-thread safe
- (id)initWithICAO:(ICAObject)theICAO {
self = [super init];
if (self) {
icao = theICAO;
ICAOpenSessionPB openPB = {};
openPB.deviceObject = theICAO;
ICAError err = TLICAOpenSession(&openPB, NULL);
if (err || openPB.header.err) {
NSLog(@"Could not open session with Image Capture source. "
@"Error %i or %i from TLICAOpenSession.",
(int)err, (int)openPB.header.err);
[super dealloc];
return nil;
}
sessionID = openPB.sessionID;
CFDictionaryRef deviceProperties = NULL;
ICACopyObjectPropertyDictionaryPB copyPropertiesPB = {};
copyPropertiesPB.object = theICAO;
copyPropertiesPB.theDict = &deviceProperties;
err = TLICACopyObjectPropertyDictionary(©PropertiesPB, NULL);
if (err || copyPropertiesPB.header.err) {
NSLog(@"Could not get Image Capture source information. "
@"Error %i or %i from TLICACopyObjectPropertyDictionary.",
(int)err, (int)copyPropertiesPB.header.err);
[super dealloc];
return nil;
}
TLCFAutorelease(deviceProperties);
//NSLog(@"%@", (id)deviceProperties);
name = [(id)CFDictionaryGetValue(deviceProperties, kTLICAObjectNameKey) copy];
CFDataRef thumbnailData = NULL;
ICACopyObjectThumbnailPB copyThumbnailPB = {};
copyThumbnailPB.object = theICAO;
/* NOTE: using TIFF is important, as PNG (and obviously not JPEG) does not contain
alpha channel. Discovered via http://developer.apple.com/samplecode/MyPhoto/listing11.html */
copyThumbnailPB.thumbnailFormat = kICAThumbnailFormatTIFF; //kICAThumbnailFormatPNG;
copyThumbnailPB.thumbnailData = &thumbnailData;
err = TLICACopyObjectThumbnail(©ThumbnailPB, NULL);
if (err || copyThumbnailPB.header.err) {
/* NOTE: will return paramErr if no thumbnail is available
See http://openradar.appspot.com/6399474 for a filed bug. */
if (err != paramErr) {
NSLog(@"Could not get Image Capture source thumbnail icon. "
@"Error %i or %i from TLICACopyObjectThumbnail.",
(int)err, (int)copyThumbnailPB.header.err);
}
}
else {
icon = [[NSImage alloc] initWithData:(NSData*)thumbnailData];
CFRelease(thumbnailData);
}
mutableItems = [NSMutableSet new];
NSArray* mediaFiles = (id)CFDictionaryGetValue(deviceProperties, kTLICAMediaFilesKey);
for (NSDictionary* fileInfo in mediaFiles) {
TLImageCaptureItem* item = [[TLImageCaptureItem alloc]
initWithSource:self info:fileInfo];
[mutableItems addObject:item];
[item release];
}
}
return self;
}
- (void)dealloc {
[name release];
[icon release];
[cacheFolder release];
[mutableItems release];
[super dealloc];
}
@end