ft2-clone

Fasttracker 2 clone
Log | Files | Refs | README | LICENSE

ft2_quadratic_spline.c (1041B)


      1 // 3-point quadratic spline interpolation LUT generator
      2 
      3 #include <stdint.h>
      4 #include <stdbool.h>
      5 #include <stdlib.h>
      6 #include "ft2_quadratic_spline.h"
      7 #include "../ft2_video.h" // showErrorMsgBox()
      8 
      9 float *fQuadraticSplineLUT = NULL; // globalized
     10 
     11 bool setupQuadraticSplineTable(void)
     12 {
     13 	fQuadraticSplineLUT = (float *)malloc(QUADRATIC_SPLINE_WIDTH * QUADRATIC_SPLINE_PHASES * sizeof (float));
     14 	if (fQuadraticSplineLUT == NULL)
     15 	{
     16 		showErrorMsgBox("Not enough memory!");
     17 		return false;
     18 	}
     19 
     20 	float *fPtr = fQuadraticSplineLUT;
     21 	for (int32_t i = 0; i < QUADRATIC_SPLINE_PHASES; i++)
     22 	{
     23 		const double x1 = i * (1.0 / QUADRATIC_SPLINE_PHASES);
     24 		const double x2 = x1 * x1; // x^2
     25 
     26 		double t1 = ( 0.5 * x2) + (-1.5 * x1) + 1.0;
     27 		double t2 = (-1.0 * x2) + ( 2.0 * x1);
     28 		double t3 = ( 0.5 * x2) + (-0.5 * x1);
     29 
     30 		*fPtr++ = (float)t1;
     31 		*fPtr++ = (float)t2;
     32 		*fPtr++ = (float)t3;
     33 	}
     34 
     35 	return true;
     36 }
     37 
     38 void freeQuadraticSplineTable(void)
     39 {
     40 	if (fQuadraticSplineLUT != NULL)
     41 	{
     42 		free(fQuadraticSplineLUT);
     43 		fQuadraticSplineLUT = NULL;
     44 	}
     45 }