Loading graphics/java/android/graphics/ColorMatrix.java +61 −33 Original line number Diff line number Diff line Loading @@ -19,23 +19,43 @@ package android.graphics; import java.util.Arrays; /** * 4x5 matrix for transforming the color+alpha components of a Bitmap. * The matrix is stored in a single array, and its treated as follows: * 4x5 matrix for transforming the color and alpha components of a Bitmap. * The matrix can be passed as single array, and is treated as follows: * * <pre> * [ a, b, c, d, e, * f, g, h, i, j, * k, l, m, n, o, * p, q, r, s, t ] * </pre> * p, q, r, s, t ]</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> * R' = a*R + b*G + c*B + d*A + e; * G' = f*R + g*G + h*B + i*A + j; * B' = k*R + l*G + m*B + n*A + o; * A' = p*R + q*G + r*B + s*A + t; * </pre> * R’ = a*R + b*G + c*B + d*A + e; * G’ = f*R + g*G + h*B + i*A + j; * B’ = k*R + l*G + m*B + n*A + o; * A’ = p*R + q*G + r*B + s*A + t;</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" }) public class ColorMatrix { Loading Loading @@ -115,9 +135,11 @@ public class ColorMatrix { /** * 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=1</code> correspond to a rotation around the GREEN color * <code>axis=2</code> correspond to a rotation around the BLUE color * </p> */ public void setRotate(int axis, float degrees) { reset(); Loading Loading @@ -151,8 +173,10 @@ public class ColorMatrix { /** * Set this colormatrix to the concatenation of the two specified * colormatrices, such that the resulting colormatrix has the same effect * as applying matB and then applying matA. It is legal for either matA or * matB to be the same colormatrix as this. * as applying matB and then applying matA. * <p> * It is legal for either matA or matB to be the same colormatrix as this. * </p> */ public void setConcat(ColorMatrix matA, ColorMatrix matB) { float[] tmp; Loading Loading @@ -181,16 +205,20 @@ public class ColorMatrix { } /** * Concat this colormatrix with the specified prematrix. This is logically * the same as calling setConcat(this, prematrix); * Concat this colormatrix with the specified prematrix. * <p> * This is logically the same as calling setConcat(this, prematrix); * </p> */ public void preConcat(ColorMatrix prematrix) { setConcat(this, prematrix); } /** * Concat this colormatrix with the specified postmatrix. This is logically * the same as calling setConcat(postmatrix, this); * Concat this colormatrix with the specified postmatrix. * <p> * This is logically the same as calling setConcat(postmatrix, this); * </p> */ public void postConcat(ColorMatrix postmatrix) { setConcat(postmatrix, this); Loading @@ -199,8 +227,9 @@ public class ColorMatrix { /////////////////////////////////////////////////////////////////////////// /** * Set the matrix to affect the saturation of colors. A value of 0 maps the * color to gray-scale. 1 is identity. * Set the matrix to affect the saturation of colors. * * @param sat A value of 0 maps the color to gray-scale. 1 is identity. */ public void setSaturation(float sat) { reset(); Loading Loading @@ -240,4 +269,3 @@ public class ColorMatrix { m[10] = 1; m[11] = 1.772f; m[12] = 0; } } Loading
graphics/java/android/graphics/ColorMatrix.java +61 −33 Original line number Diff line number Diff line Loading @@ -19,23 +19,43 @@ package android.graphics; import java.util.Arrays; /** * 4x5 matrix for transforming the color+alpha components of a Bitmap. * The matrix is stored in a single array, and its treated as follows: * 4x5 matrix for transforming the color and alpha components of a Bitmap. * The matrix can be passed as single array, and is treated as follows: * * <pre> * [ a, b, c, d, e, * f, g, h, i, j, * k, l, m, n, o, * p, q, r, s, t ] * </pre> * p, q, r, s, t ]</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> * R' = a*R + b*G + c*B + d*A + e; * G' = f*R + g*G + h*B + i*A + j; * B' = k*R + l*G + m*B + n*A + o; * A' = p*R + q*G + r*B + s*A + t; * </pre> * R’ = a*R + b*G + c*B + d*A + e; * G’ = f*R + g*G + h*B + i*A + j; * B’ = k*R + l*G + m*B + n*A + o; * A’ = p*R + q*G + r*B + s*A + t;</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" }) public class ColorMatrix { Loading Loading @@ -115,9 +135,11 @@ public class ColorMatrix { /** * 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=1</code> correspond to a rotation around the GREEN color * <code>axis=2</code> correspond to a rotation around the BLUE color * </p> */ public void setRotate(int axis, float degrees) { reset(); Loading Loading @@ -151,8 +173,10 @@ public class ColorMatrix { /** * Set this colormatrix to the concatenation of the two specified * colormatrices, such that the resulting colormatrix has the same effect * as applying matB and then applying matA. It is legal for either matA or * matB to be the same colormatrix as this. * as applying matB and then applying matA. * <p> * It is legal for either matA or matB to be the same colormatrix as this. * </p> */ public void setConcat(ColorMatrix matA, ColorMatrix matB) { float[] tmp; Loading Loading @@ -181,16 +205,20 @@ public class ColorMatrix { } /** * Concat this colormatrix with the specified prematrix. This is logically * the same as calling setConcat(this, prematrix); * Concat this colormatrix with the specified prematrix. * <p> * This is logically the same as calling setConcat(this, prematrix); * </p> */ public void preConcat(ColorMatrix prematrix) { setConcat(this, prematrix); } /** * Concat this colormatrix with the specified postmatrix. This is logically * the same as calling setConcat(postmatrix, this); * Concat this colormatrix with the specified postmatrix. * <p> * This is logically the same as calling setConcat(postmatrix, this); * </p> */ public void postConcat(ColorMatrix postmatrix) { setConcat(postmatrix, this); Loading @@ -199,8 +227,9 @@ public class ColorMatrix { /////////////////////////////////////////////////////////////////////////// /** * Set the matrix to affect the saturation of colors. A value of 0 maps the * color to gray-scale. 1 is identity. * Set the matrix to affect the saturation of colors. * * @param sat A value of 0 maps the color to gray-scale. 1 is identity. */ public void setSaturation(float sat) { reset(); Loading Loading @@ -240,4 +269,3 @@ public class ColorMatrix { m[10] = 1; m[11] = 1.772f; m[12] = 0; } }