@UnstableApi
public final class Crop implements MatrixTransformation


Specifies a crop to apply in the vertex shader.

The background color of the output frame will be black, with alpha = 0 if applicable.

Summary

Public constructors

Crop(float left, float right, float bottom, float top)

Crops a smaller (or larger) frame, per normalized device coordinates (NDC), where the input frame corresponds to the square ranging from -1 to 1 on the x and y axes.

Public methods

Size
configure(int inputWidth, int inputHeight)

Configures the input and output dimensions.

Matrix
getMatrix(long presentationTimeUs)

Returns the 3x3 transformation Matrix to apply to the frame with the given timestamp.

boolean
isNoOp(int inputWidth, int inputHeight)

Returns whether a GlEffect applies no change at every timestamp.

Inherited methods

From androidx.media3.effect.GlEffect
abstract GlShaderProgram
toGlShaderProgram(Context context, boolean useHdr)

Returns a GlShaderProgram that applies the effect.

From androidx.media3.effect.GlMatrixTransformation
BaseGlShaderProgram
toGlShaderProgram(Context context, boolean useHdr)

Returns a GlShaderProgram that applies the effect.

From androidx.media3.effect.MatrixTransformation
float[]
getGlMatrixArray(long presentationTimeUs)

Returns the 4x4 transformation Matrix to apply to the frame with the given timestamp.

Public constructors

Crop

public Crop(float left, float right, float bottom, float top)

Crops a smaller (or larger) frame, per normalized device coordinates (NDC), where the input frame corresponds to the square ranging from -1 to 1 on the x and y axes.

left and bottom default to -1, and right and top default to 1, which corresponds to not applying any crop. To crop to a smaller subset of the input frame, use values between -1 and 1. To crop to a larger frame, use values below -1 and above 1.

Parameters
float left

The left edge of the output frame, in NDC. Must be less than right.

float right

The right edge of the output frame, in NDC. Must be greater than left.

float bottom

The bottom edge of the output frame, in NDC. Must be less than top.

float top

The top edge of the output frame, in NDC. Must be greater than bottom.

Public methods

configure

public Size configure(int inputWidth, int inputHeight)

Configures the input and output dimensions.

Must be called before getGlMatrixArray.

Parameters
int inputWidth

The input frame width, in pixels.

int inputHeight

The input frame height, in pixels.

Returns
Size

The output frame width and height, in pixels.

getMatrix

public Matrix getMatrix(long presentationTimeUs)

Returns the 3x3 transformation Matrix to apply to the frame with the given timestamp.

isNoOp

public boolean isNoOp(int inputWidth, int inputHeight)

Returns whether a GlEffect applies no change at every timestamp.

This can be used as a hint to skip this instance.

Parameters
int inputWidth

The input frame width, in pixels.

int inputHeight

The input frame height, in pixels.