[svn] / branches / dev-api-3 / xvidcore / src / image / image.c Repository:
ViewVC logotype

Annotation of /branches/dev-api-3/xvidcore/src/image/image.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 579 - (view) (download)

1 : albeu 315 /**************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * image stuff
5 :     *
6 : chl 530 * 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 :     *
15 : albeu 315 * 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 :     *
20 :     * 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 :     *
25 :     * 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 :     *
29 :     *************************************************************************/
30 :    
31 :     /**************************************************************************
32 :     *
33 :     * History:
34 :     *
35 : Isibaar 579 * 05.10.2002 support for interpolated images in qpel mode - Isibaar
36 : albeu 315 * 01.05.2002 BFRAME image-based u,v interpolation
37 :     * 22.04.2002 added some B-frame support
38 :     * 14.04.2002 added image_dump_yuvpgm(), added image_mad()
39 :     * XVID_CSP_USER input support
40 : Isibaar 579 * 09.04.2002 PSNR calculations - Isibaar
41 : albeu 315 * 06.04.2002 removed interlaced edging from U,V blocks (as per spec)
42 :     * 26.03.2002 interlacing support (field-based edging in set_edges)
43 :     * 26.01.2002 rgb555, rgb565
44 :     * 07.01.2001 commented u,v interpolation (not required for uv-block-based)
45 :     * 23.12.2001 removed #ifdefs, added function pointers + init_common()
46 :     * 22.12.2001 cpu #ifdefs
47 :     * 19.12.2001 image_dump(); useful for debugging
48 :     * 6.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>
49 :     *
50 :     *************************************************************************/
51 :    
52 :     #include <stdlib.h>
53 :     #include <string.h> // memcpy, memset
54 :     #include <math.h>
55 :    
56 :     #include "../portab.h"
57 :     #include "../xvid.h"
58 :     #include "image.h"
59 :     #include "colorspace.h"
60 :     #include "interpolate8x8.h"
61 :     #include "../divx4.h"
62 :     #include "../utils/mem_align.h"
63 :    
64 :     #define SAFETY 64
65 :     #define EDGE_SIZE2 (EDGE_SIZE/2)
66 :    
67 :    
68 :     int32_t
69 :     image_create(IMAGE * image,
70 :     uint32_t edged_width,
71 :     uint32_t edged_height)
72 :     {
73 :     const uint32_t edged_width2 = edged_width / 2;
74 :     const uint32_t edged_height2 = edged_height / 2;
75 :     uint32_t i;
76 :    
77 :     image->y =
78 :     xvid_malloc(edged_width * (edged_height + 1) + SAFETY, CACHE_LINE);
79 :     if (image->y == NULL) {
80 :     return -1;
81 :     }
82 :    
83 :     for (i = 0; i < edged_width * edged_height + SAFETY; i++) {
84 :     image->y[i] = 0;
85 :     }
86 :    
87 :     image->u = xvid_malloc(edged_width2 * edged_height2 + SAFETY, CACHE_LINE);
88 :     if (image->u == NULL) {
89 :     xvid_free(image->y);
90 :     return -1;
91 :     }
92 :     image->v = xvid_malloc(edged_width2 * edged_height2 + SAFETY, CACHE_LINE);
93 :     if (image->v == NULL) {
94 :     xvid_free(image->u);
95 :     xvid_free(image->y);
96 :     return -1;
97 :     }
98 :    
99 :     image->y += EDGE_SIZE * edged_width + EDGE_SIZE;
100 :     image->u += EDGE_SIZE2 * edged_width2 + EDGE_SIZE2;
101 :     image->v += EDGE_SIZE2 * edged_width2 + EDGE_SIZE2;
102 :    
103 :     return 0;
104 :     }
105 :    
106 :    
107 :    
108 :     void
109 :     image_destroy(IMAGE * image,
110 :     uint32_t edged_width,
111 :     uint32_t edged_height)
112 :     {
113 :     const uint32_t edged_width2 = edged_width / 2;
114 :    
115 :     if (image->y) {
116 :     xvid_free(image->y - (EDGE_SIZE * edged_width + EDGE_SIZE));
117 :     }
118 :     if (image->u) {
119 :     xvid_free(image->u - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2));
120 :     }
121 :     if (image->v) {
122 :     xvid_free(image->v - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2));
123 :     }
124 :     }
125 :    
126 :    
127 :     void
128 :     image_swap(IMAGE * image1,
129 :     IMAGE * image2)
130 :     {
131 :     uint8_t *tmp;
132 :    
133 :     tmp = image1->y;
134 :     image1->y = image2->y;
135 :     image2->y = tmp;
136 :    
137 :     tmp = image1->u;
138 :     image1->u = image2->u;
139 :     image2->u = tmp;
140 :    
141 :     tmp = image1->v;
142 :     image1->v = image2->v;
143 :     image2->v = tmp;
144 :     }
145 :    
146 :    
147 :     void
148 :     image_copy(IMAGE * image1,
149 :     IMAGE * image2,
150 :     uint32_t edged_width,
151 :     uint32_t height)
152 :     {
153 :     memcpy(image1->y, image2->y, edged_width * height);
154 :     memcpy(image1->u, image2->u, edged_width * height / 4);
155 :     memcpy(image1->v, image2->v, edged_width * height / 4);
156 :     }
157 :    
158 :    
159 :     void
160 :     image_setedges(IMAGE * image,
161 :     uint32_t edged_width,
162 :     uint32_t edged_height,
163 :     uint32_t width,
164 : h 543 uint32_t height)
165 : albeu 315 {
166 :     const uint32_t edged_width2 = edged_width / 2;
167 :     const uint32_t width2 = width / 2;
168 :     uint32_t i;
169 :     uint8_t *dst;
170 :     uint8_t *src;
171 :    
172 :    
173 :     dst = image->y - (EDGE_SIZE + EDGE_SIZE * edged_width);
174 :     src = image->y;
175 :    
176 :     for (i = 0; i < EDGE_SIZE; i++) {
177 : h 543 memset(dst, *src, EDGE_SIZE);
178 :     memcpy(dst + EDGE_SIZE, src, width);
179 :     memset(dst + edged_width - EDGE_SIZE, *(src + width - 1),
180 :     EDGE_SIZE);
181 : albeu 315 dst += edged_width;
182 :     }
183 :    
184 :     for (i = 0; i < height; i++) {
185 :     memset(dst, *src, EDGE_SIZE);
186 :     memset(dst + edged_width - EDGE_SIZE, src[width - 1], EDGE_SIZE);
187 :     dst += edged_width;
188 :     src += edged_width;
189 :     }
190 :    
191 :     src -= edged_width;
192 :     for (i = 0; i < EDGE_SIZE; i++) {
193 : h 543 memset(dst, *src, EDGE_SIZE);
194 :     memcpy(dst + EDGE_SIZE, src, width);
195 :     memset(dst + edged_width - EDGE_SIZE, *(src + width - 1),
196 : albeu 315 EDGE_SIZE);
197 :     dst += edged_width;
198 :     }
199 :    
200 :    
201 :     //U
202 :     dst = image->u - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2);
203 :     src = image->u;
204 :    
205 :     for (i = 0; i < EDGE_SIZE2; i++) {
206 :     memset(dst, *src, EDGE_SIZE2);
207 :     memcpy(dst + EDGE_SIZE2, src, width2);
208 :     memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1),
209 :     EDGE_SIZE2);
210 :     dst += edged_width2;
211 :     }
212 :    
213 :     for (i = 0; i < height / 2; i++) {
214 :     memset(dst, *src, EDGE_SIZE2);
215 :     memset(dst + edged_width2 - EDGE_SIZE2, src[width2 - 1], EDGE_SIZE2);
216 :     dst += edged_width2;
217 :     src += edged_width2;
218 :     }
219 :     src -= edged_width2;
220 :     for (i = 0; i < EDGE_SIZE2; i++) {
221 :     memset(dst, *src, EDGE_SIZE2);
222 :     memcpy(dst + EDGE_SIZE2, src, width2);
223 :     memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1),
224 :     EDGE_SIZE2);
225 :     dst += edged_width2;
226 :     }
227 :    
228 :    
229 :     // V
230 :     dst = image->v - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2);
231 :     src = image->v;
232 :    
233 :     for (i = 0; i < EDGE_SIZE2; i++) {
234 :     memset(dst, *src, EDGE_SIZE2);
235 :     memcpy(dst + EDGE_SIZE2, src, width2);
236 :     memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1),
237 :     EDGE_SIZE2);
238 :     dst += edged_width2;
239 :     }
240 :    
241 :     for (i = 0; i < height / 2; i++) {
242 :     memset(dst, *src, EDGE_SIZE2);
243 :     memset(dst + edged_width2 - EDGE_SIZE2, src[width2 - 1], EDGE_SIZE2);
244 :     dst += edged_width2;
245 :     src += edged_width2;
246 :     }
247 :     src -= edged_width2;
248 :     for (i = 0; i < EDGE_SIZE2; i++) {
249 :     memset(dst, *src, EDGE_SIZE2);
250 :     memcpy(dst + EDGE_SIZE2, src, width2);
251 :     memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1),
252 :     EDGE_SIZE2);
253 :     dst += edged_width2;
254 :     }
255 :     }
256 :    
257 : chl 530 // bframe encoding requires image-based u,v interpolation
258 : albeu 315 void
259 :     image_interpolate(const IMAGE * refn,
260 :     IMAGE * refh,
261 :     IMAGE * refv,
262 :     IMAGE * refhv,
263 :     uint32_t edged_width,
264 :     uint32_t edged_height,
265 : Isibaar 579 uint32_t quarterpel,
266 : albeu 315 uint32_t rounding)
267 :     {
268 :     const uint32_t offset = EDGE_SIZE * (edged_width + 1);
269 :     const uint32_t stride_add = 7 * edged_width;
270 :    
271 : chl 530 #ifdef BFRAMES
272 : albeu 315 const uint32_t edged_width2 = edged_width / 2;
273 :     const uint32_t edged_height2 = edged_height / 2;
274 :     const uint32_t offset2 = EDGE_SIZE2 * (edged_width2 + 1);
275 :     const uint32_t stride_add2 = 7 * edged_width2;
276 : chl 530 #endif
277 : albeu 315
278 :     uint8_t *n_ptr, *h_ptr, *v_ptr, *hv_ptr;
279 :     uint32_t x, y;
280 :    
281 :    
282 :     n_ptr = refn->y;
283 :     h_ptr = refh->y;
284 :     v_ptr = refv->y;
285 :     hv_ptr = refhv->y;
286 :    
287 :     n_ptr -= offset;
288 :     h_ptr -= offset;
289 :     v_ptr -= offset;
290 :     hv_ptr -= offset;
291 :    
292 : Isibaar 579 if(quarterpel) {
293 :    
294 :     for (y = 0; y < edged_height; y += 8) {
295 :     for (x = 0; x < edged_width; x += 8) {
296 :     interpolate8x8_6tap_lowpass_h(h_ptr, n_ptr, edged_width, rounding);
297 :     interpolate8x8_6tap_lowpass_v(v_ptr, n_ptr, edged_width, rounding);
298 : albeu 315
299 : Isibaar 579 n_ptr += 8;
300 :     h_ptr += 8;
301 :     v_ptr += 8;
302 :     }
303 :    
304 :     h_ptr += stride_add;
305 :     v_ptr += stride_add;
306 :     n_ptr += stride_add;
307 : albeu 315 }
308 : Isibaar 579
309 :     h_ptr = refh->y;
310 :     h_ptr -= offset;
311 :    
312 :     for (y = 0; y < edged_height; y = y + 8) {
313 :     for (x = 0; x < edged_width; x = x + 8) {
314 :     interpolate8x8_6tap_lowpass_v(hv_ptr, h_ptr, edged_width, rounding);
315 :     hv_ptr += 8;
316 :     h_ptr += 8;
317 :     }
318 :     hv_ptr += stride_add;
319 :     h_ptr += stride_add;
320 :     }
321 : albeu 315 }
322 : Isibaar 579 else {
323 :    
324 :     for (y = 0; y < edged_height; y += 8) {
325 :     for (x = 0; x < edged_width; x += 8) {
326 :     interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width, rounding);
327 :     interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width, rounding);
328 :     interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width, rounding);
329 :    
330 :     n_ptr += 8;
331 :     h_ptr += 8;
332 :     v_ptr += 8;
333 :     hv_ptr += 8;
334 :     }
335 :    
336 :     h_ptr += stride_add;
337 :     v_ptr += stride_add;
338 :     hv_ptr += stride_add;
339 :     n_ptr += stride_add;
340 :     }
341 :     }
342 : chl 530 /*
343 :     #ifdef BFRAMES
344 : albeu 315 n_ptr = refn->u;
345 :     h_ptr = refh->u;
346 :     v_ptr = refv->u;
347 :     hv_ptr = refhv->u;
348 :    
349 :     n_ptr -= offset2;
350 :     h_ptr -= offset2;
351 :     v_ptr -= offset2;
352 :     hv_ptr -= offset2;
353 :    
354 : chl 530 for (y = 0; y < edged_height2; y += 8) {
355 :     for (x = 0; x < edged_width2; x += 8) {
356 : albeu 315 interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width2, rounding);
357 :     interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width2, rounding);
358 :     interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width2, rounding);
359 :    
360 :     n_ptr += 8;
361 :     h_ptr += 8;
362 :     v_ptr += 8;
363 :     hv_ptr += 8;
364 :     }
365 :     h_ptr += stride_add2;
366 :     v_ptr += stride_add2;
367 :     hv_ptr += stride_add2;
368 :     n_ptr += stride_add2;
369 :     }
370 :    
371 :     n_ptr = refn->v;
372 :     h_ptr = refh->v;
373 :     v_ptr = refv->v;
374 :     hv_ptr = refhv->v;
375 :    
376 :     n_ptr -= offset2;
377 :     h_ptr -= offset2;
378 :     v_ptr -= offset2;
379 :     hv_ptr -= offset2;
380 :    
381 :     for (y = 0; y < edged_height2; y = y + 8) {
382 :     for (x = 0; x < edged_width2; x = x + 8) {
383 :     interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width2, rounding);
384 :     interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width2, rounding);
385 :     interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width2, rounding);
386 :    
387 :     n_ptr += 8;
388 :     h_ptr += 8;
389 :     v_ptr += 8;
390 :     hv_ptr += 8;
391 :     }
392 :     h_ptr += stride_add2;
393 :     v_ptr += stride_add2;
394 :     hv_ptr += stride_add2;
395 :     n_ptr += stride_add2;
396 :     }
397 : chl 530 #endif
398 : suxen_drol 449 */
399 : chl 530 /*
400 :     interpolate_halfpel_h(
401 :     refh->y - offset,
402 :     refn->y - offset,
403 :     edged_width, edged_height,
404 :     rounding);
405 :    
406 :     interpolate_halfpel_v(
407 :     refv->y - offset,
408 :     refn->y - offset,
409 :     edged_width, edged_height,
410 :     rounding);
411 :    
412 :     interpolate_halfpel_hv(
413 :     refhv->y - offset,
414 :     refn->y - offset,
415 :     edged_width, edged_height,
416 :     rounding);
417 :     */
418 :    
419 :     /* uv-image-based compensation
420 :     offset = EDGE_SIZE2 * (edged_width / 2 + 1);
421 :    
422 :     interpolate_halfpel_h(
423 :     refh->u - offset,
424 :     refn->u - offset,
425 :     edged_width / 2, edged_height / 2,
426 :     rounding);
427 :    
428 :     interpolate_halfpel_v(
429 :     refv->u - offset,
430 :     refn->u - offset,
431 :     edged_width / 2, edged_height / 2,
432 :     rounding);
433 :    
434 :     interpolate_halfpel_hv(
435 :     refhv->u - offset,
436 :     refn->u - offset,
437 :     edged_width / 2, edged_height / 2,
438 :     rounding);
439 :    
440 :    
441 :     interpolate_halfpel_h(
442 :     refh->v - offset,
443 :     refn->v - offset,
444 :     edged_width / 2, edged_height / 2,
445 :     rounding);
446 :    
447 :     interpolate_halfpel_v(
448 :     refv->v - offset,
449 :     refn->v - offset,
450 :     edged_width / 2, edged_height / 2,
451 :     rounding);
452 :    
453 :     interpolate_halfpel_hv(
454 :     refhv->v - offset,
455 :     refn->v - offset,
456 :     edged_width / 2, edged_height / 2,
457 :     rounding);
458 :     */
459 : albeu 315 }
460 :    
461 :    
462 :     int
463 :     image_input(IMAGE * image,
464 :     uint32_t width,
465 :     int height,
466 :     uint32_t edged_width,
467 :     uint8_t * src,
468 :     int csp)
469 :     {
470 :    
471 :     /* if (csp & XVID_CSP_VFLIP)
472 :     {
473 :     height = -height;
474 :     }
475 :     */
476 :    
477 :     switch (csp & ~XVID_CSP_VFLIP) {
478 :     case XVID_CSP_RGB555:
479 :     rgb555_to_yv12(image->y, image->u, image->v, src, width, height,
480 :     edged_width);
481 :     return 0;
482 :    
483 :     case XVID_CSP_RGB565:
484 :     rgb565_to_yv12(image->y, image->u, image->v, src, width, height,
485 :     edged_width);
486 :     return 0;
487 :    
488 :    
489 :     case XVID_CSP_RGB24:
490 :     rgb24_to_yv12(image->y, image->u, image->v, src, width, height,
491 :     edged_width);
492 :     return 0;
493 :    
494 :     case XVID_CSP_RGB32:
495 :     rgb32_to_yv12(image->y, image->u, image->v, src, width, height,
496 :     edged_width);
497 :     return 0;
498 :    
499 :     case XVID_CSP_I420:
500 :     yuv_to_yv12(image->y, image->u, image->v, src, width, height,
501 :     edged_width);
502 :     return 0;
503 :    
504 :     case XVID_CSP_YV12: /* u/v swapped */
505 :     yuv_to_yv12(image->y, image->v, image->u, src, width, height,
506 :     edged_width);
507 :     return 0;
508 :    
509 :     case XVID_CSP_YUY2:
510 :     yuyv_to_yv12(image->y, image->u, image->v, src, width, height,
511 :     edged_width);
512 :     return 0;
513 :    
514 :     case XVID_CSP_YVYU: /* u/v swapped */
515 :     yuyv_to_yv12(image->y, image->v, image->u, src, width, height,
516 :     edged_width);
517 :     return 0;
518 :    
519 :     case XVID_CSP_UYVY:
520 :     uyvy_to_yv12(image->y, image->u, image->v, src, width, height,
521 :     edged_width);
522 :     return 0;
523 :    
524 :     case XVID_CSP_USER:
525 :     user_to_yuv_c(image->y, image->u, image->v, edged_width,
526 :     (DEC_PICTURE *) src, width, height);
527 :     return 0;
528 :    
529 :     case XVID_CSP_NULL:
530 :     break;
531 :    
532 :     }
533 :    
534 :     return -1;
535 :     }
536 :    
537 :    
538 :    
539 :     int
540 :     image_output(IMAGE * image,
541 :     uint32_t width,
542 :     int height,
543 :     uint32_t edged_width,
544 :     uint8_t * dst,
545 :     uint32_t dst_stride,
546 :     int csp)
547 :     {
548 :     if (csp & XVID_CSP_VFLIP) {
549 :     height = -height;
550 :     }
551 :    
552 :     switch (csp & ~XVID_CSP_VFLIP) {
553 :     case XVID_CSP_RGB555:
554 :     yv12_to_rgb555(dst, dst_stride, image->y, image->u, image->v,
555 :     edged_width, edged_width / 2, width, height);
556 :     return 0;
557 :    
558 :     case XVID_CSP_RGB565:
559 :     yv12_to_rgb565(dst, dst_stride, image->y, image->u, image->v,
560 :     edged_width, edged_width / 2, width, height);
561 :     return 0;
562 :    
563 :     case XVID_CSP_RGB24:
564 :     yv12_to_rgb24(dst, dst_stride, image->y, image->u, image->v,
565 :     edged_width, edged_width / 2, width, height);
566 :     return 0;
567 :    
568 :     case XVID_CSP_RGB32:
569 :     yv12_to_rgb32(dst, dst_stride, image->y, image->u, image->v,
570 :     edged_width, edged_width / 2, width, height);
571 :     return 0;
572 :    
573 :     case XVID_CSP_I420:
574 :     yv12_to_yuv(dst, dst_stride, image->y, image->u, image->v, edged_width,
575 :     edged_width / 2, width, height);
576 :     return 0;
577 :    
578 :     case XVID_CSP_YV12: // u,v swapped
579 :     yv12_to_yuv(dst, dst_stride, image->y, image->v, image->u, edged_width,
580 :     edged_width / 2, width, height);
581 :     return 0;
582 :    
583 :     case XVID_CSP_YUY2:
584 :     yv12_to_yuyv(dst, dst_stride, image->y, image->u, image->v,
585 :     edged_width, edged_width / 2, width, height);
586 :     return 0;
587 :    
588 :     case XVID_CSP_YVYU: // u,v swapped
589 :     yv12_to_yuyv(dst, dst_stride, image->y, image->v, image->u,
590 :     edged_width, edged_width / 2, width, height);
591 :     return 0;
592 :    
593 :     case XVID_CSP_UYVY:
594 :     yv12_to_uyvy(dst, dst_stride, image->y, image->u, image->v,
595 :     edged_width, edged_width / 2, width, height);
596 :     return 0;
597 :    
598 :     case XVID_CSP_USER:
599 :     ((DEC_PICTURE *) dst)->y = image->y;
600 :     ((DEC_PICTURE *) dst)->u = image->u;
601 :     ((DEC_PICTURE *) dst)->v = image->v;
602 :     ((DEC_PICTURE *) dst)->stride_y = edged_width;
603 :     ((DEC_PICTURE *) dst)->stride_uv = edged_width / 2;
604 :     return 0;
605 :    
606 :     case XVID_CSP_NULL:
607 :     case XVID_CSP_EXTERN:
608 :     return 0;
609 :    
610 :     }
611 :    
612 :     return -1;
613 :     }
614 :    
615 :     float
616 :     image_psnr(IMAGE * orig_image,
617 :     IMAGE * recon_image,
618 :     uint16_t stride,
619 :     uint16_t width,
620 :     uint16_t height)
621 :     {
622 :     int32_t diff, x, y, quad = 0;
623 :     uint8_t *orig = orig_image->y;
624 :     uint8_t *recon = recon_image->y;
625 :     float psnr_y;
626 :    
627 :     for (y = 0; y < height; y++) {
628 :     for (x = 0; x < width; x++) {
629 :     diff = *(orig + x) - *(recon + x);
630 :     quad += diff * diff;
631 :     }
632 :     orig += stride;
633 :     recon += stride;
634 :     }
635 :    
636 :     psnr_y = (float) quad / (float) (width * height);
637 :    
638 :     if (psnr_y) {
639 :     psnr_y = (float) (255 * 255) / psnr_y;
640 :     psnr_y = 10 * (float) log10(psnr_y);
641 :     } else
642 :     psnr_y = (float) 99.99;
643 :    
644 :     return psnr_y;
645 :     }
646 :    
647 :     /*
648 :    
649 :     #include <stdio.h>
650 :     #include <string.h>
651 :    
652 :     int image_dump_pgm(uint8_t * bmp, uint32_t width, uint32_t height, char * filename)
653 :     {
654 :     FILE * f;
655 :     char hdr[1024];
656 :    
657 :     f = fopen(filename, "wb");
658 :     if ( f == NULL)
659 :     {
660 :     return -1;
661 :     }
662 :     sprintf(hdr, "P5\n#xvid\n%i %i\n255\n", width, height);
663 :     fwrite(hdr, strlen(hdr), 1, f);
664 :     fwrite(bmp, width, height, f);
665 :     fclose(f);
666 :    
667 :     return 0;
668 :     }
669 :    
670 :    
671 :     // dump image+edges to yuv pgm files
672 :    
673 :     int image_dump(IMAGE * image, uint32_t edged_width, uint32_t edged_height, char * path, int number)
674 :     {
675 :     char filename[1024];
676 :    
677 :     sprintf(filename, "%s_%i_%c.pgm", path, number, 'y');
678 :     image_dump_pgm(
679 :     image->y - (EDGE_SIZE * edged_width + EDGE_SIZE),
680 :     edged_width, edged_height, filename);
681 :    
682 :     sprintf(filename, "%s_%i_%c.pgm", path, number, 'u');
683 :     image_dump_pgm(
684 :     image->u - (EDGE_SIZE2 * edged_width / 2 + EDGE_SIZE2),
685 :     edged_width / 2, edged_height / 2, filename);
686 :    
687 :     sprintf(filename, "%s_%i_%c.pgm", path, number, 'v');
688 :     image_dump_pgm(
689 :     image->v - (EDGE_SIZE2 * edged_width / 2 + EDGE_SIZE2),
690 :     edged_width / 2, edged_height / 2, filename);
691 :    
692 :     return 0;
693 :     }
694 :     */
695 :    
696 :    
697 :    
698 :     /* dump image to yuvpgm file */
699 :    
700 :     #include <stdio.h>
701 :    
702 :     int
703 :     image_dump_yuvpgm(const IMAGE * image,
704 :     const uint32_t edged_width,
705 :     const uint32_t width,
706 :     const uint32_t height,
707 :     char *filename)
708 :     {
709 :     FILE *f;
710 :     char hdr[1024];
711 :     uint32_t i;
712 :     uint8_t *bmp1;
713 :     uint8_t *bmp2;
714 :    
715 :    
716 :     f = fopen(filename, "wb");
717 :     if (f == NULL) {
718 :     return -1;
719 :     }
720 :     sprintf(hdr, "P5\n#xvid\n%i %i\n255\n", width, (3 * height) / 2);
721 :     fwrite(hdr, strlen(hdr), 1, f);
722 :    
723 :     bmp1 = image->y;
724 :     for (i = 0; i < height; i++) {
725 :     fwrite(bmp1, width, 1, f);
726 :     bmp1 += edged_width;
727 :     }
728 :    
729 :     bmp1 = image->u;
730 :     bmp2 = image->v;
731 :     for (i = 0; i < height / 2; i++) {
732 :     fwrite(bmp1, width / 2, 1, f);
733 :     fwrite(bmp2, width / 2, 1, f);
734 :     bmp1 += edged_width / 2;
735 :     bmp2 += edged_width / 2;
736 :     }
737 :    
738 :     fclose(f);
739 :     return 0;
740 :     }
741 :    
742 :    
743 :     #define ABS(X) (((X)>0)?(X):-(X))
744 :     float
745 :     image_mad(const IMAGE * img1,
746 :     const IMAGE * img2,
747 :     uint32_t stride,
748 :     uint32_t width,
749 :     uint32_t height)
750 :     {
751 :     const uint32_t stride2 = stride / 2;
752 :     const uint32_t width2 = width / 2;
753 :     const uint32_t height2 = height / 2;
754 :    
755 :     uint32_t x, y;
756 :     uint32_t sum = 0;
757 :    
758 :     for (y = 0; y < height; y++)
759 :     for (x = 0; x < width; x++)
760 :     sum += ABS(img1->y[x + y * stride] - img2->y[x + y * stride]);
761 :    
762 :     for (y = 0; y < height2; y++)
763 :     for (x = 0; x < width2; x++)
764 :     sum += ABS(img1->u[x + y * stride2] - img2->u[x + y * stride2]);
765 :    
766 :     for (y = 0; y < height2; y++)
767 :     for (x = 0; x < width2; x++)
768 :     sum += ABS(img1->v[x + y * stride2] - img2->v[x + y * stride2]);
769 :    
770 :     return (float) sum / (width * height * 3 / 2);
771 :     }
772 :    
773 :     void
774 :     output_slice(IMAGE * cur, int std, int width, XVID_DEC_PICTURE* out_frm, int mbx, int mby,int mbl) {
775 :     uint8_t *dY,*dU,*dV,*sY,*sU,*sV;
776 :     int std2 = std >> 1;
777 :     int w = mbl << 4, w2,i;
778 :    
779 :     if(w > width)
780 :     w = width;
781 :     w2 = w >> 1;
782 : suxen_drol 323
783 : albeu 315 dY = (uint8_t*)out_frm->y + (mby << 4) * out_frm->stride_y + (mbx << 4);
784 :     dU = (uint8_t*)out_frm->u + (mby << 3) * out_frm->stride_u + (mbx << 3);
785 :     dV = (uint8_t*)out_frm->v + (mby << 3) * out_frm->stride_v + (mbx << 3);
786 :     sY = cur->y + (mby << 4) * std + (mbx << 4);
787 :     sU = cur->u + (mby << 3) * std2 + (mbx << 3);
788 :     sV = cur->v + (mby << 3) * std2 + (mbx << 3);
789 :    
790 :     for(i = 0 ; i < 16 ; i++) {
791 :     memcpy(dY,sY,w);
792 : suxen_drol 323 dY += out_frm->stride_y;
793 :     sY += std;
794 :     }
795 : albeu 315 for(i = 0 ; i < 8 ; i++) {
796 :     memcpy(dU,sU,w2);
797 :     dU += out_frm->stride_u;
798 :     sU += std2;
799 :     }
800 :     for(i = 0 ; i < 8 ; i++) {
801 :     memcpy(dV,sV,w2);
802 :     dV += out_frm->stride_v;
803 :     sV += std2;
804 :     }
805 :     }

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4