diff options
author | Jason Sams <jsams@google.com> | 2012-09-07 15:38:24 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-09-07 15:38:25 -0700 |
commit | 3f7bbe8cd37aba1be1a80222270057d78a032b54 (patch) | |
tree | 6c0ad05b6e1426c5f2d5706a0dbbc85bc8624576 /graphics | |
parent | 5fc626639aa7ff2aed224b58891149e19fb24b57 (diff) | |
parent | 8fd5853c1c07c2fd3954b3c5e64702d70af31144 (diff) | |
download | frameworks_base-3f7bbe8cd37aba1be1a80222270057d78a032b54.zip frameworks_base-3f7bbe8cd37aba1be1a80222270057d78a032b54.tar.gz frameworks_base-3f7bbe8cd37aba1be1a80222270057d78a032b54.tar.bz2 |
Merge "Document ColorMatrix intrinsic and add helpers" into jb-mr1-dev
Diffstat (limited to 'graphics')
3 files changed, 118 insertions, 6 deletions
diff --git a/graphics/java/android/renderscript/Matrix4f.java b/graphics/java/android/renderscript/Matrix4f.java index a85d464..4600424 100644 --- a/graphics/java/android/renderscript/Matrix4f.java +++ b/graphics/java/android/renderscript/Matrix4f.java @@ -113,6 +113,34 @@ public class Matrix4f { } /** + * Sets the values of the matrix to those of the parameter + * + * @param src matrix to load the values from + * @hide + */ + public void load(Matrix3f src) { + mMat[0] = src.mMat[0]; + mMat[1] = src.mMat[1]; + mMat[2] = src.mMat[2]; + mMat[3] = 0; + + mMat[4] = src.mMat[3]; + mMat[5] = src.mMat[4]; + mMat[6] = src.mMat[5]; + mMat[7] = 0; + + mMat[8] = src.mMat[6]; + mMat[9] = src.mMat[7]; + mMat[10] = src.mMat[8]; + mMat[11] = 0; + + mMat[12] = 0; + mMat[13] = 0; + mMat[14] = 0; + mMat[15] = 1; + } + + /** * Sets current values to be a rotation matrix of certain angle * about a given axis * diff --git a/graphics/java/android/renderscript/ScriptIntrinsicColorMatrix.java b/graphics/java/android/renderscript/ScriptIntrinsicColorMatrix.java index 41e7e00..dce1939 100644 --- a/graphics/java/android/renderscript/ScriptIntrinsicColorMatrix.java +++ b/graphics/java/android/renderscript/ScriptIntrinsicColorMatrix.java @@ -39,8 +39,7 @@ public class ScriptIntrinsicColorMatrix extends ScriptIntrinsic { } /** - * Supported elements types are float, float4, uchar, uchar4 - * + * Supported elements types are uchar4 * * @param rs * @param e @@ -53,13 +52,98 @@ public class ScriptIntrinsicColorMatrix extends ScriptIntrinsic { } - public void setColorMatrix(Matrix4f m) { - mMatrix.load(m); + private void setMatrix() { FieldPacker fp = new FieldPacker(16*4); - fp.addMatrix(m); + fp.addMatrix(mMatrix); setVar(0, fp); } + /** + * Set the color matrix which will be applied to each cell of the image. + * + * @param m The 4x4 matrix to set. + */ + public void setColorMatrix(Matrix4f m) { + mMatrix.load(m); + setMatrix(); + } + + /** + * Set the color matrix which will be applied to each cell of the image. + * This will set the alpha channel to be a copy. + * + * @param m The 3x3 matrix to set. + */ + public void setColorMatrix(Matrix3f m) { + mMatrix.load(m); + setMatrix(); + } + + /** + * Set a color matrix to convert from RGB to luminace. The alpha channel + * will be a copy. + * + */ + public void setGreyscale() { + mMatrix.loadIdentity(); + mMatrix.set(0, 0, 0.299f); + mMatrix.set(1, 0, 0.587f); + mMatrix.set(2, 0, 0.114f); + mMatrix.set(0, 1, 0.299f); + mMatrix.set(1, 1, 0.587f); + mMatrix.set(2, 1, 0.114f); + mMatrix.set(0, 2, 0.299f); + mMatrix.set(1, 2, 0.587f); + mMatrix.set(2, 2, 0.114f); + setMatrix(); + } + + /** + * Set the matrix to convert from YUV to RGB with a direct copy of the 4th + * channel. + * + */ + public void setYUVtoRGB() { + mMatrix.loadIdentity(); + mMatrix.set(0, 0, 1.f); + mMatrix.set(1, 0, 0.f); + mMatrix.set(2, 0, 1.13983f); + mMatrix.set(0, 1, 1.f); + mMatrix.set(1, 1, -0.39465f); + mMatrix.set(2, 1, -0.5806f); + mMatrix.set(0, 2, 1.f); + mMatrix.set(1, 2, 2.03211f); + mMatrix.set(2, 2, 0.f); + setMatrix(); + } + + /** + * Set the matrix to convert from RGB to YUV with a direct copy of the 4th + * channel. + * + */ + public void setRGBtoYUV() { + mMatrix.loadIdentity(); + mMatrix.set(0, 0, 0.299f); + mMatrix.set(1, 0, 0.587f); + mMatrix.set(2, 0, 0.114f); + mMatrix.set(0, 1, -0.14713f); + mMatrix.set(1, 1, -0.28886f); + mMatrix.set(2, 1, 0.436f); + mMatrix.set(0, 2, 0.615f); + mMatrix.set(1, 2, -0.51499f); + mMatrix.set(2, 2, -0.10001f); + setMatrix(); + } + + + /** + * Invoke the kernel and apply the matrix to each cell of ain and copy to + * aout. + * + * @param ain Input allocation + * @param aout Output allocation + */ public void forEach(Allocation ain, Allocation aout) { forEach(0, ain, aout, null); } diff --git a/graphics/java/android/renderscript/ScriptIntrinsicYuvToRGB.java b/graphics/java/android/renderscript/ScriptIntrinsicYuvToRGB.java index ee5f938..b4a228b 100644 --- a/graphics/java/android/renderscript/ScriptIntrinsicYuvToRGB.java +++ b/graphics/java/android/renderscript/ScriptIntrinsicYuvToRGB.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 The Android Open Source Project + * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. |