libgimpmath/gimpmathtypes.h moved struct declarations.

2003-07-07  Sven Neumann  <sven@gimp.org>

	* libgimpmath/gimpmathtypes.h
	* libgimpmath/gimpvector.h: moved struct declarations.

	* libgimpmath/gimpmatrix.[ch]: made GimpMatrix3 and GimpMatrix4
	structs instead of typedefs for arrays. Pass them by reference,
	not by value. Added lots of const qualifiers.

	* app/core/gimpchannel.c
	* app/core/gimpdrawable-transform-utils.[ch]
	* app/core/gimpdrawable-transform.[ch]
	* app/core/gimpdrawable.c
	* app/core/gimpitem-linked.[ch]
	* app/core/gimpitem.[ch]
	* app/core/gimplayer.c
	* app/pdb/transform_tools_cmds.c
	* app/tools/gimpperspectivetool.c
	* app/tools/gimprotatetool.c
	* app/tools/gimpscaletool.c
	* app/tools/gimpsheartool.c
	* app/tools/gimptransformtool.c
	* app/vectors/gimpvectors.c
	* tools/pdbgen/pdb/transform_tools.pdb: changed accordingly.
This commit is contained in:
Sven Neumann 2003-07-07 13:50:48 +00:00 committed by Sven Neumann
parent 6b99ae0405
commit 5c4020edf2
31 changed files with 536 additions and 523 deletions

View file

@ -1,3 +1,28 @@
2003-07-07 Sven Neumann <sven@gimp.org>
* libgimpmath/gimpmathtypes.h
* libgimpmath/gimpvector.h: moved struct declarations.
* libgimpmath/gimpmatrix.[ch]: made GimpMatrix3 and GimpMatrix4
structs instead of typedefs for arrays. Pass them by reference,
not by value. Added lots of const qualifiers.
* app/core/gimpchannel.c
* app/core/gimpdrawable-transform-utils.[ch]
* app/core/gimpdrawable-transform.[ch]
* app/core/gimpdrawable.c
* app/core/gimpitem-linked.[ch]
* app/core/gimpitem.[ch]
* app/core/gimplayer.c
* app/pdb/transform_tools_cmds.c
* app/tools/gimpperspectivetool.c
* app/tools/gimprotatetool.c
* app/tools/gimpscaletool.c
* app/tools/gimpsheartool.c
* app/tools/gimptransformtool.c
* app/vectors/gimpvectors.c
* tools/pdbgen/pdb/transform_tools.pdb: changed accordingly.
2003-07-07 Sven Neumann <sven@gimp.org>
* plug-ins/common/mng.c: applied a patch from S. Mukund that fixes

View file

