Mercurial > cgi-bin > hgweb.cgi > SimpleResizer
view app/src/main/java/com/bartsent/simpleresizer/lib/LanczosKernel.kt @ 13:b1605be35bcc memo.oo
Dumping Bitmap yields 2x improvement!
author | David Barts <n5jrn@me.com> |
---|---|
date | Thu, 18 Feb 2021 14:15:26 -0800 |
parents | 678adef4774f |
children | 86740f593b6c |
line wrap: on
line source
package com.bartsent.simpleresizer.lib import kotlin.math.PI import kotlin.math.abs import kotlin.math.sin class 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 { val remembered = memory[x] if (remembered != null) return remembered val pix = PI * x val calculated = sin(pix) / pix memory[x] = calculated return calculated } override fun weight(x: Double): Double = if (abs(x) < size) sinc(x) * sinc(x/size) else 0.0 }