title: Convert a CGImage to MTLTexture without premultiplication
body: <p>I have a UIImage which I've previously created from a png file:</p>
  
  <pre><code>let strokeUIImage = UIImage(data: pngData)
  </code></pre>
  
  <p>I want to convert strokeImage (which has opacity) to an <code>MTLTexture</code> for display in an <code>MTKView</code>, but doing the conversion seems to perform an unwanted premultiplication, which darkens all the semitransparent edges.</p>
  
  <p>My blending settings are as follows:</p>
  
  <pre><code>pipelineDescriptor.colorAttachments[0].isBlendingEnabled = true
  pipelineDescriptor.colorAttachments[0].rgbBlendOperation = .add
  pipelineDescriptor.colorAttachments[0].alphaBlendOperation = .add
  pipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .one
  pipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .one
  pipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
  pipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha
  </code></pre>
  
  <p>I've tried two methods of conversion:</p>
  
  <pre><code>let stampTexture = try! MTKTextureLoader(device: self.device!).newTexture(cgImage: strokeUIImage.cgImage!, options: nil)
  </code></pre>
  
  <p>and the more elaborate dataProvider-driven method:</p>
  
  <pre><code>let image = strokeUIImage.cgImage!
      let imageWidth = image.width
      let imageHeight = image.height
      let bytesPerPixel:Int! = 4
      let rowBytes = imageWidth * bytesPerPixel        
  
      let texDescriptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: .rgba8Unorm_srgb,
                                                                width: imageWidth,
                                                                height: imageHeight,
                                                                mipmapped: false)
  
      guard let stampTexture = device!.makeTexture(descriptor: texDescriptor) else { return }
  
      let srcData: CFData! = image.dataProvider?.data
      let pixelData = CFDataGetBytePtr(srcData)
  
      let region = MTLRegionMake2D(0, 0, imageWidth, imageHeight)
      stampTexture.replace(region: region, mipmapLevel: 0, withBytes: pixelData!, bytesPerRow: Int(rowBytes))
  </code></pre>
  
  <p>both of which yield the same unwanted premultiplied result. </p>
  
  <p>The latter I tried, as there were some posts suggesting that the old swift3 method <code>CGDataProviderCopyData()</code> extracts raw pixel data from the image which is not premultiplied.  Sadly, the equivalent:</p>
  
  <pre><code>let srcData: CFData! = image.dataProvider?.data
  </code></pre>
  
  <p>does not seem to do the trick. Am I missing something? </p>
  
  <p>Any pointers would be appreciated.</p>