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

1548 lines
77 KiB
Java

package com.kofax.kmc.ken.engines;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Looper;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.kofax.BuildConfig;
import com.kofax.android.abc.machine_vision.DetectedDocumentBoundary;
import com.kofax.android.abc.machine_vision.DocumentTracker;
import com.kofax.android.abc.machine_vision.GlareDetector;
import com.kofax.android.abc.machine_vision.ShadowDetector;
import com.kofax.android.abc.machine_vision.TrackedDocument;
import com.kofax.android.abc.xvrs.XVrsBlur;
import com.kofax.android.abc.xvrs.XVrsImage;
import com.kofax.kmc.ken.engines.data.BasicSettingsProfile;
import com.kofax.kmc.ken.engines.data.BoundingTetragon;
import com.kofax.kmc.ken.engines.data.Image;
import com.kofax.kmc.ken.engines.data.ImagePerfectionProfile;
import com.kofax.kmc.ken.engines.data.ImageSource;
import com.kofax.kmc.ken.engines.data.QuickAnalysisFeedback;
import com.kofax.kmc.ken.engines.data.QuickAnalysisSettings;
import com.kofax.kmc.ken.engines.iplib.IpLib;
import com.kofax.kmc.ken.engines.iplib.ProcessPageOutRep;
import com.kofax.kmc.ken.engines.processing.ImageProcessorConfiguration;
import com.kofax.kmc.ken.engines.processing.TargetFrameCropType;
import com.kofax.kmc.ken.engines.service.ImageService;
import com.kofax.kmc.kut.utilities.AppContextProvider;
import com.kofax.kmc.kut.utilities.Licensing;
import com.kofax.kmc.kut.utilities.async.ListenerCallbackThreadType;
import com.kofax.kmc.kut.utilities.async.TaskRunner;
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 com.kofax.mobile.sdk._internal.impl.detection.c;
import java.io.File;
import java.util.ArrayList;
import java.util.EventObject;
import java.util.Iterator;
import java.util.Locale;
import java.util.Vector;
import java.util.concurrent.Callable;
import o.InterfaceC13391fZD;
import o.gjJ;
/* loaded from: classes3.dex */
public class ImageProcessor {
private static final String TAG = "ImageProcessor";
private static final String aA = "_UseLegacyProcessor_";
private static final String aB = "_ProcessCheckFront_";
private static final String aC = "_ProcessCheckBack_";
private static final String aD = "_ProcessMrzDoc_";
private static double aF = 0.2d;
private static double aG = 1.0d;
private static double aH = 0.02d;
private static double aI = 50.0d;
private static double aJ = 0.02d;
private static final String az = "_DoDocumentDetectorBasedCrop_";
private static volatile long bb;
private IBus _bus;
private ImagePerfectionProfile aP;
private BasicSettingsProfile aQ;
private String aS;
private TaskRunner aZ;
private b ba;
private boolean bc;
private final com.kofax.mobile.sdk._internal.impl.detection.c aE = Injector.getInjector(AppContextProvider.getContext()).getDetectorBasedCropper();
private String aK = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><Configuration name=\"ErrorAnalysis\"> <Section name=\"ShadowDetection\"> <Parm name=\"ScaledSize\" type=\"int\" value=\"65536\"/> <Parm name=\"MinimumShadowAreaFraction\" type=\"float\" value=\"0.1\"/> </Section></Configuration>";
private String aL = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><Configuration name=\"ErrorAnalysis\"> <Section name=\"ShadowDetection\"> <Parm name=\"ScaledSize\" type=\"int\" value=\"65536\"/> <Parm name=\"MinimumShadowAreaFraction\" type=\"float\" value=\"0.1\"/> </Section></Configuration>";
private String aM = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><Configuration name=\"ErrorAnalysis\"> <Section name=\"DocumentTracker\"> <Parm name=\"DetectorConfig\" type=\"string\" value=\"GenericSingleConfig\" /> <Parm name=\"FrameHistorySize\" type=\"int\" value=\"50\" /> <Parm name=\"MaxTrackedDocuments\" type=\"int\" value=\"1\" /> <Parm name=\"IsUseReferenceFeature\" type=\"bool\" value=\"yes\" /> </Section> <Section name=\"GenericSingleConfig\"> <Parm name=\"DetectorType\" type=\"string\" value=\"GenericSingleDetector\" /> <Parm name=\"SegmentationConfig\" type=\"string\" value=\"GenericSingleSegmentationConfig\" /> <Parm name=\"RelativeAreaRatio1\" type=\"float\" value=\"0.005\"/> <Parm name=\"RelativeAreaRatio2\" type=\"float\" value=\"0.005\"/> <Parm name=\"IsCornerDetection\" type=\"bool\" value=\"yes\"/> <Parm name=\"RelativeImageMarginX\" type=\"float\" value=\"0.01\"/> <Parm name=\"RelativeImageMarginY\" type=\"float\" value=\"0.01\"/> </Section> <Section name=\"GenericSingleSegmentationConfig\"> <Parm name=\"EdgeType\" type=\"string\" value=\"MainComponent\" /> <Parm name=\"ScaleFactor\" type=\"float\" value=\"0.2\" /> <Parm name=\"SmoothingSize\" type=\"int\" value=\"3\" /> <Parm name=\"FilterSize\" type=\"int\" value=\"3\" /> <Parm name=\"EdgeLowThreshold\" type=\"int\" value=\"30\" /> <Parm name=\"EdgeHighThreshold\" type=\"int\" value=\"255\" /> <Parm name=\"ContrastThreshold\" type=\"int\" value=\"50\"/> </Section></Configuration>";
private String aN = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><Configuration name=\"ErrorAnalysis\"> <Section name=\"GlareDetection\"> <Parm name=\"IntensityFraction\" type=\"float\" value=\"0.03\"/> <Parm name=\"IntensityThreshold\" type=\"int\" value=\"240\"/> <Parm name=\"MinimumGlareAreaFraction\" type=\"int\" value=\"0.01\"/> <Parm name=\"NumberOfTiles\" type=\"int\" value=\"100\"/> </Section> <Section name=\"DocumentTracker\"> <Parm name=\"DetectorConfig\" type=\"string\" value=\"GenericSingleConfig\" /> <Parm name=\"FrameHistorySize\" type=\"int\" value=\"50\" /> <Parm name=\"MaxTrackedDocuments\" type=\"int\" value=\"1\" /> <Parm name=\"IsUseReferenceFeature\" type=\"bool\" value=\"yes\" /> </Section> <Section name=\"GenericSingleConfig\"> <Parm name=\"DetectorType\" type=\"string\" value=\"GenericSingleDetector\" /> <Parm name=\"SegmentationConfig\" type=\"string\" value=\"GenericSingleSegmentationConfig\" /> <Parm name=\"RelativeAreaRatio1\" type=\"float\" value=\"0.005\"/> <Parm name=\"RelativeAreaRatio2\" type=\"float\" value=\"0.005\"/> <Parm name=\"IsCornerDetection\" type=\"bool\" value=\"yes\"/> <Parm name=\"RelativeImageMarginX\" type=\"float\" value=\"0.01\"/> <Parm name=\"RelativeImageMarginY\" type=\"float\" value=\"0.01\"/> </Section> <Section name=\"GenericSingleSegmentationConfig\"> <Parm name=\"EdgeType\" type=\"string\" value=\"ColorEdge\" /> <Parm name=\"ScaleFactor\" type=\"float\" value=\"0.2\" /> <Parm name=\"SmoothingSize\" type=\"int\" value=\"3\" /> <Parm name=\"FilterSize\" type=\"int\" value=\"3\" /> <Parm name=\"EdgeLowThreshold\" type=\"int\" value=\"30\" /> <Parm name=\"EdgeHighThreshold\" type=\"int\" value=\"255\" /> <Parm name=\"ContrastThreshold\" type=\"int\" value=\"50\"/> </Section></Configuration>";
private String aO = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><Configuration name=\"ErrorAnalysis\"> <Section name=\"DocumentTracker\"> <Parm name=\"DetectorConfig\" type=\"string\" value=\"GenericSingleConfig\" /> <Parm name=\"FrameHistorySize\" type=\"int\" value=\"50\" /> <Parm name=\"MaxTrackedDocuments\" type=\"int\" value=\"1\" /> <Parm name=\"IsUseReferenceFeature\" type=\"bool\" value=\"yes\" /> </Section> <Section name=\"GenericSingleConfig\"> <Parm name=\"DetectorType\" type=\"string\" value=\"GenericSingleDetector\" /> <Parm name=\"SegmentationConfig\" type=\"string\" value=\"GenericSingleSegmentationConfig\" /> <Parm name=\"RelativeAreaRatio1\" type=\"float\" value=\"0.005\"/> <Parm name=\"RelativeAreaRatio2\" type=\"float\" value=\"0.005\"/> <Parm name=\"IsCornerDetection\" type=\"bool\" value=\"yes\"/> <Parm name=\"RelativeImageMarginX\" type=\"float\" value=\"0.01\"/> <Parm name=\"RelativeImageMarginY\" type=\"float\" value=\"0.01\"/> </Section> <Section name=\"GenericSingleSegmentationConfig\"> <Parm name=\"EdgeType\" type=\"string\" value=\"MainComponent\" /> <Parm name=\"ScaleFactor\" type=\"float\" value=\"0.2\" /> <Parm name=\"SmoothingSize\" type=\"int\" value=\"3\" /> <Parm name=\"FilterSize\" type=\"int\" value=\"3\" /> <Parm name=\"EdgeLowThreshold\" type=\"int\" value=\"30\" /> <Parm name=\"EdgeHighThreshold\" type=\"int\" value=\"255\" /> <Parm name=\"ContrastThreshold\" type=\"int\" value=\"50\"/> </Section></Configuration>";
private Image.ImageRep aR = Image.ImageRep.IMAGE_REP_BITMAP;
private Image.ImageMimeType aT = Image.ImageMimeType.MIMETYPE_UNKNOWN;
private int processedImageJpegQuality = 90;
private ListenerCallbackThreadType aU = ListenerCallbackThreadType.UI_THREAD;
private ArrayList<ImageOutListener> aV = new ArrayList<>();
private ArrayList<ProcessProgressListener> aW = new ArrayList<>();
private ArrayList<AnalysisCompleteListener> aX = new ArrayList<>();
private ArrayList<AnalysisProgressListener> aY = new ArrayList<>();
/* loaded from: classes3.dex */
public interface AnalysisCompleteListener {
void analysisComplete(AnalysisCompleteEvent analysisCompleteEvent);
}
/* loaded from: classes3.dex */
public interface AnalysisProgressListener {
void analysisProgress(AnalysisProgressEvent analysisProgressEvent);
}
/* loaded from: classes3.dex */
public interface ImageOutListener {
void imageOut(ImageOutEvent imageOutEvent);
}
/* loaded from: classes3.dex */
public interface ProcessProgressListener {
void processProgress(ProcessProgressEvent processProgressEvent);
}
public void cancel() {
com.kofax.mobile.sdk._internal.k.c(TAG, "cancelCalledExternalApi");
b bVar = this.ba;
if (bVar != null) {
bVar.bt = true;
}
ImageService.cancelImageProcessing();
}
/* loaded from: classes3.dex */
public static class ImageOutEvent extends EventObject {
private static final long serialVersionUID = 3442216892248828021L;
private ErrorInfo be;
private Image image;
public ImageOutEvent(Object obj, ErrorInfo errorInfo, Image image) {
super(obj);
this.be = errorInfo;
this.image = image;
}
public ErrorInfo getStatus() {
return this.be;
}
public Image getImage() {
return this.image;
}
}
/* loaded from: classes3.dex */
public static class ProcessProgressEvent extends EventObject {
private static final long serialVersionUID = 3442216892248828021L;
private ErrorInfo be;
private int bf;
private String imageID;
public ProcessProgressEvent(Object obj, ErrorInfo errorInfo, String str, int i) {
super(obj);
this.be = errorInfo;
this.imageID = str;
this.bf = i;
}
public ErrorInfo getStatus() {
return this.be;
}
public int getProgressPct() {
return this.bf;
}
public String getImageID() {
return this.imageID;
}
}
/* loaded from: classes3.dex */
public static class AnalysisCompleteEvent extends EventObject {
private static final long serialVersionUID = 5180886074104600189L;
private ErrorInfo be;
private Image image;
public AnalysisCompleteEvent(Object obj, ErrorInfo errorInfo, Image image) {
super(obj);
this.be = errorInfo;
this.image = image;
}
public ErrorInfo getStatus() {
return this.be;
}
public Image getImage() {
return this.image;
}
}
/* loaded from: classes3.dex */
public static class AnalysisProgressEvent extends EventObject {
private static final long serialVersionUID = 9007021929022931498L;
private ErrorInfo be;
private int bf;
private String imageID;
public AnalysisProgressEvent(Object obj, ErrorInfo errorInfo, String str, int i) {
super(obj);
this.be = errorInfo;
this.imageID = str;
this.bf = i;
}
public ErrorInfo getStatus() {
return this.be;
}
public int getProgressPct() {
return this.bf;
}
public String getImageID() {
return this.imageID;
}
}
@InterfaceC13391fZD
public ImageProcessor() {
l();
IBus iBus = Injector.getInjector(AppContextProvider.getContext()).getIBus();
this._bus = iBus;
iBus.post(new com.kofax.mobile.sdk.s.c());
}
public void doCleanup() {
this._bus.post(new com.kofax.mobile.sdk.s.d());
this.aP = null;
this.aQ = null;
ArrayList<ImageOutListener> arrayList = this.aV;
if (arrayList != null) {
arrayList.clear();
this.aV = null;
}
ArrayList<ProcessProgressListener> arrayList2 = this.aW;
if (arrayList2 != null) {
arrayList2.clear();
this.aW = null;
}
ArrayList<AnalysisCompleteListener> arrayList3 = this.aX;
if (arrayList3 != null) {
arrayList3.clear();
this.aX = null;
}
TaskRunner taskRunner = this.aZ;
if (taskRunner != null) {
taskRunner.shutdown();
}
this.ba = null;
}
@Deprecated
public ImagePerfectionProfile getImagePerfectionProfile() {
ImagePerfectionProfile imagePerfectionProfile = this.aP;
if (imagePerfectionProfile != null) {
return imagePerfectionProfile.m269clone();
}
return null;
}
@Deprecated
public void setImagePerfectionProfile(ImagePerfectionProfile imagePerfectionProfile) {
if (imagePerfectionProfile != null) {
imagePerfectionProfile = imagePerfectionProfile.m269clone();
}
this.aP = imagePerfectionProfile;
}
@Deprecated
public BasicSettingsProfile getBasicSettingsProfile() {
BasicSettingsProfile basicSettingsProfile = this.aQ;
if (basicSettingsProfile != null) {
return basicSettingsProfile.m267clone();
}
return null;
}
@Deprecated
public void setBasicSettingsProfile(BasicSettingsProfile basicSettingsProfile) {
if (basicSettingsProfile != null) {
basicSettingsProfile = basicSettingsProfile.m267clone();
}
this.aQ = basicSettingsProfile;
}
public void setProcessedImageJpegQuality(int i) {
if (i <= 0 || i > 100) {
throw new KmcRuntimeException(ErrorInfo.KMC_ED_INVALID_JPEG_QUALITY_VALUE);
}
this.processedImageJpegQuality = i;
}
@Deprecated
public void processImage(Image image) throws KmcException {
a(image, "image");
a(image, false, false, null, null);
}
public void processImage(Image image, ImageProcessorConfiguration imageProcessorConfiguration) throws KmcException {
a(image, "image");
com.kofax.mobile.sdk.ae.d.b(imageProcessorConfiguration);
a(image, false, false, null, imageProcessorConfiguration.m271clone());
}
public void addImageOutEventListener(ImageOutListener imageOutListener) {
if (imageOutListener == null) {
throw new NullPointerException("addImageOutEventListener: listener parameter is null");
}
if (this.aV.contains(imageOutListener)) {
return;
}
this.aV.add(imageOutListener);
}
public void removeImageOutEventListener(ImageOutListener imageOutListener) {
this.aV.remove(imageOutListener);
}
public void addProcessProgressEventListener(ProcessProgressListener processProgressListener) {
this.aW.add(processProgressListener);
}
public void removeProcessProgressEventListener(ProcessProgressListener processProgressListener) {
this.aW.remove(processProgressListener);
}
public void doQuickAnalysis(Image image, boolean z) throws KmcException {
a(image, "image");
this.bc = z;
doQuickAnalysis(image, z, null);
}
public void doQuickAnalysis(Image image, boolean z, QuickAnalysisSettings quickAnalysisSettings) throws KmcException {
a(image, "image");
this.bc = z;
if (quickAnalysisSettings == null) {
quickAnalysisSettings = new QuickAnalysisSettings();
}
a(image, true, z, quickAnalysisSettings, null);
}
public void addAnalysisCompleteEventListener(AnalysisCompleteListener analysisCompleteListener) {
ArrayList<AnalysisCompleteListener> arrayList = this.aX;
if (arrayList == null) {
return;
}
arrayList.add(analysisCompleteListener);
}
public void removeAnalysisCompleteEventListener(AnalysisCompleteListener analysisCompleteListener) {
this.aX.remove(analysisCompleteListener);
}
public void addAnalysisProgressEventListener(AnalysisProgressListener analysisProgressListener) {
this.aY.add(analysisProgressListener);
}
public void removeAnalysisProgressEventListener(AnalysisProgressListener analysisProgressListener) {
this.aY.remove(analysisProgressListener);
}
void a(ErrorInfo errorInfo, Image image, ImageProcessorConfiguration imageProcessorConfiguration) {
String finalOpString;
if (imageProcessorConfiguration != null) {
finalOpString = com.kofax.mobile.sdk.ae.c.a(imageProcessorConfiguration).TP;
} else {
ImagePerfectionProfile imagePerfectionProfile = this.aP;
if (imagePerfectionProfile != null) {
try {
finalOpString = new ImagePerfectionProfile.FriendIPP(imagePerfectionProfile, BuildConfig.APPLICATION_ID).toFinalOpString();
} catch (KmcException | KmcRuntimeException unused) {
}
}
finalOpString = null;
}
if (image != null && image.getImageRepresentation() != Image.ImageRep.IMAGE_REP_NONE) {
this._bus.post(new com.kofax.mobile.sdk.r.b(image, ImageSource.PROCESSOR));
}
this._bus.post(new com.kofax.mobile.sdk.s.a(errorInfo, image, finalOpString));
ArrayList<ImageOutListener> arrayList = this.aV;
if (arrayList == null) {
com.kofax.mobile.sdk._internal.k.d(TAG, "Called back after this object has been destroyed");
return;
}
Iterator<ImageOutListener> it = arrayList.iterator();
while (it.hasNext()) {
it.next().imageOut(new ImageOutEvent(this, errorInfo, image));
}
}
void a(ErrorInfo errorInfo, String str, int i) {
ArrayList<ProcessProgressListener> arrayList = this.aW;
if (arrayList == null) {
com.kofax.mobile.sdk._internal.k.d(TAG, "Called back after this object has been destroyed");
return;
}
Iterator<ProcessProgressListener> it = arrayList.iterator();
while (it.hasNext()) {
it.next().processProgress(new ProcessProgressEvent(this, errorInfo, str, i));
}
}
void a(ErrorInfo errorInfo, Image image) {
ArrayList<AnalysisCompleteListener> arrayList = this.aX;
if (arrayList == null) {
com.kofax.mobile.sdk._internal.k.d(TAG, "Called back after this object has been destroyed");
return;
}
Iterator<AnalysisCompleteListener> it = arrayList.iterator();
while (it.hasNext()) {
it.next().analysisComplete(new AnalysisCompleteEvent(this, errorInfo, image));
}
}
void b(ErrorInfo errorInfo, String str, int i) {
ArrayList<AnalysisProgressListener> arrayList = this.aY;
if (arrayList == null) {
com.kofax.mobile.sdk._internal.k.d(TAG, "Called back after this object has been destroyed");
return;
}
Iterator<AnalysisProgressListener> it = arrayList.iterator();
while (it.hasNext()) {
it.next().analysisProgress(new AnalysisProgressEvent(this, errorInfo, str, i));
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public class c implements TaskRunner.TaskCompletedListener {
final ImageProcessor bi;
private ProcessPageOutRep bo;
private final b bv;
private ImageProcessor bw;
public c(ImageProcessor imageProcessor, b bVar) {
this.bi = imageProcessor;
this.bv = bVar;
}
@Override // com.kofax.kmc.kut.utilities.async.TaskRunner.TaskCompletedListener
public void onTaskCompleted(TaskRunner.TaskCompletedEvent taskCompletedEvent) {
QuickAnalysisFeedback.FriendQAF friendQAF;
Image.FriendI friendI;
ErrorInfo a;
this.bi.aZ.removeOnTaskCompletedListener(this, this.bv);
long taskID = taskCompletedEvent.getTaskID();
String str = ImageProcessor.TAG;
StringBuilder sb = new StringBuilder("Task ");
sb.append(taskID);
sb.append(" completed.");
com.kofax.mobile.sdk._internal.k.c(str, sb.toString());
ErrorInfo taskError = taskCompletedEvent.getTaskError();
if (taskError == ErrorInfo.KMC_SUCCESS) {
com.kofax.mobile.sdk._internal.k.c(ImageProcessor.TAG, "No Task Error. Good.");
if (ImageProcessor.bb != taskID) {
String str2 = ImageProcessor.TAG;
StringBuilder sb2 = new StringBuilder("Unexpected: Task ");
sb2.append(ImageProcessor.bb);
sb2.append(" was running.");
com.kofax.mobile.sdk._internal.k.c(str2, sb2.toString());
}
} else {
String str3 = ImageProcessor.TAG;
StringBuilder sb3 = new StringBuilder("Task Error: ");
sb3.append(taskError.toString());
com.kofax.mobile.sdk._internal.k.c(str3, sb3.toString());
}
long unused = ImageProcessor.bb = 0L;
ImageService.EnhancementResults enhancementResults = (ImageService.EnhancementResults) taskCompletedEvent.getTaskReturnValue();
Bitmap bitmap = null;
if (this.bo.isQuickAnalysisEnabled()) {
if (taskError == ErrorInfo.KMC_SUCCESS && enhancementResults.image != null) {
QuickAnalysisFeedback quickAnalysisFeedback = new QuickAnalysisFeedback();
String imageMetaData = enhancementResults.image.getImageMetaData();
try {
friendQAF = new QuickAnalysisFeedback.FriendQAF(quickAnalysisFeedback, BuildConfig.APPLICATION_ID);
try {
friendQAF.setMetadata(this.bi.a(this.bv.bs, imageMetaData));
friendQAF.setBlurry(this.bo.quickAnalysisSettings.getBlurDetection() && this.bv.bu > ((float) this.bo.quickAnalysisSettings.getBlurThreshold()));
if (!this.bo.quickAnalysisSettings.getSaturationDetection()) {
friendQAF.setOversaturated(false);
friendQAF.setUndersaturated(false);
}
if (!this.bo.quickAnalysisSettings.getSkewDetection()) {
friendQAF.setOverlySkewed(false);
}
friendQAF.setMissingBorder(false);
friendQAF.setLowContrastBackground(false);
friendQAF.setIsShadowed(false);
friendQAF.setGlareDetected(false);
} catch (KmcException unused2) {
}
} catch (KmcException unused3) {
friendQAF = null;
}
BoundingTetragon tetragonCorners = quickAnalysisFeedback.getTetragonCorners();
Vector vector = new Vector(4);
vector.add(tetragonCorners.getTopLeft());
vector.add(tetragonCorners.getTopRight());
vector.add(tetragonCorners.getBottomRight());
vector.add(tetragonCorners.getBottomLeft());
ErrorInfo errorInfo = ErrorInfo.KMC_SUCCESS;
Bitmap imageBitmap = enhancementResults.originalImage.getImageBitmap();
if (imageBitmap == null) {
try {
friendI = new Image.FriendI(enhancementResults.originalImage, BuildConfig.APPLICATION_ID);
try {
friendI.clearBitmapWithoutRecycle();
} catch (KmcException unused4) {
}
} catch (KmcException unused5) {
friendI = null;
}
a = this.bi.a(enhancementResults.originalImage, friendI);
if (a != ErrorInfo.KMC_SUCCESS && a != ErrorInfo.KMC_ED_ALTERNATE_FILEIO_ENGINE) {
this.bw.a(a, (Image) null);
return;
}
} else {
a = errorInfo;
friendI = null;
}
if (this.bo.quickAnalysisSettings.getMissingBordersDetection() && this.bi.d(enhancementResults.originalImage)) {
friendQAF.setMissingBorder(true);
}
if (this.bo.quickAnalysisSettings.getGlareDetection() && !quickAnalysisFeedback.isGlareDetected() && this.bi.a(this.bo.quickAnalysisSettings, enhancementResults.originalImage, (Vector<Point>) vector)) {
friendQAF.setGlareDetected(true);
}
if (this.bo.quickAnalysisSettings.getLowContrastBackgroundDetection() && this.bi.a(enhancementResults.originalImage, (Vector<Point>) vector)) {
friendQAF.setLowContrastBackground(true);
}
if (this.bo.quickAnalysisSettings.getShadowDetection() && this.bi.b(enhancementResults.originalImage, (Vector<Point>) vector)) {
friendQAF.setIsShadowed(true);
}
if (this.bo.quickAnalysisSettings.getSaturationDetection() && !quickAnalysisFeedback.isUndersaturated() && !quickAnalysisFeedback.isOversaturated() && this.bi.e(enhancementResults.originalImage)) {
friendQAF.setUndersaturated(true);
}
if (a == ErrorInfo.KMC_SUCCESS || a == ErrorInfo.KMC_ED_ALTERNATE_FILEIO_ENGINE) {
Bitmap imageBitmap2 = enhancementResults.originalImage.getImageBitmap();
if (imageBitmap == null) {
enhancementResults.originalImage.imageClearBitmap();
} else if (imageBitmap != imageBitmap2) {
friendI.setImageBitmapInternal(imageBitmap);
}
}
if (this.bi.bc && enhancementResults.image != null) {
bitmap = enhancementResults.image.getImageBitmap();
}
friendQAF.setViewBoundariesImage(bitmap);
try {
Image.FriendI friendI2 = new Image.FriendI(enhancementResults.originalImage, BuildConfig.APPLICATION_ID);
friendI2.setImageQuickAnalysisFeedBack(quickAnalysisFeedback);
friendI2.setImageMetaData(enhancementResults.image.getImageMetaData());
} catch (KmcException unused6) {
}
this.bw.a(enhancementResults.errorInfo, enhancementResults.originalImage);
return;
}
this.bw.a(enhancementResults.errorInfo, (Image) null);
return;
}
if (taskError == ErrorInfo.KMC_SUCCESS) {
Image image = enhancementResults.image;
if (image != null && image.getImageMetaData() != null) {
if (this.bv.br != null) {
try {
new Image.FriendI(image, BuildConfig.APPLICATION_ID).setImageMetaData(this.bi.a(this.bv.br, image.getImageMetaData()));
} catch (KmcException unused7) {
}
}
if (this.bv.bs != null && !this.bv.bs.equals(0, 0)) {
try {
new Image.FriendI(image, BuildConfig.APPLICATION_ID).setImageMetaData(this.bi.a(this.bv.bs, image.getImageMetaData()));
} catch (KmcException unused8) {
}
}
}
this.bw.a(enhancementResults.errorInfo, image, this.bv.bm);
return;
}
this.bw.a(taskError, (Image) null, this.bv.bm);
}
}
/* JADX INFO: Access modifiers changed from: private */
public boolean d(Image image) {
String str;
boolean z;
boolean z2;
boolean z3;
DocumentTracker documentTracker = new DocumentTracker();
try {
documentTracker.initializeString(this.aM, "DocumentTracker");
documentTracker.reset();
documentTracker.startup();
Bitmap imageBitmap = image.getImageBitmap();
documentTracker.grabImageFrame(imageBitmap);
documentTracker.processFrame();
documentTracker.releaseFrame();
Vector<TrackedDocument> Documents = documentTracker.Documents();
String str2 = "docs.size() < 1, returning null detection";
if (Documents != null && Documents.size() > 0) {
TrackedDocument trackedDocument = Documents.get(0);
if (trackedDocument != null && trackedDocument.Boundary().Corners().size() != 0) {
int width = imageBitmap.getWidth();
int height = imageBitmap.getHeight();
if (trackedDocument.Boundary().BoundaryType() == DetectedDocumentBoundary.DetectedBoundaryType.PARTIAL_OBJECT) {
Iterator<Point> it = trackedDocument.Boundary().Corners().iterator();
z = false;
while (it.hasNext()) {
Point next = it.next();
Iterator<Point> it2 = it;
String str3 = str2;
double d2 = width;
if (next.x >= d2 * 0.03d && next.x <= d2 * 0.97d) {
double d3 = height;
if (next.y >= d3 * 0.03d && next.y <= d3 * 0.97d) {
z3 = false;
z |= z3;
str2 = str3;
it = it2;
}
}
z3 = true;
z |= z3;
str2 = str3;
it = it2;
}
str = str2;
} else {
str = "docs.size() < 1, returning null detection";
z = false;
}
if (!z) {
documentTracker.initializeString(this.aN, "DocumentTracker");
documentTracker.reset();
documentTracker.startup();
documentTracker.grabImageFrame(imageBitmap);
documentTracker.processFrame();
documentTracker.releaseFrame();
Vector<TrackedDocument> Documents2 = documentTracker.Documents();
if (Documents2 != null && Documents2.size() > 0) {
TrackedDocument trackedDocument2 = Documents2.get(0);
if (trackedDocument2 != null && trackedDocument2.Boundary().Corners().size() != 0) {
if (!z && trackedDocument2.Boundary().BoundaryType() == DetectedDocumentBoundary.DetectedBoundaryType.PARTIAL_OBJECT) {
Iterator<Point> it3 = trackedDocument2.Boundary().Corners().iterator();
while (it3.hasNext()) {
Point next2 = it3.next();
double d4 = width;
if (next2.x >= d4 * 0.03d && next2.x <= d4 * 0.97d) {
double d5 = height;
if (next2.y >= d5 * 0.03d) {
if (next2.y <= d5 * 0.97d) {
z2 = false;
z |= z2;
}
z2 = true;
z |= z2;
}
}
z2 = true;
z |= z2;
}
}
}
}
com.kofax.mobile.sdk._internal.k.b(TAG, str);
}
return z;
}
documentTracker.dispose();
return true;
}
com.kofax.mobile.sdk._internal.k.b(TAG, "docs.size() < 1, returning null detection");
documentTracker.dispose();
return true;
} finally {
documentTracker.dispose();
}
}
private String a(QuickAnalysisSettings quickAnalysisSettings) {
return String.format(Locale.US, " <?xml version=\"1.0\" encoding=\"iso-8859-1\"?> <Configuration name=\"Cadence\"> <Section name=\"GlareDetection\"> <Parm name=\"IntensityFraction\" type=\"float\" value=\"%f\"/> <Parm name=\"IntensityThreshold\" type=\"int\" value=\"%d\"/> <Parm name=\"MinimumGlareAreaFraction\" type=\"float\" value=\"%f\"/> <Parm name=\"NumberOfTiles\" type=\"int\" value=\"%d\"/> </Section> </Configuration>", Double.valueOf(quickAnalysisSettings.getGlareDetectionIntensityFraction()), Integer.valueOf(quickAnalysisSettings.getGlareDetectionIntensityThreshold()), Double.valueOf(quickAnalysisSettings.getGlareDetectionMinimumGlareAreaFraction()), Integer.valueOf(quickAnalysisSettings.getGlareDetectionNumberOfTiles()));
}
/* JADX INFO: Access modifiers changed from: private */
public boolean a(QuickAnalysisSettings quickAnalysisSettings, Image image, Vector<Point> vector) {
GlareDetector glareDetector = new GlareDetector();
glareDetector.loadConfigurationString(a(quickAnalysisSettings), "GlareDetection");
glareDetector.grabImageFrame(image.getImageBitmap());
double detectGlare = glareDetector.detectGlare();
glareDetector.releaseFrame();
boolean z = detectGlare >= quickAnalysisSettings.getGlareDetectedThreshold();
if (z) {
return z;
}
return glareDetector.getGlareFraction(vector) >= aJ;
}
private double c(Point point, Point point2) {
double d2 = point.x - point2.x;
double d3 = point.y - point2.y;
return Math.sqrt((d2 * d2) + (d3 * d3));
}
/* JADX INFO: Access modifiers changed from: private */
/* JADX WARN: Removed duplicated region for block: B:16:0x007f A[Catch: all -> 0x00d6, TryCatch #0 {all -> 0x00d6, blocks: (B:3:0x0007, B:5:0x0027, B:7:0x002d, B:9:0x003f, B:10:0x0049, B:12:0x0067, B:14:0x006d, B:16:0x007f, B:20:0x008f, B:22:0x00a5, B:24:0x00ab, B:26:0x00c0), top: B:2:0x0007 }] */
/* JADX WARN: Removed duplicated region for block: B:20:0x008f A[Catch: all -> 0x00d6, LOOP:0: B:18:0x008c->B:20:0x008f, LOOP_END, TryCatch #0 {all -> 0x00d6, blocks: (B:3:0x0007, B:5:0x0027, B:7:0x002d, B:9:0x003f, B:10:0x0049, B:12:0x0067, B:14:0x006d, B:16:0x007f, B:20:0x008f, B:22:0x00a5, B:24:0x00ab, B:26:0x00c0), top: B:2:0x0007 }] */
/* JADX WARN: Removed duplicated region for block: B:24:0x00ab A[Catch: all -> 0x00d6, TryCatch #0 {all -> 0x00d6, blocks: (B:3:0x0007, B:5:0x0027, B:7:0x002d, B:9:0x003f, B:10:0x0049, B:12:0x0067, B:14:0x006d, B:16:0x007f, B:20:0x008f, B:22:0x00a5, B:24:0x00ab, B:26:0x00c0), top: B:2:0x0007 }] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public boolean a(com.kofax.kmc.ken.engines.data.Image r12, java.util.Vector<android.graphics.Point> r13) {
/*
r11 = this;
java.lang.String r0 = "DocumentTracker"
com.kofax.android.abc.machine_vision.DocumentTracker r1 = new com.kofax.android.abc.machine_vision.DocumentTracker
r1.<init>()
java.lang.String r2 = r11.aN // Catch: java.lang.Throwable -> Ld6
r1.initializeString(r2, r0) // Catch: java.lang.Throwable -> Ld6
r1.reset() // Catch: java.lang.Throwable -> Ld6
r1.startup() // Catch: java.lang.Throwable -> Ld6
android.graphics.Bitmap r2 = r12.getImageBitmap() // Catch: java.lang.Throwable -> Ld6
r1.grabImageFrame(r2) // Catch: java.lang.Throwable -> Ld6
r1.processFrame() // Catch: java.lang.Throwable -> Ld6
r1.releaseFrame() // Catch: java.lang.Throwable -> Ld6
java.util.Vector r2 = r1.Documents() // Catch: java.lang.Throwable -> Ld6
r3 = 0
r4 = 1
if (r2 == 0) goto L48
int r5 = r2.size() // Catch: java.lang.Throwable -> Ld6
if (r5 != r4) goto L48
java.lang.Object r2 = r2.get(r3) // Catch: java.lang.Throwable -> Ld6
com.kofax.android.abc.machine_vision.TrackedDocument r2 = (com.kofax.android.abc.machine_vision.TrackedDocument) r2 // Catch: java.lang.Throwable -> Ld6
com.kofax.android.abc.machine_vision.DetectedDocumentBoundary r5 = r2.Boundary() // Catch: java.lang.Throwable -> Ld6
com.kofax.android.abc.machine_vision.DetectedDocumentBoundary$DetectedBoundaryType r5 = r5.BoundaryType() // Catch: java.lang.Throwable -> Ld6
com.kofax.android.abc.machine_vision.DetectedDocumentBoundary$DetectedBoundaryType r6 = com.kofax.android.abc.machine_vision.DetectedDocumentBoundary.DetectedBoundaryType.WHOLE_OBJECT // Catch: java.lang.Throwable -> Ld6
if (r5 != r6) goto L48
com.kofax.android.abc.machine_vision.DetectedDocumentBoundary r2 = r2.Boundary() // Catch: java.lang.Throwable -> Ld6
java.util.Vector r2 = r2.Corners() // Catch: java.lang.Throwable -> Ld6
goto L49
L48:
r2 = r13
L49:
java.lang.String r5 = r11.aO // Catch: java.lang.Throwable -> Ld6
r1.initializeString(r5, r0) // Catch: java.lang.Throwable -> Ld6
r1.reset() // Catch: java.lang.Throwable -> Ld6
r1.startup() // Catch: java.lang.Throwable -> Ld6
android.graphics.Bitmap r12 = r12.getImageBitmap() // Catch: java.lang.Throwable -> Ld6
r1.grabImageFrame(r12) // Catch: java.lang.Throwable -> Ld6
r1.processFrame() // Catch: java.lang.Throwable -> Ld6
r1.releaseFrame() // Catch: java.lang.Throwable -> Ld6
java.util.Vector r12 = r1.Documents() // Catch: java.lang.Throwable -> Ld6
if (r12 == 0) goto L88
int r0 = r12.size() // Catch: java.lang.Throwable -> Ld6
if (r0 != r4) goto L88
java.lang.Object r12 = r12.get(r3) // Catch: java.lang.Throwable -> Ld6
com.kofax.android.abc.machine_vision.TrackedDocument r12 = (com.kofax.android.abc.machine_vision.TrackedDocument) r12 // Catch: java.lang.Throwable -> Ld6
com.kofax.android.abc.machine_vision.DetectedDocumentBoundary r0 = r12.Boundary() // Catch: java.lang.Throwable -> Ld6
com.kofax.android.abc.machine_vision.DetectedDocumentBoundary$DetectedBoundaryType r0 = r0.BoundaryType() // Catch: java.lang.Throwable -> Ld6
com.kofax.android.abc.machine_vision.DetectedDocumentBoundary$DetectedBoundaryType r5 = com.kofax.android.abc.machine_vision.DetectedDocumentBoundary.DetectedBoundaryType.WHOLE_OBJECT // Catch: java.lang.Throwable -> Ld6
if (r0 != r5) goto L88
com.kofax.android.abc.machine_vision.DetectedDocumentBoundary r12 = r12.Boundary() // Catch: java.lang.Throwable -> Ld6
java.util.Vector r12 = r12.Corners() // Catch: java.lang.Throwable -> Ld6
goto L89
L88:
r12 = r13
L89:
r5 = 0
r0 = r3
L8c:
r7 = 4
if (r0 >= r7) goto La5
java.lang.Object r7 = r13.get(r0) // Catch: java.lang.Throwable -> Ld6
android.graphics.Point r7 = (android.graphics.Point) r7 // Catch: java.lang.Throwable -> Ld6
int r0 = r0 + 1
int r8 = r0 % 4
java.lang.Object r8 = r13.get(r8) // Catch: java.lang.Throwable -> Ld6
android.graphics.Point r8 = (android.graphics.Point) r8 // Catch: java.lang.Throwable -> Ld6
double r7 = r11.c(r7, r8) // Catch: java.lang.Throwable -> Ld6
double r5 = r5 + r7
goto L8c
La5:
double r8 = com.kofax.kmc.ken.engines.ImageProcessor.aH // Catch: java.lang.Throwable -> Ld6
double r5 = r5 * r8
r0 = r3
La9:
if (r0 >= r7) goto Ld2
java.lang.Object r8 = r13.get(r0) // Catch: java.lang.Throwable -> Ld6
android.graphics.Point r8 = (android.graphics.Point) r8 // Catch: java.lang.Throwable -> Ld6
java.lang.Object r9 = r2.get(r0) // Catch: java.lang.Throwable -> Ld6
android.graphics.Point r9 = (android.graphics.Point) r9 // Catch: java.lang.Throwable -> Ld6
double r9 = r11.c(r8, r9) // Catch: java.lang.Throwable -> Ld6
int r9 = (r9 > r5 ? 1 : (r9 == r5 ? 0 : -1))
if (r9 <= 0) goto Lc0
goto Ld1
Lc0:
java.lang.Object r9 = r12.get(r0) // Catch: java.lang.Throwable -> Ld6
android.graphics.Point r9 = (android.graphics.Point) r9 // Catch: java.lang.Throwable -> Ld6
double r8 = r11.c(r8, r9) // Catch: java.lang.Throwable -> Ld6
int r8 = (r8 > r5 ? 1 : (r8 == r5 ? 0 : -1))
if (r8 > 0) goto Ld1
int r0 = r0 + 1
goto La9
Ld1:
r3 = r4
Ld2:
r1.dispose()
return r3
Ld6:
r12 = move-exception
r1.dispose()
throw r12
*/
throw new UnsupportedOperationException("Method not decompiled: com.kofax.kmc.ken.engines.ImageProcessor.a(com.kofax.kmc.ken.engines.data.Image, java.util.Vector):boolean");
}
/* JADX INFO: Access modifiers changed from: private */
public ErrorInfo a(Image image, Image.FriendI friendI) {
ErrorInfo errorInfo;
ErrorInfo errorInfo2 = ErrorInfo.KMC_SUCCESS;
String imageMetaData = image.getImageMetaData();
Integer imageDPI = image.getImageDPI();
Image.ImageFileRep imageFileRep = image.getImageFileRep();
try {
errorInfo = image.imageReadFromFile();
} catch (KmcException e) {
errorInfo = e.getErrorInfo();
} catch (KmcRuntimeException e2) {
errorInfo = e2.getErrorInfo();
}
friendI.setImageMetaData(imageMetaData);
friendI.setImageDPI(imageDPI);
friendI.setImageFileRepresentation(imageFileRep);
return errorInfo;
}
/* JADX INFO: Access modifiers changed from: private */
public boolean b(Image image, Vector<Point> vector) {
ShadowDetector shadowDetector = new ShadowDetector();
shadowDetector.loadConfigurationString(this.aL, "ShadowDetection");
shadowDetector.grabImageFrame(image.getImageBitmap());
double detectShadows = shadowDetector.detectShadows(vector);
shadowDetector.releaseFrame();
return detectShadows > aF && detectShadows < aG;
}
/* JADX INFO: Access modifiers changed from: private */
public boolean e(Image image) {
ShadowDetector shadowDetector = new ShadowDetector();
shadowDetector.loadConfigurationString(this.aK, "ShadowDetection");
shadowDetector.grabImageFrame(image.getImageBitmap());
int averageLightness = shadowDetector.averageLightness();
shadowDetector.releaseFrame();
return ((double) averageLightness) < aI;
}
/* JADX INFO: Access modifiers changed from: private */
public String a(Point point, String str) {
String cornersJsonFromMetaData;
BoundingTetragon cornersTetragonFromJson;
if (point.equals(0, 0) || (cornersTetragonFromJson = ImageService.getCornersTetragonFromJson((cornersJsonFromMetaData = ImageService.getCornersJsonFromMetaData(str)))) == null || cornersJsonFromMetaData == null) {
return str;
}
StringBuilder sb = new StringBuilder("{ \"BLx\": ");
sb.append(cornersTetragonFromJson.getBottomLeft().x + point.x);
sb.append(", \"BLy\": ");
sb.append(cornersTetragonFromJson.getBottomLeft().y + point.y);
sb.append(", \"BRx\": ");
sb.append(cornersTetragonFromJson.getBottomRight().x + point.x);
sb.append(", \"BRy\": ");
sb.append(cornersTetragonFromJson.getBottomRight().y + point.y);
sb.append(", \"TLx\": ");
sb.append(cornersTetragonFromJson.getTopLeft().x + point.x);
sb.append(", \"TLy\": ");
sb.append(cornersTetragonFromJson.getTopLeft().y + point.y);
sb.append(", \"TRx\": ");
sb.append(cornersTetragonFromJson.getTopRight().x + point.x);
sb.append(", \"TRy\": ");
sb.append(cornersTetragonFromJson.getTopRight().y + point.y);
sb.append(" }");
return str.replace(cornersJsonFromMetaData, sb.toString());
}
/* JADX INFO: Access modifiers changed from: private */
public String a(BoundingTetragon boundingTetragon, String str) {
String cornersJsonFromMetaData = ImageService.getCornersJsonFromMetaData(str);
if (ImageService.getCornersTetragonFromJson(cornersJsonFromMetaData) == null || cornersJsonFromMetaData == null) {
return str;
}
StringBuilder sb = new StringBuilder("{ \"BLx\": ");
sb.append(boundingTetragon.getBottomLeft().x);
sb.append(", \"BLy\": ");
sb.append(boundingTetragon.getBottomLeft().y);
sb.append(", \"BRx\": ");
sb.append(boundingTetragon.getBottomRight().x);
sb.append(", \"BRy\": ");
sb.append(boundingTetragon.getBottomRight().y);
sb.append(", \"TLx\": ");
sb.append(boundingTetragon.getTopLeft().x);
sb.append(", \"TLy\": ");
sb.append(boundingTetragon.getTopLeft().y);
sb.append(", \"TRx\": ");
sb.append(boundingTetragon.getTopRight().x);
sb.append(", \"TRy\": ");
sb.append(boundingTetragon.getTopRight().y);
sb.append(" }");
return str.replace(cornersJsonFromMetaData, sb.toString());
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public class a {
public ErrorInfo bg;
public boolean bh;
final ImageProcessor bi;
public a(ImageProcessor imageProcessor, ErrorInfo errorInfo, boolean z) {
this.bi = imageProcessor;
ErrorInfo errorInfo2 = ErrorInfo.KMC_SUCCESS;
this.bg = errorInfo;
this.bh = z;
}
}
/* loaded from: classes3.dex */
public class IpProgressClient implements IpLib.ProcessingProgressClient {
final ImageProcessor bi;
public IpProgressClient(ImageProcessor imageProcessor) {
this.bi = imageProcessor;
}
@Override // com.kofax.kmc.ken.engines.iplib.IpLib.ProcessingProgressClient
public void handleIpProgressUpdate(int i, Object obj) {
ProcessPageOutRep processPageOutRep = (ProcessPageOutRep) obj;
Handler handler = new Handler(Looper.getMainLooper());
if (processPageOutRep.callbackOnWorkerThread) {
this.bi.a(ErrorInfo.KMC_SUCCESS, processPageOutRep.imageID, i);
} else {
handler.post(new Runnable(this, processPageOutRep, i) { // from class: com.kofax.kmc.ken.engines.ImageProcessor.IpProgressClient.1
final ProcessPageOutRep bj;
final int bk;
final IpProgressClient bl;
{
this.bl = this;
this.bj = processPageOutRep;
this.bk = i;
}
@Override // java.lang.Runnable
public void run() {
this.bl.bi.a(ErrorInfo.KMC_SUCCESS, this.bj.imageID, this.bk);
}
});
}
}
}
/* loaded from: classes3.dex */
public class QaProgressClient implements IpLib.ProcessingProgressClient {
final ImageProcessor bi;
public QaProgressClient(ImageProcessor imageProcessor) {
this.bi = imageProcessor;
}
@Override // com.kofax.kmc.ken.engines.iplib.IpLib.ProcessingProgressClient
public void handleIpProgressUpdate(int i, Object obj) {
ProcessPageOutRep processPageOutRep = (ProcessPageOutRep) obj;
Handler handler = new Handler(Looper.getMainLooper());
if (processPageOutRep.callbackOnWorkerThread) {
this.bi.b(ErrorInfo.KMC_SUCCESS, processPageOutRep.imageID, i);
} else {
handler.post(new Runnable(this, processPageOutRep, i) { // from class: com.kofax.kmc.ken.engines.ImageProcessor.QaProgressClient.1
final ProcessPageOutRep bj;
final int bk;
final QaProgressClient by;
{
this.by = this;
this.bj = processPageOutRep;
this.bk = i;
}
@Override // java.lang.Runnable
public void run() {
this.by.bi.b(ErrorInfo.KMC_SUCCESS, this.bj.imageID, this.bk);
}
});
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public class b implements Callable<ImageService.EnhancementResults> {
public ImagePerfectionProfile aP;
public boolean bh;
final ImageProcessor bi;
public ImageProcessorConfiguration bm;
public Image bn;
public ProcessPageOutRep bo;
public IpLib.ProcessingProgressClient bp;
private ImageService.EnhancementResults bq;
private BoundingTetragon br;
public Point bs;
private boolean bt;
public float bu;
public Image originalImage;
private b(ImageProcessor imageProcessor) {
this.bi = imageProcessor;
this.aP = null;
this.bm = null;
this.originalImage = null;
this.bn = null;
this.bh = false;
this.bp = null;
this.bq = null;
this.br = null;
this.bs = new Point();
this.bt = false;
this.bu = BitmapDescriptorFactory.HUE_RED;
}
/* synthetic */ b(ImageProcessor imageProcessor, AnonymousClass1 anonymousClass1) {
this(imageProcessor);
}
@Override // java.util.concurrent.Callable
/* renamed from: p, reason: merged with bridge method [inline-methods] */
public ImageService.EnhancementResults call() throws Exception {
Image.FriendI friendI;
ErrorInfo errorInfo;
ErrorInfo errorInfo2 = ErrorInfo.KMC_SUCCESS;
this.bo.imageID = this.originalImage.getImageID();
if (this.aP == null && this.bm == null) {
errorInfo = ErrorInfo.KMC_IP_NO_PROFILE;
} else if (this.bh) {
Bitmap imageBitmap = this.originalImage.getImageBitmap();
if (imageBitmap == null) {
errorInfo = ErrorInfo.KMC_ED_NOIMAGE;
errorInfo.setErrCause("imageBitmap field is null");
} else if (imageBitmap.isRecycled()) {
errorInfo = ErrorInfo.KMC_ED_NOIMAGE;
errorInfo.setErrCause("imageBitmap has been recycled");
} else {
errorInfo = c(imageBitmap);
}
} else {
String imageFilePath = this.originalImage.getImageFilePath();
if (imageFilePath == null) {
ErrorInfo.KMC_ED_FILEPATH.setErrCause("imageFilePath field is null");
}
if (!new File(imageFilePath).exists()) {
ErrorInfo errorInfo3 = ErrorInfo.KMC_ED_NONEXISTENT_FILE;
}
Bitmap imageBitmap2 = this.originalImage.getImageBitmap();
try {
friendI = new Image.FriendI(this.originalImage, BuildConfig.APPLICATION_ID);
try {
friendI.clearBitmapWithoutRecycle();
} catch (KmcException unused) {
}
} catch (KmcException unused2) {
friendI = null;
}
ErrorInfo a = this.bi.a(this.originalImage, friendI);
if (a == ErrorInfo.KMC_SUCCESS || a == ErrorInfo.KMC_ED_ALTERNATE_FILEIO_ENGINE) {
a = c(this.originalImage.getImageBitmap());
if (imageBitmap2 == null) {
this.originalImage.imageClearBitmap();
} else {
friendI.setImageBitmapInternal(imageBitmap2);
}
}
errorInfo = a;
}
if (this.bq == null) {
this.bq = new ImageService.EnhancementResults(errorInfo);
}
return this.bq;
}
private ErrorInfo c(Bitmap bitmap) {
ImagePerfectionProfile imagePerfectionProfile;
Bitmap bitmap2;
Integer num;
Bitmap bitmap3 = bitmap;
if (this.bt) {
return ErrorInfo.KMC_EV_CANCEL_OPERATION_SUCCESS;
}
QuickAnalysisSettings quickAnalysisSettings = this.bo.quickAnalysisSettings;
d dVar = new d(this.aP, this.bm);
if (quickAnalysisSettings != null && quickAnalysisSettings.getBlurDetection()) {
System.loadLibrary("a1ac4");
System.loadLibrary("ee77d4");
System.loadLibrary("jbc3");
XVrsImage xVrsImage = new XVrsImage(bitmap3);
this.bu = new XVrsBlur().detect(xVrsImage);
xVrsImage.dispose();
}
ImagePerfectionProfile imagePerfectionProfile2 = this.aP;
if ((imagePerfectionProfile2 != null && imagePerfectionProfile2.getUseTargetFrameCrop() == ImagePerfectionProfile.UseTargetFrameCrop.ON) || ((quickAnalysisSettings != null && quickAnalysisSettings.getUseTargetFrameCrop() == ImagePerfectionProfile.UseTargetFrameCrop.ON) || (this.bm != null && TargetFrameCropType.TARGET_FRAME_CROP_ON.equals(this.bm.targetFrameCropType)))) {
Point point = new Point();
bitmap3 = a(bitmap3, point);
this.bs.x += point.x;
this.bs.y += point.y;
}
if ((this.bm == null && dVar.contains(ImageProcessor.az)) || (((imagePerfectionProfile = this.aP) != null && imagePerfectionProfile.getUseDocumentDetectionBasedCrop() == ImagePerfectionProfile.UseDocumentDetectionBasedCrop.ON) || q())) {
c.a i = this.bi.aE.i(bitmap3);
Bitmap bitmap4 = i.bitmap;
if (i.Ho != null) {
this.bs.x += i.Ho.left;
this.bs.y += i.Ho.top;
}
bitmap3 = bitmap4;
}
Integer num2 = null;
if (this.bm != null) {
com.kofax.mobile.sdk.ae.f fVar = new com.kofax.mobile.sdk.ae.f();
com.kofax.mobile.sdk.ae.g a = fVar.a(this.bm, bitmap3);
Bitmap processedImage = a.getProcessedImage();
this.br = a.getBounds();
if (a.lR()) {
this.bm.documentDimensions = null;
Integer num3 = this.bm.outputDPI;
if (num3 != null && num3.intValue() > 0) {
this.bm.outputDPI = 0;
num2 = num3;
}
}
fVar.doCleanUp();
num = num2;
bitmap2 = processedImage;
} else {
bitmap2 = bitmap3;
num = null;
}
if (this.bt) {
return ErrorInfo.KMC_EV_CANCEL_OPERATION_SUCCESS;
}
ErrorInfo errorInfo = ErrorInfo.KMC_SUCCESS;
this.bn = new Image();
try {
Image.FriendI friendI = new Image.FriendI(this.originalImage, BuildConfig.APPLICATION_ID);
Image.FriendI friendI2 = new Image.FriendI(this.bn, BuildConfig.APPLICATION_ID);
friendI2.setImageOriginalDateTime(friendI.getImageOriginalDateTime());
friendI2.setImageLatitude(this.originalImage.getImageLatitude());
friendI2.setImageLongitude(this.originalImage.getImageLongitude());
this.bo.exifMetadataStr = ImageService.createMetadataFromImage(this.bn, Image.FileRestriction.NONE);
ImagePerfectionProfile imagePerfectionProfile3 = this.aP;
if (imagePerfectionProfile3 == null) {
if (this.bi.aQ != null) {
friendI2.setBasicSettingsProfileUsed(this.bi.aQ);
}
} else {
friendI2.setImagePerfectProfileUsed(imagePerfectionProfile3);
}
} catch (KmcException e) {
errorInfo = e.getErrorInfo();
}
this.bn.setTargetFrame(this.originalImage.getTargetFrame());
boolean z = dVar.contains(IpLib.DO_RECOGNIZE_TEXT_MP) || dVar.contains("_DoRemoveGraphicLines_") || dVar.contains("_DoFindTextHP_") || dVar.contains("_UseLargeMetadataBuffer_");
boolean z2 = dVar.contains("_DoPreview_2") || dVar.contains("_DoPreview_4") || dVar.contains("_DoPreview_6");
int i2 = z ? 102400 : 10240;
if (z2) {
try {
this.bo.imageRep = Image.ImageRep.IMAGE_REP_NONE;
} catch (KmcException e2) {
return e2.getErrorInfo();
} catch (KmcRuntimeException e3) {
return e3.getErrorInfo();
}
}
if (this.bt) {
return ErrorInfo.KMC_EV_CANCEL_OPERATION_SUCCESS;
}
this.bq = ImageService.enhanceImage(bitmap2, this.aP, this.bm, null, this.originalImage, i2, this.bo, this.bp, this.bn, num);
return errorInfo;
}
private Bitmap a(Bitmap bitmap, Point point) {
if (this.originalImage.getTargetFrame() == null) {
return bitmap;
}
Rect targetFrame = this.originalImage.getTargetFrame();
com.kofax.mobile.sdk._internal.k.D(String.format(Locale.US, "targetFrameCrop (x: %d y: %d, w: %d h: %d)", Integer.valueOf(targetFrame.left), Integer.valueOf(targetFrame.top), Integer.valueOf(targetFrame.width()), Integer.valueOf(targetFrame.height())));
int i = targetFrame.left;
int i2 = targetFrame.left;
int width = targetFrame.width();
int i3 = targetFrame.top;
int i4 = targetFrame.top;
int height = targetFrame.height();
int max = Math.max(0, i);
int max2 = Math.max(0, i3);
int min = Math.min(bitmap.getWidth(), i2 + width);
int min2 = Math.min(bitmap.getHeight(), i4 + height);
if (point != null) {
point.set(max, max2);
}
return Bitmap.createBitmap(bitmap, max, max2, min - max, min2 - max2);
}
private boolean q() {
QuickAnalysisSettings quickAnalysisSettings = this.bo.quickAnalysisSettings;
return quickAnalysisSettings != null && quickAnalysisSettings.getUseDocumentDetectionBasedCrop() == ImagePerfectionProfile.UseDocumentDetectionBasedCrop.ON;
}
}
private void l() {
if (!Licensing.isSdkLicensed(Licensing.LicenseType.IMAGE_PROCESSING)) {
throw new KmcRuntimeException(ErrorInfo.KMC_UT_LICENSE_IMAGE_PROCESSING);
}
}
private void a(Object obj, String str) {
if (obj == null) {
StringBuilder sb = new StringBuilder("'");
sb.append(str);
sb.append("' parameter is null");
throw new NullPointerException(sb.toString());
}
if ((!obj.getClass().getSimpleName().equals("Integer") || ((Integer) obj).intValue() >= 0) && (!obj.getClass().getSimpleName().equals("Float") || ((Float) obj).floatValue() >= BitmapDescriptorFactory.HUE_RED)) {
return;
}
ErrorInfo errorInfo = ErrorInfo.KMC_GN_PARAM_NEGATIVE;
StringBuilder sb2 = new StringBuilder("'");
sb2.append(str);
sb2.append("' parameter is negative");
errorInfo.setErrCause(sb2.toString());
throw new KmcRuntimeException(errorInfo);
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: com.kofax.kmc.ken.engines.ImageProcessor$1, reason: invalid class name */
/* loaded from: classes3.dex */
public static /* synthetic */ class AnonymousClass1 {
static final int[] bd;
static {
int[] iArr = new int[ErrorInfo.values().length];
bd = iArr;
try {
iArr[ErrorInfo.KMC_GN_FILE_NOT_FOUND.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
bd[ErrorInfo.KMC_ED_NONEXISTENT_FILE.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
bd[ErrorInfo.KMC_GN_OUT_OF_MEMORY.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
try {
bd[ErrorInfo.KMC_ED_FILE_STILL_REMAINS.ordinal()] = 4;
} catch (NoSuchFieldError unused4) {
}
try {
bd[ErrorInfo.KMC_ED_FILE_EXISTS.ordinal()] = 5;
} catch (NoSuchFieldError unused5) {
}
try {
bd[ErrorInfo.KMC_EV_PROCESS_PAGE_BUSY.ordinal()] = 6;
} catch (NoSuchFieldError unused6) {
}
}
}
private boolean a(ErrorInfo errorInfo) {
switch (AnonymousClass1.bd[errorInfo.ordinal()]) {
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
return true;
default:
return false;
}
}
private TaskRunner m() {
if (this.aZ == null) {
this.aZ = new TaskRunner(1);
}
return this.aZ;
}
private a f(Image image) {
ErrorInfo errorInfo = ErrorInfo.KMC_SUCCESS;
boolean z = false;
boolean z2 = image.getImageBitmapScaling().floatValue() < 1.0f;
if (bb != 0) {
errorInfo = ErrorInfo.KMC_EV_PROCESS_PAGE_BUSY;
} else if (image.getImageRepresentation() == Image.ImageRep.IMAGE_REP_BITMAP) {
if (z2) {
errorInfo = ErrorInfo.KMC_IP_NO_REPRESENTATION;
errorInfo.setErrCause("Only representation is bitmap but it is scaled down");
} else {
z = true;
}
} else if (image.getImageRepresentation() == Image.ImageRep.IMAGE_REP_FILE) {
if (image.getImageFileRep() == Image.ImageFileRep.FILE_BUFFERED) {
errorInfo = ErrorInfo.KMC_IP_FILE_AND_BUFFERED_REPRESENTATION;
}
} else if (image.getImageRepresentation() == Image.ImageRep.IMAGE_REP_BOTH) {
z = !z2;
} else {
errorInfo = ErrorInfo.KMC_IP_NO_REPRESENTATION;
}
if (errorInfo == ErrorInfo.KMC_SUCCESS) {
if (z) {
if (image.getImageBitmap() == null) {
errorInfo = ErrorInfo.KMC_ED_NOIMAGE;
errorInfo.setErrCause("imageBitmap field is null");
}
} else {
String imageFilePath = image.getImageFilePath();
if (imageFilePath == null) {
errorInfo = ErrorInfo.KMC_ED_FILEPATH;
errorInfo.setErrCause("imageFilePath field is null");
} else if (!new File(imageFilePath).exists()) {
errorInfo = ErrorInfo.KMC_GN_FILE_NOT_FOUND;
}
}
}
return new a(this, errorInfo, z);
}
private String g(Image image) {
if (image.getImageMetaData().isEmpty()) {
return (image.getImageLatitude() == null || image.getImageLongitude() == null) ? "" : ImageService.createGPSMetadata(image);
}
return image.getImageMetaData();
}
private ProcessPageOutRep a(boolean z, boolean z2) {
ProcessPageOutRep processPageOutRep = new ProcessPageOutRep();
processPageOutRep.setQuickAnalysisMode(z, z2);
processPageOutRep.callbackOnWorkerThread = getListenerCallbackThreadType() == ListenerCallbackThreadType.WORKER_THREAD;
if (!z) {
processPageOutRep.setImageMimeType(getProcessedImageMimeType());
processPageOutRep.setImageRep(getProcessedImageRepresentation());
processPageOutRep.processedFilePathStr = getProcessedImageFilePath();
processPageOutRep.processedImageJpegQuality = getProcessedImageJpegQuality();
}
return processPageOutRep;
}
private ProcessPageOutRep a(boolean z, boolean z2, QuickAnalysisSettings quickAnalysisSettings) {
ProcessPageOutRep a2 = a(z, z2);
a2.setQuickAnalysisSettings(quickAnalysisSettings);
return a2;
}
private void a(Image image, boolean z, boolean z2, QuickAnalysisSettings quickAnalysisSettings, ImageProcessorConfiguration imageProcessorConfiguration) throws KmcException {
IpLib.ProcessingProgressClient ipProgressClient;
ErrorInfo errorInfo = ErrorInfo.KMC_SUCCESS;
a f = f(image);
ErrorInfo errorInfo2 = f.bg;
if (!z) {
if (ErrorInfo.KMC_SUCCESS == errorInfo2 && this.aQ == null && this.aP == null && imageProcessorConfiguration == null) {
errorInfo2 = ErrorInfo.KMC_IP_NO_PROFILE;
}
if (ErrorInfo.KMC_SUCCESS == errorInfo2 && (this.aR == Image.ImageRep.IMAGE_REP_FILE || this.aR == Image.ImageRep.IMAGE_REP_BOTH)) {
if (this.aT == Image.ImageMimeType.MIMETYPE_UNKNOWN) {
errorInfo2 = ErrorInfo.KMC_ED_MIMETYPE;
errorInfo2.setErrCause("processedImageMimeType set to MIMETYPE_UNKNOWN");
} else if (gjJ.e(this.aS)) {
errorInfo2 = ErrorInfo.KMC_ED_FILEPATH;
errorInfo2.setErrCause("processedImageFilePath field is whitespace, empty, or null");
} else {
File file = new File(this.aS);
if (file.getParentFile() == null || !file.getParentFile().exists()) {
errorInfo2 = ErrorInfo.KMC_GN_FILE_NOT_FOUND;
errorInfo2.setErrCause("File path is incorrect");
} else if (!file.getParentFile().exists()) {
errorInfo2 = ErrorInfo.KMC_GN_FILE_NOT_FOUND;
StringBuilder sb = new StringBuilder("processedImageFilePath parent directory");
sb.append(file.getParent());
sb.append(" does not exist");
errorInfo2.setErrCause(sb.toString());
} else if (file.exists()) {
errorInfo2 = ErrorInfo.KMC_ED_FILE_EXISTS;
StringBuilder sb2 = new StringBuilder("processedImageFilePath ");
sb2.append(file.getAbsolutePath());
sb2.append(" already exists");
errorInfo2.setErrCause(sb2.toString());
}
}
}
}
if (errorInfo2 != ErrorInfo.KMC_SUCCESS) {
if (a(errorInfo2)) {
throw new KmcException(errorInfo2);
}
throw new KmcRuntimeException(errorInfo2);
}
this._bus.post(new com.kofax.mobile.sdk.s.b(image));
this.ba = new b(this, null);
if (z) {
ImagePerfectionProfile imagePerfectionProfile = new ImagePerfectionProfile();
if (z2) {
imagePerfectionProfile.setIpOperations("_DeviceType_2__DoPreview__LoadSetting_<Property Name=\"CSkewDetect.do_blur_check.Bool\" Value=\"0\"/>_LoadSetting_<Property Name=\"CSkewDetect.side_angle_diff_thr.double\" Value=\"50.0\" Comment=\"DEFAULT 1\" />_LoadSetting_<Property Name=\"CSkewDetect.Undersaturated_Threshold.Int\" Value=\"18.0\"/>_LoadSetting_<Property Name=\"CSkewDetect.Undersaturation_Count_Perc_Threshold.Int\" Value=\"49.0\"/>");
} else {
imagePerfectionProfile.setIpOperations("_DeviceType_2__DoPreview_6_LoadSetting_<Property Name=\"CSkewDetect.do_blur_check.Bool\" Value=\"0\"/>_LoadSetting_<Property Name=\"CSkewDetect.side_angle_diff_thr.double\" Value=\"50.0\" Comment=\"DEFAULT 1\" />_LoadSetting_<Property Name=\"CSkewDetect.Undersaturated_Threshold.Int\" Value=\"18.0\"/>_LoadSetting_<Property Name=\"CSkewDetect.Undersaturation_Count_Perc_Threshold.Int\" Value=\"49.0\"/>");
}
if (quickAnalysisSettings.getUseMRZPassportDetection() == ImagePerfectionProfile.UseMRZPassportDetection.ON) {
imagePerfectionProfile.setUseMRZPassportDetection(ImagePerfectionProfile.UseMRZPassportDetection.ON);
}
this.ba.aP = imagePerfectionProfile;
} else {
if (getBasicSettingsProfile() != null) {
BasicSettingsProfile basicSettingsProfile = getBasicSettingsProfile();
String finalOpString = new BasicSettingsProfile.FriendBSP(basicSettingsProfile, BuildConfig.APPLICATION_ID).toFinalOpString();
if (basicSettingsProfile.getCropType() == BasicSettingsProfile.CropType.CROP_QUICKANALYSIS) {
StringBuilder sb3 = new StringBuilder();
sb3.append(finalOpString);
sb3.append(h(image));
finalOpString = sb3.toString();
}
if (imageProcessorConfiguration == null && basicSettingsProfile.getCropType() == BasicSettingsProfile.CropType.CROP_TETRAGON) {
ImagePerfectionProfile imagePerfectionProfile2 = new ImagePerfectionProfile();
imagePerfectionProfile2.setIpOperations(finalOpString);
this.ba.aP = imagePerfectionProfile2;
this.ba.bm = null;
} else {
this.ba.bm = new ImageProcessorConfiguration(finalOpString);
}
}
if (getImagePerfectionProfile() != null) {
ImagePerfectionProfile imagePerfectionProfile3 = getImagePerfectionProfile();
String finalOpString2 = new ImagePerfectionProfile.FriendIPP(imagePerfectionProfile3, BuildConfig.APPLICATION_ID).toFinalOpString();
if (!finalOpString2.contains(aA) && !finalOpString2.contains(aB) && !finalOpString2.contains(aC)) {
this.ba.bm = new ImageProcessorConfiguration(finalOpString2.replaceAll(aD, "").replaceAll(az, ""));
if (imagePerfectionProfile3.getUseTargetFrameCrop() == ImagePerfectionProfile.UseTargetFrameCrop.ON) {
this.ba.bm.targetFrameCropType = TargetFrameCropType.TARGET_FRAME_CROP_ON;
}
} else {
this.ba.aP = imagePerfectionProfile3;
}
}
if (imageProcessorConfiguration != null) {
String str = com.kofax.mobile.sdk.ae.c.a(imageProcessorConfiguration).ippString;
if (str.contains(aB) || str.contains(aC) || str.contains(aA)) {
this.ba.aP = new ImagePerfectionProfile();
this.ba.aP.setIpOperations(com.kofax.mobile.sdk.ae.c.a(imageProcessorConfiguration, true, false).ippString);
this.ba.bm = null;
} else {
this.ba.bm = imageProcessorConfiguration;
}
}
}
if (this.ba.aP != null) {
String str2 = TAG;
StringBuilder sb4 = new StringBuilder("Op String:");
sb4.append(this.ba.aP.getIpOperations());
com.kofax.mobile.sdk._internal.k.c(str2, sb4.toString());
}
this.ba.originalImage = image;
this.ba.bh = f.bh;
this.ba.bo = a(z, z2, quickAnalysisSettings);
if (z) {
ipProgressClient = new QaProgressClient(this);
} else {
ipProgressClient = new IpProgressClient(this);
}
this.ba.bp = ipProgressClient;
TaskRunner m = m();
c cVar = new c(this, this.ba);
cVar.bw = this;
cVar.bo = this.ba.bo;
this.aZ.addOnTaskCompletedListener(cVar, this.ba, this.aU == ListenerCallbackThreadType.UI_THREAD);
bb = m.submit(this.ba);
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public static class d {
private final String bx;
public d(ImagePerfectionProfile imagePerfectionProfile, ImageProcessorConfiguration imageProcessorConfiguration) {
this(imagePerfectionProfile == null ? com.kofax.mobile.sdk.ae.c.a(imageProcessorConfiguration).ippString : imagePerfectionProfile.getIpOperations());
}
public d(String str) {
this.bx = (str == null ? "" : str).toLowerCase(Locale.US);
}
public boolean contains(String str) {
return this.bx.contains(str.toLowerCase(Locale.US));
}
}
private static String h(Image image) {
QuickAnalysisFeedback imageQuickAnalysisFeedBack = image.getImageQuickAnalysisFeedBack();
StringBuilder sb = new StringBuilder("");
if (imageQuickAnalysisFeedBack != null) {
try {
try {
BoundingTetragon.FriendBT friendBT = new BoundingTetragon.FriendBT(ImageService.getCornersTetragonFromJson(ImageService.getCornersJsonFromMetaData(new QuickAnalysisFeedback.FriendQAF(imageQuickAnalysisFeedBack, BuildConfig.APPLICATION_ID).getMetadata())), BuildConfig.APPLICATION_ID);
sb.append(IpLib.DO_CROP_CORRECTION);
sb.append(friendBT.toExtCornersOpString("_LoadSetting_"));
} catch (KmcException e) {
com.kofax.mobile.sdk._internal.k.e(e);
}
} catch (KmcException e2) {
com.kofax.mobile.sdk._internal.k.e(e2);
}
}
return sb.toString();
}
public void setProcessedImageRepresentation(Image.ImageRep imageRep) {
this.aR = imageRep;
}
public void setProcessedImageMimeType(Image.ImageMimeType imageMimeType) {
this.aT = imageMimeType;
}
public void setProcessedImageFilePath(String str) {
this.aS = str;
}
public void setListenerCallbackThreadType(ListenerCallbackThreadType listenerCallbackThreadType) {
this.aU = listenerCallbackThreadType;
}
public Image.ImageRep getProcessedImageRepresentation() {
return this.aR;
}
public Image.ImageMimeType getProcessedImageMimeType() {
return this.aT;
}
public int getProcessedImageJpegQuality() {
return this.processedImageJpegQuality;
}
public String getProcessedImageFilePath() {
return this.aS;
}
public ListenerCallbackThreadType getListenerCallbackThreadType() {
return this.aU;
}
}