diff options
Diffstat (limited to 'graphics')
6 files changed, 278 insertions, 50 deletions
diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java index 1721bee..ea53f20 100644 --- a/graphics/java/android/graphics/BitmapFactory.java +++ b/graphics/java/android/graphics/BitmapFactory.java @@ -271,17 +271,22 @@ public class BitmapFactory { public boolean inPreferQualityOverSpeed; /** - * The resulting width of the bitmap, set independent of the state of - * inJustDecodeBounds. However, if there is an error trying to decode, - * outWidth will be set to -1. + * The resulting width of the bitmap. If {@link #inJustDecodeBounds} is + * set to false, this will be width of the output bitmap after any + * scaling is applied. If true, it will be the width of the input image + * without any accounting for scaling. + * + * <p>outWidth will be set to -1 if there is an error trying to decode.</p> */ - public int outWidth; /** - * The resulting height of the bitmap, set independent of the state of - * inJustDecodeBounds. However, if there is an error trying to decode, - * outHeight will be set to -1. + * The resulting height of the bitmap. If {@link #inJustDecodeBounds} is + * set to false, this will be height of the output bitmap after any + * scaling is applied. If true, it will be the height of the input image + * without any accounting for scaling. + * + * <p>outHeight will be set to -1 if there is an error trying to decode.</p> */ public int outHeight; diff --git a/graphics/java/android/graphics/ColorFilter.java b/graphics/java/android/graphics/ColorFilter.java index e5cf830..8e0af77 100644 --- a/graphics/java/android/graphics/ColorFilter.java +++ b/graphics/java/android/graphics/ColorFilter.java @@ -21,22 +21,30 @@ package android.graphics; - +/** + * A color filter can be used with a {@link Paint} to modify the color of + * each pixel drawn with that paint. This is an abstract class that should + * never be used directly. + */ public class ColorFilter { + // Holds the pointer to the native SkColorFilter instance int native_instance; /** + * Holds the pointer to the native SkiaColorFilter instance, from libhwui. + * * @hide */ public int nativeColorFilter; + @Override protected void finalize() throws Throwable { try { super.finalize(); } finally { - finalizer(native_instance, nativeColorFilter); + destroyFilter(native_instance, nativeColorFilter); } } - private static native void finalizer(int native_instance, int nativeColorFilter); + static native void destroyFilter(int native_instance, int nativeColorFilter); } diff --git a/graphics/java/android/graphics/ColorMatrix.java b/graphics/java/android/graphics/ColorMatrix.java index c22cda1..0ef037d 100644 --- a/graphics/java/android/graphics/ColorMatrix.java +++ b/graphics/java/android/graphics/ColorMatrix.java @@ -18,23 +18,29 @@ package android.graphics; import android.util.FloatMath; +import java.util.Arrays; + /** - * 5x4 matrix for transforming the color+alpha components of a Bitmap. - * The matrix is stored in a single array, and its treated as follows: + * 5x4 matrix for transforming the color+alpha components of a Bitmap. + * The matrix is stored in a single array, and its 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> * - * When applied to a color [r, g, b, a], the resulting color is computed as - * (after clamping) + * 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> */ +@SuppressWarnings({ "MismatchedReadAndWriteOfArray", "PointlessArithmeticExpression" }) public class ColorMatrix { - private final float[] mArray = new float[20]; /** @@ -66,17 +72,16 @@ public class ColorMatrix { /** * Set this colormatrix to identity: + * <pre> * [ 1 0 0 0 0 - red vector * 0 1 0 0 0 - green vector * 0 0 1 0 0 - blue vector * 0 0 0 1 0 ] - alpha vector + * </pre> */ public void reset() { final float[] a = mArray; - - for (int i = 19; i > 0; --i) { - a[i] = 0; - } + Arrays.fill(a, 0); a[0] = a[6] = a[12] = a[18] = 1; } @@ -112,9 +117,9 @@ public class ColorMatrix { /** * Set the rotation on a color axis by the specified values. - * axis=0 correspond to a rotation around the RED color - * axis=1 correspond to a rotation around the GREEN color - * axis=2 correspond to a rotation around the BLUE 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=2</code> correspond to a rotation around the BLUE color */ public void setRotate(int axis, float degrees) { reset(); @@ -144,7 +149,7 @@ public class ColorMatrix { throw new RuntimeException(); } } - + /** * Set this colormatrix to the concatenation of the two specified * colormatrices, such that the resulting colormatrix has the same effect @@ -152,12 +157,10 @@ public class ColorMatrix { * matB to be the same colormatrix as this. */ public void setConcat(ColorMatrix matA, ColorMatrix matB) { - float[] tmp = null; - + float[] tmp; if (matA == this || matB == this) { tmp = new float[20]; - } - else { + } else { tmp = mArray; } @@ -178,7 +181,7 @@ public class ColorMatrix { System.arraycopy(tmp, 0, mArray, 0, 20); } } - + /** * Concat this colormatrix with the specified prematrix. This is logically * the same as calling setConcat(this, prematrix); @@ -186,7 +189,7 @@ public class ColorMatrix { 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); @@ -194,7 +197,7 @@ public class ColorMatrix { public void postConcat(ColorMatrix postmatrix) { setConcat(postmatrix, this); } - + /////////////////////////////////////////////////////////////////////////// /** diff --git a/graphics/java/android/graphics/ColorMatrixColorFilter.java b/graphics/java/android/graphics/ColorMatrixColorFilter.java index 4f32342..8de32ec 100644 --- a/graphics/java/android/graphics/ColorMatrixColorFilter.java +++ b/graphics/java/android/graphics/ColorMatrixColorFilter.java @@ -16,24 +16,31 @@ package android.graphics; +/** + * A color filter that transforms colors through a 4x5 color matrix. This filter + * can be used to change the saturation of pixels, convert from YUV to RGB, etc. + * + * @see ColorMatrix + */ public class ColorMatrixColorFilter extends ColorFilter { + private final ColorMatrix mMatrix = new ColorMatrix(); + /** - * Create a colorfilter that transforms colors through a 4x5 color matrix. + * Create a color filter that transforms colors through a 4x5 color matrix. * * @param matrix 4x5 matrix used to transform colors. It is copied into * the filter, so changes made to the matrix after the filter * is constructed will not be reflected in the filter. */ public ColorMatrixColorFilter(ColorMatrix matrix) { - final float[] colorMatrix = matrix.getArray(); - native_instance = nativeColorMatrixFilter(colorMatrix); - nativeColorFilter = nColorMatrixFilter(native_instance, colorMatrix); + mMatrix.set(matrix); + update(); } /** - * Create a colorfilter that transforms colors through a 4x5 color matrix. + * Create a color filter that transforms colors through a 4x5 color matrix. * - * @param array array of floats used to transform colors, treated as a 4x5 + * @param array Array of floats used to transform colors, treated as a 4x5 * matrix. The first 20 entries of the array are copied into * the filter. See ColorMatrix. */ @@ -41,8 +48,75 @@ public class ColorMatrixColorFilter extends ColorFilter { if (array.length < 20) { throw new ArrayIndexOutOfBoundsException(); } - native_instance = nativeColorMatrixFilter(array); - nativeColorFilter = nColorMatrixFilter(native_instance, array); + mMatrix.set(array); + update(); + } + + /** + * Returns the {@link ColorMatrix} used by this filter. The returned + * value is never null. Modifying the returned matrix does not have + * any effect until you call {@link #setColorMatrix(ColorMatrix)}. + * + * @see #setColorMatrix(ColorMatrix) + */ + public ColorMatrix getColorMatrix() { + return mMatrix; + } + + /** + * Specifies the color matrix used by this filter. If the specified + * color matrix is null, this filter's color matrix will be reset to + * the identity matrix. + * + * @param matrix A {@link ColorMatrix} or null + * + * @see #getColorMatrix() + * @see android.graphics.ColorMatrix#reset() + * @see #setColorMatrix(float[]) + */ + public void setColorMatrix(ColorMatrix matrix) { + if (matrix == null) { + mMatrix.reset(); + } else if (matrix != mMatrix) { + mMatrix.set(matrix); + } + update(); + } + + /** + * Specifies the color matrix used by this filter. If the specified + * color matrix is null, this filter's color matrix will be reset to + * the identity matrix. + * + * @param array Array of floats used to transform colors, treated as a 4x5 + * matrix. The first 20 entries of the array are copied into + * the filter. See {@link ColorMatrix}. + * + * @see #getColorMatrix() + * @see android.graphics.ColorMatrix#reset() + * @see #setColorMatrix(ColorMatrix) + * + * @throws ArrayIndexOutOfBoundsException if the specified array's + * length is < 20 + */ + public void setColorMatrix(float[] array) { + if (array == null) { + mMatrix.reset(); + } else { + if (array.length < 20) { + throw new ArrayIndexOutOfBoundsException(); + } + + mMatrix.set(array); + } + update(); + } + + private void update() { + final float[] colorMatrix = mMatrix.getArray(); + destroyFilter(native_instance, nativeColorFilter); + native_instance = nativeColorMatrixFilter(colorMatrix); + nativeColorFilter = nColorMatrixFilter(native_instance, colorMatrix); } private static native int nativeColorMatrixFilter(float[] array); diff --git a/graphics/java/android/graphics/LightingColorFilter.java b/graphics/java/android/graphics/LightingColorFilter.java index c621de6..75f1827 100644 --- a/graphics/java/android/graphics/LightingColorFilter.java +++ b/graphics/java/android/graphics/LightingColorFilter.java @@ -21,16 +21,87 @@ package android.graphics; +/** + * A color filter that can be used to simulate simple lighting effects. + * A <code>LightingColorFilter</code> is defined by two parameters, one + * used to multiply the source color (called <code>colorMultiply</code>) + * and one used to add to the source color (called <code>colorAdd</code>). + * The alpha channel is left untouched by this color filter. + * + * Given a source color RGB, the resulting R'G'B' color is computed thusly: + * <pre> + * R' = R * colorMultiply.R + colorAdd.R + * G' = G * colorMultiply.G + colorAdd.G + * B' = B * colorMultiply.B + colorAdd.B + * </pre> + * The result is pinned to the <code>[0..255]</code> range for each channel. + */ public class LightingColorFilter extends ColorFilter { + private int mMul; + private int mAdd; /** - * Create a colorfilter that multiplies the RGB channels by one color, and then adds a second color, - * pinning the result for each component to [0..255]. The alpha components of the mul and add arguments - * are ignored. + * Create a colorfilter that multiplies the RGB channels by one color, + * and then adds a second color. The alpha components of the mul and add + * arguments are ignored. + * + * @see #setColorMultiply(int) + * @see #setColorAdd(int) */ public LightingColorFilter(int mul, int add) { - native_instance = native_CreateLightingFilter(mul, add); - nativeColorFilter = nCreateLightingFilter(native_instance, mul, add); + mMul = mul; + mAdd = add; + update(); + } + + /** + * Returns the RGB color used to multiply the source color when the + * color filter is applied. + * + * @see #setColorMultiply(int) + */ + public int getColorMultiply() { + return mMul; + } + + /** + * Specifies the RGB color used to multiply the source color when the + * color filter is applied. + * The alpha channel of this color is ignored. + * + * @see #getColorMultiply() + */ + public void setColorMultiply(int mul) { + mMul = mul; + update(); + } + + /** + * Returns the RGB color that will be added to the source color + * when the color filter is applied. + * + * @see #setColorAdd(int) + */ + public int getColorAdd() { + return mAdd; + } + + /** + * Specifies the RGB that will be added to the source color when + * the color filter is applied. + * The alpha channel of this color is ignored. + * + * @see #getColorAdd() + */ + public void setColorAdd(int add) { + mAdd = add; + update(); + } + + private void update() { + destroyFilter(native_instance, nativeColorFilter); + native_instance = native_CreateLightingFilter(mMul, mAdd); + nativeColorFilter = nCreateLightingFilter(native_instance, mMul, mAdd); } private static native int native_CreateLightingFilter(int mul, int add); diff --git a/graphics/java/android/graphics/PorterDuffColorFilter.java b/graphics/java/android/graphics/PorterDuffColorFilter.java index ecc7c24..9870ad2 100644 --- a/graphics/java/android/graphics/PorterDuffColorFilter.java +++ b/graphics/java/android/graphics/PorterDuffColorFilter.java @@ -16,17 +16,84 @@ package android.graphics; +/** + * A color filter that can be used to tint the source pixels using a single + * color and a specific {@link PorterDuff Porter-Duff composite mode}. + */ public class PorterDuffColorFilter extends ColorFilter { + private int mColor; + private PorterDuff.Mode mMode; + + /** + * Create a color filter that uses the specified color and Porter-Duff mode. + * + * @param color The ARGB source color used with the specified Porter-Duff mode + * @param mode The porter-duff mode that is applied + * + * @see Color + * @see #setColor(int) + * @see #setMode(android.graphics.PorterDuff.Mode) + */ + public PorterDuffColorFilter(int color, PorterDuff.Mode mode) { + mColor = color; + mMode = mode; + update(); + } + + /** + * Returns the ARGB color used to tint the source pixels when this filter + * is applied. + * + * @see Color + * @see #setColor(int) + */ + public int getColor() { + return mColor; + } + /** - * Create a colorfilter that uses the specified color and porter-duff mode. + * Specifies the color to tint the source pixels with when this color + * filter is applied. * - * @param srcColor The source color used with the specified - * porter-duff mode - * @param mode The porter-duff mode that is applied + * @param color An ARGB {@link Color color} + * + * @see Color + * @see #getColor() + * @see #getMode() */ - public PorterDuffColorFilter(int srcColor, PorterDuff.Mode mode) { - native_instance = native_CreatePorterDuffFilter(srcColor, mode.nativeInt); - nativeColorFilter = nCreatePorterDuffFilter(native_instance, srcColor, mode.nativeInt); + public void setColor(int color) { + mColor = color; + update(); + } + + /** + * Returns the Porter-Duff mode used to composite this color filter's + * color with the source pixel when this filter is applied. + * + * @see PorterDuff + * @see #setMode(android.graphics.PorterDuff.Mode) + */ + public PorterDuff.Mode getMode() { + return mMode; + } + + /** + * Specifies the Porter-Duff mode to use when compositing this color + * filter's color with the source pixel at draw time. + * + * @see PorterDuff + * @see #getMode() + * @see #getColor() + */ + public void setMode(PorterDuff.Mode mode) { + mMode = mode; + update(); + } + + private void update() { + destroyFilter(native_instance, nativeColorFilter); + native_instance = native_CreatePorterDuffFilter(mColor, mMode.nativeInt); + nativeColorFilter = nCreatePorterDuffFilter(native_instance, mColor, mMode.nativeInt); } private static native int native_CreatePorterDuffFilter(int srcColor, int porterDuffMode); |