[svn] / branches / dev-api-4 / xvidcore / src / motion / motion_inlines.h Repository:
ViewVC logotype

Annotation of /branches/dev-api-4/xvidcore/src/motion/motion_inlines.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1186 - (view) (download)

1 : edgomez 1142 /*****************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * - Motion Estimation shared functions -
5 :     *
6 :     * Copyright(C) 2002 Christoph Lampert <gruel@web.de>
7 :     * 2002 Michael Militzer <michael@xvid.org>
8 :     * 2002-2003 Radoslaw Czyz <xvid@syskin.cjb.net>
9 :     *
10 :     * This program is free software ; you can redistribute it and/or modify
11 :     * it under the terms of the GNU General Public License as published by
12 :     * the Free Software Foundation ; either version 2 of the License, or
13 :     * (at your option) any later version.
14 :     *
15 :     * This program is distributed in the hope that it will be useful,
16 :     * but WITHOUT ANY WARRANTY ; without even the implied warranty of
17 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 :     * GNU General Public License for more details.
19 :     *
20 :     * You should have received a copy of the GNU General Public License
21 :     * along with this program ; if not, write to the Free Software
22 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 :     *
24 : syskin 1186 * $Id: motion_inlines.h,v 1.1.2.4 2003-10-24 13:28:23 syskin Exp $
25 : edgomez 1142 *
26 :     ****************************************************************************/
27 :    
28 :     #ifndef _MOTION_INLINES_
29 :     #define _MOTION_INLINES_
30 :    
31 :     #include <stdlib.h>
32 :    
33 :     /*
34 :     * Calculate the min/max range
35 :     * relative to the _MACROBLOCK_ position
36 :     */
37 :     static void __inline
38 :     get_range(int32_t * const min_dx,
39 :     int32_t * const max_dx,
40 :     int32_t * const min_dy,
41 :     int32_t * const max_dy,
42 :     const uint32_t x,
43 :     const uint32_t y,
44 :     uint32_t block_sz, /* block dimension, 3(8) or 4(16) */
45 :     const uint32_t width,
46 :     const uint32_t height,
47 :     const uint32_t fcode,
48 :     const int precision, /* 2 for qpel, 1 for halfpel */
49 :     const int rrv)
50 :     {
51 :     int k;
52 :     const int search_range = 16 << fcode;
53 :     int high = search_range - 1;
54 :     int low = -search_range;
55 :    
56 :     if (rrv) {
57 :     high = RRV_MV_SCALEUP(high);
58 :     low = RRV_MV_SCALEUP(low);
59 :     block_sz++;
60 :     }
61 :    
62 :     k = (int)(width - (x<<block_sz))<<precision;
63 :     *max_dx = MIN(high, k);
64 :     k = (int)(height - (y<<block_sz))<<precision;
65 :     *max_dy = MIN(high, k);
66 :    
67 :     k = (-(int)((x+1)<<block_sz))<<precision;
68 :     *min_dx = MAX(low, k);
69 :     k = (-(int)((y+1)<<block_sz))<<precision;
70 :     *min_dy = MAX(low, k);
71 :     }
72 :    
73 :     /* mv.length table */
74 :     static const int mvtab[64] = {
75 :     1, 2, 3, 4, 6, 7, 7, 7,
76 :     9, 9, 9, 10, 10, 10, 10, 10,
77 :     10, 10, 10, 10, 10, 10, 10, 10,
78 :     10, 11, 11, 11, 11, 11, 11, 12,
79 :     12, 12, 12, 12, 12, 12, 12, 12,
80 :     12, 12, 12, 12, 12, 12, 12, 12,
81 : syskin 1186 12, 12, 12, 12, 12, 12, 12, 12,
82 : syskin 1159 12, 12, 12, 12, 12, 12, 12, 12
83 : edgomez 1142 };
84 :    
85 :     static __inline uint32_t
86 :     d_mv_bits(int x, int y, const VECTOR pred, const uint32_t iFcode, const int qpel, const int rrv)
87 :     {
88 :     int bits;
89 :     const int q = (1 << (iFcode - 1)) - 1;
90 :    
91 :     x <<= qpel;
92 :     y <<= qpel;
93 :     if (rrv) { x = RRV_MV_SCALEDOWN(x); y = RRV_MV_SCALEDOWN(y); }
94 :    
95 :     x -= pred.x;
96 :     bits = (x != 0 ? iFcode:0);
97 :     x = abs(x);
98 :     x += q;
99 :     x >>= (iFcode - 1);
100 :     bits += mvtab[x];
101 :    
102 :     y -= pred.y;
103 :     bits += (y != 0 ? iFcode:0);
104 :     y = abs(y);
105 :     y += q;
106 :     y >>= (iFcode - 1);
107 :     bits += mvtab[y];
108 :    
109 :     return bits;
110 :     }
111 :    
112 :     static __inline const uint8_t *
113 :     GetReference(const int x, const int y, const SearchData * const data)
114 :     {
115 :     const int picture = ((x&1)<<1) | (y&1);
116 :     const int offset = (x>>1) + (y>>1)*data->iEdgedWidth;
117 :     return data->RefP[picture] + offset;
118 :     }
119 :    
120 :     static __inline const uint8_t *
121 :     GetReferenceB(const int x, const int y, const uint32_t dir, const SearchData * const data)
122 :     {
123 :     /* dir : 0 = forward, 1 = backward */
124 :     const uint8_t *const *const direction = ( dir == 0 ? data->RefP : data->b_RefP );
125 :     const int picture = ((x&1)<<1) | (y&1);
126 :     const int offset = (x>>1) + (y>>1)*data->iEdgedWidth;
127 :     return direction[picture] + offset;
128 :     }
129 :    
130 :     static __inline void
131 :     ZeroMacroblockP(MACROBLOCK *pMB, const int32_t sad)
132 :     {
133 :     pMB->mode = MODE_INTER;
134 :     pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = zeroMV;
135 :     pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = zeroMV;
136 :     pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad;
137 : syskin 1158 pMB->mcsel = 0;
138 : edgomez 1142 }
139 :    
140 :     /* check if given vector is equal to any vector checked before */
141 :     static __inline int
142 : syskin 1158 vector_repeats(const VECTOR * const pmv, const unsigned int i)
143 : edgomez 1142 {
144 :     unsigned int j;
145 :     for (j = 0; j < i; j++)
146 :     if (MVequal(pmv[i], pmv[j])) return 1; /* same vector has been checked already */
147 :     return 0;
148 :     }
149 :    
150 :     /* make a binary mask that prevents diamonds/squares
151 :     from checking a vector which has been checked as a prediction */
152 :     static __inline int
153 : syskin 1158 make_mask(const VECTOR * const pmv, const unsigned int i, const unsigned int current)
154 : edgomez 1142 {
155 :     unsigned int mask = 255, j;
156 :     for (j = 0; j < i; j++) {
157 :     if (pmv[current].x == pmv[j].x) {
158 :     if (pmv[current].y == pmv[j].y + iDiamondSize) mask &= ~4;
159 :     else if (pmv[current].y == pmv[j].y - iDiamondSize) mask &= ~8;
160 :     } else
161 :     if (pmv[current].y == pmv[j].y) {
162 :     if (pmv[current].x == pmv[j].x + iDiamondSize) mask &= ~1;
163 :     else if (pmv[current].x == pmv[j].x - iDiamondSize) mask &= ~2;
164 :     }
165 :     }
166 :     return mask;
167 :     }
168 :    
169 :     #endif /* _MOTION_INLINES_ */

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