~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/codec/h263/fdct.c

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 
  2 /***********************************************************HeaderBegin*******
  3  *                                                                         
  4  * File:        fdct.c
  5  *
  6  * Author:      unknown
  7  *
  8  * Created:     unknown
  9  *                                                                         
 10  * Description: forward discrete cosine transform
 11  *
 12  ***********************************************************HeaderEnd*********/
 13 
 14 #include <string.h>
 15 #include "defs.h"
 16 
 17 
 18 /***********************************************************CommentBegin******
 19  ****************************************************************************
 20  *
 21  * -- FdctFast -- Fast DCT-Transform 
 22  *
 23  * Author :            Robert Danielsen
 24  *      
 25  * Purpose :           DCT-transform            
 26  *      
 27  * Arguments in :      int *block : pointer to an image block;
 28  *
 29  * Arguments in/out :  int *coeff : pointer to (to int) quantized coefficients.
 30  *                                  No zigzag-scan!
 31  *
 32  * Arguments out :     none
 33  *
 34  * Return values :     none
 35  *      
 36  * Side effects :      -
 37  *      
 38  * Description :       Performs fast DCT-transformation.
 39  *                     No zigzag-scan!
 40  *      
 41  * See also :          FdctRef, IdctRef, IdctFast
 42  *      
 43  * Modified :          23.09.96 Cor Quist: adapted to the MoMuSys VM
 44  *                     T.W., 11-Nov-96, adapted from Momusys VM
 45  *
 46  ****************************************************************************/
 47 void FdctFast(int *block, int *coeff)
 48 /***********************************************************CommentEnd********/
 49 {
 50   int   j1, i, j, k;
 51   float b[8];
 52   float b1[8];
 53   float d[8][8];
 54   float f0=(float).7071068;
 55   float f1=(float).4903926;
 56   float f2=(float).4619398;
 57   float f3=(float).4157348;
 58   float f4=(float).3535534;
 59   float f5=(float).2777851;
 60   float f6=(float).1913417;
 61   float f7=(float).0975452;
 62 
 63   for (i = 0, k = 0; i < 8; i++, k += 8) {
 64     for (j = 0; j < 8; j++) {
 65       b[j] = (float)block[k+j];
 66     }
 67     /* Horizontal transform */
 68     for (j = 0; j < 4; j++) {
 69       j1 = 7 - j;
 70       b1[j] = b[j] + b[j1];
 71       b1[j1] = b[j] - b[j1];
 72     }
 73     b[0] = b1[0] + b1[3];
 74     b[1] = b1[1] + b1[2];
 75     b[2] = b1[1] - b1[2];
 76     b[3] = b1[0] - b1[3];
 77     b[4] = b1[4];
 78     b[5] = (b1[6] - b1[5]) * f0;
 79     b[6] = (b1[6] + b1[5]) * f0;
 80     b[7] = b1[7];
 81     d[i][0] = (b[0] + b[1]) * f4;
 82     d[i][4] = (b[0] - b[1]) * f4;
 83     d[i][2] = b[2] * f6 + b[3] * f2;
 84     d[i][6] = b[3] * f6 - b[2] * f2;
 85     b1[4] = b[4] + b[5];
 86     b1[7] = b[7] + b[6];
 87     b1[5] = b[4] - b[5];
 88     b1[6] = b[7] - b[6];
 89     d[i][1] = b1[4] * f7 + b1[7] * f1;
 90     d[i][5] = b1[5] * f3 + b1[6] * f5;
 91     d[i][7] = b1[7] * f7 - b1[4] * f1;
 92     d[i][3] = b1[6] * f3 - b1[5] * f5;
 93   }
 94   /* Vertical transform */
 95   for (i = 0; i < 8; i++) {
 96     for (j = 0; j < 4; j++) {
 97       j1 = 7 - j;
 98       b1[j] = d[j][i] + d[j1][i];
 99       b1[j1] = d[j][i] - d[j1][i];
100     }
101     b[0] = b1[0] + b1[3];
102     b[1] = b1[1] + b1[2];
103     b[2] = b1[1] - b1[2];
104     b[3] = b1[0] - b1[3];
105     b[4] = b1[4];
106     b[5] = (b1[6] - b1[5]) * f0;
107     b[6] = (b1[6] + b1[5]) * f0;
108     b[7] = b1[7];
109     d[0][i] = (b[0] + b[1]) * f4;
110     coeff[0] = (int)d[0][i];
111     d[4][i] = (b[0] - b[1]) * f4;
112     coeff[4*8] = (int)d[4][i];
113     d[2][i] = b[2] * f6 + b[3] * f2;
114     coeff[2*8] = (int)d[2][i];
115     d[6][i] = b[3] * f6 - b[2] * f2;
116     coeff[6*8] = (int)d[6][i];
117     b1[4] = b[4] + b[5];
118     b1[7] = b[7] + b[6];
119     b1[5] = b[4] - b[5];
120     b1[6] = b[7] - b[6];
121     d[1][i] = b1[4] * f7 + b1[7] * f1;
122     coeff[1*8] = (int)d[1][i];
123     d[5][i] = b1[5] * f3 + b1[6] * f5;
124     coeff[5*8] = (int)d[5][i];
125     d[7][i] = b1[7] * f7 - b1[4] * f1;
126     coeff[7*8] = (int)d[7][i];
127     d[3][i] = b1[6] * f3 - b1[5] * f5;
128     coeff[3*8] = (int)d[3][i];
129     coeff++;
130   }
131 }
132 
133 
134 /***********************************************************CommentBegin******
135  ****************************************************************************
136  *
137  * -- FdctFast -- Fast DCT-Transform 
138  *
139  * Author :            Robert Danielsen
140  *      
141  * Purpose :           DCT-transform            
142  *      
143  * Arguments in :      Byte *block     pointer to an image block;
144  *                     int  w          picture width = skip between block lines
145  *
146  * Arguments in/out :  int *coeff : pointer to (to int) quantized coefficients.
147  *
148  * Arguments out :     none
149  *
150  * Return values :     none
151  *      
152  * Side effects :      -
153  *      
154  * Description :       Performs fast DCT-transformation
155  *                     No zigzag-scan!
156  *      
157  * See also :          FdctRef, IdctRef, IdctFast
158  *      
159  * Modified :          23.09.96 Cor Quist: adapted to the MoMuSys VM
160  *                     T.W., 11-Nov-96, adapted from Momusys VM
161  *
162  ****************************************************************************/
163 void FdctFastByte(Byte *block, int w, int *coeff)
164 /***********************************************************CommentEnd********/
165 {
166   int   j1, i, j, k;
167   float b[8];
168   float b1[8];
169   float d[8][8];
170   float f0=(float).7071068;
171   float f1=(float).4903926;
172   float f2=(float).4619398;
173   float f3=(float).4157348;
174   float f4=(float).3535534;
175   float f5=(float).2777851;
176   float f6=(float).1913417;
177   float f7=(float).0975452;
178 
179   for (i = 0, k = 0; i < 8; i++, k += w) {
180     for (j = 0; j < 8; j++) {
181       b[j] = (float)block[k+j];
182     }
183     /* Horizontal transform */
184     for (j = 0; j < 4; j++) {
185       j1 = 7 - j;
186       b1[j] = b[j] + b[j1];
187       b1[j1] = b[j] - b[j1];
188     }
189     b[0] = b1[0] + b1[3];
190     b[1] = b1[1] + b1[2];
191     b[2] = b1[1] - b1[2];
192     b[3] = b1[0] - b1[3];
193     b[4] = b1[4];
194     b[5] = (b1[6] - b1[5]) * f0;
195     b[6] = (b1[6] + b1[5]) * f0;
196     b[7] = b1[7];
197     d[i][0] = (b[0] + b[1]) * f4;
198     d[i][4] = (b[0] - b[1]) * f4;
199     d[i][2] = b[2] * f6 + b[3] * f2;
200     d[i][6] = b[3] * f6 - b[2] * f2;
201     b1[4] = b[4] + b[5];
202     b1[7] = b[7] + b[6];
203     b1[5] = b[4] - b[5];
204     b1[6] = b[7] - b[6];
205     d[i][1] = b1[4] * f7 + b1[7] * f1;
206     d[i][5] = b1[5] * f3 + b1[6] * f5;
207     d[i][7] = b1[7] * f7 - b1[4] * f1;
208     d[i][3] = b1[6] * f3 - b1[5] * f5;
209   }
210   /* Vertical transform */
211   for (i = 0; i < 8; i++) {
212     for (j = 0; j < 4; j++) {
213       j1 = 7 - j;
214       b1[j] = d[j][i] + d[j1][i];
215       b1[j1] = d[j][i] - d[j1][i];
216     }
217     b[0] = b1[0] + b1[3];
218     b[1] = b1[1] + b1[2];
219     b[2] = b1[1] - b1[2];
220     b[3] = b1[0] - b1[3];
221     b[4] = b1[4];
222     b[5] = (b1[6] - b1[5]) * f0;
223     b[6] = (b1[6] + b1[5]) * f0;
224     b[7] = b1[7];
225     d[0][i] = (b[0] + b[1]) * f4;
226     coeff[0] = (int)d[0][i];
227     d[4][i] = (b[0] - b[1]) * f4;
228     coeff[4*8] = (int)d[4][i];
229     d[2][i] = b[2] * f6 + b[3] * f2;
230     coeff[2*8] = (int)d[2][i];
231     d[6][i] = b[3] * f6 - b[2] * f2;
232     coeff[6*8] = (int)d[6][i];
233     b1[4] = b[4] + b[5];
234     b1[7] = b[7] + b[6];
235     b1[5] = b[4] - b[5];
236     b1[6] = b[7] - b[6];
237     d[1][i] = b1[4] * f7 + b1[7] * f1;
238     coeff[8] = (int)d[1][i];
239     d[5][i] = b1[5] * f3 + b1[6] * f5;
240     coeff[5*8] = (int)d[5][i];
241     d[7][i] = b1[7] * f7 - b1[4] * f1;
242     coeff[7*8] = (int)d[7][i];
243     d[3][i] = b1[6] * f3 - b1[5] * f5;
244     coeff[3*8] = (int)d[3][i];
245     coeff++;
246   }
247 }
248 
249 
250 /***********************************************************CommentBegin******
251  ****************************************************************************
252  *
253  * -- Fdct3coef --  Very fast DCT-Transform computing only the first 3 coeffs
254  *
255  * Author :            K.S.
256  *
257  * Purpose :           Extremly fast DCT-transform
258  *
259  * Arguments in :      int *block : pointer to an image block;
260  *
261  * Arguments in/out :  int *coeff : pointer to (to int) quantized coefficients.
262  *                                  No zigzag-scan!
263  *
264  * Arguments out :     none
265  *
266  * Return values :     none
267  *
268  * Side effects :      -
269  *
270  * Description :       Performs fast DCT-transformation.
271  *                     No zigzag-scan. Only the DC and the first hor. and vert.
272  *                     coefficients are computed by using only the border
273  *                     pels of the block. The other coefficients are set to
274  *                     zero.
275  *
276  * See also :          FdctVeryFast, FdctFast, FdctRef, IdctRef, IdctFast
277  *
278  * Modified :          
279  *
280  ****************************************************************************/
281 void Fdct3coef(int *block, int *coeff)
282 /***********************************************************CommentEnd********/
283 {
284   int xu, xd, xl, xr;
285 
286 
287   /* Sum over border pels */
288   xu = block[0] + block[1] + block[2] + block[3] +
289     block[4] + block[5] + block[6] + block[7];
290   xd = block[56] + block[57] + block[58] + block[59] +
291     block[60] + block[61] + block[62] + block[63];
292   xl = block[0] + block[8] + block[16] + block[24] +
293     block[32] + block[40] + block[48] + block[56];
294   xr = block[7] + block[15] + block[23] + block[31] +
295     block[39] + block[47] + block[55] + block[63];
296 
297   *coeff++ = (xu + xd + xl + xr) >> 2;   /* /4 */
298   *coeff++ = ((xl - xr) * 21) >> 6;      /* /64 */
299   /* Reset the remaining coefficients */
300   memset(coeff, 0, (64 - 2) * sizeof(int));
301   coeff += 6;
302   *coeff = ((xu - xd) * 21) >> 6;      /* /64 */
303 }
304 
305 
306 /***********************************************************CommentBegin******
307  ****************************************************************************
308  *
309  * -- Fdct3coefByte --  Very fast DCT computing only the first 3 coeffs 
310  *
311  * Author :            K.S.
312  *
313  * Purpose :           Extremly fast DCT-transform
314  *
315  * Arguments in :      Byte *block : pointer to an image block;
316  *                     int  w      : image width
317  *
318  * Arguments in/out :  int *coeff : pointer to (to Int) quantized coefficients
319  *                                  in zigzag-scan order.
320  *
321  * Arguments out :     none
322  *
323  * Return values :     none
324  *
325  * Side effects :      -
326  *
327  * Description :       Performs fast DCT-transformation orders the transform
328  *                     coefficients in zigzag-scan. Only the first three
329  *                     coefficients are computed by using only the border
330  *                     pels of the block. The other coefficients are set to
331  *                     zero.
332  *
333  * See also :          Fdct3coef, FdctFast, FdctRef, IdctRef, IdctFast
334  *
335  * Modified :          
336  *
337  ****************************************************************************/
338 void Fdct3coefByte(Byte *block, int w, int *coeff) 
339 /***********************************************************CommentEnd********/
340 {
341   int xu, xd, xl, xr;
342   Byte *b;
343 
344 
345   /* Sum over border pels */
346   xu = block[0] + block[1] + block[2] + block[3] +
347     block[4] + block[5] + block[6] + block[7];
348   b = block + 7;
349   xr = *b; b += w;
350   xr += *b; b += w;
351   xr += *b; b += w;
352   xr += *b; b += w;
353   xr += *b; b += w;
354   xr += *b; b += w;
355   xr += *b;
356   b = block;
357   xl = *b; b += w;
358   xl += *b; b += w;
359   xl += *b; b += w;
360   xl += *b; b += w;
361   xl += *b; b += w;
362   xl += *b; b += w;
363   xl += *b;
364   xd = b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6] + b[7];
365 
366   *coeff++ = (xu + xd + xl + xr) >> 2;   /* /4 */
367   *coeff++ = ((xl - xr) * 21) >> 6;      /* /64 */
368   /* Reset the remaining coefficients */
369   memset(coeff, 0, (64 - 2) * sizeof(int));
370   coeff += 6;
371   *coeff = ((xu - xd) * 21) >> 6;      /* /64 */
372 }
373 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.