Mercurial > cgi-bin > hgweb.cgi > SimpleResizer
view app/src/main/java/com/bartsent/simpleresizer/lib/LanczosKernel.kt @ 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 | 6ae738b8a814 |
children | b1605be35bcc |
line wrap: on
line source
package com.bartsent.simpleresizer.lib import kotlin.math.PI import kotlin.math.abs import kotlin.math.sin 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 { 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 }