From 0f775dc84e7bcf4892772cf6e9cde0d948965668 Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Fri, 26 Sep 2008 05:31:34 +0000 Subject: [PATCH] From: Christophe Jaillet [mailto:christophe.jaillet@wanadoo.fr] Sent: Wed 9/24/2008 2:00 PM To: submit@mamedev.org Subject: Speed up fillbitmap Hi, there are many places in mame which make use of "fill_bitmap" or the equivalent "fillbitmap" An optimisation is done when the depth of the bitmap is 16 or 32 bpp and when the UINT16 or UINT32 corresponding to the color is composed of same bytes (i.e 0xffff for example). This is usefull because most of the calls are for color 0 (black). In all other cases, the bitmap is filled one pixel at a time using a loop with a code like : ================ for (y = fill.min_y; y <= fill.max_y; y++) { UINT16 *destrow = BITMAP_ADDR16(dest, y, 0); for (x = fill.min_x; x <= fill.max_x; x++) destrow[x] = (UINT16)color; } ================ However, each rows of the final bitmap will be the same. So I modified this simple assigned to work as follow : 1) fill the first row one pixel at a time 2) fill all the other rows by copying the first one. This makes us use memcpy instead of a hard coded loop for most of the filling process. --- src/lib/util/bitmap.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/lib/util/bitmap.c b/src/lib/util/bitmap.c index 3c4dec454a5..5e97ae437f7 100644 --- a/src/lib/util/bitmap.c +++ b/src/lib/util/bitmap.c @@ -198,11 +198,19 @@ void bitmap_fill(bitmap_t *dest, const rectangle *cliprect, UINT32 color) } else { - for (y = fill.min_y; y <= fill.max_y; y++) + UINT16 *destrow, *destrow0; + + /* Fill the first line the hard way */ + destrow = BITMAP_ADDR16(dest, fill.min_y, 0); + for (x = fill.min_x; x <= fill.max_x; x++) + destrow[x] = (UINT16)color; + + /* For the other lines, just copy the first one */ + destrow0 = BITMAP_ADDR16(dest, fill.min_y, fill.min_x); + for (y = fill.min_y + 1; y <= fill.max_y; y++) { - UINT16 *destrow = BITMAP_ADDR16(dest, y, 0); - for (x = fill.min_x; x <= fill.max_x; x++) - destrow[x] = (UINT16)color; + destrow = BITMAP_ADDR16(dest, y, fill.min_x); + memcpy(destrow, destrow0, (fill.max_x + 1 - fill.min_x) * 2); } } break; @@ -216,11 +224,19 @@ void bitmap_fill(bitmap_t *dest, const rectangle *cliprect, UINT32 color) } else { - for (y = fill.min_y; y <= fill.max_y; y++) + UINT32 *destrow, *destrow0; + + /* Fill the first line the hard way */ + destrow = BITMAP_ADDR32(dest, fill.min_y, 0); + for (x = fill.min_x; x <= fill.max_x; x++) + destrow[x] = (UINT32)color; + + /* For the other lines, just copy the first one */ + destrow0 = BITMAP_ADDR32(dest, fill.min_y, fill.min_x); + for (y = fill.min_y + 1; y <= fill.max_y; y++) { - UINT32 *destrow = BITMAP_ADDR32(dest, y, 0); - for (x = fill.min_x; x <= fill.max_x; x++) - destrow[x] = (UINT32)color; + destrow = BITMAP_ADDR32(dest, y, fill.min_x); + memcpy(destrow, destrow0, (fill.max_x + 1 - fill.min_x) * 4); } } break;