FileDocCategorySizeDatePackage
RsYuv.javaAPI DocAndroid 5.1 API4678Thu Mar 12 22:22:54 GMT 2015com.android.rs.livepreview

RsYuv

public class RsYuv extends Object implements TextureView.SurfaceTextureListener

Fields Summary
private int
mHeight
private int
mWidth
private android.renderscript.RenderScript
mRS
private android.renderscript.Allocation
mAllocationOut
private android.renderscript.Allocation
mAllocationIn
private ScriptC_yuv
mScript
private ScriptIntrinsicYuvToRGB
mYuv
private boolean
mHaveSurface
private android.view.Surface
mSurface
private ScriptGroup
mGroup
private long[]
mTiming
private int
mTimingSlot
Constructors Summary
RsYuv(android.renderscript.RenderScript rs)

        mRS = rs;
        mScript = new ScriptC_yuv(mRS);
        mYuv = ScriptIntrinsicYuvToRGB.create(rs, Element.RGBA_8888(mRS));
    
Methods Summary
voidexecute(byte[] yuv)


       
        mAllocationIn.copyFrom(yuv);
        if (mHaveSurface) {
            mGroup.setOutput(mScript.getKernelID_root(), mAllocationOut);
            mGroup.execute();

            //mYuv.forEach(mAllocationOut);
            //mScript.forEach_root(mAllocationOut, mAllocationOut);
            mAllocationOut.ioSend();
        }
    
public intgetHeight()

        return mHeight;
    
public intgetWidth()

        return mWidth;
    
public voidonSurfaceTextureAvailable(android.graphics.SurfaceTexture surface, int width, int height)

        android.util.Log.v("cpa", "onSurfaceTextureAvailable " + surface);
        mSurface = new Surface(surface);
        setupSurface();
    
public booleanonSurfaceTextureDestroyed(android.graphics.SurfaceTexture surface)

        android.util.Log.v("cpa", "onSurfaceTextureDestroyed " + surface);
        mSurface = null;
        setupSurface();
        return true;
    
public voidonSurfaceTextureSizeChanged(android.graphics.SurfaceTexture surface, int width, int height)

        android.util.Log.v("cpa", "onSurfaceTextureSizeChanged " + surface);
        mSurface = new Surface(surface);
        setupSurface();
    
public voidonSurfaceTextureUpdated(android.graphics.SurfaceTexture surface)

    
voidreset(int width, int height)

        if (mAllocationOut != null) {
            mAllocationOut.destroy();
        }

        android.util.Log.v("cpa", "reset " + width + ", " + height);
        mHeight = height;
        mWidth = width;
        mScript.invoke_setSize(mWidth, mHeight);

        Type.Builder tb = new Type.Builder(mRS, Element.RGBA_8888(mRS));
        tb.setX(mWidth);
        tb.setY(mHeight);
        Type t = tb.create();
        mAllocationOut = Allocation.createTyped(mRS, t, Allocation.USAGE_SCRIPT |
                                                        Allocation.USAGE_IO_OUTPUT);


        tb = new Type.Builder(mRS, Element.createPixel(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV));
        tb.setX(mWidth);
        tb.setY(mHeight);
        tb.setYuvFormat(android.graphics.ImageFormat.NV21);
        mAllocationIn = Allocation.createTyped(mRS, tb.create(), Allocation.USAGE_SCRIPT);
        mYuv.setInput(mAllocationIn);
        setupSurface();


        ScriptGroup.Builder b = new ScriptGroup.Builder(mRS);
        b.addKernel(mScript.getKernelID_root());
        b.addKernel(mYuv.getKernelID());
        b.addConnection(t, mYuv.getKernelID(), mScript.getKernelID_root());
        mGroup = b.create();
    
voidsetupSurface()

        if (mAllocationOut != null) {
            mAllocationOut.setSurface(mSurface);
        }
        if (mSurface != null) {
            mHaveSurface = true;
        } else {
            mHaveSurface = false;
        }