From fd4bfaea1f657611a80f0ee02308bd0a46e5a974 Mon Sep 17 00:00:00 2001 From: Graeme Power Date: Sat, 31 Oct 2020 16:07:23 +0100 Subject: [PATCH 1/3] Considerably faster QR-code bitmap generation Directly assign colours to a colour buffer then use that buffer to generate the bitmap. This is much faster than using Bitmap.setPixel for every pixel. Signed-off-by: Graeme Power --- CHANGES.md | 1 + .../main/java/im/vector/app/core/qrcode/QrCode.kt | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 56d38667fe..bb52452f8d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,7 @@ Improvements 🙌: - Prepare changelog for F-Droid (#2296) - Add graphic resources for F-Droid (#812, #2220) - Highlight text in the body of the displayed result (#2200) + - Considerably faster QR-code bitmap generation (#2331) Bugfix 🐛: - Messages encrypted with no way to decrypt after SDK update from 0.18 to 1.0.0 (#2252) diff --git a/vector/src/main/java/im/vector/app/core/qrcode/QrCode.kt b/vector/src/main/java/im/vector/app/core/qrcode/QrCode.kt index f79ae7afd9..9b5e01615f 100644 --- a/vector/src/main/java/im/vector/app/core/qrcode/QrCode.kt +++ b/vector/src/main/java/im/vector/app/core/qrcode/QrCode.kt @@ -34,12 +34,15 @@ fun String.toBitMatrix(size: Int): BitMatrix { fun BitMatrix.toBitmap(@ColorInt backgroundColor: Int = Color.WHITE, @ColorInt foregroundColor: Int = Color.BLACK): Bitmap { - val bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) - for (x in 0 until width) { - for (y in 0 until height) { - bmp.setPixel(x, y, if (get(x, y)) foregroundColor else backgroundColor) + val colorBuffer = IntArray(width*height) + var rowOffset = 0 + for (y in 0 until height) { + for (x in 0 until width) { + val arrayIndex = x + rowOffset + colorBuffer[arrayIndex] = if (get(x, y)) foregroundColor else backgroundColor } + rowOffset += width } - return bmp + return Bitmap.createBitmap(colorBuffer, width, height, Bitmap.Config.ARGB_8888) } From 856ae33fd5e142c7877d3a9bbd9923db58c22573 Mon Sep 17 00:00:00 2001 From: Graeme Power Date: Sat, 31 Oct 2020 17:38:02 +0100 Subject: [PATCH 2/3] Added details to AUTHORS.md Signed-off-by: Graeme Power --- AUTHORS.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/AUTHORS.md b/AUTHORS.md index a85beb2d6f..4fb5b8c994 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -1,4 +1,4 @@ -A full developer contributors list can be found [here](https://github.com/vector-im/element-android/graphs/contributors). +A full developer contributors list can be found [here](https://github.com/vector-im/element-android/graphs/contributors). # Core team: @@ -33,3 +33,8 @@ First of all, we thank all contributors who use Element and report problems on t We do not forget all translators, for their work of translating Element into many languages. They are also the authors of Element. Feel free to add your name below, when you contribute to the project! + +Name | Matrix ID | GitHub +--------|---------------------|-------------------------------------- +gjpower | @gjpower:matrix.org | [gjpower](https://github.com/gjpower) + From bd36c67bf24c82c6ceb75bb3af73861c647b4950 Mon Sep 17 00:00:00 2001 From: Graeme Power Date: Sat, 31 Oct 2020 17:43:16 +0100 Subject: [PATCH 3/3] satisfy ktlint demand for spacing around "*" Signed-off-by: Graeme Power --- vector/src/main/java/im/vector/app/core/qrcode/QrCode.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/core/qrcode/QrCode.kt b/vector/src/main/java/im/vector/app/core/qrcode/QrCode.kt index 9b5e01615f..170baa04fe 100644 --- a/vector/src/main/java/im/vector/app/core/qrcode/QrCode.kt +++ b/vector/src/main/java/im/vector/app/core/qrcode/QrCode.kt @@ -34,7 +34,7 @@ fun String.toBitMatrix(size: Int): BitMatrix { fun BitMatrix.toBitmap(@ColorInt backgroundColor: Int = Color.WHITE, @ColorInt foregroundColor: Int = Color.BLACK): Bitmap { - val colorBuffer = IntArray(width*height) + val colorBuffer = IntArray(width * height) var rowOffset = 0 for (y in 0 until height) { for (x in 0 until width) {