Reputation: 6581
I am using the following code to initialize a vImage_Buffer from a pixel buffer. I have passed the second argument in vImageBuffer_InitWithCVPixelBuffer as NULL (vImage_CGImageFormat) so that there are no internal format conversions from pixel buffer to vImageBuffer. It gives a warning in XCode - "Null passed to a callee that requires a non-null argument", but works. Problem is if I convert it to Swift, it doesn't compiles as it needs a non-nil argument. What is the right way to make a vImage buffer from pixel buffer in a pass through manner? Even the declaration of function says a NULL value in second argument is acceptable, but not sure why the warning then.
// vImage processing
vImage_Error err;
vImage_Buffer buffer;
buffer.data = (unsigned char *)CVPixelBufferGetBaseAddress( pixelBuffer );
buffer.rowBytes = CVPixelBufferGetBytesPerRow( pixelBuffer );
buffer.width = CVPixelBufferGetWidth( pixelBuffer );
buffer.height = CVPixelBufferGetHeight( pixelBuffer );
vImageCVImageFormatRef vformat = vImageCVImageFormat_CreateWithCVPixelBuffer( pixelBuffer );
/*
vImage_CGImageFormat cgformat = {
.bitsPerComponent = 8,
.bitsPerPixel = 32,
.bitmapInfo = kCGBitmapByteOrderDefault,
.colorSpace = NULL, //sRGB
};
*/
vImageBuffer_InitWithCVPixelBuffer(&buffer, NULL, pixelBuffer, vformat, NULL, kvImageNoAllocate);
Upvotes: 2
Views: 2633