fast DCT
// Run this once before running the fastDCT for the first time
// This function creates contants (M_PI means pi)
int initFastDCT(float* c) {
c[0] = cos(M_PI * 0.0625);
c[1] = cos(M_PI * 0.125);
c[2] = cos(M_PI * 0.1875);
c[3] = cos(M_PI * 0.25);
c[4] = cos(M_PI * 0.3125);
c[5] = cos(M_PI * 0.375);
c[6] = cos(M_PI * 0.4375);
// two consts as scalars
c[7] = sqrt(.125); // for k0
c[8] = sqrt(.25); // for the rest
c[9] = sqrt(.5); // for idct
return 1;
}
// n is input of 8 values (between -1 and + 1)
// o is out
// c are the constants created on the previous function
int fastDct(float* n,float* o,float* c) {
// the q's
float q1 = n[0]-n[7];
float q2 = n[1]-n[6];
float q3 = n[2]-n[5];
float q4 = n[3]-n[4];
float q5 = n[0]+n[7];
float q6 = n[1]+n[6];
float q7 = n[2]+n[5];
float q8 = n[3]+n[4];
float q9 = q5+q8;
float q10 = q6+q7;
float q11 = q5-q8;
float q12 = q6-q7;
o[0] = c[7]*(q9+q10);
o[1] = c[8]*(c[0]*q1+c[2]*q2+c[4]*q3+c[6]*q4);
o[2] = c[8]*(c[1]*q11+c[5]*q12);
o[3] = c[8]*(c[2]*q1-c[6]*q2-c[0]*q3-c[4]*q4);
o[4] = c[8]*c[3]*(q9-q10);
o[5] = c[8]*(c[4]*q1-c[0]*q2+c[6]*q3+c[2]*q4);
o[6] = c[8]*(c[5]*q11-c[1]*q12);
o[7] = c[8]*(c[6]*q1-c[4]*q2+c[2]*q3-c[0]*q4);
return 1;
}
Public Last updated: 2017-12-13 08:27:17 PM