Commit 5d7931db authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

changed all transform utilities to modify the passed transform matrix

2005-03-21  Sven Neumann  <sven@gimp.org>

	* app/core/gimp-transform-utils.[ch]: changed all transform
	utilities to modify the passed transform matrix instead of
	creating a new one.

	* app/text/gimptextlayer-transform.c
	* app/tools/gimpperspectivetool.c
	* app/tools/gimprotatetool.c
	* app/tools/gimpscaletool.c
	* app/tools/gimpsheartool.c
	* app/vectors/gimpvectors.c
	* tools/pdbgen/pdb/drawable_transform.pdb
	* tools/pdbgen/pdb/transform_tools.pdb: changed accordingly.

	* app/pdb/drawable_transform_cmds.c
	* app/pdb/transform_tools_cmds.c: regenerated.
parent 32d063d9
2005-03-21 Sven Neumann <sven@gimp.org>
* app/core/gimp-transform-utils.[ch]: changed all transform
utilities to modify the passed transform matrix instead of
creating a new one.
* app/text/gimptextlayer-transform.c
* app/tools/gimpperspectivetool.c
* app/tools/gimprotatetool.c
* app/tools/gimpscaletool.c
* app/tools/gimpsheartool.c
* app/vectors/gimpvectors.c
* tools/pdbgen/pdb/drawable_transform.pdb
* tools/pdbgen/pdb/transform_tools.pdb: changed accordingly.
* app/pdb/drawable_transform_cmds.c
* app/pdb/transform_tools_cmds.c: regenerated.
2005-03-21 Sven Neumann <sven@gimp.org>
* plug-ins/winicon/icosave.c (ico_create_palette): fixed parameter
......
......@@ -28,26 +28,24 @@
void
gimp_transform_matrix_flip (GimpOrientationType flip_type,
gdouble axis,
GimpMatrix3 *result)
gimp_transform_matrix_flip (GimpMatrix3 *matrix,
GimpOrientationType flip_type,
gdouble axis)
{
g_return_if_fail (result != NULL);
gimp_matrix3_identity (result);
g_return_if_fail (matrix != NULL);
switch (flip_type)
{
case GIMP_ORIENTATION_HORIZONTAL:
gimp_matrix3_translate (result, - axis, 0.0);
gimp_matrix3_scale (result, -1.0, 1.0);
gimp_matrix3_translate (result, axis, 0.0);
gimp_matrix3_translate (matrix, - axis, 0.0);
gimp_matrix3_scale (matrix, -1.0, 1.0);
gimp_matrix3_translate (matrix, axis, 0.0);
break;
case GIMP_ORIENTATION_VERTICAL:
gimp_matrix3_translate (result, 0.0, - axis);
gimp_matrix3_scale (result, 1.0, -1.0);
gimp_matrix3_translate (result, 0.0, axis);
gimp_matrix3_translate (matrix, 0.0, - axis);
gimp_matrix3_scale (matrix, 1.0, -1.0);
gimp_matrix3_translate (matrix, 0.0, axis);
break;
case GIMP_ORIENTATION_UNKNOWN:
......@@ -56,81 +54,103 @@ gimp_transform_matrix_flip (GimpOrientationType flip_type,
}
void
gimp_transform_matrix_flip_free (gint x,
gimp_transform_matrix_flip_free (GimpMatrix3 *matrix,
gint x,
gint y,
gint width,
gint height,
gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2,
GimpMatrix3 *result)
gdouble y2)
{
gdouble angle;
g_return_if_fail (result != NULL);
g_return_if_fail (matrix != NULL);
angle = atan2 (y2 - y1, x2 - x1);
gimp_matrix3_identity (result);
gimp_matrix3_translate (result, -x1, -y1);
gimp_matrix3_rotate (result, -angle);
gimp_matrix3_scale (result, 1.0, -1.0);
gimp_matrix3_rotate (result, angle);
gimp_matrix3_translate (result, x1, y1);
gimp_matrix3_identity (matrix);
gimp_matrix3_translate (matrix, -x1, -y1);
gimp_matrix3_rotate (matrix, -angle);
gimp_matrix3_scale (matrix, 1.0, -1.0);
gimp_matrix3_rotate (matrix, angle);
gimp_matrix3_translate (matrix, x1, y1);
}
void
gimp_transform_matrix_rotate (GimpMatrix3 *matrix,
GimpRotationType rotate_type,
gdouble center_x,
gdouble center_y)
{
gdouble angle = 0;
switch (rotate_type)
{
case GIMP_ROTATE_90:
angle = G_PI_2;
break;
case GIMP_ROTATE_180:
angle = G_PI;
break;
case GIMP_ROTATE_270:
angle = - G_PI_2;
break;
}
gimp_transform_matrix_rotate_center (matrix, center_x, center_y, angle);
}
void
gimp_transform_matrix_rotate (gint x,
gint y,
gint width,
gint height,
gdouble angle,
GimpMatrix3 *result)
gimp_transform_matrix_rotate_rect (GimpMatrix3 *matrix,
gint x,
gint y,
gint width,
gint height,
gdouble angle)
{
gdouble center_x;
gdouble center_y;
g_return_if_fail (result != NULL);
g_return_if_fail (matrix != 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, -center_x, -center_y);
gimp_matrix3_rotate (result, angle);
gimp_matrix3_translate (result, +center_x, +center_y);
gimp_matrix3_translate (matrix, -center_x, -center_y);
gimp_matrix3_rotate (matrix, angle);
gimp_matrix3_translate (matrix, +center_x, +center_y);
}
void
gimp_transform_matrix_rotate_center (gdouble center_x,
gimp_transform_matrix_rotate_center (GimpMatrix3 *matrix,
gdouble center_x,
gdouble center_y,
gdouble angle,
GimpMatrix3 *result)
gdouble angle)
{
g_return_if_fail (result != NULL);
g_return_if_fail (matrix != NULL);
gimp_matrix3_identity (result);
gimp_matrix3_translate (result, -center_x, -center_y);
gimp_matrix3_rotate (result, angle);
gimp_matrix3_translate (result, +center_x, +center_y);
gimp_matrix3_translate (matrix, -center_x, -center_y);
gimp_matrix3_rotate (matrix, angle);
gimp_matrix3_translate (matrix, +center_x, +center_y);
}
void
gimp_transform_matrix_scale (gint x,
gimp_transform_matrix_scale (GimpMatrix3 *matrix,
gint x,
gint y,
gint width,
gint height,
gdouble t_x,
gdouble t_y,
gdouble t_width,
gdouble t_height,
GimpMatrix3 *result)
gdouble t_height)
{
gdouble scale_x = 1.0;
gdouble scale_y = 1.0;
g_return_if_fail (result != NULL);
g_return_if_fail (matrix != NULL);
if (width > 0)
scale_x = t_width / (gdouble) width;
......@@ -138,25 +158,25 @@ gimp_transform_matrix_scale (gint x,
if (height > 0)
scale_y = t_height / (gdouble) height;
gimp_matrix3_identity (result);
gimp_matrix3_translate (result, -x, -y);
gimp_matrix3_scale (result, scale_x, scale_y);
gimp_matrix3_translate (result, t_x, t_y);
gimp_matrix3_identity (matrix);
gimp_matrix3_translate (matrix, -x, -y);
gimp_matrix3_scale (matrix, scale_x, scale_y);
gimp_matrix3_translate (matrix, t_x, t_y);
}
void
gimp_transform_matrix_shear (gint x,
gimp_transform_matrix_shear (GimpMatrix3 *matrix,
gint x,
gint y,
gint width,
gint height,
GimpOrientationType orientation,
gdouble amount,
GimpMatrix3 *result)
gdouble amount)
{
gdouble center_x;
gdouble center_y;
g_return_if_fail (result != NULL);
g_return_if_fail (matrix != NULL);
if (width == 0)
width = 1;
......@@ -167,19 +187,20 @@ gimp_transform_matrix_shear (gint x,
center_x = (gdouble) x + (gdouble) width / 2.0;
center_y = (gdouble) y + (gdouble) height / 2.0;
gimp_matrix3_identity (result);
gimp_matrix3_translate (result, -center_x, -center_y);
gimp_matrix3_identity (matrix);
gimp_matrix3_translate (matrix, -center_x, -center_y);
if (orientation == GIMP_ORIENTATION_HORIZONTAL)
gimp_matrix3_xshear (result, amount / height);
gimp_matrix3_xshear (matrix, amount / height);
else
gimp_matrix3_yshear (result, amount / width);
gimp_matrix3_yshear (matrix, amount / width);
gimp_matrix3_translate (result, +center_x, +center_y);
gimp_matrix3_translate (matrix, +center_x, +center_y);
}
void
gimp_transform_matrix_perspective (gint x,
gimp_transform_matrix_perspective (GimpMatrix3 *matrix,
gint x,
gint y,
gint width,
gint height,
......@@ -190,14 +211,13 @@ gimp_transform_matrix_perspective (gint x,
gdouble t_x3,
gdouble t_y3,
gdouble t_x4,
gdouble t_y4,
GimpMatrix3 *result)
gdouble t_y4)
{
GimpMatrix3 matrix;
GimpMatrix3 trafo;
gdouble scalex;
gdouble scaley;
g_return_if_fail (result != NULL);
g_return_if_fail (matrix != NULL);
scalex = scaley = 1.0;
......@@ -207,6 +227,9 @@ gimp_transform_matrix_perspective (gint x,
if (height > 0)
scaley = 1.0 / (gdouble) height;
gimp_matrix3_translate (matrix, -x, -y);
gimp_matrix3_scale (matrix, scalex, scaley);
/* Determine the perspective transform that maps from
* the unit cube to the transformed coordinates
*/
......@@ -224,43 +247,40 @@ gimp_transform_matrix_perspective (gint x,
/* Is the mapping affine? */
if ((dx3 == 0.0) && (dy3 == 0.0))
{
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;
matrix.coeff[2][2] = 1.0;
trafo.coeff[0][0] = t_x2 - t_x1;
trafo.coeff[0][1] = t_x4 - t_x2;
trafo.coeff[0][2] = t_x1;
trafo.coeff[1][0] = t_y2 - t_y1;
trafo.coeff[1][1] = t_y4 - t_y2;
trafo.coeff[1][2] = t_y1;
trafo.coeff[2][0] = 0.0;
trafo.coeff[2][1] = 0.0;
trafo.coeff[2][2] = 1.0;
}
else
{
gdouble det1, det2;
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;
trafo.coeff[0][0] = t_x2 - t_x1 + trafo.coeff[2][0] * t_x2;
trafo.coeff[0][1] = t_x3 - t_x1 + trafo.coeff[2][1] * t_x3;
trafo.coeff[0][2] = t_x1;
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;
trafo.coeff[1][0] = t_y2 - t_y1 + trafo.coeff[2][0] * t_y2;
trafo.coeff[1][1] = t_y3 - t_y1 + trafo.coeff[2][1] * t_y3;
trafo.coeff[1][2] = t_y1;
det1 = dx3 * dy2 - dy3 * dx2;
det2 = dx1 * dy2 - dy1 * dx2;
matrix.coeff[2][0] = (det2 == 0.0) ? 1.0 : det1 / det2;
trafo.coeff[2][0] = (det2 == 0.0) ? 1.0 : det1 / det2;
det1 = dx1 * dy3 - dy1 * dx3;
matrix.coeff[2][1] = (det2 == 0.0) ? 1.0 : det1 / det2;
trafo.coeff[2][1] = (det2 == 0.0) ? 1.0 : det1 / det2;
matrix.coeff[2][2] = 1.0;
trafo.coeff[2][2] = 1.0;
}
}
gimp_matrix3_identity (result);
gimp_matrix3_translate (result, -x, -y);
gimp_matrix3_scale (result, scalex, scaley);
gimp_matrix3_mult (&matrix, result);
gimp_matrix3_mult (&trafo, matrix);
}
......@@ -20,45 +20,50 @@
#define __GIMP_TRANSFORM_UTILS_H__
void gimp_transform_matrix_flip (GimpOrientationType flip_type,
gdouble axis,
GimpMatrix3 *result);
void gimp_transform_matrix_flip_free (gint x,
void gimp_transform_matrix_flip (GimpMatrix3 *matrix,
GimpOrientationType flip_type,
gdouble axis);
void gimp_transform_matrix_flip_free (GimpMatrix3 *matrix,
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,
gdouble y2);
void gimp_transform_matrix_rotate (GimpMatrix3 *matrix,
GimpRotationType rotate_type,
gdouble center_x,
gdouble center_y);
void gimp_transform_matrix_rotate_rect (GimpMatrix3 *matrix,
gint x,
gint y,
gint width,
gint height,
gdouble angle,
GimpMatrix3 *result);
void gimp_transform_matrix_rotate_center (gdouble center_x,
gdouble angle);
void gimp_transform_matrix_rotate_center (GimpMatrix3 *matrix,
gdouble center_x,
gdouble center_y,
gdouble angle,
GimpMatrix3 *result);
void gimp_transform_matrix_scale (gint x,
gdouble angle);
void gimp_transform_matrix_scale (GimpMatrix3 *matrix,
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,
gdouble t_height);
void gimp_transform_matrix_shear (GimpMatrix3 *matrix,
gint x,
gint y,
gint width,
gint height,
GimpOrientationType orientation,
gdouble amount,
GimpMatrix3 *result);
void gimp_transform_matrix_perspective (gint x,
gdouble amount);
void gimp_transform_matrix_perspective (GimpMatrix3 *matrix,
gint x,
gint y,
gint width,
gint height,
......@@ -69,8 +74,7 @@ void gimp_transform_matrix_perspective (gint x,
gdouble t_x3,
gdouble t_y3,
gdouble t_x4,
gdouble t_y4,
GimpMatrix3 *result);
gdouble t_y4);
#endif /* __GIMP_TRANSFORM_UTILS_H__ */
......@@ -241,9 +241,9 @@ drawable_transform_flip_invoker (Gimp *gimp,
GimpMatrix3 matrix;
/* Assemble the transformation matrix */
gimp_transform_matrix_flip_free (x, y, width, height,
x0, y0, x1, y1,
&matrix);
gimp_matrix3_identity (&matrix);
gimp_transform_matrix_flip_free (&matrix,
x, y, width, height, x0, y0, x1, y1);
if (progress)
gimp_progress_start (progress, _("Flip..."), FALSE);
......@@ -393,9 +393,9 @@ drawable_transform_flip_default_invoker (Gimp *gimp,
GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
/* Assemble the transformation matrix */
gimp_transform_matrix_flip_free (x, y, width, height,
x0, y0, x1, y1,
&matrix);
gimp_matrix3_identity (&matrix);
gimp_transform_matrix_flip_free (&matrix,
x, y, width, height, x0, y0, x1, y1);
if (interpolate)
interpolation_type = gimp->config->interpolation_type;
......@@ -552,12 +552,13 @@ drawable_transform_perspective_invoker (Gimp *gimp,
GimpMatrix3 matrix;
/* Assemble the transformation matrix */
gimp_transform_matrix_perspective (x, y, width, height,
gimp_matrix3_identity (&matrix);
gimp_transform_matrix_perspective (&matrix,
x, y, width, height,
trans_info[X0], trans_info[Y0],
trans_info[X1], trans_info[Y1],
trans_info[X2], trans_info[Y2],
trans_info[X3], trans_info[Y3],
&matrix);
trans_info[X3], trans_info[Y3]);
if (progress)
gimp_progress_start (progress, _("Perspective..."), FALSE);
......@@ -732,12 +733,13 @@ drawable_transform_perspective_default_invoker (Gimp *gimp,
GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
/* Assemble the transformation matrix */
gimp_transform_matrix_perspective (x, y, width, height,
gimp_matrix3_identity (&matrix);
gimp_transform_matrix_perspective (&matrix,
x, y, width, height,
trans_info[X0], trans_info[Y0],
trans_info[X1], trans_info[Y1],
trans_info[X2], trans_info[Y2],
trans_info[X3], trans_info[Y3],
&matrix);
trans_info[X3], trans_info[Y3]);
if (interpolate)
interpolation_type = gimp->config->interpolation_type;
......@@ -1024,12 +1026,12 @@ drawable_transform_rotate_invoker (Gimp *gimp,
GimpMatrix3 matrix;
/* Assemble the transformation matrix */
gimp_matrix3_identity (&matrix);
if (auto_center)
gimp_transform_matrix_rotate (x, y, width, height, angle,
&matrix);
gimp_transform_matrix_rotate_rect (&matrix, x, y, width, height, angle);
else
gimp_transform_matrix_rotate_center (center_x, center_y, angle,
&matrix);
gimp_transform_matrix_rotate_center (&matrix,
center_x, center_y, angle);
if (progress)
gimp_progress_start (progress, _("Rotating..."), FALSE);
......@@ -1179,12 +1181,12 @@ drawable_transform_rotate_default_invoker (Gimp *gimp,
GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
/* Assemble the transformation matrix */
gimp_matrix3_identity (&matrix);
if (auto_center)
gimp_transform_matrix_rotate (x, y, width, height, angle,
&matrix);
gimp_transform_matrix_rotate_rect (&matrix, x, y, width, height, angle);
else
gimp_transform_matrix_rotate_center (center_x, center_y, angle,
&matrix);
gimp_transform_matrix_rotate_center (&matrix,
center_x, center_y, angle);
if (interpolate)
interpolation_type = gimp->config->interpolation_type;
......@@ -1335,12 +1337,13 @@ drawable_transform_scale_invoker (Gimp *gimp,
GimpMatrix3 matrix;
/* Assemble the transformation matrix */
gimp_transform_matrix_scale (x, y, width, height,
gimp_matrix3_identity (&matrix);
gimp_transform_matrix_scale (&matrix,
x, y, width, height,
trans_info[X0],
trans_info[Y0],
trans_info[X1] - trans_info[X0],
trans_info[Y1] - trans_info[Y0],
&matrix);
trans_info[Y1] - trans_info[Y0]);
if (progress)
gimp_progress_start (progress, _("Scaling..."), FALSE);
......@@ -1489,12 +1492,13 @@ drawable_transform_scale_default_invoker (Gimp *gimp,
GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
/* Assemble the transformation matrix */
gimp_transform_matrix_scale (x, y, width, height,
gimp_matrix3_identity (&matrix);
gimp_transform_matrix_scale (&matrix,
x, y, width, height,
trans_info[X0],
trans_info[Y0],
trans_info[X1] - trans_info[X0],
trans_info[Y1] - trans_info[Y0],
&matrix);
trans_info[Y1] - trans_info[Y0]);
if (interpolate)
interpolation_type = gimp->config->interpolation_type;
......@@ -1642,9 +1646,10 @@ drawable_transform_shear_invoker (Gimp *gimp,
GimpMatrix3 matrix;
/* Assemble the transformation matrix */
gimp_transform_matrix_shear (x, y, width, height,
shear_type, magnitude,
&matrix);
gimp_matrix3_identity (&matrix);
gimp_transform_matrix_shear (&matrix,
x, y, width, height,
shear_type, magnitude);
if (progress)
gimp_progress_start (progress, _("Shearing..."), FALSE);
......@@ -1780,9 +1785,10 @@ drawable_transform_shear_default_invoker (Gimp *gimp,
GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
/* Assemble the transformation matrix */
gimp_transform_matrix_shear (x, y, width, height,
shear_type, magnitude,
&matrix);
gimp_matrix3_identity (&matrix);
gimp_transform_matrix_shear (&matrix,
x, y, width, height,
shear_type, magnitude);
if (interpolate)
interpolation_type = gimp->config->interpolation_type;
......
......@@ -183,12 +183,13 @@ perspective_invoker (Gimp *gimp,
GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
/* Assemble the transformation matrix */
gimp_transform_matrix_perspective (x, y, width, height,
gimp_matrix3_identity (&matrix);
gimp_transform_matrix_perspective (&matrix,
x, y, width, height,
trans_info[X0], trans_info[Y0],
trans_info[X1], trans_info[Y1],
trans_info[X2], trans_info[Y2],
trans_info[X3], trans_info[Y3],
&matrix);
trans_info[X3], trans_info[Y3]);