Class ColorMatrix
newColor = m * color + v;
The matrix can be passed as single array, and is treated as follows:
[ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t ]
When applied to a color [R, G, B, A]
, the resulting color
is computed as:
R’ = a*R + e*G + i*B + m*A + q; G’ = b*R + f*G + j*B + n*A + r; B’ = c*R + g*G + k*B + o*A + s; A’ = d*R + h*G + l*B + p*A + t;
That resulting color [R’, G’, B’, A’]
then has each channel clamped to the 0.0
to 1.0
range.
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an identity matrix.ColorMatrix
(float... src) Create a matrix from an array of elements in row-major.ColorMatrix
(@NonNull ColorMatrix src) Create a matrix copied from an existing matrix. -
Method Summary
Modifier and TypeMethodDescriptionfloat[]
elements()
boolean
int
hashCode()
void
postConcat
(float[] rhs) void
postConcat
(@NonNull ColorMatrix rhs) Post-multiply this matrix by the givenrhs
matrix.void
preConcat
(float[] lhs) void
preConcat
(@NonNull ColorMatrix lhs) Pre-multiply this matrix by the givenlhs
matrix.void
set
(float[] src) Set the values in the matrix using a float array that contains the matrix elements in row-major order.void
set
(float[] src, int offset) Set the values in the matrix using a float array that contains the matrix elements in row-major order.void
set
(@NonNull ColorMatrix src) Store the values of the given matrix into this matrix.void
set
(@NonNull ByteBuffer src) Set the values in the matrix using a float array that contains the matrix elements in row-major order.void
set
(@NonNull FloatBuffer src) Set the values in the matrix using a float array that contains the matrix elements in row-major order.void
setConcat
(float[] lhs, float[] rhs) void
setConcat
(@NonNull ColorMatrix lhs, @NonNull ColorMatrix rhs) Set this matrix to the concatenation of the two specified matrices, such that the resulting matrix has the same effect as applyinglhs
first and then applyingrhs
.void
Reset this matrix to the identity.void
setRotateB
(float angle) Set the rotation around the blue color axis by the specified radians.void
setRotateG
(float angle) Set the rotation around the green color axis by the specified radians.void
setRotateR
(float angle) Set the rotation around the red color axis by the specified radians.void
setSaturation
(float sat) Set the matrix to affect the saturation of colors.void
setScale
(float scaleR, float scaleG, float scaleB, float scaleA) Set this matrix to scale by the specified values.void
setTranslate
(float transR, float transG, float transB, float transA) void
store
(float[] dst) Store this matrix into the give float array in row-major order.void
store
(float[] dst, int offset) Store this matrix into the give float array in row-major order.void
store
(@NonNull ColorMatrix dst) Store this matrix elements to the given matrix.void
store
(@NonNull ByteBuffer dst) Store this matrix into the give float array in row-major order.void
store
(@NonNull FloatBuffer dst) Store this matrix into the give float array in row-major order.
-
Constructor Details
-
ColorMatrix
public ColorMatrix()Create an identity matrix. -
ColorMatrix
Create a matrix from an array of elements in row-major.- Parameters:
src
- the array to create from- See Also:
-
ColorMatrix
Create a matrix copied from an existing matrix.- Parameters:
src
- the matrix to create from
-
-
Method Details
-
setIdentity
public void setIdentity()Reset this matrix to the identity. -
set
Store the values of the given matrix into this matrix.- Parameters:
src
- the matrix to copy from
-
set
Set the values in the matrix using a float array that contains the matrix elements in row-major order.- Parameters:
src
- the array to copy from
-
set
Set the values in the matrix using a float array that contains the matrix elements in row-major order.- Parameters:
src
- the array to copy fromoffset
- the element offset
-
set
Set the values in the matrix using a float array that contains the matrix elements in row-major order.- Parameters:
src
- the array to copy from
-
set
Set the values in the matrix using a float array that contains the matrix elements in row-major order.- Parameters:
src
- the array to copy from
-
store
Store this matrix elements to the given matrix.- Parameters:
dst
- the matrix to store
-
store
Store this matrix into the give float array in row-major order.- Parameters:
dst
- the array to store into
-
store
Store this matrix into the give float array in row-major order.- Parameters:
dst
- the array to store intooffset
- the element offset
-
store
Store this matrix into the give float array in row-major order.- Parameters:
dst
- the pointer of the array to store
-
store
Store this matrix into the give float array in row-major order.- Parameters:
dst
- the pointer of the array to store
-
setScale
public void setScale(float scaleR, float scaleG, float scaleB, float scaleA) Set this matrix to scale by the specified values. -
setRotateR
public void setRotateR(float angle) Set the rotation around the red color axis by the specified radians.- Parameters:
angle
- the rotation angle in radians
-
setRotateG
public void setRotateG(float angle) Set the rotation around the green color axis by the specified radians.- Parameters:
angle
- the rotation angle in radians
-
setRotateB
public void setRotateB(float angle) Set the rotation around the blue color axis by the specified radians.- Parameters:
angle
- the rotation angle in radians
-
setTranslate
public void setTranslate(float transR, float transG, float transB, float transA) -
preConcat
-
preConcat
Pre-multiply this matrix by the givenlhs
matrix.If
M
isthis
matrix andL
thelhs
matrix, then the new matrix will beL * M
(row-major). So when transforming a vectorv
with the new matrix by usingv * L * M
, the transformation of the left-hand side matrix will be applied first.- Parameters:
lhs
- the left-hand side matrix to multiply
-
postConcat
-
postConcat
Post-multiply this matrix by the givenrhs
matrix.If
M
isthis
matrix andR
therhs
matrix, then the new matrix will beM * R
(row-major). So when transforming a vectorv
with the new matrix by usingv * M * R
, the transformation ofthis
matrix will be applied first.- Parameters:
rhs
- the right-hand side matrix to multiply
-
setConcat
-
setConcat
Set this matrix to the concatenation of the two specified matrices, such that the resulting matrix has the same effect as applyinglhs
first and then applyingrhs
.It is legal for either
lhs
orrhs
to be the same matrix asthis
. -
setSaturation
public void setSaturation(float sat) Set the matrix to affect the saturation of colors.- Parameters:
sat
- A value of 0 maps the color to gray-scale. 1 is identity.
-
elements
public float[] elements()- Returns:
- the backing array
-
hashCode
public int hashCode() -
equals
-