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

Annotation of /branches/dev-api-4/xvidcore/src/motion/sad.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1054 - (view) (download)

1 : edgomez 1054 /*****************************************************************************
2 : edgomez 195 *
3 : edgomez 1054 * XVID MPEG-4 VIDEO CODEC
4 :     * - Sum Of Absolute Difference related code -
5 : edgomez 195 *
6 : edgomez 1054 * Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>
7 : edgomez 195 *
8 : edgomez 1054 * This program is free software ; you can redistribute it and/or modify
9 :     * it under the terms of the GNU General Public License as published by
10 :     * the Free Software Foundation ; either version 2 of the License, or
11 :     * (at your option) any later version.
12 : edgomez 195 *
13 : edgomez 1054 * This program is distributed in the hope that it will be useful,
14 :     * but WITHOUT ANY WARRANTY ; without even the implied warranty of
15 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 :     * GNU General Public License for more details.
17 : edgomez 195 *
18 : edgomez 1054 * You should have received a copy of the GNU General Public License
19 :     * along with this program ; if not, write to the Free Software
20 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 : edgomez 195 *
22 : edgomez 1054 * $Id: sad.c,v 1.13.2.4 2003-06-09 13:54:46 edgomez Exp $
23 : edgomez 195 *
24 : edgomez 1054 ****************************************************************************/
25 : edgomez 195
26 :     #include "../portab.h"
27 : edgomez 851 #include "../global.h"
28 : edgomez 195 #include "sad.h"
29 :    
30 : edgomez 982 #include <stdlib.h>
31 :    
32 : edgomez 195 sad16FuncPtr sad16;
33 :     sad8FuncPtr sad8;
34 :     sad16biFuncPtr sad16bi;
35 : edgomez 1053 sad8biFuncPtr sad8bi; /* not really sad16, but no difference in prototype */
36 : edgomez 195 dev16FuncPtr dev16;
37 : edgomez 851 sad16vFuncPtr sad16v;
38 : edgomez 195
39 :     sadInitFuncPtr sadInit;
40 :    
41 :    
42 :     uint32_t
43 :     sad16_c(const uint8_t * const cur,
44 :     const uint8_t * const ref,
45 :     const uint32_t stride,
46 :     const uint32_t best_sad)
47 :     {
48 :    
49 :     uint32_t sad = 0;
50 : edgomez 851 uint32_t j;
51 : edgomez 195 uint8_t const *ptr_cur = cur;
52 :     uint8_t const *ptr_ref = ref;
53 :    
54 :     for (j = 0; j < 16; j++) {
55 : edgomez 982 sad += abs(ptr_cur[0] - ptr_ref[0]);
56 :     sad += abs(ptr_cur[1] - ptr_ref[1]);
57 :     sad += abs(ptr_cur[2] - ptr_ref[2]);
58 :     sad += abs(ptr_cur[3] - ptr_ref[3]);
59 :     sad += abs(ptr_cur[4] - ptr_ref[4]);
60 :     sad += abs(ptr_cur[5] - ptr_ref[5]);
61 :     sad += abs(ptr_cur[6] - ptr_ref[6]);
62 :     sad += abs(ptr_cur[7] - ptr_ref[7]);
63 :     sad += abs(ptr_cur[8] - ptr_ref[8]);
64 :     sad += abs(ptr_cur[9] - ptr_ref[9]);
65 :     sad += abs(ptr_cur[10] - ptr_ref[10]);
66 :     sad += abs(ptr_cur[11] - ptr_ref[11]);
67 :     sad += abs(ptr_cur[12] - ptr_ref[12]);
68 :     sad += abs(ptr_cur[13] - ptr_ref[13]);
69 :     sad += abs(ptr_cur[14] - ptr_ref[14]);
70 :     sad += abs(ptr_cur[15] - ptr_ref[15]);
71 : edgomez 195
72 : edgomez 851 if (sad >= best_sad)
73 : edgomez 195 return sad;
74 :    
75 : edgomez 851 ptr_cur += stride;
76 :     ptr_ref += stride;
77 : edgomez 195
78 :     }
79 :    
80 :     return sad;
81 :    
82 :     }
83 :    
84 :     uint32_t
85 :     sad16bi_c(const uint8_t * const cur,
86 :     const uint8_t * const ref1,
87 :     const uint8_t * const ref2,
88 :     const uint32_t stride)
89 :     {
90 :    
91 :     uint32_t sad = 0;
92 :     uint32_t i, j;
93 :     uint8_t const *ptr_cur = cur;
94 :     uint8_t const *ptr_ref1 = ref1;
95 :     uint8_t const *ptr_ref2 = ref2;
96 :    
97 :     for (j = 0; j < 16; j++) {
98 :    
99 :     for (i = 0; i < 16; i++) {
100 :     int pixel = (ptr_ref1[i] + ptr_ref2[i] + 1) / 2;
101 : edgomez 982 sad += abs(ptr_cur[i] - pixel);
102 : edgomez 195 }
103 :    
104 :     ptr_cur += stride;
105 :     ptr_ref1 += stride;
106 :     ptr_ref2 += stride;
107 :    
108 :     }
109 :    
110 :     return sad;
111 :    
112 :     }
113 :    
114 :     uint32_t
115 :     sad8bi_c(const uint8_t * const cur,
116 :     const uint8_t * const ref1,
117 :     const uint8_t * const ref2,
118 :     const uint32_t stride)
119 :     {
120 :    
121 :     uint32_t sad = 0;
122 : chl 326 uint32_t i, j;
123 : edgomez 195 uint8_t const *ptr_cur = cur;
124 : chl 326 uint8_t const *ptr_ref1 = ref1;
125 :     uint8_t const *ptr_ref2 = ref2;
126 :    
127 :     for (j = 0; j < 8; j++) {
128 :    
129 :     for (i = 0; i < 8; i++) {
130 :     int pixel = (ptr_ref1[i] + ptr_ref2[i] + 1) / 2;
131 : edgomez 982 sad += abs(ptr_cur[i] - pixel);
132 : chl 326 }
133 :    
134 :     ptr_cur += stride;
135 :     ptr_ref1 += stride;
136 :     ptr_ref2 += stride;
137 :    
138 :     }
139 :    
140 :     return sad;
141 :    
142 :     }
143 :    
144 :    
145 :    
146 :     uint32_t
147 :     sad8_c(const uint8_t * const cur,
148 :     const uint8_t * const ref,
149 :     const uint32_t stride)
150 :     {
151 :     uint32_t sad = 0;
152 : edgomez 851 uint32_t j;
153 : chl 326 uint8_t const *ptr_cur = cur;
154 : edgomez 195 uint8_t const *ptr_ref = ref;
155 :    
156 :     for (j = 0; j < 8; j++) {
157 :    
158 : edgomez 982 sad += abs(ptr_cur[0] - ptr_ref[0]);
159 :     sad += abs(ptr_cur[1] - ptr_ref[1]);
160 :     sad += abs(ptr_cur[2] - ptr_ref[2]);
161 :     sad += abs(ptr_cur[3] - ptr_ref[3]);
162 :     sad += abs(ptr_cur[4] - ptr_ref[4]);
163 :     sad += abs(ptr_cur[5] - ptr_ref[5]);
164 :     sad += abs(ptr_cur[6] - ptr_ref[6]);
165 :     sad += abs(ptr_cur[7] - ptr_ref[7]);
166 : edgomez 851
167 : edgomez 195 ptr_cur += stride;
168 :     ptr_ref += stride;
169 :    
170 :     }
171 :    
172 :     return sad;
173 :     }
174 :    
175 :    
176 :     /* average deviation from mean */
177 :    
178 :     uint32_t
179 :     dev16_c(const uint8_t * const cur,
180 :     const uint32_t stride)
181 :     {
182 :    
183 :     uint32_t mean = 0;
184 :     uint32_t dev = 0;
185 :     uint32_t i, j;
186 :     uint8_t const *ptr_cur = cur;
187 :    
188 :     for (j = 0; j < 16; j++) {
189 :    
190 :     for (i = 0; i < 16; i++)
191 :     mean += *(ptr_cur + i);
192 :    
193 :     ptr_cur += stride;
194 :    
195 :     }
196 :    
197 :     mean /= (16 * 16);
198 :     ptr_cur = cur;
199 :    
200 :     for (j = 0; j < 16; j++) {
201 :    
202 :     for (i = 0; i < 16; i++)
203 : edgomez 982 dev += abs(*(ptr_cur + i) - (int32_t) mean);
204 : edgomez 195
205 :     ptr_cur += stride;
206 :    
207 :     }
208 :    
209 :     return dev;
210 :     }
211 : edgomez 851
212 :     uint32_t sad16v_c(const uint8_t * const cur,
213 :     const uint8_t * const ref,
214 :     const uint32_t stride,
215 :     int32_t *sad)
216 :     {
217 :     sad[0] = sad8(cur, ref, stride);
218 :     sad[1] = sad8(cur + 8, ref + 8, stride);
219 :     sad[2] = sad8(cur + 8*stride, ref + 8*stride, stride);
220 :     sad[3] = sad8(cur + 8*stride + 8, ref + 8*stride + 8, stride);
221 :    
222 :     return sad[0]+sad[1]+sad[2]+sad[3];
223 :     }
224 :    
225 :     uint32_t sad32v_c(const uint8_t * const cur,
226 :     const uint8_t * const ref,
227 :     const uint32_t stride,
228 :     int32_t *sad)
229 :     {
230 :     sad[0] = sad16(cur, ref, stride, 256*4096);
231 :     sad[1] = sad16(cur + 8, ref + 8, stride, 256*4096);
232 :     sad[2] = sad16(cur + 8*stride, ref + 8*stride, stride, 256*4096);
233 :     sad[3] = sad16(cur + 8*stride + 8, ref + 8*stride + 8, stride, 256*4096);
234 :    
235 :     return sad[0]+sad[1]+sad[2]+sad[3];
236 :     }
237 :    
238 :    
239 :    
240 :     #define MRSAD16_CORRFACTOR 8
241 :     uint32_t
242 :     mrsad16_c(const uint8_t * const cur,
243 :     const uint8_t * const ref,
244 :     const uint32_t stride,
245 :     const uint32_t best_sad)
246 :     {
247 :    
248 :     uint32_t sad = 0;
249 :     int32_t mean = 0;
250 :     uint32_t i, j;
251 :     uint8_t const *ptr_cur = cur;
252 :     uint8_t const *ptr_ref = ref;
253 :    
254 :     for (j = 0; j < 16; j++) {
255 :     for (i = 0; i < 16; i++) {
256 :     mean += ((int) *(ptr_cur + i) - (int) *(ptr_ref + i));
257 :     }
258 :     ptr_cur += stride;
259 :     ptr_ref += stride;
260 :    
261 :     }
262 :     mean /= 256;
263 :    
264 :     for (j = 0; j < 16; j++) {
265 :    
266 :     ptr_cur -= stride;
267 :     ptr_ref -= stride;
268 :    
269 :     for (i = 0; i < 16; i++) {
270 :    
271 : edgomez 982 sad += abs(*(ptr_cur + i) - *(ptr_ref + i) - mean);
272 : edgomez 851 if (sad >= best_sad) {
273 :     return MRSAD16_CORRFACTOR * sad;
274 :     }
275 :     }
276 :     }
277 :    
278 :     return MRSAD16_CORRFACTOR * sad;
279 :    
280 :     }
281 :    
282 :    

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