Search in sources :

Example 16 with MutableFrameFormat

use of android.filterfw.core.MutableFrameFormat in project platform_frameworks_base by android.

the class FixedRotationFilter method process.

@Override
public void process(FilterContext context) {
    Frame input = pullInput("image");
    if (mRotation == 0) {
        pushOutput("image", input);
        return;
    }
    FrameFormat inputFormat = input.getFormat();
    // Create program if not created already
    if (mProgram == null) {
        mProgram = ShaderProgram.createIdentity(context);
    }
    MutableFrameFormat outputFormat = inputFormat.mutableCopy();
    int width = inputFormat.getWidth();
    int height = inputFormat.getHeight();
    Point p1 = new Point(0.0f, 0.0f);
    Point p2 = new Point(1.0f, 0.0f);
    Point p3 = new Point(0.0f, 1.0f);
    Point p4 = new Point(1.0f, 1.0f);
    Quad sourceRegion;
    switch(((int) Math.round(mRotation / 90f)) % 4) {
        case 1:
            sourceRegion = new Quad(p3, p1, p4, p2);
            outputFormat.setDimensions(height, width);
            break;
        case 2:
            sourceRegion = new Quad(p4, p3, p2, p1);
            break;
        case 3:
            sourceRegion = new Quad(p2, p4, p1, p3);
            outputFormat.setDimensions(height, width);
            break;
        case 0:
        default:
            sourceRegion = new Quad(p1, p2, p3, p4);
            break;
    }
    // Create output frame
    Frame output = context.getFrameManager().newFrame(outputFormat);
    // Set the source region
    mProgram.setSourceRegion(sourceRegion);
    // Process
    mProgram.process(input, output);
    // Push output
    pushOutput("image", output);
    // Release pushed frame
    output.release();
}
Also used : FrameFormat(android.filterfw.core.FrameFormat) MutableFrameFormat(android.filterfw.core.MutableFrameFormat) Quad(android.filterfw.geometry.Quad) Frame(android.filterfw.core.Frame) MutableFrameFormat(android.filterfw.core.MutableFrameFormat) Point(android.filterfw.geometry.Point) Point(android.filterfw.geometry.Point)

Example 17 with MutableFrameFormat

use of android.filterfw.core.MutableFrameFormat in project platform_frameworks_base by android.

the class FrameManager method duplicateFrameToTarget.

public Frame duplicateFrameToTarget(Frame frame, int newTarget) {
    MutableFrameFormat newFormat = frame.getFormat().mutableCopy();
    newFormat.setTarget(newTarget);
    Frame result = newFrame(newFormat);
    result.setDataFromFrame(frame);
    return result;
}
Also used : Frame(android.filterfw.core.Frame) MutableFrameFormat(android.filterfw.core.MutableFrameFormat)

Example 18 with MutableFrameFormat

use of android.filterfw.core.MutableFrameFormat in project platform_frameworks_base by android.

the class ImageFormat method create.

public static MutableFrameFormat create(int width, int height, int colorspace, int bytesPerSample, int target) {
    MutableFrameFormat result = new MutableFrameFormat(FrameFormat.TYPE_BYTE, target);
    result.setDimensions(width, height);
    result.setBytesPerSample(bytesPerSample);
    result.setMetaValue(COLORSPACE_KEY, colorspace);
    if (target == FrameFormat.TARGET_SIMPLE) {
        result.setObjectClass(Bitmap.class);
    }
    return result;
}
Also used : MutableFrameFormat(android.filterfw.core.MutableFrameFormat)

Example 19 with MutableFrameFormat

use of android.filterfw.core.MutableFrameFormat 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 20 with MutableFrameFormat

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

the class ImageStitcher method calcOutputFormatForInput.

private FrameFormat calcOutputFormatForInput(FrameFormat format) {
    MutableFrameFormat outputFormat = format.mutableCopy();
    mInputWidth = format.getWidth();
    mInputHeight = format.getHeight();
    mSliceWidth = mInputWidth - 2 * mPadSize;
    mSliceHeight = mInputHeight - 2 * mPadSize;
    mImageWidth = mSliceWidth * mXSlices;
    mImageHeight = mSliceHeight * mYSlices;
    outputFormat.setDimensions(mImageWidth, mImageHeight);
    return outputFormat;
}
Also used : MutableFrameFormat(android.filterfw.core.MutableFrameFormat)

Aggregations

MutableFrameFormat (android.filterfw.core.MutableFrameFormat)126 Frame (android.filterfw.core.Frame)36 FrameFormat (android.filterfw.core.FrameFormat)24 ShaderProgram (android.filterfw.core.ShaderProgram)12 Point (android.filterfw.geometry.Point)12 Quad (android.filterfw.geometry.Quad)12 GLFrame (android.filterfw.core.GLFrame)6 KeyValueMap (android.filterfw.core.KeyValueMap)6 MediaRecorder (android.media.MediaRecorder)6 IOException (java.io.IOException)6 NativeFrame (android.filterfw.core.NativeFrame)2