@ -100,7 +100,7 @@ sample_linear(PixelSurround *surround,
TileManager *
gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
TileManager *orig_tiles,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,
@ -110,8 +110,8 @@ gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
GimpImage *gimage;
PixelRegion destPR;
TileManager *new_tiles;
GimpMatrix3 m;
GimpMatrix3 im;
GimpMatrix3 m = *matrix;
GimpMatrix3 inv = *matrix;
PixelSurround surround;
gint x1, y1, x2, y2; /* target bounding box */
@ -191,14 +191,12 @@ gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
/* keep the original matrix here, so we dont need to recalculate
* the inverse later
*/
gimp_matrix3_duplicate (matrix, m);
gimp_matrix3_invert (matrix, im);
matrix = im;
gimp_matrix3_invert (&inv);
}
else
{
/* Find the inverse of the transformation matrix */
gimp_matrix3_invert (matrix, m);
gimp_matrix3_invert (&m);
}
tile_manager_get_offsets (orig_tiles, &u1, &v1);
@ -224,10 +222,10 @@ gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
gdouble dx3, dy3;
gdouble dx4, dy4;
gimp_matrix3_transform_point (matrix, u1, v1, &dx1, &dy1);
gimp_matrix3_transform_point (matrix, u2, v1, &dx2, &dy2);
gimp_matrix3_transform_point (matrix, u1, v2, &dx3, &dy3);
gimp_matrix3_transform_point (matrix, u2, v2, &dx4, &dy4);
gimp_matrix3_transform_point (&inv, u1, v1, &dx1, &dy1);
gimp_matrix3_transform_point (&inv, u2, v1, &dx2, &dy2);
gimp_matrix3_transform_point (&inv, u1, v2, &dx3, &dy3);
gimp_matrix3_transform_point (&inv, u2, v2, &dx4, &dy4);
x1 = ROUND (MIN4 (dx1, dx2, dx3, dx4));
y1 = ROUND (MIN4 (dy1, dy2, dy3, dy4));
@ -261,9 +259,9 @@ gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
dest = g_new (guchar, tile_manager_width (new_tiles) * bytes);
uinc = m[0][0];
vinc = m[1][0];
winc = m[2][0];
uinc = m.coeff[0][0];
vinc = m.coeff[1][0];
winc = m.coeff[2][0];
coords = (interpolation_type != GIMP_INTERPOLATION_NONE) ? 5 : 1;
@ -277,30 +275,30 @@ gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
(* progress_callback) (y1, y2, y, progress_data);
/* set up inverse transform steps */
tu[0] = uinc * (x1 + 0.5) + m[0][1] * (y + 0.5) + m[0][2] - 0.5;
tv[0] = vinc * (x1 + 0.5) + m[1][1] * (y + 0.5) + m[1][2] - 0.5;
tw[0] = winc * (x1 + 0.5) + m[2][1] * (y + 0.5) + m[2][2];
tu[0] = uinc * (x1 + 0.5) + m.coeff[0][1] * (y + 0.5) + m.coeff[0][2] - 0.5;
tv[0] = vinc * (x1 + 0.5) + m.coeff[1][1] * (y + 0.5) + m.coeff[1][2] - 0.5;
tw[0] = winc * (x1 + 0.5) + m.coeff[2][1] * (y + 0.5) + m.coeff[2][2];
if (interpolation_type != GIMP_INTERPOLATION_NONE)
{
gdouble xx = x1 + 0.5;
gdouble yy = y + 0.5;
tu[1] = uinc * (xx - 1) + m[0][1] * (yy ) + m[0][2] - 0.5;
tv[1] = vinc * (xx - 1) + m[1][1] * (yy ) + m[1][2] - 0.5;
tw[1] = winc * (xx - 1) + m[2][1] * (yy ) + m[2][2];
tu[1] = uinc * (xx - 1) + m.coeff[0][1] * (yy ) + m.coeff[0][2] - 0.5;
tv[1] = vinc * (xx - 1) + m.coeff[1][1] * (yy ) + m.coeff[1][2] - 0.5;
tw[1] = winc * (xx - 1) + m.coeff[2][1] * (yy ) + m.coeff[2][2];
tu[2] = uinc * (xx ) + m[0][1] * (yy - 1) + m[0][2] - 0.5;
tv[2] = vinc * (xx ) + m[1][1] * (yy - 1) + m[1][2] - 0.5;
tw[2] = winc * (xx ) + m[2][1] * (yy - 1) + m[2][2];
tu[2] = uinc * (xx ) + m.coeff[0][1] * (yy - 1) + m.coeff[0][2] - 0.5;
tv[2] = vinc * (xx ) + m.coeff[1][1] * (yy - 1) + m.coeff[1][2] - 0.5;
tw[2] = winc * (xx ) + m.coeff[2][1] * (yy - 1) + m.coeff[2][2];
tu[3] = uinc * (xx + 1) + m[0][1] * (yy ) + m[0][2] - 0.5;
tv[3] = vinc * (xx + 1) + m[1][1] * (yy ) + m[1][2] - 0.5;
tw[3] = winc * (xx + 1) + m[2][1] * (yy ) + m[2][2];
tu[3] = uinc * (xx + 1) + m.coeff[0][1] * (yy ) + m.coeff[0][2] - 0.5;
tv[3] = vinc * (xx + 1) + m.coeff[1][1] * (yy ) + m.coeff[1][2] - 0.5;
tw[3] = winc * (xx + 1) + m.coeff[2][1] * (yy ) + m.coeff[2][2];
tu[4] = uinc * (xx ) + m[0][1] * (yy + 1) + m[0][2] - 0.5;
tv[4] = vinc * (xx ) + m[1][1] * (yy + 1) + m[1][2] - 0.5;
tw[4] = winc * (xx ) + m[2][1] * (yy + 1) + m[2][2];
tu[4] = uinc * (xx ) + m.coeff[0][1] * (yy + 1) + m.coeff[0][2] - 0.5;
tv[4] = vinc * (xx ) + m.coeff[1][1] * (yy + 1) + m.coeff[1][2] - 0.5;
tw[4] = winc * (xx ) + m.coeff[2][1] * (yy + 1) + m.coeff[2][2];
}
d = dest;
@ -805,7 +803,7 @@ gimp_drawable_transform_tiles_rotate (GimpDrawable *drawable,
gboolean
gimp_drawable_transform_affine (GimpDrawable *drawable,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result)

View file

@ -33,7 +33,7 @@ gimp_drawable_transform_matrix_rotate (gint x1,
gint x2,
gint y2,
gdouble angle,
GimpMatrix3 result)
GimpMatrix3 *result)
{
gdouble cx;
gdouble cy;
@ -51,7 +51,7 @@ void
gimp_drawable_transform_matrix_rotate_center (gdouble cx,
gdouble cy,
gdouble angle,
GimpMatrix3 result)
GimpMatrix3 *result)
{
gimp_matrix3_identity (result);
gimp_matrix3_translate (result, -cx, -cy);
@ -68,7 +68,7 @@ gimp_drawable_transform_matrix_scale (gint x1,
gdouble ty1,
gdouble tx2,
gdouble ty2,
GimpMatrix3 result)
GimpMatrix3 *result)
{
gdouble scalex;
gdouble scaley;
@ -94,7 +94,7 @@ gimp_drawable_transform_matrix_shear (gint x1,
gint y2,
GimpOrientationType orientation,
gdouble amount,
GimpMatrix3 result)
GimpMatrix3 *result)
{
gint width;
gint height;
@ -136,7 +136,7 @@ gimp_drawable_transform_matrix_perspective (gint x1,
gdouble ty3,
gdouble tx4,
gdouble ty4,
GimpMatrix3 result)
GimpMatrix3 *result)
{
GimpMatrix3 matrix;
gdouble scalex;
@ -167,14 +167,14 @@ gimp_drawable_transform_matrix_perspective (gint x1,
/* Is the mapping affine? */
if ((dx3 == 0.0) && (dy3 == 0.0))
{
matrix[0][0] = tx2 - tx1;
matrix[0][1] = tx4 - tx2;
matrix[0][2] = tx1;
matrix[1][0] = ty2 - ty1;
matrix[1][1] = ty4 - ty2;
matrix[1][2] = ty1;
matrix[2][0] = 0.0;
matrix[2][1] = 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[2][0] = 0.0;
matrix.coeff[2][1] = 0.0;
}
else
{
@ -182,24 +182,24 @@ gimp_drawable_transform_matrix_perspective (gint x1,
det1 = dx3 * dy2 - dy3 * dx2;
det2 = dx1 * dy2 - dy1 * dx2;
matrix[2][0] = det1 / det2;
matrix.coeff[2][0] = det1 / det2;
det1 = dx1 * dy3 - dy1 * dx3;
matrix[2][1] = det1 / det2;
matrix.coeff[2][1] = det1 / det2;
matrix[0][0] = tx2 - tx1 + matrix[2][0] * tx2;
matrix[0][1] = tx3 - tx1 + matrix[2][1] * tx3;
matrix[0][2] = tx1;
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[1][0] = ty2 - ty1 + matrix[2][0] * ty2;
matrix[1][1] = ty3 - ty1 + matrix[2][1] * ty3;
matrix[1][2] = ty1;
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[2][2] = 1.0;
matrix.coeff[2][2] = 1.0;
}
gimp_matrix3_identity (result);
gimp_matrix3_translate (result, -x1, -y1);
gimp_matrix3_scale (result, scalex, scaley);
gimp_matrix3_mult (matrix, result);
gimp_matrix3_mult (&matrix, result);
}

View file

@ -25,11 +25,11 @@ void gimp_drawable_transform_matrix_rotate (gint x1,
gint x2,
gint y2,
gdouble angle,
GimpMatrix3 result);
GimpMatrix3 *result);
void gimp_drawable_transform_matrix_rotate_center (gdouble cx,
gdouble cy,
gdouble angle,
GimpMatrix3 result);
GimpMatrix3 *result);
void gimp_drawable_transform_matrix_scale (gint x1,
gint y1,
gint x2,
@ -38,14 +38,14 @@ void gimp_drawable_transform_matrix_scale (gint x1,
gdouble ty1,
gdouble tx2,
gdouble ty2,
GimpMatrix3 result);
GimpMatrix3 *result);
void gimp_drawable_transform_matrix_shear (gint x1,
gint y1,
gint x2,
gint y2,
GimpOrientationType orientation,
gdouble amount,
GimpMatrix3 result);
GimpMatrix3 *result);
void gimp_drawable_transform_matrix_perspective (gint x1,
gint y1,
gint x2,
@ -58,7 +58,7 @@ void gimp_drawable_transform_matrix_perspective (gint x1,
gdouble ty3,
gdouble tx4,
gdouble ty5,
GimpMatrix3 result);
GimpMatrix3 *result);
#endif /* __GIMP_DRAWABLE_TRANSFORM_SHEAR_H__ */

View file

