QR scanner better cropping & support for inverted colors
* QR scanner fixes * QR cropping * Code cleanup * Scanning frame offsets change * Changelog update --------- Co-authored-by: Honza <rychnovsky.honza@gmail.com>
This commit is contained in:
parent
741601b65f
commit
a503091ab2
|
@ -20,6 +20,8 @@ and this application adheres to [Semantic Versioning](https://semver.org/spec/v2
|
||||||
## Fixed
|
## Fixed
|
||||||
- Support Screen now shows the Send button above keyboard instead of overlaying it. This was achieved by setting
|
- Support Screen now shows the Send button above keyboard instead of overlaying it. This was achieved by setting
|
||||||
`adjustResize` to `MainActivity` and adding `imePadding` to top level composable
|
`adjustResize` to `MainActivity` and adding `imePadding` to top level composable
|
||||||
|
- QR code scanning speed and reliability have been improved to address the latest reported scan issue. The obtained
|
||||||
|
image cropping and image reader hints have been changed as part of these improvements.
|
||||||
|
|
||||||
## [1.1.3 (682)] - 2024-07-03
|
## [1.1.3 (682)] - 2024-07-03
|
||||||
|
|
||||||
|
|
|
@ -19,3 +19,4 @@ directly impact users rather than highlighting other key architectural updates.*
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Support Screen now shows the Send button above keyboard instead of overlaying it
|
- Support Screen now shows the Send button above keyboard instead of overlaying it
|
||||||
|
- QR code scanning speed and reliability have been improved to address the latest reported scan issue
|
||||||
|
|
|
@ -48,7 +48,12 @@ class ImageUriToQrCodeConverter {
|
||||||
private fun BinaryBitmap.toQRCode(): String =
|
private fun BinaryBitmap.toQRCode(): String =
|
||||||
MultiFormatReader()
|
MultiFormatReader()
|
||||||
.apply {
|
.apply {
|
||||||
setHints(mapOf(DecodeHintType.POSSIBLE_FORMATS to arrayListOf(BarcodeFormat.QR_CODE)))
|
setHints(
|
||||||
|
mapOf(
|
||||||
|
DecodeHintType.POSSIBLE_FORMATS to arrayListOf(BarcodeFormat.QR_CODE),
|
||||||
|
DecodeHintType.ALSO_INVERTED to true
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
.decode(this@toQRCode).text
|
.decodeWithState(this@toQRCode).text
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,35 +37,55 @@ class QrCodeAnalyzer(
|
||||||
"Image height: ${image.height}"
|
"Image height: ${image.height}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO [#1380]: Leverage FramePosition in QrCodeAnalyzer
|
||||||
|
// TODO [#1380]: https://github.com/Electric-Coin-Company/zashi-android/issues/1380
|
||||||
val source =
|
val source =
|
||||||
PlanarYUVLuminanceSource(
|
if (image.height > image.width) {
|
||||||
bytes,
|
PlanarYUVLuminanceSource(
|
||||||
image.width,
|
// yuvData =
|
||||||
image.height,
|
bytes,
|
||||||
0,
|
// dataWidth =
|
||||||
0,
|
image.width,
|
||||||
image.width,
|
// dataHeight =
|
||||||
image.height,
|
image.height,
|
||||||
false
|
// left =
|
||||||
)
|
(image.width * LEFT_OFFSET).toInt(),
|
||||||
|
// top =
|
||||||
|
(image.height * TOP_OFFSET).toInt(),
|
||||||
|
// width =
|
||||||
|
(image.width * WIDTH_OFFSET).toInt(),
|
||||||
|
// height =
|
||||||
|
(image.height * HEIGHT_OFFSET).toInt(),
|
||||||
|
// reverseHorizontal =
|
||||||
|
false
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
PlanarYUVLuminanceSource(
|
||||||
|
// yuvData =
|
||||||
|
bytes,
|
||||||
|
// dataWidth =
|
||||||
|
image.width,
|
||||||
|
// dataHeight =
|
||||||
|
image.height,
|
||||||
|
// left =
|
||||||
|
(image.width * TOP_OFFSET).toInt(),
|
||||||
|
// top =
|
||||||
|
(image.height * LEFT_OFFSET).toInt(),
|
||||||
|
// width =
|
||||||
|
(image.width * HEIGHT_OFFSET).toInt(),
|
||||||
|
// height =
|
||||||
|
(image.height * WIDTH_OFFSET).toInt(),
|
||||||
|
// reverseHorizontal =
|
||||||
|
false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val binaryBmp = BinaryBitmap(HybridBinarizer(source))
|
val binaryBmp = BinaryBitmap(HybridBinarizer(source))
|
||||||
|
|
||||||
// TODO [#1380]: Leverage FramePosition in QrCodeAnalyzer
|
|
||||||
// TODO [#1380]: https://github.com/Electric-Coin-Company/zashi-android/issues/1380
|
|
||||||
@Suppress("MagicNumber")
|
|
||||||
val binaryBitmapCropped =
|
|
||||||
binaryBmp.crop(
|
|
||||||
(binaryBmp.width * 0.25).toInt(),
|
|
||||||
(binaryBmp.height * 0.30).toInt(),
|
|
||||||
(binaryBmp.width * 0.30).toInt(),
|
|
||||||
(binaryBmp.height * 0.4).toInt()
|
|
||||||
)
|
|
||||||
|
|
||||||
Twig.verbose {
|
Twig.verbose {
|
||||||
"Scan result cropped: " +
|
"Scan result cropped: " +
|
||||||
"Image width: ${binaryBitmapCropped.width}, " +
|
"Image width: ${binaryBmp.width}, " +
|
||||||
"Image height: ${binaryBitmapCropped.height}"
|
"Image height: ${binaryBmp.height}"
|
||||||
}
|
}
|
||||||
|
|
||||||
runCatching {
|
runCatching {
|
||||||
|
@ -73,13 +93,11 @@ class QrCodeAnalyzer(
|
||||||
MultiFormatReader().apply {
|
MultiFormatReader().apply {
|
||||||
setHints(
|
setHints(
|
||||||
mapOf(
|
mapOf(
|
||||||
DecodeHintType.POSSIBLE_FORMATS to
|
DecodeHintType.POSSIBLE_FORMATS to arrayListOf(BarcodeFormat.QR_CODE),
|
||||||
arrayListOf(
|
DecodeHintType.ALSO_INVERTED to true
|
||||||
BarcodeFormat.QR_CODE
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}.decode(binaryBitmapCropped)
|
}.decodeWithState(binaryBmp)
|
||||||
|
|
||||||
onQrCodeScanned(result.text)
|
onQrCodeScanned(result.text)
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
|
@ -96,3 +114,8 @@ class QrCodeAnalyzer(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const val LEFT_OFFSET = .15
|
||||||
|
private const val TOP_OFFSET = .15
|
||||||
|
private const val WIDTH_OFFSET = .7
|
||||||
|
private const val HEIGHT_OFFSET = .45
|
||||||
|
|
Loading…
Reference in New Issue