CircleToSearch with multi search engine support for all android
Kotlin
improved QR code detection
AKS Labs3244a7aa4d64
diff --git a/.kotlin/errors/errors-1774258859680.log b/.kotlin/errors/errors-1774258859680.lognew file mode 100644index 0000000..1219b50--- /dev/null+++ b/.kotlin/errors/errors-1774258859680.log@@ -0,0 +1,4 @@+kotlin version: 2.0.21+error message: The daemon has terminated unexpectedly on startup attempt #1 with error code: 0. The daemon process output:+ 1. Kotlin compile daemon is ready+diff --git a/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt b/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.ktindex 9e13ecb..d220009 100644--- a/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt+++ b/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt@@ -685,7 +685,7 @@ class CircleToSearchAccessibilityService : AccessibilityService() {executor,object : TakeScreenshotCallback {override fun onSuccess(screenshot: ScreenshotResult) {- try {+ try {val hardwareBuffer = screenshot.hardwareBufferval colorSpace = screenshot.colorSpacediff --git a/app/src/main/java/com/akslabs/circletosearch/utils/QrScanner.kt b/app/src/main/java/com/akslabs/circletosearch/utils/QrScanner.ktindex 32fa4a8..aa6a402 100644--- a/app/src/main/java/com/akslabs/circletosearch/utils/QrScanner.kt+++ b/app/src/main/java/com/akslabs/circletosearch/utils/QrScanner.kt@@ -36,16 +36,7 @@ object QrScanner {private val HINTS = mapOf(DecodeHintType.TRY_HARDER to true,- DecodeHintType.POSSIBLE_FORMATS to listOf(- BarcodeFormat.QR_CODE,- BarcodeFormat.EAN_13,- BarcodeFormat.EAN_8,- BarcodeFormat.UPC_A,- BarcodeFormat.DATA_MATRIX,- BarcodeFormat.PDF_417,- BarcodeFormat.CODE_128,- BarcodeFormat.CODE_39- )+ DecodeHintType.POSSIBLE_FORMATS to listOf(BarcodeFormat.QR_CODE))/** Scan for all barcodes / QR codes in the given bitmap. Returns empty list when none found. */@@ -57,34 +48,54 @@ object QrScanner {bitmap.getPixels(pixels, 0, width, 0, 0, width, height)val source = RGBLuminanceSource(width, height, pixels)- val binaryBitmap = BinaryBitmap(HybridBinarizer(source))-val multiReader = GenericMultipleBarcodeReader(MultiFormatReader())- android.util.Log.d("CircleToSearch", "QrScanner: Starting decodeMultiple (HybridBinarizer)...")- var rawResults: Array<Result> = try {- multiReader.decodeMultiple(binaryBitmap, HINTS)- } catch (e: NotFoundException) {- android.util.Log.d("CircleToSearch", "QrScanner: HybridBinarizer found nothing, trying GlobalHistogramBinarizer...")++ val allResults = mutableListOf<QrResultWithBounds>()+ val foundTexts = mutableSetOf<String>()++ fun tryStrategy(binarizerType: String, inverted: Boolean) {try {- val globalBitmap = BinaryBitmap(com.google.zxing.common.GlobalHistogramBinarizer(source))- multiReader.decodeMultiple(globalBitmap, HINTS)- } catch (e2: NotFoundException) {- android.util.Log.d("CircleToSearch", "QrScanner: GlobalHistogramBinarizer also found nothing")- emptyArray()+ val currentSource = if (inverted) source.invert() else source+ val binarizer = if (binarizerType == "Hybrid") {+ HybridBinarizer(currentSource)+ } else {+ com.google.zxing.common.GlobalHistogramBinarizer(currentSource)+ }++ val binaryBitmap = BinaryBitmap(binarizer)+ val rawResults = multiReader.decodeMultiple(binaryBitmap, HINTS)++ rawResults.forEach { raw ->+ if (!foundTexts.contains(raw.text)) {+ foundTexts.add(raw.text)+ val bounds = computeBounds(raw.resultPoints)+ allResults.add(QrResultWithBounds(parseResult(raw.text), raw.text, bounds))+ }+ }+ android.util.Log.d("CircleToSearch", "QrScanner: Strategy $binarizerType (inverted=$inverted) found ${rawResults.size} new codes")+ } catch (e: NotFoundException) {+ // Normal, keep going+ } catch (e: Exception) {+ android.util.Log.e("CircleToSearch", "QrScanner: Strategy $binarizerType (inverted=$inverted) error", e)}- } catch (e: Exception) {- android.util.Log.e("CircleToSearch", "QrScanner: Error during decode", e)- emptyArray()}- android.util.Log.d("CircleToSearch", "QrScanner: Processed ${rawResults.size} raw results")- rawResults.mapNotNull { raw ->- try {- val bounds = computeBounds(raw.resultPoints)- QrResultWithBounds(parseResult(raw.text), raw.text, bounds)- } catch (e: Exception) { null }- }+ // 1. Standard Hybrid (Fast and good for most cases)+ tryStrategy("Hybrid", false)++ // 2. Global Histogram (Handles low contrast / lighting issues better)+ tryStrategy("Global", false)++ // 3. Inverted Hybrid (For light-on-dark QR codes)+ tryStrategy("Hybrid", true)++ // 4. Inverted Global (For light-on-dark with poor contrast)+ tryStrategy("Global", true)++ android.util.Log.d("CircleToSearch", "QrScanner: Total distinct codes found: ${allResults.size}")+ allResults} catch (e: Exception) {+ android.util.Log.e("CircleToSearch", "QrScanner: Fatal error in scanBitmapAll", e)emptyList()}}