-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCMPBlockBuffer+Image.c
42 lines (29 loc) · 1.01 KB
/
CMPBlockBuffer+Image.c
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
#include "CMPBlockBuffer+Image.h"
CGImageRef CMPBlockBufferCopyJPEGImage(CFAllocatorRef allocator, CMBlockBufferRef blockBuffer)
{
char *buffer = NULL;
size_t size = 0;
OSStatus status = CMBlockBufferGetDataPointer(blockBuffer, 0, &size, NULL, &buffer);
if(status != noErr)
{
return NULL;
}
CGDataProviderRef source = CGDataProviderCreateWithData(NULL, buffer, size, NULL);
CGImageRef image = CGImageCreateWithJPEGDataProvider(source, NULL, false, kCGRenderingIntentDefault);
CFRelease(source);
return image;
}
CGImageRef CMPBlockBufferCopyPNGImage(CFAllocatorRef allocator, CMBlockBufferRef blockBuffer)
{
char *buffer = NULL;
size_t size = 0;
OSStatus status = CMBlockBufferGetDataPointer(blockBuffer, 0, &size, NULL, &buffer);
if(status != noErr)
{
return NULL;
}
CGDataProviderRef source = CGDataProviderCreateWithData(NULL, buffer, size, NULL);
CGImageRef image = CGImageCreateWithPNGDataProvider(source, NULL, false, kCGRenderingIntentDefault);
CFRelease(source);
return image;
}