2

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);
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131
  • 1
    Hi, Apple have a sample code project that demonstrates ``vImageBuffer_InitWithCVPixelBuffer` at: https://developer.apple.com/documentation/accelerate/vimage/reading_from_and_writing_to_core_video_pixel_buffers . You don't need to set the `data` property of the buffer if you use `vImageBuffer_InitWithCVPixelBuffer` - see the sample code. – Flex Monkey Mar 12 '18 at 10:08
  • Thanks for the sample code. It seems there was no need to call vImageBuffer_InitWithCVPixelBuffer in my case, just setting the data, rowBytes, width, height are enough. – Deepak Sharma Mar 12 '18 at 19:24
  • This SO answer contains working code to grab properties from a CoreVideo pixel buffer. https://stackoverflow.com/a/53737749/763355 – MoDJ Dec 12 '18 at 20:13

0 Answers0