Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5b41215b authored by Chris Craik's avatar Chris Craik Committed by Android Git Automerger
Browse files

am 93ef9639: Merge "Improve ColorMatrix docs" into lmp-mr1-dev

* commit '93ef9639':
  Improve ColorMatrix docs
parents 62a7d533 93ef9639
Loading
Loading
Loading
Loading
+61 −33
Original line number Diff line number Diff line
@@ -21,23 +21,43 @@ import android.util.FloatMath;
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&rsquo; = a*R + b*G + c*B + d*A + e;
 *   G&rsquo; = f*R + g*G + h*B + i*A + j;
 *   B&rsquo; = k*R + l*G + m*B + n*A + o;
 *   A&rsquo; = p*R + q*G + r*B + s*A + t;</pre>
 *
 * <p>
 * That resulting color <code>[R&rsquo;, G&rsquo;, B&rsquo;, A&rsquo;]</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 {
@@ -117,9 +137,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();
@@ -153,8 +175,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;
@@ -183,16 +207,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);
@@ -201,8 +229,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();
@@ -242,4 +271,3 @@ public class ColorMatrix {
        m[10] = 1;  m[11] = 1.772f;     m[12] = 0;
    }
}