Search in sources :

Example 66 with FrameFormat

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

the class GLFrame method init.

void init(GLEnvironment glEnv) {
    FrameFormat format = getFormat();
    mGLEnvironment = glEnv;
    // Check that we have a valid format
    if (format.getBytesPerSample() != 4) {
        throw new IllegalArgumentException("GL frames must have 4 bytes per sample!");
    } else if (format.getDimensionCount() != 2) {
        throw new IllegalArgumentException("GL frames must be 2-dimensional!");
    } else if (getFormat().getSize() < 0) {
        throw new IllegalArgumentException("Initializing GL frame with zero size!");
    }
    // Create correct frame
    int bindingType = getBindingType();
    boolean reusable = true;
    if (bindingType == Frame.NO_BINDING) {
        initNew(false);
    } else if (bindingType == EXTERNAL_TEXTURE) {
        initNew(true);
        reusable = false;
    } else if (bindingType == EXISTING_TEXTURE_BINDING) {
        initWithTexture((int) getBindingId());
    } else if (bindingType == EXISTING_FBO_BINDING) {
        initWithFbo((int) getBindingId());
    } else if (bindingType == NEW_TEXTURE_BINDING) {
        initWithTexture((int) getBindingId());
    } else if (bindingType == NEW_FBO_BINDING) {
        initWithFbo((int) getBindingId());
    } else {
        throw new RuntimeException("Attempting to create GL frame with unknown binding type " + bindingType + "!");
    }
    setReusable(reusable);
}
Also used : FrameFormat(android.filterfw.core.FrameFormat)

Example 67 with FrameFormat

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

the class BitmapOverlayFilter 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());
    }
    if (mBitmap != null) {
        Frame frame = createBitmapFrame(context);
        // Process
        Frame[] inputs = { input, frame };
        mProgram.process(inputs, output);
        frame.release();
    } else {
        output.setDataFromFrame(input);
    }
    // Push output
    pushOutput("image", output);
    // Release pushed frame
    output.release();
}
Also used : FrameFormat(android.filterfw.core.FrameFormat) Frame(android.filterfw.core.Frame)

Example 68 with FrameFormat

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

the class BitmapSource method loadImage.

public void loadImage(FilterContext filterContext) {
    // Create frame with bitmap
    mTarget = FrameFormat.readTargetString(mTargetString);
    FrameFormat outputFormat = ImageFormat.create(mBitmap.getWidth(), mBitmap.getHeight(), ImageFormat.COLORSPACE_RGBA, mTarget);
    mImageFrame = filterContext.getFrameManager().newFrame(outputFormat);
    mImageFrame.setBitmap(mBitmap);
    mImageFrame.setTimestamp(Frame.TIMESTAMP_UNKNOWN);
    // Free up space used by bitmap
    if (mRecycleBitmap) {
        mBitmap.recycle();
    }
    mBitmap = null;
}
Also used : FrameFormat(android.filterfw.core.FrameFormat)

Example 69 with FrameFormat

use of android.filterfw.core.FrameFormat 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 70 with FrameFormat

use of android.filterfw.core.FrameFormat 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

FrameFormat (android.filterfw.core.FrameFormat)270 Frame (android.filterfw.core.Frame)198 MutableFrameFormat (android.filterfw.core.MutableFrameFormat)39 NativeFrame (android.filterfw.core.NativeFrame)25 GLFrame (android.filterfw.core.GLFrame)18 ShaderProgram (android.filterfw.core.ShaderProgram)12 Quad (android.filterfw.geometry.Quad)12 FrameManager (android.filterfw.core.FrameManager)6 Point (android.filterfw.geometry.Point)6 Bitmap (android.graphics.Bitmap)6 Paint (android.graphics.Paint)6 CachedFrameManager (android.filterfw.core.CachedFrameManager)1