Parent Directory | Revision Log
Revision 957 - (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 : | sad16FuncPtr sad16; | ||
46 : | sad8FuncPtr sad8; | ||
47 : | sad16biFuncPtr sad16bi; | ||
48 : | edgomez | 851 | sad8biFuncPtr sad8bi; // not really sad16, but no difference in prototype |
49 : | edgomez | 195 | dev16FuncPtr dev16; |
50 : | edgomez | 851 | sad16vFuncPtr sad16v; |
51 : | edgomez | 195 | |
52 : | sadInitFuncPtr sadInit; | ||
53 : | |||
54 : | |||
55 : | uint32_t | ||
56 : | sad16_c(const uint8_t * const cur, | ||
57 : | const uint8_t * const ref, | ||
58 : | const uint32_t stride, | ||
59 : | const uint32_t best_sad) | ||
60 : | { | ||
61 : | |||
62 : | uint32_t sad = 0; | ||
63 : | edgomez | 851 | uint32_t j; |
64 : | edgomez | 195 | uint8_t const *ptr_cur = cur; |
65 : | uint8_t const *ptr_ref = ref; | ||
66 : | |||
67 : | for (j = 0; j < 16; j++) { | ||
68 : | edgomez | 851 | sad += ABS(ptr_cur[0] - ptr_ref[0]); |
69 : | sad += ABS(ptr_cur[1] - ptr_ref[1]); | ||
70 : | sad += ABS(ptr_cur[2] - ptr_ref[2]); | ||
71 : | sad += ABS(ptr_cur[3] - ptr_ref[3]); | ||
72 : | sad += ABS(ptr_cur[4] - ptr_ref[4]); | ||
73 : | sad += ABS(ptr_cur[5] - ptr_ref[5]); | ||
74 : | sad += ABS(ptr_cur[6] - ptr_ref[6]); | ||
75 : | sad += ABS(ptr_cur[7] - ptr_ref[7]); | ||
76 : | sad += ABS(ptr_cur[8] - ptr_ref[8]); | ||
77 : | sad += ABS(ptr_cur[9] - ptr_ref[9]); | ||
78 : | sad += ABS(ptr_cur[10] - ptr_ref[10]); | ||
79 : | sad += ABS(ptr_cur[11] - ptr_ref[11]); | ||
80 : | sad += ABS(ptr_cur[12] - ptr_ref[12]); | ||
81 : | sad += ABS(ptr_cur[13] - ptr_ref[13]); | ||
82 : | sad += ABS(ptr_cur[14] - ptr_ref[14]); | ||
83 : | sad += ABS(ptr_cur[15] - ptr_ref[15]); | ||
84 : | edgomez | 195 | |
85 : | edgomez | 851 | if (sad >= best_sad) |
86 : | edgomez | 195 | return sad; |
87 : | |||
88 : | edgomez | 851 | ptr_cur += stride; |
89 : | ptr_ref += stride; | ||
90 : | edgomez | 195 | |
91 : | } | ||
92 : | |||
93 : | return sad; | ||
94 : | |||
95 : | } | ||
96 : | |||
97 : | uint32_t | ||
98 : | sad16bi_c(const uint8_t * const cur, | ||
99 : | const uint8_t * const ref1, | ||
100 : | const uint8_t * const ref2, | ||
101 : | const uint32_t stride) | ||
102 : | { | ||
103 : | |||
104 : | uint32_t sad = 0; | ||
105 : | uint32_t i, j; | ||
106 : | uint8_t const *ptr_cur = cur; | ||
107 : | uint8_t const *ptr_ref1 = ref1; | ||
108 : | uint8_t const *ptr_ref2 = ref2; | ||
109 : | |||
110 : | for (j = 0; j < 16; j++) { | ||
111 : | |||
112 : | for (i = 0; i < 16; i++) { | ||
113 : | int pixel = (ptr_ref1[i] + ptr_ref2[i] + 1) / 2; | ||
114 : | sad += ABS(ptr_cur[i] - pixel); | ||
115 : | } | ||
116 : | |||
117 : | ptr_cur += stride; | ||
118 : | ptr_ref1 += stride; | ||
119 : | ptr_ref2 += stride; | ||
120 : | |||
121 : | } | ||
122 : | |||
123 : | return sad; | ||
124 : | |||
125 : | } | ||
126 : | |||
127 : | uint32_t | ||
128 : | sad8bi_c(const uint8_t * const cur, | ||
129 : | const uint8_t * const ref1, | ||
130 : | const uint8_t * const ref2, | ||
131 : | const uint32_t stride) | ||
132 : | { | ||
133 : | |||
134 : | uint32_t sad = 0; | ||
135 : | chl | 326 | uint32_t i, j; |
136 : | edgomez | 195 | uint8_t const *ptr_cur = cur; |
137 : | chl | 326 | uint8_t const *ptr_ref1 = ref1; |
138 : | uint8_t const *ptr_ref2 = ref2; | ||
139 : | |||
140 : | for (j = 0; j < 8; j++) { | ||
141 : | |||
142 : | for (i = 0; i < 8; i++) { | ||
143 : | int pixel = (ptr_ref1[i] + ptr_ref2[i] + 1) / 2; | ||
144 : | sad += ABS(ptr_cur[i] - pixel); | ||
145 : | } | ||
146 : | |||
147 : | ptr_cur += stride; | ||
148 : | ptr_ref1 += stride; | ||
149 : | ptr_ref2 += stride; | ||
150 : | |||
151 : | } | ||
152 : | |||
153 : | return sad; | ||
154 : | |||
155 : | } | ||
156 : | |||
157 : | |||
158 : | |||
159 : | uint32_t | ||
160 : | sad8_c(const uint8_t * const cur, | ||
161 : | const uint8_t * const ref, | ||
162 : | const uint32_t stride) | ||
163 : | { | ||
164 : | uint32_t sad = 0; | ||
165 : | edgomez | 851 | uint32_t j; |
166 : | chl | 326 | uint8_t const *ptr_cur = cur; |
167 : | edgomez | 195 | uint8_t const *ptr_ref = ref; |
168 : | |||
169 : | for (j = 0; j < 8; j++) { | ||
170 : | |||
171 : | edgomez | 851 | sad += ABS(ptr_cur[0] - ptr_ref[0]); |
172 : | sad += ABS(ptr_cur[1] - ptr_ref[1]); | ||
173 : | sad += ABS(ptr_cur[2] - ptr_ref[2]); | ||
174 : | sad += ABS(ptr_cur[3] - ptr_ref[3]); | ||
175 : | sad += ABS(ptr_cur[4] - ptr_ref[4]); | ||
176 : | sad += ABS(ptr_cur[5] - ptr_ref[5]); | ||
177 : | sad += ABS(ptr_cur[6] - ptr_ref[6]); | ||
178 : | sad += ABS(ptr_cur[7] - ptr_ref[7]); | ||
179 : | |||
180 : | edgomez | 195 | ptr_cur += stride; |
181 : | ptr_ref += stride; | ||
182 : | |||
183 : | } | ||
184 : | |||
185 : | return sad; | ||
186 : | } | ||
187 : | |||
188 : | |||
189 : | /* average deviation from mean */ | ||
190 : | |||
191 : | uint32_t | ||
192 : | dev16_c(const uint8_t * const cur, | ||
193 : | const uint32_t stride) | ||
194 : | { | ||
195 : | |||
196 : | uint32_t mean = 0; | ||
197 : | uint32_t dev = 0; | ||
198 : | uint32_t i, j; | ||
199 : | uint8_t const *ptr_cur = cur; | ||
200 : | |||
201 : | for (j = 0; j < 16; j++) { | ||
202 : | |||
203 : | for (i = 0; i < 16; i++) | ||
204 : | mean += *(ptr_cur + i); | ||
205 : | |||
206 : | ptr_cur += stride; | ||
207 : | |||
208 : | } | ||
209 : | |||
210 : | mean /= (16 * 16); | ||
211 : | ptr_cur = cur; | ||
212 : | |||
213 : | for (j = 0; j < 16; j++) { | ||
214 : | |||
215 : | for (i = 0; i < 16; i++) | ||
216 : | dev += ABS(*(ptr_cur + i) - (int32_t) mean); | ||
217 : | |||
218 : | ptr_cur += stride; | ||
219 : | |||
220 : | } | ||
221 : | |||
222 : | return dev; | ||
223 : | } | ||
224 : | edgomez | 851 | |
225 : | uint32_t sad16v_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] = sad8(cur, ref, stride); | ||
231 : | sad[1] = sad8(cur + 8, ref + 8, stride); | ||
232 : | sad[2] = sad8(cur + 8*stride, ref + 8*stride, stride); | ||
233 : | sad[3] = sad8(cur + 8*stride + 8, ref + 8*stride + 8, stride); | ||
234 : | |||
235 : | return sad[0]+sad[1]+sad[2]+sad[3]; | ||
236 : | } | ||
237 : | |||
238 : | uint32_t sad32v_c(const uint8_t * const cur, | ||
239 : | const uint8_t * const ref, | ||
240 : | const uint32_t stride, | ||
241 : | int32_t *sad) | ||
242 : | { | ||
243 : | sad[0] = sad16(cur, ref, stride, 256*4096); | ||
244 : | sad[1] = sad16(cur + 8, ref + 8, stride, 256*4096); | ||
245 : | sad[2] = sad16(cur + 8*stride, ref + 8*stride, stride, 256*4096); | ||
246 : | sad[3] = sad16(cur + 8*stride + 8, ref + 8*stride + 8, stride, 256*4096); | ||
247 : | |||
248 : | return sad[0]+sad[1]+sad[2]+sad[3]; | ||
249 : | } | ||
250 : | |||
251 : | |||
252 : | |||
253 : | #define MRSAD16_CORRFACTOR 8 | ||
254 : | uint32_t | ||
255 : | mrsad16_c(const uint8_t * const cur, | ||
256 : | const uint8_t * const ref, | ||
257 : | const uint32_t stride, | ||
258 : | const uint32_t best_sad) | ||
259 : | { | ||
260 : | |||
261 : | uint32_t sad = 0; | ||
262 : | int32_t mean = 0; | ||
263 : | uint32_t i, j; | ||
264 : | uint8_t const *ptr_cur = cur; | ||
265 : | uint8_t const *ptr_ref = ref; | ||
266 : | |||
267 : | for (j = 0; j < 16; j++) { | ||
268 : | for (i = 0; i < 16; i++) { | ||
269 : | mean += ((int) *(ptr_cur + i) - (int) *(ptr_ref + i)); | ||
270 : | } | ||
271 : | ptr_cur += stride; | ||
272 : | ptr_ref += stride; | ||
273 : | |||
274 : | } | ||
275 : | mean /= 256; | ||
276 : | |||
277 : | for (j = 0; j < 16; j++) { | ||
278 : | |||
279 : | ptr_cur -= stride; | ||
280 : | ptr_ref -= stride; | ||
281 : | |||
282 : | for (i = 0; i < 16; i++) { | ||
283 : | |||
284 : | sad += ABS(*(ptr_cur + i) - *(ptr_ref + i) - mean); | ||
285 : | if (sad >= best_sad) { | ||
286 : | return MRSAD16_CORRFACTOR * sad; | ||
287 : | } | ||
288 : | } | ||
289 : | } | ||
290 : | |||
291 : | return MRSAD16_CORRFACTOR * sad; | ||
292 : | |||
293 : | } | ||
294 : | |||
295 : |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |