500 lines
24 KiB
Java
500 lines
24 KiB
Java
package com.kofax.kmc.ken.engines.gpu;
|
|
|
|
import android.graphics.Point;
|
|
import android.graphics.Rect;
|
|
import android.opengl.GLES20;
|
|
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
|
import com.google.common.primitives.UnsignedBytes;
|
|
import com.kofax.kmc.ken.engines.data.DocumentDetectionSettings;
|
|
import com.kofax.kmc.ken.engines.gpu.shaders.BarnsenShader;
|
|
import com.kofax.kmc.ken.engines.gpu.shaders.GlobalThresholdShader;
|
|
import com.kofax.kmc.ken.engines.gpu.shaders.LocalAdaptiveThresholdShader;
|
|
import com.kofax.kmc.ken.engines.gpu.shaders.PassThroughShader;
|
|
import com.kofax.kmc.ken.engines.gpu.shaders.RgbSobelShader;
|
|
import com.kofax.kmc.ken.engines.gpu.shaders.ScaleHistogramShader;
|
|
import com.kofax.kmc.kut.utilities.RectUtil;
|
|
import java.nio.Buffer;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteOrder;
|
|
import java.nio.FloatBuffer;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes3.dex */
|
|
public abstract class e extends ImageProcessor {
|
|
static final float[] fH = {-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f};
|
|
protected OpenGLESContextManager fD;
|
|
private FloatBuffer fG;
|
|
private FloatBuffer fK;
|
|
protected LocalAdaptiveThresholdShader gA;
|
|
protected BarnsenShader gB;
|
|
protected PassThroughShader gg;
|
|
protected RgbSobelShader gx;
|
|
protected GlobalThresholdShader gy;
|
|
protected ScaleHistogramShader gz;
|
|
private FrameBufferTexture fY = null;
|
|
private FrameBufferTexture gC = null;
|
|
private FrameBufferTexture gD = null;
|
|
private FrameBufferTexture gE = null;
|
|
private ByteBuffer gc = null;
|
|
private ByteBuffer gd = null;
|
|
protected float[] gF = null;
|
|
private int fO = 0;
|
|
private int fP = 0;
|
|
private int fZ = 0;
|
|
private int ga = 0;
|
|
|
|
@Override // com.kofax.kmc.ken.engines.gpu.ImageProcessor
|
|
public void processByteData(byte[] bArr, int i, int i2) {
|
|
}
|
|
|
|
public e() {
|
|
float[] fArr = fH;
|
|
FloatBuffer asFloatBuffer = ByteBuffer.allocateDirect(fArr.length << 2).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
|
this.fG = asFloatBuffer;
|
|
asFloatBuffer.put(fArr).position(0);
|
|
FloatBuffer asFloatBuffer2 = ByteBuffer.allocateDirect(TextureRotationUtil.TEXTURE_ROTATED_270.length << 2).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
|
this.fK = asFloatBuffer2;
|
|
asFloatBuffer2.clear();
|
|
this.fK.put(TextureRotationUtil.TEXTURE_ROTATED_270).position(0);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: protected */
|
|
public void a(FrameBufferTexture frameBufferTexture) {
|
|
this.gF = null;
|
|
V();
|
|
FrameBufferTexture frameBufferTexture2 = this.fY;
|
|
if (frameBufferTexture2 != null) {
|
|
d(frameBufferTexture, frameBufferTexture2);
|
|
boolean e = e(this.fY, this.gC);
|
|
FrameBufferTexture frameBufferTexture3 = this.gC;
|
|
this.gE = frameBufferTexture3;
|
|
if (e) {
|
|
this.gF = b(frameBufferTexture3, (ByteBuffer) null, GPUSettings.getSettings().enableRgbSobelOLC);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: protected */
|
|
public void b(FrameBufferTexture frameBufferTexture) {
|
|
this.gF = null;
|
|
V();
|
|
FrameBufferTexture frameBufferTexture2 = this.fY;
|
|
if (frameBufferTexture2 != null) {
|
|
if (!f(frameBufferTexture, frameBufferTexture2)) {
|
|
this.gE = this.fY;
|
|
return;
|
|
}
|
|
ByteBuffer g = g(this.fY, this.gC);
|
|
FrameBufferTexture frameBufferTexture3 = this.gC;
|
|
this.gE = frameBufferTexture3;
|
|
this.gF = b(frameBufferTexture3, g, GPUSettings.getSettings().enableGlobalAdaptiveThresholdOLC);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: protected */
|
|
public void c(FrameBufferTexture frameBufferTexture) {
|
|
this.gF = null;
|
|
V();
|
|
FrameBufferTexture frameBufferTexture2 = this.fY;
|
|
if (frameBufferTexture2 != null) {
|
|
if (!f(frameBufferTexture, frameBufferTexture2)) {
|
|
this.gE = this.fY;
|
|
return;
|
|
}
|
|
FrameBufferTexture frameBufferTexture3 = this.fY;
|
|
a(frameBufferTexture3, frameBufferTexture3, this.gC);
|
|
FrameBufferTexture frameBufferTexture4 = this.fY;
|
|
this.gE = frameBufferTexture4;
|
|
this.gF = b(frameBufferTexture4, (ByteBuffer) null, GPUSettings.getSettings().enableLocalAdaptiveThresholdOLC);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: protected */
|
|
public void d(FrameBufferTexture frameBufferTexture) {
|
|
this.gF = null;
|
|
V();
|
|
FrameBufferTexture frameBufferTexture2 = this.fY;
|
|
if (frameBufferTexture2 != null) {
|
|
b(frameBufferTexture, frameBufferTexture2, this.gC);
|
|
FrameBufferTexture frameBufferTexture3 = this.fY;
|
|
this.gE = frameBufferTexture3;
|
|
this.gF = b(frameBufferTexture3, (ByteBuffer) null, GPUSettings.getSettings().enableBarnsenOLC);
|
|
}
|
|
}
|
|
|
|
@Override // com.kofax.kmc.ken.engines.gpu.ImageProcessor
|
|
public void destroy() {
|
|
FrameBufferTexture frameBufferTexture = this.fY;
|
|
if (frameBufferTexture != null) {
|
|
frameBufferTexture.destroy();
|
|
this.fY = null;
|
|
}
|
|
FrameBufferTexture frameBufferTexture2 = this.gC;
|
|
if (frameBufferTexture2 != null) {
|
|
frameBufferTexture2.destroy();
|
|
this.gC = null;
|
|
}
|
|
FrameBufferTexture frameBufferTexture3 = this.gD;
|
|
if (frameBufferTexture3 != null) {
|
|
frameBufferTexture3.destroy();
|
|
this.gD = null;
|
|
}
|
|
RgbSobelShader rgbSobelShader = this.gx;
|
|
if (rgbSobelShader != null) {
|
|
rgbSobelShader.destroy();
|
|
this.gx = null;
|
|
}
|
|
GlobalThresholdShader globalThresholdShader = this.gy;
|
|
if (globalThresholdShader != null) {
|
|
globalThresholdShader.destroy();
|
|
this.gy = null;
|
|
}
|
|
ScaleHistogramShader scaleHistogramShader = this.gz;
|
|
if (scaleHistogramShader != null) {
|
|
scaleHistogramShader.destroy();
|
|
this.gz = null;
|
|
}
|
|
LocalAdaptiveThresholdShader localAdaptiveThresholdShader = this.gA;
|
|
if (localAdaptiveThresholdShader != null) {
|
|
localAdaptiveThresholdShader.destroy();
|
|
this.gA = null;
|
|
}
|
|
BarnsenShader barnsenShader = this.gB;
|
|
if (barnsenShader != null) {
|
|
barnsenShader.destroy();
|
|
this.gB = null;
|
|
}
|
|
PassThroughShader passThroughShader = this.gg;
|
|
if (passThroughShader != null) {
|
|
passThroughShader.destroy();
|
|
this.gg = null;
|
|
}
|
|
}
|
|
|
|
private void d(FrameBufferTexture frameBufferTexture, FrameBufferTexture frameBufferTexture2) {
|
|
GLES20.glBindFramebuffer(36160, frameBufferTexture2.mFrameBuffer);
|
|
GLES20.glViewport(0, 0, frameBufferTexture2.mWidth, frameBufferTexture2.mHeight);
|
|
RgbSobelShader rgbSobelShader = this.gx;
|
|
GLES20.glUseProgram(rgbSobelShader.getProgram());
|
|
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);
|
|
float f = GPUSettings.getSettings().rgbSobelEdgeStrength;
|
|
GLES20.glUniform1f(rgbSobelShader.getTexelWidthUniform(), 1.0f / frameBufferTexture.mWidth);
|
|
GLES20.glUniform1f(rgbSobelShader.getTexelHeightUniform(), 1.0f / frameBufferTexture.mHeight);
|
|
GLES20.glUniform1f(rgbSobelShader.getEdgeStrengthUniform(), f);
|
|
GLES20.glDrawArrays(5, 0, 4);
|
|
GLES20.glBindTexture(3553, 0);
|
|
}
|
|
|
|
private boolean e(FrameBufferTexture frameBufferTexture, FrameBufferTexture frameBufferTexture2) {
|
|
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();
|
|
int i = frameBufferTexture.mWidth << 2;
|
|
int i2 = 0;
|
|
int i3 = 0;
|
|
for (int i4 = 0; i4 < frameBufferTexture.mHeight; i4++) {
|
|
for (int i5 = 0; i5 < i; i5 += 4) {
|
|
int i6 = array[i3 + i5] & UnsignedBytes.MAX_VALUE;
|
|
if (i2 < i6) {
|
|
i2 = i6;
|
|
}
|
|
}
|
|
i3 += i;
|
|
}
|
|
float f = i2;
|
|
float f2 = f / 255.0f >= GPUSettings.getSettings().contrastThreshold ? 255.0f / f : BitmapDescriptorFactory.HUE_RED;
|
|
GLES20.glBindFramebuffer(36160, frameBufferTexture2.mFrameBuffer);
|
|
GLES20.glViewport(0, 0, frameBufferTexture2.mWidth, frameBufferTexture2.mHeight);
|
|
GlobalThresholdShader globalThresholdShader = this.gy;
|
|
GLES20.glUseProgram(globalThresholdShader.getProgram());
|
|
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.glUniform1f(globalThresholdShader.getThresholdUniform(), GPUSettings.getSettings().edgeLowThreshold);
|
|
GLES20.glUniform1f(globalThresholdShader.getScaleFactorUniform(), f2);
|
|
GLES20.glDrawArrays(5, 0, 4);
|
|
GLES20.glBindTexture(3553, 0);
|
|
return ((double) f2) > 0.0d;
|
|
}
|
|
|
|
private float[] b(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[] fArr = new float[8];
|
|
if (this.mSettings == null) {
|
|
this.mSettings = new DocumentDetectionSettings();
|
|
}
|
|
Rect createTargetRect = RectUtil.createTargetRect(this.mSettings.getTargetFramePaddingPercent(), this.mSettings.getTargetFrameAspectRatio(), this.mSettings.getCenterPoint() != null ? new Point((this.mSettings.getCenterPoint().x * frameBufferTexture.mWidth) / this.fO, (this.mSettings.getCenterPoint().y * frameBufferTexture.mHeight) / this.fP) : null, frameBufferTexture.mWidth, frameBufferTexture.mHeight);
|
|
if (!GPUImageNativeLibrary.DetectBounds(bArr, frameBufferTexture.mWidth, frameBufferTexture.mHeight, Math.min(((createTargetRect.width() * createTargetRect.height()) / (frameBufferTexture.mWidth * frameBufferTexture.mHeight)) * 0.5f, GPUSettings.getSettings().relativeAreaRatio), GPUSettings.getSettings().maxAspectRatio, (float) this.mSettings.getTargetFrameAspectRatio(), z, fArr)) {
|
|
return null;
|
|
}
|
|
fArr[0] = this.fO * (fArr[0] / frameBufferTexture.mWidth);
|
|
fArr[1] = this.fP * (fArr[1] / frameBufferTexture.mHeight);
|
|
fArr[2] = this.fO * (fArr[2] / frameBufferTexture.mWidth);
|
|
fArr[3] = this.fP * (fArr[3] / frameBufferTexture.mHeight);
|
|
fArr[4] = this.fO * (fArr[4] / frameBufferTexture.mWidth);
|
|
fArr[5] = this.fP * (fArr[5] / frameBufferTexture.mHeight);
|
|
fArr[6] = this.fO * (fArr[6] / frameBufferTexture.mWidth);
|
|
fArr[7] = this.fP * (fArr[7] / frameBufferTexture.mHeight);
|
|
return fArr;
|
|
}
|
|
|
|
private void V() {
|
|
int i;
|
|
int i2;
|
|
if (this.fY != null || (i = this.fZ) == 0 || (i2 = this.ga) == 0) {
|
|
return;
|
|
}
|
|
this.fY = new FrameBufferTexture(i, i2);
|
|
this.gC = new FrameBufferTexture(this.fZ, this.ga);
|
|
OpenGLESContextManager openGLESContextManager = new OpenGLESContextManager();
|
|
this.fD = openGLESContextManager;
|
|
this.gx = new RgbSobelShader(openGLESContextManager);
|
|
this.gy = new GlobalThresholdShader(this.fD);
|
|
this.gz = new ScaleHistogramShader(this.fD);
|
|
this.gA = new LocalAdaptiveThresholdShader(this.fD);
|
|
this.gB = new BarnsenShader(this.fD);
|
|
this.gg = new PassThroughShader(this.fD);
|
|
}
|
|
|
|
private boolean f(FrameBufferTexture frameBufferTexture, FrameBufferTexture frameBufferTexture2) {
|
|
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();
|
|
int i = frameBufferTexture.mWidth << 2;
|
|
int i2 = 0;
|
|
int i3 = 0;
|
|
int i4 = 255;
|
|
for (int i5 = 0; i5 < frameBufferTexture.mHeight; i5++) {
|
|
for (int i6 = 0; i6 < i; i6 += 4) {
|
|
int i7 = array[i3 + i6] & UnsignedBytes.MAX_VALUE;
|
|
if (i7 > i2) {
|
|
i2 = i7;
|
|
}
|
|
if (i7 < i4) {
|
|
i4 = i7;
|
|
}
|
|
}
|
|
i3 += i;
|
|
}
|
|
float f = i2 - i4;
|
|
float f2 = f / 255.0f >= GPUSettings.getSettings().contrastThreshold ? 255.0f / f : 0.0f;
|
|
GLES20.glBindFramebuffer(36160, frameBufferTexture2.mFrameBuffer);
|
|
GLES20.glViewport(0, 0, frameBufferTexture2.mWidth, frameBufferTexture2.mHeight);
|
|
ScaleHistogramShader scaleHistogramShader = this.gz;
|
|
GLES20.glUseProgram(scaleHistogramShader.getProgram());
|
|
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.glUniform1f(scaleHistogramShader.getMinValueUniform(), i4 / 255.0f);
|
|
GLES20.glUniform1f(scaleHistogramShader.getScaleFactorUniform(), f2);
|
|
GLES20.glDrawArrays(5, 0, 4);
|
|
GLES20.glBindTexture(3553, 0);
|
|
return f2 > BitmapDescriptorFactory.HUE_RED;
|
|
}
|
|
|
|
private void a(FrameBufferTexture frameBufferTexture, FrameBufferTexture frameBufferTexture2, FrameBufferTexture frameBufferTexture3) {
|
|
LocalAdaptiveThresholdShader localAdaptiveThresholdShader = this.gA;
|
|
GLES20.glBindFramebuffer(36160, frameBufferTexture3.mFrameBuffer);
|
|
GLES20.glViewport(0, 0, frameBufferTexture3.mWidth, frameBufferTexture3.mHeight);
|
|
localAdaptiveThresholdShader.setRadius(GPUSettings.getSettings().localAdaptiveThresholdRadius);
|
|
GLES20.glUseProgram(localAdaptiveThresholdShader.getFirstPassProgram());
|
|
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);
|
|
float f = GPUSettings.getSettings().localAdaptiveThreshold;
|
|
GLES20.glUniform1f(localAdaptiveThresholdShader.getFirstPassTexelWidthUniform(), 1.0f / frameBufferTexture.mWidth);
|
|
GLES20.glUniform1f(localAdaptiveThresholdShader.getFirstPassTexelHeightUniform(), BitmapDescriptorFactory.HUE_RED);
|
|
GLES20.glUniform1f(localAdaptiveThresholdShader.getFirstPassThresholdUniform(), f);
|
|
GLES20.glDrawArrays(5, 0, 4);
|
|
GLES20.glBindTexture(3553, 0);
|
|
GLES20.glBindFramebuffer(36160, frameBufferTexture2.mFrameBuffer);
|
|
GLES20.glViewport(0, 0, frameBufferTexture2.mWidth, frameBufferTexture2.mHeight);
|
|
GLES20.glUseProgram(localAdaptiveThresholdShader.getSecondPassProgram());
|
|
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, frameBufferTexture3.mTexture);
|
|
float f2 = GPUSettings.getSettings().localAdaptiveThreshold;
|
|
GLES20.glUniform1f(localAdaptiveThresholdShader.getSecondPassTexelWidthUniform(), BitmapDescriptorFactory.HUE_RED);
|
|
GLES20.glUniform1f(localAdaptiveThresholdShader.getSecondPassTexelHeightUniform(), 1.0f / frameBufferTexture3.mHeight);
|
|
GLES20.glUniform1f(localAdaptiveThresholdShader.getSecondPassThresholdUniform(), f2);
|
|
GLES20.glDrawArrays(5, 0, 4);
|
|
GLES20.glBindTexture(3553, 0);
|
|
}
|
|
|
|
private ByteBuffer g(FrameBufferTexture frameBufferTexture, FrameBufferTexture frameBufferTexture2) {
|
|
int i;
|
|
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);
|
|
}
|
|
if (this.gd == null) {
|
|
ByteBuffer allocateDirect2 = ByteBuffer.allocateDirect(frameBufferTexture.mWidth * frameBufferTexture.mHeight);
|
|
this.gd = allocateDirect2;
|
|
allocateDirect2.order(ByteOrder.nativeOrder());
|
|
}
|
|
GLES20.glReadPixels(0, 0, frameBufferTexture.mWidth, frameBufferTexture.mHeight, 6408, 5121, this.gc);
|
|
byte[] array = this.gc.array();
|
|
byte[] array2 = this.gd.array();
|
|
int i2 = frameBufferTexture.mWidth * frameBufferTexture.mHeight;
|
|
int i3 = 0;
|
|
int i4 = 0;
|
|
while (i3 < i2) {
|
|
array2[i3] = array[i4];
|
|
i3++;
|
|
i4 += 4;
|
|
}
|
|
GPUImageNativeLibrary.OtsyThreshold(array2, frameBufferTexture.mWidth, frameBufferTexture.mHeight, 30.0f, 255.0f);
|
|
if (GPUSettings.getSettings().showProcessedImageAndBounds) {
|
|
if (this.gD == null) {
|
|
this.gD = new FrameBufferTexture(this.fZ, this.ga);
|
|
}
|
|
if (this.gD != null) {
|
|
int i5 = 0;
|
|
for (int i6 = 0; i6 < i2; i6++) {
|
|
if (array2[i6] != 0) {
|
|
array[i5] = -1;
|
|
array[i5 + 1] = -1;
|
|
array[i5 + 2] = -1;
|
|
i = i5 + 4;
|
|
array[i5 + 3] = -1;
|
|
} else {
|
|
array[i5] = 0;
|
|
array[i5 + 1] = 0;
|
|
array[i5 + 2] = 0;
|
|
i = i5 + 4;
|
|
array[i5 + 3] = -1;
|
|
}
|
|
i5 = i;
|
|
}
|
|
this.gD.setTextureBuffer(this.gc);
|
|
GLES20.glBindFramebuffer(36160, frameBufferTexture2.mFrameBuffer);
|
|
GLES20.glViewport(0, 0, frameBufferTexture2.mWidth, frameBufferTexture2.mHeight);
|
|
GLES20.glUseProgram(this.gg.getProgram());
|
|
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, this.gD.mTexture);
|
|
GLES20.glDrawArrays(5, 0, 4);
|
|
GLES20.glBindTexture(3553, 0);
|
|
}
|
|
}
|
|
return this.gd;
|
|
}
|
|
|
|
private void b(FrameBufferTexture frameBufferTexture, FrameBufferTexture frameBufferTexture2, FrameBufferTexture frameBufferTexture3) {
|
|
BarnsenShader barnsenShader = this.gB;
|
|
GLES20.glBindFramebuffer(36160, frameBufferTexture3.mFrameBuffer);
|
|
GLES20.glViewport(0, 0, frameBufferTexture3.mWidth, frameBufferTexture3.mHeight);
|
|
barnsenShader.setRadius(GPUSettings.getSettings().barnsenRadius);
|
|
GLES20.glUseProgram(barnsenShader.getFirstPassProgram());
|
|
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);
|
|
float f = GPUSettings.getSettings().barnsenThreshold;
|
|
GLES20.glUniform1f(barnsenShader.getFirstPassTexelWidthUniform(), 1.0f / frameBufferTexture.mWidth);
|
|
GLES20.glUniform1f(barnsenShader.getFirstPassTexelHeightUniform(), BitmapDescriptorFactory.HUE_RED);
|
|
GLES20.glUniform1f(barnsenShader.getFirstPassThresholdUniform(), f);
|
|
GLES20.glDrawArrays(5, 0, 4);
|
|
GLES20.glBindTexture(3553, 0);
|
|
GLES20.glBindFramebuffer(36160, frameBufferTexture2.mFrameBuffer);
|
|
GLES20.glViewport(0, 0, frameBufferTexture2.mWidth, frameBufferTexture2.mHeight);
|
|
GLES20.glUseProgram(barnsenShader.getSecondPassProgram());
|
|
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, frameBufferTexture3.mTexture);
|
|
float f2 = GPUSettings.getSettings().barnsenThreshold;
|
|
GLES20.glUniform1f(barnsenShader.getSecondPassTexelWidthUniform(), BitmapDescriptorFactory.HUE_RED);
|
|
GLES20.glUniform1f(barnsenShader.getSecondPassTexelHeightUniform(), 1.0f / frameBufferTexture3.mHeight);
|
|
GLES20.glUniform1f(barnsenShader.getSecondPassThresholdUniform(), f2);
|
|
GLES20.glDrawArrays(5, 0, 4);
|
|
GLES20.glBindTexture(3553, 0);
|
|
}
|
|
|
|
@Override // com.kofax.kmc.ken.engines.gpu.ImageProcessor
|
|
public void setResizedResolution(int i, int i2) {
|
|
this.fZ = i;
|
|
this.ga = i2;
|
|
}
|
|
|
|
@Override // com.kofax.kmc.ken.engines.gpu.ImageProcessor
|
|
public void setPreviewResoution(int i, int i2) {
|
|
this.fO = i;
|
|
this.fP = i2;
|
|
}
|
|
|
|
@Override // com.kofax.kmc.ken.engines.gpu.ImageProcessor
|
|
public FrameBufferTexture getProcessedTexture() {
|
|
return this.gE;
|
|
}
|
|
|
|
@Override // com.kofax.kmc.ken.engines.gpu.ImageProcessor
|
|
public float[] getBounds() {
|
|
return this.gF;
|
|
}
|
|
}
|