Commit d0ab9a74 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

app/core/gimp-transform-utils.[ch]. switch from x1,y1,x2,y2 bounding boxes

2004-10-27  Michael Natterer  <mitch@gimp.org>

	* app/core/gimp-transform-utils.[ch]. switch from x1,y1,x2,y2
	bounding boxes to x,y,width,height ones. Added
	gimp_transform_matrix_flip_free(). Renamed some parameters to be
	consistent with others. Some internal cleanup.

	* app/tools/gimpperspectivetool.c
	* app/tools/gimpscaletool.c
	* app/tools/gimpsheartool.c
	* tools/pdbgen/pdb/drawable_transform.pdb
	* tools/pdbgen/pdb/transform_tools.pdb: changed accordingly.

	* tools/pdbgen/pdb/drawable_transform.pdb
	* tools/pdbgen/pdb/transform_tools.pdb: guard all transform
	wrappers with if(gimp_drawable_mask_intersect(...)), also the
	ones which don't need the returned bounding box.

	* tools/pdbgen/pdb/drawable_transform.pdb: renamed some parameters
	and added gimp_drawable_transform_matrix() which takes the 9
	coefficients of a 3x3 matrix for ultimate flexibility ;)

	* app/pdb/drawable_transform_cmds.c
	* app/pdb/internal_procs.c
	* app/pdb/transform_tools_cmds.c
	* libgimp/gimpdrawabletransform_pdb.[ch]: regenerated.
parent 4349469e
2004-10-27 Michael Natterer <mitch@gimp.org>
* app/core/gimp-transform-utils.[ch]. switch from x1,y1,x2,y2
bounding boxes to x,y,width,height ones. Added
gimp_transform_matrix_flip_free(). Renamed some parameters to be
consistent with others. Some internal cleanup.
* app/tools/gimpperspectivetool.c
* app/tools/gimpscaletool.c
* app/tools/gimpsheartool.c
* tools/pdbgen/pdb/drawable_transform.pdb
* tools/pdbgen/pdb/transform_tools.pdb: changed accordingly.
* tools/pdbgen/pdb/drawable_transform.pdb
* tools/pdbgen/pdb/transform_tools.pdb: guard all transform
wrappers with if(gimp_drawable_mask_intersect(...)), also the
ones which don't need the returned bounding box.
* tools/pdbgen/pdb/drawable_transform.pdb: renamed some parameters
and added gimp_drawable_transform_matrix() which takes the 9
coefficients of a 3x3 matrix for ultimate flexibility ;)
* app/pdb/drawable_transform_cmds.c
* app/pdb/internal_procs.c
* app/pdb/transform_tools_cmds.c
* libgimp/gimpdrawabletransform_pdb.[ch]: regenerated.
2004-10-27 Sven Neumann <sven@gimp.org>
 
