speedup blurhash decoding by using a intermediate int array (#1835)

This commit is contained in:
Konrad Pozniak 2020-06-21 18:26:06 +02:00 committed by Alibek Omarov
parent fe6f34fd9f
commit 426db0ca88
1 changed files with 3 additions and 3 deletions

View File

@ -87,7 +87,7 @@ object BlurHashDecoder {
numCompX: Int, numCompY: Int, numCompX: Int, numCompY: Int,
colors: Array<FloatArray> colors: Array<FloatArray>
): Bitmap { ): Bitmap {
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) val imageArray = IntArray(width * height)
for (y in 0 until height) { for (y in 0 until height) {
for (x in 0 until width) { for (x in 0 until width) {
var r = 0f var r = 0f
@ -102,10 +102,10 @@ object BlurHashDecoder {
b += color[2] * basis b += color[2] * basis
} }
} }
bitmap.setPixel(x, y, Color.rgb(linearToSrgb(r), linearToSrgb(g), linearToSrgb(b))) imageArray[x + width * y] = Color.rgb(linearToSrgb(r), linearToSrgb(g), linearToSrgb(b))
} }
} }
return bitmap return Bitmap.createBitmap(imageArray, width, height, Bitmap.Config.ARGB_8888)
} }
private fun linearToSrgb(value: Float): Int { private fun linearToSrgb(value: Float): Int {