]> git.sesse.net Git - vlc/blob - plugins/idct/vdec_idct.c
808ad851726f8e7add71935b810f2ac376ae57dc
[vlc] / plugins / idct / vdec_idct.c
1 /*****************************************************************************
2  * vdec_idct.c : common IDCT functions
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: vdec_idct.c,v 1.2 2001/07/17 09:48:07 massiot Exp $
6  *
7  * Authors: GaĆ«l Hendryckx <jimmy@via.ecp.fr>
8  *
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
24 /* MODULE_NAME defined in Makefile together with -DBUILTIN */
25 #ifdef BUILTIN
26 #   include "modules_inner.h"
27 #else
28 #   define _M( foo ) foo
29 #endif
30
31 /*****************************************************************************
32  * Preamble
33  *****************************************************************************/
34 #include "defs.h"
35
36 #include <string.h>                                    /* memcpy(), memset() */
37
38 #include "config.h"
39 #include "common.h"
40 #include "threads.h"
41 #include "mtime.h"
42
43 #include "video.h"
44 #include "video_output.h"
45
46 #include "modules.h"
47
48 #include "vdec_ext-plugins.h"
49 #include "vdec_idct.h"
50
51 /*****************************************************************************
52  * vdec_InitIDCT : initialize datas for vdec_SparseIDCT
53  *****************************************************************************/
54 void _M( vdec_InitIDCT ) ( vdec_thread_t * p_vdec )
55 {
56     int i;
57     dctelem_t * p_pre;
58
59     p_vdec->p_idct_data = malloc( sizeof(dctelem_t) * 64 * 64 );
60     p_pre = (dctelem_t *) p_vdec->p_idct_data;
61     memset( p_pre, 0, 64 * 64 * sizeof(dctelem_t) );
62
63     for( i=0 ; i < 64 ; i++ )
64     {
65         p_pre[i*64+i] = 1 << SPARSE_SCALE_FACTOR;
66         _M( vdec_IDCT )( p_vdec, &p_pre[i*64], 0) ;
67     }
68     return;
69 }
70
71 /*****************************************************************************
72  * vdec_SparseIDCT : IDCT function for sparse matrices
73  *****************************************************************************/
74 void _M( vdec_SparseIDCT ) ( void * p_idct_data,
75                              dctelem_t * p_block, int i_sparse_pos )
76 {
77     short int val;
78     int * dp;
79     int v;
80     short int * p_dest;
81     short int * p_source;
82     int coeff, rr;
83     dctelem_t * p_pre = (dctelem_t *) p_idct_data;
84
85     /* If DC Coefficient. */
86     if ( i_sparse_pos == 0 )
87     {
88         dp=(int *)p_block;
89         val=RIGHT_SHIFT((*p_block + 4), 3);
90         /* Compute int to assign.  This speeds things up a bit */
91         v = ((val & 0xffff) | (val << 16));
92         dp[0] = v;     dp[1] = v;     dp[2] = v;     dp[3] = v;
93         dp[4] = v;     dp[5] = v;     dp[6] = v;     dp[7] = v;
94         dp[8] = v;     dp[9] = v;     dp[10] = v;    dp[11] = v;
95         dp[12] = v;    dp[13] = v;    dp[14] = v;    dp[15] = v;
96         dp[16] = v;    dp[17] = v;    dp[18] = v;    dp[19] = v;
97         dp[20] = v;    dp[21] = v;    dp[22] = v;    dp[23] = v;
98         dp[24] = v;    dp[25] = v;    dp[26] = v;    dp[27] = v;
99         dp[28] = v;    dp[29] = v;    dp[30] = v;    dp[31] = v;
100         return;
101     }
102     /* Some other coefficient. */
103     p_dest = (s16*)p_block;
104     p_source = (s16*)&p_pre[i_sparse_pos * 64];
105     coeff = (int)p_dest[i_sparse_pos];
106     for( rr=0 ; rr < 4 ; rr++ )
107     {
108         p_dest[0] = (p_source[0] * coeff) >> SPARSE_SCALE_FACTOR;
109         p_dest[1] = (p_source[1] * coeff) >> SPARSE_SCALE_FACTOR;
110         p_dest[2] = (p_source[2] * coeff) >> SPARSE_SCALE_FACTOR;
111         p_dest[3] = (p_source[3] * coeff) >> SPARSE_SCALE_FACTOR;
112         p_dest[4] = (p_source[4] * coeff) >> SPARSE_SCALE_FACTOR;
113         p_dest[5] = (p_source[5] * coeff) >> SPARSE_SCALE_FACTOR;
114         p_dest[6] = (p_source[6] * coeff) >> SPARSE_SCALE_FACTOR;
115         p_dest[7] = (p_source[7] * coeff) >> SPARSE_SCALE_FACTOR;
116         p_dest[8] = (p_source[8] * coeff) >> SPARSE_SCALE_FACTOR;
117         p_dest[9] = (p_source[9] * coeff) >> SPARSE_SCALE_FACTOR;
118         p_dest[10] = (p_source[10] * coeff) >> SPARSE_SCALE_FACTOR;
119         p_dest[11] = (p_source[11] * coeff) >> SPARSE_SCALE_FACTOR;
120         p_dest[12] = (p_source[12] * coeff) >> SPARSE_SCALE_FACTOR;
121         p_dest[13] = (p_source[13] * coeff) >> SPARSE_SCALE_FACTOR;
122         p_dest[14] = (p_source[14] * coeff) >> SPARSE_SCALE_FACTOR;
123         p_dest[15] = (p_source[15] * coeff) >> SPARSE_SCALE_FACTOR;
124         p_dest += 16;
125         p_source += 16;
126     }
127     return;
128 }
129