diff options
author | Philip Withnall <philip@tecnocode.co.uk> | 2017-01-07 19:18:36 +0000 |
---|---|---|
committer | Philip Withnall <withnall@endlessm.com> | 2017-01-10 09:52:33 +0000 |
commit | bab37cdc936a78b792aaf842845c726a5b128d80 (patch) | |
tree | 7dc147ea55eb33be250e4635d29cceddda7a89ec | |
parent | f4b97747e770650063bf7f6d7c1199ecba5ed54f (diff) | |
download | gdk-pixbuf-bab37cdc936a78b792aaf842845c726a5b128d80.tar.gz |
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
-rw-r--r-- | 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 202e433ac..a17855317 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; |