[svn] / branches / dev-api-4 / xvidcore / src / dct / simple_idct.c Repository:
ViewVC logotype

Annotation of /branches/dev-api-4/xvidcore/src/dct/simple_idct.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1161 - (view) (download)

1 : edgomez 1054 /*****************************************************************************
2 : edgomez 851 *
3 : edgomez 1054 * XVID MPEG-4 VIDEO CODEC
4 :     * - Inverse DCT (More precise version) -
5 : edgomez 851 *
6 : edgomez 1054 * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
7 : edgomez 851 *
8 : edgomez 1054 * Originally distributed under the GNU LGPL License (ffmpeg).
9 :     * It is licensed under the GNU GPL for the XviD tree.
10 : edgomez 851 *
11 : edgomez 1054 * This program is free software ; you can redistribute it and/or modify
12 :     * it under the terms of the GNU General Public License as published by
13 :     * the Free Software Foundation ; either version 2 of the License, or
14 :     * (at your option) any later version.
15 :     *
16 :     * This program is distributed in the hope that it will be useful,
17 :     * but WITHOUT ANY WARRANTY ; without even the implied warranty of
18 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 :     * GNU General Public License for more details.
20 :     *
21 :     * You should have received a copy of the GNU General Public License
22 :     * along with this program ; if not, write to the Free Software
23 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 :     *
25 : edgomez 1161 * $Id: simple_idct.c,v 1.2.2.4 2003-10-01 23:23:01 edgomez Exp $
26 : edgomez 1054 *
27 :     ****************************************************************************/
28 :    
29 : edgomez 851 /*
30 :     based upon some outcommented c code from mpeg2dec (idct_mmx.c
31 : edgomez 1161 written by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>)
32 : edgomez 851 */
33 : edgomez 1054
34 : edgomez 851 #include "../portab.h"
35 :     #include "idct.h"
36 :    
37 :     #if 0
38 :     #define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
39 :     #define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
40 :     #define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
41 :     #define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */
42 :     #define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
43 :     #define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
44 :     #define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
45 :     #define ROW_SHIFT 8
46 :     #define COL_SHIFT 17
47 :     #else
48 : edgomez 1053 #define W1 22725 /* cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 */
49 :     #define W2 21407 /* cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 */
50 :     #define W3 19266 /* cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 */
51 :     #define W4 16383 /* cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 */
52 :     #define W5 12873 /* cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 */
53 :     #define W6 8867 /* cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 */
54 :     #define W7 4520 /* cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 */
55 : edgomez 851 #define ROW_SHIFT 11
56 : edgomez 1053 #define COL_SHIFT 20 /* 6 */
57 : edgomez 851 #endif
58 :    
59 :     #if defined(ARCH_IS_PPC)
60 :    
61 :     /* signed 16x16 -> 32 multiply add accumulate */
62 :     #define MAC16(rt, ra, rb) \
63 :     asm ("maclhw %0, %2, %3" : "=r" (rt) : "0" (rt), "r" (ra), "r" (rb));
64 :    
65 :     /* signed 16x16 -> 32 multiply */
66 :     #define MUL16(rt, ra, rb) \
67 :     asm ("mullhw %0, %1, %2" : "=r" (rt) : "r" (ra), "r" (rb));
68 :    
69 :     #else
70 :    
71 :     /* signed 16x16 -> 32 multiply add accumulate */
72 :     #define MAC16(rt, ra, rb) rt += (ra) * (rb)
73 :    
74 :     /* signed 16x16 -> 32 multiply */
75 :     #define MUL16(rt, ra, rb) rt = (ra) * (rb)
76 :    
77 :     #endif
78 :    
79 :     static __inline void idctRowCondDC (int16_t * const row)
80 :     {
81 :     int a0, a1, a2, a3, b0, b1, b2, b3;
82 :     #ifdef FAST_64BIT
83 :     uint64_t temp;
84 :     #else
85 :     uint32_t temp;
86 :     #endif
87 :    
88 :     #ifdef FAST_64BIT
89 :     #ifdef ARCH_IS_BIG_ENDIAN
90 :     #define ROW0_MASK 0xffff000000000000LL
91 :     #else
92 :     #define ROW0_MASK 0xffffLL
93 :     #endif
94 : edgomez 1161 if ( ((((uint64_t *)row)[0] & ~ROW0_MASK) |
95 : edgomez 851 ((uint64_t *)row)[1]) == 0) {
96 :     temp = (row[0] << 3) & 0xffff;
97 :     temp += temp << 16;
98 :     temp += temp << 32;
99 :     ((uint64_t *)row)[0] = temp;
100 :     ((uint64_t *)row)[1] = temp;
101 :     return;
102 :     }
103 :     #else
104 :     if (!(((uint32_t*)row)[1] |
105 :     ((uint32_t*)row)[2] |
106 : edgomez 1161 ((uint32_t*)row)[3] |
107 : edgomez 851 row[1])) {
108 :     temp = (row[0] << 3) & 0xffff;
109 :     temp += temp << 16;
110 :     ((uint32_t*)row)[0]=((uint32_t*)row)[1] =
111 :     ((uint32_t*)row)[2]=((uint32_t*)row)[3] = temp;
112 :     return;
113 :     }
114 :     #endif
115 :    
116 :     a0 = (W4 * row[0]) + (1 << (ROW_SHIFT - 1));
117 :     a1 = a0;
118 :     a2 = a0;
119 :     a3 = a0;
120 :    
121 :     /* no need to optimize : gcc does it */
122 :     a0 += W2 * row[2];
123 :     a1 += W6 * row[2];
124 :     a2 -= W6 * row[2];
125 :     a3 -= W2 * row[2];
126 :    
127 :     MUL16(b0, W1, row[1]);
128 :     MAC16(b0, W3, row[3]);
129 :     MUL16(b1, W3, row[1]);
130 :     MAC16(b1, -W7, row[3]);
131 :     MUL16(b2, W5, row[1]);
132 :     MAC16(b2, -W1, row[3]);
133 :     MUL16(b3, W7, row[1]);
134 :     MAC16(b3, -W5, row[3]);
135 :    
136 :     #ifdef FAST_64BIT
137 :     temp = ((uint64_t*)row)[1];
138 :     #else
139 :     temp = ((uint32_t*)row)[2] | ((uint32_t*)row)[3];
140 :     #endif
141 :     if (temp != 0) {
142 :     a0 += W4*row[4] + W6*row[6];
143 :     a1 += - W4*row[4] - W2*row[6];
144 :     a2 += - W4*row[4] + W2*row[6];
145 :     a3 += W4*row[4] - W6*row[6];
146 :    
147 :     MAC16(b0, W5, row[5]);
148 :     MAC16(b0, W7, row[7]);
149 : edgomez 1161
150 : edgomez 851 MAC16(b1, -W1, row[5]);
151 :     MAC16(b1, -W5, row[7]);
152 : edgomez 1161
153 : edgomez 851 MAC16(b2, W7, row[5]);
154 :     MAC16(b2, W3, row[7]);
155 : edgomez 1161
156 : edgomez 851 MAC16(b3, W3, row[5]);
157 :     MAC16(b3, -W1, row[7]);
158 :     }
159 :    
160 :     row[0] = (a0 + b0) >> ROW_SHIFT;
161 :     row[7] = (a0 - b0) >> ROW_SHIFT;
162 :     row[1] = (a1 + b1) >> ROW_SHIFT;
163 :     row[6] = (a1 - b1) >> ROW_SHIFT;
164 :     row[2] = (a2 + b2) >> ROW_SHIFT;
165 :     row[5] = (a2 - b2) >> ROW_SHIFT;
166 :     row[3] = (a3 + b3) >> ROW_SHIFT;
167 :     row[4] = (a3 - b3) >> ROW_SHIFT;
168 :     }
169 :    
170 :    
171 :     static __inline void idctSparseCol (int16_t * const col)
172 :     {
173 :     int a0, a1, a2, a3, b0, b1, b2, b3;
174 :    
175 :     /* XXX: I did that only to give same values as previous code */
176 :     a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
177 :     a1 = a0;
178 :     a2 = a0;
179 :     a3 = a0;
180 :    
181 :     a0 += + W2*col[8*2];
182 :     a1 += + W6*col[8*2];
183 :     a2 += - W6*col[8*2];
184 :     a3 += - W2*col[8*2];
185 :    
186 :     MUL16(b0, W1, col[8*1]);
187 :     MUL16(b1, W3, col[8*1]);
188 :     MUL16(b2, W5, col[8*1]);
189 :     MUL16(b3, W7, col[8*1]);
190 :    
191 :     MAC16(b0, + W3, col[8*3]);
192 :     MAC16(b1, - W7, col[8*3]);
193 :     MAC16(b2, - W1, col[8*3]);
194 :     MAC16(b3, - W5, col[8*3]);
195 :    
196 :     if(col[8*4]){
197 :     a0 += + W4*col[8*4];
198 :     a1 += - W4*col[8*4];
199 :     a2 += - W4*col[8*4];
200 :     a3 += + W4*col[8*4];
201 :     }
202 :    
203 :     if (col[8*5]) {
204 :     MAC16(b0, + W5, col[8*5]);
205 :     MAC16(b1, - W1, col[8*5]);
206 :     MAC16(b2, + W7, col[8*5]);
207 :     MAC16(b3, + W3, col[8*5]);
208 :     }
209 :    
210 :     if(col[8*6]){
211 :     a0 += + W6*col[8*6];
212 :     a1 += - W2*col[8*6];
213 :     a2 += + W2*col[8*6];
214 :     a3 += - W6*col[8*6];
215 :     }
216 :    
217 :     if (col[8*7]) {
218 :     MAC16(b0, + W7, col[8*7]);
219 :     MAC16(b1, - W5, col[8*7]);
220 :     MAC16(b2, + W3, col[8*7]);
221 :     MAC16(b3, - W1, col[8*7]);
222 :     }
223 :    
224 :     col[0 ] = ((a0 + b0) >> COL_SHIFT);
225 :     col[8 ] = ((a1 + b1) >> COL_SHIFT);
226 :     col[16] = ((a2 + b2) >> COL_SHIFT);
227 :     col[24] = ((a3 + b3) >> COL_SHIFT);
228 :     col[32] = ((a3 - b3) >> COL_SHIFT);
229 :     col[40] = ((a2 - b2) >> COL_SHIFT);
230 :     col[48] = ((a1 - b1) >> COL_SHIFT);
231 :     col[56] = ((a0 - b0) >> COL_SHIFT);
232 :     }
233 :    
234 :     void simple_idct_c(int16_t * const block)
235 :     {
236 :     int i;
237 :     for(i=0; i<8; i++)
238 :     idctRowCondDC(block + i*8);
239 : edgomez 1161
240 : edgomez 851 for(i=0; i<8; i++)
241 :     idctSparseCol(block + i);
242 :     }

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4