FileDocCategorySizeDatePackage
ScriptIntrinsicColorMatrix.javaAPI DocAndroid 5.1 API4876Thu Mar 12 22:22:56 GMT 2015android.support.v8.renderscript

ScriptIntrinsicColorMatrix

public class ScriptIntrinsicColorMatrix extends ScriptIntrinsic
Intrinsic for applying a color matrix to allocations. This has the same effect as loading each element and converting it to a {@link Element#F32_4}, multiplying the result by the 4x4 color matrix as performed by rsMatrixMultiply() and writing it to the output after conversion back to {@link Element#U8_4}.

Fields Summary
private final Matrix4f
mMatrix
private Allocation
mInput
Constructors Summary
protected ScriptIntrinsicColorMatrix(int id, RenderScript rs)


         
        super(id, rs);
    
Methods Summary
public static android.support.v8.renderscript.ScriptIntrinsicColorMatrixcreate(RenderScript rs, Element e)
Create an intrinsic for applying a color matrix to an allocation. Supported elements types are {@link Element#U8_4}

param
rs The RenderScript context
param
e Element type for intputs and outputs
return
ScriptIntrinsicColorMatrix

        if (rs.isNative) {
            RenderScriptThunker rst = (RenderScriptThunker) rs;
            return ScriptIntrinsicColorMatrixThunker.create(rs, e);
        }

        if (!e.isCompatible(Element.U8_4(rs))) {
            throw new RSIllegalArgumentException("Unsuported element type.");
        }
        int id = rs.nScriptIntrinsicCreate(2, e.getID(rs));
        return new ScriptIntrinsicColorMatrix(id, rs);

    
public voidforEach(Allocation ain, Allocation aout)
Invoke the kernel and apply the matrix to each cell of ain and copy to aout.

param
ain Input allocation
param
aout Output allocation

        forEach(0, ain, aout, null);
    
public Script.KernelIDgetKernelID()
Get a KernelID for this intrinsic kernel.

return
Script.KernelID The KernelID object.

        return createKernelID(0, 3, null, null);
    
public voidsetColorMatrix(Matrix4f m)
Set the color matrix which will be applied to each cell of the image.

param
m The 4x4 matrix to set.

        mMatrix.load(m);
        setMatrix();
    
public voidsetColorMatrix(Matrix3f m)
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.

        mMatrix.load(m);
        setMatrix();
    
public voidsetGreyscale()
Set a color matrix to convert from RGB to luminance. The alpha channel will be a copy.

        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();
    
private voidsetMatrix()

        FieldPacker fp = new FieldPacker(16*4);
        fp.addMatrix(mMatrix);
        setVar(0, fp);
    
public voidsetRGBtoYUV()
Set the matrix to convert from RGB to YUV with a direct copy of the 4th channel.

        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();
    
public voidsetYUVtoRGB()
Set the matrix to convert from YUV to RGB with a direct copy of the 4th channel.

        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();