* app/actions/dockable-actions.c (dockable_toggle_actions): changed
......
......@@ -32,6 +32,8 @@ gimp_transform_matrix_flip (GimpOrientationType flip_type,
gdouble axis,
GimpMatrix3 *result)
{
g_return_if_fail (result != NULL);
gimp_matrix3_identity (result);
switch (flip_type)
......@@ -54,127 +56,159 @@ gimp_transform_matrix_flip (GimpOrientationType flip_type,
}
void
gimp_transform_matrix_rotate (gint x1,
gint y1,
gint x2,
gint y2,
gimp_transform_matrix_flip_free (gint x,
gint y,
gint width,
gint height,
gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2,
GimpMatrix3 *result)
{
gdouble angle;
gdouble dx, dy;
g_return_if_fail (result != NULL);
angle = atan2 (y2 - y1, x2 - x1);
dx = x - x1;
dy = (x1 + ((y2 - y1) / (x2 - x1) ) * x) - y1;
gimp_matrix3_identity (result);
gimp_matrix3_translate (result, dx, dy);
gimp_matrix3_rotate (result, -angle);
gimp_matrix3_scale (result, 1.0, -1.0);
gimp_matrix3_rotate (result, angle);
gimp_matrix3_translate (result, -dx, -dy);
}
void
gimp_transform_matrix_rotate (gint x,
gint y,
gint width,
gint height,
gdouble angle,
GimpMatrix3 *result)
{
gdouble cx;
gdouble cy;
gdouble center_x;
gdouble center_y;
cx = (gdouble) (x1 + x2) / 2.0;
cy = (gdouble) (y1 + y2) / 2.0;
g_return_if_fail (result != NULL);
center_x = (gdouble) x + (gdouble) width / 2.0;
center_y = (gdouble) y + (gdouble) height / 2.0;
gimp_matrix3_identity (result);
gimp_matrix3_translate (result, -cx, -cy);
gimp_matrix3_translate (result, -center_x, -center_y);
gimp_matrix3_rotate (result, angle);
gimp_matrix3_translate (result, +cx, +cy);
gimp_matrix3_translate (result, +center_x, +center_y);
}
void
gimp_transform_matrix_rotate_center (gdouble cx,
gdouble cy,
gimp_transform_matrix_rotate_center (gdouble center_x,
gdouble center_y,
gdouble angle,
GimpMatrix3 *result)
{
g_return_if_fail (result != NULL);
gimp_matrix3_identity (result);
gimp_matrix3_translate (result, -cx, -cy);
gimp_matrix3_translate (result, -center_x, -center_y);
gimp_matrix3_rotate (result, angle);
gimp_matrix3_translate (result, +cx, +cy);
gimp_matrix3_translate (result, +center_x, +center_y);
}
void
gimp_transform_matrix_scale (gint x1,
gint y1,
gint x2,
gint y2,
gdouble tx1,
gdouble ty1,
gdouble tx2,
gdouble ty2,
gimp_transform_matrix_scale (gint x,
gint y,
gint width,
gint height,
gdouble t_x,
gdouble t_y,
gdouble t_width,
gdouble t_height,
GimpMatrix3 *result)
{
gdouble scalex;
gdouble scaley;
gdouble scale_x = 1.0;
gdouble scale_y = 1.0;
scalex = scaley = 1.0;
g_return_if_fail (result != NULL);
if ((x2 - x1) > 0)
scalex = (tx2 - tx1) / (gdouble) (x2 - x1);
if (width > 0)
scale_x = t_width / (gdouble) width;
if ((y2 - y1) > 0)
scaley = (ty2 - ty1) / (gdouble) (y2 - y1);
if (height > 0)
scale_y = t_height / (gdouble) height;
gimp_matrix3_identity (result);
gimp_matrix3_translate (result, -x1, -y1);
gimp_matrix3_scale (result, scalex, scaley);
gimp_matrix3_translate (result, tx1, ty1);
gimp_matrix3_translate (result, -x, -y);
gimp_matrix3_scale (result, scale_x, scale_y);
gimp_matrix3_translate (result, t_x, t_y);
}
void
gimp_transform_matrix_shear (gint x1,
gint y1,
gint x2,
gint y2,
gimp_transform_matrix_shear (gint x,
gint y,
gint width,
gint height,
GimpOrientationType orientation,
gdouble amount,
GimpMatrix3 *result)
{
gint width;
gint height;
gdouble cx;
gdouble cy;
gdouble center_x;
gdouble center_y;
width = x2 - x1;
height = y2 - y1;
g_return_if_fail (result != NULL);
if (width == 0)
width = 1;
if (height == 0)
height = 1;
cx = (gdouble) (x1 + x2) / 2.0;
cy = (gdouble) (y1 + y2) / 2.0;
center_x = (gdouble) x + (gdouble) width / 2.0;
center_y = (gdouble) y + (gdouble) height / 2.0;
gimp_matrix3_identity (result);
gimp_matrix3_translate (result, -cx, -cy);
gimp_matrix3_translate (result, -center_x, -center_y);
if (orientation == GIMP_ORIENTATION_HORIZONTAL)
gimp_matrix3_xshear (result, amount / height);
else
gimp_matrix3_yshear (result, amount / width);
gimp_matrix3_translate (result, +cx, +cy);
gimp_matrix3_translate (result, +center_x, +center_y);
}
void
gimp_transform_matrix_perspective (gint x1,
gint y1,
gint x2,
gint y2,
gdouble tx1,
gdouble ty1,
gdouble tx2,
gdouble ty2,
gdouble tx3,
gdouble ty3,
gdouble tx4,
gdouble ty4,
gimp_transform_matrix_perspective (gint x,
gint y,
gint width,
gint height,
gdouble t_x1,
gdouble t_y1,
gdouble t_x2,
gdouble t_y2,
gdouble t_x3,
gdouble t_y3,
gdouble t_x4,
gdouble t_y4,
GimpMatrix3 *result)
{
GimpMatrix3 matrix;
gdouble scalex;
gdouble scaley;
g_return_if_fail (result != NULL);
scalex = scaley = 1.0;
if ((x2 - x1) > 0)
scalex = 1.0 / (gdouble) (x2 - x1);
if (width > 0)
scalex = 1.0 / (gdouble) width;
if ((y2 - y1) > 0)
scaley = 1.0 / (gdouble) (y2 - y1);
if (height > 0)
scaley = 1.0 / (gdouble) height;
/* Determine the perspective transform that maps from
* the unit cube to the transformed coordinates
......@@ -182,23 +216,23 @@ gimp_transform_matrix_perspective (gint x1,
{
gdouble dx1, dx2, dx3, dy1, dy2, dy3;
dx1 = tx2 - tx4;
dx2 = tx3 - tx4;
dx3 = tx1 - tx2 + tx4 - tx3;
dx1 = t_x2 - t_x4;
dx2 = t_x3 - t_x4;
dx3 = t_x1 - t_x2 + t_x4 - t_x3;
dy1 = ty2 - ty4;
dy2 = ty3 - ty4;
dy3 = ty1 - ty2 + ty4 - ty3;
dy1 = t_y2 - t_y4;
dy2 = t_y3 - t_y4;
dy3 = t_y1 - t_y2 + t_y4 - t_y3;
/* Is the mapping affine? */
if ((dx3 == 0.0) && (dy3 == 0.0))
{
matrix.coeff[0][0] = tx2 - tx1;
matrix.coeff[0][1] = tx4 - tx2;
matrix.coeff[0][2] = tx1;
matrix.coeff[1][0] = ty2 - ty1;
matrix.coeff[1][1] = ty4 - ty2;
matrix.coeff[1][2] = ty1;
matrix.coeff[0][0] = t_x2 - t_x1;
matrix.coeff[0][1] = t_x4 - t_x2;
matrix.coeff[0][2] = t_x1;
matrix.coeff[1][0] = t_y2 - t_y1;
matrix.coeff[1][1] = t_y4 - t_y2;
matrix.coeff[1][2] = t_y1;
matrix.coeff[2][0] = 0.0;
matrix.coeff[2][1] = 0.0;
}
......@@ -221,20 +255,20 @@ gimp_transform_matrix_perspective (gint x1,
else
matrix.coeff[2][1] = det1 / det2;
matrix.coeff[0][0] = tx2 - tx1 + matrix.coeff[2][0] * tx2;
matrix.coeff[0][1] = tx3 - tx1 + matrix.coeff[2][1] * tx3;
matrix.coeff[0][2] = tx1;
matrix.coeff[0][0] = t_x2 - t_x1 + matrix.coeff[2][0] * t_x2;
matrix.coeff[0][1] = t_x3 - t_x1 + matrix.coeff[2][1] * t_x3;
matrix.coeff[0][2] = t_x1;
matrix.coeff[1][0] = ty2 - ty1 + matrix.coeff[2][0] * ty2;
matrix.coeff[1][1] = ty3 - ty1 + matrix.coeff[2][1] * ty3;
matrix.coeff[1][2] = ty1;
matrix.coeff[1][0] = t_y2 - t_y1 + matrix.coeff[2][0] * t_y2;
matrix.coeff[1][1] = t_y3 - t_y1 + matrix.coeff[2][1] * t_y3;
matrix.coeff[1][2] = t_y1;
}
matrix.coeff[2][2] = 1.0;
}
gimp_matrix3_identity (result);
gimp_matrix3_translate (result, -x1, -y1);
gimp_matrix3_translate (result, -x, -y);
gimp_matrix3_scale (result, scalex, scaley);
gimp_matrix3_mult (&matrix, result);
}
......@@ -21,47 +21,56 @@
void gimp_transform_matrix_flip (GimpOrientationType flip_type,
gdouble axis,
GimpMatrix3 *result);
void gimp_transform_matrix_rotate (gint x1,
gint y1,
gint x2,
gint y2,
gdouble angle,
GimpMatrix3 *result);
void gimp_transform_matrix_rotate_center (gdouble cx,
gdouble cy,
gdouble angle,
GimpMatrix3 *result);
void gimp_transform_matrix_scale (gint x1,
gint y1,
gint x2,
gint y2,
gdouble tx1,
gdouble ty1,
gdouble tx2,
gdouble ty2,
GimpMatrix3 *result);
void gimp_transform_matrix_shear (gint x1,
gint y1,
gint x2,
gint y2,
gdouble axis,
GimpMatrix3 *result);
void gimp_transform_matrix_flip_free (gint x,
gint y,
gint width,
gint height,
gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2,
GimpMatrix3 *result);
void gimp_transform_matrix_rotate (gint x,
gint y,
gint width,
gint height,
gdouble angle,
GimpMatrix3 *result);
void gimp_transform_matrix_rotate_center (gdouble center_x,
gdouble center_y,
gdouble angle,
GimpMatrix3 *result);
void gimp_transform_matrix_scale (gint x,
gint y,
gint width,
gint height,
gdouble t_x,
gdouble t_y,
gdouble t_width,
gdouble t_height,
GimpMatrix3 *result);
void gimp_transform_matrix_shear (gint x,
gint y,
gint width,
gint height,
GimpOrientationType orientation,
gdouble amount,
GimpMatrix3 *result);
void gimp_transform_matrix_perspective (gint x1,
gint y1,
gint x2,
gint y2,
gdouble tx1,
gdouble ty1,
gdouble tx2,
gdouble ty2,
gdouble tx3,
gdouble ty3,
gdouble tx4,
gdouble ty5,
GimpMatrix3 *result);
gdouble amount,
GimpMatrix3 *result);
void gimp_transform_matrix_perspective (gint x,
gint y,
gint width,
gint height,
gdouble t_x1,
gdouble t_y1,
gdouble t_x2,
gdouble t_y2,
gdouble t_x3,
gdouble t_y3,
gdouble t_x4,
gdouble t_y4,
GimpMatrix3 *result);
#endif /* __GIMP_TRANSFORM_UTILS_H__ */
This diff is collapsed.
......@@ -74,7 +74,7 @@ void register_transform_tools_procs (Gimp *gimp);
void register_undo_procs (Gimp *gimp);
void register_unit_procs (Gimp *gimp);
/* 420 procedures registered total */
/* 421 procedures registered total */
void
internal_procs_init (Gimp *gimp,
......@@ -101,67 +101,67 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Context"), 0.095);
register_context_procs (gimp);
(* status_callback) (NULL, _("Convert"), 0.148);
(* status_callback) (NULL, _("Convert"), 0.147);
register_convert_procs (gimp);
(* status_callback) (NULL, _("Display procedures"), 0.155);
(* status_callback) (NULL, _("Display procedures"), 0.154);
register_display_procs (gimp);
(* status_callback) (NULL, _("Drawable procedures"), 0.164);
register_drawable_procs (gimp);
(* status_callback) (NULL, _("Transformation procedures"), 0.243);
(* status_callback) (NULL, _("Transformation procedures"), 0.242);
register_drawable_transform_procs (gimp);
(* status_callback) (NULL, _("Edit procedures"), 0.26);
(* status_callback) (NULL, _("Edit procedures"), 0.261);
register_edit_procs (gimp);
(* status_callback) (NULL, _("File Operations"), 0.279);
(* status_callback) (NULL, _("File Operations"), 0.28);
register_fileops_procs (gimp);
(* status_callback) (NULL, _("Floating selections"), 0.3);
(* status_callback) (NULL, _("Floating selections"), 0.302);
register_floating_sel_procs (gimp);
(* status_callback) (NULL, _("Font UI"), 0.314);
(* status_callback) (NULL, _("Font UI"), 0.316);
register_font_select_procs (gimp);
(* status_callback) (NULL, _("Fonts"), 0.321);
(* status_callback) (NULL, _("Fonts"), 0.323);
register_fonts_procs (gimp);
(* status_callback) (NULL, _("Gimprc procedures"), 0.326);
(* status_callback) (NULL, _("Gimprc procedures"), 0.328);
register_gimprc_procs (gimp);
(* status_callback) (NULL, _("Gradient"), 0.34);
(* status_callback) (NULL, _("Gradient"), 0.342);
register_gradient_procs (gimp);
(* status_callback) (NULL, _("Gradient UI"), 0.41);
(* status_callback) (NULL, _("Gradient UI"), 0.411);
register_gradient_select_procs (gimp);
(* status_callback) (NULL, _("Gradients"), 0.417);
(* status_callback) (NULL, _("Gradients"), 0.418);
register_gradients_procs (gimp);
(* status_callback) (NULL, _("Guide procedures"), 0.429);
(* status_callback) (NULL, _("Guide procedures"), 0.43);
register_guides_procs (gimp);
(* status_callback) (NULL, _("Help procedures"), 0.443);
(* status_callback) (NULL, _("Help procedures"), 0.444);
register_help_procs (gimp);
(* status_callback) (NULL, _("Image"), 0.445);
(* status_callback) (NULL, _("Image"), 0.447);
register_image_procs (gimp);
(* status_callback) (NULL, _("Layer"), 0.593);
(* status_callback) (NULL, _("Layer"), 0.594);
register_layer_procs (gimp);
(* status_callback) (NULL, _("Message procedures"), 0.655);
(* status_callback) (NULL, _("Message procedures"), 0.656);
register_message_procs (gimp);
(* status_callback) (NULL, _("Miscellaneous"), 0.662);
(* status_callback) (NULL, _("Miscellaneous"), 0.663);
register_misc_procs (gimp);
(* status_callback) (NULL, _("Paint Tool procedures"), 0.667);
register_paint_tools_procs (gimp);
(* status_callback) (NULL, _("Palette"), 0.702);
(* status_callback) (NULL, _("Palette"), 0.703);
register_palette_procs (gimp);
(* status_callback) (NULL, _("Palette UI"), 0.729);
......@@ -170,7 +170,7 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Palettes"), 0.736);
register_palettes_procs (gimp);
(* status_callback) (NULL, _("Parasite procedures"), 0.745);
(* status_callback) (NULL, _("Parasite procedures"), 0.746);
register_parasite_procs (gimp);
(* status_callback) (NULL, _("Paths"), 0.774);
......@@ -179,10 +179,10 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Pattern"), 0.81);
register_pattern_procs (gimp);
(* status_callback) (NULL, _("Pattern UI"), 0.814);
(* status_callback) (NULL, _("Pattern UI"), 0.815);
register_pattern_select_procs (gimp);
(* status_callback) (NULL, _("Patterns"), 0.821);
(* status_callback) (NULL, _("Patterns"), 0.822);
register_patterns_procs (gimp);
(* status_callback) (NULL, _("Plug-in"), 0.831);
......@@ -191,7 +191,7 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Procedural database"), 0.843);
register_procedural_db_procs (gimp);
(* status_callback) (NULL, _("Progress"), 0.864);
(* status_callback) (NULL, _("Progress"), 0.865);
register_progress_procs (gimp);
(* status_callback) (NULL, _("Image mask"), 0.876);
......@@ -203,7 +203,7 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Text procedures"), 0.931);
register_text_tool_procs (gimp);
(* status_callback) (NULL, _("Transform Tool procedures"), 0.94);
(* status_callback) (NULL, _("Transform Tool procedures"), 0.941);
register_transform_tools_procs (gimp);
(* status_callback) (NULL, _("Undo"), 0.955);
......
......@@ -76,11 +76,16 @@ flip_invoker (Gimp *gimp,
if (success)
{
gint x, y, width, height;
success = gimp_item_is_attached (GIMP_ITEM (drawable));
if (success)
success = gimp_drawable_transform_flip (drawable, context,
flip_type, TRUE, 0.0, FALSE);
if (success &&
gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
{
success = gimp_drawable_transform_flip (drawable, context,
flip_type, TRUE, 0.0, FALSE);
}
}
return_args = procedural_db_return_args (&flip_proc, success);
......@@ -167,43 +172,39 @@ perspective_invoker (Gimp *gimp,
if (success)
{
gint x, y, width, height;
success = gimp_item_is_attached (GIMP_ITEM (drawable));
if (success)
if (success &&
gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
{
gint x, y, width, height;
if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
{