-
-
Notifications
You must be signed in to change notification settings - Fork 605
feat: Always return capture size #1202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7d536b0
75208e4
816c059
73827ae
1e7154c
47e39d0
b0d58a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,22 +47,17 @@ class MobileScannerHandler( | |
private var analyzerResult: MethodChannel.Result? = null | ||
|
||
private val callback: MobileScannerCallback = { barcodes: List<Map<String, Any?>>, image: ByteArray?, width: Int?, height: Int? -> | ||
if (image != null) { | ||
barcodeHandler.publishEvent(mapOf( | ||
"name" to "barcode", | ||
"data" to barcodes, | ||
"image" to mapOf( | ||
"bytes" to image, | ||
"width" to width?.toDouble(), | ||
"height" to height?.toDouble(), | ||
) | ||
)) | ||
} else { | ||
barcodeHandler.publishEvent(mapOf( | ||
"name" to "barcode", | ||
"data" to barcodes | ||
)) | ||
} | ||
barcodeHandler.publishEvent(mapOf( | ||
"name" to "barcode", | ||
"data" to barcodes, | ||
// The image dimensions are always provided. | ||
// The image bytes are only non-null when `returnImage` is true. | ||
"image" to mapOf( | ||
"bytes" to image, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The width / height were nullable, which could have been changed. However, the Dart code already handles null, so I just left it as-is, to reduce the diff here. |
||
"width" to width?.toDouble(), | ||
"height" to height?.toDouble(), | ||
) | ||
)) | ||
} | ||
|
||
private val errorCallback: MobileScannerErrorCallback = {error: String -> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,22 +69,18 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | |
return | ||
} | ||
|
||
if (!MobileScannerPlugin.returnImage) { | ||
barcodeHandler.publishEvent([ | ||
"name": "barcode", | ||
"data": barcodesMap, | ||
]) | ||
return | ||
} | ||
// The image dimensions are always provided. | ||
// The image bytes are only non-null when `returnImage` is true. | ||
let imageData: [String: Any?] = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making the bytes conditional started giving a warning with nullable Any, so I moved it to a separate dict here to fix that. |
||
"bytes": MobileScannerPlugin.returnImage ? FlutterStandardTypedData(bytes: image.jpegData(compressionQuality: 0.8)!) : nil, | ||
"width": image.size.width, | ||
"height": image.size.height, | ||
] | ||
|
||
barcodeHandler.publishEvent([ | ||
"name": "barcode", | ||
"data": barcodesMap, | ||
"image": [ | ||
"bytes": FlutterStandardTypedData(bytes: image.jpegData(compressionQuality: 0.8)!), | ||
"width": image.size.width, | ||
"height": image.size.height, | ||
], | ||
"image": imageData, | ||
]) | ||
}, torchModeChangeCallback: { torchState in | ||
barcodeHandler.publishEvent(["name": "torchState", "data": torchState]) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,8 +75,7 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { | |
/// If this is empty, all supported formats are detected. | ||
final List<BarcodeFormat> formats; | ||
|
||
/// Whether scanned barcodes should contain the image | ||
/// that is embedded into the barcode. | ||
/// Whether the [BarcodeCapture.image] bytes should be provided. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wording was incorrect, so I adjusted it. There is no support for returning images that are embedded in the center of some specific QR codes. (i.e. little square logo's) |
||
/// | ||
/// If this is false, [BarcodeCapture.image] will always be null. | ||
/// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,6 @@ class BarcodeCapture { | |
/// This is the data that was used to detect the available [barcodes], the input [image] and the [size]. | ||
final Object? raw; | ||
|
||
/// The size of the input [image]. | ||
/// | ||
/// If [image] is null, this will be [Size.zero]. | ||
/// The size of the camera input [image]. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adjusted the wording to match the new behavior. |
||
final Size size; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,7 @@ class MobileScannerWeb extends MobileScannerPlatform { | |
final JSArray<JSString>? facingModes = capabilities.facingModeNullable; | ||
|
||
// TODO: this is an empty array on MacOS Chrome, where there is no facing mode, but one, user facing camera. | ||
// We might be able to add a workaround, using the label of the video track. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to revisit the broken check for the transform on the web in the future. Just left a breadcrumb for myself here. |
||
// Facing mode is not supported by this track, do nothing. | ||
if (facingModes == null || facingModes.toDart.isEmpty) { | ||
return; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,7 @@ final class ZXingBarcodeReader extends BarcodeReader { | |
controller.add( | ||
BarcodeCapture( | ||
barcodes: [result.toBarcode], | ||
size: videoSize, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already had this information in the getter implementation, so I just forwarded it. This returns |
||
), | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,22 +156,26 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | |
}) | ||
|
||
DispatchQueue.main.async { | ||
if (!MobileScannerPlugin.returnImage) { | ||
guard let image = cgImage else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a guard-let to avoid |
||
self?.sink?([ | ||
"name": "barcode", | ||
"data": barcodes.map({ $0.toMap() }), | ||
]) | ||
return | ||
} | ||
|
||
|
||
// The image dimensions are always provided. | ||
// The image bytes are only non-null when `returnImage` is true. | ||
let imageData: [String: Any?] = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like on iOS, I moved the dict to a separate var to fix a warning. |
||
"bytes": MobileScannerPlugin.returnImage ? FlutterStandardTypedData(bytes: image.jpegData(compressionQuality: 0.8)!) : nil, | ||
"width": Double(image.width), | ||
"height": Double(image.height), | ||
] | ||
|
||
self?.sink?([ | ||
"name": "barcode", | ||
"data": barcodes.map({ $0.toMap() }), | ||
"image": cgImage == nil ? nil : [ | ||
"bytes": FlutterStandardTypedData(bytes: cgImage!.jpegData(compressionQuality: 0.8)!), | ||
"width": Double(cgImage!.width), | ||
"height": Double(cgImage!.height), | ||
], | ||
"image": imageData, | ||
]) | ||
} | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When not returning the created bitmap, use the available dimensions from the input image, which are the same.