-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCMCaptureImagePopoverViewControllerOSX.m
More file actions
175 lines (148 loc) · 4.41 KB
/
CMCaptureImagePopoverViewControllerOSX.m
File metadata and controls
175 lines (148 loc) · 4.41 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#import "CMCaptureImagePopoverViewControllerOSX.h"
#import "CMCaptureImageModelCIImage.h"
#if !TARGET_OS_IPHONE
@interface CMCaptureImagePopoverViewControllerOSX ()<CMCaptureImageControllerDelegate,NSPopoverDelegate>
@property (ARC_PROP_STRONG) NSData* imageData;
@property (ARC_PROP_OUTLET) IBOutlet CMCaptureImageControllerBase* outletCaptureController;
@property (ARC_PROP_STRONG) NSPopover* popover;
@end
@implementation CMCaptureImagePopoverViewControllerOSX
ARC_SYNTHESIZEOUTLET(outletPopover);
ARC_SYNTHESIZEOUTLET(outletCaptureStillImage);
ARC_SYNTHESIZEOUTLET(outletCaptureVideoImage);
ARC_SYNTHESIZEOUTLET(outletCaptureController);
ARC_SYNTHESIZE(imageData,__imageData);
ARC_SYNTHESIZE(currentImage,__currentImage);
ARC_SYNTHESIZE(popover,__popover);
- (void) dealloc {
if (REQUIRED_DEBUG(outletCaptureController!=nil))
[outletCaptureController captureTeardown];
ARC_DEALLOC_NIL(self.imageData);
ARC_DEALLOC_NIL(self.currentImageData);
ARC_DEALLOC_NIL(self.popover);
ARC_SUPERDEALLOC(self);
}
- (BOOL) xibInternalConsistency
{
return REQUIRED_DEBUG(outletCaptureStillImage!=nil) &&
REQUIRED_DEBUG(outletCaptureVideoImage!=nil) &&
REQUIRED_DEBUG(outletCaptureController!=nil);
}
- (void)awakeFromNib
{
/* enclosing nib should set these */
/* if no popover on the outlet, allocate one */
if (outletPopover==nil)
{
NSPopover* popover = [[NSPopover alloc] init];
if (REQUIRED_DEBUG(popover!=nil))
{
popover.contentViewController=self;
popover.animates = YES;
popover.delegate = self;
self.popover = popover;
outletPopover = popover;
ARC_RELEASE(popover);
}
}
REQUIRED_DEBUG(outletPopover!=nil);
}
#pragma mark -
-(IBAction) actionPopoverDisplayWithPositioningViewSender:(NSView*)positioningView
{
if (REQUIRED_DEBUG(outletPopover!=nil) && REQUIRED_DEBUG(positioningView!=nil))
{
if ([outletPopover isShown])
[outletPopover performClose:positioningView];
else
{
if (REQUIRED_DEBUG([positioningView respondsToSelector:@selector(bounds)]))
{
outletPopover.behavior = NSPopoverBehaviorSemitransient;
outletPopover.delegate = self;
NSInteger preferredEdge = CGRectMinYEdge;
[outletPopover showRelativeToRect:positioningView.bounds
ofView:positioningView
preferredEdge:preferredEdge];
}
}
}
}
#pragma mark -
+(NSSet*) keyPathsForValuesAffectingCurrentImage
{
return [NSSet setWithObjects:@"imageData",@"currentImageData",nil];
}
+(NSSet*) keyPathsForValuesAffectingCurrentImageData
{
return [NSSet setWithObject:@"imageData"];
}
-(NSData*) currentImageData
{
return self.imageData;
}
-(void) setCurrentImageData:(NSData*)imageData
{
self.currentImage = nil;
self.imageData = imageData;
if (REQUIRED_DEBUG(self.imageData!=nil))
{
@try {
self.currentImage = [[NSImage alloc] initWithData:self.imageData];
ARC_RELEASE(self.currentImage);
}
@catch (NSException* x){
NSLOG_METHOD(x);
}
}
}
- (void)captureController:(CMCaptureImageControllerBase*)controller outputCaptureImage:(CMCaptureImageModel*)image sampleBuffer:(CMSampleBufferRef)sampleBuffer
{
NSLOG_METHOD(image);
if (![image isKindOfClass:[CMCaptureImageModelCIImage class]])
{
self.currentImageData = (NSData*)image.imageData;
}
}
- (void)captureController:(CMCaptureImageControllerBase*)controller outputCaptureImage:(CMCaptureImageModel*)image imageBuffer:(CVImageBufferRef)imageBuffer
{
NSLOG_METHOD(image);
if (REQUIRED_DEBUG(imageBuffer!=NULL))
{
self.currentImageData = [CMCaptureImageModelCIImage copyStillImageDataFromImageBuffer:imageBuffer];
}
}
#pragma mark -
- (BOOL)popoverShouldClose:(NSPopover *)popover
{
return YES;
}
- (BOOL)popoverShouldDetach:(NSPopover *)popover
{
return NO;
}
- (void)popoverDidShow:(NSNotification *)notification
{
// NSLOG_METHOD(notification);
if (REQUIRED_DEBUG(outletCaptureController!=nil))
{
if (outletCaptureController.captureSetupNeeded)
[outletCaptureController captureSetup];
outletCaptureController.delegate = self;
}
}
- (void)popoverDidClose:(NSNotification *)notification
{
NSLOG_METHOD(notification);
if (REQUIRED_DEBUG(outletCaptureController!=nil))
if (outletCaptureController.captureTeardownNeeded)
[outletCaptureController captureTeardown];
}
#pragma mark -
- (void)viewDidLoad {
NSLOG_METHOD(self);
REQUIRED_DEBUG(self.xibInternalConsistency);
REQUIRED_DEBUG(self.outletCaptureController) && REQUIRED_DEBUG(self.outletCaptureController.delegate==self);
}
@end
#endif /* TARGET_OS_IPHONE */