From dcf7b7854ff869f870e63f1f08db5a35db67d14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Tue, 23 Feb 2021 09:45:24 +0800 Subject: [PATCH] Fix reading reverse color qr code --- .../java/org/telegram/ui/CameraScanActivity.java | 11 +++++++++-- .../java/tw/nekomimi/nekogram/utils/ProxyUtil.kt | 12 +++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/ui/CameraScanActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/CameraScanActivity.java index 3fac5138d..5e1771133 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/CameraScanActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/CameraScanActivity.java @@ -38,7 +38,6 @@ import com.google.zxing.PlanarYUVLuminanceSource; import com.google.zxing.RGBLuminanceSource; import com.google.zxing.Result; import com.google.zxing.common.GlobalHistogramBinarizer; -import com.google.zxing.common.HybridBinarizer; import com.google.zxing.qrcode.QRCodeReader; import org.telegram.messenger.AndroidUtilities; @@ -670,7 +669,15 @@ public class CameraScanActivity extends BaseFragment implements Camera.PreviewCa } else { source = new PlanarYUVLuminanceSource(data, size.getWidth(), size.getHeight(), x, y, side, side, false); } - Result result = qrReader.decode(new BinaryBitmap(new GlobalHistogramBinarizer(source))); + Result result = null; + try { + result = qrReader.decode(new BinaryBitmap(new GlobalHistogramBinarizer(source))); + } catch (NotFoundException e) { + try { + result = qrReader.decode(new BinaryBitmap(new GlobalHistogramBinarizer(source.invert()))); + } catch (NotFoundException ignore) { + } + } if (result == null) { onNoQrFound(); return null; diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/utils/ProxyUtil.kt b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/utils/ProxyUtil.kt index a17c7c2db..874a1b7fe 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/utils/ProxyUtil.kt +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/utils/ProxyUtil.kt @@ -596,9 +596,15 @@ object ProxyUtil { try { - val result = qrReader.decode(BinaryBitmap(GlobalHistogramBinarizer(source)), mapOf( - DecodeHintType.TRY_HARDER to true - )) + val result = try { + qrReader.decode(BinaryBitmap(GlobalHistogramBinarizer(source)), mapOf( + DecodeHintType.TRY_HARDER to true + )) + } catch (e: NotFoundException) { + qrReader.decode(BinaryBitmap(GlobalHistogramBinarizer(source.invert())), mapOf( + DecodeHintType.TRY_HARDER to true + )) + } showLinkAlert(ctx, result.text)