ft2_cubic_spline.c (1922B)
1 // 4-point cubic Hermite spline (Catmull-Rom) interpolation LUT generator 2 3 #include <stdint.h> 4 #include <stdbool.h> 5 #include <stdlib.h> 6 #include "ft2_cubic_spline.h" 7 #include "../ft2_video.h" // showErrorMsgBox() 8 9 float *fCubicSplineLUT = NULL; // globalized 10 11 bool setupCubicSplineTable(void) 12 { 13 fCubicSplineLUT = (float *)malloc(CUBIC_SPLINE_WIDTH * CUBIC_SPLINE_PHASES * sizeof (float)); 14 if (fCubicSplineLUT == NULL) 15 { 16 showErrorMsgBox("Not enough memory!"); 17 return false; 18 } 19 20 float *fPtr = fCubicSplineLUT; 21 for (int32_t i = 0; i < CUBIC_SPLINE_PHASES; i++) 22 { 23 const double x1 = i * (1.0 / CUBIC_SPLINE_PHASES); 24 const double x2 = x1 * x1; // x^2 25 const double x3 = x2 * x1; // x^3 26 27 double t1 = (-0.5 * x3) + ( 1.0 * x2) + (-0.5 * x1); 28 double t2 = ( 1.5 * x3) + (-2.5 * x2) + 1.0; 29 double t3 = (-1.5 * x3) + ( 2.0 * x2) + ( 0.5 * x1); 30 double t4 = ( 0.5 * x3) + (-0.5 * x2); 31 32 *fPtr++ = (float)t1; 33 *fPtr++ = (float)t2; 34 *fPtr++ = (float)t3; 35 *fPtr++ = (float)t4; 36 } 37 38 /* 39 // 6-point Cubic Hermite (Catmull-Rom) 40 for (int32_t i = 0; i < CUBIC_SPLINE_PHASES; i++) 41 { 42 const double x1 = i * (1.0 / CUBIC_SPLINE_PHASES); 43 const double x2 = x1 * x1; // x^2 44 const double x3 = x2 * x1; // x^3 45 46 double t1 = ( (1.0/12.0) * x3) + (-(1.0/ 6.0) * x2) + ( (1.0/12.0) * x1); 47 double t2 = (-(7.0/12.0) * x3) + ( (5.0/ 4.0) * x2) + (-(2.0/ 3.0) * x1); 48 double t3 = ( (4.0/ 3.0) * x3) + (-(7.0/ 3.0) * x2) + 1.0; 49 double t4 = (-(4.0/ 3.0) * x3) + ( (5.0/ 3.0) * x2) + ( (2.0/ 3.0) * x1); 50 double t5 = ( (7.0/12.0) * x3) + (-(1.0/ 2.0) * x2) + (-(1.0/12.0) * x1); 51 double t6 = (-(1.0/12.0) * x3) + ( (1.0/12.0) * x2); 52 53 *fPtr++ = (float)t1; 54 *fPtr++ = (float)t2; 55 *fPtr++ = (float)t3; 56 *fPtr++ = (float)t4; 57 *fPtr++ = (float)t5; 58 *fPtr++ = (float)t6; 59 } 60 */ 61 62 return true; 63 } 64 65 void freeCubicSplineTable(void) 66 { 67 if (fCubicSplineLUT != NULL) 68 { 69 free(fCubicSplineLUT); 70 fCubicSplineLUT = NULL; 71 } 72 }