From 85a58dddba28d49332c0cf8679a7f821e81c7c78 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Tue, 7 Aug 2001 17:49:09 +0000 Subject: [PATCH] a comment asked to optimize this function, so that's what I did. 2001-08-07 Sven Neumann * gdk-pixbuf.c (gdk_pixbuf_fill): a comment asked to optimize this function, so that's what I did. --- gdk-pixbuf/ChangeLog | 5 +++++ gdk-pixbuf/gdk-pixbuf.c | 35 ++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/gdk-pixbuf/ChangeLog b/gdk-pixbuf/ChangeLog index ed830a35b9..3f0cc9457d 100644 --- a/gdk-pixbuf/ChangeLog +++ b/gdk-pixbuf/ChangeLog @@ -1,3 +1,8 @@ +2001-08-07 Sven Neumann + + * gdk-pixbuf.c (gdk_pixbuf_fill): a comment asked to optimize this + function, so that's what I did. + 2001-08-06 Kjartan Maraas * gdk-pixdata.c: Fix a typo. diff --git a/gdk-pixbuf/gdk-pixbuf.c b/gdk-pixbuf/gdk-pixbuf.c index cfc0bb323c..60750f4a05 100644 --- a/gdk-pixbuf/gdk-pixbuf.c +++ b/gdk-pixbuf/gdk-pixbuf.c @@ -429,6 +429,9 @@ gdk_pixbuf_fill (GdkPixbuf *pixbuf, g_return_if_fail (GDK_IS_PIXBUF (pixbuf)); + if (pixbuf->width == 0 || pixbuf->height == 0) + return; + pixels = pixbuf->pixels; r = (pixel & 0xff000000) >> 24; @@ -448,20 +451,30 @@ gdk_pixbuf_fill (GdkPixbuf *pixbuf, pixbuf->rowstride * pixbuf->height); } else { guchar *p; - guchar *end; + guchar c[4]; + gint n; - /* feel free to optimize this */ + c[0] = r; c[1] = g; c[2] = b; c[3] = a; p = pixels; - end = pixels + pixbuf->rowstride * pixbuf->height; - end -= (pixbuf->rowstride - pixbuf->width * pixbuf->n_channels); - - while (p < end) { - *p++ = r; - *p++ = g; - *p++ = b; - if (pixbuf->has_alpha) - *p++ = a; + n = pixbuf->width; + if (pixbuf->has_alpha) { + do { + memcpy (p, c, 4); + p += 4; + } while (--n); + } else { + do { + memcpy (p, c, 3); + p += 3; + } while (--n); + } + + p = pixels; + n = pixbuf->height - 1; + while (n--) { + p += pixbuf->rowstride; + memcpy (p, pixels, pixbuf->width * pixbuf->n_channels); } } }