Search in sources :

Example 76 with Frame

use of android.filterfw.core.Frame 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 77 with Frame

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

the class DuotoneFilter method process.

@Override
public void process(FilterContext context) {
    // Get input frame
    Frame input = pullInput("image");
    FrameFormat inputFormat = input.getFormat();
    // Create output frame
    Frame output = context.getFrameManager().newFrame(inputFormat);
    // Create program if not created already
    if (mProgram == null || inputFormat.getTarget() != mTarget) {
        initProgram(context, inputFormat.getTarget());
    }
    updateParameters();
    // Process
    mProgram.process(input, output);
    // Push output
    pushOutput("image", output);
    // Release pushed frame
    output.release();
}
Also used : FrameFormat(android.filterfw.core.FrameFormat) Frame(android.filterfw.core.Frame) NativeFrame(android.filterfw.core.NativeFrame)

Example 78 with Frame

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

the class FillLightFilter method process.

@Override
public void process(FilterContext context) {
    // Get input frame
    Frame input = pullInput("image");
    FrameFormat inputFormat = input.getFormat();
    // Create output frame
    Frame output = context.getFrameManager().newFrame(inputFormat);
    // Create program if not created already
    if (mProgram == null || inputFormat.getTarget() != mTarget) {
        initProgram(context, inputFormat.getTarget());
        updateParameters();
    }
    // Process
    mProgram.process(input, output);
    // Push output
    pushOutput("image", output);
    // Release pushed frame
    output.release();
}
Also used : FrameFormat(android.filterfw.core.FrameFormat) Frame(android.filterfw.core.Frame) NativeFrame(android.filterfw.core.NativeFrame)

Example 79 with Frame

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

the class CameraSource method process.

@Override
public void process(FilterContext context) {
    if (mLogVerbose)
        Log.v(TAG, "Processing new frame");
    if (mWaitForNewFrame) {
        int waitCount = 0;
        while (!mNewFrameAvailable) {
            if (waitCount == NEWFRAME_TIMEOUT_REPEAT) {
                throw new RuntimeException("Timeout waiting for new frame");
            }
            try {
                this.wait(NEWFRAME_TIMEOUT);
            } catch (InterruptedException e) {
                if (mLogVerbose)
                    Log.v(TAG, "Interrupted while waiting for new frame");
            }
        }
        mNewFrameAvailable = false;
        if (mLogVerbose)
            Log.v(TAG, "Got new frame");
    }
    mSurfaceTexture.updateTexImage();
    if (mLogVerbose)
        Log.v(TAG, "Using frame extractor in thread: " + Thread.currentThread());
    mSurfaceTexture.getTransformMatrix(mCameraTransform);
    Matrix.multiplyMM(mMappedCoords, 0, mCameraTransform, 0, mSourceCoords, 0);
    mFrameExtractor.setSourceRegion(mMappedCoords[0], mMappedCoords[1], mMappedCoords[4], mMappedCoords[5], mMappedCoords[8], mMappedCoords[9], mMappedCoords[12], mMappedCoords[13]);
    Frame output = context.getFrameManager().newFrame(mOutputFormat);
    mFrameExtractor.process(mCameraFrame, output);
    long timestamp = mSurfaceTexture.getTimestamp();
    if (mLogVerbose)
        Log.v(TAG, "Timestamp: " + (timestamp / 1000000000.0) + " s");
    output.setTimestamp(timestamp);
    pushOutput("video", output);
    // Release pushed frame
    output.release();
    if (mLogVerbose)
        Log.v(TAG, "Done processing new frame");
}
Also used : Frame(android.filterfw.core.Frame) GLFrame(android.filterfw.core.GLFrame) NativeFrame(android.filterfw.core.NativeFrame)

Example 80 with Frame

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

the class SurfaceTextureSource method process.

@Override
public void process(FilterContext context) {
    if (mLogVerbose)
        Log.v(TAG, "Processing new frame");
    // First, get new frame if available
    if (mWaitForNewFrame || mFirstFrame) {
        boolean gotNewFrame;
        if (mWaitTimeout != 0) {
            gotNewFrame = mNewFrameAvailable.block(mWaitTimeout);
            if (!gotNewFrame) {
                if (!mCloseOnTimeout) {
                    throw new RuntimeException("Timeout waiting for new frame");
                } else {
                    if (mLogVerbose)
                        Log.v(TAG, "Timeout waiting for a new frame. Closing.");
                    closeOutputPort("video");
                    return;
                }
            }
        } else {
            mNewFrameAvailable.block();
        }
        mNewFrameAvailable.close();
        mFirstFrame = false;
    }
    mSurfaceTexture.updateTexImage();
    mSurfaceTexture.getTransformMatrix(mFrameTransform);
    Matrix.multiplyMM(mMappedCoords, 0, mFrameTransform, 0, mSourceCoords, 0);
    mFrameExtractor.setSourceRegion(mMappedCoords[0], mMappedCoords[1], mMappedCoords[4], mMappedCoords[5], mMappedCoords[8], mMappedCoords[9], mMappedCoords[12], mMappedCoords[13]);
    // Next, render to output
    Frame output = context.getFrameManager().newFrame(mOutputFormat);
    mFrameExtractor.process(mMediaFrame, output);
    output.setTimestamp(mSurfaceTexture.getTimestamp());
    pushOutput("video", output);
    output.release();
}
Also used : Frame(android.filterfw.core.Frame) GLFrame(android.filterfw.core.GLFrame)

Aggregations

Frame (android.filterfw.core.Frame)414 FrameFormat (android.filterfw.core.FrameFormat)198 GLFrame (android.filterfw.core.GLFrame)73 MutableFrameFormat (android.filterfw.core.MutableFrameFormat)47 NativeFrame (android.filterfw.core.NativeFrame)38 Quad (android.filterfw.geometry.Quad)24 GLEnvironment (android.filterfw.core.GLEnvironment)18 ShaderProgram (android.filterfw.core.ShaderProgram)18 ByteBuffer (java.nio.ByteBuffer)18 Point (android.filterfw.geometry.Point)12 IOException (java.io.IOException)12 FrameManager (android.filterfw.core.FrameManager)6 Bitmap (android.graphics.Bitmap)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Map (java.util.Map)6 SortedMap (java.util.SortedMap)6 TreeMap (java.util.TreeMap)6 CachedFrameManager (android.filterfw.core.CachedFrameManager)1