Skip to content

Instantly share code, notes, and snippets.

View ViktoriiaKh's full-sized avatar

Viktoriia ViktoriiaKh

View GitHub Profile
@allenhumphreys
allenhumphreys / CreateCroppedPixelBufferBiPlanar.c
Last active May 3, 2024 06:58
Functions in Swift/C to Crop and Scale CVPixelBuffers in the BiPlanar formats
CVPixelBufferRef createCroppedPixelBufferBiPlanar(CVPixelBufferRef srcPixelBuffer, CGRect croppingRect, CGSize scaleSize) {
OSType inputPixelFormat = CVPixelBufferGetPixelFormatType(srcPixelBuffer);
assert(inputPixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
|| inputPixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange);
size_t inputWidth = CVPixelBufferGetWidth(srcPixelBuffer);
size_t inputHeight = CVPixelBufferGetHeight(srcPixelBuffer);
assert(CGRectGetMinX(croppingRect) >= 0);