00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "faanidct.h"
00022 #include "libavutil/common.h"
00023
00024
00025 #define FLOAT float
00026
00027 #define B0 1.0000000000000000000000
00028 #define B1 1.3870398453221474618216 // cos(pi*1/16)sqrt(2)
00029 #define B2 1.3065629648763765278566 // cos(pi*2/16)sqrt(2)
00030 #define B3 1.1758756024193587169745 // cos(pi*3/16)sqrt(2)
00031 #define B4 1.0000000000000000000000 // cos(pi*4/16)sqrt(2)
00032 #define B5 0.7856949583871021812779 // cos(pi*5/16)sqrt(2)
00033 #define B6 0.5411961001461969843997 // cos(pi*6/16)sqrt(2)
00034 #define B7 0.2758993792829430123360 // cos(pi*7/16)sqrt(2)
00035
00036 #define A4 0.70710678118654752438 // cos(pi*4/16)
00037 #define A2 0.92387953251128675613 // cos(pi*2/16)
00038
00039 static const FLOAT prescale[64]={
00040 B0*B0/8, B0*B1/8, B0*B2/8, B0*B3/8, B0*B4/8, B0*B5/8, B0*B6/8, B0*B7/8,
00041 B1*B0/8, B1*B1/8, B1*B2/8, B1*B3/8, B1*B4/8, B1*B5/8, B1*B6/8, B1*B7/8,
00042 B2*B0/8, B2*B1/8, B2*B2/8, B2*B3/8, B2*B4/8, B2*B5/8, B2*B6/8, B2*B7/8,
00043 B3*B0/8, B3*B1/8, B3*B2/8, B3*B3/8, B3*B4/8, B3*B5/8, B3*B6/8, B3*B7/8,
00044 B4*B0/8, B4*B1/8, B4*B2/8, B4*B3/8, B4*B4/8, B4*B5/8, B4*B6/8, B4*B7/8,
00045 B5*B0/8, B5*B1/8, B5*B2/8, B5*B3/8, B5*B4/8, B5*B5/8, B5*B6/8, B5*B7/8,
00046 B6*B0/8, B6*B1/8, B6*B2/8, B6*B3/8, B6*B4/8, B6*B5/8, B6*B6/8, B6*B7/8,
00047 B7*B0/8, B7*B1/8, B7*B2/8, B7*B3/8, B7*B4/8, B7*B5/8, B7*B6/8, B7*B7/8,
00048 };
00049
00050 static inline void p8idct(DCTELEM data[64], FLOAT temp[64], uint8_t *dest, int stride, int x, int y, int type){
00051 int i;
00052 FLOAT av_unused tmp0;
00053 FLOAT s04, d04, s17, d17, s26, d26, s53, d53;
00054 FLOAT os07, os16, os25, os34;
00055 FLOAT od07, od16, od25, od34;
00056
00057 for(i=0; i<y*8; i+=y){
00058 s17= temp[1*x + i] + temp[7*x + i];
00059 d17= temp[1*x + i] - temp[7*x + i];
00060 s53= temp[5*x + i] + temp[3*x + i];
00061 d53= temp[5*x + i] - temp[3*x + i];
00062
00063 od07= s17 + s53;
00064 od25= (s17 - s53)*(2*A4);
00065
00066 #if 0 //these 2 are equivalent
00067 tmp0= (d17 + d53)*(2*A2);
00068 od34= d17*( 2*B6) - tmp0;
00069 od16= d53*(-2*B2) + tmp0;
00070 #else
00071 od34= d17*(2*(B6-A2)) - d53*(2*A2);
00072 od16= d53*(2*(A2-B2)) + d17*(2*A2);
00073 #endif
00074
00075 od16 -= od07;
00076 od25 -= od16;
00077 od34 += od25;
00078
00079 s26 = temp[2*x + i] + temp[6*x + i];
00080 d26 = temp[2*x + i] - temp[6*x + i];
00081 d26*= 2*A4;
00082 d26-= s26;
00083
00084 s04= temp[0*x + i] + temp[4*x + i];
00085 d04= temp[0*x + i] - temp[4*x + i];
00086
00087 os07= s04 + s26;
00088 os34= s04 - s26;
00089 os16= d04 + d26;
00090 os25= d04 - d26;
00091
00092 if(type==0){
00093 temp[0*x + i]= os07 + od07;
00094 temp[7*x + i]= os07 - od07;
00095 temp[1*x + i]= os16 + od16;
00096 temp[6*x + i]= os16 - od16;
00097 temp[2*x + i]= os25 + od25;
00098 temp[5*x + i]= os25 - od25;
00099 temp[3*x + i]= os34 - od34;
00100 temp[4*x + i]= os34 + od34;
00101 }else if(type==1){
00102 data[0*x + i]= lrintf(os07 + od07);
00103 data[7*x + i]= lrintf(os07 - od07);
00104 data[1*x + i]= lrintf(os16 + od16);
00105 data[6*x + i]= lrintf(os16 - od16);
00106 data[2*x + i]= lrintf(os25 + od25);
00107 data[5*x + i]= lrintf(os25 - od25);
00108 data[3*x + i]= lrintf(os34 - od34);
00109 data[4*x + i]= lrintf(os34 + od34);
00110 }else if(type==2){
00111 dest[0*stride + i]= av_clip_uint8(((int)dest[0*stride + i]) + lrintf(os07 + od07));
00112 dest[7*stride + i]= av_clip_uint8(((int)dest[7*stride + i]) + lrintf(os07 - od07));
00113 dest[1*stride + i]= av_clip_uint8(((int)dest[1*stride + i]) + lrintf(os16 + od16));
00114 dest[6*stride + i]= av_clip_uint8(((int)dest[6*stride + i]) + lrintf(os16 - od16));
00115 dest[2*stride + i]= av_clip_uint8(((int)dest[2*stride + i]) + lrintf(os25 + od25));
00116 dest[5*stride + i]= av_clip_uint8(((int)dest[5*stride + i]) + lrintf(os25 - od25));
00117 dest[3*stride + i]= av_clip_uint8(((int)dest[3*stride + i]) + lrintf(os34 - od34));
00118 dest[4*stride + i]= av_clip_uint8(((int)dest[4*stride + i]) + lrintf(os34 + od34));
00119 }else{
00120 dest[0*stride + i]= av_clip_uint8(lrintf(os07 + od07));
00121 dest[7*stride + i]= av_clip_uint8(lrintf(os07 - od07));
00122 dest[1*stride + i]= av_clip_uint8(lrintf(os16 + od16));
00123 dest[6*stride + i]= av_clip_uint8(lrintf(os16 - od16));
00124 dest[2*stride + i]= av_clip_uint8(lrintf(os25 + od25));
00125 dest[5*stride + i]= av_clip_uint8(lrintf(os25 - od25));
00126 dest[3*stride + i]= av_clip_uint8(lrintf(os34 - od34));
00127 dest[4*stride + i]= av_clip_uint8(lrintf(os34 + od34));
00128 }
00129 }
00130 }
00131
00132 void ff_faanidct(DCTELEM block[64]){
00133 FLOAT temp[64];
00134 int i;
00135
00136 emms_c();
00137
00138 for(i=0; i<64; i++)
00139 temp[i] = block[i] * prescale[i];
00140
00141 p8idct(block, temp, NULL, 0, 1, 8, 0);
00142 p8idct(block, temp, NULL, 0, 8, 1, 1);
00143 }
00144
00145 void ff_faanidct_add(uint8_t *dest, int line_size, DCTELEM block[64]){
00146 FLOAT temp[64];
00147 int i;
00148
00149 emms_c();
00150
00151 for(i=0; i<64; i++)
00152 temp[i] = block[i] * prescale[i];
00153
00154 p8idct(block, temp, NULL, 0, 1, 8, 0);
00155 p8idct(NULL , temp, dest, line_size, 8, 1, 2);
00156 }
00157
00158 void ff_faanidct_put(uint8_t *dest, int line_size, DCTELEM block[64]){
00159 FLOAT temp[64];
00160 int i;
00161
00162 emms_c();
00163
00164 for(i=0; i<64; i++)
00165 temp[i] = block[i] * prescale[i];
00166
00167 p8idct(block, temp, NULL, 0, 1, 8, 0);
00168 p8idct(NULL , temp, dest, line_size, 8, 1, 3);
00169 }