]> git.sesse.net Git - vlc/blob - plugins/idct/vdec_block_c.c
9bba8cf1e73949e1243a2e42fa703ae3655e78fc
[vlc] / plugins / idct / vdec_block_c.c
1 /*****************************************************************************
2  * vdec_block_c.c: Macroblock copy functions in C
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id: vdec_block_c.c,v 1.1 2001/05/06 04:32:02 sam Exp $
6  *
7  * Authors: Christophe Massiot <massiot@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 "config.h"
37 #include "common.h"
38 #include "threads.h"
39 #include "mtime.h"
40
41 #include "intf_msg.h"
42
43 #include "input_ext-dec.h"
44
45 #include "video.h"
46 #include "video_output.h"
47
48 #include "vdec_motion.h"
49 #include "video_decoder.h"
50
51 #include "vpar_blocks.h"
52
53 #include "vpar_headers.h"
54 #include "vpar_synchro.h"
55 #include "video_parser.h"
56 #include "video_fifo.h"
57
58 #include "vdec_block.h"
59
60 /*****************************************************************************
61  * Static variables
62  *****************************************************************************
63  * We can keep them static since they will always contain the same values.
64  *****************************************************************************/
65 static u8  pi_crop_buf[VDEC_CROPRANGE];
66 static u8 *pi_crop;
67
68 /*****************************************************************************
69  * vdec_Init: initialize video decoder thread
70  *****************************************************************************/
71 void _M( vdec_Init ) ( vdec_thread_t *p_vdec )
72 {
73     int i_dummy;
74
75     /* Init crop table */
76     pi_crop = pi_crop_buf + (VDEC_CROPRANGE >> 1);
77
78     for( i_dummy = -(VDEC_CROPRANGE >> 1); i_dummy < 0; i_dummy++ )
79     {
80         pi_crop[i_dummy] = 0;
81     }
82
83     for( ; i_dummy < 255; i_dummy ++ )
84     {
85         pi_crop[i_dummy] = i_dummy;
86     }
87
88     for( ; i_dummy < (VDEC_CROPRANGE >> 1) -1; i_dummy++ )
89     {
90         pi_crop[i_dummy] = 255;
91     }
92 }
93
94 /*****************************************************************************
95  * AddBlock : add a block
96  *****************************************************************************/
97 static __inline__ void AddBlock( vdec_thread_t * p_vdec, dctelem_t * p_block,
98                                  yuv_data_t * p_data, int i_incr )
99 {
100     int i_x, i_y;
101
102     for( i_y = 0; i_y < 8; i_y++ )
103     {
104         for( i_x = 0; i_x < 8; i_x++ )
105         {
106             *p_data = pi_crop[*p_data + *p_block++];
107             p_data++;
108         }
109         p_data += i_incr;
110     }
111 }
112
113 /*****************************************************************************
114  * CopyBlock : copy a block
115  *****************************************************************************/
116 static __inline__ void CopyBlock( vdec_thread_t * p_vdec, dctelem_t * p_block,
117                                   yuv_data_t * p_data, int i_incr )
118 {
119     int i_x, i_y;
120
121     for( i_y = 0; i_y < 8; i_y++ )
122     {
123         for( i_x = 0; i_x < 8; i_x++ )
124         {
125             *p_data++ = pi_crop[*p_block++];
126         }
127         p_data += i_incr;
128     }
129 }
130
131 void _M( vdec_DecodeMacroblockC ) ( vdec_thread_t *p_vdec, macroblock_t * p_mb )
132 {
133     if( !(p_mb->i_mb_type & MB_INTRA) )
134     {
135         /*
136          * Motion Compensation (ISO/IEC 13818-2 section 7.6)
137          */
138         if( p_mb->pf_motion == 0 )
139         {
140             intf_WarnMsg( 2, "pf_motion set to NULL" );
141         }
142         else
143         {
144             p_mb->pf_motion( p_mb );
145         }
146
147         DECODEBLOCKSC( AddBlock )
148     }
149     else
150     {
151         DECODEBLOCKSC( CopyBlock )
152     }
153
154     /*
155      * Decoding is finished, release the macroblock and free
156      * unneeded memory.
157      */
158     vpar_ReleaseMacroblock( &p_vdec->p_vpar->vfifo, p_mb );
159 }
160
161 void _M( vdec_DecodeMacroblockBW ) ( vdec_thread_t *p_vdec,
162                                      macroblock_t * p_mb )
163 {
164     if( !(p_mb->i_mb_type & MB_INTRA) )
165     {
166         /*
167          * Motion Compensation (ISO/IEC 13818-2 section 7.6)
168          */
169         if( p_mb->pf_motion == 0 )
170         {
171             intf_WarnMsg( 2, "pf_motion set to NULL" );
172         }
173         else
174         {
175             p_mb->pf_motion( p_mb );
176         }
177
178         DECODEBLOCKSBW( AddBlock )
179     }
180     else
181     {
182         DECODEBLOCKSBW( CopyBlock )
183     }
184
185     /*
186      * Decoding is finished, release the macroblock and free
187      * unneeded memory.
188      */
189     vpar_ReleaseMacroblock( &p_vdec->p_vpar->vfifo, p_mb );
190 }
191