[cvs] / xvidcore / src / prediction / mbprediction.h Repository:
ViewVC logotype

Annotation of /xvidcore/src/prediction/mbprediction.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (view) (download)

1 : Isibaar 1.1 #ifndef _MBPREDICTION_H_
2 :     #define _MBPREDICTION_H_
3 :    
4 :     #include "../portab.h"
5 :     #include "../decoder.h"
6 :     #include "../global.h"
7 :    
8 :     #define MIN(X, Y) ((X)<(Y)?(X):(Y))
9 :     #define MAX(X, Y) ((X)>(Y)?(X):(Y))
10 :    
11 :     // very large value
12 :     #define MV_MAX_ERROR (4096 * 256)
13 :    
14 :     #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )
15 :    
16 : suxen_drol 1.3 void MBPrediction(FRAMEINFO *frame, /* <-- the parameter for ACDC and MV prediction */
17 : Isibaar 1.1 uint32_t x_pos, /* <-- The x position of the MB to be searched */
18 :     uint32_t y_pos, /* <-- The y position of the MB to be searched */
19 :     uint32_t x_dim, /* <-- Number of macroblocks in a row */
20 : suxen_drol 1.3 int16_t *qcoeff /* <-> The quantized DCT coefficients */
21 : Isibaar 1.1 );
22 :    
23 :     void add_acdc(MACROBLOCK *pMB,
24 :     uint32_t block,
25 :     int16_t dct_codes[64],
26 :     uint32_t iDcScaler,
27 :     int16_t predictors[8]);
28 :    
29 :    
30 :     void predict_acdc(MACROBLOCK *pMBs,
31 :     uint32_t x, uint32_t y, uint32_t mb_width,
32 :     uint32_t block,
33 :     int16_t qcoeff[64],
34 :     uint32_t current_quant,
35 :     int32_t iDcScaler,
36 :     int16_t predictors[8]);
37 :    
38 :     /* This is somehow a copy of get_pmv, but returning all MVs and Minimum SAD
39 :     instead of only Median MV */
40 :    
41 :     static __inline int get_pmvdata(const MACROBLOCK * const pMBs,
42 :     const uint32_t x, const uint32_t y,
43 :     const uint32_t x_dim,
44 :     const uint32_t block,
45 :     VECTOR * const pmv,
46 :     int32_t * const psad)
47 :     {
48 :     /* pmv are filled with:
49 :     [0]: Median (or whatever is correct in a special case)
50 :     [1]: left neighbour
51 :     [2]: top neighbour,
52 :     [3]: topright neighbour,
53 :     psad are filled with:
54 :     [0]: minimum of [1] to [3]
55 :     [1]: left neighbour's SAD // [1] to [3] are actually not needed
56 :     [2]: top neighbour's SAD,
57 :     [3]: topright neighbour's SAD,
58 :     */
59 :    
60 :     int xin1, xin2, xin3;
61 :     int yin1, yin2, yin3;
62 :     int vec1, vec2, vec3;
63 :    
64 :     static VECTOR zeroMV;
65 :     uint32_t index = x + y * x_dim;
66 :     zeroMV.x = zeroMV.y = 0;
67 :    
68 :     // first row (special case)
69 :     if (y == 0 && (block == 0 || block == 1))
70 :     {
71 :     if ((x == 0) && (block == 0)) // first column, first block
72 :     {
73 :     pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV;
74 :     psad[0] = psad[1] = psad[2] = psad[3] = MV_MAX_ERROR;
75 :     return 0;
76 :     }
77 :     if (block == 1) // second block; has only a left neighbour
78 :     {
79 :     pmv[0] = pmv[1] = pMBs[index].mvs[0];
80 :     pmv[2] = pmv[3] = zeroMV;
81 :     psad[0] = psad[1] = pMBs[index].sad8[0];
82 :     psad[2] = psad[3] = MV_MAX_ERROR;
83 :     return 0;
84 :     }
85 :     else /* block==0, but x!=0, so again, there is a left neighbour*/
86 :     {
87 :     pmv[0] = pmv[1] = pMBs[index-1].mvs[1];
88 :     pmv[2] = pmv[3] = zeroMV;
89 :     psad[0] = psad[1] = pMBs[index-1].sad8[1];
90 :     psad[2] = psad[3] = MV_MAX_ERROR;
91 :     return 0;
92 :     }
93 :     }
94 :    
95 :     /*
96 :     MODE_INTER, vm18 page 48
97 :     MODE_INTER4V vm18 page 51
98 :    
99 :     (x,y-1) (x+1,y-1)
100 :     [ | ] [ | ]
101 :     [ 2 | 3 ] [ 2 | ]
102 :    
103 :     (x-1,y) (x,y) (x+1,y)
104 :     [ | 1 ] [ 0 | 1 ] [ 0 | ]
105 :     [ | 3 ] [ 2 | 3 ] [ | ]
106 :     */
107 :    
108 :     switch (block)
109 :     {
110 :     case 0:
111 :     xin1 = x - 1; yin1 = y; vec1 = 1; /* left */
112 :     xin2 = x; yin2 = y - 1; vec2 = 2; /* top */
113 :     xin3 = x + 1; yin3 = y - 1; vec3 = 2; /* top right */
114 :     break;
115 :     case 1:
116 :     xin1 = x; yin1 = y; vec1 = 0;
117 :     xin2 = x; yin2 = y - 1; vec2 = 3;
118 :     xin3 = x + 1; yin3 = y - 1; vec3 = 2;
119 :     break;
120 :     case 2:
121 :     xin1 = x - 1; yin1 = y; vec1 = 3;
122 :     xin2 = x; yin2 = y; vec2 = 0;
123 :     xin3 = x; yin3 = y; vec3 = 1;
124 :     break;
125 :     default:
126 :     xin1 = x; yin1 = y; vec1 = 2;
127 :     xin2 = x; yin2 = y; vec2 = 0;
128 :     xin3 = x; yin3 = y; vec3 = 1;
129 :     }
130 :    
131 :    
132 :     if (xin1 < 0 || /* yin1 < 0 || */ xin1 >= (int32_t)x_dim)
133 :     {
134 :     pmv[1] = zeroMV;
135 :     psad[1] = MV_MAX_ERROR;
136 :     }
137 :     else
138 :     {
139 :     pmv[1] = pMBs[xin1 + yin1 * x_dim].mvs[vec1];
140 :     psad[1] = pMBs[xin1 + yin1 * x_dim].sad8[vec1];
141 :     }
142 :    
143 :     if (xin2 < 0 || /* yin2 < 0 || */ xin2 >= (int32_t)x_dim)
144 :     {
145 :     pmv[2] = zeroMV;
146 :     psad[2] = MV_MAX_ERROR;
147 :     }
148 :     else
149 :     {
150 :     pmv[2] = pMBs[xin2 + yin2 * x_dim].mvs[vec2];
151 :     psad[2] = pMBs[xin2 + yin2 * x_dim].sad8[vec2];
152 :     }
153 :    
154 :     if (xin3 < 0 || /* yin3 < 0 || */ xin3 >= (int32_t)x_dim)
155 :     {
156 :     pmv[3] = zeroMV;
157 :     psad[3] = MV_MAX_ERROR;
158 :     }
159 :     else
160 :     {
161 :     pmv[3] = pMBs[xin3 + yin3 * x_dim].mvs[vec3];
162 :     psad[3] = pMBs[xin2 + yin2 * x_dim].sad8[vec3];
163 :     }
164 :    
165 :     if ( (MVequal(pmv[1],pmv[2])) && (MVequal(pmv[1],pmv[3])) )
166 :     { pmv[0]=pmv[1];
167 :     psad[0]=psad[1];
168 :     return 1;
169 :     }
170 :    
171 :     // median,minimum
172 :    
173 :     pmv[0].x = MIN(MAX(pmv[1].x, pmv[2].x), MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
174 :     pmv[0].y = MIN(MAX(pmv[1].y, pmv[2].y), MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
175 :     psad[0]=MIN(MIN(psad[1],psad[2]),psad[3]);
176 :     return 0;
177 :     }
178 :    
179 :    
180 :     #endif /* _MBPREDICTION_H_ */

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4