casvanluijtelaar

cleanup

@@ -231,6 +231,7 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan @@ -231,6 +231,7 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan
231 videoOutput.alwaysDiscardsLateVideoFrames = true 231 videoOutput.alwaysDiscardsLateVideoFrames = true
232 232
233 videoOutput.setSampleBufferDelegate(self, queue: DispatchQueue.main) 233 videoOutput.setSampleBufferDelegate(self, queue: DispatchQueue.main)
  234 +
234 captureSession.addOutput(videoOutput) 235 captureSession.addOutput(videoOutput)
235 for connection in videoOutput.connections { 236 for connection in videoOutput.connections {
236 connection.videoOrientation = .portrait 237 connection.videoOrientation = .portrait
@@ -240,25 +241,25 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan @@ -240,25 +241,25 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan
240 } 241 }
241 captureSession.commitConfiguration() 242 captureSession.commitConfiguration()
242 captureSession.startRunning() 243 captureSession.startRunning()
243 - 244 +
244 let demensions = CMVideoFormatDescriptionGetDimensions(device.activeFormat.formatDescription) 245 let demensions = CMVideoFormatDescriptionGetDimensions(device.activeFormat.formatDescription)
245 -  
246 246
247 - /// limit captureSession area of interest to the scanWindow if provided  
248 - let scanWindowData: Array? = argReader.intArray(key: "scanWindow") 247 + /// limit captureSession area of interest to the scanWindow if provided
  248 + let scanWindowData: Array? = argReader.floatArray(key: "scanWindow")
249 if(scanWindowData != nil) { 249 if(scanWindowData != nil) {
250 250
251 let captureMetadataOutput = AVCaptureMetadataOutput() 251 let captureMetadataOutput = AVCaptureMetadataOutput()
252 252
253 - let x = CGFloat(scanWindowData![0] / Int(demensions.width))  
254 - let y = CGFloat(scanWindowData![1] / Int(demensions.height))  
255 - let w = CGFloat((scanWindowData![2] - scanWindowData![0]) / Int(demensions.width))  
256 - let h = CGFloat((scanWindowData![3] - scanWindowData![1]) / Int(demensions.height)) 253 + let x = scanWindowData![0] / CGFloat(demensions.width)
  254 + let y = scanWindowData![1] / CGFloat(demensions.height)
  255 + let w = scanWindowData![2] - scanWindowData![0] / CGFloat(demensions.width)
  256 + let h = scanWindowData![3] - scanWindowData![1] / CGFloat(demensions.height)
257 257
258 captureMetadataOutput.rectOfInterest = CGRect(x: x, y: y, width: w, height: h) 258 captureMetadataOutput.rectOfInterest = CGRect(x: x, y: y, width: w, height: h)
259 captureSession.addOutput(captureMetadataOutput) 259 captureSession.addOutput(captureMetadataOutput)
260 } 260 }
261 - 261 +
  262 +
262 let width = Double(demensions.height) 263 let width = Double(demensions.height)
263 let height = Double(demensions.width) 264 let height = Double(demensions.width)
264 let size = ["width": width, "height": height] 265 let size = ["width": width, "height": height]
@@ -391,5 +392,9 @@ class MapArgumentReader { @@ -391,5 +392,9 @@ class MapArgumentReader {
391 func intArray(key: String) -> [Int]? { 392 func intArray(key: String) -> [Int]? {
392 return args?[key] as? [Int] 393 return args?[key] as? [Int]
393 } 394 }
  395 +
  396 + func floatArray(key: String) -> [CGFloat]? {
  397 + return args?[key] as? [CGFloat]
  398 + }
394 399
395 } 400 }