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