Search in sources :

Example 56 with ShaderProgram

use of android.filterfw.core.ShaderProgram in project android_frameworks_base by ResurrectionRemix.

the class CropFilter method process.

@Override
public void process(FilterContext env) {
    // Get input frame
    Frame imageFrame = pullInput("image");
    Frame boxFrame = pullInput("box");
    createProgram(env, imageFrame.getFormat());
    // Get the box
    Quad box = (Quad) boxFrame.getObjectValue();
    // Create output format
    MutableFrameFormat outputFormat = imageFrame.getFormat().mutableCopy();
    outputFormat.setDimensions(mOutputWidth == -1 ? outputFormat.getWidth() : mOutputWidth, mOutputHeight == -1 ? outputFormat.getHeight() : mOutputHeight);
    // Create output frame
    Frame output = env.getFrameManager().newFrame(outputFormat);
    // Set the program parameters
    if (mProgram instanceof ShaderProgram) {
        ShaderProgram shaderProgram = (ShaderProgram) mProgram;
        shaderProgram.setSourceRegion(box);
    }
    mProgram.process(imageFrame, output);
    // Push output
    pushOutput("image", output);
    // Release pushed frame
    output.release();
}
Also used : Quad(android.filterfw.geometry.Quad) Frame(android.filterfw.core.Frame) ShaderProgram(android.filterfw.core.ShaderProgram) MutableFrameFormat(android.filterfw.core.MutableFrameFormat)

Example 57 with ShaderProgram

use of android.filterfw.core.ShaderProgram in project android_frameworks_base by ResurrectionRemix.

the class MediaSource method prepare.

@Override
protected void prepare(FilterContext context) {
    if (mLogVerbose)
        Log.v(TAG, "Preparing MediaSource");
    mFrameExtractor = new ShaderProgram(context, mFrameShader);
    // SurfaceTexture defines (0,0) to be bottom-left. The filter framework
    // defines (0,0) as top-left, so do the flip here.
    mFrameExtractor.setSourceRect(0, 1, 1, -1);
    createFormats();
}
Also used : ShaderProgram(android.filterfw.core.ShaderProgram)

Example 58 with ShaderProgram

use of android.filterfw.core.ShaderProgram in project android_frameworks_base by DirtyUnicorns.

the class MediaSource method prepare.

@Override
protected void prepare(FilterContext context) {
    if (mLogVerbose)
        Log.v(TAG, "Preparing MediaSource");
    mFrameExtractor = new ShaderProgram(context, mFrameShader);
    // SurfaceTexture defines (0,0) to be bottom-left. The filter framework
    // defines (0,0) as top-left, so do the flip here.
    mFrameExtractor.setSourceRect(0, 1, 1, -1);
    createFormats();
}
Also used : ShaderProgram(android.filterfw.core.ShaderProgram)

Example 59 with ShaderProgram

use of android.filterfw.core.ShaderProgram in project android_frameworks_base by DirtyUnicorns.

the class ImageSlicer method process.

