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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 329 - (view) (download)
Original Path: trunk/xvidcore/src/motion/sad.c

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

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