]> Pileus Git - ~andy/gtk/commitdiff
a comment asked to optimize this function, so that's what I did.
authorSven Neumann <sven@gimp.org>
Tue, 7 Aug 2001 17:49:09 +0000 (17:49 +0000)
committerSven Neumann <neo@src.gnome.org>
Tue, 7 Aug 2001 17:49:09 +0000 (17:49 +0000)
2001-08-07  Sven Neumann  <sven@gimp.org>

* gdk-pixbuf.c (gdk_pixbuf_fill): a comment asked to optimize this
function, so that's what I did.

gdk-pixbuf/ChangeLog
gdk-pixbuf/gdk-pixbuf.c

index ed830a35b905992574bb8494632a697c72a32e7c..3f0cc9457d88a5b3018bd659260a1ef88165e1bd 100644 (file)
@@ -1,3 +1,8 @@
+2001-08-07  Sven Neumann  <sven@gimp.org>
+
+       * gdk-pixbuf.c (gdk_pixbuf_fill): a comment asked to optimize this
+       function, so that's what I did.
+
 2001-08-06  Kjartan Maraas  <kmaraas@gnome.org>
 
        * gdk-pixdata.c: Fix a typo.
index cfc0bb323c5e8b7420fa59e67cffcde03480f528..60750f4a05a6f2a01fc64709f8b35bc7e1b8295f 100644 (file)
@@ -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);
                 }
         }
 }