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