@ -84,7 +84,7 @@ static void gimp_channel_rotate (GimpItem *item,
gdouble center_y,
gboolean flip_result);
static void gimp_channel_transform (GimpItem *item,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,
@ -468,7 +468,7 @@ gimp_channel_rotate (GimpItem *item,
static void
gimp_channel_transform (GimpItem *item,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,

View file

@ -84,7 +84,7 @@ static void gimp_channel_rotate (GimpItem *item,
gdouble center_y,
gboolean flip_result);
static void gimp_channel_transform (GimpItem *item,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,
@ -468,7 +468,7 @@ gimp_channel_rotate (GimpItem *item,
static void
gimp_channel_transform (GimpItem *item,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,

View file

@ -33,7 +33,7 @@ gimp_drawable_transform_matrix_rotate (gint x1,
gint x2,
gint y2,
gdouble angle,
GimpMatrix3 result)
GimpMatrix3 *result)
{
gdouble cx;
gdouble cy;
@ -51,7 +51,7 @@ void
gimp_drawable_transform_matrix_rotate_center (gdouble cx,
gdouble cy,
gdouble angle,
GimpMatrix3 result)
GimpMatrix3 *result)
{
gimp_matrix3_identity (result);
gimp_matrix3_translate (result, -cx, -cy);
@ -68,7 +68,7 @@ gimp_drawable_transform_matrix_scale (gint x1,
gdouble ty1,
gdouble tx2,
gdouble ty2,
GimpMatrix3 result)
GimpMatrix3 *result)
{
gdouble scalex;
gdouble scaley;
@ -94,7 +94,7 @@ gimp_drawable_transform_matrix_shear (gint x1,
gint y2,
GimpOrientationType orientation,
gdouble amount,
GimpMatrix3 result)
GimpMatrix3 *result)
{
gint width;
gint height;
@ -136,7 +136,7 @@ gimp_drawable_transform_matrix_perspective (gint x1,
gdouble ty3,
gdouble tx4,
gdouble ty4,
GimpMatrix3 result)
GimpMatrix3 *result)
{
GimpMatrix3 matrix;
gdouble scalex;
@ -167,14 +167,14 @@ gimp_drawable_transform_matrix_perspective (gint x1,
/* Is the mapping affine? */
if ((dx3 == 0.0) && (dy3 == 0.0))
{
matrix[0][0] = tx2 - tx1;
matrix[0][1] = tx4 - tx2;
matrix[0][2] = tx1;
matrix[1][0] = ty2 - ty1;
matrix[1][1] = ty4 - ty2;
matrix[1][2] = ty1;
matrix[2][0] = 0.0;
matrix[2][1] = 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[2][0] = 0.0;
matrix.coeff[2][1] = 0.0;
}
else
{
@ -182,24 +182,24 @@ gimp_drawable_transform_matrix_perspective (gint x1,
det1 = dx3 * dy2 - dy3 * dx2;
det2 = dx1 * dy2 - dy1 * dx2;
matrix[2][0] = det1 / det2;
matrix.coeff[2][0] = det1 / det2;
det1 = dx1 * dy3 - dy1 * dx3;
matrix[2][1] = det1 / det2;
matrix.coeff[2][1] = det1 / det2;
matrix[0][0] = tx2 - tx1 + matrix[2][0] * tx2;
matrix[0][1] = tx3 - tx1 + matrix[2][1] * tx3;
matrix[0][2] = tx1;
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[1][0] = ty2 - ty1 + matrix[2][0] * ty2;
matrix[1][1] = ty3 - ty1 + matrix[2][1] * ty3;
matrix[1][2] = ty1;
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[2][2] = 1.0;
matrix.coeff[2][2] = 1.0;
}
gimp_matrix3_identity (result);
gimp_matrix3_translate (result, -x1, -y1);
gimp_matrix3_scale (result, scalex, scaley);
gimp_matrix3_mult (matrix, result);
gimp_matrix3_mult (&matrix, result);
}

View file

@ -25,11 +25,11 @@ void gimp_drawable_transform_matrix_rotate (gint x1,
gint x2,
gint y2,
gdouble angle,
GimpMatrix3 result);
GimpMatrix3 *result);
void gimp_drawable_transform_matrix_rotate_center (gdouble cx,
gdouble cy,
gdouble angle,
GimpMatrix3 result);
GimpMatrix3 *result);
void gimp_drawable_transform_matrix_scale (gint x1,
gint y1,
gint x2,
@ -38,14 +38,14 @@ void gimp_drawable_transform_matrix_scale (gint x1,
gdouble ty1,
gdouble tx2,
gdouble ty2,
GimpMatrix3 result);
GimpMatrix3 *result);
void gimp_drawable_transform_matrix_shear (gint x1,
gint y1,
gint x2,
gint y2,
GimpOrientationType orientation,
gdouble amount,
GimpMatrix3 result);
GimpMatrix3 *result);
void gimp_drawable_transform_matrix_perspective (gint x1,
gint y1,
gint x2,
@ -58,7 +58,7 @@ void gimp_drawable_transform_matrix_perspective (gint x1,
gdouble ty3,
gdouble tx4,
gdouble ty5,
GimpMatrix3 result);
GimpMatrix3 *result);
#endif /* __GIMP_DRAWABLE_TRANSFORM_SHEAR_H__ */

View file

@ -100,7 +100,7 @@ sample_linear(PixelSurround *surround,
TileManager *
gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
TileManager *orig_tiles,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,
@ -110,8 +110,8 @@ gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
GimpImage *gimage;
PixelRegion destPR;
TileManager *new_tiles;
GimpMatrix3 m;
GimpMatrix3 im;
GimpMatrix3 m = *matrix;
GimpMatrix3 inv = *matrix;
PixelSurround surround;
gint x1, y1, x2, y2; /* target bounding box */
@ -191,14 +191,12 @@ gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
/* keep the original matrix here, so we dont need to recalculate
* the inverse later
*/
gimp_matrix3_duplicate (matrix, m);
gimp_matrix3_invert (matrix, im);
matrix = im;
gimp_matrix3_invert (&inv);
}
else
{
/* Find the inverse of the transformation matrix */
gimp_matrix3_invert (matrix, m);
gimp_matrix3_invert (&m);
}
tile_manager_get_offsets (orig_tiles, &u1, &v1);
@ -224,10 +222,10 @@ gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
gdouble dx3, dy3;
gdouble dx4, dy4;
gimp_matrix3_transform_point (matrix, u1, v1, &dx1, &dy1);
gimp_matrix3_transform_point (matrix, u2, v1, &dx2, &dy2);
gimp_matrix3_transform_point (matrix, u1, v2, &dx3, &dy3);
gimp_matrix3_transform_point (matrix, u2, v2, &dx4, &dy4);
gimp_matrix3_transform_point (&inv, u1, v1, &dx1, &dy1);
gimp_matrix3_transform_point (&inv, u2, v1, &dx2, &dy2);
gimp_matrix3_transform_point (&inv, u1, v2, &dx3, &dy3);
gimp_matrix3_transform_point (&inv, u2, v2, &dx4, &dy4);
x1 = ROUND (MIN4 (dx1, dx2, dx3, dx4));
y1 = ROUND (MIN4 (dy1, dy2, dy3, dy4));
@ -261,9 +259,9 @@ gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
dest = g_new (guchar, tile_manager_width (new_tiles) * bytes);
uinc = m[0][0];
vinc = m[1][0];
winc = m[2][0];
uinc = m.coeff[0][0];
vinc = m.coeff[1][0];
winc = m.coeff[2][0];
coords = (interpolation_type != GIMP_INTERPOLATION_NONE) ? 5 : 1;
@ -277,30 +275,30 @@ gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
(* progress_callback) (y1, y2, y, progress_data);
/* set up inverse transform steps */
tu[0] = uinc * (x1 + 0.5) + m[0][1] * (y + 0.5) + m[0][2] - 0.5;
tv[0] = vinc * (x1 + 0.5) + m[1][1] * (y + 0.5) + m[1][2] - 0.5;
tw[0] = winc * (x1 + 0.5) + m[2][1] * (y + 0.5) + m[2][2];
tu[0] = uinc * (x1 + 0.5) + m.coeff[0][1] * (y + 0.5) + m.coeff[0][2] - 0.5;
tv[0] = vinc * (x1 + 0.5) + m.coeff[1][1] * (y + 0.5) + m.coeff[1][2] - 0.5;
tw[0] = winc * (x1 + 0.5) + m.coeff[2][1] * (y + 0.5) + m.coeff[2][2];
if (interpolation_type != GIMP_INTERPOLATION_NONE)
{
gdouble xx = x1 + 0.5;
gdouble yy = y + 0.5;
tu[1] = uinc * (xx - 1) + m[0][1] * (yy ) + m[0][2] - 0.5;
tv[1] = vinc * (xx - 1) + m[1][1] * (yy ) + m[1][2] - 0.5;
tw[1] = winc * (xx - 1) + m[2][1] * (yy ) + m[2][2];
tu[1] = uinc * (xx - 1) + m.coeff[0][1] * (yy ) + m.coeff[0][2] - 0.5;
tv[1] = vinc * (xx - 1) + m.coeff[1][1] * (yy ) + m.coeff[1][2] - 0.5;
tw[1] = winc * (xx - 1) + m.coeff[2][1] * (yy ) + m.coeff[2][2];
tu[2] = uinc * (xx ) + m[0][1] * (yy - 1) + m[0][2] - 0.5;
tv[2] = vinc * (xx ) + m[1][1] * (yy - 1) + m[1][2] - 0.5;
tw[2] = winc * (xx ) + m[2][1] * (yy - 1) + m[2][2];
tu[2] = uinc * (xx ) + m.coeff[0][1] * (yy - 1) + m.coeff[0][2] - 0.5;
tv[2] = vinc * (xx ) + m.coeff[1][1] * (yy - 1) + m.coeff[1][2] - 0.5;
tw[2] = winc * (xx ) + m.coeff[2][1] * (yy - 1) + m.coeff[2][2];
tu[3] = uinc * (xx + 1) + m[0][1] * (yy ) + m[0][2] - 0.5;
tv[3] = vinc * (xx + 1) + m[1][1] * (yy ) + m[1][2] - 0.5;
tw[3] = winc * (xx + 1) + m[2][1] * (yy ) + m[2][2];
tu[3] = uinc * (xx + 1) + m.coeff[0][1] * (yy ) + m.coeff[0][2] - 0.5;
tv[3] = vinc * (xx + 1) + m.coeff[1][1] * (yy ) + m.coeff[1][2] - 0.5;
tw[3] = winc * (xx + 1) + m.coeff[2][1] * (yy ) + m.coeff[2][2];
tu[4] = uinc * (xx ) + m[0][1] * (yy + 1) + m[0][2] - 0.5;
tv[4] = vinc * (xx ) + m[1][1] * (yy + 1) + m[1][2] - 0.5;
tw[4] = winc * (xx ) + m[2][1] * (yy + 1) + m[2][2];
tu[4] = uinc * (xx ) + m.coeff[0][1] * (yy + 1) + m.coeff[0][2] - 0.5;
tv[4] = vinc * (xx ) + m.coeff[1][1] * (yy + 1) + m.coeff[1][2] - 0.5;
tw[4] = winc * (xx ) + m.coeff[2][1] * (yy + 1) + m.coeff[2][2];
}
d = dest;
@ -805,7 +803,7 @@ gimp_drawable_transform_tiles_rotate (GimpDrawable *drawable,
gboolean
gimp_drawable_transform_affine (GimpDrawable *drawable,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result)

View file

@ -35,7 +35,7 @@ typedef enum
TileManager * gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
TileManager *orig_tiles,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,
@ -54,7 +54,7 @@ TileManager * gimp_drawable_transform_tiles_rotate (GimpDrawable *drawable,
gdouble center_y,
gboolean clip_result);
gboolean gimp_drawable_transform_affine (GimpDrawable *drawable,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result);

View file

@ -98,7 +98,7 @@ static void gimp_drawable_rotate (GimpItem *item,
gdouble center_y,
gboolean clip_result);
static void gimp_drawable_transform (GimpItem *item,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,
@ -524,7 +524,7 @@ gimp_drawable_rotate (GimpItem *item,
static void
gimp_drawable_transform (GimpItem *item,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,

View file

@ -141,7 +141,7 @@ gimp_item_linked_rotate (GimpItem *item,
void
gimp_item_linked_transform (GimpItem *item,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,

View file

@ -34,7 +34,7 @@ void gimp_item_linked_rotate (GimpItem *item,
gdouble center_y,
gboolean clip_result);
void gimp_item_linked_transform (GimpItem *item,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,

View file

@ -687,7 +687,7 @@ gimp_item_rotate (GimpItem *item,
void
gimp_item_transform (GimpItem *item,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,

View file

@ -90,7 +90,7 @@ struct _GimpItemClass
gdouble center_y,
gboolean clip_result);
void (* transform) (GimpItem *item,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,
@ -166,7 +166,7 @@ void gimp_item_rotate (GimpItem *item,
gdouble center_y,
gboolean flip_result);
void gimp_item_transform (GimpItem *item,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,

View file

@ -101,7 +101,7 @@ static void gimp_layer_rotate (GimpItem *item,
gdouble center_y,
gboolean clip_result);
static void gimp_layer_transform (GimpItem *item,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,
@ -540,7 +540,7 @@ gimp_layer_rotate (GimpItem *item,
static void
gimp_layer_transform (GimpItem *item,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,

View file

@ -172,7 +172,7 @@ perspective_invoker (Gimp *gimp,
trans_info[Y2],
trans_info[X3],
trans_info[Y3],
matrix);
&matrix);
if (interpolation)
interpolation_type = gimp->config->interpolation_type;
@ -181,7 +181,7 @@ perspective_invoker (Gimp *gimp,
/* Perspective the selection */
success = gimp_drawable_transform_affine (drawable,
matrix, GIMP_TRANSFORM_FORWARD,
&matrix, GIMP_TRANSFORM_FORWARD,
interpolation_type, FALSE);
}
@ -301,7 +301,7 @@ rotate_invoker (Gimp *gimp,
/* Assemble the transformation matrix */
gimp_drawable_transform_matrix_rotate (x1, y1, x2, y2,
angle,
matrix);
&matrix);
if (interpolation)
interpolation_type = gimp->config->interpolation_type;
@ -310,7 +310,7 @@ rotate_invoker (Gimp *gimp,
/* Rotate the selection */
success = gimp_drawable_transform_affine (drawable,
matrix, GIMP_TRANSFORM_FORWARD,
&matrix, GIMP_TRANSFORM_FORWARD,
interpolation_type, FALSE);
}
@ -406,7 +406,7 @@ scale_invoker (Gimp *gimp,
trans_info[Y0],
trans_info[X1],
trans_info[Y1],
matrix);
&matrix);
if (interpolation)
interpolation_type = gimp->config->interpolation_type;
@ -415,7 +415,7 @@ scale_invoker (Gimp *gimp,
/* Scale the selection */
success = gimp_drawable_transform_affine (drawable,
matrix, GIMP_TRANSFORM_FORWARD,
&matrix, GIMP_TRANSFORM_FORWARD,
interpolation_type, FALSE);
}
else
@ -525,7 +525,7 @@ shear_invoker (Gimp *gimp,
gimp_drawable_transform_matrix_shear (x1, y1, x2, y2,
shear_type,
magnitude,
matrix);
&matrix);
if (interpolation)
interpolation_type = gimp->config->interpolation_type;
@ -534,7 +534,7 @@ shear_invoker (Gimp *gimp,
/* Shear the selection */
success = gimp_drawable_transform_affine (drawable,
matrix, GIMP_TRANSFORM_FORWARD,
&matrix, GIMP_TRANSFORM_FORWARD,
interpolation_type, FALSE);
}
@ -636,11 +636,11 @@ transform_2d_invoker (Gimp *gimp,
if (success)
{
/* Assemble the transformation matrix */
gimp_matrix3_identity (matrix);
gimp_matrix3_translate (matrix, -source_x, -source_y);
gimp_matrix3_scale (matrix, scale_x, scale_y);
gimp_matrix3_rotate (matrix, angle);
gimp_matrix3_translate (matrix, dest_x, dest_y);
gimp_matrix3_identity (&matrix);
gimp_matrix3_translate (&matrix, -source_x, -source_y);
gimp_matrix3_scale (&matrix, scale_x, scale_y);
gimp_matrix3_rotate (&matrix, angle);
gimp_matrix3_translate (&matrix, dest_x, dest_y);
if (interpolation)
interpolation_type = gimp->config->interpolation_type;
@ -649,7 +649,7 @@ transform_2d_invoker (Gimp *gimp,
/* Transform the selection */
success = gimp_drawable_transform_affine (drawable,
matrix, GIMP_TRANSFORM_FORWARD,
&matrix, GIMP_TRANSFORM_FORWARD,
interpolation_type, FALSE);
}

View file

@ -230,7 +230,7 @@ gimp_perspective_tool_recalc (GimpTransformTool *tr_tool,
tr_tool->trans_info[Y2],
tr_tool->trans_info[X3],
tr_tool->trans_info[Y3],
tr_tool->transform);
&tr_tool->transform);
/* transform the bounding box */
gimp_transform_tool_transform_bounding_box (tr_tool);
@ -252,7 +252,7 @@ perspective_info_update (GimpTransformTool *tr_tool)
for (j = 0; j < 3; j++)
{
p += g_snprintf (p, MAX_INFO_BUF - (p - matrix_row_buf[i]),
"%10.3g", tr_tool->transform[i][j]);
"%10.3g", tr_tool->transform.coeff[i][j]);
}
}

View file

@ -344,7 +344,7 @@ gimp_rotate_tool_recalc (GimpTransformTool *tr_tool,
gimp_drawable_transform_matrix_rotate_center (tr_tool->cx,
tr_tool->cy,
tr_tool->trans_info[ANGLE],
tr_tool->transform);
&tr_tool->transform);
/* transform the bounding box */
gimp_transform_tool_transform_bounding_box (tr_tool);

View file

@ -398,7 +398,7 @@ gimp_scale_tool_recalc (GimpTransformTool *tr_tool,
tr_tool->trans_info[Y0],
tr_tool->trans_info[X1],
tr_tool->trans_info[Y1],
tr_tool->transform);
&tr_tool->transform);
/* transform the bounding box */
gimp_transform_tool_transform_bounding_box (tr_tool);

View file

@ -286,7 +286,7 @@ gimp_shear_tool_recalc (GimpTransformTool *tr_tool,
tr_tool->y2,
tr_tool->trans_info[HORZ_OR_VERT],
amount,
tr_tool->transform);
&tr_tool->transform);
/* transform the bounding box */
gimp_transform_tool_transform_bounding_box (tr_tool);

View file

@ -224,7 +224,7 @@ gimp_transform_tool_init (GimpTransformTool *tr_tool)
tr_tool->old_trans_info[i] = 0.0;
}
gimp_matrix3_identity (tr_tool->transform);
gimp_matrix3_identity (&tr_tool->transform);
tr_tool->use_grid = TRUE;
tr_tool->use_center = TRUE;
@ -728,24 +728,24 @@ gimp_transform_tool_draw (GimpDrawTool *draw_tool)
FALSE);
}
#if 0
if (tr_tool->type == GIMP_TRANSFORM_TYPE_PATH)
{
GimpMatrix3 tmp_matrix;
if (options->direction == GIMP_TRANSFORM_BACKWARD)
{
gimp_matrix3_invert (tr_tool->transform, tmp_matrix);
GimpMatrix3 inv_matrix = tr_tool->transform;
gimp_matrix3_invert (&inv_matrix);
path_transform_draw_current (tool->gdisp,
draw_tool, inv_matrix);
}
else
{
gimp_matrix3_duplicate (tr_tool->transform, tmp_matrix);
}
#if 0
path_transform_draw_current (tool->gdisp,
draw_tool, tmp_matrix);
#endif
draw_tool, tr_tool->transform);
}
}
#endif
}
static TileManager *
@ -768,7 +768,7 @@ gimp_transform_tool_real_transform (GimpTransformTool *tr_tool,
NULL, NULL);
if (gimp_item_get_linked (active_item))
gimp_item_linked_transform (active_item, tr_tool->transform,
gimp_item_linked_transform (active_item, &tr_tool->transform,
options->direction,
options->interpolation, options->clip,
progress ?
@ -792,7 +792,7 @@ gimp_transform_tool_real_transform (GimpTransformTool *tr_tool,
ret =
gimp_drawable_transform_tiles_affine (GIMP_DRAWABLE (active_item),
tr_tool->original,
tr_tool->transform,
&tr_tool->transform,
options->direction,
options->interpolation,
clip_result,
@ -952,20 +952,20 @@ gimp_transform_tool_transform_bounding_box (GimpTransformTool *tr_tool)
{
g_return_if_fail (GIMP_IS_TRANSFORM_TOOL (tr_tool));
gimp_matrix3_transform_point (tr_tool->transform,
gimp_matrix3_transform_point (&tr_tool->transform,
tr_tool->x1, tr_tool->y1,
&tr_tool->tx1, &tr_tool->ty1);
gimp_matrix3_transform_point (tr_tool->transform,
gimp_matrix3_transform_point (&tr_tool->transform,
tr_tool->x2, tr_tool->y1,
&tr_tool->tx2, &tr_tool->ty2);
gimp_matrix3_transform_point (tr_tool->transform,
gimp_matrix3_transform_point (&tr_tool->transform,
tr_tool->x1, tr_tool->y2,
&tr_tool->tx3, &tr_tool->ty3);
gimp_matrix3_transform_point (tr_tool->transform,
gimp_matrix3_transform_point (&tr_tool->transform,
tr_tool->x2, tr_tool->y2,
&tr_tool->tx4, &tr_tool->ty4);
gimp_matrix3_transform_point (tr_tool->transform,
gimp_matrix3_transform_point (&tr_tool->transform,
tr_tool->cx, tr_tool->cy,
&tr_tool->tcx, &tr_tool->tcy);
@ -979,7 +979,7 @@ gimp_transform_tool_transform_bounding_box (GimpTransformTool *tr_tool)
for (i = 0; i < k; i++)
{
gimp_matrix3_transform_point (tr_tool->transform,
gimp_matrix3_transform_point (&tr_tool->transform,
tr_tool->grid_coords[gci],
tr_tool->grid_coords[gci + 1],
&tr_tool->tgrid_coords[gci],

View file

@ -81,7 +81,7 @@ static void gimp_vectors_rotate (GimpItem *item,
gdouble center_y,
gboolean clip_result);
static void gimp_vectors_transform (GimpItem *item,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interp_type,
gboolean clip_result,
@ -463,7 +463,7 @@ gimp_vectors_rotate (GimpItem *item,
}
gimp_drawable_transform_matrix_rotate_center (center_x, center_y, angle,
matrix);
&matrix);
vectors = GIMP_VECTORS (item);
@ -482,7 +482,7 @@ gimp_vectors_rotate (GimpItem *item,
{
GimpAnchor *anchor = list2->data;
gimp_matrix3_transform_point (matrix,
gimp_matrix3_transform_point (&matrix,
anchor->position.x,
anchor->position.y,
&anchor->position.x,
@ -495,7 +495,7 @@ gimp_vectors_rotate (GimpItem *item,
static void
gimp_vectors_transform (GimpItem *item,
GimpMatrix3 matrix,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,

View file

@ -1,3 +1,8 @@
2003-07-07 Sven Neumann <sven@gimp.org>
* libgimpmath/libgimpmath-sections.txt
* libgimpmath/tmpl/gimpmatrix.sgml: updated.
2003-07-02 Michael Natterer <mitch@gimp.org>
* libgimpbase/tmpl/gimpbasetypes.sgml

View file

@ -19,8 +19,8 @@ gimp_md5_get_digest
<SECTION>
<FILE>gimpmatrix</FILE>
<TITLE>GimpMatrix</TITLE>
GimpMatrix3[3][3]
GimpMatrix4[4][4]
GimpMatrix3
GimpMatrix4
gimp_matrix3_transform_point
gimp_matrix3_mult
gimp_matrix3_identity
@ -31,7 +31,6 @@ gimp_matrix3_xshear
gimp_matrix3_yshear
gimp_matrix3_determinant
gimp_matrix3_invert
gimp_matrix3_duplicate
gimp_matrix3_is_diagonal
gimp_matrix3_is_identity
gimp_matrix3_is_simple

View file

@ -24,17 +24,19 @@ basic matrix manipulations and tests.
#GimpVector4
</para>
<!-- ##### TYPEDEF GimpMatrix3[3][3] ##### -->
<!-- ##### STRUCT GimpMatrix3 ##### -->
<para>
</para>
@coeff:
<!-- ##### TYPEDEF GimpMatrix4[4][4] ##### -->
<!-- ##### STRUCT GimpMatrix4 ##### -->
<para>
</para>
@coeff:
<!-- ##### FUNCTION gimp_matrix3_transform_point ##### -->
<para>
@ -127,16 +129,6 @@ basic matrix manipulations and tests.
</para>
@matrix:
@matrix_inv:
<!-- ##### FUNCTION gimp_matrix3_duplicate ##### -->
<para>
</para>
@src:
@target:
<!-- ##### FUNCTION gimp_matrix3_is_diagonal ##### -->

View file

@ -24,30 +24,13 @@
G_BEGIN_DECLS
typedef gdouble GimpMatrix3[3][3];
typedef gdouble GimpMatrix4[4][4];
typedef struct _GimpMatrix3 GimpMatrix3;
typedef struct _GimpMatrix4 GimpMatrix4;
typedef struct _GimpVector2 GimpVector2;
typedef struct _GimpVector3 GimpVector3;
typedef struct _GimpVector4 GimpVector4;
struct _GimpVector2
{
gdouble x, y;
};
struct _GimpVector3
{
gdouble x, y, z;
};
struct _GimpVector4
{
gdouble x, y, z, w;
};
G_END_DECLS
#endif /* __GIMP_MATH_TYPES_H__ */

View file

@ -22,8 +22,6 @@
#include "config.h"
#include <string.h> /* memcmp */
#include <glib.h>
#include "gimpmath.h"
@ -43,7 +41,7 @@
* Transforms a point in 2D as specified by the transformation matrix.
*/
void
gimp_matrix3_transform_point (GimpMatrix3 matrix,
gimp_matrix3_transform_point (const GimpMatrix3 *matrix,
gdouble x,
gdouble y,
gdouble *newx,
@ -51,27 +49,31 @@ gimp_matrix3_transform_point (GimpMatrix3 matrix,
{
gdouble w;
w = matrix[2][0]*x + matrix[2][1]*y + matrix[2][2];
w = matrix->coeff[2][0] * x + matrix->coeff[2][1] * y + matrix->coeff[2][2];
if (w == 0.0)
w = 1.0;
else
w = 1.0/w;
*newx = (matrix[0][0]*x + matrix[0][1]*y + matrix[0][2])*w;
*newy = (matrix[1][0]*x + matrix[1][1]*y + matrix[1][2])*w;
*newx = (matrix->coeff[0][0] * x +
matrix->coeff[0][1] * y +
matrix->coeff[0][2]) * w;
*newy = (matrix->coeff[1][0] * x +
matrix->coeff[1][1] * y +
matrix->coeff[1][2]) * w;
}
/**
* gimp_matrix3_mult:
* @matrix1: The first input matrix.
* @matrix2: The second input matrix which will be oeverwritten ba the result.
* @matrix2: The second input matrix which will be oeverwritten by the result.
*
* Multiplies two matrices and puts the result into the second one.
*/
void
gimp_matrix3_mult (GimpMatrix3 matrix1,
GimpMatrix3 matrix2)
gimp_matrix3_mult (const GimpMatrix3 *matrix1,
GimpMatrix3 *matrix2)
{
gint i, j;
GimpMatrix3 tmp;
@ -79,19 +81,19 @@ gimp_matrix3_mult (GimpMatrix3 matrix1,
for (i = 0; i < 3; i++)
{
t1 = matrix1[i][0];
t2 = matrix1[i][1];
t3 = matrix1[i][2];
t1 = matrix1->coeff[i][0];
t2 = matrix1->coeff[i][1];
t3 = matrix1->coeff[i][2];
for (j = 0; j < 3; j++)
{
tmp[i][j] = t1 * matrix2[0][j];
tmp[i][j] += t2 * matrix2[1][j];
tmp[i][j] += t3 * matrix2[2][j];
tmp.coeff[i][j] = t1 * matrix2->coeff[0][j];
tmp.coeff[i][j] += t2 * matrix2->coeff[1][j];
tmp.coeff[i][j] += t3 * matrix2->coeff[2][j];
}
}
/* put the results in matrix2 */
memcpy (&matrix2[0][0], &tmp[0][0], sizeof (GimpMatrix3));
*matrix2 = tmp;
}
/**
@ -101,13 +103,13 @@ gimp_matrix3_mult (GimpMatrix3 matrix1,
* Sets the matrix to the identity matrix.
*/
void
gimp_matrix3_identity (GimpMatrix3 matrix)
gimp_matrix3_identity (GimpMatrix3 *matrix)
{
static GimpMatrix3 identity = { { 1.0, 0.0, 0.0 },
static GimpMatrix3 identity = { { { 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 } };
{ 0.0, 0.0, 1.0 } } };
memcpy (&matrix[0][0], &identity[0][0], sizeof (GimpMatrix3));
*matrix = identity;
}
/**
@ -119,22 +121,22 @@ gimp_matrix3_identity (GimpMatrix3 matrix)
* Translates the matrix by x and y.
*/
void
gimp_matrix3_translate (GimpMatrix3 matrix,
gimp_matrix3_translate (GimpMatrix3 *matrix,
gdouble x,
gdouble y)
{
gdouble g, h, i;
g = matrix[2][0];
h = matrix[2][1];
i = matrix[2][2];
g = matrix->coeff[2][0];
h = matrix->coeff[2][1];
i = matrix->coeff[2][2];
matrix[0][0] += x * g;
matrix[0][1] += x * h;
matrix[0][2] += x * i;
matrix[1][0] += y * g;
matrix[1][1] += y * h;
matrix[1][2] += y * i;
matrix->coeff[0][0] += x * g;
matrix->coeff[0][1] += x * h;
matrix->coeff[0][2] += x * i;
matrix->coeff[1][0] += y * g;
matrix->coeff[1][1] += y * h;
matrix->coeff[1][2] += y * i;
}
/**
@ -146,17 +148,17 @@ gimp_matrix3_translate (GimpMatrix3 matrix,
* Scales the matrix by x and y
*/
void
gimp_matrix3_scale (GimpMatrix3 matrix,
gimp_matrix3_scale (GimpMatrix3 *matrix,
gdouble x,
gdouble y)
{
matrix[0][0] *= x;
matrix[0][1] *= x;
matrix[0][2] *= x;
matrix->coeff[0][0] *= x;
matrix->coeff[0][1] *= x;
matrix->coeff[0][2] *= x;
matrix[1][0] *= y;
matrix[1][1] *= y;
matrix[1][2] *= y;
matrix->coeff[1][0] *= y;
matrix->coeff[1][1] *= y;
matrix->coeff[1][2] *= y;
}
/**
@ -167,7 +169,7 @@ gimp_matrix3_scale (GimpMatrix3 matrix,
* Rotates the matrix by theta degrees.
*/
void
gimp_matrix3_rotate (GimpMatrix3 matrix,
gimp_matrix3_rotate (GimpMatrix3 *matrix,
gdouble theta)
{
gdouble t1, t2;
@ -176,20 +178,20 @@ gimp_matrix3_rotate (GimpMatrix3 matrix,
cost = cos (theta);
sint = sin (theta);
t1 = matrix[0][0];
t2 = matrix[1][0];
matrix[0][0] = cost * t1 - sint * t2;
matrix[1][0] = sint * t1 + cost * t2;
t1 = matrix->coeff[0][0];
t2 = matrix->coeff[1][0];
matrix->coeff[0][0] = cost * t1 - sint * t2;
matrix->coeff[1][0] = sint * t1 + cost * t2;
t1 = matrix[0][1];
t2 = matrix[1][1];
matrix[0][1] = cost * t1 - sint * t2;
matrix[1][1] = sint*t1 + cost*t2;
t1 = matrix->coeff[0][1];
t2 = matrix->coeff[1][1];
matrix->coeff[0][1] = cost * t1 - sint * t2;
matrix->coeff[1][1] = sint * t1 + cost * t2;
t1 = matrix[0][2];
t2 = matrix[1][2];
matrix[0][2] = cost*t1 - sint*t2;
matrix[1][2] = sint*t1 + cost*t2;
t1 = matrix->coeff[0][2];
t2 = matrix->coeff[1][2];
matrix->coeff[0][2] = cost * t1 - sint * t2;
matrix->coeff[1][2] = sint * t1 + cost * t2;
}
/**
@ -200,12 +202,12 @@ gimp_matrix3_rotate (GimpMatrix3 matrix,
* Shears the matrix in the X direction.
*/
void
gimp_matrix3_xshear (GimpMatrix3 matrix,
gimp_matrix3_xshear (GimpMatrix3 *matrix,
gdouble amount)
{
matrix[0][0] += amount * matrix[1][0];
matrix[0][1] += amount * matrix[1][1];
matrix[0][2] += amount * matrix[1][2];
matrix->coeff[0][0] += amount * matrix->coeff[1][0];
matrix->coeff[0][1] += amount * matrix->coeff[1][1];
matrix->coeff[0][2] += amount * matrix->coeff[1][2];
}
/**
@ -216,12 +218,12 @@ gimp_matrix3_xshear (GimpMatrix3 matrix,
* Shears the matrix in the Y direction.
*/
void
gimp_matrix3_yshear (GimpMatrix3 matrix,
gimp_matrix3_yshear (GimpMatrix3 *matrix,
gdouble amount)
{
matrix[1][0] += amount * matrix[0][0];
matrix[1][1] += amount * matrix[0][1];
matrix[1][2] += amount * matrix[0][2];
matrix->coeff[1][0] += amount * matrix->coeff[0][0];
matrix->coeff[1][1] += amount * matrix->coeff[0][1];
matrix->coeff[1][2] += amount * matrix->coeff[0][2];
}
/**
@ -233,16 +235,19 @@ gimp_matrix3_yshear (GimpMatrix3 matrix,
* Returns: The determinant.
*/
gdouble
gimp_matrix3_determinant (GimpMatrix3 matrix)
gimp_matrix3_determinant (const GimpMatrix3 *matrix)
{
gdouble determinant;
determinant =
matrix[0][0] * (matrix[1][1]*matrix[2][2] - matrix[1][2]*matrix[2][1]);
determinant -=
matrix[1][0] * (matrix[0][1]*matrix[2][2] - matrix[0][2]*matrix[2][1]);
determinant +=
matrix[2][0] * (matrix[0][1]*matrix[1][2] - matrix[0][2]*matrix[1][1]);
determinant = (matrix->coeff[0][0] *
(matrix->coeff[1][1] * matrix->coeff[2][2] -
matrix->coeff[1][2] * matrix->coeff[2][1]));
determinant -= (matrix->coeff[1][0] *
(matrix->coeff[0][1] * matrix->coeff[2][2] -
matrix->coeff[0][2] * matrix->coeff[2][1]));
determinant += (matrix->coeff[2][0] *
(matrix->coeff[0][1] * matrix->coeff[1][2] -
matrix->coeff[0][2] * matrix->coeff[1][1]));
return determinant;
}
@ -250,64 +255,50 @@ gimp_matrix3_determinant (GimpMatrix3 matrix)
/**
* gimp_matrix3_invert:
* @matrix: The matrix that is to be inverted.
* @matrix_inv: A matrix the inverted matrix should be written into.
*
* Inverts the given matrix.
*/
void
gimp_matrix3_invert (GimpMatrix3 matrix,
GimpMatrix3 matrix_inv)
gimp_matrix3_invert (GimpMatrix3 *matrix)
{
gdouble det_1;
GimpMatrix3 inv;
gdouble det;
det_1 = gimp_matrix3_determinant (matrix);
det = gimp_matrix3_determinant (matrix);
if (det_1 == 0.0)
if (det == 0.0)
return;
det_1 = 1.0 / det_1;
det = 1.0 / det;
matrix_inv[0][0] =
(matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1]) * det_1;
inv.coeff[0][0] = (matrix->coeff[1][1] * matrix->coeff[2][2] -
matrix->coeff[1][2] * matrix->coeff[2][1]) * det;
matrix_inv[1][0] =
- (matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0]) * det_1;
inv.coeff[1][0] = - (matrix->coeff[1][0] * matrix->coeff[2][2] -
matrix->coeff[1][2] * matrix->coeff[2][0]) * det;
matrix_inv[2][0] =
(matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0]) * det_1;
inv.coeff[2][0] = (matrix->coeff[1][0] * matrix->coeff[2][1] -
matrix->coeff[1][1] * matrix->coeff[2][0]) * det;
matrix_inv[0][1] =
- (matrix[0][1] * matrix[2][2] - matrix[0][2] * matrix[2][1] ) * det_1;
inv.coeff[0][1] = - (matrix->coeff[0][1] * matrix->coeff[2][2] -
matrix->coeff[0][2] * matrix->coeff[2][1]) * det;
matrix_inv[1][1] =
(matrix[0][0] * matrix[2][2] - matrix[0][2] * matrix[2][0]) * det_1;
inv.coeff[1][1] = (matrix->coeff[0][0] * matrix->coeff[2][2] -
matrix->coeff[0][2] * matrix->coeff[2][0]) * det;
matrix_inv[2][1] =
- (matrix[0][0] * matrix[2][1] - matrix[0][1] * matrix[2][0]) * det_1;
inv.coeff[2][1] = - (matrix->coeff[0][0] * matrix->coeff[2][1] -
matrix->coeff[0][1] * matrix->coeff[2][0]) * det;
matrix_inv[0][2] =
(matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1]) * det_1;
inv.coeff[0][2] = (matrix->coeff[0][1] * matrix->coeff[1][2] -
matrix->coeff[0][2] * matrix->coeff[1][1]) * det;
matrix_inv[1][2] =
- (matrix[0][0] * matrix[1][2] - matrix[0][2] * matrix[1][0]) * det_1;
inv.coeff[1][2] = - (matrix->coeff[0][0] * matrix->coeff[1][2] -
matrix->coeff[0][2] * matrix->coeff[1][0]) * det;
matrix_inv[2][2] =
(matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]) * det_1;
}
inv.coeff[2][2] = (matrix->coeff[0][0] * matrix->coeff[1][1] -
matrix->coeff[0][1] * matrix->coeff[1][0]) * det;
/**
* gimp_matrix3_duplicate:
* @src: The source matrix.
* @target: The destination matrix.
*
* Copies the source matrix to the destination matrix.
*/
void
gimp_matrix3_duplicate (GimpMatrix3 src,
GimpMatrix3 target)
{
memcpy (&target[0][0], &src[0][0], sizeof (GimpMatrix3));
*matrix = inv;
}
@ -323,7 +314,7 @@ gimp_matrix3_duplicate (GimpMatrix3 src,
* Returns: TRUE if the matrix is diagonal.
*/
gboolean
gimp_matrix3_is_diagonal (GimpMatrix3 matrix)
gimp_matrix3_is_diagonal (const GimpMatrix3 *matrix)
{
gint i, j;
@ -331,7 +322,7 @@ gimp_matrix3_is_diagonal (GimpMatrix3 matrix)
{
for (j = 0; j < 3; j++)
{
if (i != j && fabs (matrix[i][j]) > EPSILON)
if (i != j && fabs (matrix->coeff[i][j]) > EPSILON)
return FALSE;
}
}
@ -348,9 +339,9 @@ gimp_matrix3_is_diagonal (GimpMatrix3 matrix)
* Returns: TRUE if the matrix is the identity matrix.
*/
gboolean
gimp_matrix3_is_identity (GimpMatrix3 matrix)
gimp_matrix3_is_identity (const GimpMatrix3 *matrix)
{
gint i,j;
gint i, j;
for (i = 0; i < 3; i++)
{
@ -358,12 +349,12 @@ gimp_matrix3_is_identity (GimpMatrix3 matrix)
{
if (i == j)
{
if (fabs (matrix[i][j] - 1.0) > EPSILON)
if (fabs (matrix->coeff[i][j] - 1.0) > EPSILON)
return FALSE;
}
else
{
if (fabs (matrix[i][j]) > EPSILON)
if (fabs (matrix->coeff[i][j]) > EPSILON)
return FALSE;
}
}
@ -389,7 +380,7 @@ gimp_matrix3_is_identity (GimpMatrix3 matrix)
* 0 or 1
*/
gboolean
gimp_matrix3_is_simple (GimpMatrix3 matrix)
gimp_matrix3_is_simple (const GimpMatrix3 *matrix)
{
gdouble absm;
gint i, j;
@ -398,7 +389,7 @@ gimp_matrix3_is_simple (GimpMatrix3 matrix)
{
for (j = 0; j < 2; j++)
{
absm = fabs (matrix[i][j]);
absm = fabs (matrix->coeff[i][j]);
if (absm > EPSILON && fabs (absm - 1.0) > EPSILON)
return FALSE;
}
@ -408,12 +399,12 @@ gimp_matrix3_is_simple (GimpMatrix3 matrix)
}
void
gimp_matrix4_to_deg (GimpMatrix4 matrix,
gimp_matrix4_to_deg (const GimpMatrix4 *matrix,
gdouble *a,
gdouble *b,
gdouble *c)
{
*a = 180 * (asin (matrix[1][0]) / G_PI_2);
*b = 180 * (asin (matrix[2][0]) / G_PI_2);
*c = 180 * (asin (matrix[2][1]) / G_PI_2);
*a = 180 * (asin (matrix->coeff[1][0]) / G_PI_2);
*b = 180 * (asin (matrix->coeff[2][0]) / G_PI_2);
*c = 180 * (asin (matrix->coeff[2][1]) / G_PI_2);
}

View file

@ -27,39 +27,46 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
struct _GimpMatrix3
{
gdouble coeff[3][3];
};
void gimp_matrix3_transform_point (GimpMatrix3 matrix,
struct _GimpMatrix4
{
gdouble coeff[4][4];
};
void gimp_matrix3_transform_point (const GimpMatrix3 *matrix,
gdouble x,
gdouble y,
gdouble *newx,
gdouble *newy);
void gimp_matrix3_mult (GimpMatrix3 matrix1,
GimpMatrix3 matrix2);
void gimp_matrix3_identity (GimpMatrix3 matrix);
void gimp_matrix3_translate (GimpMatrix3 matrix,
void gimp_matrix3_mult (const GimpMatrix3 *matrix1,
GimpMatrix3 *matrix2);
void gimp_matrix3_identity (GimpMatrix3 *matrix);
void gimp_matrix3_translate (GimpMatrix3 *matrix,
gdouble x,
gdouble y);
void gimp_matrix3_scale (GimpMatrix3 matrix,
void gimp_matrix3_scale (GimpMatrix3 *matrix,
gdouble x,
gdouble y);
void gimp_matrix3_rotate (GimpMatrix3 matrix,
void gimp_matrix3_rotate (GimpMatrix3 *matrix,
gdouble theta);
void gimp_matrix3_xshear (GimpMatrix3 matrix,
void gimp_matrix3_xshear (GimpMatrix3 *matrix,
gdouble amount);
void gimp_matrix3_yshear (GimpMatrix3 matrix,
void gimp_matrix3_yshear (GimpMatrix3 *matrix,
gdouble amount);
gdouble gimp_matrix3_determinant (GimpMatrix3 matrix);
void gimp_matrix3_invert (GimpMatrix3 matrix,
GimpMatrix3 matrix_inv);
void gimp_matrix3_duplicate (GimpMatrix3 src,
GimpMatrix3 target);
gdouble gimp_matrix3_determinant (const GimpMatrix3 *matrix);
void gimp_matrix3_invert (GimpMatrix3 *matrix);
gboolean gimp_matrix3_is_diagonal (GimpMatrix3 matrix);
gboolean gimp_matrix3_is_identity (GimpMatrix3 matrix);
gboolean gimp_matrix3_is_simple (GimpMatrix3 matrix);
gboolean gimp_matrix3_is_diagonal (const GimpMatrix3 *matrix);
gboolean gimp_matrix3_is_identity (const GimpMatrix3 *matrix);
gboolean gimp_matrix3_is_simple (const GimpMatrix3 *matrix);
void gimp_matrix4_to_deg (GimpMatrix4 matrix,
void gimp_matrix4_to_deg (const GimpMatrix4 *matrix,
gdouble *a,
gdouble *b,
gdouble *c);

View file

@ -30,6 +30,21 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
struct _GimpVector2
{
gdouble x, y;
};
struct _GimpVector3
{
gdouble x, y, z;
};
struct _GimpVector4
{
gdouble x, y, z, w;
};
/* Two dimensional vector functions */
/* ================================ */

View file

@ -137,7 +137,7 @@ HELP
trans_info[Y2],
trans_info[X3],
trans_info[Y3],
matrix);
&matrix);
if (interpolation)
interpolation_type = gimp->config->interpolation_type;
@ -146,7 +146,7 @@ HELP
/* Perspective the selection */
success = gimp_drawable_transform_affine (drawable,
matrix, GIMP_TRANSFORM_FORWARD,
&matrix, GIMP_TRANSFORM_FORWARD,
interpolation_type, FALSE);
}
CODE
@ -191,7 +191,7 @@ HELP
/* Assemble the transformation matrix */
gimp_drawable_transform_matrix_rotate (x1, y1, x2, y2,
angle,
matrix);
&matrix);
if (interpolation)
interpolation_type = gimp->config->interpolation_type;
@ -200,7 +200,7 @@ HELP
/* Rotate the selection */
success = gimp_drawable_transform_affine (drawable,
matrix, GIMP_TRANSFORM_FORWARD,
&matrix, GIMP_TRANSFORM_FORWARD,
interpolation_type, FALSE);
}
CODE
@ -260,7 +260,7 @@ HELP
trans_info[Y0],
trans_info[X1],
trans_info[Y1],
matrix);
&matrix);
if (interpolation)
interpolation_type = gimp->config->interpolation_type;
@ -269,7 +269,7 @@ HELP
/* Scale the selection */
success = gimp_drawable_transform_affine (drawable,
matrix, GIMP_TRANSFORM_FORWARD,
&matrix, GIMP_TRANSFORM_FORWARD,
interpolation_type, FALSE);
}
else
@ -325,7 +325,7 @@ HELP
gimp_drawable_transform_matrix_shear (x1, y1, x2, y2,
shear_type,
magnitude,
matrix);
&matrix);
if (interpolation)
interpolation_type = gimp->config->interpolation_type;
@ -334,7 +334,7 @@ HELP
/* Shear the selection */
success = gimp_drawable_transform_affine (drawable,
matrix, GIMP_TRANSFORM_FORWARD,
&matrix, GIMP_TRANSFORM_FORWARD,
interpolation_type, FALSE);
}
CODE
@ -390,11 +390,11 @@ HELP
code => <<'CODE'
{
/* Assemble the transformation matrix */
gimp_matrix3_identity (matrix);
gimp_matrix3_translate (matrix, -source_x, -source_y);
gimp_matrix3_scale (matrix, scale_x, scale_y);
gimp_matrix3_rotate (matrix, angle);
gimp_matrix3_translate (matrix, dest_x, dest_y);
gimp_matrix3_identity (&matrix);
gimp_matrix3_translate (&matrix, -source_x, -source_y);
gimp_matrix3_scale (&matrix, scale_x, scale_y);
gimp_matrix3_rotate (&matrix, angle);
gimp_matrix3_translate (&matrix, dest_x, dest_y);
if (interpolation)
interpolation_type = gimp->config->interpolation_type;
@ -403,7 +403,7 @@ HELP
/* Transform the selection */
success = gimp_drawable_transform_affine (drawable,
matrix, GIMP_TRANSFORM_FORWARD,
&matrix, GIMP_TRANSFORM_FORWARD,
interpolation_type, FALSE);
}
CODE