Search in sources :

Example 31 with ShaderProgram

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

the class SepiaFilter method initProgram.

public void initProgram(FilterContext context, int target) {
    switch(target) {
        case FrameFormat.TARGET_GPU:
            ShaderProgram shaderProgram = new ShaderProgram(context, mSepiaShader);
            shaderProgram.setMaximumTileSize(mTileSize);
            mProgram = shaderProgram;
            break;
        default:
            throw new RuntimeException("Filter Sharpen does not support frames of " + "target " + target + "!");
    }
    mTarget = target;
}
Also used : ShaderProgram(android.filterfw.core.ShaderProgram)

Example 32 with ShaderProgram

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

the class FlipFilter method initProgram.

public void initProgram(FilterContext context, int target) {
    switch(target) {
        case FrameFormat.TARGET_GPU:
            ShaderProgram shaderProgram = ShaderProgram.createIdentity(context);
            shaderProgram.setMaximumTileSize(mTileSize);
            mProgram = shaderProgram;
            break;
        default:
            throw new RuntimeException("Filter Sharpen does not support frames of " + "target " + target + "!");
    }
    mTarget = target;
    updateParameters();
}
Also used : ShaderProgram(android.filterfw.core.ShaderProgram)

Example 33 with ShaderProgram

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

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 34 with ShaderProgram

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

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)

Example 35 with ShaderProgram

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

the class CrossProcessFilter method initProgram.

public void initProgram(FilterContext context, int target) {
    switch(target) {
        case FrameFormat.TARGET_GPU:
            ShaderProgram shaderProgram = new ShaderProgram(context, mCrossProcessShader);
            shaderProgram.setMaximumTileSize(mTileSize);
            mProgram = shaderProgram;
            break;
        default:
            throw new RuntimeException("Filter CrossProcess does not support frames of " + "target " + target + "!");
    }
    mTarget = target;
}
Also used : 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