title: Rendering small CIImage centered in MTKView
body: <p>I'm rendering a <code>CIImage</code> to <code>MTKView</code> and the image is smaller than the drawable. </p>
  
  <pre><code>let centered = image.transformed(by: CGAffineTransform(translationX: (view.drawableSize.width - image.extent.width) / 2, y: (view.drawableSize.height - image.extent.height) / 2))
  context.render(centered, to: drawable.texture, commandBuffer: buffer, bounds: centered.extent, colorSpace: CGColorSpaceCreateDeviceRGB())
  </code></pre>
  
  <p>I'd expect the code above to render the image in the center of the view, but the image is positioned at origin instead. </p>
  
  <p>Here's the repo illustrating the problem: <a href="https://github.com/truemetal/centered-render-of-ciimage-to-mtkview" rel="nofollow noreferrer">https://github.com/truemetal/centered-render-of-ciimage-to-mtkview</a></p>
  
  <p>Before blaming <code>Metal</code> or <code>CoreImage</code> I'd like to make sure I'm not doing something wrong. </p>
  
  <p>I'd appreciate a link to the documentation that says I can't do something like that.</p>
  
  <p><a href="https://i.stack.imgur.com/Tivgc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Tivgc.png" alt="problem screenshot"></a></p>
  
  <p>I can workaround this by compositing the image over another one that would be exactly the size of the drawable like so, but I'm still interested in why exactly the code above does not work.</p>
  
  <pre><code>let centered = image.transformed(by: CGAffineTransform(translationX: (view.drawableSize.width - image.extent.width) / 2, y: (view.drawableSize.height - image.extent.height) / 2))
  let background = CIImage(color: .white).cropped(to: CGRect(origin: .zero, size: view.drawableSize))
  let preparedImage = centered.composited(over: background)
  self.context.render(preparedImage, to: drawable.texture, commandBuffer: buffer, bounds: preparedImage.extent, colorSpace: CGColorSpaceCreateDeviceRGB())
  </code></pre>