]> git.sesse.net Git - vlc/blob - plugins/idct/vdec_block_c.c
20ab131f7dfc56d905137f3e8fbe898f709b1f76
[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.5 2001/07/17 09:48:07 massiot 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 <string.h>
37
38 #include "config.h"
39 #include "common.h"
40 #include "threads.h"
41 #include "mtime.h"
42
43 #include "intf_msg.h"
44
45 #include "input_ext-dec.h"
46
47 #include "video.h"
48 #include "video_output.h"
49
50 #include "vdec_ext-plugins.h"
51
52 #include "vdec_block.h"
53
54 #include "modules.h"
55 #include "modules_export.h"
56
57 /*****************************************************************************
58  * Static variables
59  *****************************************************************************
60  * We can keep them static since they will always contain the same values.
61  *****************************************************************************/
62 static u8  pi_crop_buf[VDEC_CROPRANGE];
63 static u8 *pi_crop;
64
65 /*****************************************************************************
66  * vdec_InitDecode: initialize video decoder thread
67  *****************************************************************************/
68 void _M( vdec_InitDecode ) ( vdec_thread_t *p_vdec )
69 {
70     int i_dummy;
71
72     /* Init crop table */
73     pi_crop = pi_crop_buf + (VDEC_CROPRANGE >> 1);
74
75     for( i_dummy = -(VDEC_CROPRANGE >> 1); i_dummy < 0; i_dummy++ )
76     {
77         pi_crop[i_dummy] = 0;
78     }
79
80     for( ; i_dummy < 255; i_dummy ++ )
81     {
82         pi_crop[i_dummy] = i_dummy;
83     }
84
85     for( ; i_dummy < (VDEC_CROPRANGE >> 1) -1; i_dummy++ )
86     {
87         pi_crop[i_dummy] = 255;
88     }
89 }
90
91 /*****************************************************************************
92  * AddBlock : add a block
93  *****************************************************************************/
94 static __inline__ void AddBlock( vdec_thread_t * p_vdec, dctelem_t * p_block,
95                                  yuv_data_t * p_data, int i_incr )
96 {
97     int i_x, i_y;
98
99     for( i_y = 0; i_y < 8; i_y++ )
100     {
101         for( i_x = 0; i_x < 8; i_x++ )
102         {
103             *p_data = pi_crop[*p_data + *p_block++];
104             p_data++;
105         }
106         p_data += i_incr;
107     }
108 }
109
110 /*****************************************************************************
111  * CopyBlock : copy a block
112  *****************************************************************************/
113 static __inline__ void CopyBlock( vdec_thread_t * p_vdec, dctelem_t * p_block,
114                                   yuv_data_t * p_data, int i_incr )
115 {
116     int i_x, i_y;
117
118     for( i_y = 0; i_y < 8; i_y++ )
119     {
120         for( i_x = 0; i_x < 8; i_x++ )
121         {
122             *p_data++ = pi_crop[*p_block++];
123         }
124         p_data += i_incr;
125     }
126 }
127
128 void _M( vdec_DecodeMacroblockC ) ( vdec_thread_t *p_vdec, macroblock_t * p_mb )
129 {
130     if( !(p_mb->i_mb_type & MB_INTRA) )
131     {
132         /*
133          * Motion Compensation (ISO/IEC 13818-2 section 7.6)
134          */
135         if( p_mb->pf_motion == 0 )
136         {
137             intf_WarnMsg( 2, "pf_motion set to NULL" );
138         }
139         else
140         {
141             p_mb->pf_motion( p_mb );
142         }
143
144         DECODEBLOCKSC( AddBlock )
145     }
146     else
147     {
148         DECODEBLOCKSC( CopyBlock )
149     }
150 }
151
152 void _M( vdec_DecodeMacroblockBW ) ( vdec_thread_t *p_vdec,
153                                      macroblock_t * p_mb )
154 {
155     if( !(p_mb->i_mb_type & MB_INTRA) )
156     {
157         /*
158          * Motion Compensation (ISO/IEC 13818-2 section 7.6)
159          */
160         if( p_mb->pf_motion == 0 )
161         {
162             intf_WarnMsg( 2, "pf_motion set to NULL" );
163         }
164         else
165         {
166             p_mb->pf_motion( p_mb );
167         }
168
169         DECODEBLOCKSBW( AddBlock )
170     }
171     else
172     {
173         DECODEBLOCKSBW( CopyBlock )
174     }
175 }
176