what-the-bank/sources/com/kofax/kmc/ken/engines/gpu/f.java

564 lines
23 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.kofax.kmc.ken.engines.gpu;
import android.opengl.GLES20;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.kofax.kmc.ken.engines.data.DocumentDetectionSettings;
import com.kofax.kmc.ken.engines.gpu.shaders.ColorPassThroughShader;
import com.kofax.kmc.ken.engines.gpu.shaders.GrayGaussianBlur3x3Shader;
import com.kofax.kmc.ken.engines.gpu.shaders.PassThroughShader;
import com.kofax.kmc.ken.engines.gpu.shaders.RgbGaussianBlur3x3Shader;
import com.kofax.kmc.ken.engines.gpu.shaders.YuvToRgbShader;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.util.LinkedList;
import java.util.Queue;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
/* loaded from: classes3.dex */
class f implements IGPUImageRenderer {
public static final int fC = -1;
static final float[] fH = {-1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f};
static final float[] fJ = {-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f};
protected OpenGLESContextManager fD;
private final FloatBuffer fG;
private final FloatBuffer fI;
private final FloatBuffer fK;
private final FloatBuffer fL;
private int fM;
private int fN;
private int fO;
private int fP;
protected float fQ;
protected float fR;
private Rotation fU;
private final FloatBuffer gG;
private ByteBuffer gO;
protected ColorPassThroughShader gS;
protected GrayGaussianBlur3x3Shader gT;
protected RgbGaussianBlur3x3Shader gU;
protected YuvToRgbShader gV;
protected ImageProcessor gW;
protected boolean gX;
private ByteBuffer gb;
protected PassThroughShader gg;
public final Object fE = new Object();
private int gf = -1;
private ScaleType fV = ScaleType.CENTER_CROP;
private FrameBufferTexture fW = null;
private FrameBufferTexture gH = null;
private FrameBufferTexture fX = null;
private float[] gF = null;
private int fZ = 0;
private int ga = 0;
private long gI = 0;
private int gJ = 0;
private int gK = 0;
private double gL = 0.0d;
private int gM = 0;
long gN = 0;
private int ge = -1;
private int gP = -1;
private boolean gQ = false;
private boolean gR = false;
private boolean fF = false;
private final Queue<Runnable> fS = new LinkedList();
private final Queue<Runnable> fT = new LinkedList();
private float a(float f, float f2) {
return f != BitmapDescriptorFactory.HUE_RED ? 1.0f - f2 : f2;
}
public f(ImageProcessor imageProcessor) {
this.gW = null;
this.gX = false;
float[] fArr = fH;
FloatBuffer asFloatBuffer = ByteBuffer.allocateDirect(fArr.length << 2).order(ByteOrder.nativeOrder()).asFloatBuffer();
this.fG = asFloatBuffer;
asFloatBuffer.put(fArr).position(0);
float[] fArr2 = fJ;
FloatBuffer asFloatBuffer2 = ByteBuffer.allocateDirect(fArr2.length << 2).order(ByteOrder.nativeOrder()).asFloatBuffer();
this.fI = asFloatBuffer2;
asFloatBuffer2.put(fArr2).position(0);
FloatBuffer asFloatBuffer3 = ByteBuffer.allocateDirect(fArr.length << 2).order(ByteOrder.nativeOrder()).asFloatBuffer();
this.gG = asFloatBuffer3;
asFloatBuffer3.put(fArr).position(0);
this.fK = ByteBuffer.allocateDirect(TextureRotationUtil.TEXTURE_NO_ROTATION.length << 2).order(ByteOrder.nativeOrder()).asFloatBuffer();
FloatBuffer asFloatBuffer4 = ByteBuffer.allocateDirect(TextureRotationUtil.TEXTURE_ROTATED_270.length << 2).order(ByteOrder.nativeOrder()).asFloatBuffer();
this.fL = asFloatBuffer4;
asFloatBuffer4.clear();
asFloatBuffer4.put(TextureRotationUtil.TEXTURE_ROTATED_270).position(0);
setRotation(Rotation.NORMAL);
this.gX = true;
this.gW = imageProcessor;
}
@Override // android.opengl.GLSurfaceView.Renderer
public void onSurfaceCreated(GL10 gl10, EGLConfig eGLConfig) {
GLES20.glClearColor(BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED, 1.0f);
GLES20.glDisable(2929);
}
@Override // android.opengl.GLSurfaceView.Renderer
public void onSurfaceChanged(GL10 gl10, int i, int i2) {
this.fM = i;
this.fN = i2;
GLES20.glViewport(0, 0, i, i2);
P();
synchronized (this.fE) {
this.fE.notifyAll();
}
}
@Override // android.opengl.GLSurfaceView.Renderer
public void onDrawFrame(GL10 gl10) {
synchronized (this) {
long currentTimeMillis = System.currentTimeMillis();
a(this.fS);
M();
if (this.fF) {
if (this.gI == 0) {
this.gI = currentTimeMillis;
}
if (this.ge != -1 && this.fW != null) {
N();
}
this.gF = null;
this.fX = null;
if (this.fW != null && this.gW != null) {
if (this.gX) {
int[] iArr = new int[1];
int[] iArr2 = new int[4];
GLES20.glGetIntegerv(36006, iArr, 0);
GLES20.glGetIntegerv(2978, iArr2, 0);
this.gW.processTexture(this.fW, this.gH);
GLES20.glBindFramebuffer(36160, iArr[0]);
GLES20.glViewport(iArr2[0], iArr2[1], iArr2[2], iArr2[3]);
}
if (GPUSettings.getSettings().showProcessedImageAndBounds) {
this.fX = this.gW.getProcessedTexture();
}
this.gF = this.gW.getBounds();
}
}
long currentTimeMillis2 = System.currentTimeMillis();
if (GPUSettings.getSettings().showProcessedImageAndBounds) {
if (this.fX == null) {
this.fX = this.gQ ? this.gH : this.fW;
}
e(this.fX);
a(this.gF);
}
a(this.fT);
if (this.fF && this.fW != null) {
this.gK++;
int i = this.gM + 1;
this.gM = i;
long j = this.gN + (currentTimeMillis2 - currentTimeMillis);
this.gN = j;
if (i % 50 == 0) {
this.gL = j / i;
this.gN = 0L;
this.gM = 0;
}
long currentTimeMillis3 = System.currentTimeMillis();
long j2 = currentTimeMillis3 - this.gI;
if (j2 >= 1000) {
this.gI = currentTimeMillis3;
this.gJ = (int) ((this.gK * 1000.0f) / ((float) j2));
this.gK = 0;
}
}
}
}
private void M() {
if (this.fD == null) {
OpenGLESContextManager openGLESContextManager = new OpenGLESContextManager();
this.fD = openGLESContextManager;
this.gg = new PassThroughShader(openGLESContextManager);
this.gS = new ColorPassThroughShader(this.fD);
this.gT = new GrayGaussianBlur3x3Shader(this.fD);
this.gU = new RgbGaussianBlur3x3Shader(this.fD);
this.gV = new YuvToRgbShader(this.fD);
}
if (this.fW != null || this.fO == 0 || this.fP == 0) {
return;
}
float f = GPUSettings.getSettings().scaleFactor;
int i = (int) (this.fO * f);
this.fZ = i;
if (i % 2 != 0) {
this.fZ = i + 1;
}
int i2 = (int) (f * this.fP);
this.ga = i2;
if (i2 % 2 != 0) {
this.ga = i2 + 1;
}
ImageProcessor imageProcessor = this.gW;
if (imageProcessor != null) {
imageProcessor.setResizedResolution(this.fZ, this.ga);
}
this.fW = new FrameBufferTexture(this.fZ, this.ga);
if (this.gH == null) {
this.gH = new FrameBufferTexture(this.fZ, this.ga);
}
}
private void N() {
int[] iArr = new int[1];
int[] iArr2 = new int[4];
GLES20.glGetIntegerv(36006, iArr, 0);
GLES20.glGetIntegerv(2978, iArr2, 0);
if (this.gQ) {
GLES20.glBindFramebuffer(36160, this.fW.mFrameBuffer);
GLES20.glViewport(0, 0, this.fW.mWidth, this.fW.mHeight);
W();
h(this.fW, this.gH);
}
if (this.gR) {
GLES20.glBindFramebuffer(36160, this.fW.mFrameBuffer);
GLES20.glViewport(0, 0, this.fW.mWidth, this.fW.mHeight);
X();
}
GLES20.glBindFramebuffer(36160, iArr[0]);
GLES20.glViewport(iArr2[0], iArr2[1], iArr2[2], iArr2[3]);
}
private void W() {
YuvToRgbShader yuvToRgbShader = this.gV;
GLES20.glUseProgram(yuvToRgbShader.getProgram());
GLES20.glVertexAttribPointer(0, 2, 5126, false, 0, (Buffer) this.fI);
GLES20.glEnableVertexAttribArray(0);
GLES20.glVertexAttribPointer(1, 2, 5126, false, 0, (Buffer) this.fL);
GLES20.glEnableVertexAttribArray(1);
GLES20.glActiveTexture(33984);
GLES20.glBindTexture(3553, this.ge);
GLES20.glUniform1i(yuvToRgbShader.getYTextureUniform(), 0);
GLES20.glActiveTexture(33985);
GLES20.glBindTexture(3553, this.gP);
GLES20.glUniform1i(yuvToRgbShader.getUVTextureUniform(), 1);
GLES20.glDrawArrays(5, 0, 4);
GLES20.glActiveTexture(33985);
GLES20.glBindTexture(3553, 0);
GLES20.glActiveTexture(33984);
GLES20.glBindTexture(3553, 0);
}
private void X() {
GrayGaussianBlur3x3Shader grayGaussianBlur3x3Shader = this.gT;
GLES20.glUseProgram(grayGaussianBlur3x3Shader.getProgram());
GLES20.glVertexAttribPointer(0, 2, 5126, false, 0, (Buffer) this.fI);
GLES20.glEnableVertexAttribArray(0);
GLES20.glVertexAttribPointer(1, 2, 5126, false, 0, (Buffer) this.fL);
GLES20.glEnableVertexAttribArray(1);
GLES20.glBindTexture(3553, this.ge);
GLES20.glUniform1f(grayGaussianBlur3x3Shader.getTexelWidthUniform(), 1.0f / this.fO);
GLES20.glUniform1f(grayGaussianBlur3x3Shader.getTexelHeightUniform(), 1.0f / this.fP);
GLES20.glDrawArrays(5, 0, 4);
GLES20.glBindTexture(3553, 0);
}
private void h(FrameBufferTexture frameBufferTexture, FrameBufferTexture frameBufferTexture2) {
GLES20.glBindFramebuffer(36160, frameBufferTexture2.mFrameBuffer);
GLES20.glViewport(0, 0, frameBufferTexture2.mWidth, frameBufferTexture2.mHeight);
RgbGaussianBlur3x3Shader rgbGaussianBlur3x3Shader = this.gU;
GLES20.glUseProgram(rgbGaussianBlur3x3Shader.getProgram());
GLES20.glVertexAttribPointer(0, 2, 5126, false, 0, (Buffer) this.fI);
GLES20.glEnableVertexAttribArray(0);
GLES20.glVertexAttribPointer(1, 2, 5126, false, 0, (Buffer) this.fL);
GLES20.glEnableVertexAttribArray(1);
GLES20.glBindTexture(3553, frameBufferTexture.mTexture);
GLES20.glUniform1f(rgbGaussianBlur3x3Shader.getTexelWidthUniform(), 1.0f / frameBufferTexture.mWidth);
GLES20.glUniform1f(rgbGaussianBlur3x3Shader.getTexelHeightUniform(), 1.0f / frameBufferTexture.mHeight);
GLES20.glDrawArrays(5, 0, 4);
GLES20.glBindTexture(3553, 0);
}
private void e(FrameBufferTexture frameBufferTexture) {
if (frameBufferTexture == null) {
return;
}
GLES20.glUseProgram(this.gg.getProgram());
GLES20.glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
GLES20.glClear(16640);
GLES20.glVertexAttribPointer(0, 2, 5126, false, 0, (Buffer) this.fG);
GLES20.glEnableVertexAttribArray(0);
GLES20.glVertexAttribPointer(1, 2, 5126, false, 0, (Buffer) this.fK);
GLES20.glEnableVertexAttribArray(1);
GLES20.glBindTexture(3553, frameBufferTexture.mTexture);
GLES20.glDrawArrays(5, 0, 4);
GLES20.glBindTexture(3553, 0);
}
private void a(float[] fArr) {
if (fArr == null) {
return;
}
ColorPassThroughShader colorPassThroughShader = this.gS;
GLES20.glUseProgram(colorPassThroughShader.getProgram());
float f = (float) (this.fM * this.fN * 4.0E-6d);
if (f < 2.0f) {
f = 2.0f;
}
GLES20.glLineWidth(f);
GLES20.glUniform4f(colorPassThroughShader.getColorUniform(), 1.0f, BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED, 1.0f);
float f2 = fArr[0];
float f3 = this.fO;
float f4 = fArr[1];
float f5 = this.fP;
float f6 = (f4 * 2.0f) / f5;
float f7 = (fArr[2] * 2.0f) / f3;
float f8 = (fArr[3] * 2.0f) / f5;
float f9 = (fArr[4] * 2.0f) / f3;
float f10 = (fArr[5] * 2.0f) / f5;
float f11 = (fArr[6] * 2.0f) / f3;
float f12 = (fArr[7] * 2.0f) / f5;
float f13 = this.fQ;
float f14 = this.fR;
this.gG.clear();
this.gG.put(new float[]{(((f2 * 2.0f) / f3) - 1.0f) * f13, (1.0f - f6) * f14, (f7 - 1.0f) * f13, (1.0f - f8) * f14, (f9 - 1.0f) * f13, (1.0f - f10) * f14, f13 * (f11 - 1.0f), f14 * (1.0f - f12)}).position(0);
GLES20.glVertexAttribPointer(0, 2, 5126, false, 0, (Buffer) this.gG);
GLES20.glEnableVertexAttribArray(0);
GLES20.glDrawArrays(2, 0, 4);
}
private void a(Queue<Runnable> queue) {
synchronized (queue) {
while (!queue.isEmpty()) {
queue.poll().run();
}
}
}
@Override // com.kofax.kmc.ken.engines.gpu.IGPUImageRenderer
public void onPreviewFrame(byte[] bArr, int i, int i2) {
if (this.gb == null) {
ByteBuffer allocateDirect = ByteBuffer.allocateDirect(i * i2);
this.gb = allocateDirect;
allocateDirect.order(ByteOrder.nativeOrder());
}
if (this.gO == null) {
ByteBuffer allocateDirect2 = ByteBuffer.allocateDirect((i * i2) / 2);
this.gO = allocateDirect2;
allocateDirect2.order(ByteOrder.nativeOrder());
}
if (this.fS.isEmpty()) {
a(new Runnable(this, i, i2, bArr) { // from class: com.kofax.kmc.ken.engines.gpu.f.1
final f gY;
final byte[] gn;
final int h;
final int i;
{
this.gY = this;
this.h = i;
this.i = i2;
this.gn = bArr;
}
@Override // java.lang.Runnable
public void run() {
this.gY.gb.clear();
int remaining = this.gY.gb.remaining();
int i3 = this.h * this.i;
if (remaining < i3) {
this.gY.gb = ByteBuffer.allocateDirect(i3);
this.gY.gb.order(ByteOrder.nativeOrder());
}
this.gY.gb.put(this.gn, 0, this.h * this.i);
this.gY.gb.position(0);
if (this.gY.ge != -1) {
GLES20.glBindTexture(3553, this.gY.ge);
GLES20.glTexSubImage2D(3553, 0, 0, 0, this.h, this.i, 6409, 5121, this.gY.gb);
} else {
int[] iArr = new int[1];
GLES20.glGenTextures(1, iArr, 0);
GLES20.glBindTexture(3553, iArr[0]);
GLES20.glTexParameterf(3553, 10240, 9729.0f);
GLES20.glTexParameterf(3553, 10241, 9729.0f);
GLES20.glTexParameterf(3553, 10242, 33071.0f);
GLES20.glTexParameterf(3553, 10243, 33071.0f);
GLES20.glTexImage2D(3553, 0, 6409, this.h, this.i, 0, 6409, 5121, this.gY.gb);
this.gY.ge = iArr[0];
}
f fVar = this.gY;
fVar.gR = fVar.gW.isGrayScaleInputTextureRequired();
f fVar2 = this.gY;
fVar2.gQ = fVar2.gW.isRGBInputTextureRequired();
if (this.gY.gQ) {
this.gY.gO.clear();
int remaining2 = this.gY.gO.remaining();
int i4 = (this.h * this.i) / 2;
if (remaining2 < i4) {
this.gY.gO = ByteBuffer.allocateDirect(i4);
this.gY.gO.order(ByteOrder.nativeOrder());
}
ByteBuffer byteBuffer = this.gY.gO;
byte[] bArr2 = this.gn;
int i5 = this.h * this.i;
byteBuffer.put(bArr2, i5, i5 / 2);
this.gY.gO.position(0);
if (this.gY.gP != -1) {
GLES20.glBindTexture(3553, this.gY.gP);
GLES20.glTexSubImage2D(3553, 0, 0, 0, this.h / 2, this.i / 2, 6410, 5121, this.gY.gO);
} else {
int[] iArr2 = new int[1];
GLES20.glGenTextures(1, iArr2, 0);
GLES20.glBindTexture(3553, iArr2[0]);
GLES20.glTexParameterf(3553, 10240, 9729.0f);
GLES20.glTexParameterf(3553, 10241, 9729.0f);
GLES20.glTexParameterf(3553, 10242, 33071.0f);
GLES20.glTexParameterf(3553, 10243, 33071.0f);
GLES20.glTexImage2D(3553, 0, 6410, this.h / 2, this.i / 2, 0, 6410, 5121, this.gY.gO);
this.gY.gP = iArr2[0];
}
}
this.gY.fF = true;
if (this.gY.gW != null && !this.gY.gX) {
this.gY.gW.processByteData(this.gn, this.h, this.i);
}
int i6 = this.gY.fO;
int i7 = this.h;
if (i6 != i7) {
this.gY.fO = i7;
this.gY.fP = this.i;
if (this.gY.gW != null) {
this.gY.gW.setPreviewResoution(this.gY.fO, this.gY.fP);
}
this.gY.P();
}
}
});
}
}
@Override // com.kofax.kmc.ken.engines.gpu.IGPUImageRenderer
public final void destroy() {
synchronized (this) {
FrameBufferTexture frameBufferTexture = this.fW;
if (frameBufferTexture != null) {
frameBufferTexture.destroy();
this.fW = null;
}
FrameBufferTexture frameBufferTexture2 = this.gH;
if (frameBufferTexture2 != null) {
frameBufferTexture2.destroy();
this.gH = null;
}
int i = this.gf;
if (i != -1) {
GLES20.glDeleteTextures(1, new int[]{i}, 0);
this.gf = -1;
}
int i2 = this.ge;
if (i2 != -1) {
GLES20.glDeleteTextures(1, new int[]{i2}, 0);
this.ge = -1;
}
int i3 = this.gP;
if (i3 != -1) {
GLES20.glDeleteTextures(1, new int[]{i3}, 0);
this.gP = -1;
}
ImageProcessor imageProcessor = this.gW;
if (imageProcessor != null) {
imageProcessor.destroy();
this.gW = null;
}
PassThroughShader passThroughShader = this.gg;
if (passThroughShader != null) {
passThroughShader.destroy();
this.gg = null;
}
ColorPassThroughShader colorPassThroughShader = this.gS;
if (colorPassThroughShader != null) {
colorPassThroughShader.destroy();
this.gS = null;
}
GrayGaussianBlur3x3Shader grayGaussianBlur3x3Shader = this.gT;
if (grayGaussianBlur3x3Shader != null) {
grayGaussianBlur3x3Shader.destroy();
this.gT = null;
}
RgbGaussianBlur3x3Shader rgbGaussianBlur3x3Shader = this.gU;
if (rgbGaussianBlur3x3Shader != null) {
rgbGaussianBlur3x3Shader.destroy();
this.gU = null;
}
YuvToRgbShader yuvToRgbShader = this.gV;
if (yuvToRgbShader != null) {
yuvToRgbShader.destroy();
this.gV = null;
}
}
}
/* JADX INFO: Access modifiers changed from: private */
public void P() {
float f = this.fM;
float f2 = this.fN;
if (this.fU == Rotation.ROTATION_270 || this.fU == Rotation.ROTATION_90) {
f = this.fN;
f2 = this.fM;
}
float max = Math.max(f / this.fO, f2 / this.fP);
int round = Math.round(this.fO * max);
int round2 = Math.round(this.fP * max);
this.fQ = round / f;
this.fR = round2 / f2;
float[] fArr = fH;
float[] rotation = TextureRotationUtil.getRotation(this.fU, false, false);
if (this.fV == ScaleType.CENTER_CROP) {
float f3 = (1.0f - (1.0f / this.fQ)) / 2.0f;
float f4 = (1.0f - (1.0f / this.fR)) / 2.0f;
rotation = new float[]{a(rotation[0], f3), a(rotation[1], f4), a(rotation[2], f3), a(rotation[3], f4), a(rotation[4], f3), a(rotation[5], f4), a(rotation[6], f3), a(rotation[7], f4)};
} else {
float f5 = fArr[0];
float f6 = this.fR;
float f7 = fArr[1];
float f8 = this.fQ;
fArr = new float[]{f5 / f6, f7 / f8, fArr[2] / f6, fArr[3] / f8, fArr[4] / f6, fArr[5] / f8, fArr[6] / f6, fArr[7] / f8};
}
this.fG.clear();
this.fG.put(fArr).position(0);
this.fK.clear();
this.fK.put(rotation).position(0);
}
@Override // com.kofax.kmc.ken.engines.gpu.IGPUImageRenderer
public void setRotation(Rotation rotation) {
this.fU = rotation;
P();
}
protected void a(Runnable runnable) {
synchronized (this.fS) {
this.fS.add(runnable);
}
}
public void setSettings(DocumentDetectionSettings documentDetectionSettings) {
ImageProcessor imageProcessor = this.gW;
if (imageProcessor != null) {
imageProcessor.setSettings(documentDetectionSettings);
}
}
@Override // com.kofax.kmc.ken.engines.gpu.IGPUImageRenderer
public void setScaleType(ScaleType scaleType) {
this.fV = scaleType;
}
public Rotation getRotation() {
return this.fU;
}
public float[] getBounds() {
return this.gF;
}
}