From 6cd81d4dd5032d046b007a9d7124cbb9c98549ff Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Sat, 26 Jul 2014 15:36:15 -0700 Subject: [PATCH] Put the polynomials in horner form to save a multiplication. --- stb_resample.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stb_resample.h b/stb_resample.h index b06c4a8..24e723a 100644 --- a/stb_resample.h +++ b/stb_resample.h @@ -254,9 +254,9 @@ static float stbr__filter_catmullrom(float x) float xx = x*x; if (x < 1.0f) - return 1.5f * (x * xx) - 2.5f * xx + 1; + return 1.5f * xx * (x - 1.66666666f) + 1; else if (x < 2.0f) - return -0.5f * (x * xx) + 2.5f * xx - 4 * x + 2; + return -0.5f * x * ((xx - 5 * x) + 8) + 2; return (0.0f); } @@ -268,9 +268,9 @@ static float stbr__filter_mitchell(float x) float xx = x*x; if (x < 1.0f) - return 1.1666666666666f * (x * xx) - 2 * xx + 0.8888888888f; + return 1.1666666666666f * xx * (x - 1.714285715f) + 0.8888888888f; else if (x < 2.0f) - return -0.3888888888f * (x * xx) + 2 * xx - 3.333333333f * x + 1.777777777777f; + return -0.3888888888f * x * ((xx - 5.14285714f * x) + 8.571428571f) + 1.777777777777f; return (0.0f); }