title: How do you scale an image using vImage in the Accelerate framework in iOS 8?
body: <p>I am trying to resize a CMSampleBufferRef as quickly as possible on an iOS 8 device for use in image processing. From what I have found online, the way to do this seems to be by using the <a href="https://developer.apple.com/library/ios/documentation/Performance/Conceptual/vImage/GeometricOperations/GeometricOperations.html#//apple_ref/doc/uid/TP30001001-CH206-SW1" rel="nofollow">vImage API</a> in the Accelerate framework. However, I haven't done much with the Accelerate framework and I can't quite figure out how to do this. Here is what I have so far to scale an image to 200x200:</p>
  
  <pre><code>- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
  {
      CVImageBufferRef cvimgRef = CMSampleBufferGetImageBuffer(sampleBuffer);
      CVPixelBufferLockBaseAddress(cvimgRef,0);
      void *imageData = CVPixelBufferGetBaseAddress(cvimgRef);
      NSInteger width = CVPixelBufferGetWidth(cvimgRef);
      NSInteger height = CVPixelBufferGetHeight(cvimgRef);
  
      unsigned char *newData= // NOT SURE WHAT THIS SHOULD BE...
      vImage_Buffer  inBuff = { imageData, height, width, 4*width };
      vImage_Buffer  outBuff = { newData, 200, 200, 4*200 };
  
      // NOT SURE IF THIS IS THE CORRECT METHOD... video output settings for kCVPixelBufferPixelFormatTypeKey is set to kCVPixelFormatType_32BGRA
      // This seems wrong since the image scale is ARGB, not BGRA.
      vImageScale_ARGB8888(inBuffer, outBuffer, NULL, kvImageNoFlags);
      CVPixelBufferUnlockBaseAddress(cvimgRef,0);
  }
  </code></pre>
  
  <p>Where outBuffer is the result. After that, I am also not sure how to convert the outBuffer back to a CVImageBufferRef for further image processing. Any suggestions would be appreciated!</p>