diff options
author | Bastien Nocera <hadess@hadess.net> | 2017-01-06 17:36:20 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2017-02-03 19:02:30 +0100 |
commit | cb64228291842ac73d6bf64d93e35070aab88de1 (patch) | |
tree | 78c3300673718d9e948617f29a304937c3fcae5d | |
parent | a42a5d0806b8a70112d0daabd26bd20b281eb472 (diff) | |
download | gnome-desktop-cb64228291842ac73d6bf64d93e35070aab88de1.tar.gz |
thumbnail: Deprecate gnome_desktop_thumbnail_scale_down_pixbuf()
As scaling down by huge factors is now fixed in gdk-pixbuf. Require the
newer gdk-pixbuf as well, to avoid running into a pre-fix version.
https://bugzilla.gnome.org/show_bug.cgi?id=775991
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | libgnome-desktop/gnome-desktop-thumbnail.h | 7 | ||||
-rw-r--r-- | libgnome-desktop/gnome-thumbnail-pixbuf-utils.c | 129 |
3 files changed, 20 insertions, 118 deletions
diff --git a/configure.ac b/configure.ac index 5baf1a2e..2174a468 100644 --- a/configure.ac +++ b/configure.ac @@ -103,7 +103,7 @@ GLIB_TESTS dnl If you add a version number here, you *must* add an AC_SUBST line for dnl it too, or it will never make it into the spec file! -GDK_PIXBUF_REQUIRED=2.36.1 +GDK_PIXBUF_REQUIRED=2.36.5 GTK_REQUIRED=3.3.6 GLIB_REQUIRED=2.44.0 XRANDR_REQUIRED=1.3 diff --git a/libgnome-desktop/gnome-desktop-thumbnail.h b/libgnome-desktop/gnome-desktop-thumbnail.h index 424f6cce..9ad36ca2 100644 --- a/libgnome-desktop/gnome-desktop-thumbnail.h +++ b/libgnome-desktop/gnome-desktop-thumbnail.h @@ -103,6 +103,13 @@ char * gnome_desktop_thumbnail_path_for_uri (const char *uri, /* Pixbuf utils */ +#ifndef __GTK_DOC_IGNORE__ +#define GNOME_DESKTOP_DEPRECATED_IN_3_24_FOR(f) G_DEPRECATED_FOR(f) extern +#else +#define GNOME_DESKTOP_DEPRECATED_IN_3_24_FOR(f) extern +#endif + +GNOME_DESKTOP_DEPRECATED_IN_3_24_FOR(gdk_pixbuf_scale_simple) GdkPixbuf *gnome_desktop_thumbnail_scale_down_pixbuf (GdkPixbuf *pixbuf, int dest_width, int dest_height); diff --git a/libgnome-desktop/gnome-thumbnail-pixbuf-utils.c b/libgnome-desktop/gnome-thumbnail-pixbuf-utils.c index f704bb64..fcd88c03 100644 --- a/libgnome-desktop/gnome-thumbnail-pixbuf-utils.c +++ b/libgnome-desktop/gnome-thumbnail-pixbuf-utils.c @@ -39,8 +39,11 @@ * @dest_height: the desired new height * * Scales the pixbuf to the desired size. This function - * is a lot faster than gdk-pixbuf when scaling down by - * large amounts. + * used to be a lot faster than gdk-pixbuf when scaling + * down by large amounts. This is not true anymore since + * gdk-pixbuf UNRELEASED. You should use + * gdk_pixbuf_scale_simple() instead, which this function + * now does internally. * * Return value: (transfer full): a scaled pixbuf * @@ -48,123 +51,15 @@ **/ GdkPixbuf * gnome_desktop_thumbnail_scale_down_pixbuf (GdkPixbuf *pixbuf, - int dest_width, - int dest_height) + int dest_width, + int dest_height) { - int source_width, source_height; - int s_x1, s_y1, s_x2, s_y2; - int s_xfrac, s_yfrac; - int dx, dx_frac, dy, dy_frac; - div_t ddx, ddy; - int x, y; - int r, g, b, a; - int n_pixels; - gboolean has_alpha; - guchar *dest, *src, *xsrc, *src_pixels; - GdkPixbuf *dest_pixbuf; - int pixel_stride; - int source_rowstride, dest_rowstride; + g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL); + g_return_val_if_fail (gdk_pixbuf_get_width (pixbuf) >= dest_width, NULL); + g_return_val_if_fail (gdk_pixbuf_get_height (pixbuf) >= dest_height, NULL); - if (dest_width == 0 || dest_height == 0) { + if (dest_width == 0 || dest_height == 0) return NULL; - } - - source_width = gdk_pixbuf_get_width (pixbuf); - source_height = gdk_pixbuf_get_height (pixbuf); - g_assert (source_width >= dest_width); - g_assert (source_height >= dest_height); - - ddx = div (source_width, dest_width); - dx = ddx.quot; - dx_frac = ddx.rem; - - ddy = div (source_height, dest_height); - dy = ddy.quot; - dy_frac = ddy.rem; - - has_alpha = gdk_pixbuf_get_has_alpha (pixbuf); - source_rowstride = gdk_pixbuf_get_rowstride (pixbuf); - src_pixels = gdk_pixbuf_get_pixels (pixbuf); - - dest_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, has_alpha, 8, - dest_width, dest_height); - dest = gdk_pixbuf_get_pixels (dest_pixbuf); - dest_rowstride = gdk_pixbuf_get_rowstride (dest_pixbuf); - - pixel_stride = (has_alpha)?4:3; - - s_y1 = 0; - s_yfrac = -dest_height/2; - while (s_y1 < source_height) { - s_y2 = s_y1 + dy; - s_yfrac += dy_frac; - if (s_yfrac > 0) { - s_y2++; - s_yfrac -= dest_height; - } - - s_x1 = 0; - s_xfrac = -dest_width/2; - while (s_x1 < source_width) { - s_x2 = s_x1 + dx; - s_xfrac += dx_frac; - if (s_xfrac > 0) { - s_x2++; - s_xfrac -= dest_width; - } - - /* Average block of [x1,x2[ x [y1,y2[ and store in dest */ - r = g = b = a = 0; - n_pixels = 0; - - src = src_pixels + s_y1 * source_rowstride + s_x1 * pixel_stride; - for (y = s_y1; y < s_y2; y++) { - xsrc = src; - if (has_alpha) { - for (x = 0; x < s_x2-s_x1; x++) { - n_pixels++; - - r += xsrc[3] * xsrc[0]; - g += xsrc[3] * xsrc[1]; - b += xsrc[3] * xsrc[2]; - a += xsrc[3]; - xsrc += 4; - } - } else { - for (x = 0; x < s_x2-s_x1; x++) { - n_pixels++; - r += *xsrc++; - g += *xsrc++; - b += *xsrc++; - } - } - src += source_rowstride; - } - - if (has_alpha) { - if (a != 0) { - *dest++ = r / a; - *dest++ = g / a; - *dest++ = b / a; - *dest++ = a / n_pixels; - } else { - *dest++ = 0; - *dest++ = 0; - *dest++ = 0; - *dest++ = 0; - } - } else { - *dest++ = r / n_pixels; - *dest++ = g / n_pixels; - *dest++ = b / n_pixels; - } - - s_x1 = s_x2; - } - s_y1 = s_y2; - dest += dest_rowstride - dest_width * pixel_stride; - } - - return dest_pixbuf; + return gdk_pixbuf_scale_simple (pixbuf, dest_width, dest_height, GDK_INTERP_HYPER); } |