-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCMCaptureImageModelCIImage.m
More file actions
81 lines (72 loc) · 2.16 KB
/
CMCaptureImageModelCIImage.m
File metadata and controls
81 lines (72 loc) · 2.16 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
#import "CMCaptureImageModelCIImage.h"
@interface CMCaptureImageModelCIImage()
@end
@implementation CMCaptureImageModelCIImage
@dynamic imageData;
#if TARGET_OS_IPHONE
+ (UIImage*)imageWithCIImage:(CIImage*)image
{
UIImage* imageResult = nil;
CIContext* context = [CIContext contextWithOptions:nil];
if (REQUIRED_DEBUG(context!=nil))
{
CGImageRef rasterizedImage = [context createCGImage:image fromRect:image.extent];
if (REQUIRED_DEBUG(rasterizedImage!=NULL))
{
imageResult = [UIImage imageWithCGImage:rasterizedImage];
CGImageRelease(rasterizedImage);
}
}
return imageResult;
}
#endif /* TARGET_OS_IPHONE */
+ (id)copyStillImageDataFromImageBuffer:(CVImageBufferRef)imageBuffer
{ NSLOG_METHOD(imageBuffer);
NSData* imageData = nil;
if (REQUIRED_DEBUGGER(imageBuffer!=NULL))
{
CIImage* image = [self copyImageDataFromImageBuffer:imageBuffer];
if (REQUIRED_DEBUGGER(image!=nil))
{
#if TARGET_OS_IPHONE
UIImage* platformImage = [self imageWithCIImage:image];
if (REQUIRED_DEBUG(platformImage!=nil))
{
imageData = [[NSData alloc] initWithData:UIImageJPEGRepresentation(platformImage, 0.9f)];
}
#else
NSBitmapImageRep* bitmapImageRep = [[NSBitmapImageRep alloc] initWithCIImage:image];
if (REQUIRED_DEBUG(bitmapImageRep!=NULL))
{
NSData* jpegData = [bitmapImageRep representationUsingType:NSJPEGFileType properties: nil];
if (REQUIRED_DEBUG(jpegData!=nil))
{
imageData = [[NSData alloc] initWithData:jpegData];
REQUIRED_DEBUG(imageData!=nil);
}
ARC_RELEASE(bitmapImageRep);
}
#endif
ARC_RELEASE(image);
}
}
REQUIRED_DEBUG(imageData!=nil);
return imageData;
}
+ (id)copyImageDataFromImageBuffer:(CVImageBufferRef)imageBuffer
{
CIImage* bufferImage = nil;
if (REQUIRED_DEBUG(imageBuffer!=NULL))
{
#if TARGET_OS_IPHONE
// NSDictionary* attachments = [self imageMetadataFromSampleBuffer:sampleBuffer];
NSDictionary* attachments = [NSDictionary dictionary];
bufferImage = [[CIImage alloc] initWithCVPixelBuffer:imageBuffer options:attachments];
#else /* MAC */
bufferImage = [[CIImage alloc] initWithCVImageBuffer:imageBuffer];
#endif
REQUIRED_DEBUGGER(bufferImage!=nil);
}
return bufferImage;
}
@end