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