     
     var image:UIImage! {
         didSet {
+            guard let device = SNTrimController.device else {
+                return
+            }
             let size = image.size
             let length = 4 * Int(size.width) * Int(size.height)
-            self.pixelBuffer = SNTrimController.device?.newBufferWithLength(length, options: [.StorageModeShared])
+            self.pixelBuffer = device.newBufferWithLength(length, options: [.StorageModeShared])
+            self.horizontalBuffer = device.newBufferWithLength(4 * Int(size.height), options: [.StorageModeShared])
+            self.verticalBuffer = device.newBufferWithLength(4 * Int(size.width), options: [.StorageModeShared])
         }
     }
     var delegate:SNTrimControllerDelegate!

    // Metal
    static let device = MTLCreateSystemDefaultDevice()
    static let queue = SNTrimController.device?.newCommandQueue()
    static let pipeline:MTLComputePipelineState? = {
        if let function = SNTrimController.device?.newDefaultLibrary()?.newFunctionWithName("maskImage") {
            return try! SNTrimController.device?.newComputePipelineStateWithFunction(function)
        }
        return nil
    }()
    var pixelBuffer:MTLBuffer?
    
    private let borderView:UIView = {
        let borderView = UIView()

extension SNTrimController: SNTrimColorPickerDelegate {
    func updateMaskColor(color:UIColor?, fPlus:Bool) {
        guard let queue = SNTrimController.queue,
              let psMask = SNTrimController.psMask,
              let pixelBuffer = self.pixelBuffer else {
            print("SNTrim No Metal. User CPU")
            return updateMaskColorCPU(color, fPlus: fPlus)
