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()booleaninthashCode()voidpostConcat(float[] rhs) voidpostConcat(@NonNull ColorMatrix rhs) Post-multiply this matrix by the givenrhsmatrix.voidpreConcat(float[] lhs) voidpreConcat(@NonNull ColorMatrix lhs) Pre-multiply this matrix by the givenlhsmatrix.voidset(float[] src) Set the values in the matrix using a float array that contains the matrix elements in row-major order.voidset(float[] src, int offset) Set the values in the matrix using a float array that contains the matrix elements in row-major order.voidset(@NonNull ColorMatrix src) Store the values of the given matrix into this matrix.voidset(@NonNull ByteBuffer src) Set the values in the matrix using a float array that contains the matrix elements in row-major order.voidset(@NonNull FloatBuffer src) Set the values in the matrix using a float array that contains the matrix elements in row-major order.voidsetConcat(float[] lhs, float[] rhs) voidsetConcat(@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 applyinglhsfirst and then applyingrhs.voidReset this matrix to the identity.voidsetRotateB(float angle) Set the rotation around the blue color axis by the specified radians.voidsetRotateG(float angle) Set the rotation around the green color axis by the specified radians.voidsetRotateR(float angle) Set the rotation around the red color axis by the specified radians.voidsetSaturation(float sat) Set the matrix to affect the saturation of colors.voidsetScale(float scaleR, float scaleG, float scaleB, float scaleA) Set this matrix to scale by the specified values.voidsetTranslate(float transR, float transG, float transB, float transA) voidstore(float[] dst) Store this matrix into the give float array in row-major order.voidstore(float[] dst, int offset) Store this matrix into the give float array in row-major order.voidstore(@NonNull ColorMatrix dst) Store this matrix elements to the given matrix.voidstore(@NonNull ByteBuffer dst) Store this matrix into the give float array in row-major order.voidstore(@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 givenlhsmatrix.If
Misthismatrix andLthelhsmatrix, then the new matrix will beL * M(row-major). So when transforming a vectorvwith 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 givenrhsmatrix.If
Misthismatrix andRtherhsmatrix, then the new matrix will beM * R(row-major). So when transforming a vectorvwith the new matrix by usingv * M * R, the transformation ofthismatrix 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 applyinglhsfirst and then applyingrhs.It is legal for either
lhsorrhsto 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
-