diff options
author | Tim Murray <timmurray@google.com> | 2014-01-13 11:47:53 -0800 |
---|---|---|
committer | Tim Murray <timmurray@google.com> | 2014-01-13 11:47:53 -0800 |
commit | 6f842ac8aa37dd855fbffdc09f5491bd85ab3c9a (patch) | |
tree | 9228f5d9e3f2f84b26c5921f288567abd799b54e /rs | |
parent | 291d64685dd05f76deaf210a75d2d06c153f4b39 (diff) | |
download | frameworks_base-6f842ac8aa37dd855fbffdc09f5491bd85ab3c9a.zip frameworks_base-6f842ac8aa37dd855fbffdc09f5491bd85ab3c9a.tar.gz frameworks_base-6f842ac8aa37dd855fbffdc09f5491bd85ab3c9a.tar.bz2 |
Add clipping for intrinsics.
Change-Id: Ic7e1da3c69aa3d5f990816178739120b6059e7a5
Diffstat (limited to 'rs')
8 files changed, 312 insertions, 26 deletions
diff --git a/rs/java/android/renderscript/ScriptIntrinsic3DLUT.java b/rs/java/android/renderscript/ScriptIntrinsic3DLUT.java index 33e64bd..ce149d9 100644 --- a/rs/java/android/renderscript/ScriptIntrinsic3DLUT.java +++ b/rs/java/android/renderscript/ScriptIntrinsic3DLUT.java @@ -84,10 +84,23 @@ public final class ScriptIntrinsic3DLUT extends ScriptIntrinsic { * @param aout Output allocation */ public void forEach(Allocation ain, Allocation aout) { - forEach(0, ain, aout, null); + forEach(ain, aout, null); } /** + * Invoke the kernel and apply the lookup to each cell of ain + * and copy to aout. + * + * @param ain Input allocation + * @param aout Output allocation + * @param opt Launch options for kernel + */ + public void forEach(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + forEach(0, ain, aout, null, opt); + } + + + /** * Get a KernelID for this intrinsic kernel. * * @return Script.KernelID The KernelID object. diff --git a/rs/java/android/renderscript/ScriptIntrinsicBlend.java b/rs/java/android/renderscript/ScriptIntrinsicBlend.java index 40f1a3e..d4038c2 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicBlend.java +++ b/rs/java/android/renderscript/ScriptIntrinsicBlend.java @@ -40,14 +40,14 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { } - private void blend(int id, Allocation ain, Allocation aout) { + private void blend(int id, Allocation ain, Allocation aout, Script.LaunchOptions opt) { if (!ain.getElement().isCompatible(Element.U8_4(mRS))) { throw new RSIllegalArgumentException("Input is not of expected format."); } if (!aout.getElement().isCompatible(Element.U8_4(mRS))) { throw new RSIllegalArgumentException("Output is not of expected format."); } - forEach(id, ain, aout, null); + forEach(id, ain, aout, null, opt); } /** @@ -57,7 +57,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachClear(Allocation ain, Allocation aout) { - blend(0, ain, aout); + forEachClear(ain, aout, null); + } + + /** + * Sets dst = {0, 0, 0, 0} + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachClear(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(0, ain, aout, opt); } /** @@ -77,7 +88,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachSrc(Allocation ain, Allocation aout) { - blend(1, ain, aout); + forEachSrc(ain, aout, null); + } + + /** + * Sets dst = src + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachSrc(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + forEachDst(ain, aout, null); } /** @@ -102,6 +124,19 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { } /** + * Sets dst = dst + * + * This is a NOP. + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachDst(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + // N, optOP + } + + /** * Get a KernelID for the Dst kernel. * * @return Script.KernelID The KernelID object. @@ -117,7 +152,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachSrcOver(Allocation ain, Allocation aout) { - blend(3, ain, aout); + forEachSrcOver(ain, aout, null); + } + + /** + * Sets dst = src + dst * (1.0 - src.a) + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachSrcOver(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(3, ain, aout, opt); } /** @@ -136,7 +182,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachDstOver(Allocation ain, Allocation aout) { - blend(4, ain, aout); + forEachDstOver(ain, aout, null); + } + + /** + * Sets dst = dst + src * (1.0 - dst.a) + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachDstOver(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(4, ain, aout, opt); } /** @@ -155,7 +212,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachSrcIn(Allocation ain, Allocation aout) { - blend(5, ain, aout); + forEachSrcIn(ain, aout, null); + } + + /** + * Sets dst = src * dst.a + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachSrcIn(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(5, ain, aout, opt); } /** @@ -174,7 +242,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachDstIn(Allocation ain, Allocation aout) { - blend(6, ain, aout); + forEachDstIn(ain, aout, null); + } + + /** + * Sets dst = dst * src.a + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachDstIn(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(6, ain, aout, opt); } /** @@ -193,7 +272,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachSrcOut(Allocation ain, Allocation aout) { - blend(7, ain, aout); + forEachSrcOut(ain, aout, null); + } + + /** + * Sets dst = src * (1.0 - dst.a) + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachSrcOut(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(7, ain, aout, opt); } /** @@ -212,7 +302,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachDstOut(Allocation ain, Allocation aout) { - blend(8, ain, aout); + forEachDstOut(ain, aout, null); + } + + /** + * Sets dst = dst * (1.0 - src.a) + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachDstOut(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(8, ain, aout, opt); } /** @@ -232,7 +333,19 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachSrcAtop(Allocation ain, Allocation aout) { - blend(9, ain, aout); + forEachSrcAtop(ain, aout, null); + } + + /** + * dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb + * dst.a = dst.a + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachSrcAtop(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(9, ain, aout, opt); } /** @@ -252,7 +365,19 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachDstAtop(Allocation ain, Allocation aout) { - blend(10, ain, aout); + forEachDstAtop(ain, aout, null); + } + + /** + * dst = dst.rgb * src.a + (1.0 - dst.a) * src.rgb + * dst.a = src.a + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachDstAtop(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(10, ain, aout, opt); } /** @@ -271,7 +396,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachXor(Allocation ain, Allocation aout) { - blend(11, ain, aout); + forEachXor(ain, aout, null); + } + + /** + * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a} + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachXor(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(11, ain, aout, opt); } /** @@ -300,7 +436,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachMultiply(Allocation ain, Allocation aout) { - blend(14, ain, aout); + forEachMultiply(ain, aout, null); + } + + /** + * Sets dst = src * dst + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachMultiply(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(14, ain, aout, opt); } /** @@ -396,7 +543,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachAdd(Allocation ain, Allocation aout) { - blend(34, ain, aout); + forEachAdd(ain, aout, null); + } + + /** + * Sets dst = min(src + dst, 1.0) + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachAdd(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(34, ain, aout, opt); } /** @@ -415,7 +573,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachSubtract(Allocation ain, Allocation aout) { - blend(35, ain, aout); + forEachSubtract(ain, aout, null); + } + + /** + * Sets dst = max(dst - src, 0.0) + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachSubtract(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(35, ain, aout, opt); } /** diff --git a/rs/java/android/renderscript/ScriptIntrinsicBlur.java b/rs/java/android/renderscript/ScriptIntrinsicBlur.java index 2b36d27..e7e33b8 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicBlur.java +++ b/rs/java/android/renderscript/ScriptIntrinsicBlur.java @@ -84,10 +84,23 @@ public final class ScriptIntrinsicBlur extends ScriptIntrinsic { * type. */ public void forEach(Allocation aout) { - forEach(0, null, aout, null); + forEach(aout, null); } /** + * Apply the filter to the input and save to the specified + * allocation. + * + * @param aout Output allocation. Must match creation element + * type. + * @param opt LaunchOptions for clipping + */ + public void forEach(Allocation aout, Script.LaunchOptions opt) { + forEach(0, null, aout, null, opt); + } + + + /** * Get a KernelID for this intrinsic kernel. * * @return Script.KernelID The KernelID object. diff --git a/rs/java/android/renderscript/ScriptIntrinsicColorMatrix.java b/rs/java/android/renderscript/ScriptIntrinsicColorMatrix.java index 4b0d507..57d917c 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicColorMatrix.java +++ b/rs/java/android/renderscript/ScriptIntrinsicColorMatrix.java @@ -206,7 +206,6 @@ public final class ScriptIntrinsicColorMatrix extends ScriptIntrinsic { setMatrix(); } - /** * Invoke the kernel and apply the matrix to each cell of input * {@link Allocation} and copy to the output {@link Allocation}. @@ -223,6 +222,26 @@ public final class ScriptIntrinsicColorMatrix extends ScriptIntrinsic { * @param aout Output allocation */ public void forEach(Allocation ain, Allocation aout) { + forEach(ain, aout, null); + } + + /** + * Invoke the kernel and apply the matrix to each cell of input + * {@link Allocation} and copy to the output {@link Allocation}. + * + * If the vector size of the input is less than four, the + * remaining components are treated as zero for the matrix + * multiply. + * + * If the output vector size is less than four, the unused + * vector components are discarded. + * + * + * @param ain Input allocation + * @param aout Output allocation + * @param opt LaunchOptions for clipping + */ + public void forEach(Allocation ain, Allocation aout, Script.LaunchOptions opt) { if (!ain.getElement().isCompatible(Element.U8(mRS)) && !ain.getElement().isCompatible(Element.U8_2(mRS)) && !ain.getElement().isCompatible(Element.U8_3(mRS)) && @@ -247,7 +266,7 @@ public final class ScriptIntrinsicColorMatrix extends ScriptIntrinsic { throw new RSIllegalArgumentException("Unsuported element type."); } - forEach(0, ain, aout, null); + forEach(0, ain, aout, null, opt); } /** diff --git a/rs/java/android/renderscript/ScriptIntrinsicConvolve3x3.java b/rs/java/android/renderscript/ScriptIntrinsicConvolve3x3.java index a1a1b7e..fb91fdc 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicConvolve3x3.java +++ b/rs/java/android/renderscript/ScriptIntrinsicConvolve3x3.java @@ -106,7 +106,19 @@ public final class ScriptIntrinsicConvolve3x3 extends ScriptIntrinsic { * type. */ public void forEach(Allocation aout) { - forEach(0, null, aout, null); + forEach(aout, null); + } + + /** + * Apply the filter to the input and save to the specified + * allocation. + * + * @param aout Output allocation. Must match creation element + * type. + * @param opt LaunchOptions for clipping + */ + public void forEach(Allocation aout, Script.LaunchOptions opt) { + forEach(0, null, aout, null, opt); } /** diff --git a/rs/java/android/renderscript/ScriptIntrinsicConvolve5x5.java b/rs/java/android/renderscript/ScriptIntrinsicConvolve5x5.java index 8b66896..0357560 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicConvolve5x5.java +++ b/rs/java/android/renderscript/ScriptIntrinsicConvolve5x5.java @@ -107,10 +107,23 @@ public final class ScriptIntrinsicConvolve5x5 extends ScriptIntrinsic { * type. */ public void forEach(Allocation aout) { - forEach(0, null, aout, null); + forEach(aout, null); } /** + * Apply the filter to the input and save to the specified + * allocation. + * + * @param aout Output allocation. Must match creation element + * type. + * @param opt LaunchOptions for clipping + */ + public void forEach(Allocation aout, Script.LaunchOptions opt) { + forEach(0, null, aout, null, opt); + } + + + /** * Get a KernelID for this intrinsic kernel. * * @return Script.KernelID The KernelID object. diff --git a/rs/java/android/renderscript/ScriptIntrinsicHistogram.java b/rs/java/android/renderscript/ScriptIntrinsicHistogram.java index 536663d..95b610a 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicHistogram.java +++ b/rs/java/android/renderscript/ScriptIntrinsicHistogram.java @@ -67,6 +67,24 @@ public final class ScriptIntrinsicHistogram extends ScriptIntrinsic { * @param ain The input image */ public void forEach(Allocation ain) { + forEach(ain, null); + } + + /** + * Process an input buffer and place the histogram into the + * output allocation. The output allocation may be a narrower + * vector size than the input. In this case the vector size of + * the output is used to determine how many of the input + * channels are used in the computation. This is useful if you + * have an RGBA input buffer but only want the histogram for + * RGB. + * + * 1D and 2D input allocations are supported. + * + * @param ain The input image + * @param opt LaunchOptions for clipping + */ + public void forEach(Allocation ain, Script.LaunchOptions opt) { if (ain.getType().getElement().getVectorSize() < mOut.getType().getElement().getVectorSize()) { @@ -78,9 +96,11 @@ public final class ScriptIntrinsicHistogram extends ScriptIntrinsic { throw new RSIllegalArgumentException("Output type must be U32 or I32."); } - forEach(0, ain, null, null); + forEach(0, ain, null, null, opt); } + + /** * Set the coefficients used for the RGBA to Luminocity * calculation. The default is {0.299f, 0.587f, 0.114f, 0.f}. @@ -137,6 +157,7 @@ public final class ScriptIntrinsicHistogram extends ScriptIntrinsic { setVar(1, aout); } + /** * Process an input buffer and place the histogram into the * output allocation. The dot product of the input channel and @@ -148,6 +169,21 @@ public final class ScriptIntrinsicHistogram extends ScriptIntrinsic { * @param ain The input image */ public void forEach_Dot(Allocation ain) { + forEach_Dot(ain, null); + } + + /** + * Process an input buffer and place the histogram into the + * output allocation. The dot product of the input channel and + * the coefficients from 'setDotCoefficients' are used to + * calculate the output values. + * + * 1D and 2D input allocations are supported. + * + * @param ain The input image + * @param opt LaunchOptions for clipping + */ + public void forEach_Dot(Allocation ain, Script.LaunchOptions opt) { if (mOut.getType().getElement().getVectorSize() != 1) { throw new RSIllegalArgumentException("Output vector size must be one."); } @@ -156,7 +192,7 @@ public final class ScriptIntrinsicHistogram extends ScriptIntrinsic { throw new RSIllegalArgumentException("Output type must be U32 or I32."); } - forEach(1, ain, null, null); + forEach(1, ain, null, null, opt); } diff --git a/rs/java/android/renderscript/ScriptIntrinsicLUT.java b/rs/java/android/renderscript/ScriptIntrinsicLUT.java index 001095c..69ff64a 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicLUT.java +++ b/rs/java/android/renderscript/ScriptIntrinsicLUT.java @@ -114,7 +114,6 @@ public final class ScriptIntrinsicLUT extends ScriptIntrinsic { mDirty = true; } - /** * Invoke the kernel and apply the lookup to each cell of ain * and copy to aout. @@ -123,11 +122,23 @@ public final class ScriptIntrinsicLUT extends ScriptIntrinsic { * @param aout Output allocation */ public void forEach(Allocation ain, Allocation aout) { + forEach(ain, aout, null); + } + + /** + * Invoke the kernel and apply the lookup to each cell of ain + * and copy to aout. + * + * @param ain Input allocation + * @param aout Output allocation + * @param opt Options for clipping + */ + public void forEach(Allocation ain, Allocation aout, Script.LaunchOptions opt) { if (mDirty) { mDirty = false; mTables.copyFromUnchecked(mCache); } - forEach(0, ain, aout, null); + forEach(0, ain, aout, null, opt); } /** |