-
-
Notifications
You must be signed in to change notification settings - Fork 527
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
feat: Always return capture size #1202
feat: Always return capture size #1202
Conversation
@@ -120,7 +120,11 @@ class MobileScanner( | |||
} | |||
|
|||
if (!returnImage) { | |||
mobileScannerCallback(barcodeMap, null, null, null) | |||
mobileScannerCallback( | |||
barcodeMap, |
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.
@@ -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 comment
The 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)
/// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted the wording to match the new behavior.
@@ -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 comment
The 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 Size.zero
if the camera output is not available.
// 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 comment
The 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.
@@ -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 comment
The 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.
} | ||
// 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 comment
The 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.
|
||
// 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 comment
The 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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Using a guard-let to avoid !
in the cgImage below, makes things look better
This PR updates the behavior of
returnImage
to only refer to the bytes of the output image, not the size.The size can always be returned, to allow users to do calculations with it (for example, together with the
Barcode.size
)Part of #1183