diff options
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | libmate-desktop/mate-desktop-thumbnail.h | 7 | ||||
-rw-r--r-- | libmate-desktop/mate-thumbnail-pixbuf-utils.c | 131 |
3 files changed, 18 insertions, 122 deletions
diff --git a/configure.ac b/configure.ac index 5e17d20..9bc5c2d 100644 --- a/configure.ac +++ b/configure.ac @@ -98,7 +98,7 @@ else EXTERNAL_PNP_IDS="$with_pnp_ids_path" fi -GDK_PIXBUF_REQUIRED=2.36.1 +GDK_PIXBUF_REQUIRED=2.36.5 GLIB_REQUIRED=2.50.0 GIO_REQUIRED=2.26.0 GTK_REQUIRED=3.22.0 diff --git a/libmate-desktop/mate-desktop-thumbnail.h b/libmate-desktop/mate-desktop-thumbnail.h index 1decb4a..9f26dab 100644 --- a/libmate-desktop/mate-desktop-thumbnail.h +++ b/libmate-desktop/mate-desktop-thumbnail.h @@ -101,6 +101,13 @@ char * mate_desktop_thumbnail_path_for_uri (const char *uri, /* Pixbuf utils */ +#ifndef __GTK_DOC_IGNORE__ +#define MATE_DESKTOP_DEPRECATED_IN_1_24_FOR(f) G_DEPRECATED_FOR(f) extern +#else +#define MATE_DESKTOP_DEPRECATED_IN_1_24_FOR(f) extern +#endif + +MATE_DESKTOP_DEPRECATED_IN_1_24_FOR(gdk_pixbuf_scale_simple) GdkPixbuf *mate_desktop_thumbnail_scale_down_pixbuf (GdkPixbuf *pixbuf, int dest_width, int dest_height); diff --git a/libmate-desktop/mate-thumbnail-pixbuf-utils.c b/libmate-desktop/mate-thumbnail-pixbuf-utils.c index d005913..ee00655 100644 --- a/libmate-desktop/mate-thumbnail-pixbuf-utils.c +++ b/libmate-desktop/mate-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 * @@ -51,126 +54,12 @@ mate_desktop_thumbnail_scale_down_pixbuf (GdkPixbuf *pixbuf, 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 { - if (n_pixels != 0) { - *dest++ = r / n_pixels; - *dest++ = g / n_pixels; - *dest++ = b / n_pixels; - } else { - *dest++ = 0; - *dest++ = 0; - *dest++ = 0; - } - } - - 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); } |