From e47366fa2f7342fc3a9b4f6b1f975bbe5f70dee9 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Fri, 4 May 2007 12:36:08 +0000 Subject: [PATCH] crop the image, even if the layer is fully opaque. Fixes bug #413906. 2007-05-04 Sven Neumann * plug-ins/common/autocrop.c (autocrop): crop the image, even if the layer is fully opaque. Fixes bug #413906. svn path=/trunk/; revision=22413 --- ChangeLog | 5 +++ plug-ins/common/autocrop.c | 71 +++++++++++++++++++------------------- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index d3f46a2a7d..75cc586ba4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-05-04 Sven Neumann + + * plug-ins/common/autocrop.c (autocrop): crop the image, even if + the layer is fully opaque. Fixes bug #413906. + 2007-05-04 Sven Neumann * plug-ins/common/autocrop.c (guess_bgcolor): special case fully diff --git a/plug-ins/common/autocrop.c b/plug-ins/common/autocrop.c index 004fc4af14..937b2a0e7e 100644 --- a/plug-ins/common/autocrop.c +++ b/plug-ins/common/autocrop.c @@ -221,10 +221,12 @@ autocrop (GimpDrawable *drawable, if (y1 == height && !abort) { - /* whee - a plain color drawable. Do nothing. */ - g_free (buffer); - gimp_drawable_detach (drawable); - return; + /* whee - a plain color drawable. */ + x1 = 0; + x2 = width; + y1 = 0; + y2 = height; + goto done; } if (show_progress) @@ -242,7 +244,6 @@ autocrop (GimpDrawable *drawable, y2++; /* to make y2 - y1 == height */ - /* The coordinates are now the first rows which DON'T match * the color. Crop instead to one row larger: */ @@ -289,48 +290,46 @@ autocrop (GimpDrawable *drawable, if (x2 < width) x2++; + done: g_free (buffer); - gimp_drawable_detach (drawable); - if (x2 - x1 != width || y2 - y1 != height) + if (layer_only && + (x2 - x1 != width || y2 - y1 != height)) { - if (layer_only) + gimp_layer_resize (layer_id, x2 - x1, y2 - y1, -x1, -y1); + } + else + { + /* convert to image coordinates */ + x1 += off_x; x2 += off_x; + y1 += off_y; y2 += off_y; + + gimp_image_undo_group_start (image_id); + + if (x1 < 0 || y1 < 0 || + x2 > gimp_image_width (image_id) || + y2 > gimp_image_height (image_id)) { - gimp_layer_resize (layer_id, x2 - x1, y2 - y1, -x1, -y1); + /* + * partially outside the image area, we need to + * resize the image to be able to crop properly. + */ + gimp_image_resize (image_id, x2 - x1, y2 - y1, -x1, -y1); + + x2 -= x1; + y2 -= y1; + + x1 = y1 = 0; } - else - { - /* convert to image coordinates */ - x1 += off_x; x2 += off_x; - y1 += off_y; y2 += off_y; - gimp_image_undo_group_start (image_id); + gimp_image_crop (image_id, x2 - x1, y2 - y1, x1, y1); - if (x1 < 0 || y1 < 0 || - x2 > gimp_image_width (image_id) || - y2 > gimp_image_height (image_id)) - { - /* - * partially outside the image area, we need to - * resize the image to be able to crop properly. - */ - gimp_image_resize (image_id, x2 - x1, y2 - y1, -x1, -y1); - - x2 -= x1; - y2 -= y1; - - x1 = y1 = 0; - } - - gimp_image_crop (image_id, x2 - x1, y2 - y1, x1, y1); - - gimp_image_undo_group_end (image_id); - } + gimp_image_undo_group_end (image_id); } if (show_progress) - gimp_progress_update (1.00); + gimp_progress_update (1.0); } static gint