diff app/src/main/java/com/bartsent/simpleresizer/lib/LanczosKernel.kt @ 6:e8059b166de1

Lanczos works, but is painfully slow.
author David Barts <n5jrn@me.com>
date Tue, 16 Feb 2021 17:29:52 -0800
parents
children 6ae738b8a814
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/src/main/java/com/bartsent/simpleresizer/lib/LanczosKernel.kt	Tue Feb 16 17:29:52 2021 -0800
@@ -0,0 +1,19 @@
+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 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) sinc(x) * sinc(x/size) else 0.0
+}
\ No newline at end of file