--- libvisual-0.1-pre5-org/libvisual/lv_video.c 2004-04-18 19:49:18.000000000 +0200 +++ libvisual-0.1-pre5/libvisual/lv_video.c 2004-04-30 01:20:22.000000000 +0200 @@ -203,43 +203,39 @@ } int visual_video_center (VisVideo *dest, VisVideo *src) -{ - unsigned char *destr, *srcr; - int spaceright = 0; - int centupper; - int centlower; - int spare; - int i, j, dind = 0, sind = 0; - - /* This is sub optimal, could be cleaner so to say */ - spare = dest->width - src->width; +{ + int move_x, move_y; + int lines; + int width, height; + int dx, sx; + unsigned char *d, *s; - destr = dest->screenbuffer; - srcr = src->screenbuffer; + if (dest->bpp != src->bpp) + return -1; - if (spare % 2 != 0) { - if (spare > 1) - spaceright = spare; - else - spaceright = 1; + move_x = (dest->width - src->width) / 2; + width = dest->width > src->width ? src->width : dest->width; + move_y = (dest->height - src->height) / 2; + height = dest->height > src->height ? src->height : dest->height; + d = dest->screenbuffer; + s = src->screenbuffer; + if (move_y > 0) { + d += dest->width * dest->bpp * move_y; } else { - spaceright = spare / 1; + s += src->width * src->bpp * (-move_y); } - - /* FIXME this is all so majorly broken */ -/* printf ("Jo eh %d %d | %d %d | %d %d\n", - dest->width, dest->height, - src->width, src->height, - spare, spaceright); -*/ - for (i = 0; i < src->height; i++) { - for (j = 0; j < src->width * src->bpp; j++) { - destr[dind++] = srcr[sind++]; - } - - dind += spaceright * src->bpp; + if (move_x > 0) { + dx = dest->bpp * move_x; + sx = 0; + } else { + dx = 0; + sx = src->bpp * (-move_x); + } + for (lines = 0; lines < height; lines++) { + memcpy (d + dx, s + sx, width * dest->bpp); + d += dest->width * dest->bpp; + s += src->width * src->bpp; } - return 0; }