Exemplo n.º 1
0
/**
 * eog_thumbnail_fit_to_size:
 * @thumbnail: a #GdkPixbuf
 * @dimension: the maximum width or height desired
 *
 * Ensures a pixbuf fits a given @dimension
 *
 * Returns: (transfer full): a new #GdkPixbuf
 **/
GdkPixbuf *
eog_thumbnail_fit_to_size (GdkPixbuf *thumbnail, gint dimension)
{
	gint width, height;

	width = gdk_pixbuf_get_width (thumbnail);
	height = gdk_pixbuf_get_height (thumbnail);

	if (width > dimension || height > dimension) {
		GdkPixbuf *result_pixbuf;
		gfloat factor;

		if (width > height) {
			factor = (gfloat) dimension / (gfloat) width;
		} else {
			factor = (gfloat) dimension / (gfloat) height;
		}

		width  = MAX (width  * factor, 1);
		height = MAX (height * factor, 1);

		result_pixbuf = gnome_desktop_thumbnail_scale_down_pixbuf (thumbnail, width, height);

		return result_pixbuf;
	}
	return gdk_pixbuf_copy (thumbnail);
}
Exemplo n.º 2
0
/**
 * e_icon_factory_pixbuf_scale
 * @pixbuf: a #GdkPixbuf
 * @width: desired width, if less or equal to 0, then changed to 1
 * @height: desired height, if less or equal to 0, then changed to 1
 *
 * Scales @pixbuf to desired size.
 *
 * Returns: a scaled #GdkPixbuf
 **/
GdkPixbuf *
e_icon_factory_pixbuf_scale (GdkPixbuf *pixbuf,
                             gint width,
                             gint height)
{
	g_return_val_if_fail (pixbuf != NULL, NULL);

	if (width <= 0)
		width = 1;

	if (height <= 0)
		height = 1;

	#ifdef HAVE_GNOME_DESKTOP
	/* because this can only scale down, not up */
	if (gdk_pixbuf_get_width (pixbuf) > width && gdk_pixbuf_get_height (pixbuf) > height)
		return gnome_desktop_thumbnail_scale_down_pixbuf (pixbuf, width, height);
	#endif

	return gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
}
Exemplo n.º 3
0
static GdkPixbuf *
create_thumbnail_from_pixbuf (EogThumbData *data,
			      GdkPixbuf *pixbuf,
			      GError **error)
{
	GdkPixbuf *thumb;
	gint width, height;
	gfloat perc;

	g_assert (factory != NULL);

	width = gdk_pixbuf_get_width (pixbuf);
	height = gdk_pixbuf_get_height (pixbuf);

	perc = CLAMP (128.0/(MAX (width, height)), 0, 1);

	thumb = gnome_desktop_thumbnail_scale_down_pixbuf (pixbuf,
							   width*perc,
							   height*perc);

	return thumb;
}