documented gimpmatrix
--Sven
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
Sun Feb 6 23:45:09 CET 2000 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
|
* libgimp/gimpmatrix.[ch]: use g* types and name the parameters
|
||||||
|
in the header.
|
||||||
|
|
||||||
Sun Feb 6 22:18:24 CET 2000 Sven Neumann <sven@gimp.org>
|
Sun Feb 6 22:18:24 CET 2000 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* libgimp/gimpexport.[ch]: use an enum instead of defines
|
* libgimp/gimpexport.[ch]: use an enum instead of defines
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
Sun Feb 6 23:44:17 CET 2000 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
|
* devel-docs/libgimp/libgimp-decl.txt
|
||||||
|
* devel-docs/libgimp/tmpl/gimpmatrix.sgml: documented gimpmatrix
|
||||||
|
|
||||||
|
* devel-docs/libgimp/tmpl/gimpcolorspace.sgml
|
||||||
|
* devel-docs/libgimp/tmpl/gimpmenu.sgml: cleanup
|
||||||
|
|
||||||
Sun Feb 6 22:15:20 CET 2000 Sven Neumann <sven@gimp.org>
|
Sun Feb 6 22:15:20 CET 2000 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* libgimp/.cvsignore
|
* libgimp/.cvsignore
|
||||||
|
@ -2549,72 +2549,72 @@ typedef double GimpMatrix[3][3];
|
|||||||
<FUNCTION>
|
<FUNCTION>
|
||||||
<NAME>gimp_matrix_transform_point</NAME>
|
<NAME>gimp_matrix_transform_point</NAME>
|
||||||
<RETURNS>void </RETURNS>
|
<RETURNS>void </RETURNS>
|
||||||
GimpMatrix, double, double,double *, double *
|
GimpMatrix matrix,gdouble x,gdouble y,gdouble *newx,gdouble *newy
|
||||||
</FUNCTION>
|
</FUNCTION>
|
||||||
<FUNCTION>
|
<FUNCTION>
|
||||||
<NAME>gimp_matrix_mult</NAME>
|
<NAME>gimp_matrix_mult</NAME>
|
||||||
<RETURNS>void </RETURNS>
|
<RETURNS>void </RETURNS>
|
||||||
GimpMatrix, GimpMatrix
|
GimpMatrix matrix1,GimpMatrix matrix2
|
||||||
</FUNCTION>
|
</FUNCTION>
|
||||||
<FUNCTION>
|
<FUNCTION>
|
||||||
<NAME>gimp_matrix_identity</NAME>
|
<NAME>gimp_matrix_identity</NAME>
|
||||||
<RETURNS>void </RETURNS>
|
<RETURNS>void </RETURNS>
|
||||||
GimpMatrix
|
GimpMatrix matrix
|
||||||
</FUNCTION>
|
</FUNCTION>
|
||||||
<FUNCTION>
|
<FUNCTION>
|
||||||
<NAME>gimp_matrix_translate</NAME>
|
<NAME>gimp_matrix_translate</NAME>
|
||||||
<RETURNS>void </RETURNS>
|
<RETURNS>void </RETURNS>
|
||||||
GimpMatrix, double, double
|
GimpMatrix matrix,gdouble x,gdouble y
|
||||||
</FUNCTION>
|
</FUNCTION>
|
||||||
<FUNCTION>
|
<FUNCTION>
|
||||||
<NAME>gimp_matrix_scale</NAME>
|
<NAME>gimp_matrix_scale</NAME>
|
||||||
<RETURNS>void </RETURNS>
|
<RETURNS>void </RETURNS>
|
||||||
GimpMatrix, double, double
|
GimpMatrix matrix,gdouble x,gdouble y
|
||||||
</FUNCTION>
|
</FUNCTION>
|
||||||
<FUNCTION>
|
<FUNCTION>
|
||||||
<NAME>gimp_matrix_rotate</NAME>
|
<NAME>gimp_matrix_rotate</NAME>
|
||||||
<RETURNS>void </RETURNS>
|
<RETURNS>void </RETURNS>
|
||||||
GimpMatrix, double
|
GimpMatrix matrix,gdouble theta
|
||||||
</FUNCTION>
|
</FUNCTION>
|
||||||
<FUNCTION>
|
<FUNCTION>
|
||||||
<NAME>gimp_matrix_xshear</NAME>
|
<NAME>gimp_matrix_xshear</NAME>
|
||||||
<RETURNS>void </RETURNS>
|
<RETURNS>void </RETURNS>
|
||||||
GimpMatrix, double
|
GimpMatrix matrix,gdouble amount
|
||||||
</FUNCTION>
|
</FUNCTION>
|
||||||
<FUNCTION>
|
<FUNCTION>
|
||||||
<NAME>gimp_matrix_yshear</NAME>
|
<NAME>gimp_matrix_yshear</NAME>
|
||||||
<RETURNS>void </RETURNS>
|
<RETURNS>void </RETURNS>
|
||||||
GimpMatrix, double
|
GimpMatrix matrix,gdouble amount
|
||||||
</FUNCTION>
|
</FUNCTION>
|
||||||
<FUNCTION>
|
<FUNCTION>
|
||||||
<NAME>gimp_matrix_determinant</NAME>
|
<NAME>gimp_matrix_determinant</NAME>
|
||||||
<RETURNS>double </RETURNS>
|
<RETURNS>gdouble </RETURNS>
|
||||||
GimpMatrix
|
GimpMatrix matrix
|
||||||
</FUNCTION>
|
</FUNCTION>
|
||||||
<FUNCTION>
|
<FUNCTION>
|
||||||
<NAME>gimp_matrix_invert</NAME>
|
<NAME>gimp_matrix_invert</NAME>
|
||||||
<RETURNS>void </RETURNS>
|
<RETURNS>void </RETURNS>
|
||||||
GimpMatrix m, GimpMatrix m_inv
|
GimpMatrix matrix,GimpMatrix matrix_inv
|
||||||
</FUNCTION>
|
</FUNCTION>
|
||||||
<FUNCTION>
|
<FUNCTION>
|
||||||
<NAME>gimp_matrix_duplicate</NAME>
|
<NAME>gimp_matrix_duplicate</NAME>
|
||||||
<RETURNS>void </RETURNS>
|
<RETURNS>void </RETURNS>
|
||||||
GimpMatrix src, GimpMatrix target
|
GimpMatrix src,GimpMatrix target
|
||||||
</FUNCTION>
|
</FUNCTION>
|
||||||
<FUNCTION>
|
<FUNCTION>
|
||||||
<NAME>gimp_matrix_is_diagonal</NAME>
|
<NAME>gimp_matrix_is_diagonal</NAME>
|
||||||
<RETURNS>int </RETURNS>
|
<RETURNS>gboolean </RETURNS>
|
||||||
GimpMatrix m
|
GimpMatrix matrix
|
||||||
</FUNCTION>
|
</FUNCTION>
|
||||||
<FUNCTION>
|
<FUNCTION>
|
||||||
<NAME>gimp_matrix_is_identity</NAME>
|
<NAME>gimp_matrix_is_identity</NAME>
|
||||||
<RETURNS>int </RETURNS>
|
<RETURNS>gboolean </RETURNS>
|
||||||
GimpMatrix m
|
GimpMatrix matrix
|
||||||
</FUNCTION>
|
</FUNCTION>
|
||||||
<FUNCTION>
|
<FUNCTION>
|
||||||
<NAME>gimp_matrix_is_simple</NAME>
|
<NAME>gimp_matrix_is_simple</NAME>
|
||||||
<RETURNS>int </RETURNS>
|
<RETURNS>gboolean </RETURNS>
|
||||||
GimpMatrix m
|
GimpMatrix matrix
|
||||||
</FUNCTION>
|
</FUNCTION>
|
||||||
<MACRO>
|
<MACRO>
|
||||||
<NAME>PARASITE_PERSISTENT</NAME>
|
<NAME>PARASITE_PERSISTENT</NAME>
|
||||||
|
@ -22,10 +22,6 @@ gimpcolorspace
|
|||||||
@red:
|
@red:
|
||||||
@green:
|
@green:
|
||||||
@blue:
|
@blue:
|
||||||
<!-- # Unused Parameters # -->
|
|
||||||
@Param1:
|
|
||||||
@Param2:
|
|
||||||
@Param3:
|
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_hsv_to_rgb ##### -->
|
<!-- ##### FUNCTION gimp_hsv_to_rgb ##### -->
|
||||||
@ -36,10 +32,6 @@ gimpcolorspace
|
|||||||
@hue:
|
@hue:
|
||||||
@saturation:
|
@saturation:
|
||||||
@value:
|
@value:
|
||||||
<!-- # Unused Parameters # -->
|
|
||||||
@Param1:
|
|
||||||
@Param2:
|
|
||||||
@Param3:
|
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_rgb_to_hls ##### -->
|
<!-- ##### FUNCTION gimp_rgb_to_hls ##### -->
|
||||||
@ -50,10 +42,6 @@ gimpcolorspace
|
|||||||
@red:
|
@red:
|
||||||
@green:
|
@green:
|
||||||
@blue:
|
@blue:
|
||||||
<!-- # Unused Parameters # -->
|
|
||||||
@Param1:
|
|
||||||
@Param2:
|
|
||||||
@Param3:
|
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_rgb_to_l ##### -->
|
<!-- ##### FUNCTION gimp_rgb_to_l ##### -->
|
||||||
@ -65,10 +53,6 @@ gimpcolorspace
|
|||||||
@green:
|
@green:
|
||||||
@blue:
|
@blue:
|
||||||
@Returns:
|
@Returns:
|
||||||
<!-- # Unused Parameters # -->
|
|
||||||
@Varargs:
|
|
||||||
@Varargs:
|
|
||||||
@Varargs:
|
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_hls_to_rgb ##### -->
|
<!-- ##### FUNCTION gimp_hls_to_rgb ##### -->
|
||||||
@ -79,10 +63,6 @@ gimpcolorspace
|
|||||||
@hue:
|
@hue:
|
||||||
@lightness:
|
@lightness:
|
||||||
@saturation:
|
@saturation:
|
||||||
<!-- # Unused Parameters # -->
|
|
||||||
@Param1:
|
|
||||||
@Param2:
|
|
||||||
@Param3:
|
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_rgb_to_hsv_double ##### -->
|
<!-- ##### FUNCTION gimp_rgb_to_hsv_double ##### -->
|
||||||
@ -93,10 +73,6 @@ gimpcolorspace
|
|||||||
@red:
|
@red:
|
||||||
@green:
|
@green:
|
||||||
@blue:
|
@blue:
|
||||||
<!-- # Unused Parameters # -->
|
|
||||||
@Param1:
|
|
||||||
@Param2:
|
|
||||||
@Param3:
|
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_hsv_to_rgb_double ##### -->
|
<!-- ##### FUNCTION gimp_hsv_to_rgb_double ##### -->
|
||||||
@ -107,10 +83,6 @@ gimpcolorspace
|
|||||||
@hue:
|
@hue:
|
||||||
@saturation:
|
@saturation:
|
||||||
@value:
|
@value:
|
||||||
<!-- # Unused Parameters # -->
|
|
||||||
@Param1:
|
|
||||||
@Param2:
|
|
||||||
@Param3:
|
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_rgb_to_hsv4 ##### -->
|
<!-- ##### FUNCTION gimp_rgb_to_hsv4 ##### -->
|
||||||
@ -122,11 +94,6 @@ gimpcolorspace
|
|||||||
@red:
|
@red:
|
||||||
@green:
|
@green:
|
||||||
@blue:
|
@blue:
|
||||||
<!-- # Unused Parameters # -->
|
|
||||||
@Param1:
|
|
||||||
@Param2:
|
|
||||||
@Param3:
|
|
||||||
@Param4:
|
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_hsv_to_rgb4 ##### -->
|
<!-- ##### FUNCTION gimp_hsv_to_rgb4 ##### -->
|
||||||
@ -138,11 +105,6 @@ gimpcolorspace
|
|||||||
@hue:
|
@hue:
|
||||||
@saturation:
|
@saturation:
|
||||||
@value:
|
@value:
|
||||||
<!-- # Unused Parameters # -->
|
|
||||||
@Param1:
|
|
||||||
@Param2:
|
|
||||||
@Param3:
|
|
||||||
@Param4:
|
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### MACRO INTENSITY_RED ##### -->
|
<!-- ##### MACRO INTENSITY_RED ##### -->
|
||||||
|
@ -2,11 +2,15 @@
|
|||||||
gimpmatrix
|
gimpmatrix
|
||||||
|
|
||||||
<!-- ##### SECTION Short_Description ##### -->
|
<!-- ##### SECTION Short_Description ##### -->
|
||||||
|
Utilities to set up and manipulate 3x3 transformation matrices.
|
||||||
|
|
||||||
<!-- ##### SECTION Long_Description ##### -->
|
<!-- ##### SECTION Long_Description ##### -->
|
||||||
<para>
|
<para>
|
||||||
|
When doing image manipulation you will often need 3x3 transformation
|
||||||
|
matrices that define translation, rotation, scaling, shearing and
|
||||||
|
arbitrary perspective transformations using a 3x3 matrix. Here you'll
|
||||||
|
find a set of utility functions to set up those matrices and to perform
|
||||||
|
basic matrix manipulations and tests.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<!-- ##### SECTION See_Also ##### -->
|
<!-- ##### SECTION See_Also ##### -->
|
||||||
@ -25,11 +29,11 @@ gimpmatrix
|
|||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@Param1:
|
@matrix:
|
||||||
@Param2:
|
@x:
|
||||||
@Param3:
|
@y:
|
||||||
@Param4:
|
@newx:
|
||||||
@Param5:
|
@newy:
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_matrix_mult ##### -->
|
<!-- ##### FUNCTION gimp_matrix_mult ##### -->
|
||||||
@ -37,8 +41,8 @@ gimpmatrix
|
|||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@Param1:
|
@matrix1:
|
||||||
@Param2:
|
@matrix2:
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_matrix_identity ##### -->
|
<!-- ##### FUNCTION gimp_matrix_identity ##### -->
|
||||||
@ -46,7 +50,7 @@ gimpmatrix
|
|||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@Param1:
|
@matrix:
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_matrix_translate ##### -->
|
<!-- ##### FUNCTION gimp_matrix_translate ##### -->
|
||||||
@ -54,9 +58,9 @@ gimpmatrix
|
|||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@Param1:
|
@matrix:
|
||||||
@Param2:
|
@x:
|
||||||
@Param3:
|
@y:
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_matrix_scale ##### -->
|
<!-- ##### FUNCTION gimp_matrix_scale ##### -->
|
||||||
@ -64,9 +68,9 @@ gimpmatrix
|
|||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@Param1:
|
@matrix:
|
||||||
@Param2:
|
@x:
|
||||||
@Param3:
|
@y:
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_matrix_rotate ##### -->
|
<!-- ##### FUNCTION gimp_matrix_rotate ##### -->
|
||||||
@ -74,8 +78,8 @@ gimpmatrix
|
|||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@Param1:
|
@matrix:
|
||||||
@Param2:
|
@theta:
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_matrix_xshear ##### -->
|
<!-- ##### FUNCTION gimp_matrix_xshear ##### -->
|
||||||
@ -83,8 +87,8 @@ gimpmatrix
|
|||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@Param1:
|
@matrix:
|
||||||
@Param2:
|
@amount:
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_matrix_yshear ##### -->
|
<!-- ##### FUNCTION gimp_matrix_yshear ##### -->
|
||||||
@ -92,8 +96,8 @@ gimpmatrix
|
|||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@Param1:
|
@matrix:
|
||||||
@Param2:
|
@amount:
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_matrix_determinant ##### -->
|
<!-- ##### FUNCTION gimp_matrix_determinant ##### -->
|
||||||
@ -101,7 +105,7 @@ gimpmatrix
|
|||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@Param1:
|
@matrix:
|
||||||
@Returns:
|
@Returns:
|
||||||
|
|
||||||
|
|
||||||
@ -110,8 +114,8 @@ gimpmatrix
|
|||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@m:
|
@matrix:
|
||||||
@m_inv:
|
@matrix_inv:
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_matrix_duplicate ##### -->
|
<!-- ##### FUNCTION gimp_matrix_duplicate ##### -->
|
||||||
@ -128,7 +132,7 @@ gimpmatrix
|
|||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@m:
|
@matrix:
|
||||||
@Returns:
|
@Returns:
|
||||||
|
|
||||||
|
|
||||||
@ -137,7 +141,7 @@ gimpmatrix
|
|||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@m:
|
@matrix:
|
||||||
@Returns:
|
@Returns:
|
||||||
|
|
||||||
|
|
||||||
@ -146,7 +150,7 @@ gimpmatrix
|
|||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@m:
|
@matrix:
|
||||||
@Returns:
|
@Returns:
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,8 +48,6 @@ gimpmenu
|
|||||||
@mask_data:
|
@mask_data:
|
||||||
@dialog_closing:
|
@dialog_closing:
|
||||||
@user_data:
|
@user_data:
|
||||||
<!-- # Unused Parameters # -->
|
|
||||||
@Param1:
|
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### USER_FUNCTION GRunPatternCallback ##### -->
|
<!-- ##### USER_FUNCTION GRunPatternCallback ##### -->
|
||||||
@ -64,8 +62,6 @@ gimpmenu
|
|||||||
@mask_data:
|
@mask_data:
|
||||||
@dialog_closing:
|
@dialog_closing:
|
||||||
@user_data:
|
@user_data:
|
||||||
<!-- # Unused Parameters # -->
|
|
||||||
@Param1:
|
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### USER_FUNCTION GRunGradientCallback ##### -->
|
<!-- ##### USER_FUNCTION GRunGradientCallback ##### -->
|
||||||
@ -78,8 +74,6 @@ gimpmenu
|
|||||||
@grad_data:
|
@grad_data:
|
||||||
@dialog_closing:
|
@dialog_closing:
|
||||||
@user_data:
|
@user_data:
|
||||||
<!-- # Unused Parameters # -->
|
|
||||||
@Param1:
|
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION gimp_image_menu_new ##### -->
|
<!-- ##### FUNCTION gimp_image_menu_new ##### -->
|
||||||
|
@ -24,159 +24,281 @@
|
|||||||
|
|
||||||
#define EPSILON 1e-6
|
#define EPSILON 1e-6
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_matrix_transform_point:
|
||||||
|
* @matrix: The transformation matrix.
|
||||||
|
* @x: The source X coordinate.
|
||||||
|
* @y: The source Y coordinate.
|
||||||
|
* @newx: The transformed X coordinate.
|
||||||
|
* @newy: The transformed Y coordinate.
|
||||||
|
*
|
||||||
|
* Transforms a point in 2D as specified by the transformation matrix.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
gimp_matrix_transform_point (GimpMatrix m, double x, double y,
|
gimp_matrix_transform_point (GimpMatrix matrix,
|
||||||
double *newx, double *newy)
|
gdouble x,
|
||||||
|
gdouble y,
|
||||||
|
gdouble *newx,
|
||||||
|
gdouble *newy)
|
||||||
{
|
{
|
||||||
double w;
|
gdouble w;
|
||||||
w = m[2][0]*x + m[2][1]*y + m[2][2];
|
|
||||||
|
w = matrix[2][0]*x + matrix[2][1]*y + matrix[2][2];
|
||||||
|
|
||||||
if (w == 0.0)
|
if (w == 0.0)
|
||||||
w = 1.0;
|
w = 1.0;
|
||||||
else
|
else
|
||||||
w = 1.0/w;
|
w = 1.0/w;
|
||||||
|
|
||||||
*newx = (m[0][0]*x + m[0][1]*y + m[0][2])*w;
|
*newx = (matrix[0][0]*x + matrix[0][1]*y + matrix[0][2])*w;
|
||||||
*newy = (m[1][0]*x + m[1][1]*y + m[1][2])*w;
|
*newy = (matrix[1][0]*x + matrix[1][1]*y + matrix[1][2])*w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_matrix_mult:
|
||||||
|
* @matrix1: The first input matrix.
|
||||||
|
* @matrix2: The second input matrix which will be oeverwritten ba the result.
|
||||||
|
*
|
||||||
|
* Multiplies two matrices and puts the result into the second one.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
gimp_matrix_mult (GimpMatrix m1, GimpMatrix m2)
|
gimp_matrix_mult (GimpMatrix matrix1,
|
||||||
|
GimpMatrix matrix2)
|
||||||
{
|
{
|
||||||
int i, j;
|
gint i, j;
|
||||||
GimpMatrix tmp;
|
GimpMatrix tmp;
|
||||||
double t1, t2, t3;
|
gdouble t1, t2, t3;
|
||||||
|
|
||||||
for (i = 0; i < 3; i++)
|
for (i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
t1 = m1[i][0];
|
t1 = matrix1[i][0];
|
||||||
t2 = m1[i][1];
|
t2 = matrix1[i][1];
|
||||||
t3 = m1[i][2];
|
t3 = matrix1[i][2];
|
||||||
for (j = 0; j < 3; j++)
|
for (j = 0; j < 3; j++)
|
||||||
{
|
{
|
||||||
tmp[i][j] = t1 * m2[0][j];
|
tmp[i][j] = t1 * matrix2[0][j];
|
||||||
tmp[i][j] += t2 * m2[1][j];
|
tmp[i][j] += t2 * matrix2[1][j];
|
||||||
tmp[i][j] += t3 * m2[2][j];
|
tmp[i][j] += t3 * matrix2[2][j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* put the results in m2 */
|
|
||||||
memcpy(&m2[0][0], &tmp[0][0], sizeof(GimpMatrix));
|
/* put the results in matrix2 */
|
||||||
|
memcpy (&matrix2[0][0], &tmp[0][0], sizeof(GimpMatrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_matrix_identity:
|
||||||
|
* @matrix: A matrix.
|
||||||
|
*
|
||||||
|
* Sets the matrix to the identity matrix.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
gimp_matrix_identity (GimpMatrix m)
|
gimp_matrix_identity (GimpMatrix matrix)
|
||||||
{
|
{
|
||||||
static GimpMatrix identity = { {1.0, 0.0, 0.0},
|
static GimpMatrix identity = { {1.0, 0.0, 0.0},
|
||||||
{0.0, 1.0, 0.0},
|
{0.0, 1.0, 0.0},
|
||||||
{0.0, 0.0, 1.0} };
|
{0.0, 0.0, 1.0} };
|
||||||
|
|
||||||
memcpy(&m[0][0], &identity[0][0], sizeof(GimpMatrix));
|
memcpy (&matrix[0][0], &identity[0][0], sizeof(GimpMatrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_matrix_translate:
|
||||||
|
* @matrix: The matrix that is to be translated.
|
||||||
|
* @x: Translation in X direction.
|
||||||
|
* @y: Translation in Y direction.
|
||||||
|
*
|
||||||
|
* Translates the matrix by x and y.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
gimp_matrix_translate (GimpMatrix m, double x, double y)
|
gimp_matrix_translate (GimpMatrix matrix,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y)
|
||||||
{
|
{
|
||||||
double g, h, i;
|
gdouble g, h, i;
|
||||||
g = m[2][0];
|
|
||||||
h = m[2][1];
|
g = matrix[2][0];
|
||||||
i = m[2][2];
|
h = matrix[2][1];
|
||||||
m[0][0] += x*g;
|
i = matrix[2][2];
|
||||||
m[0][1] += x*h;
|
|
||||||
m[0][2] += x*i;
|
matrix[0][0] += x*g;
|
||||||
m[1][0] += y*g;
|
matrix[0][1] += x*h;
|
||||||
m[1][1] += y*h;
|
matrix[0][2] += x*i;
|
||||||
m[1][2] += y*i;
|
matrix[1][0] += y*g;
|
||||||
|
matrix[1][1] += y*h;
|
||||||
|
matrix[1][2] += y*i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_matrix_scale:
|
||||||
|
* @matrix: The matrix that is to be scaled.
|
||||||
|
* @x: X scale factor.
|
||||||
|
* @y: Y scale factor.
|
||||||
|
*
|
||||||
|
* Scales the matrix by x and y
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
gimp_matrix_scale (GimpMatrix m, double x, double y)
|
gimp_matrix_scale (GimpMatrix matrix,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y)
|
||||||
{
|
{
|
||||||
m[0][0] *= x;
|
matrix[0][0] *= x;
|
||||||
m[0][1] *= x;
|
matrix[0][1] *= x;
|
||||||
m[0][2] *= x;
|
matrix[0][2] *= x;
|
||||||
|
|
||||||
m[1][0] *= y;
|
matrix[1][0] *= y;
|
||||||
m[1][1] *= y;
|
matrix[1][1] *= y;
|
||||||
m[1][2] *= y;
|
matrix[1][2] *= y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_matrix_rotate:
|
||||||
|
* @matrix: The matrix that is to be rotated.
|
||||||
|
* @theta: The angle of rotation (in radians).
|
||||||
|
*
|
||||||
|
* Rotates the matrix by theta degrees.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
gimp_matrix_rotate (GimpMatrix m, double theta)
|
gimp_matrix_rotate (GimpMatrix matrix,
|
||||||
|
gdouble theta)
|
||||||
{
|
{
|
||||||
double t1, t2;
|
gdouble t1, t2;
|
||||||
double cost, sint;
|
gdouble cost, sint;
|
||||||
|
|
||||||
cost = cos(theta);
|
cost = cos(theta);
|
||||||
sint = sin(theta);
|
sint = sin(theta);
|
||||||
|
|
||||||
t1 = m[0][0];
|
t1 = matrix[0][0];
|
||||||
t2 = m[1][0];
|
t2 = matrix[1][0];
|
||||||
m[0][0] = cost*t1 - sint*t2;
|
matrix[0][0] = cost*t1 - sint*t2;
|
||||||
m[1][0] = sint*t1 + cost*t2;
|
matrix[1][0] = sint*t1 + cost*t2;
|
||||||
|
|
||||||
t1 = m[0][1];
|
t1 = matrix[0][1];
|
||||||
t2 = m[1][1];
|
t2 = matrix[1][1];
|
||||||
m[0][1] = cost*t1 - sint*t2;
|
matrix[0][1] = cost*t1 - sint*t2;
|
||||||
m[1][1] = sint*t1 + cost*t2;
|
matrix[1][1] = sint*t1 + cost*t2;
|
||||||
|
|
||||||
t1 = m[0][2];
|
t1 = matrix[0][2];
|
||||||
t2 = m[1][2];
|
t2 = matrix[1][2];
|
||||||
m[0][2] = cost*t1 - sint*t2;
|
matrix[0][2] = cost*t1 - sint*t2;
|
||||||
m[1][2] = sint*t1 + cost*t2;
|
matrix[1][2] = sint*t1 + cost*t2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_matrix_xshear:
|
||||||
|
* @matrix: The matrix that is to be sheared.
|
||||||
|
* @amount: X shear amount.
|
||||||
|
*
|
||||||
|
* Shears the matrix in the X direction.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
gimp_matrix_xshear (GimpMatrix m, double amnt)
|
gimp_matrix_xshear (GimpMatrix matrix,
|
||||||
|
gdouble amount)
|
||||||
{
|
{
|
||||||
m[0][0] += amnt * m[1][0];
|
matrix[0][0] += amount * matrix[1][0];
|
||||||
m[0][1] += amnt * m[1][1];
|
matrix[0][1] += amount * matrix[1][1];
|
||||||
m[0][2] += amnt * m[1][2];
|
matrix[0][2] += amount * matrix[1][2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_matrix_yshear:
|
||||||
|
* @matrix: The matrix that is to be sheared.
|
||||||
|
* @amount: Y shear amount.
|
||||||
|
*
|
||||||
|
* Shears the matrix in the Y direction.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
gimp_matrix_yshear (GimpMatrix m, double amnt)
|
gimp_matrix_yshear (GimpMatrix matrix,
|
||||||
|
gdouble amount)
|
||||||
{
|
{
|
||||||
m[1][0] += amnt * m[0][0];
|
matrix[1][0] += amount * matrix[0][0];
|
||||||
m[1][1] += amnt * m[0][1];
|
matrix[1][1] += amount * matrix[0][1];
|
||||||
m[1][2] += amnt * m[0][2];
|
matrix[1][2] += amount * matrix[0][2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
double
|
* gimp_matrix_determinant:
|
||||||
gimp_matrix_determinant (GimpMatrix m)
|
* @matrix: The input matrix.
|
||||||
|
*
|
||||||
|
* Calculates the determinant of the given matrix.
|
||||||
|
*
|
||||||
|
* Returns: The determinant.
|
||||||
|
*/
|
||||||
|
gdouble
|
||||||
|
gimp_matrix_determinant (GimpMatrix matrix)
|
||||||
{
|
{
|
||||||
double determinant;
|
gdouble determinant;
|
||||||
|
|
||||||
determinant = m[0][0] * (m[1][1]*m[2][2] - m[1][2]*m[2][1]);
|
determinant =
|
||||||
determinant -= m[1][0] * (m[0][1]*m[2][2] - m[0][2]*m[2][1]);
|
matrix[0][0] * (matrix[1][1]*matrix[2][2] - matrix[1][2]*matrix[2][1]);
|
||||||
determinant += m[2][0] * (m[0][1]*m[1][2] - m[0][2]*m[1][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]);
|
||||||
|
|
||||||
return determinant;
|
return determinant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_matrix_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
|
void
|
||||||
gimp_matrix_invert (GimpMatrix m, GimpMatrix m_inv)
|
gimp_matrix_invert (GimpMatrix matrix,
|
||||||
|
GimpMatrix matrix_inv)
|
||||||
{
|
{
|
||||||
double det_1;
|
gdouble det_1;
|
||||||
|
|
||||||
|
det_1 = gimp_matrix_determinant (matrix);
|
||||||
|
|
||||||
det_1 = gimp_matrix_determinant (m);
|
|
||||||
if (det_1 == 0.0)
|
if (det_1 == 0.0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
det_1 = 1.0 / det_1;
|
det_1 = 1.0 / det_1;
|
||||||
|
|
||||||
m_inv[0][0] = ( m[1][1] * m[2][2] - m[1][2] * m[2][1] ) * det_1;
|
matrix_inv[0][0] =
|
||||||
m_inv[1][0] = - ( m[1][0] * m[2][2] - m[1][2] * m[2][0] ) * det_1;
|
(matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1]) * det_1;
|
||||||
m_inv[2][0] = ( m[1][0] * m[2][1] - m[1][1] * m[2][0] ) * det_1;
|
|
||||||
m_inv[0][1] = - ( m[0][1] * m[2][2] - m[0][2] * m[2][1] ) * det_1;
|
matrix_inv[1][0] =
|
||||||
m_inv[1][1] = ( m[0][0] * m[2][2] - m[0][2] * m[2][0] ) * det_1;
|
- (matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0]) * det_1;
|
||||||
m_inv[2][1] = - ( m[0][0] * m[2][1] - m[0][1] * m[2][0] ) * det_1;
|
|
||||||
m_inv[0][2] = ( m[0][1] * m[1][2] - m[0][2] * m[1][1] ) * det_1;
|
matrix_inv[2][0] =
|
||||||
m_inv[1][2] = - ( m[0][0] * m[1][2] - m[0][2] * m[1][0] ) * det_1;
|
(matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0]) * det_1;
|
||||||
m_inv[2][2] = ( m[0][0] * m[1][1] - m[0][1] * m[1][0] ) * det_1;
|
|
||||||
|
matrix_inv[0][1] =
|
||||||
|
- (matrix[0][1] * matrix[2][2] - matrix[0][2] * matrix[2][1] ) * det_1;
|
||||||
|
|
||||||
|
matrix_inv[1][1] =
|
||||||
|
(matrix[0][0] * matrix[2][2] - matrix[0][2] * matrix[2][0]) * det_1;
|
||||||
|
|
||||||
|
matrix_inv[2][1] =
|
||||||
|
- (matrix[0][0] * matrix[2][1] - matrix[0][1] * matrix[2][0]) * det_1;
|
||||||
|
|
||||||
|
matrix_inv[0][2] =
|
||||||
|
(matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1]) * det_1;
|
||||||
|
|
||||||
|
matrix_inv[1][2] =
|
||||||
|
- (matrix[0][0] * matrix[1][2] - matrix[0][2] * matrix[1][0]) * det_1;
|
||||||
|
|
||||||
|
matrix_inv[2][2] =
|
||||||
|
(matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]) * det_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_matrix_duplicate:
|
||||||
|
* @src: The source matrix.
|
||||||
|
* @target: The destination matrix.
|
||||||
|
*
|
||||||
|
* Copies the source matrix to the destination matrix.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
gimp_matrix_duplicate (GimpMatrix src, GimpMatrix target)
|
gimp_matrix_duplicate (GimpMatrix src,
|
||||||
|
GimpMatrix target)
|
||||||
{
|
{
|
||||||
memcpy (&target[0][0], &src[0][0], sizeof(GimpMatrix));
|
memcpy (&target[0][0], &src[0][0], sizeof(GimpMatrix));
|
||||||
}
|
}
|
||||||
@ -184,26 +306,44 @@ gimp_matrix_duplicate (GimpMatrix src, GimpMatrix target)
|
|||||||
|
|
||||||
/* functions to test for matrix properties */
|
/* functions to test for matrix properties */
|
||||||
|
|
||||||
int
|
|
||||||
gimp_matrix_is_diagonal (GimpMatrix m)
|
/**
|
||||||
|
* gimp_matrix_is_diagonal:
|
||||||
|
* @matrix: The matrix that is to be tested.
|
||||||
|
*
|
||||||
|
* Checks if the given matrix is diagonal.
|
||||||
|
*
|
||||||
|
* Returns: TRUE if the matrix is diagonal.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
gimp_matrix_is_diagonal (GimpMatrix matrix)
|
||||||
{
|
{
|
||||||
int i,j;
|
gint i, j;
|
||||||
|
|
||||||
for (i = 0; i < 3; i++)
|
for (i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
for (j = 0; j < 3; j++)
|
for (j = 0; j < 3; j++)
|
||||||
{
|
{
|
||||||
if (i != j && fabs (m[i][j]) > EPSILON)
|
if (i != j && fabs (matrix[i][j]) > EPSILON)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
/**
|
||||||
gimp_matrix_is_identity (GimpMatrix m)
|
* gimp_matrix_is_identity:
|
||||||
|
* @matrix: The matrix that is to be tested.
|
||||||
|
*
|
||||||
|
* Checks if the given matrix is the identity matrix.
|
||||||
|
*
|
||||||
|
* Returns: TRUE if the matrix is the identity matrix.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
gimp_matrix_is_identity (GimpMatrix matrix)
|
||||||
{
|
{
|
||||||
int i,j;
|
gint i,j;
|
||||||
|
|
||||||
for (i = 0; i < 3; i++)
|
for (i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
@ -211,16 +351,17 @@ gimp_matrix_is_identity (GimpMatrix m)
|
|||||||
{
|
{
|
||||||
if (i == j)
|
if (i == j)
|
||||||
{
|
{
|
||||||
if (fabs (m[i][j] - 1.0) > EPSILON)
|
if (fabs (matrix[i][j] - 1.0) > EPSILON)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (fabs (m[i][j]) > EPSILON)
|
if (fabs (matrix[i][j]) > EPSILON)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,24 +369,33 @@ gimp_matrix_is_identity (GimpMatrix m)
|
|||||||
This function returns TRUE if all entries of the upper left
|
This function returns TRUE if all entries of the upper left
|
||||||
2x2 matrix are either 0 or 1
|
2x2 matrix are either 0 or 1
|
||||||
*/
|
*/
|
||||||
int
|
|
||||||
gimp_matrix_is_simple (GimpMatrix m)
|
|
||||||
|
/**
|
||||||
|
* gimp_matrix_is_simple:
|
||||||
|
* @matrix: The matrix that is to be tested.
|
||||||
|
*
|
||||||
|
* Checks if we'll need to interpolate when applying this matrix as
|
||||||
|
* a transformation.
|
||||||
|
*
|
||||||
|
* Returns: TRUE if all entries of the upper left 2x2 matrix are either
|
||||||
|
* 0 or 1
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
gimp_matrix_is_simple (GimpMatrix matrix)
|
||||||
{
|
{
|
||||||
double absm;
|
gdouble absm;
|
||||||
int i,j;
|
gint i, j;
|
||||||
|
|
||||||
for (i = 0; i < 2; i++)
|
for (i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
for (j = 0; j < 2; j++)
|
for (j = 0; j < 2; j++)
|
||||||
{
|
{
|
||||||
absm = fabs (m[i][j]);
|
absm = fabs (matrix[i][j]);
|
||||||
if (absm > EPSILON && fabs (absm - 1.0) > EPSILON)
|
if (absm > EPSILON && fabs (absm - 1.0) > EPSILON)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,21 +26,35 @@ extern "C" {
|
|||||||
|
|
||||||
typedef double GimpMatrix[3][3];
|
typedef double GimpMatrix[3][3];
|
||||||
|
|
||||||
void gimp_matrix_transform_point (GimpMatrix, double, double,
|
void gimp_matrix_transform_point (GimpMatrix matrix,
|
||||||
double *, double *);
|
gdouble x,
|
||||||
void gimp_matrix_mult (GimpMatrix, GimpMatrix);
|
gdouble y,
|
||||||
void gimp_matrix_identity (GimpMatrix);
|
gdouble *newx,
|
||||||
void gimp_matrix_translate (GimpMatrix, double, double);
|
gdouble *newy);
|
||||||
void gimp_matrix_scale (GimpMatrix, double, double);
|
void gimp_matrix_mult (GimpMatrix matrix1,
|
||||||
void gimp_matrix_rotate (GimpMatrix, double);
|
GimpMatrix matrix2);
|
||||||
void gimp_matrix_xshear (GimpMatrix, double);
|
void gimp_matrix_identity (GimpMatrix matrix);
|
||||||
void gimp_matrix_yshear (GimpMatrix, double);
|
void gimp_matrix_translate (GimpMatrix matrix,
|
||||||
double gimp_matrix_determinant (GimpMatrix);
|
gdouble x,
|
||||||
void gimp_matrix_invert (GimpMatrix m, GimpMatrix m_inv);
|
gdouble y);
|
||||||
void gimp_matrix_duplicate (GimpMatrix src, GimpMatrix target);
|
void gimp_matrix_scale (GimpMatrix matrix,
|
||||||
int gimp_matrix_is_diagonal (GimpMatrix m);
|
gdouble x,
|
||||||
int gimp_matrix_is_identity (GimpMatrix m);
|
gdouble y);
|
||||||
int gimp_matrix_is_simple (GimpMatrix m);
|
void gimp_matrix_rotate (GimpMatrix matrix,
|
||||||
|
gdouble theta);
|
||||||
|
void gimp_matrix_xshear (GimpMatrix matrix,
|
||||||
|
gdouble amount);
|
||||||
|
void gimp_matrix_yshear (GimpMatrix matrix,
|
||||||
|
gdouble amount);
|
||||||
|
gdouble gimp_matrix_determinant (GimpMatrix matrix);
|
||||||
|
void gimp_matrix_invert (GimpMatrix matrix,
|
||||||
|
GimpMatrix matrix_inv);
|
||||||
|
void gimp_matrix_duplicate (GimpMatrix src,
|
||||||
|
GimpMatrix target);
|
||||||
|
|
||||||
|
gboolean gimp_matrix_is_diagonal (GimpMatrix matrix);
|
||||||
|
gboolean gimp_matrix_is_identity (GimpMatrix matrix);
|
||||||
|
gboolean gimp_matrix_is_simple (GimpMatrix matrix);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user