package com.kofax.kmc.ken.engines; import android.graphics.Bitmap; import android.os.Handler; import com.kofax.android.abc.image_classification.ResultPair; import com.kofax.kmc.ken.engines.data.Image; import com.kofax.kmc.kut.utilities.AppContextProvider; import com.kofax.kmc.kut.utilities.Licensing; import com.kofax.kmc.kut.utilities.error.ErrorInfo; import com.kofax.kmc.kut.utilities.error.KmcException; import com.kofax.kmc.kut.utilities.error.KmcRuntimeException; import com.kofax.mobile.sdk._internal.IBus; import com.kofax.mobile.sdk._internal.dagger.Injector; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Vector; import java.util.concurrent.CopyOnWriteArrayList; import o.InterfaceC13391fZD; @Deprecated /* loaded from: classes3.dex */ public class ImageClassifier { private static volatile ImageClassificationStatus ap; private IBus _bus; private String an; private String ao; private com.kofax.android.abc.image_classification.ImageClassifier ak = new com.kofax.android.abc.image_classification.ImageClassifier(); private final Handler al = new Handler(); private CopyOnWriteArrayList am = new CopyOnWriteArrayList<>(); private int aq = 20; private Image ar = null; private boolean as = false; final Runnable at = new Runnable(this) { // from class: com.kofax.kmc.ken.engines.ImageClassifier.1 final ImageClassifier au; { this.au = this; } @Override // java.lang.Runnable public void run() { List list; try { list = a(this.au.ak.getClassificationResults()); } catch (Exception unused) { ImageClassificationStatus unused2 = ImageClassifier.ap = ImageClassificationStatus.ERROR; list = null; } if (this.au.ar != null) { this.au.ar.setImageClassifyResults(list); if (this.au.as) { this.au.ar.imageClearBitmap(); this.au.as = false; } } ImageClassificationStatus unused3 = ImageClassifier.ap = ImageClassificationStatus.COMPLETE; this.au._bus.post(new ImageClassificationCompleteEvent(this, this.au.ar)); a(this.au.ar, this.au.am); } private List a(Vector vector) { ArrayList arrayList = new ArrayList(); if (vector == null) { return arrayList; } for (int i = 0; i < vector.size(); i++) { ResultPair resultPair = vector.get(i); if (resultPair != null) { arrayList.add(new ImageClassificationResult(resultPair.classID, resultPair.confidence, resultPair.orientation)); } } return arrayList; } private void a(Image image, List list) { if (list != null) { for (ImageClassificationCompletedListener imageClassificationCompletedListener : list) { if (imageClassificationCompletedListener != null) { imageClassificationCompletedListener.onImageClassified(new ImageClassificationCompleteEvent(this, image)); } } } } }; /* loaded from: classes3.dex */ public enum ImageClassificationStatus { IN_PROGRESS, COMPLETE, ERROR } static { System.loadLibrary("a1ac4"); System.loadLibrary("ee77d4"); System.loadLibrary("d8b3e6"); System.loadLibrary("b2681f"); ap = ImageClassificationStatus.COMPLETE; } @InterfaceC13391fZD public ImageClassifier() { a(); IBus iBus = Injector.getInjector(AppContextProvider.getContext()).getIBus(); this._bus = iBus; iBus.post(new com.kofax.mobile.sdk.p.b()); } public void doCleanup() { this._bus.post(new com.kofax.mobile.sdk.p.c()); com.kofax.android.abc.image_classification.ImageClassifier imageClassifier = this.ak; if (imageClassifier != null) { imageClassifier.dispose(); this.ak = null; } CopyOnWriteArrayList copyOnWriteArrayList = this.am; if (copyOnWriteArrayList != null) { copyOnWriteArrayList.clear(); this.am = null; } this.ar = null; } private ImageClassifier(boolean z) { } private static void a() { if (!Licensing.isSdkLicensed(Licensing.LicenseType.IMAGE_PROCESSING)) { throw new KmcRuntimeException(ErrorInfo.KMC_UT_LICENSE_IMAGE_PROCESSING); } } public void addImageClassificationCompletedEventListener(ImageClassificationCompletedListener imageClassificationCompletedListener) { if (imageClassificationCompletedListener == null) { throw new KmcRuntimeException(ErrorInfo.KMC_CL_LISTENER_NULL); } this.am.add(imageClassificationCompletedListener); } public void removeImageClassificationCompletedEventListener(ImageClassificationCompletedListener imageClassificationCompletedListener) { if (imageClassificationCompletedListener != null) { this.am.remove(imageClassificationCompletedListener); } } public void setMaxNumberOfResults(int i) { if (i <= 0 || i > 64) { throw new KmcRuntimeException(ErrorInfo.KMC_CL_MAX_NUM_RESULTS_INVALID); } this.aq = i; } public int loadConfigurationFile(String str) { if (str == null || str.length() == 0) { throw new KmcRuntimeException(ErrorInfo.KMC_CL_CONFIG_NULL); } if (!new File(str).exists()) { throw new KmcRuntimeException(ErrorInfo.KMC_GN_FILE_NOT_FOUND); } ErrorInfo errorInfo = ErrorInfo.KMC_SUCCESS; try { this.ak.loadConfigurationFile(str); this.an = str; } catch (Exception unused) { errorInfo = ErrorInfo.KMC_CL_CONFIG_NOT_LOADED; } return errorInfo.getErr(); } public int loadModel(String str) { if (str == null || str.length() == 0) { throw new KmcRuntimeException(ErrorInfo.KMC_CL_MODEL_NULL); } if (!new File(str).exists()) { throw new KmcRuntimeException(ErrorInfo.KMC_GN_FILE_NOT_FOUND); } ErrorInfo errorInfo = ErrorInfo.KMC_SUCCESS; try { this.ak.loadModel(str); this.ao = str; } catch (Exception unused) { errorInfo = ErrorInfo.KMC_CL_MODEL_NOT_LOADED; } return errorInfo.getErr(); } private void k() { a(); String str = this.an; if (str == null || str.length() == 0) { throw new KmcRuntimeException(ErrorInfo.KMC_CL_CONFIG_NOT_LOADED); } String str2 = this.ao; if (str2 == null || str2.length() == 0) { throw new KmcRuntimeException(ErrorInfo.KMC_CL_MODEL_NOT_LOADED); } } public int classifyImage(Image image) { if (image == null) { return ErrorInfo.KMC_CL_NO_IMAGE_SUPPLIED.getErr(); } k(); if (ap == ImageClassificationStatus.IN_PROGRESS) { return ErrorInfo.KMC_CL_CLASSIFIER_BUSY.getErr(); } this._bus.post(new com.kofax.mobile.sdk.p.a(image)); this.ar = image; ap = ImageClassificationStatus.IN_PROGRESS; Image.ImageRep imageRepresentation = image.getImageRepresentation(); if (imageRepresentation == null || imageRepresentation.equals(Image.ImageRep.IMAGE_REP_NONE)) { ap = ImageClassificationStatus.ERROR; return ErrorInfo.KMC_CL_NO_IMAGE_SUPPLIED.getErr(); } if (imageRepresentation.equals(Image.ImageRep.IMAGE_REP_BITMAP)) { b(image.getImageBitmap()); } else if (imageRepresentation.equals(Image.ImageRep.IMAGE_REP_FILE)) { if (image.getImageMimeType() == Image.ImageMimeType.MIMETYPE_TIFF) { this.as = true; try { image.imageReadFromFile(); } catch (KmcException | KmcRuntimeException unused) { } b(image.getImageBitmap()); } else { a(image.getImageFilePath()); } } else if (imageRepresentation.equals(Image.ImageRep.IMAGE_REP_BOTH)) { if (c(image)) { a(image.getImageFilePath()); } else { b(image.getImageBitmap()); } } return ErrorInfo.KMC_SUCCESS.getErr(); } private boolean c(Image image) { return image.getImageBitmapHeight().intValue() * image.getImageBitmapWidth().intValue() < image.getImageFileHeight().intValue() * image.getImageFileWidth().intValue(); } private void a(String str) { new Thread(this, str) { // from class: com.kofax.kmc.ken.engines.ImageClassifier.2 final ImageClassifier au; final String av; { this.au = this; this.av = str; } @Override // java.lang.Thread, java.lang.Runnable public void run() { this.au.ak.classify(this.av, this.au.aq); this.au.al.post(this.au.at); } }.start(); } private void b(Bitmap bitmap) { new Thread(this, bitmap) { // from class: com.kofax.kmc.ken.engines.ImageClassifier.3 final ImageClassifier au; final Bitmap aw; { this.au = this; this.aw = bitmap; } @Override // java.lang.Thread, java.lang.Runnable public void run() { this.au.ak.classify(this.aw, this.au.aq); this.au.al.post(this.au.at); } }.start(); } public ImageClassificationStatus getStatus() { return ap; } public int getMaxNumberOfResults() { return this.aq; } }