mirror of https://github.com/GNOME/gimp.git
parent
cb7da6395d
commit
7512a83ab9
|
@ -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>
|
||||
|
||||
* 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>
|
||||
|
||||
* libgimp/.cvsignore
|
||||
|
|
|
@ -2549,72 +2549,72 @@ typedef double GimpMatrix[3][3];
|
|||
<FUNCTION>
|
||||
<NAME>gimp_matrix_transform_point</NAME>
|
||||
<RETURNS>void </RETURNS>
|
||||
GimpMatrix, double, double,double *, double *
|
||||
GimpMatrix matrix,gdouble x,gdouble y,gdouble *newx,gdouble *newy
|
||||
</FUNCTION>
|
||||
<FUNCTION>
|
||||
<NAME>gimp_matrix_mult</NAME>
|
||||
<RETURNS>void </RETURNS>
|
||||
GimpMatrix, GimpMatrix
|
||||
GimpMatrix matrix1,GimpMatrix matrix2
|
||||
</FUNCTION>
|
||||
<FUNCTION>
|
||||
<NAME>gimp_matrix_identity</NAME>
|
||||
<RETURNS>void </RETURNS>
|
||||
GimpMatrix
|
||||
GimpMatrix matrix
|
||||
</FUNCTION>
|
||||
<FUNCTION>
|
||||
<NAME>gimp_matrix_translate</NAME>
|
||||
<RETURNS>void </RETURNS>
|
||||
GimpMatrix, double, double
|
||||
GimpMatrix matrix,gdouble x,gdouble y
|
||||
</FUNCTION>
|
||||
<FUNCTION>
|
||||
<NAME>gimp_matrix_scale</NAME>
|
||||
<RETURNS>void </RETURNS>
|
||||
GimpMatrix, double, double
|
||||
GimpMatrix matrix,gdouble x,gdouble y
|
||||
</FUNCTION>
|
||||
<FUNCTION>
|
||||
<NAME>gimp_matrix_rotate</NAME>
|
||||
<RETURNS>void </RETURNS>
|
||||
GimpMatrix, double
|
||||
GimpMatrix matrix,gdouble theta
|
||||
</FUNCTION>
|
||||
<FUNCTION>
|
||||
<NAME>gimp_matrix_xshear</NAME>
|
||||
<RETURNS>void </RETURNS>
|
||||
GimpMatrix, double
|
||||
GimpMatrix matrix,gdouble amount
|
||||
</FUNCTION>
|
||||
<FUNCTION>
|
||||
<NAME>gimp_matrix_yshear</NAME>
|
||||
<RETURNS>void </RETURNS>
|
||||
GimpMatrix, double
|
||||
GimpMatrix matrix,gdouble amount
|
||||
</FUNCTION>
|
||||
<FUNCTION>
|
||||
<NAME>gimp_matrix_determinant</NAME>
|
||||
<RETURNS>double </RETURNS>
|
||||
GimpMatrix
|
||||
<RETURNS>gdouble </RETURNS>
|
||||
GimpMatrix matrix
|
||||
</FUNCTION>
|
||||
<FUNCTION>
|
||||
<NAME>gimp_matrix_invert</NAME>
|
||||
<RETURNS>void </RETURNS>
|
||||
GimpMatrix m, GimpMatrix m_inv
|
||||
GimpMatrix matrix,GimpMatrix matrix_inv
|
||||
</FUNCTION>
|
||||
<FUNCTION>
|
||||
<NAME>gimp_matrix_duplicate</NAME>
|
||||
<RETURNS>void </RETURNS>
|
||||
GimpMatrix src, GimpMatrix target
|
||||
GimpMatrix src,GimpMatrix target
|
||||
</FUNCTION>
|
||||
<FUNCTION>
|
||||
<NAME>gimp_matrix_is_diagonal</NAME>
|
||||
<RETURNS>int </RETURNS>
|
||||
GimpMatrix m
|
||||
<RETURNS>gboolean </RETURNS>
|
||||
GimpMatrix matrix
|
||||
</FUNCTION>
|
||||
<FUNCTION>
|
||||
<NAME>gimp_matrix_is_identity</NAME>
|
||||
<RETURNS>int </RETURNS>
|
||||
GimpMatrix m
|
||||
<RETURNS>gboolean </RETURNS>
|
||||
GimpMatrix matrix
|
||||
</FUNCTION>
|
||||
<FUNCTION>
|
||||
<NAME>gimp_matrix_is_simple</NAME>
|
||||
<RETURNS>int </RETURNS>
|
||||
GimpMatrix m
|
||||
<RETURNS>gboolean </RETURNS>
|
||||
GimpMatrix matrix
|
||||
</FUNCTION>
|
||||
<MACRO>
|
||||
<NAME>PARASITE_PERSISTENT</NAME>
|
||||
|
|
|
@ -22,10 +22,6 @@ gimpcolorspace
|
|||
@red:
|
||||
@green:
|
||||
@blue:
|
||||
<!-- # Unused Parameters # -->
|
||||
@Param1:
|
||||
@Param2:
|
||||
@Param3:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_hsv_to_rgb ##### -->
|
||||
|
@ -36,10 +32,6 @@ gimpcolorspace
|
|||
@hue:
|
||||
@saturation:
|
||||
@value:
|
||||
<!-- # Unused Parameters # -->
|
||||
@Param1:
|
||||
@Param2:
|
||||
@Param3:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_rgb_to_hls ##### -->
|
||||
|
@ -50,10 +42,6 @@ gimpcolorspace
|
|||
@red:
|
||||
@green:
|
||||
@blue:
|
||||
<!-- # Unused Parameters # -->
|
||||
@Param1:
|
||||
@Param2:
|
||||
@Param3:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_rgb_to_l ##### -->
|
||||
|
@ -65,10 +53,6 @@ gimpcolorspace
|
|||
@green:
|
||||
@blue:
|
||||
@Returns:
|
||||
<!-- # Unused Parameters # -->
|
||||
@Varargs:
|
||||
@Varargs:
|
||||
@Varargs:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_hls_to_rgb ##### -->
|
||||
|
@ -79,10 +63,6 @@ gimpcolorspace
|
|||
@hue:
|
||||
@lightness:
|
||||
@saturation:
|
||||
<!-- # Unused Parameters # -->
|
||||
@Param1:
|
||||
@Param2:
|
||||
@Param3:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_rgb_to_hsv_double ##### -->
|
||||
|
@ -93,10 +73,6 @@ gimpcolorspace
|
|||
@red:
|
||||
@green:
|
||||
@blue:
|
||||
<!-- # Unused Parameters # -->
|
||||
@Param1:
|
||||
@Param2:
|
||||
@Param3:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_hsv_to_rgb_double ##### -->
|
||||
|
@ -107,10 +83,6 @@ gimpcolorspace
|
|||
@hue:
|
||||
@saturation:
|
||||
@value:
|
||||
<!-- # Unused Parameters # -->
|
||||
@Param1:
|
||||
@Param2:
|
||||
@Param3:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_rgb_to_hsv4 ##### -->
|
||||
|
@ -122,11 +94,6 @@ gimpcolorspace
|
|||
@red:
|
||||
@green:
|
||||
@blue:
|
||||
<!-- # Unused Parameters # -->
|
||||
@Param1:
|
||||
@Param2:
|
||||
@Param3:
|
||||
@Param4:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_hsv_to_rgb4 ##### -->
|
||||
|
@ -138,11 +105,6 @@ gimpcolorspace
|
|||
@hue:
|
||||
@saturation:
|
||||
@value:
|
||||
<!-- # Unused Parameters # -->
|
||||
@Param1:
|
||||
@Param2:
|
||||
@Param3:
|
||||
@Param4:
|
||||
|
||||
|
||||
<!-- ##### MACRO INTENSITY_RED ##### -->
|
||||
|
|
|
@ -2,11 +2,15 @@
|
|||
gimpmatrix
|
||||
|
||||
<!-- ##### SECTION Short_Description ##### -->
|
||||
|
||||
Utilities to set up and manipulate 3x3 transformation matrices.
|
||||
|
||||
<!-- ##### SECTION Long_Description ##### -->
|
||||
<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>
|
||||
|
||||
<!-- ##### SECTION See_Also ##### -->
|
||||
|
@ -25,11 +29,11 @@ gimpmatrix
|
|||
|
||||
</para>
|
||||
|
||||
@Param1:
|
||||
@Param2:
|
||||
@Param3:
|
||||
@Param4:
|
||||
@Param5:
|
||||
@matrix:
|
||||
@x:
|
||||
@y:
|
||||
@newx:
|
||||
@newy:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_matrix_mult ##### -->
|
||||
|
@ -37,8 +41,8 @@ gimpmatrix
|
|||
|
||||
</para>
|
||||
|
||||
@Param1:
|
||||
@Param2:
|
||||
@matrix1:
|
||||
@matrix2:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_matrix_identity ##### -->
|
||||
|
@ -46,7 +50,7 @@ gimpmatrix
|
|||
|
||||
</para>
|
||||
|
||||
@Param1:
|
||||
@matrix:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_matrix_translate ##### -->
|
||||
|
@ -54,9 +58,9 @@ gimpmatrix
|
|||
|
||||
</para>
|
||||
|
||||
@Param1:
|
||||
@Param2:
|
||||
@Param3:
|
||||
@matrix:
|
||||
@x:
|
||||
@y:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_matrix_scale ##### -->
|
||||
|
@ -64,9 +68,9 @@ gimpmatrix
|
|||
|
||||
</para>
|
||||
|
||||
@Param1:
|
||||
@Param2:
|
||||
@Param3:
|
||||
@matrix:
|
||||
@x:
|
||||
@y:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_matrix_rotate ##### -->
|
||||
|
@ -74,8 +78,8 @@ gimpmatrix
|
|||
|
||||
</para>
|
||||
|
||||
@Param1:
|
||||
@Param2:
|
||||
@matrix:
|
||||
@theta:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_matrix_xshear ##### -->
|
||||
|
@ -83,8 +87,8 @@ gimpmatrix
|
|||
|
||||
</para>
|
||||
|
||||
@Param1:
|
||||
@Param2:
|
||||
@matrix:
|
||||
@amount:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_matrix_yshear ##### -->
|
||||
|
@ -92,8 +96,8 @@ gimpmatrix
|
|||
|
||||
</para>
|
||||
|
||||
@Param1:
|
||||
@Param2:
|
||||
@matrix:
|
||||
@amount:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_matrix_determinant ##### -->
|
||||
|
@ -101,7 +105,7 @@ gimpmatrix
|
|||
|
||||
</para>
|
||||
|
||||
@Param1:
|
||||
@matrix:
|
||||
@Returns:
|
||||
|
||||
|
||||
|
@ -110,8 +114,8 @@ gimpmatrix
|
|||
|
||||
</para>
|
||||
|
||||
@m:
|
||||
@m_inv:
|
||||
@matrix:
|
||||
@matrix_inv:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_matrix_duplicate ##### -->
|
||||
|
@ -128,7 +132,7 @@ gimpmatrix
|
|||
|
||||
</para>
|
||||
|
||||
@m:
|
||||
@matrix:
|
||||
@Returns:
|
||||
|
||||
|
||||
|
@ -137,7 +141,7 @@ gimpmatrix
|
|||
|
||||
</para>
|
||||
|
||||
@m:
|
||||
@matrix:
|
||||
@Returns:
|
||||
|
||||
|
||||
|
@ -146,7 +150,7 @@ gimpmatrix
|
|||
|
||||
</para>
|
||||
|
||||
@m:
|
||||
@matrix:
|
||||
@Returns:
|
||||
|
||||
|
||||
|
|
|
@ -48,8 +48,6 @@ gimpmenu
|
|||
@mask_data:
|
||||
@dialog_closing:
|
||||
@user_data:
|
||||
<!-- # Unused Parameters # -->
|
||||
@Param1:
|
||||
|
||||
|
||||
<!-- ##### USER_FUNCTION GRunPatternCallback ##### -->
|
||||
|
@ -64,8 +62,6 @@ gimpmenu
|
|||
@mask_data:
|
||||
@dialog_closing:
|
||||
@user_data:
|
||||
<!-- # Unused Parameters # -->
|
||||
@Param1:
|
||||
|
||||
|
||||
<!-- ##### USER_FUNCTION GRunGradientCallback ##### -->
|
||||
|
@ -78,8 +74,6 @@ gimpmenu
|
|||
@grad_data:
|
||||
@dialog_closing:
|
||||
@user_data:
|
||||
<!-- # Unused Parameters # -->
|
||||
@Param1:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION gimp_image_menu_new ##### -->
|
||||
|
|
|
@ -24,159 +24,281 @@
|
|||
|
||||
#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
|
||||
gimp_matrix_transform_point (GimpMatrix m, double x, double y,
|
||||
double *newx, double *newy)
|
||||
gimp_matrix_transform_point (GimpMatrix matrix,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
gdouble *newx,
|
||||
gdouble *newy)
|
||||
{
|
||||
double w;
|
||||
w = m[2][0]*x + m[2][1]*y + m[2][2];
|
||||
gdouble w;
|
||||
|
||||
w = matrix[2][0]*x + matrix[2][1]*y + matrix[2][2];
|
||||
|
||||
if (w == 0.0)
|
||||
w = 1.0;
|
||||
else
|
||||
w = 1.0/w;
|
||||
|
||||
*newx = (m[0][0]*x + m[0][1]*y + m[0][2])*w;
|
||||
*newy = (m[1][0]*x + m[1][1]*y + m[1][2])*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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
gimp_matrix_mult (GimpMatrix m1, GimpMatrix m2)
|
||||
gimp_matrix_mult (GimpMatrix matrix1,
|
||||
GimpMatrix matrix2)
|
||||
{
|
||||
int i, j;
|
||||
gint i, j;
|
||||
GimpMatrix tmp;
|
||||
double t1, t2, t3;
|
||||
gdouble t1, t2, t3;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
t1 = m1[i][0];
|
||||
t2 = m1[i][1];
|
||||
t3 = m1[i][2];
|
||||
for (j = 0; j < 3; j++)
|
||||
{
|
||||
tmp[i][j] = t1 * m2[0][j];
|
||||
tmp[i][j] += t2 * m2[1][j];
|
||||
tmp[i][j] += t3 * m2[2][j];
|
||||
t1 = matrix1[i][0];
|
||||
t2 = matrix1[i][1];
|
||||
t3 = matrix1[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];
|
||||
}
|
||||
}
|
||||
}
|
||||
/* 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
|
||||
gimp_matrix_identity (GimpMatrix m)
|
||||
gimp_matrix_identity (GimpMatrix matrix)
|
||||
{
|
||||
static GimpMatrix identity = { {1.0, 0.0, 0.0},
|
||||
{0.0, 1.0, 0.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
|
||||
gimp_matrix_translate (GimpMatrix m, double x, double y)
|
||||
gimp_matrix_translate (GimpMatrix matrix,
|
||||
gdouble x,
|
||||
gdouble y)
|
||||
{
|
||||
double g, h, i;
|
||||
g = m[2][0];
|
||||
h = m[2][1];
|
||||
i = m[2][2];
|
||||
m[0][0] += x*g;
|
||||
m[0][1] += x*h;
|
||||
m[0][2] += x*i;
|
||||
m[1][0] += y*g;
|
||||
m[1][1] += y*h;
|
||||
m[1][2] += y*i;
|
||||
gdouble g, h, i;
|
||||
|
||||
g = matrix[2][0];
|
||||
h = matrix[2][1];
|
||||
i = matrix[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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
gimp_matrix_scale (GimpMatrix m, double x, double y)
|
||||
gimp_matrix_scale (GimpMatrix matrix,
|
||||
gdouble x,
|
||||
gdouble y)
|
||||
{
|
||||
m[0][0] *= x;
|
||||
m[0][1] *= x;
|
||||
m[0][2] *= x;
|
||||
matrix[0][0] *= x;
|
||||
matrix[0][1] *= x;
|
||||
matrix[0][2] *= x;
|
||||
|
||||
m[1][0] *= y;
|
||||
m[1][1] *= y;
|
||||
m[1][2] *= y;
|
||||
matrix[1][0] *= y;
|
||||
matrix[1][1] *= 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
|
||||
gimp_matrix_rotate (GimpMatrix m, double theta)
|
||||
gimp_matrix_rotate (GimpMatrix matrix,
|
||||
gdouble theta)
|
||||
{
|
||||
double t1, t2;
|
||||
double cost, sint;
|
||||
gdouble t1, t2;
|
||||
gdouble cost, sint;
|
||||
|
||||
cost = cos(theta);
|
||||
sint = sin(theta);
|
||||
|
||||
t1 = m[0][0];
|
||||
t2 = m[1][0];
|
||||
m[0][0] = cost*t1 - sint*t2;
|
||||
m[1][0] = sint*t1 + cost*t2;
|
||||
t1 = matrix[0][0];
|
||||
t2 = matrix[1][0];
|
||||
matrix[0][0] = cost*t1 - sint*t2;
|
||||
matrix[1][0] = sint*t1 + cost*t2;
|
||||
|
||||
t1 = m[0][1];
|
||||
t2 = m[1][1];
|
||||
m[0][1] = cost*t1 - sint*t2;
|
||||
m[1][1] = 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 = m[0][2];
|
||||
t2 = m[1][2];
|
||||
m[0][2] = cost*t1 - sint*t2;
|
||||
m[1][2] = 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_matrix_xshear:
|
||||
* @matrix: The matrix that is to be sheared.
|
||||
* @amount: X shear amount.
|
||||
*
|
||||
* Shears the matrix in the X direction.
|
||||
*/
|
||||
void
|
||||
gimp_matrix_xshear (GimpMatrix m, double amnt)
|
||||
gimp_matrix_xshear (GimpMatrix matrix,
|
||||
gdouble amount)
|
||||
{
|
||||
m[0][0] += amnt * m[1][0];
|
||||
m[0][1] += amnt * m[1][1];
|
||||
m[0][2] += amnt * m[1][2];
|
||||
matrix[0][0] += amount * matrix[1][0];
|
||||
matrix[0][1] += amount * matrix[1][1];
|
||||
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
|
||||
gimp_matrix_yshear (GimpMatrix m, double amnt)
|
||||
gimp_matrix_yshear (GimpMatrix matrix,
|
||||
gdouble amount)
|
||||
{
|
||||
m[1][0] += amnt * m[0][0];
|
||||
m[1][1] += amnt * m[0][1];
|
||||
m[1][2] += amnt * m[0][2];
|
||||
matrix[1][0] += amount * matrix[0][0];
|
||||
matrix[1][1] += amount * matrix[0][1];
|
||||
matrix[1][2] += amount * matrix[0][2];
|
||||
}
|
||||
|
||||
|
||||
double
|
||||
gimp_matrix_determinant (GimpMatrix m)
|
||||
/**
|
||||
* gimp_matrix_determinant:
|
||||
* @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 -= m[1][0] * (m[0][1]*m[2][2] - m[0][2]*m[2][1]);
|
||||
determinant += m[2][0] * (m[0][1]*m[1][2] - m[0][2]*m[1][1]);
|
||||
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]);
|
||||
|
||||
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
|
||||
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)
|
||||
return;
|
||||
|
||||
det_1 = 1.0 / det_1;
|
||||
|
||||
m_inv[0][0] = ( m[1][1] * m[2][2] - m[1][2] * m[2][1] ) * det_1;
|
||||
m_inv[1][0] = - ( m[1][0] * m[2][2] - m[1][2] * m[2][0] ) * 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;
|
||||
m_inv[1][1] = ( m[0][0] * m[2][2] - m[0][2] * m[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;
|
||||
m_inv[1][2] = - ( m[0][0] * m[1][2] - m[0][2] * m[1][0] ) * det_1;
|
||||
m_inv[2][2] = ( m[0][0] * m[1][1] - m[0][1] * m[1][0] ) * det_1;
|
||||
matrix_inv[0][0] =
|
||||
(matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1]) * det_1;
|
||||
|
||||
matrix_inv[1][0] =
|
||||
- (matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0]) * det_1;
|
||||
|
||||
matrix_inv[2][0] =
|
||||
(matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][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
|
||||
gimp_matrix_duplicate (GimpMatrix src, GimpMatrix target)
|
||||
gimp_matrix_duplicate (GimpMatrix src,
|
||||
GimpMatrix target)
|
||||
{
|
||||
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 */
|
||||
|
||||
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 (j = 0; j < 3; j++)
|
||||
{
|
||||
if (i != j && fabs (m[i][j]) > EPSILON)
|
||||
if (i != j && fabs (matrix[i][j]) > EPSILON)
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
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++)
|
||||
{
|
||||
|
@ -211,16 +351,17 @@ gimp_matrix_is_identity (GimpMatrix m)
|
|||
{
|
||||
if (i == j)
|
||||
{
|
||||
if (fabs (m[i][j] - 1.0) > EPSILON)
|
||||
if (fabs (matrix[i][j] - 1.0) > EPSILON)
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fabs (m[i][j]) > EPSILON)
|
||||
if (fabs (matrix[i][j]) > EPSILON)
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -228,24 +369,33 @@ gimp_matrix_is_identity (GimpMatrix m)
|
|||
This function returns TRUE if all entries of the upper left
|
||||
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;
|
||||
int i,j;
|
||||
gdouble absm;
|
||||
gint i, j;
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
for (j = 0; j < 2; j++)
|
||||
{
|
||||
absm = fabs (m[i][j]);
|
||||
absm = fabs (matrix[i][j]);
|
||||
if (absm > EPSILON && fabs (absm - 1.0) > EPSILON)
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -26,21 +26,35 @@ extern "C" {
|
|||
|
||||
typedef double GimpMatrix[3][3];
|
||||
|
||||
void gimp_matrix_transform_point (GimpMatrix, double, double,
|
||||
double *, double *);
|
||||
void gimp_matrix_mult (GimpMatrix, GimpMatrix);
|
||||
void gimp_matrix_identity (GimpMatrix);
|
||||
void gimp_matrix_translate (GimpMatrix, double, double);
|
||||
void gimp_matrix_scale (GimpMatrix, double, double);
|
||||
void gimp_matrix_rotate (GimpMatrix, double);
|
||||
void gimp_matrix_xshear (GimpMatrix, double);
|
||||
void gimp_matrix_yshear (GimpMatrix, double);
|
||||
double gimp_matrix_determinant (GimpMatrix);
|
||||
void gimp_matrix_invert (GimpMatrix m, GimpMatrix m_inv);
|
||||
void gimp_matrix_duplicate (GimpMatrix src, GimpMatrix target);
|
||||
int gimp_matrix_is_diagonal (GimpMatrix m);
|
||||
int gimp_matrix_is_identity (GimpMatrix m);
|
||||
int gimp_matrix_is_simple (GimpMatrix m);
|
||||
void gimp_matrix_transform_point (GimpMatrix matrix,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
gdouble *newx,
|
||||
gdouble *newy);
|
||||
void gimp_matrix_mult (GimpMatrix matrix1,
|
||||
GimpMatrix matrix2);
|
||||
void gimp_matrix_identity (GimpMatrix matrix);
|
||||
void gimp_matrix_translate (GimpMatrix matrix,
|
||||
gdouble x,
|
||||
gdouble y);
|
||||
void gimp_matrix_scale (GimpMatrix matrix,
|
||||
gdouble x,
|
||||
gdouble y);
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue