diff options
author | Jason Sams <jsams@google.com> | 2013-06-19 00:26:38 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-06-19 00:26:38 +0000 |
commit | 109c46b8eaff88d7f0106ec9ca059f9cd09b0664 (patch) | |
tree | fd4d81a6f254883f179d2a4b491c397a7f0c0479 | |
parent | a7cfb4f82751a4f4166006c1725758e8f9bb5c5c (diff) | |
parent | 01e9f90576f356905b392e3bbff0ad442988180f (diff) | |
download | frameworks_base-109c46b8eaff88d7f0106ec9ca059f9cd09b0664.zip frameworks_base-109c46b8eaff88d7f0106ec9ca059f9cd09b0664.tar.gz frameworks_base-109c46b8eaff88d7f0106ec9ca059f9cd09b0664.tar.bz2 |
Merge "Add histogram intrinsic"
-rw-r--r-- | api/current.txt | 10 | ||||
-rw-r--r-- | graphics/java/android/renderscript/ScriptIntrinsicHistogram.java | 143 |
2 files changed, 153 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt index d026c24..e3d0674 100644 --- a/api/current.txt +++ b/api/current.txt @@ -21333,6 +21333,16 @@ package android.renderscript { method public void setInput(android.renderscript.Allocation); } + public final class ScriptIntrinsicHistogram extends android.renderscript.ScriptIntrinsic { + method public static android.renderscript.ScriptIntrinsicHistogram create(android.renderscript.RenderScript, android.renderscript.Element); + method public void forEach(android.renderscript.Allocation); + method public void forEach_dot(android.renderscript.Allocation); + method public android.renderscript.Script.FieldID getFieldID_Input(); + method public android.renderscript.Script.KernelID getKernelID_seperate(); + method public void setDotCoefficients(float, float, float, float); + method public void setOutput(android.renderscript.Allocation); + } + public final class ScriptIntrinsicLUT extends android.renderscript.ScriptIntrinsic { method public static android.renderscript.ScriptIntrinsicLUT create(android.renderscript.RenderScript, android.renderscript.Element); method public void forEach(android.renderscript.Allocation, android.renderscript.Allocation); diff --git a/graphics/java/android/renderscript/ScriptIntrinsicHistogram.java b/graphics/java/android/renderscript/ScriptIntrinsicHistogram.java new file mode 100644 index 0000000..e7f87d4 --- /dev/null +++ b/graphics/java/android/renderscript/ScriptIntrinsicHistogram.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.renderscript; + +import android.content.Context; +import android.content.res.Resources; +import android.util.Log; + +/** + * Intrinsic Histogram filter. + * + * + **/ +public final class ScriptIntrinsicHistogram extends ScriptIntrinsic { + private Allocation mOut; + + private ScriptIntrinsicHistogram(int id, RenderScript rs) { + super(id, rs); + } + + /** + * Create an intrinsic for calculating the histogram of an uchar + * or uchar4 image. + * + * Supported elements types are {@link Element#U8_4, @link + * Element#U8} + * + * @param rs The RenderScript context + * @param e Element type for inputs and outputs + * + * @return ScriptIntrinsicHistogram + */ + public static ScriptIntrinsicHistogram create(RenderScript rs, Element e) { + if ((!e.isCompatible(Element.U8_4(rs))) && (!e.isCompatible(Element.U8(rs)))) { + throw new RSIllegalArgumentException("Unsuported element type."); + } + int id = rs.nScriptIntrinsicCreate(9, e.getID(rs)); + ScriptIntrinsicHistogram sib = new ScriptIntrinsicHistogram(id, rs); + return sib; + } + + public void forEach(Allocation ain) { + int vecSize = mOut.getType().getElement().getVectorSize(); + if (ain.getType().getElement().getVectorSize() != vecSize) { + throw new RSIllegalArgumentException("Vector sizes must match."); + } + if (ain.getType().getElement().isCompatible(Element.U8(mRS)) && + ain.getType().getElement().isCompatible(Element.U8_4(mRS))) { + throw new RSIllegalArgumentException("Output type must be U32 or I32."); + } + + forEach(0, ain, null, null); + } + + public void setDotCoefficients(float r, float g, float b, float a) { + if ((r < 0.f) || (g < 0.f) || (b < 0.f) || (a < 0.f)) { + throw new RSIllegalArgumentException("Coefficient may not be negative."); + } + if ((r + g + b + a) > 1.f) { + throw new RSIllegalArgumentException("Sum of coefficients must be 1.0 or less."); + } + + FieldPacker fp = new FieldPacker(16); + fp.addF32(r); + fp.addF32(g); + fp.addF32(b); + fp.addF32(a); + setVar(0, fp); + } + + /** + * Set the output of the histogram. + * + * @param ain The input allocation + */ + public void setOutput(Allocation aout) { + mOut = aout; + if (mOut.getType().getElement() != Element.U32(mRS) && + mOut.getType().getElement() != Element.U32_3(mRS) && + mOut.getType().getElement() != Element.U32_4(mRS) && + mOut.getType().getElement() != Element.I32(mRS) && + mOut.getType().getElement() != Element.I32_3(mRS) && + mOut.getType().getElement() != Element.I32_4(mRS)) { + + throw new RSIllegalArgumentException("Output type must be U32 or I32."); + } + if ((mOut.getType().getX() != 256) || + (mOut.getType().getY() != 0) || + mOut.getType().hasMipmaps() || + (mOut.getType().getYuv() != 0)) { + + throw new RSIllegalArgumentException("Output must be 1D, 256 elements."); + } + setVar(1, aout); + } + + public void forEach_dot(Allocation ain) { + if (mOut.getType().getElement().getVectorSize() != 1) { + throw new RSIllegalArgumentException("Output vector size must be one."); + } + if (ain.getType().getElement().isCompatible(Element.U8(mRS)) && + ain.getType().getElement().isCompatible(Element.U8_4(mRS))) { + throw new RSIllegalArgumentException("Output type must be U32 or I32."); + } + + forEach(1, ain, null, null); + } + + + + /** + * Get a KernelID for this intrinsic kernel. + * + * @return Script.KernelID The KernelID object. + */ + public Script.KernelID getKernelID_seperate() { + return createKernelID(0, 3, null, null); + } + + /** + * Get a FieldID for the input field of this intrinsic. + * + * @return Script.FieldID The FieldID object. + */ + public Script.FieldID getFieldID_Input() { + return createFieldID(1, null); + } +} + |