Parent Directory | Revision Log
Revision 435 - (view) (download)
1 : | chl | 433 | /***************************************************************************** |
2 : | albeu | 315 | * |
3 : | chl | 433 | * XVID MPEG-4 VIDEO CODEC |
4 : | * - image module - | ||
5 : | albeu | 315 | * |
6 : | chl | 433 | * Copyright(C) 2002 Peter Ross <pross@xvid.org> |
7 : | albeu | 315 | * |
8 : | chl | 433 | * This program is an implementation of a part of one or more MPEG-4 |
9 : | * Video tools as specified in ISO/IEC 14496-2 standard. Those intending | ||
10 : | * to use this software module in hardware or software products are | ||
11 : | * advised that its use may infringe existing patents or copyrights, and | ||
12 : | * any such use would be at such party's own risk. The original | ||
13 : | * developer of this software module and his/her company, and subsequent | ||
14 : | * editors and their companies, will have no liability for use of this | ||
15 : | * software or modifications or derivatives thereof. | ||
16 : | albeu | 315 | * |
17 : | chl | 433 | * This program is free software; you can redistribute it and/or modify |
18 : | * it under the terms of the GNU General Public License as published by | ||
19 : | * the Free Software Foundation; either version 2 of the License, or | ||
20 : | * (at your option) any later version. | ||
21 : | albeu | 315 | * |
22 : | chl | 433 | * This program is distributed in the hope that it will be useful, |
23 : | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
24 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
25 : | * GNU General Public License for more details. | ||
26 : | albeu | 315 | * |
27 : | chl | 433 | * You should have received a copy of the GNU General Public License |
28 : | * along with this program; if not, write to the Free Software | ||
29 : | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
30 : | albeu | 315 | * |
31 : | chl | 433 | ****************************************************************************/ |
32 : | albeu | 315 | |
33 : | #include <stdlib.h> | ||
34 : | #include <string.h> // memcpy, memset | ||
35 : | #include <math.h> | ||
36 : | |||
37 : | #include "../portab.h" | ||
38 : | #include "../xvid.h" | ||
39 : | #include "image.h" | ||
40 : | #include "colorspace.h" | ||
41 : | #include "interpolate8x8.h" | ||
42 : | #include "../divx4.h" | ||
43 : | #include "../utils/mem_align.h" | ||
44 : | |||
45 : | #define SAFETY 64 | ||
46 : | #define EDGE_SIZE2 (EDGE_SIZE/2) | ||
47 : | |||
48 : | |||
49 : | int32_t | ||
50 : | image_create(IMAGE * image, | ||
51 : | uint32_t edged_width, | ||
52 : | uint32_t edged_height) | ||
53 : | { | ||
54 : | const uint32_t edged_width2 = edged_width / 2; | ||
55 : | const uint32_t edged_height2 = edged_height / 2; | ||
56 : | uint32_t i; | ||
57 : | |||
58 : | image->y = | ||
59 : | xvid_malloc(edged_width * (edged_height + 1) + SAFETY, CACHE_LINE); | ||
60 : | if (image->y == NULL) { | ||
61 : | return -1; | ||
62 : | } | ||
63 : | |||
64 : | for (i = 0; i < edged_width * edged_height + SAFETY; i++) { | ||
65 : | image->y[i] = 0; | ||
66 : | } | ||
67 : | |||
68 : | image->u = xvid_malloc(edged_width2 * edged_height2 + SAFETY, CACHE_LINE); | ||
69 : | if (image->u == NULL) { | ||
70 : | xvid_free(image->y); | ||
71 : | return -1; | ||
72 : | } | ||
73 : | image->v = xvid_malloc(edged_width2 * edged_height2 + SAFETY, CACHE_LINE); | ||
74 : | if (image->v == NULL) { | ||
75 : | xvid_free(image->u); | ||
76 : | xvid_free(image->y); | ||
77 : | return -1; | ||
78 : | } | ||
79 : | |||
80 : | image->y += EDGE_SIZE * edged_width + EDGE_SIZE; | ||
81 : | image->u += EDGE_SIZE2 * edged_width2 + EDGE_SIZE2; | ||
82 : | image->v += EDGE_SIZE2 * edged_width2 + EDGE_SIZE2; | ||
83 : | |||
84 : | return 0; | ||
85 : | } | ||
86 : | |||
87 : | |||
88 : | |||
89 : | void | ||
90 : | image_destroy(IMAGE * image, | ||
91 : | uint32_t edged_width, | ||
92 : | uint32_t edged_height) | ||
93 : | { | ||
94 : | const uint32_t edged_width2 = edged_width / 2; | ||
95 : | |||
96 : | if (image->y) { | ||
97 : | xvid_free(image->y - (EDGE_SIZE * edged_width + EDGE_SIZE)); | ||
98 : | } | ||
99 : | if (image->u) { | ||
100 : | xvid_free(image->u - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2)); | ||
101 : | } | ||
102 : | if (image->v) { | ||
103 : | xvid_free(image->v - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2)); | ||
104 : | } | ||
105 : | } | ||
106 : | |||
107 : | |||
108 : | void | ||
109 : | image_swap(IMAGE * image1, | ||
110 : | IMAGE * image2) | ||
111 : | { | ||
112 : | uint8_t *tmp; | ||
113 : | |||
114 : | tmp = image1->y; | ||
115 : | image1->y = image2->y; | ||
116 : | image2->y = tmp; | ||
117 : | |||
118 : | tmp = image1->u; | ||
119 : | image1->u = image2->u; | ||
120 : | image2->u = tmp; | ||
121 : | |||
122 : | tmp = image1->v; | ||
123 : | image1->v = image2->v; | ||
124 : | image2->v = tmp; | ||
125 : | } | ||
126 : | |||
127 : | |||
128 : | void | ||
129 : | image_copy(IMAGE * image1, | ||
130 : | IMAGE * image2, | ||
131 : | uint32_t edged_width, | ||
132 : | uint32_t height) | ||
133 : | { | ||
134 : | memcpy(image1->y, image2->y, edged_width * height); | ||
135 : | memcpy(image1->u, image2->u, edged_width * height / 4); | ||
136 : | memcpy(image1->v, image2->v, edged_width * height / 4); | ||
137 : | } | ||
138 : | |||
139 : | |||
140 : | void | ||
141 : | image_setedges(IMAGE * image, | ||
142 : | uint32_t edged_width, | ||
143 : | uint32_t edged_height, | ||
144 : | uint32_t width, | ||
145 : | uint32_t height, | ||
146 : | uint32_t interlacing) | ||
147 : | { | ||
148 : | const uint32_t edged_width2 = edged_width / 2; | ||
149 : | const uint32_t width2 = width / 2; | ||
150 : | uint32_t i; | ||
151 : | uint8_t *dst; | ||
152 : | uint8_t *src; | ||
153 : | |||
154 : | |||
155 : | dst = image->y - (EDGE_SIZE + EDGE_SIZE * edged_width); | ||
156 : | src = image->y; | ||
157 : | |||
158 : | for (i = 0; i < EDGE_SIZE; i++) { | ||
159 : | h | 389 | /* // if interlacing, edges contain top-most data from each field |
160 : | albeu | 315 | if (interlacing && (i & 1)) { |
161 : | memset(dst, *(src + edged_width), EDGE_SIZE); | ||
162 : | memcpy(dst + EDGE_SIZE, src + edged_width, width); | ||
163 : | memset(dst + edged_width - EDGE_SIZE, | ||
164 : | *(src + edged_width + width - 1), EDGE_SIZE); | ||
165 : | h | 389 | } else {*/ |
166 : | albeu | 315 | memset(dst, *src, EDGE_SIZE); |
167 : | memcpy(dst + EDGE_SIZE, src, width); | ||
168 : | memset(dst + edged_width - EDGE_SIZE, *(src + width - 1), | ||
169 : | EDGE_SIZE); | ||
170 : | h | 389 | /*}*/ |
171 : | albeu | 315 | dst += edged_width; |
172 : | } | ||
173 : | |||
174 : | for (i = 0; i < height; i++) { | ||
175 : | memset(dst, *src, EDGE_SIZE); | ||
176 : | memset(dst + edged_width - EDGE_SIZE, src[width - 1], EDGE_SIZE); | ||
177 : | dst += edged_width; | ||
178 : | src += edged_width; | ||
179 : | } | ||
180 : | |||
181 : | src -= edged_width; | ||
182 : | for (i = 0; i < EDGE_SIZE; i++) { | ||
183 : | h | 389 | /* // if interlacing, edges contain bottom-most data from each field |
184 : | albeu | 315 | if (interlacing && !(i & 1)) { |
185 : | memset(dst, *(src - edged_width), EDGE_SIZE); | ||
186 : | memcpy(dst + EDGE_SIZE, src - edged_width, width); | ||
187 : | memset(dst + edged_width - EDGE_SIZE, | ||
188 : | *(src - edged_width + width - 1), EDGE_SIZE); | ||
189 : | h | 389 | } else {*/ |
190 : | albeu | 315 | memset(dst, *src, EDGE_SIZE); |
191 : | memcpy(dst + EDGE_SIZE, src, width); | ||
192 : | memset(dst + edged_width - EDGE_SIZE, *(src + width - 1), | ||
193 : | EDGE_SIZE); | ||
194 : | h | 389 | /*}*/ |
195 : | albeu | 315 | dst += edged_width; |
196 : | } | ||
197 : | |||
198 : | |||
199 : | //U | ||
200 : | dst = image->u - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2); | ||
201 : | src = image->u; | ||
202 : | |||
203 : | for (i = 0; i < EDGE_SIZE2; i++) { | ||
204 : | memset(dst, *src, EDGE_SIZE2); | ||
205 : | memcpy(dst + EDGE_SIZE2, src, width2); | ||
206 : | memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1), | ||
207 : | EDGE_SIZE2); | ||
208 : | dst += edged_width2; | ||
209 : | } | ||
210 : | |||
211 : | for (i = 0; i < height / 2; i++) { | ||
212 : | memset(dst, *src, EDGE_SIZE2); | ||
213 : | memset(dst + edged_width2 - EDGE_SIZE2, src[width2 - 1], EDGE_SIZE2); | ||
214 : | dst += edged_width2; | ||
215 : | src += edged_width2; | ||
216 : | } | ||
217 : | src -= edged_width2; | ||
218 : | for (i = 0; i < EDGE_SIZE2; i++) { | ||
219 : | memset(dst, *src, EDGE_SIZE2); | ||
220 : | memcpy(dst + EDGE_SIZE2, src, width2); | ||
221 : | memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1), | ||
222 : | EDGE_SIZE2); | ||
223 : | dst += edged_width2; | ||
224 : | } | ||
225 : | |||
226 : | |||
227 : | // V | ||
228 : | dst = image->v - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2); | ||
229 : | src = image->v; | ||
230 : | |||
231 : | for (i = 0; i < EDGE_SIZE2; i++) { | ||
232 : | memset(dst, *src, EDGE_SIZE2); | ||
233 : | memcpy(dst + EDGE_SIZE2, src, width2); | ||
234 : | memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1), | ||
235 : | EDGE_SIZE2); | ||
236 : | dst += edged_width2; | ||
237 : | } | ||
238 : | |||
239 : | for (i = 0; i < height / 2; i++) { | ||
240 : | memset(dst, *src, EDGE_SIZE2); | ||
241 : | memset(dst + edged_width2 - EDGE_SIZE2, src[width2 - 1], EDGE_SIZE2); | ||
242 : | dst += edged_width2; | ||
243 : | src += edged_width2; | ||
244 : | } | ||
245 : | src -= edged_width2; | ||
246 : | for (i = 0; i < EDGE_SIZE2; i++) { | ||
247 : | memset(dst, *src, EDGE_SIZE2); | ||
248 : | memcpy(dst + EDGE_SIZE2, src, width2); | ||
249 : | memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1), | ||
250 : | EDGE_SIZE2); | ||
251 : | dst += edged_width2; | ||
252 : | } | ||
253 : | } | ||
254 : | |||
255 : | // bframe encoding requires image-based u,v interpolation | ||
256 : | void | ||
257 : | image_interpolate(const IMAGE * refn, | ||
258 : | IMAGE * refh, | ||
259 : | IMAGE * refv, | ||
260 : | IMAGE * refhv, | ||
261 : | uint32_t edged_width, | ||
262 : | uint32_t edged_height, | ||
263 : | uint32_t rounding) | ||
264 : | { | ||
265 : | const uint32_t offset = EDGE_SIZE * (edged_width + 1); | ||
266 : | const uint32_t stride_add = 7 * edged_width; | ||
267 : | |||
268 : | uint8_t *n_ptr, *h_ptr, *v_ptr, *hv_ptr; | ||
269 : | uint32_t x, y; | ||
270 : | |||
271 : | |||
272 : | n_ptr = refn->y; | ||
273 : | h_ptr = refh->y; | ||
274 : | v_ptr = refv->y; | ||
275 : | hv_ptr = refhv->y; | ||
276 : | |||
277 : | n_ptr -= offset; | ||
278 : | h_ptr -= offset; | ||
279 : | v_ptr -= offset; | ||
280 : | hv_ptr -= offset; | ||
281 : | |||
282 : | for (y = 0; y < edged_height; y = y + 8) { | ||
283 : | for (x = 0; x < edged_width; x = x + 8) { | ||
284 : | interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width, rounding); | ||
285 : | interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width, rounding); | ||
286 : | interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width, rounding); | ||
287 : | |||
288 : | n_ptr += 8; | ||
289 : | h_ptr += 8; | ||
290 : | v_ptr += 8; | ||
291 : | hv_ptr += 8; | ||
292 : | } | ||
293 : | h_ptr += stride_add; | ||
294 : | v_ptr += stride_add; | ||
295 : | hv_ptr += stride_add; | ||
296 : | n_ptr += stride_add; | ||
297 : | } | ||
298 : | |||
299 : | /* | ||
300 : | interpolate_halfpel_h( | ||
301 : | refh->y - offset, | ||
302 : | refn->y - offset, | ||
303 : | edged_width, edged_height, | ||
304 : | rounding); | ||
305 : | |||
306 : | interpolate_halfpel_v( | ||
307 : | refv->y - offset, | ||
308 : | refn->y - offset, | ||
309 : | edged_width, edged_height, | ||
310 : | rounding); | ||
311 : | |||
312 : | interpolate_halfpel_hv( | ||
313 : | refhv->y - offset, | ||
314 : | refn->y - offset, | ||
315 : | edged_width, edged_height, | ||
316 : | rounding); | ||
317 : | */ | ||
318 : | |||
319 : | /* uv-image-based compensation | ||
320 : | offset = EDGE_SIZE2 * (edged_width / 2 + 1); | ||
321 : | |||
322 : | interpolate_halfpel_h( | ||
323 : | refh->u - offset, | ||
324 : | refn->u - offset, | ||
325 : | edged_width / 2, edged_height / 2, | ||
326 : | rounding); | ||
327 : | |||
328 : | interpolate_halfpel_v( | ||
329 : | refv->u - offset, | ||
330 : | refn->u - offset, | ||
331 : | edged_width / 2, edged_height / 2, | ||
332 : | rounding); | ||
333 : | |||
334 : | interpolate_halfpel_hv( | ||
335 : | refhv->u - offset, | ||
336 : | refn->u - offset, | ||
337 : | edged_width / 2, edged_height / 2, | ||
338 : | rounding); | ||
339 : | |||
340 : | |||
341 : | interpolate_halfpel_h( | ||
342 : | refh->v - offset, | ||
343 : | refn->v - offset, | ||
344 : | edged_width / 2, edged_height / 2, | ||
345 : | rounding); | ||
346 : | |||
347 : | interpolate_halfpel_v( | ||
348 : | refv->v - offset, | ||
349 : | refn->v - offset, | ||
350 : | edged_width / 2, edged_height / 2, | ||
351 : | rounding); | ||
352 : | |||
353 : | interpolate_halfpel_hv( | ||
354 : | refhv->v - offset, | ||
355 : | refn->v - offset, | ||
356 : | edged_width / 2, edged_height / 2, | ||
357 : | rounding); | ||
358 : | */ | ||
359 : | } | ||
360 : | |||
361 : | |||
362 : | int | ||
363 : | image_input(IMAGE * image, | ||
364 : | uint32_t width, | ||
365 : | int height, | ||
366 : | uint32_t edged_width, | ||
367 : | uint8_t * src, | ||
368 : | int csp) | ||
369 : | { | ||
370 : | |||
371 : | /* if (csp & XVID_CSP_VFLIP) | ||
372 : | { | ||
373 : | height = -height; | ||
374 : | } | ||
375 : | */ | ||
376 : | |||
377 : | switch (csp & ~XVID_CSP_VFLIP) { | ||
378 : | case XVID_CSP_RGB555: | ||
379 : | rgb555_to_yv12(image->y, image->u, image->v, src, width, height, | ||
380 : | edged_width); | ||
381 : | return 0; | ||
382 : | |||
383 : | case XVID_CSP_RGB565: | ||
384 : | rgb565_to_yv12(image->y, image->u, image->v, src, width, height, | ||
385 : | edged_width); | ||
386 : | return 0; | ||
387 : | |||
388 : | |||
389 : | case XVID_CSP_RGB24: | ||
390 : | rgb24_to_yv12(image->y, image->u, image->v, src, width, height, | ||
391 : | edged_width); | ||
392 : | return 0; | ||
393 : | |||
394 : | case XVID_CSP_RGB32: | ||
395 : | rgb32_to_yv12(image->y, image->u, image->v, src, width, height, | ||
396 : | edged_width); | ||
397 : | return 0; | ||
398 : | |||
399 : | case XVID_CSP_I420: | ||
400 : | yuv_to_yv12(image->y, image->u, image->v, src, width, height, | ||
401 : | edged_width); | ||
402 : | return 0; | ||
403 : | |||
404 : | case XVID_CSP_YV12: /* u/v swapped */ | ||
405 : | yuv_to_yv12(image->y, image->v, image->u, src, width, height, | ||
406 : | edged_width); | ||
407 : | return 0; | ||
408 : | |||
409 : | case XVID_CSP_YUY2: | ||
410 : | yuyv_to_yv12(image->y, image->u, image->v, src, width, height, | ||
411 : | edged_width); | ||
412 : | return 0; | ||
413 : | |||
414 : | case XVID_CSP_YVYU: /* u/v swapped */ | ||
415 : | yuyv_to_yv12(image->y, image->v, image->u, src, width, height, | ||
416 : | edged_width); | ||
417 : | return 0; | ||
418 : | |||
419 : | case XVID_CSP_UYVY: | ||
420 : | uyvy_to_yv12(image->y, image->u, image->v, src, width, height, | ||
421 : | edged_width); | ||
422 : | return 0; | ||
423 : | |||
424 : | case XVID_CSP_USER: | ||
425 : | user_to_yuv_c(image->y, image->u, image->v, edged_width, | ||
426 : | (DEC_PICTURE *) src, width, height); | ||
427 : | return 0; | ||
428 : | |||
429 : | case XVID_CSP_NULL: | ||
430 : | break; | ||
431 : | |||
432 : | } | ||
433 : | |||
434 : | return -1; | ||
435 : | } | ||
436 : | |||
437 : | |||
438 : | |||
439 : | int | ||
440 : | image_output(IMAGE * image, | ||
441 : | uint32_t width, | ||
442 : | int height, | ||
443 : | uint32_t edged_width, | ||
444 : | uint8_t * dst, | ||
445 : | uint32_t dst_stride, | ||
446 : | int csp) | ||
447 : | { | ||
448 : | if (csp & XVID_CSP_VFLIP) { | ||
449 : | height = -height; | ||
450 : | } | ||
451 : | |||
452 : | switch (csp & ~XVID_CSP_VFLIP) { | ||
453 : | case XVID_CSP_RGB555: | ||
454 : | yv12_to_rgb555(dst, dst_stride, image->y, image->u, image->v, | ||
455 : | edged_width, edged_width / 2, width, height); | ||
456 : | return 0; | ||
457 : | |||
458 : | case XVID_CSP_RGB565: | ||
459 : | yv12_to_rgb565(dst, dst_stride, image->y, image->u, image->v, | ||
460 : | edged_width, edged_width / 2, width, height); | ||
461 : | return 0; | ||
462 : | |||
463 : | case XVID_CSP_RGB24: | ||
464 : | yv12_to_rgb24(dst, dst_stride, image->y, image->u, image->v, | ||
465 : | edged_width, edged_width / 2, width, height); | ||
466 : | return 0; | ||
467 : | |||
468 : | case XVID_CSP_RGB32: | ||
469 : | yv12_to_rgb32(dst, dst_stride, image->y, image->u, image->v, | ||
470 : | edged_width, edged_width / 2, width, height); | ||
471 : | return 0; | ||
472 : | |||
473 : | case XVID_CSP_I420: | ||
474 : | yv12_to_yuv(dst, dst_stride, image->y, image->u, image->v, edged_width, | ||
475 : | edged_width / 2, width, height); | ||
476 : | return 0; | ||
477 : | |||
478 : | case XVID_CSP_YV12: // u,v swapped | ||
479 : | yv12_to_yuv(dst, dst_stride, image->y, image->v, image->u, edged_width, | ||
480 : | edged_width / 2, width, height); | ||
481 : | return 0; | ||
482 : | |||
483 : | case XVID_CSP_YUY2: | ||
484 : | yv12_to_yuyv(dst, dst_stride, image->y, image->u, image->v, | ||
485 : | edged_width, edged_width / 2, width, height); | ||
486 : | return 0; | ||
487 : | |||
488 : | case XVID_CSP_YVYU: // u,v swapped | ||
489 : | yv12_to_yuyv(dst, dst_stride, image->y, image->v, image->u, | ||
490 : | edged_width, edged_width / 2, width, height); | ||
491 : | return 0; | ||
492 : | |||
493 : | case XVID_CSP_UYVY: | ||
494 : | yv12_to_uyvy(dst, dst_stride, image->y, image->u, image->v, | ||
495 : | edged_width, edged_width / 2, width, height); | ||
496 : | return 0; | ||
497 : | |||
498 : | case XVID_CSP_USER: | ||
499 : | ((DEC_PICTURE *) dst)->y = image->y; | ||
500 : | ((DEC_PICTURE *) dst)->u = image->u; | ||
501 : | ((DEC_PICTURE *) dst)->v = image->v; | ||
502 : | ((DEC_PICTURE *) dst)->stride_y = edged_width; | ||
503 : | ((DEC_PICTURE *) dst)->stride_uv = edged_width / 2; | ||
504 : | return 0; | ||
505 : | |||
506 : | case XVID_CSP_NULL: | ||
507 : | case XVID_CSP_EXTERN: | ||
508 : | return 0; | ||
509 : | |||
510 : | } | ||
511 : | |||
512 : | return -1; | ||
513 : | } | ||
514 : | |||
515 : | float | ||
516 : | image_psnr(IMAGE * orig_image, | ||
517 : | IMAGE * recon_image, | ||
518 : | uint16_t stride, | ||
519 : | uint16_t width, | ||
520 : | uint16_t height) | ||
521 : | { | ||
522 : | int32_t diff, x, y, quad = 0; | ||
523 : | uint8_t *orig = orig_image->y; | ||
524 : | uint8_t *recon = recon_image->y; | ||
525 : | float psnr_y; | ||
526 : | |||
527 : | for (y = 0; y < height; y++) { | ||
528 : | for (x = 0; x < width; x++) { | ||
529 : | diff = *(orig + x) - *(recon + x); | ||
530 : | quad += diff * diff; | ||
531 : | } | ||
532 : | orig += stride; | ||
533 : | recon += stride; | ||
534 : | } | ||
535 : | |||
536 : | psnr_y = (float) quad / (float) (width * height); | ||
537 : | |||
538 : | if (psnr_y) { | ||
539 : | psnr_y = (float) (255 * 255) / psnr_y; | ||
540 : | psnr_y = 10 * (float) log10(psnr_y); | ||
541 : | } else | ||
542 : | psnr_y = (float) 99.99; | ||
543 : | |||
544 : | return psnr_y; | ||
545 : | } | ||
546 : | |||
547 : | /* | ||
548 : | |||
549 : | #include <stdio.h> | ||
550 : | #include <string.h> | ||
551 : | |||
552 : | int image_dump_pgm(uint8_t * bmp, uint32_t width, uint32_t height, char * filename) | ||
553 : | { | ||
554 : | FILE * f; | ||
555 : | char hdr[1024]; | ||
556 : | |||
557 : | f = fopen(filename, "wb"); | ||
558 : | if ( f == NULL) | ||
559 : | { | ||
560 : | return -1; | ||
561 : | } | ||
562 : | sprintf(hdr, "P5\n#xvid\n%i %i\n255\n", width, height); | ||
563 : | fwrite(hdr, strlen(hdr), 1, f); | ||
564 : | fwrite(bmp, width, height, f); | ||
565 : | fclose(f); | ||
566 : | |||
567 : | return 0; | ||
568 : | } | ||
569 : | |||
570 : | |||
571 : | // dump image+edges to yuv pgm files | ||
572 : | |||
573 : | int image_dump(IMAGE * image, uint32_t edged_width, uint32_t edged_height, char * path, int number) | ||
574 : | { | ||
575 : | char filename[1024]; | ||
576 : | |||
577 : | sprintf(filename, "%s_%i_%c.pgm", path, number, 'y'); | ||
578 : | image_dump_pgm( | ||
579 : | image->y - (EDGE_SIZE * edged_width + EDGE_SIZE), | ||
580 : | edged_width, edged_height, filename); | ||
581 : | |||
582 : | sprintf(filename, "%s_%i_%c.pgm", path, number, 'u'); | ||
583 : | image_dump_pgm( | ||
584 : | image->u - (EDGE_SIZE2 * edged_width / 2 + EDGE_SIZE2), | ||
585 : | edged_width / 2, edged_height / 2, filename); | ||
586 : | |||
587 : | sprintf(filename, "%s_%i_%c.pgm", path, number, 'v'); | ||
588 : | image_dump_pgm( | ||
589 : | image->v - (EDGE_SIZE2 * edged_width / 2 + EDGE_SIZE2), | ||
590 : | edged_width / 2, edged_height / 2, filename); | ||
591 : | |||
592 : | return 0; | ||
593 : | } | ||
594 : | */ | ||
595 : | |||
596 : | |||
597 : | |||
598 : | /* dump image to yuvpgm file */ | ||
599 : | |||
600 : | #include <stdio.h> | ||
601 : | |||
602 : | int | ||
603 : | image_dump_yuvpgm(const IMAGE * image, | ||
604 : | const uint32_t edged_width, | ||
605 : | const uint32_t width, | ||
606 : | const uint32_t height, | ||
607 : | char *filename) | ||
608 : | { | ||
609 : | FILE *f; | ||
610 : | char hdr[1024]; | ||
611 : | uint32_t i; | ||
612 : | uint8_t *bmp1; | ||
613 : | uint8_t *bmp2; | ||
614 : | |||
615 : | |||
616 : | f = fopen(filename, "wb"); | ||
617 : | if (f == NULL) { | ||
618 : | return -1; | ||
619 : | } | ||
620 : | sprintf(hdr, "P5\n#xvid\n%i %i\n255\n", width, (3 * height) / 2); | ||
621 : | fwrite(hdr, strlen(hdr), 1, f); | ||
622 : | |||
623 : | bmp1 = image->y; | ||
624 : | for (i = 0; i < height; i++) { | ||
625 : | fwrite(bmp1, width, 1, f); | ||
626 : | bmp1 += edged_width; | ||
627 : | } | ||
628 : | |||
629 : | bmp1 = image->u; | ||
630 : | bmp2 = image->v; | ||
631 : | for (i = 0; i < height / 2; i++) { | ||
632 : | fwrite(bmp1, width / 2, 1, f); | ||
633 : | fwrite(bmp2, width / 2, 1, f); | ||
634 : | bmp1 += edged_width / 2; | ||
635 : | bmp2 += edged_width / 2; | ||
636 : | } | ||
637 : | |||
638 : | fclose(f); | ||
639 : | return 0; | ||
640 : | } | ||
641 : | |||
642 : | |||
643 : | #define ABS(X) (((X)>0)?(X):-(X)) | ||
644 : | float | ||
645 : | image_mad(const IMAGE * img1, | ||
646 : | const IMAGE * img2, | ||
647 : | uint32_t stride, | ||
648 : | uint32_t width, | ||
649 : | uint32_t height) | ||
650 : | { | ||
651 : | const uint32_t stride2 = stride / 2; | ||
652 : | const uint32_t width2 = width / 2; | ||
653 : | const uint32_t height2 = height / 2; | ||
654 : | |||
655 : | uint32_t x, y; | ||
656 : | uint32_t sum = 0; | ||
657 : | |||
658 : | for (y = 0; y < height; y++) | ||
659 : | for (x = 0; x < width; x++) | ||
660 : | sum += ABS(img1->y[x + y * stride] - img2->y[x + y * stride]); | ||
661 : | |||
662 : | for (y = 0; y < height2; y++) | ||
663 : | for (x = 0; x < width2; x++) | ||
664 : | sum += ABS(img1->u[x + y * stride2] - img2->u[x + y * stride2]); | ||
665 : | |||
666 : | for (y = 0; y < height2; y++) | ||
667 : | for (x = 0; x < width2; x++) | ||
668 : | sum += ABS(img1->v[x + y * stride2] - img2->v[x + y * stride2]); | ||
669 : | |||
670 : | return (float) sum / (width * height * 3 / 2); | ||
671 : | } | ||
672 : | |||
673 : | void | ||
674 : | output_slice(IMAGE * cur, int std, int width, XVID_DEC_PICTURE* out_frm, int mbx, int mby,int mbl) { | ||
675 : | uint8_t *dY,*dU,*dV,*sY,*sU,*sV; | ||
676 : | int std2 = std >> 1; | ||
677 : | int w = mbl << 4, w2,i; | ||
678 : | |||
679 : | if(w > width) | ||
680 : | w = width; | ||
681 : | w2 = w >> 1; | ||
682 : | suxen_drol | 323 | |
683 : | albeu | 315 | dY = (uint8_t*)out_frm->y + (mby << 4) * out_frm->stride_y + (mbx << 4); |
684 : | dU = (uint8_t*)out_frm->u + (mby << 3) * out_frm->stride_u + (mbx << 3); | ||
685 : | dV = (uint8_t*)out_frm->v + (mby << 3) * out_frm->stride_v + (mbx << 3); | ||
686 : | sY = cur->y + (mby << 4) * std + (mbx << 4); | ||
687 : | sU = cur->u + (mby << 3) * std2 + (mbx << 3); | ||
688 : | sV = cur->v + (mby << 3) * std2 + (mbx << 3); | ||
689 : | |||
690 : | for(i = 0 ; i < 16 ; i++) { | ||
691 : | memcpy(dY,sY,w); | ||
692 : | suxen_drol | 323 | dY += out_frm->stride_y; |
693 : | sY += std; | ||
694 : | } | ||
695 : | albeu | 315 | for(i = 0 ; i < 8 ; i++) { |
696 : | memcpy(dU,sU,w2); | ||
697 : | dU += out_frm->stride_u; | ||
698 : | sU += std2; | ||
699 : | } | ||
700 : | for(i = 0 ; i < 8 ; i++) { | ||
701 : | memcpy(dV,sV,w2); | ||
702 : | dV += out_frm->stride_v; | ||
703 : | sV += std2; | ||
704 : | } | ||
705 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |