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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 890 - (view) (download)

1 : edgomez 851 /**************************************************************************
2 : albeu 315 *
3 : edgomez 851 * XVID MPEG-4 VIDEO CODEC
4 :     * image stuff
5 : albeu 315 *
6 : edgomez 851 * 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 : albeu 315 *
15 : edgomez 851 * 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 : albeu 315 *
20 : edgomez 851 * 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 : albeu 315 *
25 : edgomez 851 * 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 : albeu 315 *
29 : edgomez 851 *************************************************************************/
30 :    
31 :     /**************************************************************************
32 : albeu 315 *
33 : edgomez 851 * History:
34 : edgomez 651 *
35 : edgomez 851 * 05.10.2002 support for interpolated images in qpel mode - Isibaar
36 :     * 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 :     * 09.04.2002 PSNR calculations - Isibaar
41 :     * 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 : edgomez 651 *
50 : edgomez 851 *************************************************************************/
51 : albeu 315
52 :     #include <stdlib.h>
53 : edgomez 851 #include <string.h> // memcpy, memset
54 : albeu 315 #include <math.h>
55 :    
56 :     #include "../portab.h"
57 : edgomez 851 #include "../global.h"
58 :     #include "../xvid.h"
59 : albeu 315 #include "image.h"
60 :     #include "colorspace.h"
61 :     #include "interpolate8x8.h"
62 : edgomez 851 #include "reduced.h"
63 : albeu 315 #include "../utils/mem_align.h"
64 :    
65 : edgomez 851 #include "font.h"
66 :    
67 : albeu 315 #define SAFETY 64
68 :     #define EDGE_SIZE2 (EDGE_SIZE/2)
69 :    
70 :    
71 :     int32_t
72 :     image_create(IMAGE * image,
73 :     uint32_t edged_width,
74 :     uint32_t edged_height)
75 :     {
76 :     const uint32_t edged_width2 = edged_width / 2;
77 :     const uint32_t edged_height2 = edged_height / 2;
78 :     uint32_t i;
79 :    
80 :     image->y =
81 :     xvid_malloc(edged_width * (edged_height + 1) + SAFETY, CACHE_LINE);
82 :     if (image->y == NULL) {
83 :     return -1;
84 :     }
85 :    
86 :     for (i = 0; i < edged_width * edged_height + SAFETY; i++) {
87 :     image->y[i] = 0;
88 :     }
89 :    
90 :     image->u = xvid_malloc(edged_width2 * edged_height2 + SAFETY, CACHE_LINE);
91 :     if (image->u == NULL) {
92 :     xvid_free(image->y);
93 :     return -1;
94 :     }
95 :     image->v = xvid_malloc(edged_width2 * edged_height2 + SAFETY, CACHE_LINE);
96 :     if (image->v == NULL) {
97 :     xvid_free(image->u);
98 :     xvid_free(image->y);
99 :     return -1;
100 :     }
101 :    
102 :     image->y += EDGE_SIZE * edged_width + EDGE_SIZE;
103 :     image->u += EDGE_SIZE2 * edged_width2 + EDGE_SIZE2;
104 :     image->v += EDGE_SIZE2 * edged_width2 + EDGE_SIZE2;
105 :    
106 :     return 0;
107 :     }
108 :    
109 :    
110 :    
111 :     void
112 :     image_destroy(IMAGE * image,
113 :     uint32_t edged_width,
114 :     uint32_t edged_height)
115 :     {
116 :     const uint32_t edged_width2 = edged_width / 2;
117 :    
118 :     if (image->y) {
119 :     xvid_free(image->y - (EDGE_SIZE * edged_width + EDGE_SIZE));
120 :     }
121 :     if (image->u) {
122 :     xvid_free(image->u - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2));
123 :     }
124 :     if (image->v) {
125 :     xvid_free(image->v - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2));
126 :     }
127 :     }
128 :    
129 :    
130 :     void
131 :     image_swap(IMAGE * image1,
132 :     IMAGE * image2)
133 :     {
134 :     uint8_t *tmp;
135 :    
136 :     tmp = image1->y;
137 :     image1->y = image2->y;
138 :     image2->y = tmp;
139 :    
140 :     tmp = image1->u;
141 :     image1->u = image2->u;
142 :     image2->u = tmp;
143 :    
144 :     tmp = image1->v;
145 :     image1->v = image2->v;
146 :     image2->v = tmp;
147 :     }
148 :    
149 :    
150 :     void
151 :     image_copy(IMAGE * image1,
152 :     IMAGE * image2,
153 :     uint32_t edged_width,
154 :     uint32_t height)
155 :     {
156 :     memcpy(image1->y, image2->y, edged_width * height);
157 :     memcpy(image1->u, image2->u, edged_width * height / 4);
158 :     memcpy(image1->v, image2->v, edged_width * height / 4);
159 :     }
160 :    
161 :    
162 :     void
163 :     image_setedges(IMAGE * image,
164 :     uint32_t edged_width,
165 :     uint32_t edged_height,
166 :     uint32_t width,
167 : h 541 uint32_t height)
168 : albeu 315 {
169 :     const uint32_t edged_width2 = edged_width / 2;
170 :     const uint32_t width2 = width / 2;
171 :     uint32_t i;
172 :     uint8_t *dst;
173 :     uint8_t *src;
174 :    
175 :    
176 :     dst = image->y - (EDGE_SIZE + EDGE_SIZE * edged_width);
177 :     src = image->y;
178 :    
179 :     for (i = 0; i < EDGE_SIZE; i++) {
180 : edgomez 851 memset(dst, *src, EDGE_SIZE);
181 :     memcpy(dst + EDGE_SIZE, src, width);
182 :     memset(dst + edged_width - EDGE_SIZE, *(src + width - 1),
183 :     EDGE_SIZE);
184 : albeu 315 dst += edged_width;
185 :     }
186 :    
187 :     for (i = 0; i < height; i++) {
188 :     memset(dst, *src, EDGE_SIZE);
189 :     memset(dst + edged_width - EDGE_SIZE, src[width - 1], EDGE_SIZE);
190 :     dst += edged_width;
191 :     src += edged_width;
192 :     }
193 :    
194 :     src -= edged_width;
195 :     for (i = 0; i < EDGE_SIZE; i++) {
196 : edgomez 851 memset(dst, *src, EDGE_SIZE);
197 :     memcpy(dst + EDGE_SIZE, src, width);
198 :     memset(dst + edged_width - EDGE_SIZE, *(src + width - 1),
199 : albeu 315 EDGE_SIZE);
200 :     dst += edged_width;
201 :     }
202 :    
203 :    
204 : edgomez 851 //U
205 : albeu 315 dst = image->u - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2);
206 :     src = image->u;
207 :    
208 :     for (i = 0; i < EDGE_SIZE2; i++) {
209 :     memset(dst, *src, EDGE_SIZE2);
210 :     memcpy(dst + EDGE_SIZE2, src, width2);
211 :     memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1),
212 :     EDGE_SIZE2);
213 :     dst += edged_width2;
214 :     }
215 :    
216 :     for (i = 0; i < height / 2; i++) {
217 :     memset(dst, *src, EDGE_SIZE2);
218 :     memset(dst + edged_width2 - EDGE_SIZE2, src[width2 - 1], EDGE_SIZE2);
219 :     dst += edged_width2;
220 :     src += edged_width2;
221 :     }
222 :     src -= edged_width2;
223 :     for (i = 0; i < EDGE_SIZE2; i++) {
224 :     memset(dst, *src, EDGE_SIZE2);
225 :     memcpy(dst + EDGE_SIZE2, src, width2);
226 :     memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1),
227 :     EDGE_SIZE2);
228 :     dst += edged_width2;
229 :     }
230 :    
231 :    
232 : edgomez 851 // V
233 : albeu 315 dst = image->v - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2);
234 :     src = image->v;
235 :    
236 :     for (i = 0; i < EDGE_SIZE2; i++) {
237 :     memset(dst, *src, EDGE_SIZE2);
238 :     memcpy(dst + EDGE_SIZE2, src, width2);
239 :     memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1),
240 :     EDGE_SIZE2);
241 :     dst += edged_width2;
242 :     }
243 :    
244 :     for (i = 0; i < height / 2; i++) {
245 :     memset(dst, *src, EDGE_SIZE2);
246 :     memset(dst + edged_width2 - EDGE_SIZE2, src[width2 - 1], EDGE_SIZE2);
247 :     dst += edged_width2;
248 :     src += edged_width2;
249 :     }
250 :     src -= edged_width2;
251 :     for (i = 0; i < EDGE_SIZE2; i++) {
252 :     memset(dst, *src, EDGE_SIZE2);
253 :     memcpy(dst + EDGE_SIZE2, src, width2);
254 :     memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1),
255 :     EDGE_SIZE2);
256 :     dst += edged_width2;
257 :     }
258 :     }
259 :    
260 : edgomez 851 // bframe encoding requires image-based u,v interpolation
261 : albeu 315 void
262 :     image_interpolate(const IMAGE * refn,
263 :     IMAGE * refh,
264 :     IMAGE * refv,
265 :     IMAGE * refhv,
266 :     uint32_t edged_width,
267 :     uint32_t edged_height,
268 : edgomez 851 uint32_t quarterpel,
269 : albeu 315 uint32_t rounding)
270 :     {
271 : edgomez 851 const uint32_t offset = EDGE_SIZE2 * (edged_width + 1); // we only interpolate half of the edge area
272 : albeu 315 const uint32_t stride_add = 7 * edged_width;
273 : edgomez 851 /*
274 :     #ifdef BFRAMES
275 :     const uint32_t edged_width2 = edged_width / 2;
276 :     const uint32_t edged_height2 = edged_height / 2;
277 :     const uint32_t offset2 = EDGE_SIZE2 * (edged_width2 + 1);
278 :     const uint32_t stride_add2 = 7 * edged_width2;
279 :     #endif
280 :     */
281 : albeu 315 uint8_t *n_ptr, *h_ptr, *v_ptr, *hv_ptr;
282 :     uint32_t x, y;
283 :    
284 :    
285 :     n_ptr = refn->y;
286 :     h_ptr = refh->y;
287 :     v_ptr = refv->y;
288 :     hv_ptr = refhv->y;
289 :    
290 :     n_ptr -= offset;
291 :     h_ptr -= offset;
292 :     v_ptr -= offset;
293 :     hv_ptr -= offset;
294 :    
295 : edgomez 851 if(quarterpel) {
296 :    
297 :     for (y = 0; y < (edged_height - EDGE_SIZE); y += 8) {
298 :     for (x = 0; x < (edged_width - EDGE_SIZE); x += 8) {
299 :     interpolate8x8_6tap_lowpass_h(h_ptr, n_ptr, edged_width, rounding);
300 :     interpolate8x8_6tap_lowpass_v(v_ptr, n_ptr, edged_width, rounding);
301 : albeu 315
302 : edgomez 851 n_ptr += 8;
303 :     h_ptr += 8;
304 :     v_ptr += 8;
305 :     }
306 :    
307 :     n_ptr += EDGE_SIZE;
308 :     h_ptr += EDGE_SIZE;
309 :     v_ptr += EDGE_SIZE;
310 :    
311 :     h_ptr += stride_add;
312 :     v_ptr += stride_add;
313 :     n_ptr += stride_add;
314 :     }
315 :    
316 :     h_ptr = refh->y;
317 :     h_ptr -= offset;
318 :    
319 :     for (y = 0; y < (edged_height - EDGE_SIZE); y = y + 8) {
320 :     for (x = 0; x < (edged_width - EDGE_SIZE); x = x + 8) {
321 :     interpolate8x8_6tap_lowpass_v(hv_ptr, h_ptr, edged_width, rounding);
322 :     hv_ptr += 8;
323 :     h_ptr += 8;
324 :     }
325 :    
326 :     hv_ptr += EDGE_SIZE;
327 :     h_ptr += EDGE_SIZE;
328 :    
329 :     hv_ptr += stride_add;
330 :     h_ptr += stride_add;
331 :     }
332 :     }
333 :     else {
334 :    
335 :     for (y = 0; y < (edged_height - EDGE_SIZE); y += 8) {
336 :     for (x = 0; x < (edged_width - EDGE_SIZE); x += 8) {
337 :     interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width, rounding);
338 :     interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width, rounding);
339 :     interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width, rounding);
340 :    
341 :     n_ptr += 8;
342 :     h_ptr += 8;
343 :     v_ptr += 8;
344 :     hv_ptr += 8;
345 :     }
346 :    
347 :     h_ptr += EDGE_SIZE;
348 :     v_ptr += EDGE_SIZE;
349 :     hv_ptr += EDGE_SIZE;
350 :     n_ptr += EDGE_SIZE;
351 :    
352 :     h_ptr += stride_add;
353 :     v_ptr += stride_add;
354 :     hv_ptr += stride_add;
355 :     n_ptr += stride_add;
356 :     }
357 :     }
358 :     /*
359 :     #ifdef BFRAMES
360 :     n_ptr = refn->u;
361 :     h_ptr = refh->u;
362 :     v_ptr = refv->u;
363 :     hv_ptr = refhv->u;
364 :    
365 :     n_ptr -= offset2;
366 :     h_ptr -= offset2;
367 :     v_ptr -= offset2;
368 :     hv_ptr -= offset2;
369 :    
370 :     for (y = 0; y < edged_height2; y += 8) {
371 :     for (x = 0; x < edged_width2; x += 8) {
372 :     interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width2, rounding);
373 :     interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width2, rounding);
374 :     interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width2, rounding);
375 :    
376 : albeu 315 n_ptr += 8;
377 :     h_ptr += 8;
378 :     v_ptr += 8;
379 :     hv_ptr += 8;
380 :     }
381 : edgomez 851 h_ptr += stride_add2;
382 :     v_ptr += stride_add2;
383 :     hv_ptr += stride_add2;
384 :     n_ptr += stride_add2;
385 : albeu 315 }
386 :    
387 : edgomez 851 n_ptr = refn->v;
388 :     h_ptr = refh->v;
389 :     v_ptr = refv->v;
390 :     hv_ptr = refhv->v;
391 :    
392 :     n_ptr -= offset2;
393 :     h_ptr -= offset2;
394 :     v_ptr -= offset2;
395 :     hv_ptr -= offset2;
396 :    
397 :     for (y = 0; y < edged_height2; y = y + 8) {
398 :     for (x = 0; x < edged_width2; x = x + 8) {
399 :     interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width2, rounding);
400 :     interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width2, rounding);
401 :     interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width2, rounding);
402 :    
403 :     n_ptr += 8;
404 :     h_ptr += 8;
405 :     v_ptr += 8;
406 :     hv_ptr += 8;
407 :     }
408 :     h_ptr += stride_add2;
409 :     v_ptr += stride_add2;
410 :     hv_ptr += stride_add2;
411 :     n_ptr += stride_add2;
412 :     }
413 :     #endif
414 :     */
415 : albeu 315 /*
416 :     interpolate_halfpel_h(
417 :     refh->y - offset,
418 :     refn->y - offset,
419 :     edged_width, edged_height,
420 :     rounding);
421 :    
422 :     interpolate_halfpel_v(
423 :     refv->y - offset,
424 :     refn->y - offset,
425 :     edged_width, edged_height,
426 :     rounding);
427 :    
428 :     interpolate_halfpel_hv(
429 :     refhv->y - offset,
430 :     refn->y - offset,
431 :     edged_width, edged_height,
432 :     rounding);
433 :     */
434 :    
435 :     /* uv-image-based compensation
436 :     offset = EDGE_SIZE2 * (edged_width / 2 + 1);
437 :    
438 :     interpolate_halfpel_h(
439 :     refh->u - offset,
440 :     refn->u - offset,
441 :     edged_width / 2, edged_height / 2,
442 :     rounding);
443 :    
444 :     interpolate_halfpel_v(
445 :     refv->u - offset,
446 :     refn->u - offset,
447 :     edged_width / 2, edged_height / 2,
448 :     rounding);
449 :    
450 :     interpolate_halfpel_hv(
451 :     refhv->u - offset,
452 :     refn->u - offset,
453 :     edged_width / 2, edged_height / 2,
454 :     rounding);
455 :    
456 :    
457 :     interpolate_halfpel_h(
458 :     refh->v - offset,
459 :     refn->v - offset,
460 :     edged_width / 2, edged_height / 2,
461 :     rounding);
462 :    
463 :     interpolate_halfpel_v(
464 :     refv->v - offset,
465 :     refn->v - offset,
466 :     edged_width / 2, edged_height / 2,
467 :     rounding);
468 :    
469 :     interpolate_halfpel_hv(
470 :     refhv->v - offset,
471 :     refn->v - offset,
472 :     edged_width / 2, edged_height / 2,
473 :     rounding);
474 :     */
475 :     }
476 :    
477 :    
478 : edgomez 851 /*
479 :     chroma optimize filter, invented by mf
480 :     a chroma pixel is average from the surrounding pixels, when the
481 :     correpsonding luma pixels are pure black or white.
482 :     */
483 :    
484 :     void
485 :     image_chroma_optimize(IMAGE * img, int width, int height, int edged_width)
486 :     {
487 :     int x,y;
488 :     int pixels = 0;
489 :    
490 :     for (y = 1; y < height/2 - 1; y++)
491 :     for (x = 1; x < width/2 - 1; x++)
492 :     {
493 :     #define IS_PURE(a) ((a)<=16||(a)>=235)
494 :     #define IMG_Y(Y,X) img->y[(Y)*edged_width + (X)]
495 :     #define IMG_U(Y,X) img->u[(Y)*edged_width/2 + (X)]
496 :     #define IMG_V(Y,X) img->v[(Y)*edged_width/2 + (X)]
497 :    
498 :     if (IS_PURE(IMG_Y(y*2 ,x*2 )) &&
499 :     IS_PURE(IMG_Y(y*2 ,x*2+1)) &&
500 :     IS_PURE(IMG_Y(y*2+1,x*2 )) &&
501 :     IS_PURE(IMG_Y(y*2+1,x*2+1)))
502 :     {
503 :     IMG_U(y,x) = (IMG_U(y,x-1) + IMG_U(y-1, x) + IMG_U(y, x+1) + IMG_U(y+1, x)) / 4;
504 :     IMG_V(y,x) = (IMG_V(y,x-1) + IMG_V(y-1, x) + IMG_V(y, x+1) + IMG_V(y+1, x)) / 4;
505 :     pixels++;
506 :     }
507 :    
508 :     #undef IS_PURE
509 :     #undef IMG_Y
510 :     #undef IMG_U
511 :     #undef IMG_V
512 :     }
513 :    
514 :     DPRINTF(DPRINTF_DEBUG,"chroma_optimized_pixels = %i/%i", pixels, width*height/4);
515 :     }
516 :    
517 :    
518 :    
519 :    
520 :    
521 :     /*
522 :     perform safe packed colorspace conversion, by splitting
523 :     the image up into an optimized area (pixel width divisible by 16),
524 :     and two unoptimized/plain-c areas (pixel width divisible by 2)
525 :     */
526 :    
527 :     static void
528 :     safe_packed_conv(uint8_t * x_ptr, int x_stride,
529 :     uint8_t * y_ptr, uint8_t * u_ptr, uint8_t * v_ptr,
530 :     int y_stride, int uv_stride,
531 :     int width, int height, int vflip,
532 :     packedFunc * func_opt, packedFunc func_c, int size)
533 :     {
534 :     int width_opt, width_c;
535 :    
536 :     if (func_opt != func_c && x_stride < size*((width+15)/16)*16)
537 :     {
538 :     width_opt = width & (~15);
539 :     width_c = width - width_opt;
540 :     }
541 :     else
542 :     {
543 :     width_opt = width;
544 :     width_c = 0;
545 :     }
546 :    
547 :     func_opt(x_ptr, x_stride,
548 :     y_ptr, u_ptr, v_ptr, y_stride, uv_stride,
549 :     width_opt, height, vflip);
550 :    
551 :     if (width_c)
552 :     {
553 :     func_c(x_ptr + size*width_opt, x_stride,
554 :     y_ptr + width_opt, u_ptr + width_opt/2, v_ptr + width_opt/2,
555 :     y_stride, uv_stride, width_c, height, vflip);
556 :     }
557 :     }
558 :    
559 :    
560 :    
561 : albeu 315 int
562 :     image_input(IMAGE * image,
563 :     uint32_t width,
564 :     int height,
565 :     uint32_t edged_width,
566 : suxen_drol 890 uint8_t * src[4],
567 :     int src_stride[4],
568 : edgomez 851 int csp,
569 :     int interlacing)
570 : albeu 315 {
571 : edgomez 851 const int edged_width2 = edged_width/2;
572 :     const int width2 = width/2;
573 :     const int height2 = height/2;
574 :     //const int height_signed = (csp & XVID_CSP_VFLIP) ? -height : height;
575 : albeu 315
576 :     switch (csp & ~XVID_CSP_VFLIP) {
577 :     case XVID_CSP_RGB555:
578 : edgomez 851 safe_packed_conv(
579 : suxen_drol 890 src[0], src_stride[0], image->y, image->u, image->v,
580 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
581 :     interlacing?rgb555i_to_yv12 :rgb555_to_yv12,
582 :     interlacing?rgb555i_to_yv12_c:rgb555_to_yv12_c, 2);
583 :     break;
584 : albeu 315
585 :     case XVID_CSP_RGB565:
586 : edgomez 851 safe_packed_conv(
587 : suxen_drol 890 src[0], src_stride[0], image->y, image->u, image->v,
588 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
589 :     interlacing?rgb565i_to_yv12 :rgb565_to_yv12,
590 :     interlacing?rgb565i_to_yv12_c:rgb565_to_yv12_c, 2);
591 :     break;
592 : albeu 315
593 :    
594 : suxen_drol 890 case XVID_CSP_BGR:
595 : edgomez 851 safe_packed_conv(
596 : suxen_drol 890 src[0], src_stride[0], image->y, image->u, image->v,
597 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
598 :     interlacing?bgri_to_yv12 :bgr_to_yv12,
599 :     interlacing?bgri_to_yv12_c:bgr_to_yv12_c, 3);
600 :     break;
601 : albeu 315
602 : suxen_drol 890 case XVID_CSP_BGRA:
603 : edgomez 851 safe_packed_conv(
604 : suxen_drol 890 src[0], src_stride[0], image->y, image->u, image->v,
605 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
606 :     interlacing?bgrai_to_yv12 :bgra_to_yv12,
607 :     interlacing?bgrai_to_yv12_c:bgra_to_yv12_c, 4);
608 :     break;
609 : albeu 315
610 : edgomez 851 case XVID_CSP_ABGR :
611 :     safe_packed_conv(
612 : suxen_drol 890 src[0], src_stride[0], image->y, image->u, image->v,
613 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
614 :     interlacing?abgri_to_yv12 :abgr_to_yv12,
615 :     interlacing?abgri_to_yv12_c:abgr_to_yv12_c, 4);
616 :     break;
617 : albeu 315
618 : edgomez 851 case XVID_CSP_RGBA :
619 :     safe_packed_conv(
620 : suxen_drol 890 src[0], src_stride[0], image->y, image->u, image->v,
621 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
622 :     interlacing?rgbai_to_yv12 :rgba_to_yv12,
623 :     interlacing?rgbai_to_yv12_c:rgba_to_yv12_c, 4);
624 :     break;
625 : albeu 315
626 :     case XVID_CSP_YUY2:
627 : edgomez 851 safe_packed_conv(
628 : suxen_drol 890 src[0], src_stride[0], image->y, image->u, image->v,
629 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
630 :     interlacing?yuyvi_to_yv12 :yuyv_to_yv12,
631 :     interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2);
632 :     break;
633 : albeu 315
634 :     case XVID_CSP_YVYU: /* u/v swapped */
635 : edgomez 851 safe_packed_conv(
636 : suxen_drol 890 src[0], src_stride[0], image->y, image->v, image->y,
637 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
638 :     interlacing?yuyvi_to_yv12 :yuyv_to_yv12,
639 :     interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2);
640 :     break;
641 : albeu 315
642 :     case XVID_CSP_UYVY:
643 : edgomez 851 safe_packed_conv(
644 : suxen_drol 890 src[0], src_stride[0], image->y, image->u, image->v,
645 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
646 :     interlacing?uyvyi_to_yv12 :uyvy_to_yv12,
647 :     interlacing?uyvyi_to_yv12_c:uyvy_to_yv12_c, 2);
648 :     break;
649 : albeu 315
650 : edgomez 851 case XVID_CSP_I420:
651 :     yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2,
652 : suxen_drol 890 src[0], src[0] + src_stride[0]*height, src[0] + src_stride[0]*height + (src_stride[0]/2)*height2,
653 :     src_stride[0], src_stride[0]/2, width, height, (csp & XVID_CSP_VFLIP));
654 : edgomez 851 break
655 :     ;
656 :     case XVID_CSP_YV12: /* u/v swapped */
657 :     yv12_to_yv12(image->y, image->v, image->u, edged_width, edged_width2,
658 : suxen_drol 890 src[0], src[0] + src_stride[0]*height, src[0] + src_stride[0]*height + (src_stride[0]/2)*height2,
659 :     src_stride[0], src_stride[0]/2, width, height, (csp & XVID_CSP_VFLIP));
660 : edgomez 851 break;
661 :    
662 : albeu 315 case XVID_CSP_USER:
663 : suxen_drol 890 /*XXX: support for different u & v strides */
664 :     yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2,
665 :     src[0], src[1], src[2], src_stride[0], src_stride[1],
666 :     width, height, (csp & XVID_CSP_VFLIP));
667 : edgomez 851 break;
668 : albeu 315
669 :     case XVID_CSP_NULL:
670 :     break;
671 :    
672 : edgomez 851 default :
673 :     return -1;
674 : albeu 315 }
675 :    
676 : edgomez 851
677 :     /* pad out image when the width and/or height is not a multiple of 16 */
678 :    
679 :     if (width & 15)
680 :     {
681 :     int i;
682 :     int pad_width = 16 - (width&15);
683 :     for (i = 0; i < height; i++)
684 :     {
685 :     memset(image->y + i*edged_width + width,
686 :     *(image->y + i*edged_width + width - 1), pad_width);
687 :     }
688 :     for (i = 0; i < height/2; i++)
689 :     {
690 :     memset(image->u + i*edged_width2 + width2,
691 :     *(image->u + i*edged_width2 + width2 - 1),pad_width/2);
692 :     memset(image->v + i*edged_width2 + width2,
693 :     *(image->v + i*edged_width2 + width2 - 1),pad_width/2);
694 :     }
695 :     }
696 :    
697 :     if (height & 15)
698 :     {
699 :     int pad_height = 16 - (height&15);
700 :     int length = ((width+15)/16)*16;
701 :     int i;
702 :     for (i = 0; i < pad_height; i++)
703 :     {
704 :     memcpy(image->y + (height+i)*edged_width,
705 :     image->y + (height-1)*edged_width,length);
706 :     }
707 :    
708 :     for (i = 0; i < pad_height/2; i++)
709 :     {
710 :     memcpy(image->u + (height2+i)*edged_width2,
711 :     image->u + (height2-1)*edged_width2,length/2);
712 :     memcpy(image->v + (height2+i)*edged_width2,
713 :     image->v + (height2-1)*edged_width2,length/2);
714 :     }
715 :     }
716 :    
717 :     /*
718 :     if (interlacing)
719 :     image_printf(image, edged_width, height, 5,5, "[i]");
720 :     image_dump_yuvpgm(image, edged_width, ((width+15)/16)*16, ((height+15)/16)*16, "\\encode.pgm");
721 :     */
722 :     return 0;
723 : albeu 315 }
724 :    
725 :    
726 :    
727 :     int
728 :     image_output(IMAGE * image,
729 :     uint32_t width,
730 :     int height,
731 :     uint32_t edged_width,
732 : suxen_drol 890 uint8_t * dst[4],
733 :     uint32_t dst_stride[4],
734 : edgomez 851 int csp,
735 :     int interlacing)
736 : albeu 315 {
737 : edgomez 851 const int edged_width2 = edged_width/2;
738 :     int height2 = height/2;
739 :    
740 :     /*
741 :     if (interlacing)
742 :     image_printf(image, edged_width, height, 5,100, "[i]=%i,%i",width,height);
743 :     image_dump_yuvpgm(image, edged_width, width, height, "\\decode.pgm");
744 :     */
745 :    
746 : albeu 315 switch (csp & ~XVID_CSP_VFLIP) {
747 :     case XVID_CSP_RGB555:
748 : edgomez 851 safe_packed_conv(
749 : suxen_drol 890 dst[0], dst_stride[0], image->y, image->u, image->v,
750 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
751 :     interlacing?yv12_to_rgb555i :yv12_to_rgb555,
752 :     interlacing?yv12_to_rgb555i_c:yv12_to_rgb555_c, 2);
753 : albeu 315 return 0;
754 :    
755 :     case XVID_CSP_RGB565:
756 : edgomez 851 safe_packed_conv(
757 : suxen_drol 890 dst[0], dst_stride[0], image->y, image->u, image->v,
758 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
759 :     interlacing?yv12_to_rgb565i :yv12_to_rgb565,
760 :     interlacing?yv12_to_rgb565i_c:yv12_to_rgb565_c, 2);
761 : albeu 315 return 0;
762 :    
763 : suxen_drol 890 case XVID_CSP_BGR:
764 : edgomez 851 safe_packed_conv(
765 : suxen_drol 890 dst[0], dst_stride[0], image->y, image->u, image->v,
766 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
767 :     interlacing?yv12_to_bgri :yv12_to_bgr,
768 :     interlacing?yv12_to_bgri_c:yv12_to_bgr_c, 3);
769 : albeu 315 return 0;
770 :    
771 : suxen_drol 890 case XVID_CSP_BGRA:
772 : edgomez 851 safe_packed_conv(
773 : suxen_drol 890 dst[0], dst_stride[0], image->y, image->u, image->v,
774 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
775 :     interlacing?yv12_to_bgrai :yv12_to_bgra,
776 :     interlacing?yv12_to_bgrai_c:yv12_to_bgra_c, 4);
777 : albeu 315 return 0;
778 :    
779 : edgomez 851 case XVID_CSP_ABGR:
780 :     safe_packed_conv(
781 : suxen_drol 890 dst[0], dst_stride[0], image->y, image->u, image->v,
782 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
783 :     interlacing?yv12_to_abgri :yv12_to_abgr,
784 :     interlacing?yv12_to_abgri_c:yv12_to_abgr_c, 4);
785 : albeu 315 return 0;
786 :    
787 : edgomez 851 case XVID_CSP_RGBA:
788 :     safe_packed_conv(
789 : suxen_drol 890 dst[0], dst_stride[0], image->y, image->u, image->v,
790 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
791 :     interlacing?yv12_to_rgbai :yv12_to_rgba,
792 :     interlacing?yv12_to_rgbai_c:yv12_to_rgba_c, 4);
793 : albeu 315 return 0;
794 :    
795 :     case XVID_CSP_YUY2:
796 : edgomez 851 safe_packed_conv(
797 : suxen_drol 890 dst[0], dst_stride[0], image->y, image->u, image->v,
798 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
799 :     interlacing?yv12_to_yuyvi :yv12_to_yuyv,
800 :     interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2);
801 : albeu 315 return 0;
802 :    
803 : edgomez 851 case XVID_CSP_YVYU: // u,v swapped
804 :     safe_packed_conv(
805 : suxen_drol 890 dst[0], dst_stride[0], image->y, image->v, image->u,
806 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
807 :     interlacing?yv12_to_yuyvi :yv12_to_yuyv,
808 :     interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2);
809 : albeu 315 return 0;
810 :    
811 :     case XVID_CSP_UYVY:
812 : edgomez 851 safe_packed_conv(
813 : suxen_drol 890 dst[0], dst_stride[0], image->y, image->u, image->v,
814 : edgomez 851 edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
815 :     interlacing?yv12_to_uyvyi :yv12_to_uyvy,
816 :     interlacing?yv12_to_uyvyi_c:yv12_to_uyvy_c, 2);
817 : albeu 315 return 0;
818 :    
819 : edgomez 851 case XVID_CSP_I420:
820 : suxen_drol 890 yv12_to_yv12(dst[0], dst[0] + dst_stride[0]*height, dst[0] + dst_stride[0]*height + (dst_stride[0]/2)*height2,
821 :     dst_stride[0], dst_stride[0]/2,
822 : edgomez 851 image->y, image->u, image->v, edged_width, edged_width2,
823 :     width, height, (csp & XVID_CSP_VFLIP));
824 :     return 0;
825 :    
826 :     case XVID_CSP_YV12: // u,v swapped
827 : suxen_drol 890 yv12_to_yv12(dst[0], dst[0] + dst_stride[0]*height, dst[0] + dst_stride[0]*height + (dst_stride[0]/2)*height2,
828 :     dst_stride[0], dst_stride[0]/2,
829 : edgomez 851 image->y, image->v, image->u, edged_width, edged_width2,
830 :     width, height, (csp & XVID_CSP_VFLIP));
831 :     return 0;
832 :    
833 : suxen_drol 890 case XVID_CSP_USER : // u,v swapped
834 :     yv12_to_yv12(dst[0], dst[1], dst[2],
835 :     dst_stride[0], dst_stride[1], /* v: dst_stride[2] */
836 :     image->y, image->v, image->u, edged_width, edged_width2,
837 :     width, height, (csp & XVID_CSP_VFLIP));
838 : albeu 315 return 0;
839 :    
840 : suxen_drol 890 case XVID_CSP_INTERNAL :
841 :     dst[0] = image->y;
842 :     dst[1] = image->u;
843 :     dst[2] = image->v;
844 :     dst_stride[0] = edged_width;
845 :     dst_stride[1] = edged_width/2;
846 :     dst_stride[2] = edged_width/2;
847 :     return 0;
848 :    
849 : albeu 315 case XVID_CSP_NULL:
850 : suxen_drol 890 case XVID_CSP_SLICE:
851 : albeu 315 return 0;
852 :    
853 :     }
854 :    
855 :     return -1;
856 :     }
857 :    
858 :     float
859 :     image_psnr(IMAGE * orig_image,
860 :     IMAGE * recon_image,
861 :     uint16_t stride,
862 :     uint16_t width,
863 :     uint16_t height)
864 :     {
865 :     int32_t diff, x, y, quad = 0;
866 :     uint8_t *orig = orig_image->y;
867 :     uint8_t *recon = recon_image->y;
868 :     float psnr_y;
869 :    
870 :     for (y = 0; y < height; y++) {
871 :     for (x = 0; x < width; x++) {
872 :     diff = *(orig + x) - *(recon + x);
873 :     quad += diff * diff;
874 :     }
875 :     orig += stride;
876 :     recon += stride;
877 :     }
878 :    
879 :     psnr_y = (float) quad / (float) (width * height);
880 :    
881 :     if (psnr_y) {
882 :     psnr_y = (float) (255 * 255) / psnr_y;
883 :     psnr_y = 10 * (float) log10(psnr_y);
884 :     } else
885 :     psnr_y = (float) 99.99;
886 :    
887 :     return psnr_y;
888 :     }
889 :    
890 :    
891 : edgomez 851 float sse_to_PSNR(long sse, int pixels)
892 :     {
893 :     if (sse==0)
894 :     return 99.99F;
895 :    
896 :     return 48.131F - 10*(float)log10((float)sse/(float)(pixels)); // log10(255*255)=4.8131
897 :    
898 :     }
899 :    
900 :     long plane_sse(uint8_t * orig,
901 :     uint8_t * recon,
902 :     uint16_t stride,
903 :     uint16_t width,
904 :     uint16_t height)
905 :     {
906 :     int diff, x, y;
907 :     long sse=0;
908 :    
909 :     for (y = 0; y < height; y++) {
910 :     for (x = 0; x < width; x++) {
911 :     diff = *(orig + x) - *(recon + x);
912 :     sse += diff * diff;
913 :     }
914 :     orig += stride;
915 :     recon += stride;
916 :     }
917 :     return sse;
918 :     }
919 :    
920 :     /*
921 :    
922 : albeu 315 #include <stdio.h>
923 :     #include <string.h>
924 :    
925 :     int image_dump_pgm(uint8_t * bmp, uint32_t width, uint32_t height, char * filename)
926 :     {
927 :     FILE * f;
928 :     char hdr[1024];
929 :    
930 :     f = fopen(filename, "wb");
931 :     if ( f == NULL)
932 :     {
933 :     return -1;
934 :     }
935 :     sprintf(hdr, "P5\n#xvid\n%i %i\n255\n", width, height);
936 :     fwrite(hdr, strlen(hdr), 1, f);
937 :     fwrite(bmp, width, height, f);
938 :     fclose(f);
939 :    
940 :     return 0;
941 :     }
942 :    
943 :    
944 : edgomez 851 // dump image+edges to yuv pgm files
945 : albeu 315
946 :     int image_dump(IMAGE * image, uint32_t edged_width, uint32_t edged_height, char * path, int number)
947 :     {
948 :     char filename[1024];
949 :    
950 :     sprintf(filename, "%s_%i_%c.pgm", path, number, 'y');
951 :     image_dump_pgm(
952 :     image->y - (EDGE_SIZE * edged_width + EDGE_SIZE),
953 :     edged_width, edged_height, filename);
954 :    
955 :     sprintf(filename, "%s_%i_%c.pgm", path, number, 'u');
956 :     image_dump_pgm(
957 :     image->u - (EDGE_SIZE2 * edged_width / 2 + EDGE_SIZE2),
958 :     edged_width / 2, edged_height / 2, filename);
959 :    
960 :     sprintf(filename, "%s_%i_%c.pgm", path, number, 'v');
961 :     image_dump_pgm(
962 :     image->v - (EDGE_SIZE2 * edged_width / 2 + EDGE_SIZE2),
963 :     edged_width / 2, edged_height / 2, filename);
964 :    
965 :     return 0;
966 :     }
967 : edgomez 851 */
968 : albeu 315
969 :    
970 :    
971 :     /* dump image to yuvpgm file */
972 :    
973 :     #include <stdio.h>
974 :    
975 :     int
976 :     image_dump_yuvpgm(const IMAGE * image,
977 :     const uint32_t edged_width,
978 :     const uint32_t width,
979 :     const uint32_t height,
980 :     char *filename)
981 :     {
982 :     FILE *f;
983 :     char hdr[1024];
984 :     uint32_t i;
985 :     uint8_t *bmp1;
986 :     uint8_t *bmp2;
987 :    
988 :    
989 :     f = fopen(filename, "wb");
990 :     if (f == NULL) {
991 :     return -1;
992 :     }
993 :     sprintf(hdr, "P5\n#xvid\n%i %i\n255\n", width, (3 * height) / 2);
994 :     fwrite(hdr, strlen(hdr), 1, f);
995 :    
996 :     bmp1 = image->y;
997 :     for (i = 0; i < height; i++) {
998 :     fwrite(bmp1, width, 1, f);
999 :     bmp1 += edged_width;
1000 :     }
1001 :    
1002 :     bmp1 = image->u;
1003 :     bmp2 = image->v;
1004 :     for (i = 0; i < height / 2; i++) {
1005 :     fwrite(bmp1, width / 2, 1, f);
1006 :     fwrite(bmp2, width / 2, 1, f);
1007 :     bmp1 += edged_width / 2;
1008 :     bmp2 += edged_width / 2;
1009 :     }
1010 :    
1011 :     fclose(f);
1012 :     return 0;
1013 :     }
1014 :    
1015 :    
1016 :     float
1017 :     image_mad(const IMAGE * img1,
1018 :     const IMAGE * img2,
1019 :     uint32_t stride,
1020 :     uint32_t width,
1021 :     uint32_t height)
1022 :     {
1023 :     const uint32_t stride2 = stride / 2;
1024 :     const uint32_t width2 = width / 2;
1025 :     const uint32_t height2 = height / 2;
1026 :    
1027 :     uint32_t x, y;
1028 :     uint32_t sum = 0;
1029 :    
1030 :     for (y = 0; y < height; y++)
1031 :     for (x = 0; x < width; x++)
1032 :     sum += ABS(img1->y[x + y * stride] - img2->y[x + y * stride]);
1033 :    
1034 :     for (y = 0; y < height2; y++)
1035 :     for (x = 0; x < width2; x++)
1036 :     sum += ABS(img1->u[x + y * stride2] - img2->u[x + y * stride2]);
1037 :    
1038 :     for (y = 0; y < height2; y++)
1039 :     for (x = 0; x < width2; x++)
1040 :     sum += ABS(img1->v[x + y * stride2] - img2->v[x + y * stride2]);
1041 :    
1042 :     return (float) sum / (width * height * 3 / 2);
1043 :     }
1044 :    
1045 :     void
1046 : suxen_drol 890 output_slice(IMAGE * cur, int std, int width, xvid_image_t* out_frm, int mbx, int mby,int mbl) {
1047 : albeu 315 uint8_t *dY,*dU,*dV,*sY,*sU,*sV;
1048 :     int std2 = std >> 1;
1049 :     int w = mbl << 4, w2,i;
1050 :    
1051 :     if(w > width)
1052 :     w = width;
1053 :     w2 = w >> 1;
1054 : suxen_drol 323
1055 : suxen_drol 890 dY = (uint8_t*)out_frm->plane[0] + (mby << 4) * out_frm->stride[0] + (mbx << 4);
1056 :     dU = (uint8_t*)out_frm->plane[1] + (mby << 3) * out_frm->stride[1] + (mbx << 3);
1057 :     dV = (uint8_t*)out_frm->plane[2] + (mby << 3) * out_frm->stride[2] + (mbx << 3);
1058 : albeu 315 sY = cur->y + (mby << 4) * std + (mbx << 4);
1059 :     sU = cur->u + (mby << 3) * std2 + (mbx << 3);
1060 :     sV = cur->v + (mby << 3) * std2 + (mbx << 3);
1061 :    
1062 :     for(i = 0 ; i < 16 ; i++) {
1063 :     memcpy(dY,sY,w);
1064 : suxen_drol 890 dY += out_frm->stride[0];
1065 : suxen_drol 323 sY += std;
1066 :     }
1067 : albeu 315 for(i = 0 ; i < 8 ; i++) {
1068 :     memcpy(dU,sU,w2);
1069 : suxen_drol 890 dU += out_frm->stride[1];
1070 : albeu 315 sU += std2;
1071 :     }
1072 :     for(i = 0 ; i < 8 ; i++) {
1073 :     memcpy(dV,sV,w2);
1074 : suxen_drol 890 dV += out_frm->stride[2];
1075 : albeu 315 sV += std2;
1076 :     }
1077 :     }
1078 : edgomez 851
1079 :    
1080 :     void
1081 :     image_clear(IMAGE * img, int width, int height, int edged_width,
1082 :     int y, int u, int v)
1083 :     {
1084 :     uint8_t * p;
1085 :     int i;
1086 :    
1087 :     p = img->y;
1088 :     for (i = 0; i < height; i++) {
1089 :     memset(p, y, width);
1090 :     p += edged_width;
1091 :     }
1092 :    
1093 :     p = img->u;
1094 :     for (i = 0; i < height/2; i++) {
1095 :     memset(p, u, width/2);
1096 :     p += edged_width/2;
1097 :     }
1098 :    
1099 :     p = img->v;
1100 :     for (i = 0; i < height/2; i++) {
1101 :     memset(p, v, width/2);
1102 :     p += edged_width/2;
1103 :     }
1104 :     }
1105 :    
1106 :    
1107 :     /* reduced resolution deblocking filter
1108 :     block = block size (16=rrv, 8=full resolution)
1109 :     flags = XVID_DEC_YDEBLOCK|XVID_DEC_UVDEBLOCK
1110 :     */
1111 :     void
1112 :     image_deblock_rrv(IMAGE * img, int edged_width,
1113 :     const MACROBLOCK * mbs, int mb_width, int mb_height, int mb_stride,
1114 :     int block, int flags)
1115 :     {
1116 :     const int edged_width2 = edged_width /2;
1117 :     const int nblocks = block / 8; /* skals code uses 8pixel block uints */
1118 :     int i,j;
1119 :    
1120 :     /* luma: j,i in block units */
1121 : suxen_drol 890
1122 : edgomez 851 for (j = 1; j < mb_height*2; j++) /* horizontal deblocking */
1123 :     for (i = 0; i < mb_width*2; i++)
1124 :     {
1125 :     if (mbs[(j-1)/2*mb_stride + (i/2)].mode != MODE_NOT_CODED ||
1126 :     mbs[(j+0)/2*mb_stride + (i/2)].mode != MODE_NOT_CODED)
1127 :     {
1128 :     hfilter_31(img->y + (j*block - 1)*edged_width + i*block,
1129 :     img->y + (j*block + 0)*edged_width + i*block, nblocks);
1130 :     }
1131 :     }
1132 :    
1133 :     for (j = 0; j < mb_height*2; j++) /* vertical deblocking */
1134 :     for (i = 1; i < mb_width*2; i++)
1135 :     {
1136 :     if (mbs[(j/2)*mb_stride + (i-1)/2].mode != MODE_NOT_CODED ||
1137 :     mbs[(j/2)*mb_stride + (i+0)/2].mode != MODE_NOT_CODED)
1138 :     {
1139 :     vfilter_31(img->y + (j*block)*edged_width + i*block - 1,
1140 :     img->y + (j*block)*edged_width + i*block + 0,
1141 :     edged_width, nblocks);
1142 :     }
1143 :     }
1144 :    
1145 :    
1146 : suxen_drol 890
1147 : edgomez 851 /* chroma */
1148 : suxen_drol 890
1149 : edgomez 851 for (j = 1; j < mb_height; j++) /* horizontal deblocking */
1150 :     for (i = 0; i < mb_width; i++)
1151 :     {
1152 :     if (mbs[(j-1)*mb_stride + i].mode != MODE_NOT_CODED ||
1153 :     mbs[(j+0)*mb_stride + i].mode != MODE_NOT_CODED)
1154 :     {
1155 :     hfilter_31(img->u + (j*block - 1)*edged_width2 + i*block,
1156 :     img->u + (j*block + 0)*edged_width2 + i*block, nblocks);
1157 :     hfilter_31(img->v + (j*block - 1)*edged_width2 + i*block,
1158 :     img->v + (j*block + 0)*edged_width2 + i*block, nblocks);
1159 :     }
1160 :     }
1161 :    
1162 :     for (j = 0; j < mb_height; j++) /* vertical deblocking */
1163 :     for (i = 1; i < mb_width; i++)
1164 :     {
1165 :     if (mbs[j*mb_stride + i - 1].mode != MODE_NOT_CODED ||
1166 :     mbs[j*mb_stride + i + 0].mode != MODE_NOT_CODED)
1167 :     {
1168 :     vfilter_31(img->u + (j*block)*edged_width2 + i*block - 1,
1169 :     img->u + (j*block)*edged_width2 + i*block + 0,
1170 :     edged_width2, nblocks);
1171 :     vfilter_31(img->v + (j*block)*edged_width2 + i*block - 1,
1172 :     img->v + (j*block)*edged_width2 + i*block + 0,
1173 :     edged_width2, nblocks);
1174 :     }
1175 :     }
1176 :    
1177 : suxen_drol 890
1178 : edgomez 851 }
1179 :    

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