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

444 lines
18 KiB
Java

package com.kofax.kmc.ken.engines.gpu;
import android.graphics.Rect;
import android.opengl.GLES20;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.kofax.kmc.ken.engines.gpu.shaders.GrayScaleAndLaplacianShader;
import com.kofax.kmc.ken.engines.gpu.shaders.GraySobelShader;
import com.kofax.kmc.ken.engines.gpu.shaders.PassThroughShader;
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 b 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 ByteBuffer gb;
protected PassThroughShader gg;
protected GraySobelShader gh;
protected GrayScaleAndLaplacianShader gi;
private Rect gk;
private boolean gl;
private boolean gm;
public final Object fE = new Object();
private boolean fF = false;
private ScaleType fV = ScaleType.CENTER_CROP;
private FrameBufferTexture fW = null;
private FrameBufferTexture fX = null;
private FrameBufferTexture fY = null;
private int fZ = 0;
private int ga = 0;
private ByteBuffer gc = null;
private ByteBuffer gd = null;
private int ge = -1;
private int gf = -1;
private int[] gj = null;
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 b() {
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);
this.fK = ByteBuffer.allocateDirect(TextureRotationUtil.TEXTURE_NO_ROTATION.length << 2).order(ByteOrder.nativeOrder()).asFloatBuffer();
FloatBuffer asFloatBuffer3 = ByteBuffer.allocateDirect(TextureRotationUtil.TEXTURE_ROTATED_270.length << 2).order(ByteOrder.nativeOrder()).asFloatBuffer();
this.fL = asFloatBuffer3;
asFloatBuffer3.clear();
asFloatBuffer3.put(TextureRotationUtil.TEXTURE_ROTATED_270).position(0);
setRotation(Rotation.NORMAL);
}
@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();
}
}
private void M() {
int i;
int i2;
if (this.fD == null) {
OpenGLESContextManager openGLESContextManager = new OpenGLESContextManager();
this.fD = openGLESContextManager;
this.gg = new PassThroughShader(openGLESContextManager);
}
if (this.fW == null && this.fO != 0 && this.fP != 0) {
float f = GPUSettings.getSettings().scaleFactor;
int i3 = (int) (this.fO * f);
this.fZ = i3;
if (i3 % 2 != 0) {
this.fZ = i3 + 1;
}
int i4 = (int) (f * this.fP);
this.ga = i4;
if (i4 % 2 != 0) {
this.ga = i4 + 1;
}
this.fW = new FrameBufferTexture(this.fZ, this.ga);
}
if (this.fY != null || (i = this.fZ) == 0 || (i2 = this.ga) == 0) {
return;
}
this.fY = new FrameBufferTexture(i, i2);
OpenGLESContextManager openGLESContextManager2 = new OpenGLESContextManager();
this.fD = openGLESContextManager2;
this.gh = new GraySobelShader(openGLESContextManager2);
this.gi = new GrayScaleAndLaplacianShader(this.fD);
}
private void N() {
int[] iArr = new int[1];
int[] iArr2 = new int[4];
GLES20.glGetIntegerv(36006, iArr, 0);
GLES20.glGetIntegerv(2978, iArr2, 0);
GLES20.glBindFramebuffer(36160, this.fW.mFrameBuffer);
GLES20.glViewport(0, 0, this.fW.mWidth, this.fW.mHeight);
O();
GLES20.glBindFramebuffer(36160, iArr[0]);
GLES20.glViewport(iArr2[0], iArr2[1], iArr2[2], iArr2[3]);
}
private void O() {
GLES20.glUseProgram(this.gg.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.glDrawArrays(5, 0, 4);
GLES20.glBindTexture(3553, 0);
}
private void b(int i) {
if (i == -1) {
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, i);
GLES20.glDrawArrays(5, 0, 4);
GLES20.glBindTexture(3553, 0);
}
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.fS.isEmpty()) {
a(new Runnable(this, bArr, i, i2) { // from class: com.kofax.kmc.ken.engines.gpu.b.1
final byte[] gn;
final b go;
final int h;
final int i;
{
this.go = this;
this.gn = bArr;
this.h = i;
this.i = i2;
}
@Override // java.lang.Runnable
public void run() {
this.go.gb.clear();
this.go.gb.put(this.gn, 0, this.h * this.i);
this.go.gb.position(0);
if (this.go.ge != -1) {
GLES20.glBindTexture(3553, this.go.ge);
GLES20.glTexSubImage2D(3553, 0, 0, 0, this.h, this.i, 6409, 5121, this.go.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.go.gb);
this.go.ge = iArr[0];
}
this.go.fF = true;
int i3 = this.go.fO;
int i4 = this.h;
if (i3 != i4) {
this.go.fO = i4;
this.go.fP = this.i;
this.go.P();
}
}
});
}
}
@Override // android.opengl.GLSurfaceView.Renderer
public void onDrawFrame(GL10 gl10) {
synchronized (this) {
a(this.fS);
M();
if (this.fF) {
if (this.ge != -1 && this.fW != null) {
N();
}
this.gj = null;
this.fX = null;
if (this.fW != null) {
int[] iArr = new int[1];
int[] iArr2 = new int[4];
GLES20.glGetIntegerv(36006, iArr, 0);
GLES20.glGetIntegerv(2978, iArr2, 0);
FrameBufferTexture frameBufferTexture = this.fY;
if (frameBufferTexture != null) {
if (this.gl) {
b(this.fW, frameBufferTexture);
} else {
a(this.fW, frameBufferTexture);
}
FrameBufferTexture frameBufferTexture2 = this.fY;
this.fX = frameBufferTexture2;
this.gj = a(frameBufferTexture2, (ByteBuffer) null, GPUSettings.getSettings().enableRgbSobelOLC);
}
GLES20.glBindFramebuffer(36160, iArr[0]);
GLES20.glViewport(iArr2[0], iArr2[1], iArr2[2], iArr2[3]);
}
}
if (GPUSettings.getSettings().showProcessedImageAndBounds) {
if (this.fX == null) {
this.fX = this.fW;
}
b(this.fX.mTexture);
}
a(this.fT);
}
}
@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;
}
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;
}
PassThroughShader passThroughShader = this.gg;
if (passThroughShader != null) {
passThroughShader.destroy();
this.gg = null;
}
FrameBufferTexture frameBufferTexture2 = this.fY;
if (frameBufferTexture2 != null) {
frameBufferTexture2.destroy();
this.fY = null;
}
GraySobelShader graySobelShader = this.gh;
if (graySobelShader != null) {
graySobelShader.destroy();
this.gh = null;
}
GrayScaleAndLaplacianShader grayScaleAndLaplacianShader = this.gi;
if (grayScaleAndLaplacianShader != null) {
grayScaleAndLaplacianShader.destroy();
this.gi = 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);
}
}
private void a(FrameBufferTexture frameBufferTexture, FrameBufferTexture frameBufferTexture2) {
GLES20.glBindFramebuffer(36160, frameBufferTexture2.mFrameBuffer);
GLES20.glViewport(0, 0, frameBufferTexture2.mWidth, frameBufferTexture2.mHeight);
GraySobelShader graySobelShader = this.gh;
GLES20.glUseProgram(graySobelShader.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(graySobelShader.getTexelWidthUniform(), 1.0f / frameBufferTexture.mWidth);
GLES20.glUniform1f(graySobelShader.getTexelHeightUniform(), 1.0f / frameBufferTexture.mHeight);
GLES20.glUniform1f(graySobelShader.getEdgeStrengthUniform(), 0.5f);
GLES20.glDrawArrays(5, 0, 4);
GLES20.glBindTexture(3553, 0);
}
private void b(FrameBufferTexture frameBufferTexture, FrameBufferTexture frameBufferTexture2) {
GLES20.glBindFramebuffer(36160, frameBufferTexture2.mFrameBuffer);
GLES20.glViewport(0, 0, frameBufferTexture2.mWidth, frameBufferTexture2.mHeight);
GrayScaleAndLaplacianShader grayScaleAndLaplacianShader = this.gi;
GLES20.glUseProgram(grayScaleAndLaplacianShader.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(grayScaleAndLaplacianShader.getTexelWidthUniform(), 1.0f / frameBufferTexture.mWidth);
GLES20.glUniform1f(grayScaleAndLaplacianShader.getTexelHeightUniform(), 1.0f / frameBufferTexture.mHeight);
GLES20.glDrawArrays(5, 0, 4);
GLES20.glBindTexture(3553, 0);
}
private int[] a(FrameBufferTexture frameBufferTexture, ByteBuffer byteBuffer, boolean z) {
byte[] bArr;
if (byteBuffer != null) {
bArr = byteBuffer.array();
} else {
GLES20.glFinish();
GLES20.glBindFramebuffer(36160, frameBufferTexture.mFrameBuffer);
GLES20.glViewport(0, 0, frameBufferTexture.mWidth, frameBufferTexture.mHeight);
if (this.gc == null) {
ByteBuffer allocateDirect = ByteBuffer.allocateDirect((frameBufferTexture.mWidth * frameBufferTexture.mHeight) << 2);
this.gc = allocateDirect;
allocateDirect.order(ByteOrder.LITTLE_ENDIAN);
}
GLES20.glReadPixels(0, 0, frameBufferTexture.mWidth, frameBufferTexture.mHeight, 6408, 5121, this.gc);
byte[] array = this.gc.array();
if (this.gd == null) {
ByteBuffer allocateDirect2 = ByteBuffer.allocateDirect(frameBufferTexture.mWidth * frameBufferTexture.mHeight);
this.gd = allocateDirect2;
allocateDirect2.order(ByteOrder.nativeOrder());
}
byte[] array2 = this.gd.array();
int i = frameBufferTexture.mWidth;
int i2 = frameBufferTexture.mHeight;
int i3 = 0;
int i4 = 0;
while (i3 < i * i2) {
array2[i3] = array[i4];
i3++;
i4 += 4;
}
bArr = array2;
}
float f = frameBufferTexture.mWidth / this.fO;
GPUImageNativeLibrary.ContrastFactor(bArr, frameBufferTexture.mWidth, frameBufferTexture.mHeight, new int[]{(int) (this.gk.left * f), (int) (this.gk.top * f), (int) (this.gk.right * f), (int) (this.gk.bottom * f)}, this.gm, GPUSettings.getSettings().contrastFactorDivider, r2);
int[] iArr = {(int) (iArr[0] / f), (int) (iArr[1] / f), (int) (iArr[2] / f), (int) (iArr[3] / f)};
return iArr;
}
@Override // com.kofax.kmc.ken.engines.gpu.IGPUImageRenderer
public void setScaleType(ScaleType scaleType) {
this.fV = scaleType;
}
public Rotation getRotation() {
return this.fU;
}
public void a(Rect rect, boolean z, boolean z2) {
this.gk = rect;
this.gl = z;
this.gm = z2;
}
public int[] L() {
return this.gj;
}
}