Mercurial > cgi-bin > hgweb.cgi > SimpleResizer
view app/src/main/java/com/bartsent/simpleresizer/lib/LanczosKernel.kt @ 46:8205f3c17500 default tip
Tweak messages a little.
author | David Barts <n5jrn@me.com> |
---|---|
date | Wed, 14 Apr 2021 08:18:23 -0700 |
parents | 6607f675a5f7 |
children |
line wrap: on
line source
package com.bartsent.simpleresizer.lib /* * Some code in this file has been adapted from: https://github.com/disintegration/imaging/ . */ 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>() private fun sinc(x: Double): Double { if (x == 0.0) return 1.0 val pix = PI * x return sin(pix) / pix } override fun weight(x: Double): Double { if (abs(x) >= size) return 0.0 val remembered = memory[x] if (remembered != null) return remembered val calculated = sinc(x) * sinc(x/size) memory[x] = calculated return calculated } }