Skip to content

Commit 25229bb

Browse files
committed
Support updating the overlay. It must be the same size.
1 parent 28c1802 commit 25229bb

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

videocore/api/iOS/VCSimpleSession.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,6 @@ typedef NS_ENUM(NSInteger, VCFilter) {
153153
- (void) addPixelBufferSource: (UIImage*) image
154154
withRect: (CGRect) rect;
155155

156+
- (void)updatePixelBuffer:(UIImage *)image;
157+
156158
@end

videocore/api/iOS/VCSimpleSession.mm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,30 @@ - (void) addPixelBufferSource: (UIImage*) image
899899
free(rawData);
900900

901901
}
902+
903+
- (void)updatePixelBuffer:(UIImage *)image {
904+
CGImageRef ref = [image CGImage];
905+
906+
NSUInteger width = CGImageGetWidth(ref);
907+
NSUInteger height = CGImageGetHeight(ref);
908+
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
909+
unsigned char *rawData = (unsigned char*) calloc(height * width * 4, sizeof(unsigned char));
910+
NSUInteger bytesPerPixel = 4;
911+
NSUInteger bytesPerRow = bytesPerPixel * width;
912+
NSUInteger bitsPerComponent = 8;
913+
CGContextRef context = CGBitmapContextCreate(rawData, width, height,
914+
bitsPerComponent, bytesPerRow, colorSpace,
915+
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little);
916+
CGColorSpaceRelease(colorSpace);
917+
918+
CGContextDrawImage(context, CGRectMake(0, 0, width, height), ref);
919+
CGContextRelease(context);
920+
921+
m_pixelBufferSource->pushPixelBuffer(rawData, width * height * 4);
922+
923+
free(rawData);
924+
}
925+
902926
- (NSString *) applicationDocumentsDirectory
903927
{
904928
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

0 commit comments

Comments
 (0)