[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 449 - (view) (download)

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

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