1 /*****************************************************************************
2 * idctclassic.c : Classic IDCT module
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id: idctclassic.c,v 1.26 2002/07/31 20:56:51 sam Exp $
7 * Authors: Gaƫl Hendryckx <jimmy@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
35 static int Open( vlc_object_t *p_this );
37 /*****************************************************************************
39 *****************************************************************************/
41 set_description( _("classic IDCT module") );
42 set_capability( "idct", 100 );
43 add_shortcut( "classic" );
44 set_callbacks( Open, NULL );
47 /*****************************************************************************
48 * NormScan : Unused in this IDCT
49 *****************************************************************************/
50 static void NormScan( u8 ppi_scan[2][64] )
54 /*****************************************************************************
55 * IDCT : IDCT function for normal matrices
56 *****************************************************************************/
57 static inline void IDCT( dctelem_t * p_block )
59 s32 tmp0, tmp1, tmp2, tmp3;
60 s32 tmp10, tmp11, tmp12, tmp13;
61 s32 z1, z2, z3, z4, z5;
66 /* Pass 1: process rows. */
67 /* Note results are scaled up by sqrt(8) compared to a true IDCT; */
68 /* furthermore, we scale the results by 2**PASS1_BITS. */
71 for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--)
73 /* Due to quantization, we will usually find that many of the input
74 * coefficients are zero, especially the AC terms. We can exploit this
75 * by short-circuiting the IDCT calculation for any row in which all
76 * the AC terms are zero. In that case each output is equal to the
77 * DC coefficient (with scale factor as needed).
78 * With typical images and quantization tables, half or more of the
79 * row DCT calculations can be simplified this way.
82 if ((dataptr[1] | dataptr[2] | dataptr[3] | dataptr[4] |
83 dataptr[5] | dataptr[6] | dataptr[7]) == 0)
85 /* AC terms all zero */
86 dctelem_t dcval = (dctelem_t) (dataptr[0] << PASS1_BITS);
97 dataptr += DCTSIZE; /* advance pointer to next row */
101 /* Even part: reverse the even part of the forward DCT. */
102 /* The rotator is sqrt(2)*c(-6). */
104 z2 = (s32) dataptr[2];
105 z3 = (s32) dataptr[6];
107 z1 = MULTIPLY(z2 + z3, FIX(0.541196100));
108 tmp2 = z1 + MULTIPLY(z3, - FIX(1.847759065));
109 tmp3 = z1 + MULTIPLY(z2, FIX(0.765366865));
111 tmp0 = ((s32) dataptr[0] + (s32) dataptr[4]) << CONST_BITS;
112 tmp1 = ((s32) dataptr[0] - (s32) dataptr[4]) << CONST_BITS;
119 /* Odd part per figure 8; the matrix is unitary and hence its
120 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
123 tmp0 = (s32) dataptr[7];
124 tmp1 = (s32) dataptr[5];
125 tmp2 = (s32) dataptr[3];
126 tmp3 = (s32) dataptr[1];
132 z5 = MULTIPLY(z3 + z4, FIX(1.175875602)); /* sqrt(2) * c3 */
134 tmp0 = MULTIPLY(tmp0, FIX(0.298631336)); /* sqrt(2) * (-c1+c3+c5-c7) */
135 tmp1 = MULTIPLY(tmp1, FIX(2.053119869)); /* sqrt(2) * ( c1+c3-c5+c7) */
136 tmp2 = MULTIPLY(tmp2, FIX(3.072711026)); /* sqrt(2) * ( c1+c3+c5-c7) */
137 tmp3 = MULTIPLY(tmp3, FIX(1.501321110)); /* sqrt(2) * ( c1+c3-c5-c7) */
138 z1 = MULTIPLY(z1, - FIX(0.899976223)); /* sqrt(2) * (c7-c3) */
139 z2 = MULTIPLY(z2, - FIX(2.562915447)); /* sqrt(2) * (-c1-c3) */
140 z3 = MULTIPLY(z3, - FIX(1.961570560)); /* sqrt(2) * (-c3-c5) */
141 z4 = MULTIPLY(z4, - FIX(0.390180644)); /* sqrt(2) * (c5-c3) */
151 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
153 dataptr[0] = (dctelem_t) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
154 dataptr[7] = (dctelem_t) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
155 dataptr[1] = (dctelem_t) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
156 dataptr[6] = (dctelem_t) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
157 dataptr[2] = (dctelem_t) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
158 dataptr[5] = (dctelem_t) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
159 dataptr[3] = (dctelem_t) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
160 dataptr[4] = (dctelem_t) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
162 dataptr += DCTSIZE; /* advance pointer to next row */
165 /* Pass 2: process columns. */
166 /* Note that we must descale the results by a factor of 8 == 2**3, */
167 /* and also undo the PASS1_BITS scaling. */
170 for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--)
172 /* Columns of zeroes can be exploited in the same way as we did with rows.
173 * However, the row calculation has created many nonzero AC terms, so the
174 * simplification applies less often (typically 5% to 10% of the time).
175 * On machines with very fast multiplication, it's possible that the
176 * test takes more time than it's worth. In that case this section
177 * may be commented out.
180 #ifndef NO_ZERO_COLUMN_TEST /* Adds a test but avoids calculus */
181 if ((dataptr[DCTSIZE*1] | dataptr[DCTSIZE*2] | dataptr[DCTSIZE*3] |
182 dataptr[DCTSIZE*4] | dataptr[DCTSIZE*5] | dataptr[DCTSIZE*6] |
183 dataptr[DCTSIZE*7]) == 0)
185 /* AC terms all zero */
186 dctelem_t dcval = (dctelem_t) DESCALE((s32) dataptr[0], PASS1_BITS+3);
188 dataptr[DCTSIZE*0] = dcval;
189 dataptr[DCTSIZE*1] = dcval;
190 dataptr[DCTSIZE*2] = dcval;
191 dataptr[DCTSIZE*3] = dcval;
192 dataptr[DCTSIZE*4] = dcval;
193 dataptr[DCTSIZE*5] = dcval;
194 dataptr[DCTSIZE*6] = dcval;
195 dataptr[DCTSIZE*7] = dcval;
197 dataptr++; /* advance pointer to next column */
202 /* Even part: reverse the even part of the forward DCT. */
203 /* The rotator is sqrt(2)*c(-6). */
205 z2 = (s32) dataptr[DCTSIZE*2];
206 z3 = (s32) dataptr[DCTSIZE*6];
208 z1 = MULTIPLY(z2 + z3, FIX(0.541196100));
209 tmp2 = z1 + MULTIPLY(z3, - FIX(1.847759065));
210 tmp3 = z1 + MULTIPLY(z2, FIX(0.765366865));
212 tmp0 = ((s32) dataptr[DCTSIZE*0] + (s32) dataptr[DCTSIZE*4]) << CONST_BITS;
213 tmp1 = ((s32) dataptr[DCTSIZE*0] - (s32) dataptr[DCTSIZE*4]) << CONST_BITS;
220 /* Odd part per figure 8; the matrix is unitary and hence its
221 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
224 tmp0 = (s32) dataptr[DCTSIZE*7];
225 tmp1 = (s32) dataptr[DCTSIZE*5];
226 tmp2 = (s32) dataptr[DCTSIZE*3];
227 tmp3 = (s32) dataptr[DCTSIZE*1];
233 z5 = MULTIPLY(z3 + z4, FIX(1.175875602)); /* sqrt(2) * c3 */
235 tmp0 = MULTIPLY(tmp0, FIX(0.298631336)); /* sqrt(2) * (-c1+c3+c5-c7) */
236 tmp1 = MULTIPLY(tmp1, FIX(2.053119869)); /* sqrt(2) * ( c1+c3-c5+c7) */
237 tmp2 = MULTIPLY(tmp2, FIX(3.072711026)); /* sqrt(2) * ( c1+c3+c5-c7) */
238 tmp3 = MULTIPLY(tmp3, FIX(1.501321110)); /* sqrt(2) * ( c1+c3-c5-c7) */
239 z1 = MULTIPLY(z1, - FIX(0.899976223)); /* sqrt(2) * (c7-c3) */
240 z2 = MULTIPLY(z2, - FIX(2.562915447)); /* sqrt(2) * (-c1-c3) */
241 z3 = MULTIPLY(z3, - FIX(1.961570560)); /* sqrt(2) * (-c3-c5) */
242 z4 = MULTIPLY(z4, - FIX(0.390180644)); /* sqrt(2) * (c5-c3) */
252 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
254 dataptr[DCTSIZE*0] = (dctelem_t) DESCALE(tmp10 + tmp3,
255 CONST_BITS+PASS1_BITS+3);
256 dataptr[DCTSIZE*7] = (dctelem_t) DESCALE(tmp10 - tmp3,
257 CONST_BITS+PASS1_BITS+3);
258 dataptr[DCTSIZE*1] = (dctelem_t) DESCALE(tmp11 + tmp2,
259 CONST_BITS+PASS1_BITS+3);
260 dataptr[DCTSIZE*6] = (dctelem_t) DESCALE(tmp11 - tmp2,
261 CONST_BITS+PASS1_BITS+3);
262 dataptr[DCTSIZE*2] = (dctelem_t) DESCALE(tmp12 + tmp1,
263 CONST_BITS+PASS1_BITS+3);
264 dataptr[DCTSIZE*5] = (dctelem_t) DESCALE(tmp12 - tmp1,
265 CONST_BITS+PASS1_BITS+3);
266 dataptr[DCTSIZE*3] = (dctelem_t) DESCALE(tmp13 + tmp0,
267 CONST_BITS+PASS1_BITS+3);
268 dataptr[DCTSIZE*4] = (dctelem_t) DESCALE(tmp13 - tmp0,
269 CONST_BITS+PASS1_BITS+3);
271 dataptr++; /* advance pointer to next column */
275 static inline void RestoreCPUState( )
280 #include "idct_sparse.h"
281 #include "idct_decl.h"