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 <gjpower@tcd.ie>
This commit is contained in:
parent
a639ac42c4
commit
fd4bfaea1f
|
@ -17,6 +17,7 @@ Improvements 🙌:
|
||||||
- Prepare changelog for F-Droid (#2296)
|
- Prepare changelog for F-Droid (#2296)
|
||||||
- Add graphic resources for F-Droid (#812, #2220)
|
- Add graphic resources for F-Droid (#812, #2220)
|
||||||
- Highlight text in the body of the displayed result (#2200)
|
- Highlight text in the body of the displayed result (#2200)
|
||||||
|
- Considerably faster QR-code bitmap generation (#2331)
|
||||||
|
|
||||||
Bugfix 🐛:
|
Bugfix 🐛:
|
||||||
- Messages encrypted with no way to decrypt after SDK update from 0.18 to 1.0.0 (#2252)
|
- Messages encrypted with no way to decrypt after SDK update from 0.18 to 1.0.0 (#2252)
|
||||||
|
|
|
@ -34,12 +34,15 @@ fun String.toBitMatrix(size: Int): BitMatrix {
|
||||||
|
|
||||||
fun BitMatrix.toBitmap(@ColorInt backgroundColor: Int = Color.WHITE,
|
fun BitMatrix.toBitmap(@ColorInt backgroundColor: Int = Color.WHITE,
|
||||||
@ColorInt foregroundColor: Int = Color.BLACK): Bitmap {
|
@ColorInt foregroundColor: Int = Color.BLACK): Bitmap {
|
||||||
val bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
val colorBuffer = IntArray(width*height)
|
||||||
for (x in 0 until width) {
|
var rowOffset = 0
|
||||||
for (y in 0 until height) {
|
for (y in 0 until height) {
|
||||||
bmp.setPixel(x, y, if (get(x, y)) foregroundColor else backgroundColor)
|
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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue