summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2023-09-07 01:23:00 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-09-07 01:23:00 +0000
commit8a005dea991e4332298d3e4744c92734b33a1fbc (patch)
tree0d13e3ec82d3ef85305167e1a0645e816d74f0a1
parent59e7faed34ff45105892aa3e11db6ab87dee69c6 (diff)
parent1e9a9bc1621f59438897a600b860b12e2c47ca99 (diff)
Merge "Support color reverse QR code" into main
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/qrcode/QrCamera.java27
1 files changed, 17 insertions, 10 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/qrcode/QrCamera.java b/packages/SettingsLib/src/com/android/settingslib/qrcode/QrCamera.java
index 364f46619061..e65109003856 100644
--- a/packages/SettingsLib/src/com/android/settingslib/qrcode/QrCamera.java
+++ b/packages/SettingsLib/src/com/android/settingslib/qrcode/QrCamera.java
@@ -36,6 +36,7 @@ import androidx.annotation.VisibleForTesting;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
+import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
@@ -249,16 +250,10 @@ public class QrCamera extends Handler {
// Semaphore.acquire() blocking until permit is available, or the thread is
// interrupted.
imageGot.acquire();
- Result qrCode = null;
- try {
- qrCode =
- mReader.decodeWithState(
- new BinaryBitmap(new HybridBinarizer(mImage)));
- } catch (ReaderException e) {
- // No logging since every time the reader cannot decode the
- // image, this ReaderException will be thrown.
- } finally {
- mReader.reset();
+ Result qrCode = decodeQrCode(mImage);
+ if (qrCode == null) {
+ // Check color inversion QR code
+ qrCode = decodeQrCode(mImage.invert());
}
if (qrCode != null) {
if (mScannerCallback.isValid(qrCode.getText())) {
@@ -272,6 +267,18 @@ public class QrCamera extends Handler {
}
}
+ private Result decodeQrCode(LuminanceSource source) {
+ try {
+ return mReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(source)));
+ } catch (ReaderException e) {
+ // No logging since every time the reader cannot decode the
+ // image, this ReaderException will be thrown.
+ } finally {
+ mReader.reset();
+ }
+ return null;
+ }
+
@Override
protected void onPostExecute(String qrCode) {
if (qrCode != null) {