       cropRect = facesRect
     }
     
-    return rescaled.imageByCroppingToRect(cropRect)
+    let cropped = image.imageByCroppingToRect(cropRect)
+    let transform = CGAffineTransformMakeTranslation(-cropped.extent.minX, -cropped.extent.minY)
+    return cropped.imageByApplyingTransform(transform)
   }
-  
+
+  private func createTexture(width width: Int, height: Int) -> MTLTexture {
+    let descriptor = MTLTextureDescriptor.texture2DDescriptorWithPixelFormat(.BGRA8Unorm, width: width, height: height, mipmapped: false)
+    descriptor.usage = [.ShaderRead, .ShaderWrite]
+    return device.newTextureWithDescriptor(descriptor)
+  }
+
+  private func createScaledTexture(sourceTexture: MTLTexture, dimension: Int) -> MTLTexture {
+    let scale = MPSImageLanczosScale(device: device)
+    let factor = Double(dimension) / Double(sourceTexture.width)
+    var scaleTransform = MPSScaleTransform(scaleX: factor, scaleY: factor, translateX: 0, translateY: 0)
+
+    withUnsafePointer(&scaleTransform) { ptr in
+      scale.scaleTransform = ptr
+    }
+
+    let texture = createTexture(width: dimension, height: dimension)
+    scale.encodeToCommandBuffer(commandBuffer, sourceTexture: sourceTexture, destinationTexture: texture)
+    return texture
+  }
+
+  private func transposeTexture(sourceTexture: MTLTexture) -> MTLTexture {
+    let texture = createTexture(width: sourceTexture.height, height: sourceTexture.width)
+
+    let transpose = MPSImageTranspose(device: device)
+    transpose.encodeToCommandBuffer(commandBuffer, sourceTexture: sourceTexture, destinationTexture: texture)
+
+    return texture
+  }
+
 }

import CoreImage
import ImageIO
import Metal

class GoldenSpiralFilter: CIFilter {



  private var colorSpace: CGColorSpaceRef?

  private let device: MTLDevice! = MTLCreateSystemDefaultDevice()

  lazy var commandQueue: MTLCommandQueue = {
    return self.device.newCommandQueue()
  }()

  lazy var commandBuffer: MTLCommandBuffer = {
    return self.commandQueue.commandBuffer()
  }()

  private func tileImage(image: CIImage) -> CIImage? {
    guard let colorSpace = colorSpace else {
      return nil
    }

