Parent Directory | Revision Log
Revision 603 -
(view)
(download)
Original Path: trunk/xvidcore/src/motion/sad.c
1 : | chl | 430 | /***************************************************************************** |
2 : | edgomez | 195 | * |
3 : | chl | 430 | * XVID MPEG-4 VIDEO CODEC |
4 : | * - SAD calculation module (C part) - | ||
5 : | edgomez | 195 | * |
6 : | edgomez | 603 | * Copyright(C) 2002 Michael Militzer <isibaar@xvid.org> |
7 : | chl | 430 | * Copyright(C) 2002 Pete Ross |
8 : | edgomez | 195 | * |
9 : | chl | 430 | * This program is an implementation of a part of one or more MPEG-4 |
10 : | * Video tools as specified in ISO/IEC 14496-2 standard. Those intending | ||
11 : | * to use this software module in hardware or software products are | ||
12 : | * advised that its use may infringe existing patents or copyrights, and | ||
13 : | * any such use would be at such party's own risk. The original | ||
14 : | * developer of this software module and his/her company, and subsequent | ||
15 : | * editors and their companies, will have no liability for use of this | ||
16 : | * software or modifications or derivatives thereof. | ||
17 : | edgomez | 195 | * |
18 : | chl | 430 | * This program is free software; you can redistribute it and/or modify |
19 : | * it under the terms of the GNU General Public License as published by | ||
20 : | * the Free Software Foundation; either version 2 of the License, or | ||
21 : | * (at your option) any later version. | ||
22 : | edgomez | 195 | * |
23 : | chl | 430 | * This program is distributed in the hope that it will be useful, |
24 : | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
25 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
26 : | * GNU General Public License for more details. | ||
27 : | edgomez | 195 | * |
28 : | chl | 430 | * You should have received a copy of the GNU General Public License |
29 : | * along with this program; if not, write to the Free Software | ||
30 : | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
31 : | edgomez | 195 | * |
32 : | chl | 430 | ****************************************************************************/ |
33 : | edgomez | 195 | |
34 : | #include "../portab.h" | ||
35 : | #include "sad.h" | ||
36 : | |||
37 : | sad16FuncPtr sad16; | ||
38 : | sad8FuncPtr sad8; | ||
39 : | sad16biFuncPtr sad16bi; | ||
40 : | sad8biFuncPtr sad8bi; // not really sad16, but no difference in prototype | ||
41 : | dev16FuncPtr dev16; | ||
42 : | |||
43 : | sadInitFuncPtr sadInit; | ||
44 : | |||
45 : | #define ABS(X) (((X)>0)?(X):-(X)) | ||
46 : | |||
47 : | suxen_drol | 329 | #define MRSAD16_CORRFACTOR 8 |
48 : | edgomez | 195 | uint32_t |
49 : | suxen_drol | 329 | mrsad16_c(const uint8_t * const cur, |
50 : | edgomez | 195 | const uint8_t * const ref, |
51 : | chl | 326 | const uint32_t stride, |
52 : | edgomez | 195 | const uint32_t best_sad) |
53 : | { | ||
54 : | |||
55 : | uint32_t sad = 0; | ||
56 : | int32_t mean = 0; | ||
57 : | uint32_t i, j; | ||
58 : | uint8_t const *ptr_cur = cur; | ||
59 : | uint8_t const *ptr_ref = ref; | ||
60 : | |||
61 : | for (j = 0; j < 16; j++) { | ||
62 : | for (i = 0; i < 16; i++) { | ||
63 : | mean += ((int) *(ptr_cur + i) - (int) *(ptr_ref + i)); | ||
64 : | } | ||
65 : | ptr_cur += stride; | ||
66 : | ptr_ref += stride; | ||
67 : | |||
68 : | } | ||
69 : | mean /= 256; | ||
70 : | |||
71 : | for (j = 0; j < 16; j++) { | ||
72 : | |||
73 : | ptr_cur -= stride; | ||
74 : | ptr_ref -= stride; | ||
75 : | |||
76 : | for (i = 0; i < 16; i++) { | ||
77 : | |||
78 : | sad += ABS(*(ptr_cur + i) - *(ptr_ref + i) - mean); | ||
79 : | if (sad >= best_sad) { | ||
80 : | return MRSAD16_CORRFACTOR * sad; | ||
81 : | } | ||
82 : | } | ||
83 : | } | ||
84 : | |||
85 : | return MRSAD16_CORRFACTOR * sad; | ||
86 : | |||
87 : | } | ||
88 : | |||
89 : | |||
90 : | uint32_t | ||
91 : | sad16_c(const uint8_t * const cur, | ||
92 : | const uint8_t * const ref, | ||
93 : | const uint32_t stride, | ||
94 : | const uint32_t best_sad) | ||
95 : | { | ||
96 : | |||
97 : | uint32_t sad = 0; | ||
98 : | uint32_t i, j; | ||
99 : | uint8_t const *ptr_cur = cur; | ||
100 : | uint8_t const *ptr_ref = ref; | ||
101 : | |||
102 : | for (j = 0; j < 16; j++) { | ||
103 : | |||
104 : | for (i = 0; i < 16; i++) { | ||
105 : | |||
106 : | sad += ABS(*(ptr_cur + i) - *(ptr_ref + i)); | ||
107 : | |||
108 : | if (sad >= best_sad) { | ||
109 : | return sad; | ||
110 : | } | ||
111 : | |||
112 : | |||
113 : | } | ||
114 : | |||
115 : | ptr_cur += stride; | ||
116 : | ptr_ref += stride; | ||
117 : | |||
118 : | } | ||
119 : | |||
120 : | return sad; | ||
121 : | |||
122 : | } | ||
123 : | |||
124 : | |||
125 : | |||
126 : | uint32_t | ||
127 : | sad16bi_c(const uint8_t * const cur, | ||
128 : | const uint8_t * const ref1, | ||
129 : | const uint8_t * const ref2, | ||
130 : | const uint32_t stride) | ||
131 : | { | ||
132 : | |||
133 : | uint32_t sad = 0; | ||
134 : | uint32_t i, j; | ||
135 : | uint8_t const *ptr_cur = cur; | ||
136 : | uint8_t const *ptr_ref1 = ref1; | ||
137 : | uint8_t const *ptr_ref2 = ref2; | ||
138 : | |||
139 : | for (j = 0; j < 16; j++) { | ||
140 : | |||
141 : | for (i = 0; i < 16; i++) { | ||
142 : | int pixel = (ptr_ref1[i] + ptr_ref2[i] + 1) / 2; | ||
143 : | |||
144 : | if (pixel < 0) { | ||
145 : | pixel = 0; | ||
146 : | } else if (pixel > 255) { | ||
147 : | pixel = 255; | ||
148 : | } | ||
149 : | |||
150 : | sad += ABS(ptr_cur[i] - pixel); | ||
151 : | } | ||
152 : | |||
153 : | ptr_cur += stride; | ||
154 : | ptr_ref1 += stride; | ||
155 : | ptr_ref2 += stride; | ||
156 : | |||
157 : | } | ||
158 : | |||
159 : | return sad; | ||
160 : | |||
161 : | } | ||
162 : | |||
163 : | uint32_t | ||
164 : | sad8bi_c(const uint8_t * const cur, | ||
165 : | const uint8_t * const ref1, | ||
166 : | const uint8_t * const ref2, | ||
167 : | const uint32_t stride) | ||
168 : | { | ||
169 : | |||
170 : | uint32_t sad = 0; | ||
171 : | chl | 326 | uint32_t i, j; |
172 : | edgomez | 195 | uint8_t const *ptr_cur = cur; |
173 : | chl | 326 | uint8_t const *ptr_ref1 = ref1; |
174 : | uint8_t const *ptr_ref2 = ref2; | ||
175 : | |||
176 : | for (j = 0; j < 8; j++) { | ||
177 : | |||
178 : | for (i = 0; i < 8; i++) { | ||
179 : | int pixel = (ptr_ref1[i] + ptr_ref2[i] + 1) / 2; | ||
180 : | |||
181 : | if (pixel < 0) { | ||
182 : | pixel = 0; | ||
183 : | } else if (pixel > 255) { | ||
184 : | pixel = 255; | ||
185 : | } | ||
186 : | |||
187 : | sad += ABS(ptr_cur[i] - pixel); | ||
188 : | } | ||
189 : | |||
190 : | ptr_cur += stride; | ||
191 : | ptr_ref1 += stride; | ||
192 : | ptr_ref2 += stride; | ||
193 : | |||
194 : | } | ||
195 : | |||
196 : | return sad; | ||
197 : | |||
198 : | } | ||
199 : | |||
200 : | |||
201 : | |||
202 : | uint32_t | ||
203 : | sad8_c(const uint8_t * const cur, | ||
204 : | const uint8_t * const ref, | ||
205 : | const uint32_t stride) | ||
206 : | { | ||
207 : | uint32_t sad = 0; | ||
208 : | uint32_t i, j; | ||
209 : | uint8_t const *ptr_cur = cur; | ||
210 : | edgomez | 195 | uint8_t const *ptr_ref = ref; |
211 : | |||
212 : | for (j = 0; j < 8; j++) { | ||
213 : | |||
214 : | for (i = 0; i < 8; i++) { | ||
215 : | sad += ABS(*(ptr_cur + i) - *(ptr_ref + i)); | ||
216 : | } | ||
217 : | |||
218 : | ptr_cur += stride; | ||
219 : | ptr_ref += stride; | ||
220 : | |||
221 : | } | ||
222 : | |||
223 : | return sad; | ||
224 : | } | ||
225 : | |||
226 : | |||
227 : | |||
228 : | |||
229 : | /* average deviation from mean */ | ||
230 : | |||
231 : | uint32_t | ||
232 : | dev16_c(const uint8_t * const cur, | ||
233 : | const uint32_t stride) | ||
234 : | { | ||
235 : | |||
236 : | uint32_t mean = 0; | ||
237 : | uint32_t dev = 0; | ||
238 : | uint32_t i, j; | ||
239 : | uint8_t const *ptr_cur = cur; | ||
240 : | |||
241 : | for (j = 0; j < 16; j++) { | ||
242 : | |||
243 : | for (i = 0; i < 16; i++) | ||
244 : | mean += *(ptr_cur + i); | ||
245 : | |||
246 : | ptr_cur += stride; | ||
247 : | |||
248 : | } | ||
249 : | |||
250 : | mean /= (16 * 16); | ||
251 : | ptr_cur = cur; | ||
252 : | |||
253 : | for (j = 0; j < 16; j++) { | ||
254 : | |||
255 : | for (i = 0; i < 16; i++) | ||
256 : | dev += ABS(*(ptr_cur + i) - (int32_t) mean); | ||
257 : | |||
258 : | ptr_cur += stride; | ||
259 : | |||
260 : | } | ||
261 : | |||
262 : | return dev; | ||
263 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |