From f3718e496c8d26d9a39f1e75f75fc63a4782c681 Mon Sep 17 00:00:00 2001 From: Daniel Lublin Date: Tue, 8 Mar 2022 13:32:57 +0100 Subject: [PATCH] Use whole preview image when decoding QR When scanning Mailbox QR, the whole preview is visible on screen, so we should use it. We choose to never crop the preview, because it was originally a speed optimization which no longer is needed. --- .../briar/android/qrcode/QrCodeDecoder.java | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/briar-android/src/main/java/org/briarproject/briar/android/qrcode/QrCodeDecoder.java b/briar-android/src/main/java/org/briarproject/briar/android/qrcode/QrCodeDecoder.java index b3c5de4ee..d03c841b3 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/qrcode/QrCodeDecoder.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/qrcode/QrCodeDecoder.java @@ -1,7 +1,6 @@ package org.briarproject.briar.android.qrcode; import android.hardware.Camera; -import android.hardware.Camera.CameraInfo; import android.hardware.Camera.PreviewCallback; import android.hardware.Camera.Size; @@ -78,9 +77,7 @@ public class QrCodeDecoder implements PreviewConsumer, PreviewCallback { // The preview should be in NV21 format: width * height bytes of // Y followed by width * height / 2 bytes of interleaved U and V if (data.length == size.width * size.height * 3 / 2) { - CameraInfo info = new CameraInfo(); - Camera.getCameraInfo(cameraIndex, info); - decode(data, size.width, size.height, info.orientation); + decode(data, size.width, size.height); } else { // Camera parameters have changed - ask for a new preview LOG.info("Preview size does not match camera parameters"); @@ -94,9 +91,9 @@ public class QrCodeDecoder implements PreviewConsumer, PreviewCallback { } } - private void decode(byte[] data, int width, int height, int orientation) { + private void decode(byte[] data, int width, int height) { ioExecutor.execute(() -> { - BinaryBitmap bitmap = binarize(data, width, height, orientation); + BinaryBitmap bitmap = binarize(data, width, height); Result result; try { result = reader.decode(bitmap, @@ -113,16 +110,9 @@ public class QrCodeDecoder implements PreviewConsumer, PreviewCallback { }); } - private static BinaryBitmap binarize(byte[] data, int width, int height, - int orientation) { - // Crop to a square at the top (portrait) or left (landscape) of the - // screen - this will be faster to decode and should include - // everything visible in the viewfinder - int crop = Math.min(width, height); - int left = orientation >= 180 ? width - crop : 0; - int top = orientation >= 180 ? height - crop : 0; - LuminanceSource src = new PlanarYUVLuminanceSource(data, width, - height, left, top, crop, crop, false); + private static BinaryBitmap binarize(byte[] data, int width, int height) { + LuminanceSource src = new PlanarYUVLuminanceSource(data, width, height, + 0, 0, width, height, false); return new BinaryBitmap(new HybridBinarizer(src)); }