00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "config.h"
00030
00031 #define W1 2841
00032 #define W2 2676
00033 #define W3 2408
00034 #define W5 1609
00035 #define W6 1108
00036 #define W7 565
00037
00038
00039 void init_idct _ANSI_ARGS_((void));
00040 void idct _ANSI_ARGS_((short *block));
00041
00042
00043 static short iclip[1024];
00044 static short *iclp;
00045
00046
00047 static void idctrow _ANSI_ARGS_((short *blk));
00048 static void idctcol _ANSI_ARGS_((short *blk));
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 static void idctrow(blk)
00061 short *blk;
00062 {
00063 int x0, x1, x2, x3, x4, x5, x6, x7, x8;
00064
00065
00066 if (!((x1 = blk[4]<<11) | (x2 = blk[6]) | (x3 = blk[2]) |
00067 (x4 = blk[1]) | (x5 = blk[7]) | (x6 = blk[5]) | (x7 = blk[3])))
00068 {
00069 blk[0]=blk[1]=blk[2]=blk[3]=blk[4]=blk[5]=blk[6]=blk[7]=blk[0]<<3;
00070 return;
00071 }
00072
00073 x0 = (blk[0]<<11) + 128;
00074
00075
00076 x8 = W7*(x4+x5);
00077 x4 = x8 + (W1-W7)*x4;
00078 x5 = x8 - (W1+W7)*x5;
00079 x8 = W3*(x6+x7);
00080 x6 = x8 - (W3-W5)*x6;
00081 x7 = x8 - (W3+W5)*x7;
00082
00083
00084 x8 = x0 + x1;
00085 x0 -= x1;
00086 x1 = W6*(x3+x2);
00087 x2 = x1 - (W2+W6)*x2;
00088 x3 = x1 + (W2-W6)*x3;
00089 x1 = x4 + x6;
00090 x4 -= x6;
00091 x6 = x5 + x7;
00092 x5 -= x7;
00093
00094
00095 x7 = x8 + x3;
00096 x8 -= x3;
00097 x3 = x0 + x2;
00098 x0 -= x2;
00099 x2 = (181*(x4+x5)+128)>>8;
00100 x4 = (181*(x4-x5)+128)>>8;
00101
00102
00103 blk[0] = (x7+x1)>>8;
00104 blk[1] = (x3+x2)>>8;
00105 blk[2] = (x0+x4)>>8;
00106 blk[3] = (x8+x6)>>8;
00107 blk[4] = (x8-x6)>>8;
00108 blk[5] = (x0-x4)>>8;
00109 blk[6] = (x3-x2)>>8;
00110 blk[7] = (x7-x1)>>8;
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 static void idctcol(blk)
00123 short *blk;
00124 {
00125 int x0, x1, x2, x3, x4, x5, x6, x7, x8;
00126
00127
00128 if (!((x1 = (blk[8*4]<<8)) | (x2 = blk[8*6]) | (x3 = blk[8*2]) |
00129 (x4 = blk[8*1]) | (x5 = blk[8*7]) | (x6 = blk[8*5]) | (x7 = blk[8*3])))
00130 {
00131 blk[8*0]=blk[8*1]=blk[8*2]=blk[8*3]=blk[8*4]=blk[8*5]=blk[8*6]=blk[8*7]=
00132 iclp[(blk[8*0]+32)>>6];
00133 return;
00134 }
00135
00136 x0 = (blk[8*0]<<8) + 8192;
00137
00138
00139 x8 = W7*(x4+x5) + 4;
00140 x4 = (x8+(W1-W7)*x4)>>3;
00141 x5 = (x8-(W1+W7)*x5)>>3;
00142 x8 = W3*(x6+x7) + 4;
00143 x6 = (x8-(W3-W5)*x6)>>3;
00144 x7 = (x8-(W3+W5)*x7)>>3;
00145
00146
00147 x8 = x0 + x1;
00148 x0 -= x1;
00149 x1 = W6*(x3+x2) + 4;
00150 x2 = (x1-(W2+W6)*x2)>>3;
00151 x3 = (x1+(W2-W6)*x3)>>3;
00152 x1 = x4 + x6;
00153 x4 -= x6;
00154 x6 = x5 + x7;
00155 x5 -= x7;
00156
00157
00158 x7 = x8 + x3;
00159 x8 -= x3;
00160 x3 = x0 + x2;
00161 x0 -= x2;
00162 x2 = (181*(x4+x5)+128)>>8;
00163 x4 = (181*(x4-x5)+128)>>8;
00164
00165
00166 blk[8*0] = iclp[(x7+x1)>>14];
00167 blk[8*1] = iclp[(x3+x2)>>14];
00168 blk[8*2] = iclp[(x0+x4)>>14];
00169 blk[8*3] = iclp[(x8+x6)>>14];
00170 blk[8*4] = iclp[(x8-x6)>>14];
00171 blk[8*5] = iclp[(x0-x4)>>14];
00172 blk[8*6] = iclp[(x3-x2)>>14];
00173 blk[8*7] = iclp[(x7-x1)>>14];
00174 }
00175
00176
00177 void idct(block)
00178 short *block;
00179 {
00180 int i;
00181
00182 for (i=0; i<8; i++)
00183 idctrow(block+8*i);
00184
00185 for (i=0; i<8; i++)
00186 idctcol(block+i);
00187 }
00188
00189 void init_idct()
00190 {
00191 int i;
00192
00193 iclp = iclip+512;
00194 for (i= -512; i<512; i++)
00195 iclp[i] = (i<-256) ? -256 : ((i>255) ? 255 : i);
00196 }