package com.kofax.kmc.ken.engines.gpu; import android.graphics.Bitmap; import android.opengl.GLSurfaceView; import com.airbnb.deeplinkdispatch.UrlTreeKt; import com.kofax.mobile.sdk._internal.k; import java.nio.IntBuffer; import javax.microedition.khronos.egl.EGL10; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.egl.EGLContext; import javax.microedition.khronos.egl.EGLDisplay; import javax.microedition.khronos.egl.EGLSurface; import javax.microedition.khronos.opengles.GL10; /* loaded from: classes3.dex */ public class PixelBuffer { private static final boolean hh = false; private GLSurfaceView.Renderer hi; private EGL10 hj; private EGLDisplay hk; private EGLConfig[] hl; private EGLConfig hm; private EGLContext hn; private EGLSurface ho; private GL10 hp; String hq; private int mHeight; private int mWidth; private static int a(int i, int i2, int i3, int i4) { return (((i2 - 1) - i4) * i) + i3; } private static int b(int i, int i2, int i3, int i4) { return (i * i4) + i3; } private static int c(int i, int i2, int i3, int i4) { return ((i2 - 1) - i4) + (i2 * i3); } private static int d(int i, int i2, int i3, int i4) { return ((i - 1) - i3) + (((i2 - 1) - i4) * i); } private static int e(int i, int i2, int i3, int i4) { return i4 + (i2 * ((i - 1) - i3)); } public PixelBuffer(int i, int i2) { this.mWidth = i; this.mHeight = i2; int[] iArr = {12375, i, 12374, i2, 12344}; EGL10 egl10 = (EGL10) EGLContext.getEGL(); this.hj = egl10; EGLDisplay eglGetDisplay = egl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); this.hk = eglGetDisplay; this.hj.eglInitialize(eglGetDisplay, new int[2]); EGLConfig Y = Y(); this.hm = Y; this.hn = this.hj.eglCreateContext(this.hk, Y, EGL10.EGL_NO_CONTEXT, new int[]{12440, 2, 12344}); EGLSurface eglCreatePbufferSurface = this.hj.eglCreatePbufferSurface(this.hk, this.hm, iArr); this.ho = eglCreatePbufferSurface; c(this.hj.eglMakeCurrent(this.hk, eglCreatePbufferSurface, eglCreatePbufferSurface, this.hn)); this.hp = (GL10) this.hn.getGL(); this.hq = Thread.currentThread().getName(); } public void destroy() { this.hi = null; EGL10 egl10 = this.hj; if (egl10 != null) { c(egl10.eglMakeCurrent(this.hk, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT)); EGLSurface eGLSurface = this.ho; if (eGLSurface != null) { c(this.hj.eglDestroySurface(this.hk, eGLSurface)); this.ho = null; } if (this.hm != null) { c(this.hj.eglDestroyContext(this.hk, this.hn)); this.hm = null; } EGLDisplay eGLDisplay = this.hk; if (eGLDisplay != null) { c(this.hj.eglTerminate(eGLDisplay)); this.hk = null; } this.hj = null; } } private static void c(boolean z) { if (!z) { throw new AssertionError(); } } public void setRenderer(GLSurfaceView.Renderer renderer) { this.hi = renderer; if (!Thread.currentThread().getName().equals(this.hq)) { k.g(this, "setRenderer: This thread does not own the OpenGL context."); } else { this.hi.onSurfaceCreated(this.hp, this.hm); this.hi.onSurfaceChanged(this.hp, this.mWidth, this.mHeight); } } public void drawFrame() { if (this.hi == null) { k.g(this, "getBitmap: Renderer was not set."); } else if (!Thread.currentThread().getName().equals(this.hq)) { k.g(this, "getBitmap: This thread does not own the OpenGL context."); } else { this.hi.onDrawFrame(this.hp); } } public Bitmap getBitmap(int i) { return c(i); } private EGLConfig Y() { int[] iArr = {12325, 0, 12326, 0, 12324, 8, 12323, 8, 12322, 8, 12321, 8, 12352, 4, 12344}; int[] iArr2 = new int[1]; this.hj.eglChooseConfig(this.hk, iArr, null, 0, iArr2); int i = iArr2[0]; EGLConfig[] eGLConfigArr = new EGLConfig[i]; this.hl = eGLConfigArr; this.hj.eglChooseConfig(this.hk, iArr, eGLConfigArr, i, iArr2); return this.hl[0]; } private void Z() { k.e(this, "Config List {"); for (EGLConfig eGLConfig : this.hl) { int a = a(eGLConfig, 12325); int a2 = a(eGLConfig, 12326); int a3 = a(eGLConfig, 12324); int a4 = a(eGLConfig, 12323); int a5 = a(eGLConfig, 12322); int a6 = a(eGLConfig, 12321); StringBuilder sb = new StringBuilder(" = <"); sb.append(a); sb.append(","); sb.append(a2); sb.append(","); sb.append(a3); sb.append(","); sb.append(a4); sb.append(","); sb.append(a5); sb.append(","); sb.append(a6); sb.append(UrlTreeKt.configurablePathSegmentSuffix); k.e(this, sb.toString()); } k.e(this, UrlTreeKt.componentParamSuffix); } private int a(EGLConfig eGLConfig, int i) { int[] iArr = new int[1]; if (this.hj.eglGetConfigAttrib(this.hk, eGLConfig, i, iArr)) { return iArr[0]; } return 0; } private Bitmap c(int i) { int i2 = this.mWidth * this.mHeight; int[] iArr = new int[i2]; IntBuffer allocate = IntBuffer.allocate(i2); this.hp.glReadPixels(0, 0, this.mWidth, this.mHeight, 6408, 5121, allocate); int[] array = allocate.array(); int i3 = this.mWidth; int i4 = this.mHeight; for (int i5 = 0; i5 < this.mHeight; i5++) { int i6 = 0; while (true) { int i7 = this.mWidth; if (i6 < i7) { if (i == 90) { iArr[c(i7, this.mHeight, i6, i5)] = array[a(this.mWidth, this.mHeight, i6, i5)]; i3 = this.mHeight; i4 = this.mWidth; } else if (i == 180) { iArr[d(i7, this.mHeight, i6, i5)] = array[a(this.mWidth, this.mHeight, i6, i5)]; } else if (i == 270) { iArr[e(i7, this.mHeight, i6, i5)] = array[a(this.mWidth, this.mHeight, i6, i5)]; i3 = this.mHeight; i4 = this.mWidth; } else { iArr[b(i7, this.mHeight, i6, i5)] = array[a(this.mWidth, this.mHeight, i6, i5)]; } i6++; } } } Bitmap createBitmap = Bitmap.createBitmap(i3, i4, Bitmap.Config.ARGB_8888); createBitmap.copyPixelsFromBuffer(IntBuffer.wrap(iArr)); return createBitmap; } }