Add scaling support to surface view renderer.
PiperOrigin-RevId: 575134648
This commit is contained in:
parent
305d7abec4
commit
8fc3a0473f
|
@ -25,6 +25,7 @@ import android.opengl.GLES31;
|
||||||
import android.opengl.GLSurfaceView;
|
import android.opengl.GLSurfaceView;
|
||||||
import android.opengl.Matrix;
|
import android.opengl.Matrix;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.Pair;
|
||||||
import com.google.mediapipe.framework.TextureFrame;
|
import com.google.mediapipe.framework.TextureFrame;
|
||||||
import com.google.mediapipe.glutil.CommonShaders;
|
import com.google.mediapipe.glutil.CommonShaders;
|
||||||
import com.google.mediapipe.glutil.ShaderUtil;
|
import com.google.mediapipe.glutil.ShaderUtil;
|
||||||
|
@ -92,6 +93,9 @@ public class GlSurfaceViewRenderer implements GLSurfaceView.Renderer {
|
||||||
private boolean shouldClampToBorder = false;
|
private boolean shouldClampToBorder = false;
|
||||||
private Scale scale = Scale.FILL;
|
private Scale scale = Scale.FILL;
|
||||||
|
|
||||||
|
private float zoomFactor = 1.0f;
|
||||||
|
private Pair<Float, Float> zoomLocation = new Pair<>(0.5f, 0.5f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the {@link BitmapCaptureListener}.
|
* Sets the {@link BitmapCaptureListener}.
|
||||||
*/
|
*/
|
||||||
|
@ -294,6 +298,15 @@ public class GlSurfaceViewRenderer implements GLSurfaceView.Renderer {
|
||||||
float textureBottom = (1.0f - scaleHeight) * alignmentVertical;
|
float textureBottom = (1.0f - scaleHeight) * alignmentVertical;
|
||||||
float textureTop = textureBottom + scaleHeight;
|
float textureTop = textureBottom + scaleHeight;
|
||||||
|
|
||||||
|
Pair<Float, Float> currentZoomLocation = this.zoomLocation;
|
||||||
|
float zoomLocationX = currentZoomLocation.first;
|
||||||
|
float zoomLocationY = currentZoomLocation.second;
|
||||||
|
|
||||||
|
textureLeft = (textureLeft - 0.5f) / zoomFactor + zoomLocationX;
|
||||||
|
textureRight = (textureRight - 0.5f) / zoomFactor + zoomLocationX;
|
||||||
|
textureBottom = (textureBottom - 0.5f) / zoomFactor + zoomLocationY;
|
||||||
|
textureTop = (textureTop - 0.5f) / zoomFactor + zoomLocationY;
|
||||||
|
|
||||||
return new float[] {textureLeft, textureRight, textureBottom, textureTop};
|
return new float[] {textureLeft, textureRight, textureBottom, textureTop};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,6 +393,22 @@ public class GlSurfaceViewRenderer implements GLSurfaceView.Renderer {
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Zoom factor applied to the frame, must not be 0. */
|
||||||
|
public void setZoomFactor(float zoomFactor) {
|
||||||
|
if (zoomFactor == 0.f) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.zoomFactor = zoomFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Location where to apply the zooming of the frame to. Default is 0.5, 0.5 (scaling is applied to
|
||||||
|
* the center).
|
||||||
|
*/
|
||||||
|
public void setZoomLocation(float zoomLocationX, float zoomLocationY) {
|
||||||
|
this.zoomLocation = new Pair<>(zoomLocationX, zoomLocationY);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isExternalTexture() {
|
private boolean isExternalTexture() {
|
||||||
return textureTarget == GLES11Ext.GL_TEXTURE_EXTERNAL_OES;
|
return textureTarget == GLES11Ext.GL_TEXTURE_EXTERNAL_OES;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user