Skip to content

Conversation

navaronbracke
Copy link
Collaborator

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

if (!returnImage) {
mobileScannerCallback(barcodeMap, null, null, null)
mobileScannerCallback(
barcodeMap,
Copy link
Collaborator Author

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.


/// Whether scanned barcodes should contain the image
/// that is embedded into the barcode.
/// Whether the [BarcodeCapture.image] bytes should be provided.
Copy link
Collaborator Author

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].
Copy link
Collaborator Author

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.

controller.add(
BarcodeCapture(
barcodes: [result.toBarcode],
size: videoSize,
Copy link
Collaborator Author

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,
Copy link
Collaborator Author

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.

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.
Copy link
Collaborator Author

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?] = [
Copy link
Collaborator Author

@navaronbracke navaronbracke Oct 5, 2024

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?] = [
Copy link
Collaborator Author

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.


DispatchQueue.main.async {
if (!MobileScannerPlugin.returnImage) {
guard let image = cgImage else {
Copy link
Collaborator Author

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

@navaronbracke navaronbracke changed the title Always return capture size imp: Always return capture size Oct 5, 2024
@navaronbracke navaronbracke changed the title imp: Always return capture size feat: Always return capture size Oct 5, 2024
@navaronbracke navaronbracke merged commit 7edd187 into juliansteenbakker:master Oct 5, 2024
4 of 6 checks passed
@navaronbracke navaronbracke deleted the always_return_capture_size branch October 5, 2024 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant