1 /*
2     libfame - Fast Assembly MPEG Encoder Library
3     Copyright (C) 2000-2001 Vivien Chappelier
4 
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Library General Public
7     License as published by the Free Software Foundation; either
8     version 2 of the License, or (at your option) any later version.
9 
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Library General Public License for more details.
14 
15     You should have received a copy of the GNU Library General Public
16     License along with this library; if not, write to the Free
17     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /*************************** floating point DCT/iDCT *************************/
20 
21 #define IDCT1 1.414213562
22 #define IDCT2 2.613125930
23 #define IDCT3 1.082392200
24 #define IDCT4 0.765366865
25 
26 /*  idct_aan_row                                                             */
27 /*                                                                           */
28 /*  Description:                                                             */
29 /*    Perform the second step a 1-D AA&N iDCT on a row of a block            */
30 /*                                                                           */
31 /*  Arguments:                                                               */
32 /*    dct_t *block: a 8x8 block                                              */
33 /*    int row: which row to perform the 1-D iDCT on                          */
34 /*                                                                           */
35 /*  Return value:                                                            */
36 /*    None.                                                                  */
37 
idct_aan_row(dct_t * block,int row)38 static void inline idct_aan_row(dct_t * block, int row)
39 {
40    dct_t v0, v1, v2, v3, v4, v5, v6, v7;
41    dct_t v04,v05;
42    dct_t v11,v12,v13,v15;
43    dct_t v22,v23,v24,v25;
44    dct_t v31,v32,v35;
45    dct_t v44,v45;
46    dct_t v51,v53,v54,v55;
47    dct_t v62,v64,v65;
48    dct_t v71,v73,v74,v75;
49    dct_t va2, va3;
50 
51    v0 = block[row*8+0];
52    v1 = block[row*8+1];
53    v2 = block[row*8+2];
54    v3 = block[row*8+3];
55    v4 = block[row*8+4];
56    v5 = block[row*8+5];
57    v6 = block[row*8+6];
58    v7 = block[row*8+7];
59 
60    /* even part */
61    v22 = v2-v6;
62    v62 = v2+v6;
63    v23 = v22*IDCT1;
64    v04 = v0+v4;
65    v44 = v0-v4;
66    v24 = v23-v62;
67    v64 = v62;
68    v05 = v04+v64;
69    v45 = v44+v24;
70    v25 = v44-v24;
71    v65 = v04-v64;
72 
73    /* odd part */
74    v51 = v5-v3;
75    v11 = v1+v7;
76    v71 = v1-v7;
77    v31 = v5+v3;
78 
79    v12 = v11-v31;
80    v32 = v11+v31;
81    va2 = v51-v71;
82 
83    v53 = v51*IDCT2;
84    v13 = v12*IDCT1;
85    v73 = v71*IDCT3;
86    va3 = va2*IDCT4;
87 
88    v54 = va3-v53;
89    v74 = v73-va3;
90 
91    v35 = v32;
92    v75 = v74-v35;
93    v15 = v13-v75;
94    v55 = (v54+v15);
95 
96    /* output butterfly */
97    block[row*8+0] = v05+v35;
98    block[row*8+1] = v45+v75;
99    block[row*8+2] = v25+v15;
100    block[row*8+3] = v65-v55;
101    block[row*8+4] = v65+v55;
102    block[row*8+5] = v25-v15;
103    block[row*8+6] = v45-v75;
104    block[row*8+7] = v05-v35;
105 }
106 
107 /*  idct_aan_col                                                             */
108 /*                                                                           */
109 /*  Description:                                                             */
110 /*    Perform the second step a 1-D AA&N iDCT on a column of a block         */
111 /*                                                                           */
112 /*  Arguments:                                                               */
113 /*    dct_t *block: a 8x8 block                                              */
114 /*    int col: which column to perform the 1-D iDCT on                       */
115 /*                                                                           */
116 /*  Return value:                                                            */
117 /*    None.                                                                  */
118 
idct_aan_col(dct_t * block,int col)119 static void inline idct_aan_col(dct_t * block, int col)
120 {
121    dct_t v0, v1, v2, v3, v4, v5, v6, v7;
122    dct_t v04,v05;
123    dct_t v11,v12,v13,v15;
124    dct_t v22,v23,v24,v25;
125    dct_t v31,v32,v35;
126    dct_t v44,v45;
127    dct_t v51,v53,v54,v55;
128    dct_t v62,v64,v65;
129    dct_t v71,v73,v74,v75;
130    dct_t va2, va3;
131 
132    v0 = block[0*8+col];
133    v1 = block[1*8+col];
134    v2 = block[2*8+col];
135    v3 = block[3*8+col];
136    v4 = block[4*8+col];
137    v5 = block[5*8+col];
138    v6 = block[6*8+col];
139    v7 = block[7*8+col];
140 
141    /* even part */
142    v22 = v2-v6;
143    v62 = v2+v6;
144    v23 = v22*IDCT1;
145    v04 = v0+v4;
146    v44 = v0-v4;
147    v24 = v23-v62;
148    v64 = v62;
149    v05 = v04+v64;
150    v45 = v44+v24;
151    v25 = v44-v24;
152    v65 = v04-v64;
153 
154    /* odd part */
155    v51 = v5-v3;
156    v11 = v1+v7;
157    v71 = v1-v7;
158    v31 = v5+v3;
159 
160    v12 = v11-v31;
161    v32 = v11+v31;
162    va2 = v51-v71;
163 
164    v53 = v51*IDCT2;
165    v13 = v12*IDCT1;
166    v73 = v71*IDCT3;
167    va3 = va2*IDCT4;
168 
169    v54 = va3-v53;
170    v74 = v73-va3;
171 
172    v35 = v32;
173    v75 = v74-v35;
174    v15 = v13-v75;
175    v55 = (v54+v15);
176 
177    /* output butterfly */
178    block[0*8+col] = v05+v35;
179    block[1*8+col] = v45+v75;
180    block[2*8+col] = v25+v15;
181    block[3*8+col] = v65-v55;
182    block[4*8+col] = v65+v55;
183    block[5*8+col] = v25-v15;
184    block[6*8+col] = v45-v75;
185    block[7*8+col] = v05-v35;
186 }
187 
188 
189 /*  idct                                                                     */
190 /*                                                                           */
191 /*  Description:                                                             */
192 /*    Perform the second step of a 2-D AA&N iDCT on a 8x8 block              */
193 /*                                                                           */
194 /*  Arguments:                                                               */
195 /*    dct_t *block: a 8x8 block                                              */
196 /*                                                                           */
197 /*  Return value:                                                            */
198 /*    None.                                                                  */
idct(dct_t * block)199 static void inline idct(dct_t *block)
200 {
201    int i;
202 
203    /* TODO : clipping (-2048,2048) */
204    for(i = 0; i < 8; i++)
205      idct_aan_row(block, i);
206    for(i = 0; i < 8; i++)
207      idct_aan_col(block, i);
208 }
209