[svn] / trunk / xvidcore / src / image / image.c Repository:
ViewVC logotype

Annotation of /trunk/xvidcore/src/image/image.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1382 - (view) (download)

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

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