Mercurial > cgi-bin > hgweb.cgi > SimpleResizer
changeset 8:6ae738b8a814 memo
Memoize. Only modest improvement results.
author | David Barts <n5jrn@me.com> |
---|---|
date | Wed, 17 Feb 2021 07:43:50 -0800 |
parents | e8059b166de1 |
children | 5626557ac542 |
files | app/src/main/java/com/bartsent/simpleresizer/lib/LanczosKernel.kt |
diffstat | 1 files changed, 10 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/app/src/main/java/com/bartsent/simpleresizer/lib/LanczosKernel.kt Tue Feb 16 17:29:52 2021 -0800 +++ b/app/src/main/java/com/bartsent/simpleresizer/lib/LanczosKernel.kt Wed Feb 17 07:43:50 2021 -0800 @@ -6,12 +6,19 @@ object LanczosKernel: ScalingKernel { override val size = 3.0 + private val memory = HashMap<Double, Double>() + init { + memory.put(0.0, 1.0) + } private fun sinc(x: Double): Double { - if (x == 0.0) - return 1.0 + val remembered = memory.get(x) + if (remembered != null) + return remembered val pix = PI * x - return sin(pix) / pix + val calculated = sin(pix) / pix + memory.put(x, calculated) + return calculated } override fun weight(x: Double): Double =