Skip to content

Commit

Permalink
changes for returning a raw image, question on returning the CGImageR…
Browse files Browse the repository at this point in the history
…ef, is this ARC code
  • Loading branch information
sdevore committed Apr 9, 2012
1 parent 4326c4c commit f51270a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion framework/Source/GPUImageStillCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

// Photography controls
- (void)capturePhotoProcessedUpToFilter:(GPUImageOutput<GPUImageInput> *)finalFilterInChain withCompletionHandler:(void (^)(UIImage *processedImage, NSError *error))block;

- (void)capturePhotoRawWithCompletionHandler:(void (^)(CGImageRef rawImageRef, NSError *error))block;
@end
41 changes: 40 additions & 1 deletion framework/Source/GPUImageStillCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ @interface GPUImageStillCamera ()

@end


@implementation GPUImageStillCamera

#pragma mark -
Expand Down Expand Up @@ -42,7 +43,7 @@ - (void)removeInputsAndOutputs;
- (void)capturePhotoProcessedUpToFilter:(GPUImageOutput<GPUImageInput> *)finalFilterInChain withCompletionHandler:(void (^)(UIImage *processedImage, NSError *error))block;
{
[photoOutput captureStillImageAsynchronouslyFromConnection:[[photoOutput connections] objectAtIndex:0] completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) {

[self captureOutput:photoOutput didOutputSampleBuffer:imageSampleBuffer fromConnection:[[photoOutput connections] objectAtIndex:0]];
// Will need an alternate pathway for the iOS 4.0 support here

Expand All @@ -53,4 +54,42 @@ - (void)capturePhotoProcessedUpToFilter:(GPUImageOutput<GPUImageInput> *)finalFi
}];
return;
}

- (void)capturePhotoRawWithCompletionHandler:(void (^)(CGImageRef rawImageRef, NSError *error))block;
{
[photoOutput captureStillImageAsynchronouslyFromConnection:[[photoOutput connections] objectAtIndex:0] completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
// todo [scd] this is the starting point
[self captureOutput:photoOutput didOutputSampleBuffer:imageSampleBuffer fromConnection:[[photoOutput connections] objectAtIndex:0]];
// Will need an alternate pathway for the iOS 4.0 support here
// crop the image around the center
// new gpuimagefilter
// pass in the texture

CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(imageSampleBuffer);
/*Lock the image buffer*/
CVPixelBufferLockBaseAddress(imageBuffer,0);
/*Get information about the image*/
uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);

/*We unlock the image buffer*/
CVPixelBufferUnlockBaseAddress(imageBuffer,0);

/*Create a CGImageRef from the CVImageBufferRef*/
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef newContext = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
CGImageRef newImage = CGBitmapContextCreateImage(newContext);

/*We release some components*/
CGContextRelease(newContext);
CGColorSpaceRelease(colorSpace);
//
block(newImage, error);

}];
return;
}

@end

0 comments on commit f51270a

Please sign in to comment.