new 3D interpolation codes

2 codes are there for future use, on my bench both are faster than used
now, about 146% faster on float and 160% on a clean code
This commit is contained in:
VitorBoss 2016-10-27 12:02:51 -02:00
parent 011d625bd4
commit af7bb6b261
1 changed files with 84 additions and 0 deletions

View File

@ -375,3 +375,87 @@ int get3DTableValue(struct table3D *fromTable, int Y, int X)
int r = (p * q) >> 8;
return ( (A * m) + (B * n) + (C * o) + (D * r) ) >> 8;
}
/* Executed a benchmark on all options and this is the results
* Stadard version:141164 20 float version:57456 20.51 simple version:54196 20, Number of loops:2500
*
//This function pulls a value from a 3D table given a target for X and Y coordinates.
//It performs a 2D linear interpolation as descibred in: http://www.megamanual.com/v22manual/ve_tuner.pdf
float get3DTableValue2(struct table3D *fromTable, int Y, int X)
{
float m, n, o ,p, q, r;
long tempVar1, tempVar2;
byte xMin, xMax;
byte yMin, yMax;
for (xMin = fromTable->xSize-1; xMin>=0; xMin--)
{
if(X>fromTable->axisX[xMin]) {break};
}
for (yMin = fromTable->ySize-1; yMin>=0; yMin--)
{
if(Y>fromTable->axisY[yMin]) {break};
}
if (xMin>fromTable->xSize-1) (xMin = fromTable->xSize-1}; //Overflow protection
if (yMin>fromTable->ySize-1) (yMin = fromTable->ySize-1}; //Overflow protection
xMax = xMin + 1;
yMax = yMin + 1;
if (xMax>fromTable->xSize-1) {xMax = fromTable->xSize-1}; //Overflow protection
if (yMax>fromTable->ySize-1) {yMax = fromTable->ySize-1}; //Overflow protection
p = float(X-fromTable->axisX[xMin]) / float(fromTable->axisX[xMax] - fromTable->axisX[xMin]);
q = float(Y-fromTable->axisY[yMin]) / float(fromTable->axisY[yMax] - fromTable->axisY[yMin]);
int A = fromTable->values[yMin][xMin];
int B = fromTable->values[yMin][xMax];
int C = fromTable->values[yMax][xMin];
int D = fromTable->values[yMax][xMax];
m = (1.0-p) * (1.0-q);
n = p * (1-q);
o = (1-p) * q;
r = p * q;
return ( (A * m) + (B * n) + (C * o) + (D * r) );
}
//This function pulls a value from a 3D table given a target for X and Y coordinates.
//It performs a 2D linear interpolation as descibred in: http://www.megamanual.com/v22manual/ve_tuner.pdf
int get3DTableValue3(struct table3D *fromTable, int Y, int X)
{
byte xMin, xMax;
byte yMin, yMax;
for (xMin = fromTable->xSize-1; xMin>=0; xMin--)
{
if(X>fromTable->axisX[xMin]) {break};
}
for (yMin = fromTable->ySize-1; yMin>=0; yMin--)
{
if(Y>fromTable->axisY[yMin]) {break};
}
if (xMin>fromTable->xSize-1) (xMin = fromTable->xSize-1}; //Overflow protection
if (yMin>fromTable->ySize-1) (yMin = fromTable->ySize-1}; //Overflow protection
xMax = xMin + 1;
yMax = yMin + 1;
if (xMax>fromTable->xSize-1) {xMax = fromTable->xSize-1}; //Overflow protection
if (yMax>fromTable->ySize-1) {yMax = fromTable->ySize-1}; //Overflow protection
long p, q;
p = ((long)(X-fromTable->axisX[xMin]) <<8) / (fromTable->axisX[xMax] - fromTable->axisX[xMin]);
q = 256 - (((long)(Y-fromTable->axisY[yMin])<<8) / (fromTable->axisY[yMax] - fromTable->axisY[yMin]));
int A = fromTable->values[yMin][xMin];
int B = fromTable->values[yMin][xMax];
int C = fromTable->values[yMax][xMin];
int D = fromTable->values[yMax][xMax];
int m = ((256-p) * (256-q)) >> 8;
int n = (p * (256-q)) >> 8;
int o = ((256-p) * q) >> 8;
int r = (p * q) >> 8;
return ( (A * m) + (B * n) + (C * o) + (D * r) ) >> 8;
}
*/