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

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