[gdk-pixbuf] gdk-pixbuf-scale: Add a fast path for a no-op scale



commit bab37cdc936a78b792aaf842845c726a5b128d80
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sat Jan 7 19:18:36 2017 +0000

    gdk-pixbuf-scale: Add a fast path for a no-op scale
    
    If calling gdk_pixbuf_scale_simple() with equal src and dest dimensions,
    there’s nothing to do, so just return a copy of the src pixbuf. Document
    the new fast path.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=442452

 gdk-pixbuf/gdk-pixbuf-scale.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
---
diff --git a/gdk-pixbuf/gdk-pixbuf-scale.c b/gdk-pixbuf/gdk-pixbuf-scale.c
index 202e433..a178553 100644
--- a/gdk-pixbuf/gdk-pixbuf-scale.c
+++ b/gdk-pixbuf/gdk-pixbuf-scale.c
@@ -330,6 +330,9 @@ gdk_pixbuf_composite_color (const GdkPixbuf *src,
  * You can scale a sub-portion of @src by creating a sub-pixbuf
  * pointing into @src; see gdk_pixbuf_new_subpixbuf().
  *
+ * If @dest_width and @dest_height are equal to the @src width and height, a
+ * copy of @src is returned, avoiding any scaling.
+ *
  * For more complicated scaling/alpha blending see gdk_pixbuf_scale()
  * and gdk_pixbuf_composite().
  * 
@@ -348,6 +351,10 @@ gdk_pixbuf_scale_simple (const GdkPixbuf *src,
   g_return_val_if_fail (dest_width > 0, NULL);
   g_return_val_if_fail (dest_height > 0, NULL);
 
+  /* Fast path. */
+  if (dest_width == src->width && dest_height == src->height)
+    return gdk_pixbuf_copy (src);
+
   dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, src->has_alpha, 8, dest_width, dest_height);
   if (!dest)
     return NULL;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]