-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCMCaptureImageModel.m
More file actions
109 lines (93 loc) · 2.74 KB
/
CMCaptureImageModel.m
File metadata and controls
109 lines (93 loc) · 2.74 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
#import "CMCaptureImageModel.h"
#import "CMCaptureImageModelCIImage.h"
#import "RequiredAVFoundation.h"
@interface CMCaptureImageModel()
@end
@implementation CMCaptureImageModel
+ (id)imageMetadataFromSampleBuffer:(CMSampleBufferRef)sampleBuffer
{
NSDictionary* imageMetadata = [NSDictionary dictionary];
if (REQUIRED_DEBUG(sampleBuffer!=NULL))
{
CFDictionaryRef bufferAttachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate);
if (REQUIRED_DEBUG(bufferAttachments!=NULL))
{
REQUIRED_DEBUG(imageMetadata = [NSDictionary dictionaryWithDictionary:ARC_BRIDGE(NSDictionary*)bufferAttachments]);
CFRelease(bufferAttachments);
}
}
return imageMetadata;
}
+ (id)copyImageDataFromImageBuffer:(CVImageBufferRef)imageBuffer
{
REQUIRED_DEBUG(imageBuffer!=NULL);
return nil;
}
+ (id)copyImageDataFromSampleBuffer:(CMSampleBufferRef)sampleBuffer
{
CIImage* sampleBufferImage = nil;
if (REQUIRED_DEBUG(sampleBuffer!=NULL))
{
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
if (REQUIRED_DEBUG(imageBuffer!=NULL))
{
REQUIRED_DEBUG(sampleBufferImage = [self copyImageDataFromImageBuffer:imageBuffer]);
}
}
return sampleBufferImage;
}
#pragma mark -
ARC_SYNTHESIZE(imageData,__imageData);
ARC_SYNTHESIZE(imageMetadata,__imageMetadata);
- (instancetype)init
{
if ((self=[super init])!=nil)
{
}
return self;
}
- (void)dealloc
{
ARC_DEALLOC_NIL(self.imageData);
ARC_DEALLOC_NIL(self.imageMetadata);
ARC_SUPERDEALLOC(self);
}
#pragma mark -
-(void) setImageDataWithSampleBuffer:(CMSampleBufferRef)sampleBuffer
{
id sampleBufferImageData = nil;
if (sampleBuffer!=NULL)
sampleBufferImageData = [[self class] copyImageDataFromSampleBuffer:sampleBuffer];
[self setImageData:sampleBufferImageData];
self.imageMetadata = [[self class] imageMetadataFromSampleBuffer:sampleBuffer];
if (sampleBufferImageData!=nil)
ARC_RELEASE(sampleBufferImageData);
}
- (void)setImageDataWithCVImageBuffer:(CVImageBufferRef)imageBuffer
{
id imageBufferImageData = nil;
if (imageBuffer!=NULL)
imageBufferImageData = [[self class] copyImageDataFromImageBuffer:imageBuffer];
[self setImageData:imageBufferImageData];
self.imageMetadata = nil;
if (imageBufferImageData!=nil)
ARC_RELEASE(imageBufferImageData);
}
-(void) setImageDataWithImageData:(NSData*)imageData imageMetadata:(id)imageMetadata
{
[self setImageData:imageData];
[self setImageMetadata:imageMetadata];
}
-(NSString*) imageClassName
{
NSString* imageClassName = @"<?>";
if (self.imageData!=nil) imageClassName = NSStringFromClass([(id)self.imageData class]);
return imageClassName;
}
-(NSString*) description
{
return [NSString stringWithFormat:@"{ %@ : %@ }",
self.imageClassName,
self.imageMetadata];
}
@end