mirror of https://github.com/GNOME/gimp.git
remove code duplication, cleanup.
2006-05-27 Michael Natterer <mitch@gimp.org> * app/core/gimpimage-crop.c (gimp_image_crop_guess_bgcolor): remove code duplication, cleanup.
This commit is contained in:
parent
41e76ffdcf
commit
cec27e0b48
|
@ -1,3 +1,8 @@
|
||||||
|
2006-05-27 Michael Natterer <mitch@gimp.org>
|
||||||
|
|
||||||
|
* app/core/gimpimage-crop.c (gimp_image_crop_guess_bgcolor):
|
||||||
|
remove code duplication, cleanup.
|
||||||
|
|
||||||
2006-05-27 Michael Natterer <mitch@gimp.org>
|
2006-05-27 Michael Natterer <mitch@gimp.org>
|
||||||
|
|
||||||
* app/core/gimpimage.h: fix spacing broken by tab removal.
|
* app/core/gimpimage.h: fix spacing broken by tab removal.
|
||||||
|
|
|
@ -425,11 +425,12 @@ gimp_image_crop_guess_bgcolor (GimpPickable *pickable,
|
||||||
gint y1,
|
gint y1,
|
||||||
gint y2)
|
gint y2)
|
||||||
{
|
{
|
||||||
guchar *tl = NULL;
|
AutoCropType retval = AUTO_CROP_NOTHING;
|
||||||
guchar *tr = NULL;
|
guchar *tl = NULL;
|
||||||
guchar *bl = NULL;
|
guchar *tr = NULL;
|
||||||
guchar *br = NULL;
|
guchar *bl = NULL;
|
||||||
gint i, alpha;
|
guchar *br = NULL;
|
||||||
|
gint i;
|
||||||
|
|
||||||
for (i = 0; i < bytes; i++)
|
for (i = 0; i < bytes; i++)
|
||||||
color[i] = 0;
|
color[i] = 0;
|
||||||
|
@ -438,28 +439,23 @@ gimp_image_crop_guess_bgcolor (GimpPickable *pickable,
|
||||||
* background-color to see if at least 2 corners are equal.
|
* background-color to see if at least 2 corners are equal.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!(tl = gimp_pickable_get_color_at (pickable, x1, y1)))
|
if (! (tl = gimp_pickable_get_color_at (pickable, x1, y1)) ||
|
||||||
goto ERROR;
|
! (tr = gimp_pickable_get_color_at (pickable, x1, y2)) ||
|
||||||
if (!(tr = gimp_pickable_get_color_at (pickable, x1, y2)))
|
! (bl = gimp_pickable_get_color_at (pickable, x2, y1)) ||
|
||||||
goto ERROR;
|
! (br = gimp_pickable_get_color_at (pickable, x2, y2)))
|
||||||
if (!(bl = gimp_pickable_get_color_at (pickable, x2, y1)))
|
goto done;
|
||||||
goto ERROR;
|
|
||||||
if (!(br = gimp_pickable_get_color_at (pickable, x2, y2)))
|
|
||||||
goto ERROR;
|
|
||||||
|
|
||||||
if (has_alpha)
|
if (has_alpha)
|
||||||
{
|
{
|
||||||
alpha = bytes - 1;
|
gint alpha = bytes - 1;
|
||||||
|
|
||||||
if ((tl[alpha] == 0 && tr[alpha] == 0) ||
|
if ((tl[alpha] == 0 && tr[alpha] == 0) ||
|
||||||
(tl[alpha] == 0 && bl[alpha] == 0) ||
|
(tl[alpha] == 0 && bl[alpha] == 0) ||
|
||||||
(tr[alpha] == 0 && br[alpha] == 0) ||
|
(tr[alpha] == 0 && br[alpha] == 0) ||
|
||||||
(bl[alpha] == 0 && br[alpha] == 0))
|
(bl[alpha] == 0 && br[alpha] == 0))
|
||||||
{
|
{
|
||||||
g_free (tl);
|
retval = AUTO_CROP_ALPHA;
|
||||||
g_free (tr);
|
goto done;
|
||||||
g_free (bl);
|
|
||||||
g_free (br);
|
|
||||||
return AUTO_CROP_ALPHA;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,29 +463,22 @@ gimp_image_crop_guess_bgcolor (GimpPickable *pickable,
|
||||||
gimp_image_crop_colors_equal (tl, bl, bytes))
|
gimp_image_crop_colors_equal (tl, bl, bytes))
|
||||||
{
|
{
|
||||||
memcpy (color, tl, bytes);
|
memcpy (color, tl, bytes);
|
||||||
|
retval = AUTO_CROP_COLOR;
|
||||||
}
|
}
|
||||||
else if (gimp_image_crop_colors_equal (br, bl, bytes) ||
|
else if (gimp_image_crop_colors_equal (br, bl, bytes) ||
|
||||||
gimp_image_crop_colors_equal (br, tr, bytes))
|
gimp_image_crop_colors_equal (br, tr, bytes))
|
||||||
{
|
{
|
||||||
memcpy (color, br, bytes);
|
memcpy (color, br, bytes);
|
||||||
}
|
retval = AUTO_CROP_COLOR;
|
||||||
else
|
|
||||||
{
|
|
||||||
goto ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
g_free (tl);
|
g_free (tl);
|
||||||
g_free (tr);
|
g_free (tr);
|
||||||
g_free (bl);
|
g_free (bl);
|
||||||
g_free (br);
|
g_free (br);
|
||||||
return AUTO_CROP_COLOR;
|
|
||||||
|
|
||||||
ERROR:
|
return retval;
|
||||||
g_free (tl);
|
|
||||||
g_free (tr);
|
|
||||||
g_free (bl);
|
|
||||||
g_free (br);
|
|
||||||
return AUTO_CROP_NOTHING;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
Loading…
Reference in New Issue