changeset 11:678adef4774f memo

Move more stuff into worker threads.
author David Barts <n5jrn@me.com>
date Wed, 17 Feb 2021 14:29:45 -0800
parents 5626557ac542
children b1605be35bcc
files app/src/main/java/com/bartsent/simpleresizer/EditImage.kt app/src/main/java/com/bartsent/simpleresizer/lib/LanczosKernel.kt
diffstat 2 files changed, 4 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/app/src/main/java/com/bartsent/simpleresizer/EditImage.kt	Wed Feb 17 13:39:50 2021 -0800
+++ b/app/src/main/java/com/bartsent/simpleresizer/EditImage.kt	Wed Feb 17 14:29:45 2021 -0800
@@ -142,8 +142,6 @@
         if (factor >= 1.0) {
             throw IllegalArgumentException("can only scale down")
         }
-        val newBitmap = Bitmap.createBitmap((oldBitmap.width * factor).roundToInt(), (oldBitmap.height * factor).roundToInt(), oldBitmap.config)
-        copyColorSpace(oldBitmap, newBitmap)
         binding.progressBar.visibility = ProgressBar.VISIBLE
         thread {
             val newBitmap = oldBitmap.getScaledInstance(
@@ -218,14 +216,14 @@
             throw IllegalArgumentException("$deg not a multiple of 90")
         }
         val (w, h) = if (deg % 180 == 0) Pair(oldBitmap.width, oldBitmap.height) else Pair(oldBitmap.height, oldBitmap.width)
-        val newBitmap = Bitmap.createBitmap(w, h, oldBitmap.config)
-        copyColorSpace(oldBitmap, newBitmap)
         val rotater = Matrix().apply {
             setRotate(deg.toFloat(), oldBitmap.width.toFloat()/2.0f, oldBitmap.height.toFloat()/2.0f)
             postTranslate((w - oldBitmap.width).toFloat()/2.0f, (h - oldBitmap.height).toFloat()/2.0f)
         }
         binding.progressBar.visibility = ProgressBar.VISIBLE
         thread {
+            val newBitmap = Bitmap.createBitmap(w, h, oldBitmap.config)
+            copyColorSpace(oldBitmap, newBitmap)
             Canvas(newBitmap).run {
                 drawBitmap(oldBitmap, rotater, null)
             }
--- a/app/src/main/java/com/bartsent/simpleresizer/lib/LanczosKernel.kt	Wed Feb 17 13:39:50 2021 -0800
+++ b/app/src/main/java/com/bartsent/simpleresizer/lib/LanczosKernel.kt	Wed Feb 17 14:29:45 2021 -0800
@@ -12,12 +12,12 @@
     }
 
     private fun sinc(x: Double): Double {
-        val remembered = memory.get(x)
+        val remembered = memory[x]
         if (remembered != null)
             return remembered
         val pix = PI * x
         val calculated = sin(pix) / pix
-        memory.put(x, calculated)
+        memory[x] = calculated
         return calculated
     }