00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00028 #include "dsputil.h"
00029 #include "faandct.h"
00030 #include "libavutil/internal.h"
00031 #include "libavutil/libm.h"
00032
00033 #define FLOAT float
00034
00035
00036
00037
00038
00039
00040
00041 #define B0 1.00000000000000000000
00042 #define B1 0.72095982200694791383 // (cos(pi*1/16)sqrt(2))^-1
00043 #define B2 0.76536686473017954350 // (cos(pi*2/16)sqrt(2))^-1
00044 #define B3 0.85043009476725644878 // (cos(pi*3/16)sqrt(2))^-1
00045 #define B4 1.00000000000000000000 // (cos(pi*4/16)sqrt(2))^-1
00046 #define B5 1.27275858057283393842 // (cos(pi*5/16)sqrt(2))^-1
00047 #define B6 1.84775906502257351242 // (cos(pi*6/16)sqrt(2))^-1
00048 #define B7 3.62450978541155137218 // (cos(pi*7/16)sqrt(2))^-1
00049
00050
00051 #define A1 0.70710678118654752438 // cos(pi*4/16)
00052 #define A2 0.54119610014619698435 // cos(pi*6/16)sqrt(2)
00053 #define A5 0.38268343236508977170 // cos(pi*6/16)
00054 #define A4 1.30656296487637652774 // cos(pi*2/16)sqrt(2)
00055
00056 static const FLOAT postscale[64]={
00057 B0*B0, B0*B1, B0*B2, B0*B3, B0*B4, B0*B5, B0*B6, B0*B7,
00058 B1*B0, B1*B1, B1*B2, B1*B3, B1*B4, B1*B5, B1*B6, B1*B7,
00059 B2*B0, B2*B1, B2*B2, B2*B3, B2*B4, B2*B5, B2*B6, B2*B7,
00060 B3*B0, B3*B1, B3*B2, B3*B3, B3*B4, B3*B5, B3*B6, B3*B7,
00061 B4*B0, B4*B1, B4*B2, B4*B3, B4*B4, B4*B5, B4*B6, B4*B7,
00062 B5*B0, B5*B1, B5*B2, B5*B3, B5*B4, B5*B5, B5*B6, B5*B7,
00063 B6*B0, B6*B1, B6*B2, B6*B3, B6*B4, B6*B5, B6*B6, B6*B7,
00064 B7*B0, B7*B1, B7*B2, B7*B3, B7*B4, B7*B5, B7*B6, B7*B7,
00065 };
00066
00067 static av_always_inline void row_fdct(FLOAT temp[64], DCTELEM * data)
00068 {
00069 FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
00070 FLOAT tmp10, tmp11, tmp12, tmp13;
00071 FLOAT z2, z4, z11, z13;
00072 FLOAT av_unused z5;
00073 int i;
00074
00075 for (i=0; i<8*8; i+=8) {
00076 tmp0= data[0 + i] + data[7 + i];
00077 tmp7= data[0 + i] - data[7 + i];
00078 tmp1= data[1 + i] + data[6 + i];
00079 tmp6= data[1 + i] - data[6 + i];
00080 tmp2= data[2 + i] + data[5 + i];
00081 tmp5= data[2 + i] - data[5 + i];
00082 tmp3= data[3 + i] + data[4 + i];
00083 tmp4= data[3 + i] - data[4 + i];
00084
00085 tmp10= tmp0 + tmp3;
00086 tmp13= tmp0 - tmp3;
00087 tmp11= tmp1 + tmp2;
00088 tmp12= tmp1 - tmp2;
00089
00090 temp[0 + i]= tmp10 + tmp11;
00091 temp[4 + i]= tmp10 - tmp11;
00092
00093 tmp12 += tmp13;
00094 tmp12 *= A1;
00095 temp[2 + i]= tmp13 + tmp12;
00096 temp[6 + i]= tmp13 - tmp12;
00097
00098 tmp4 += tmp5;
00099 tmp5 += tmp6;
00100 tmp6 += tmp7;
00101
00102 #if 0
00103 z5= (tmp4 - tmp6) * A5;
00104 z2= tmp4*A2 + z5;
00105 z4= tmp6*A4 + z5;
00106 #else
00107 z2= tmp4*(A2+A5) - tmp6*A5;
00108 z4= tmp6*(A4-A5) + tmp4*A5;
00109 #endif
00110 tmp5*=A1;
00111
00112 z11= tmp7 + tmp5;
00113 z13= tmp7 - tmp5;
00114
00115 temp[5 + i]= z13 + z2;
00116 temp[3 + i]= z13 - z2;
00117 temp[1 + i]= z11 + z4;
00118 temp[7 + i]= z11 - z4;
00119 }
00120 }
00121
00122 void ff_faandct(DCTELEM * data)
00123 {
00124 FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
00125 FLOAT tmp10, tmp11, tmp12, tmp13;
00126 FLOAT z2, z4, z11, z13;
00127 FLOAT av_unused z5;
00128 FLOAT temp[64];
00129 int i;
00130
00131 emms_c();
00132
00133 row_fdct(temp, data);
00134
00135 for (i=0; i<8; i++) {
00136 tmp0= temp[8*0 + i] + temp[8*7 + i];
00137 tmp7= temp[8*0 + i] - temp[8*7 + i];
00138 tmp1= temp[8*1 + i] + temp[8*6 + i];
00139 tmp6= temp[8*1 + i] - temp[8*6 + i];
00140 tmp2= temp[8*2 + i] + temp[8*5 + i];
00141 tmp5= temp[8*2 + i] - temp[8*5 + i];
00142 tmp3= temp[8*3 + i] + temp[8*4 + i];
00143 tmp4= temp[8*3 + i] - temp[8*4 + i];
00144
00145 tmp10= tmp0 + tmp3;
00146 tmp13= tmp0 - tmp3;
00147 tmp11= tmp1 + tmp2;
00148 tmp12= tmp1 - tmp2;
00149
00150 data[8*0 + i]= lrintf(postscale[8*0 + i] * (tmp10 + tmp11));
00151 data[8*4 + i]= lrintf(postscale[8*4 + i] * (tmp10 - tmp11));
00152
00153 tmp12 += tmp13;
00154 tmp12 *= A1;
00155 data[8*2 + i]= lrintf(postscale[8*2 + i] * (tmp13 + tmp12));
00156 data[8*6 + i]= lrintf(postscale[8*6 + i] * (tmp13 - tmp12));
00157
00158 tmp4 += tmp5;
00159 tmp5 += tmp6;
00160 tmp6 += tmp7;
00161
00162 #if 0
00163 z5= (tmp4 - tmp6) * A5;
00164 z2= tmp4*A2 + z5;
00165 z4= tmp6*A4 + z5;
00166 #else
00167 z2= tmp4*(A2+A5) - tmp6*A5;
00168 z4= tmp6*(A4-A5) + tmp4*A5;
00169 #endif
00170 tmp5*=A1;
00171
00172 z11= tmp7 + tmp5;
00173 z13= tmp7 - tmp5;
00174
00175 data[8*5 + i]= lrintf(postscale[8*5 + i] * (z13 + z2));
00176 data[8*3 + i]= lrintf(postscale[8*3 + i] * (z13 - z2));
00177 data[8*1 + i]= lrintf(postscale[8*1 + i] * (z11 + z4));
00178 data[8*7 + i]= lrintf(postscale[8*7 + i] * (z11 - z4));
00179 }
00180 }
00181
00182 void ff_faandct248(DCTELEM * data)
00183 {
00184 FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
00185 FLOAT tmp10, tmp11, tmp12, tmp13;
00186 FLOAT temp[64];
00187 int i;
00188
00189 emms_c();
00190
00191 row_fdct(temp, data);
00192
00193 for (i=0; i<8; i++) {
00194 tmp0 = temp[8*0 + i] + temp[8*1 + i];
00195 tmp1 = temp[8*2 + i] + temp[8*3 + i];
00196 tmp2 = temp[8*4 + i] + temp[8*5 + i];
00197 tmp3 = temp[8*6 + i] + temp[8*7 + i];
00198 tmp4 = temp[8*0 + i] - temp[8*1 + i];
00199 tmp5 = temp[8*2 + i] - temp[8*3 + i];
00200 tmp6 = temp[8*4 + i] - temp[8*5 + i];
00201 tmp7 = temp[8*6 + i] - temp[8*7 + i];
00202
00203 tmp10 = tmp0 + tmp3;
00204 tmp11 = tmp1 + tmp2;
00205 tmp12 = tmp1 - tmp2;
00206 tmp13 = tmp0 - tmp3;
00207
00208 data[8*0 + i] = lrintf(postscale[8*0 + i] * (tmp10 + tmp11));
00209 data[8*4 + i] = lrintf(postscale[8*4 + i] * (tmp10 - tmp11));
00210
00211 tmp12 += tmp13;
00212 tmp12 *= A1;
00213 data[8*2 + i] = lrintf(postscale[8*2 + i] * (tmp13 + tmp12));
00214 data[8*6 + i] = lrintf(postscale[8*6 + i] * (tmp13 - tmp12));
00215
00216 tmp10 = tmp4 + tmp7;
00217 tmp11 = tmp5 + tmp6;
00218 tmp12 = tmp5 - tmp6;
00219 tmp13 = tmp4 - tmp7;
00220
00221 data[8*1 + i] = lrintf(postscale[8*0 + i] * (tmp10 + tmp11));
00222 data[8*5 + i] = lrintf(postscale[8*4 + i] * (tmp10 - tmp11));
00223
00224 tmp12 += tmp13;
00225 tmp12 *= A1;
00226 data[8*3 + i] = lrintf(postscale[8*2 + i] * (tmp13 + tmp12));
00227 data[8*7 + i] = lrintf(postscale[8*6 + i] * (tmp13 - tmp12));
00228 }
00229 }