title: RGB values of CIImage pixel
body: <p>I want to access the average colour value of a specific area of <code>CVPixelBuffer</code> that I get from <code>ARFrame</code> in real-time. I managed to crop the image, use filter to calculate average colour and after converting to <code>CGImage</code> I get the value from the pixel but unfortunately, it affects the performance of my app (FPS drops below 30fps). I think that the reason for that is using CGContext. Is there a way to access colour without converting <code>CIImage</code> to <code>CGImage</code>?
  This is code that I'm using at the moment:</p>
  
  <pre class="lang-swift prettyprint-override"><code>func fun() {
    let croppVector = CIVector(cgRect: inputImageRect)
  
    guard let filter = CIFilter(
      name: "CIAreaAverage",
      parameters: [kCIInputImageKey: image, kCIInputExtentKey: croppVector]
    ),
      let outputImage = filter.outputImage,
      let cgImage = context.createCGImage(
        outputImage,
        from: CGRect(x: 0, y: 0, width: 1, height: 1)
      ),
      let dataProvider = cgImage.dataProvider,
      let data = CFDataGetBytePtr(dataProvider.data) else { return nil }
  
    let color = UIColor(
      red: CGFloat(data[0]) / 255,
      green: CGFloat(data[1]) / 255,
      blue: CGFloat(data[2]) / 255,
      alpha: CGFloat(data[3]) / 255
    )
  }
  </code></pre>