@Override
public void process(FilterContext context) {
    // Get input frame
    if (mSliceIndex == 0) {
        mOriginalFrame = pullInput("image");
        calcOutputFormatForInput(mOriginalFrame);
    }
    FrameFormat inputFormat = mOriginalFrame.getFormat();
    MutableFrameFormat outputFormat = inputFormat.mutableCopy();
    outputFormat.setDimensions(mOutputWidth, mOutputHeight);
    // Create output frame
    Frame output = context.getFrameManager().newFrame(outputFormat);
    // Create the program if not created already
    if (mProgram == null) {
        mProgram = ShaderProgram.createIdentity(context);
    }
    // Calculate the four corner of the source region
    int xSliceIndex = mSliceIndex % mXSlices;
    int ySliceIndex = mSliceIndex / mXSlices;
    // TODO(rslin) : not sure shifting by 0.5 is needed.
    float x0 = (xSliceIndex * mSliceWidth - mPadSize) / ((float) mInputWidth);
    float y0 = (ySliceIndex * mSliceHeight - mPadSize) / ((float) mInputHeight);
    ((ShaderProgram) mProgram).setSourceRect(x0, y0, ((float) mOutputWidth) / mInputWidth, ((float) mOutputHeight) / mInputHeight);
    // Process
    mProgram.process(mOriginalFrame, output);
    mSliceIndex++;
    if (mSliceIndex == mXSlices * mYSlices) {
        mSliceIndex = 0;
        mOriginalFrame.release();
        setWaitsOnInputPort("image", true);
    } else {
        // Retain the original frame so it can be used next time.
        mOriginalFrame.retain();
        setWaitsOnInputPort("image", false);
    }
    // Push output
    pushOutput("image", output);
    // Release pushed frame
    output.release();
}
Also used : FrameFormat(android.filterfw.core.FrameFormat) MutableFrameFormat(android.filterfw.core.MutableFrameFormat) Frame(android.filterfw.core.Frame) ShaderProgram(android.filterfw.core.ShaderProgram) MutableFrameFormat(android.filterfw.core.MutableFrameFormat)

Example 60 with ShaderProgram

use of android.filterfw.core.ShaderProgram in project android_frameworks_base by DirtyUnicorns.

the class ImageStitcher method process.

@Override
public void process(FilterContext context) {
    // Get input frame
    Frame input = pullInput("image");
    FrameFormat format = input.getFormat();
    // Create output frame
    if (mSliceIndex == 0) {
        mOutputFrame = context.getFrameManager().newFrame(calcOutputFormatForInput(format));
    } else {
        if ((format.getWidth() != mInputWidth) || (format.getHeight() != mInputHeight)) {
            // CHECK input format here
            throw new RuntimeException("Image size should not change.");
        }
    }
    // Create the program if not created already
    if (mProgram == null) {
        mProgram = ShaderProgram.createIdentity(context);
    }
    // TODO(rslin) : not sure shifting by 0.5 is needed.
    float x0 = ((float) mPadSize) / mInputWidth;
    float y0 = ((float) mPadSize) / mInputHeight;
    int outputOffsetX = (mSliceIndex % mXSlices) * mSliceWidth;
    int outputOffsetY = (mSliceIndex / mXSlices) * mSliceHeight;
    float outputWidth = (float) Math.min(mSliceWidth, mImageWidth - outputOffsetX);
    float outputHeight = (float) Math.min(mSliceHeight, mImageHeight - outputOffsetY);
    // We need to set the source rect as well because the input are padded images.
    ((ShaderProgram) mProgram).setSourceRect(x0, y0, outputWidth / mInputWidth, outputHeight / mInputHeight);
    ((ShaderProgram) mProgram).setTargetRect(((float) outputOffsetX) / mImageWidth, ((float) outputOffsetY) / mImageHeight, outputWidth / mImageWidth, outputHeight / mImageHeight);
    // Process this tile
    mProgram.process(input, mOutputFrame);
    mSliceIndex++;
    // Push output
    if (mSliceIndex == mXSlices * mYSlices) {
        pushOutput("image", mOutputFrame);
        mOutputFrame.release();
        mSliceIndex = 0;
    }
}
Also used : FrameFormat(android.filterfw.core.FrameFormat) MutableFrameFormat(android.filterfw.core.MutableFrameFormat) Frame(android.filterfw.core.Frame) ShaderProgram(android.filterfw.core.ShaderProgram)

Aggregations

ShaderProgram (android.filterfw.core.ShaderProgram)198 Frame (android.filterfw.core.Frame)18 MutableFrameFormat (android.filterfw.core.MutableFrameFormat)18 Quad (android.filterfw.geometry.Quad)18 FrameFormat (android.filterfw.core.FrameFormat)12 Point (android.filterfw.geometry.Point)12 NativeFrame (android.filterfw.core.NativeFrame)1