Skip to content

Instantly share code, notes, and snippets.

@jamespenguin
Created February 26, 2012 05:29
Show Gist options
  • Save jamespenguin/1913487 to your computer and use it in GitHub Desktop.
Save jamespenguin/1913487 to your computer and use it in GitHub Desktop.
it's a secret
int bufferWidth = CVPixelBufferGetWidth(pixelBuffer);
int bufferHeight = CVPixelBufferGetHeight(pixelBuffer);
uint8_t *pixel = CVPixelBufferGetBaseAddress(pixelBuffer);
uint8_t * baseAddressGray = (uint8_t *) malloc(bufferWidth*bufferHeight);
intrinsicBGRAtoGrayscale(baseAddressGray, pixel, bufferWidth*bufferHeight);
for (int i = 0; i < (bufferWidth * bufferHeight); i++) {
pixel[0] = baseAddressGray[0];
pixel[1] = baseAddressGray[0];
pixel[2] = baseAddressGray[0];
pixel += BYTES_PER_PIXEL;
baseAddressGray += 1;
}
free(baseAddressGray);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment