00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "dct32.h"
00023 #include "mathops.h"
00024
00025 #if DCT32_FLOAT
00026 # define dct32 ff_dct32_float
00027 # define FIXHR(x) ((float)(x))
00028 # define MULH3(x, y, s) ((s)*(y)*(x))
00029 # define INTFLOAT float
00030 #else
00031 # define dct32 ff_dct32_fixed
00032 # define FIXHR(a) ((int)((a) * (1LL<<32) + 0.5))
00033 # define MULH3(x, y, s) MULH((s)*(x), y)
00034 # define INTFLOAT int
00035 #endif
00036
00037
00038
00039
00040
00041
00042 #define COS0_0 FIXHR(0.50060299823519630134/2)
00043 #define COS0_1 FIXHR(0.50547095989754365998/2)
00044 #define COS0_2 FIXHR(0.51544730992262454697/2)
00045 #define COS0_3 FIXHR(0.53104259108978417447/2)
00046 #define COS0_4 FIXHR(0.55310389603444452782/2)
00047 #define COS0_5 FIXHR(0.58293496820613387367/2)
00048 #define COS0_6 FIXHR(0.62250412303566481615/2)
00049 #define COS0_7 FIXHR(0.67480834145500574602/2)
00050 #define COS0_8 FIXHR(0.74453627100229844977/2)
00051 #define COS0_9 FIXHR(0.83934964541552703873/2)
00052 #define COS0_10 FIXHR(0.97256823786196069369/2)
00053 #define COS0_11 FIXHR(1.16943993343288495515/4)
00054 #define COS0_12 FIXHR(1.48416461631416627724/4)
00055 #define COS0_13 FIXHR(2.05778100995341155085/8)
00056 #define COS0_14 FIXHR(3.40760841846871878570/8)
00057 #define COS0_15 FIXHR(10.19000812354805681150/32)
00058
00059 #define COS1_0 FIXHR(0.50241928618815570551/2)
00060 #define COS1_1 FIXHR(0.52249861493968888062/2)
00061 #define COS1_2 FIXHR(0.56694403481635770368/2)
00062 #define COS1_3 FIXHR(0.64682178335999012954/2)
00063 #define COS1_4 FIXHR(0.78815462345125022473/2)
00064 #define COS1_5 FIXHR(1.06067768599034747134/4)
00065 #define COS1_6 FIXHR(1.72244709823833392782/4)
00066 #define COS1_7 FIXHR(5.10114861868916385802/16)
00067
00068 #define COS2_0 FIXHR(0.50979557910415916894/2)
00069 #define COS2_1 FIXHR(0.60134488693504528054/2)
00070 #define COS2_2 FIXHR(0.89997622313641570463/2)
00071 #define COS2_3 FIXHR(2.56291544774150617881/8)
00072
00073 #define COS3_0 FIXHR(0.54119610014619698439/2)
00074 #define COS3_1 FIXHR(1.30656296487637652785/4)
00075
00076 #define COS4_0 FIXHR(0.70710678118654752439/2)
00077
00078
00079 #define BF(a, b, c, s)\
00080 {\
00081 tmp0 = val##a + val##b;\
00082 tmp1 = val##a - val##b;\
00083 val##a = tmp0;\
00084 val##b = MULH3(tmp1, c, 1<<(s));\
00085 }
00086
00087 #define BF0(a, b, c, s)\
00088 {\
00089 tmp0 = tab[a] + tab[b];\
00090 tmp1 = tab[a] - tab[b];\
00091 val##a = tmp0;\
00092 val##b = MULH3(tmp1, c, 1<<(s));\
00093 }
00094
00095 #define BF1(a, b, c, d)\
00096 {\
00097 BF(a, b, COS4_0, 1);\
00098 BF(c, d,-COS4_0, 1);\
00099 val##c += val##d;\
00100 }
00101
00102 #define BF2(a, b, c, d)\
00103 {\
00104 BF(a, b, COS4_0, 1);\
00105 BF(c, d,-COS4_0, 1);\
00106 val##c += val##d;\
00107 val##a += val##c;\
00108 val##c += val##b;\
00109 val##b += val##d;\
00110 }
00111
00112 #define ADD(a, b) val##a += val##b
00113
00114
00115 void dct32(INTFLOAT *out, const INTFLOAT *tab)
00116 {
00117 INTFLOAT tmp0, tmp1;
00118
00119 INTFLOAT val0 , val1 , val2 , val3 , val4 , val5 , val6 , val7 ,
00120 val8 , val9 , val10, val11, val12, val13, val14, val15,
00121 val16, val17, val18, val19, val20, val21, val22, val23,
00122 val24, val25, val26, val27, val28, val29, val30, val31;
00123
00124
00125 BF0( 0, 31, COS0_0 , 1);
00126 BF0(15, 16, COS0_15, 5);
00127
00128 BF( 0, 15, COS1_0 , 1);
00129 BF(16, 31,-COS1_0 , 1);
00130
00131 BF0( 7, 24, COS0_7 , 1);
00132 BF0( 8, 23, COS0_8 , 1);
00133
00134 BF( 7, 8, COS1_7 , 4);
00135 BF(23, 24,-COS1_7 , 4);
00136
00137 BF( 0, 7, COS2_0 , 1);
00138 BF( 8, 15,-COS2_0 , 1);
00139 BF(16, 23, COS2_0 , 1);
00140 BF(24, 31,-COS2_0 , 1);
00141
00142 BF0( 3, 28, COS0_3 , 1);
00143 BF0(12, 19, COS0_12, 2);
00144
00145 BF( 3, 12, COS1_3 , 1);
00146 BF(19, 28,-COS1_3 , 1);
00147
00148 BF0( 4, 27, COS0_4 , 1);
00149 BF0(11, 20, COS0_11, 2);
00150
00151 BF( 4, 11, COS1_4 , 1);
00152 BF(20, 27,-COS1_4 , 1);
00153
00154 BF( 3, 4, COS2_3 , 3);
00155 BF(11, 12,-COS2_3 , 3);
00156 BF(19, 20, COS2_3 , 3);
00157 BF(27, 28,-COS2_3 , 3);
00158
00159 BF( 0, 3, COS3_0 , 1);
00160 BF( 4, 7,-COS3_0 , 1);
00161 BF( 8, 11, COS3_0 , 1);
00162 BF(12, 15,-COS3_0 , 1);
00163 BF(16, 19, COS3_0 , 1);
00164 BF(20, 23,-COS3_0 , 1);
00165 BF(24, 27, COS3_0 , 1);
00166 BF(28, 31,-COS3_0 , 1);
00167
00168
00169
00170
00171 BF0( 1, 30, COS0_1 , 1);
00172 BF0(14, 17, COS0_14, 3);
00173
00174 BF( 1, 14, COS1_1 , 1);
00175 BF(17, 30,-COS1_1 , 1);
00176
00177 BF0( 6, 25, COS0_6 , 1);
00178 BF0( 9, 22, COS0_9 , 1);
00179
00180 BF( 6, 9, COS1_6 , 2);
00181 BF(22, 25,-COS1_6 , 2);
00182
00183 BF( 1, 6, COS2_1 , 1);
00184 BF( 9, 14,-COS2_1 , 1);
00185 BF(17, 22, COS2_1 , 1);
00186 BF(25, 30,-COS2_1 , 1);
00187
00188
00189 BF0( 2, 29, COS0_2 , 1);
00190 BF0(13, 18, COS0_13, 3);
00191
00192 BF( 2, 13, COS1_2 , 1);
00193 BF(18, 29,-COS1_2 , 1);
00194
00195 BF0( 5, 26, COS0_5 , 1);
00196 BF0(10, 21, COS0_10, 1);
00197
00198 BF( 5, 10, COS1_5 , 2);
00199 BF(21, 26,-COS1_5 , 2);
00200
00201 BF( 2, 5, COS2_2 , 1);
00202 BF(10, 13,-COS2_2 , 1);
00203 BF(18, 21, COS2_2 , 1);
00204 BF(26, 29,-COS2_2 , 1);
00205
00206 BF( 1, 2, COS3_1 , 2);
00207 BF( 5, 6,-COS3_1 , 2);
00208 BF( 9, 10, COS3_1 , 2);
00209 BF(13, 14,-COS3_1 , 2);
00210 BF(17, 18, COS3_1 , 2);
00211 BF(21, 22,-COS3_1 , 2);
00212 BF(25, 26, COS3_1 , 2);
00213 BF(29, 30,-COS3_1 , 2);
00214
00215
00216 BF1( 0, 1, 2, 3);
00217 BF2( 4, 5, 6, 7);
00218 BF1( 8, 9, 10, 11);
00219 BF2(12, 13, 14, 15);
00220 BF1(16, 17, 18, 19);
00221 BF2(20, 21, 22, 23);
00222 BF1(24, 25, 26, 27);
00223 BF2(28, 29, 30, 31);
00224
00225
00226
00227 ADD( 8, 12);
00228 ADD(12, 10);
00229 ADD(10, 14);
00230 ADD(14, 9);
00231 ADD( 9, 13);
00232 ADD(13, 11);
00233 ADD(11, 15);
00234
00235 out[ 0] = val0;
00236 out[16] = val1;
00237 out[ 8] = val2;
00238 out[24] = val3;
00239 out[ 4] = val4;
00240 out[20] = val5;
00241 out[12] = val6;
00242 out[28] = val7;
00243 out[ 2] = val8;
00244 out[18] = val9;
00245 out[10] = val10;
00246 out[26] = val11;
00247 out[ 6] = val12;
00248 out[22] = val13;
00249 out[14] = val14;
00250 out[30] = val15;
00251
00252 ADD(24, 28);
00253 ADD(28, 26);
00254 ADD(26, 30);
00255 ADD(30, 25);
00256 ADD(25, 29);
00257 ADD(29, 27);
00258 ADD(27, 31);
00259
00260 out[ 1] = val16 + val24;
00261 out[17] = val17 + val25;
00262 out[ 9] = val18 + val26;
00263 out[25] = val19 + val27;
00264 out[ 5] = val20 + val28;
00265 out[21] = val21 + val29;
00266 out[13] = val22 + val30;
00267 out[29] = val23 + val31;
00268 out[ 3] = val24 + val20;
00269 out[19] = val25 + val21;
00270 out[11] = val26 + val22;
00271 out[27] = val27 + val23;
00272 out[ 7] = val28 + val18;
00273 out[23] = val29 + val19;
00274 out[15] = val30 + val17;
00275 out[31] = val31;
00276 }