title: Pixel colors change as I save MTLTexture to CGImage?
body: <p>I need to save and load metal textures to a file. Example code below is below. I'm noticing the RGB values are changing as it gets saved and reloaded again.</p>
  
  <pre><code>metal texture pixel: RGBA: 42,79,12,95  
  after save and reload:     66,88,37,95
  </code></pre>
  
  <p>That got brighter and grayer. Next save it starts getting darker. I'm on an iPad Pro so wondering if this is a colorspace issue. Any pointers on why this might be happening and how to fix it?</p>
  
  <p>In the line below that is saving the <code>cgImage</code>, I can inspect the raw pixel data and see that the RGBA is 66,88,37. </p>
  
  <pre><code>// saving...
  let ciCtx = CIContext()
  let ciImage = CIImage(mtlTexture: metalTexture, options: [:])
  // [ … transfrom to flip y-coordinate …]
  let colorSpace = CGColorSpaceCreateDeviceRGB()
  let cgImage = ciCtx.createCGImage(ciImage, from: fullRect, format: kCIFormatRGBA8, colorSpace: colorSpace)!
  let imageDest = CGImageDestinationCreateWithData(mData, kUTTypePNG, 1, nil)!
  CGImageDestinationAddImage(imageDest, cgImage, nil)
  CGImageDestinationFinalize(imageDest)
  
  // loading...
  let src = CGImageSourceCreateWithData(imgData, nil)
  let img = CGImageSourceCreateImageAtIndex(src, 0, nil)
  let loader = MTKTextureLoader(device: self.metalDevice)
  let texture = try! loader.newTexture(cgImage: img, options: [:])
  </code></pre>