Skip to content
This repository has been archived by the owner on Apr 18, 2020. It is now read-only.

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jgh- committed Feb 25, 2011
0 parents commit a87b538
Show file tree
Hide file tree
Showing 69 changed files with 56,189 additions and 0 deletions.
19 changes: 19 additions & 0 deletions CGImageWrapper.h
@@ -0,0 +1,19 @@
/*
* Webcam/FaceTracking/Custom Views example project - jamesghurley<at>gmail.com
* This project emulates 1-on-1 video conferencing using modern Cocoa frameworks and techniques.
*
* CGImageWrapper.h/.m - Used to pass a CGImageRef to the main thread.
*/

#import <Cocoa/Cocoa.h>


@interface CGImageWrapper : NSObject {
@public
CGImageRef image;
}
@property CGImageRef image;

-(id) initWithCGImage: (CGImageRef) _image;
-(id) initWithCVImageBufferRef: (CVImageBufferRef) _imageBuffer;
@end
46 changes: 46 additions & 0 deletions CGImageWrapper.m
@@ -0,0 +1,46 @@
/*
* Webcam/FaceTracking/Custom Views example project - jamesghurley<at>gmail.com
* This project emulates 1-on-1 video conferencing using modern Cocoa frameworks and techniques.
*
* CGImageWrapper.h/.m - Used to pass a CGImageRef to the main thread.
*/
#import "CGImageWrapper.h"
#import <CoreVideo/CoreVideo.h>


@implementation CGImageWrapper
@synthesize image;
// -----------------------------------------------------------------------------
- (id) initWithCGImage:(CGImageRef)_image{
if((self = [super init])){
image = _image;
}
return self;
}
// -----------------------------------------------------------------------------
-(id) initWithCVImageBufferRef: (CVImageBufferRef) _imageBuffer{

if((self = [super init])){

CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
void *baseAddr = CVPixelBufferGetBaseAddress(_imageBuffer);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(_imageBuffer);
size_t width = CVPixelBufferGetWidth(_imageBuffer);
size_t height = CVPixelBufferGetHeight(_imageBuffer);

CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, baseAddr, bytesPerRow*height, NULL);

image = CGImageCreate(width, height, 8, 24, bytesPerRow, colorSpace, kCGImageAlphaNone, provider, NULL, false, kCGRenderingIntentDefault);

CGColorSpaceRelease(colorSpace);
CGDataProviderRelease(provider);
}

return self;
}
// -----------------------------------------------------------------------------
- (void) dealloc{
CGImageRelease(image);
[super dealloc];
}
@end

0 comments on commit a87b538

Please sign in to comment.