From 806abdbb1f31e2e119ef82883cd63c5cd9abc332 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 1 Mar 2015 16:19:57 +0100 Subject: [PATCH] Store only the right-hand side of the Lanczos table, saving a branch. --- interpolate.cpp | 6 +++--- interpolate.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/interpolate.cpp b/interpolate.cpp index cd250c1..78b2dae 100644 --- a/interpolate.cpp +++ b/interpolate.cpp @@ -1,11 +1,11 @@ #include "interpolate.h" -double lanczos_table[(LANCZOS_RADIUS * 2) * LANCZOS_RESOLUTION]; +double lanczos_table[LANCZOS_RADIUS * LANCZOS_RESOLUTION]; void make_lanczos_weight_table() { - for (int i = 0; i < (LANCZOS_RADIUS * 2) * LANCZOS_RESOLUTION; ++i) { - float x = double(i) / LANCZOS_RESOLUTION - LANCZOS_RADIUS; + for (int i = 0; i < LANCZOS_RADIUS * LANCZOS_RESOLUTION; ++i) { + float x = double(i) / LANCZOS_RESOLUTION; lanczos_table[i] = lanczos_weight(x); } } diff --git a/interpolate.h b/interpolate.h index 55bc61c..f9aeb11 100644 --- a/interpolate.h +++ b/interpolate.h @@ -26,13 +26,13 @@ inline double lanczos_weight(double x) return sinc(M_PI * x) * sinc(M_PI * x / LANCZOS_RADIUS); } -extern double lanczos_table[(LANCZOS_RADIUS * 2) * LANCZOS_RESOLUTION]; +extern double lanczos_table[LANCZOS_RADIUS * LANCZOS_RESOLUTION]; void make_lanczos_weight_table(); inline double lanczos_weight_table(double x) { - int table_id = lrintf((x + LANCZOS_RADIUS) * LANCZOS_RESOLUTION); - if (table_id < 0 || table_id >= (LANCZOS_RADIUS * 2) * LANCZOS_RESOLUTION) { + int table_id = lrintf(fabs(x) * LANCZOS_RESOLUTION); + if (table_id >= LANCZOS_RADIUS * LANCZOS_RESOLUTION) { return 0.0; } return lanczos_table[table_id]; -- 2.39.2