From 35f88ca386d469183f525167290dbd778eef6564 Mon Sep 17 00:00:00 2001 From: herodotos Date: Wed, 7 May 2025 08:19:13 +0200 Subject: [PATCH 1/2] Fix for coloured QR code fails to scan #2366 --- app/src/main/java/protect/card_locker/Utils.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/protect/card_locker/Utils.java b/app/src/main/java/protect/card_locker/Utils.java index 3be629d71..787e73806 100644 --- a/app/src/main/java/protect/card_locker/Utils.java +++ b/app/src/main/java/protect/card_locker/Utils.java @@ -53,10 +53,11 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.zxing.BinaryBitmap; import com.google.zxing.LuminanceSource; import com.google.zxing.MultiFormatReader; +import com.google.zxing.DecodeHintType; import com.google.zxing.NotFoundException; import com.google.zxing.RGBLuminanceSource; import com.google.zxing.Result; -import com.google.zxing.common.HybridBinarizer; +import com.google.zxing.common.GlobalHistogramBinarizer; import com.google.zxing.multi.GenericMultipleBarcodeReader; import com.google.zxing.multi.MultipleBarcodeReader; @@ -82,6 +83,7 @@ import java.util.Calendar; import java.util.Collections; import java.util.Currency; import java.util.Date; +import java.util.EnumMap; import java.util.GregorianCalendar; import java.util.HashMap; import java.util.List; @@ -381,14 +383,17 @@ public class Utils { // ...and then turned into a binary bitmap from its luminance LuminanceSource source = new RGBLuminanceSource(bitmap.getWidth(), bitmap.getHeight(), intArray); - BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source)); + BinaryBitmap binaryBitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source)); List parseResultList = new ArrayList<>(); try { MultiFormatReader multiFormatReader = new MultiFormatReader(); MultipleBarcodeReader multipleBarcodeReader = new GenericMultipleBarcodeReader(multiFormatReader); - Result[] barcodeResults = multipleBarcodeReader.decodeMultiple(binaryBitmap); + Map hints = new EnumMap<>(DecodeHintType.class); + hints.put(DecodeHintType.ALSO_INVERTED, Boolean.TRUE); + + Result[] barcodeResults = multipleBarcodeReader.decodeMultiple(binaryBitmap,hints); for (Result barcodeResult : barcodeResults) { Log.i(TAG, "Read barcode id: " + barcodeResult.getText()); From 88019dcae33536429a725c043cd8be85fa6274ab Mon Sep 17 00:00:00 2001 From: Sylvia van Os Date: Wed, 7 May 2025 22:56:48 +0200 Subject: [PATCH 2/2] Also apply inverted scanning to camera --- app/src/main/java/protect/card_locker/ScanActivity.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/protect/card_locker/ScanActivity.java b/app/src/main/java/protect/card_locker/ScanActivity.java index b5264adfe..6625ea113 100644 --- a/app/src/main/java/protect/card_locker/ScanActivity.java +++ b/app/src/main/java/protect/card_locker/ScanActivity.java @@ -37,6 +37,7 @@ import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.zxing.DecodeHintType; import com.google.zxing.ResultPoint; import com.google.zxing.client.android.Intents; import com.journeyapps.barcodescanner.BarcodeCallback; @@ -176,7 +177,13 @@ public class ScanActivity extends CatimaAppCompatActivity { builder.show(); }); + // Configure barcodeScanner barcodeScannerView = binding.zxingBarcodeScanner; + Intent barcodeScannerIntent = new Intent(); + Bundle barcodeScannerIntentBundle = new Bundle(); + barcodeScannerIntentBundle.putBoolean(DecodeHintType.ALSO_INVERTED.name(), Boolean.TRUE); + barcodeScannerIntent.putExtras(barcodeScannerIntentBundle); + barcodeScannerView.initializeFromIntent(barcodeScannerIntent); // Even though we do the actual decoding with the barcodeScannerView // CaptureManager needs to be running to show the camera and scanning bar