From 8ad8318ae483cae8f6a9b53245e10de428e55a63 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 5 Apr 2010 11:31:01 -0400 Subject: [PATCH] Fix some issues with icon handling Preserve alpha channels if present in the file, and be careful about not passing out-of-bounds coordinates to gdk_pixbuf_new_subpixbuf() --- src/um-crop-area.c | 18 ++++++++++++++---- 1 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/um-crop-area.c b/src/um-crop-area.c index 2c473a1..14ba5ee 100644 --- a/src/um-crop-area.c +++ b/src/um-crop-area.c @@ -107,8 +107,10 @@ update_pixbufs (UmCropArea *area) gdk_pixbuf_get_height (area->priv->pixbuf) != allocation.height) { if (area->priv->pixbuf != NULL) g_object_unref (area->priv->pixbuf); - area->priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, - allocation.width, allocation.height); + area->priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, + gdk_pixbuf_get_has_alpha (area->priv->browse_pixbuf), + 8, + allocation.width, allocation.height); color = &widget->style->bg[GTK_WIDGET_STATE (widget)]; pixel = ((color->red & 0xff00) << 16) | @@ -800,9 +802,17 @@ um_crop_area_new (void) GdkPixbuf * um_crop_area_get_picture (UmCropArea *area) { + gint width, height; + + width = gdk_pixbuf_get_width (area->priv->browse_pixbuf); + height = gdk_pixbuf_get_height (area->priv->browse_pixbuf); + width = MIN (area->priv->crop.width, width - area->priv->crop.x); + height = MIN (area->priv->crop.height, height - area->priv->crop.y); + return gdk_pixbuf_new_subpixbuf (area->priv->browse_pixbuf, - area->priv->crop.x, area->priv->crop.y, - area->priv->crop.width, area->priv->crop.height); + area->priv->crop.x, + area->priv->crop.y, + width, height); } void -- 1.7.0.1