Merge "Improve ColorMatrix docs" into lmp-mr1-dev
This commit is contained in:
@@ -21,23 +21,43 @@ import android.util.FloatMath;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 4x5 matrix for transforming the color+alpha components of a Bitmap.
|
* 4x5 matrix for transforming the color and alpha components of a Bitmap.
|
||||||
* The matrix is stored in a single array, and its treated as follows:
|
* The matrix can be passed as single array, and is treated as follows:
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* [ a, b, c, d, e,
|
* [ a, b, c, d, e,
|
||||||
* f, g, h, i, j,
|
* f, g, h, i, j,
|
||||||
* k, l, m, n, o,
|
* k, l, m, n, o,
|
||||||
* p, q, r, s, t ]
|
* p, q, r, s, t ]</pre>
|
||||||
* </pre>
|
*
|
||||||
|
* <p>
|
||||||
|
* When applied to a color <code>[R, G, B, A]</code>, the resulting color
|
||||||
|
* is computed as:
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* When applied to a color <code>[r, g, b, a]</code>, the resulting color
|
|
||||||
* is computed as (after clamping):
|
|
||||||
* <pre>
|
* <pre>
|
||||||
* R' = a*R + b*G + c*B + d*A + e;
|
* R’ = a*R + b*G + c*B + d*A + e;
|
||||||
* G' = f*R + g*G + h*B + i*A + j;
|
* G’ = f*R + g*G + h*B + i*A + j;
|
||||||
* B' = k*R + l*G + m*B + n*A + o;
|
* B’ = k*R + l*G + m*B + n*A + o;
|
||||||
* A' = p*R + q*G + r*B + s*A + t;
|
* A’ = p*R + q*G + r*B + s*A + t;</pre>
|
||||||
* </pre>
|
*
|
||||||
|
* <p>
|
||||||
|
* That resulting color <code>[R’, G’, B’, A’]</code>
|
||||||
|
* then has each channel clamped to the <code>0</code> to <code>255</code>
|
||||||
|
* range.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The sample ColorMatrix below inverts incoming colors by scaling each
|
||||||
|
* channel by <code>-1</code>, and then shifting the result up by
|
||||||
|
* <code>255</code> to remain in the standard color space.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* [ -1, 0, 0, 0, 255,
|
||||||
|
* 0, -1, 0, 0, 255,
|
||||||
|
* 0, 0, -1, 0, 255,
|
||||||
|
* 0, 0, 0, 1, 0 ]</pre>
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "MismatchedReadAndWriteOfArray", "PointlessArithmeticExpression" })
|
@SuppressWarnings({ "MismatchedReadAndWriteOfArray", "PointlessArithmeticExpression" })
|
||||||
public class ColorMatrix {
|
public class ColorMatrix {
|
||||||
@@ -117,9 +137,11 @@ public class ColorMatrix {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the rotation on a color axis by the specified values.
|
* Set the rotation on a color axis by the specified values.
|
||||||
|
* <p>
|
||||||
* <code>axis=0</code> correspond to a rotation around the RED color
|
* <code>axis=0</code> correspond to a rotation around the RED color
|
||||||
* <code>axis=1</code> correspond to a rotation around the GREEN color
|
* <code>axis=1</code> correspond to a rotation around the GREEN color
|
||||||
* <code>axis=2</code> correspond to a rotation around the BLUE color
|
* <code>axis=2</code> correspond to a rotation around the BLUE color
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
public void setRotate(int axis, float degrees) {
|
public void setRotate(int axis, float degrees) {
|
||||||
reset();
|
reset();
|
||||||
@@ -153,8 +175,10 @@ public class ColorMatrix {
|
|||||||
/**
|
/**
|
||||||
* Set this colormatrix to the concatenation of the two specified
|
* Set this colormatrix to the concatenation of the two specified
|
||||||
* colormatrices, such that the resulting colormatrix has the same effect
|
* colormatrices, such that the resulting colormatrix has the same effect
|
||||||
* as applying matB and then applying matA. It is legal for either matA or
|
* as applying matB and then applying matA.
|
||||||
* matB to be the same colormatrix as this.
|
* <p>
|
||||||
|
* It is legal for either matA or matB to be the same colormatrix as this.
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
public void setConcat(ColorMatrix matA, ColorMatrix matB) {
|
public void setConcat(ColorMatrix matA, ColorMatrix matB) {
|
||||||
float[] tmp;
|
float[] tmp;
|
||||||
@@ -183,16 +207,20 @@ public class ColorMatrix {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Concat this colormatrix with the specified prematrix. This is logically
|
* Concat this colormatrix with the specified prematrix.
|
||||||
* the same as calling setConcat(this, prematrix);
|
* <p>
|
||||||
|
* This is logically the same as calling setConcat(this, prematrix);
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
public void preConcat(ColorMatrix prematrix) {
|
public void preConcat(ColorMatrix prematrix) {
|
||||||
setConcat(this, prematrix);
|
setConcat(this, prematrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Concat this colormatrix with the specified postmatrix. This is logically
|
* Concat this colormatrix with the specified postmatrix.
|
||||||
* the same as calling setConcat(postmatrix, this);
|
* <p>
|
||||||
|
* This is logically the same as calling setConcat(postmatrix, this);
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
public void postConcat(ColorMatrix postmatrix) {
|
public void postConcat(ColorMatrix postmatrix) {
|
||||||
setConcat(postmatrix, this);
|
setConcat(postmatrix, this);
|
||||||
@@ -201,8 +229,9 @@ public class ColorMatrix {
|
|||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the matrix to affect the saturation of colors. A value of 0 maps the
|
* Set the matrix to affect the saturation of colors.
|
||||||
* color to gray-scale. 1 is identity.
|
*
|
||||||
|
* @param sat A value of 0 maps the color to gray-scale. 1 is identity.
|
||||||
*/
|
*/
|
||||||
public void setSaturation(float sat) {
|
public void setSaturation(float sat) {
|
||||||
reset();
|
reset();
|
||||||
@@ -242,4 +271,3 @@ public class ColorMatrix {
|
|||||||
m[10] = 1; m[11] = 1.772f; m[12] = 0;
|
m[10] = 1; m[11] = 1.772f; m[12] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user