|
/***************************************************************************** |
|
|
* |
|
|
* XVID MPEG-4 VIDEO CODEC |
|
|
* - Global structures, constants - |
|
|
* |
|
|
* Copyright(C) 2002 Michael Militzer <isibaar@xvid.org> |
|
|
* |
|
|
* This file is part of XviD, a free MPEG-4 video encoder/decoder |
|
|
* |
|
|
* XviD is free software; you can redistribute it and/or modify it |
|
|
* under the terms of the GNU General Public License as published by |
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
|
* (at your option) any later version. |
|
|
* |
|
|
* This program is distributed in the hope that it will be useful, |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
* GNU General Public License for more details. |
|
|
* |
|
|
* You should have received a copy of the GNU General Public License |
|
|
* along with this program; if not, write to the Free Software |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
|
* |
|
|
* Under section 8 of the GNU General Public License, the copyright |
|
|
* holders of XVID explicitly forbid distribution in the following |
|
|
* countries: |
|
|
* |
|
|
* - Japan |
|
|
* - United States of America |
|
|
* |
|
|
* Linking XviD statically or dynamically with other modules is making a |
|
|
* combined work based on XviD. Thus, the terms and conditions of the |
|
|
* GNU General Public License cover the whole combination. |
|
|
* |
|
|
* As a special exception, the copyright holders of XviD give you |
|
|
* permission to link XviD with independent modules that communicate with |
|
|
* XviD solely through the VFW1.1 and DShow interfaces, regardless of the |
|
|
* license terms of these independent modules, and to copy and distribute |
|
|
* the resulting combined work under terms of your choice, provided that |
|
|
* every copy of the combined work is accompanied by a complete copy of |
|
|
* the source code of XviD (the version of XviD used to produce the |
|
|
* combined work), being distributed under the terms of the GNU General |
|
|
* Public License plus this exception. An independent module is a module |
|
|
* which is not derived from or based on XviD. |
|
|
* |
|
|
* Note that people who make modified versions of XviD are not obligated |
|
|
* to grant this special exception for their modified versions; it is |
|
|
* their choice whether to do so. The GNU General Public License gives |
|
|
* permission to release a modified version without this exception; this |
|
|
* exception also makes it possible to release a modified version which |
|
|
* carries forward this exception. |
|
|
* |
|
|
* $Id: global.h,v 1.18 2002-12-15 01:21:12 edgomez Exp $ |
|
|
* |
|
|
****************************************************************************/ |
|
|
|
|
1 |
#ifndef _GLOBAL_H_ |
#ifndef _GLOBAL_H_ |
2 |
#define _GLOBAL_H_ |
#define _GLOBAL_H_ |
3 |
|
|
11 |
#define MODE_INTER4V 2 |
#define MODE_INTER4V 2 |
12 |
#define MODE_INTRA 3 |
#define MODE_INTRA 3 |
13 |
#define MODE_INTRA_Q 4 |
#define MODE_INTRA_Q 4 |
|
#define MODE_STUFFING 7 |
|
14 |
#define MODE_NOT_CODED 16 |
#define MODE_NOT_CODED 16 |
15 |
|
#define MODE_NOT_CODED_GMC 17 |
16 |
|
|
17 |
/* --- bframe specific --- */ |
/* --- bframe specific --- */ |
18 |
|
|
21 |
#define MODE_BACKWARD 2 |
#define MODE_BACKWARD 2 |
22 |
#define MODE_FORWARD 3 |
#define MODE_FORWARD 3 |
23 |
#define MODE_DIRECT_NONE_MV 4 |
#define MODE_DIRECT_NONE_MV 4 |
24 |
|
#define MODE_DIRECT_NO4V 5 |
25 |
|
|
26 |
|
typedef struct |
27 |
|
{ |
28 |
|
VECTOR duv[3]; |
29 |
|
} |
30 |
|
WARPPOINTS; |
31 |
|
|
32 |
|
/* save all warping parameters for GMC once and for all, instead of |
33 |
|
recalculating for every block. This is needed for encoding&decoding |
34 |
|
When switching to incremental calculations, this will get much shorter |
35 |
|
*/ |
36 |
|
|
37 |
|
/* we don't include WARPPOINTS wp here, but in FRAMEINFO itself */ |
38 |
|
|
39 |
|
typedef struct |
40 |
|
{ |
41 |
|
int num_wp; // [input]: 0=none, 1=translation, 2,3 = warping |
42 |
|
// a value of -1 means: "structure not initialized!" |
43 |
|
int s; // [input]: calc is done with 1/s pel resolution |
44 |
|
|
45 |
|
int W; |
46 |
|
int H; |
47 |
|
|
48 |
|
int ss; |
49 |
|
int smask; |
50 |
|
int sigma; |
51 |
|
|
52 |
|
int r; |
53 |
|
int rho; |
54 |
|
|
55 |
|
int i0s; |
56 |
|
int j0s; |
57 |
|
int i1s; |
58 |
|
int j1s; |
59 |
|
int i2s; |
60 |
|
int j2s; |
61 |
|
|
62 |
|
int i1ss; |
63 |
|
int j1ss; |
64 |
|
int i2ss; |
65 |
|
int j2ss; |
66 |
|
|
67 |
|
int alpha; |
68 |
|
int beta; |
69 |
|
int Ws; |
70 |
|
int Hs; |
71 |
|
|
72 |
|
int dxF, dyF, dxG, dyG; |
73 |
|
int Fo, Go; |
74 |
|
int cFo, cGo; |
75 |
|
} |
76 |
|
GMC_DATA; |
77 |
|
|
78 |
|
|
79 |
|
typedef struct |
80 |
|
{ |
81 |
|
uint8_t *y; |
82 |
|
uint8_t *u; |
83 |
|
uint8_t *v; |
84 |
|
} |
85 |
|
IMAGE; |
86 |
|
|
87 |
|
|
88 |
typedef struct |
typedef struct |
103 |
|
|
104 |
typedef struct |
typedef struct |
105 |
{ |
{ |
106 |
/* decoder/encoder */ |
// decoder/encoder |
107 |
VECTOR mvs[4]; |
VECTOR mvs[4]; |
108 |
|
|
109 |
short int pred_values[6][MBPRED_SIZE]; |
short int pred_values[6][MBPRED_SIZE]; |
110 |
int acpred_directions[6]; |
int acpred_directions[6]; |
111 |
|
|
112 |
int mode; |
int mode; |
113 |
int quant; /* absolute quant */ |
int quant; // absolute quant |
114 |
|
|
115 |
int field_dct; |
int field_dct; |
116 |
int field_pred; |
int field_pred; |
117 |
int field_for_top; |
int field_for_top; |
118 |
int field_for_bot; |
int field_for_bot; |
119 |
|
|
120 |
/* encoder specific */ |
// encoder specific |
121 |
|
|
122 |
VECTOR mv16; |
VECTOR mv16; |
123 |
VECTOR pmvs[4]; |
VECTOR pmvs[4]; |
124 |
|
VECTOR qmvs[4]; // mvs in quarter pixel resolution |
125 |
|
|
126 |
int32_t sad8[4]; /* SAD values for inter4v-VECTORs */ |
int32_t sad8[4]; // SAD values for inter4v-VECTORs |
127 |
int32_t sad16; /* SAD value for inter-VECTOR */ |
int32_t sad16; // SAD value for inter-VECTOR |
128 |
|
|
129 |
int dquant; |
int dquant; |
130 |
int cbp; |
int cbp; |
131 |
|
|
132 |
/* bframe stuff */ |
// bframe stuff |
133 |
|
|
134 |
VECTOR b_mvs[4]; |
VECTOR b_mvs[4]; |
135 |
VECTOR b_pmvs[4]; |
VECTOR b_qmvs[4]; |
136 |
|
// VECTOR b_pmvs[1]; |
137 |
|
|
138 |
/* bframe direct mode */ |
// bframe direct mode |
139 |
|
|
140 |
VECTOR directmv[4]; |
// VECTOR directmv[4]; |
141 |
VECTOR deltamv; |
// VECTOR deltamv; |
142 |
|
|
143 |
int mb_type; |
int mb_type; |
144 |
int dbquant; |
int dbquant; |
145 |
|
|
146 |
/* stuff for block based ME (needed for Qpel ME) */ |
// stuff for block based ME (needed for Qpel ME) |
147 |
/* backup of last integer ME vectors/sad */ |
// backup of last integer ME vectors/sad |
148 |
|
|
149 |
VECTOR i_mv16; |
// VECTOR i_mv16; |
150 |
VECTOR i_mvs[4]; |
VECTOR i_mvs[4]; |
151 |
|
|
152 |
int32_t i_sad8[4]; /* SAD values for inter4v-VECTORs */ |
int32_t i_sad8[4]; // SAD values for inter4v-VECTORs |
153 |
int32_t i_sad16; /* SAD value for inter-VECTOR */ |
// int32_t i_sad16; // SAD value for inter-VECTOR |
154 |
|
|
155 |
|
VECTOR amv; // average motion vectors from GMC |
156 |
|
int32_t mcsel; |
157 |
|
|
158 |
|
/* This structure has become way to big! What to do? Split it up? */ |
159 |
|
|
160 |
} |
} |
161 |
MACROBLOCK; |
MACROBLOCK; |
162 |
|
|
163 |
static __inline int8_t |
static __inline uint32_t |
164 |
get_dc_scaler(uint32_t quant, |
get_dc_scaler(uint32_t quant, |
165 |
uint32_t lum) |
uint32_t lum) |
166 |
{ |
{ |
168 |
return 8; |
return 8; |
169 |
|
|
170 |
if (quant < 25 && !lum) |
if (quant < 25 && !lum) |
171 |
return (int8_t)((quant + 13) / 2); |
return (quant + 13) / 2; |
172 |
|
|
173 |
if (quant < 9) |
if (quant < 9) |
174 |
return (int8_t)(2 * quant); |
return 2 * quant; |
175 |
|
|
176 |
if (quant < 25) |
if (quant < 25) |
177 |
return (int8_t)(quant + 8); |
return quant + 8; |
178 |
|
|
179 |
if (lum) |
if (lum) |
180 |
return (int8_t)(2 * quant - 16); |
return 2 * quant - 16; |
181 |
else |
else |
182 |
return (int8_t)(quant - 6); |
return quant - 6; |
183 |
} |
} |
184 |
|
|
185 |
/* useful macros */ |
// useful macros |
186 |
|
|
187 |
#define MIN(X, Y) ((X)<(Y)?(X):(Y)) |
#define MIN(X, Y) ((X)<(Y)?(X):(Y)) |
188 |
#define MAX(X, Y) ((X)>(Y)?(X):(Y)) |
#define MAX(X, Y) ((X)>(Y)?(X):(Y)) |
189 |
#define ABS(X) (((X)>0)?(X):-(X)) |
#define ABS(X) (((X)>0)?(X):-(X)) |
190 |
#define SIGN(X) (((X)>0)?1:-1) |
#define SIGN(X) (((X)>0)?1:-1) |
191 |
|
#define CLIP(X,AMIN,AMAX) (((X)<(AMIN)) ? (AMIN) : ((X)>(AMAX)) ? (AMAX) : (X)) |
192 |
|
#define DIV_DIV(a,b) (((a)>0) ? ((a)+((b)>>1))/(b) : ((a)-((b)>>1))/(b)) |
193 |
|
|
194 |
|
|
195 |
#endif /* _GLOBAL_H_ */ |
#endif /* _GLOBAL_H_ */ |