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

2015 lines
87 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.kofax.kmc.ken.engines.service;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Debug;
import android.os.Environment;
import android.text.TextUtils;
import com.airbnb.deeplinkdispatch.UrlTreeKt;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.common.primitives.UnsignedBytes;
import com.kofax.BuildConfig;
import com.kofax.kmc.ken.engines.data.BarCodeDataFormat;
import com.kofax.kmc.ken.engines.data.BarCodeResult;
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.iplib.IpFileBuffer;
import com.kofax.kmc.ken.engines.iplib.IpImage;
import com.kofax.kmc.ken.engines.iplib.IpImageMetadata;
import com.kofax.kmc.ken.engines.iplib.IpLib;
import com.kofax.kmc.ken.engines.iplib.ProcessPageOutRep;
import com.kofax.kmc.ken.engines.iplib.ProcessPageResults;
import com.kofax.kmc.ken.engines.processing.ImageProcessorConfiguration;
import com.kofax.kmc.kut.utilities.AppContextProvider;
import com.kofax.kmc.kut.utilities.IpLibUtil;
import com.kofax.kmc.kut.utilities.error.ErrorInfo;
import com.kofax.kmc.kut.utilities.error.FileNotFoundException;
import com.kofax.kmc.kut.utilities.error.IOException;
import com.kofax.kmc.kut.utilities.error.InternalError;
import com.kofax.kmc.kut.utilities.error.KmcException;
import com.kofax.kmc.kut.utilities.error.KmcRuntimeException;
import com.kofax.mobile.sdk._internal.impl.extraction.rtti.RttiJsonExactionHelper;
import com.kofax.mobile.sdk._internal.k;
import com.kofax.mobile.sdk.ae.c;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import o.gjJ;
import o.gjP;
import o.gjT;
import o.gjU;
import org.json.JSONException;
import org.json.JSONObject;
/* loaded from: classes3.dex */
public class ImageService {
public static final String EXIF_TIME_FORMAT = "yyyy:MM:dd HH:mm:ss";
public static final String KExifTagDateTime = "Digitized Date Time: ";
public static final String KExifTagDateTimeDigitized = "File_Change_Date_Time: ";
public static final String KExifTagDateTimeOriginal = "Original Date Time: ";
private static final String TAG = "ImageService";
private static final int ig = 1;
private static final int ih = 1;
private static final int ii = 200;
private static final int ij = 200;
private static final int ik = 24;
private static final int il = 3;
private static final int im = 72;
/* renamed from: io, reason: collision with root package name */
private static final int f6503io = 72;
private static final int ip = 5;
static final int iq = 0;
static final int ir = 2;
static final int is = 3;
static final int it = 5;
private static final String iv = "Software Used: Kofax";
private static final boolean iw = true;
public static boolean passBarcodes = false;
private static final gjT iu = gjP.e;
private static UseableImageMemoryLimit ix = UseableImageMemoryLimit.NORMAL;
private static InterimImageFileFormat iy = InterimImageFileFormat.PNG;
/* loaded from: classes3.dex */
public enum InterimImageFileFormat {
PNG,
JPEG
}
/* loaded from: classes3.dex */
public enum UseableImageMemoryLimit {
NORMAL,
LARGE,
MAXIMUM
}
/* loaded from: classes3.dex */
public static class ImageDimension {
private int height;
private int width;
public ImageDimension(int i, int i2) {
this.width = i;
this.height = i2;
}
public void setWidth(int i) {
this.width = i;
}
public void setHeight(int i) {
this.height = i;
}
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
}
public static IpImageMetadata getImageFileMetadata(String str) {
IpImageMetadata ipImageMetadata = new IpImageMetadata();
readBitmapFromFileUsingIp(str, 1.0f, ipImageMetadata);
return ipImageMetadata;
}
public static void cancelImageProcessing() {
try {
IpLib.getInstance().cancelProcessing();
} catch (KmcException unused) {
}
}
public static String createGPSMetadata(Image image) {
StringBuilder sb = new StringBuilder("GPS Latitude Reference: ");
String str = image.getImageLatitude().floatValue() < BitmapDescriptorFactory.HUE_RED ? "S" : "N";
String str2 = image.getImageLongitude().floatValue() < BitmapDescriptorFactory.HUE_RED ? "W" : "E";
sb.append(str);
sb.append(System.getProperty("line.separator"));
sb.append("GPS Latitude: ");
int intValue = image.getImageLatitude().intValue();
sb.append(Integer.toString(intValue));
sb.append("/1, ");
sb.append(Integer.toString(Float.valueOf((image.getImageLatitude().floatValue() - intValue) * 100.0f * 60.0f).intValue()));
sb.append("/100, 0/1");
sb.append(System.getProperty("line.separator"));
sb.append("GPS Longitude Reference: ");
sb.append(str2);
sb.append(System.getProperty("line.separator"));
sb.append("GPS Longitude: ");
int intValue2 = image.getImageLongitude().intValue();
sb.append(Integer.toString(intValue2));
sb.append("/1, ");
sb.append(Integer.toString(Float.valueOf((image.getImageLongitude().floatValue() - intValue2) * 100.0f * 60.0f).intValue()));
sb.append("/100, 0/1");
sb.append(System.getProperty("line.separator"));
return sb.toString();
}
public static String createTargetFrameMetadata(Image image) {
StringBuilder sb = new StringBuilder("Subject Area: ");
Rect targetFrame = image.getTargetFrame();
sb.append(String.format(Locale.US, "%d, %d, %d, %d", Integer.valueOf(targetFrame.centerX()), Integer.valueOf(targetFrame.centerY()), Integer.valueOf(targetFrame.width()), Integer.valueOf(targetFrame.height())));
sb.append(System.getProperty("line.separator"));
return sb.toString();
}
public static ErrorInfo saveBitmap(Bitmap bitmap, String str, Image.ImageMimeType imageMimeType, int i) {
FileOutputStream fileOutputStream;
BufferedOutputStream bufferedOutputStream;
k.b(TAG, "Saving a bitmap to ".concat(String.valueOf(str)));
ErrorInfo errorInfo = ErrorInfo.KMC_SUCCESS;
Bitmap.CompressFormat compressFormat = imageMimeType == Image.ImageMimeType.MIMETYPE_JPEG ? Bitmap.CompressFormat.JPEG : Bitmap.CompressFormat.PNG;
if (imageMimeType == Image.ImageMimeType.MIMETYPE_TIFF || imageMimeType == Image.ImageMimeType.MIMETYPE_UNKNOWN) {
ErrorInfo errorInfo2 = ErrorInfo.KMC_ED_MIMETYPE;
errorInfo2.setErrCause("saveBitmap method supports MIMETYPE_JPG, MIMETYPE_PNG only");
return errorInfo2;
}
BufferedOutputStream bufferedOutputStream2 = null;
try {
try {
} catch (Exception e) {
k.e(TAG, "Error flushing streams", (Throwable) e);
}
} catch (Exception e2) {
e = e2;
fileOutputStream = null;
} catch (Throwable th) {
th = th;
fileOutputStream = null;
}
if (new File(str).exists()) {
ErrorInfo errorInfo3 = ErrorInfo.KMC_ED_FILE_EXISTS;
StringBuilder sb = new StringBuilder("saveBitmap failed: file ");
sb.append(str);
sb.append(" already exists.");
errorInfo3.setErrCause(sb.toString());
return errorInfo3;
}
fileOutputStream = new FileOutputStream(str);
try {
try {
bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
} catch (Exception e3) {
e = e3;
}
} catch (Throwable th2) {
th = th2;
}
try {
if (!bitmap.compress(compressFormat, i, bufferedOutputStream)) {
errorInfo = ErrorInfo.KMC_ED_BITMAP_WRITE_TO_FILE_FAILED;
StringBuilder sb2 = new StringBuilder("bitmap.compress failed: file ");
sb2.append(str);
sb2.append(", quality=");
sb2.append(i);
errorInfo.setErrCause(sb2.toString());
}
bufferedOutputStream.flush();
bufferedOutputStream.close();
fileOutputStream.flush();
} catch (Exception e4) {
e = e4;
bufferedOutputStream2 = bufferedOutputStream;
String str2 = TAG;
StringBuilder sb3 = new StringBuilder("Error saving image - ");
sb3.append(str);
k.e(str2, sb3.toString(), (Throwable) e);
errorInfo = ErrorInfo.KMC_ED_BITMAP_WRITE_TO_FILE_FAILED;
StringBuilder sb4 = new StringBuilder("bitmap.compress exception: file ");
sb4.append(str);
sb4.append(", quality=");
sb4.append(i);
sb4.append(", exception info: ");
sb4.append(e.getMessage());
errorInfo.setErrCause(sb4.toString());
if (bufferedOutputStream2 != null) {
bufferedOutputStream2.flush();
bufferedOutputStream2.close();
}
if (fileOutputStream != null) {
fileOutputStream.flush();
fileOutputStream.close();
}
return errorInfo;
} catch (Throwable th3) {
th = th3;
bufferedOutputStream2 = bufferedOutputStream;
if (bufferedOutputStream2 != null) {
try {
bufferedOutputStream2.flush();
bufferedOutputStream2.close();
} catch (Exception e5) {
k.e(TAG, "Error flushing streams", (Throwable) e5);
throw th;
}
}
if (fileOutputStream != null) {
fileOutputStream.flush();
fileOutputStream.close();
}
throw th;
}
fileOutputStream.close();
return errorInfo;
}
/* JADX WARN: Code restructure failed: missing block: B:22:0x0075, code lost:
if (r13 != null) goto L38;
*/
/* JADX WARN: Code restructure failed: missing block: B:24:0x0090, code lost:
if (r9 != com.kofax.kmc.kut.utilities.error.ErrorInfo.KMC_SUCCESS) goto L43;
*/
/* JADX WARN: Code restructure failed: missing block: B:25:0x0092, code lost:
if (r1 == null) goto L43;
*/
/* JADX WARN: Code restructure failed: missing block: B:26:?, code lost:
return r1;
*/
/* JADX WARN: Code restructure failed: missing block: B:29:0x0096, code lost:
return r9;
*/
/* JADX WARN: Code restructure failed: missing block: B:30:0x008b, code lost:
r14.releaseImage(r13);
*/
/* JADX WARN: Code restructure failed: missing block: B:38:0x0089, code lost:
if (r13 == null) goto L39;
*/
/* JADX WARN: Removed duplicated region for block: B:44:0x0099 */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public static com.kofax.kmc.kut.utilities.error.ErrorInfo saveIpBitmap(android.graphics.Bitmap r15, java.lang.String r16, com.kofax.kmc.ken.engines.data.Image.ImageMimeType r17, int r18, int r19, int r20, java.lang.String r21) {
/*
r0 = r16
r7 = r20
r8 = r21
java.lang.String r1 = com.kofax.kmc.ken.engines.service.ImageService.TAG
java.lang.String r2 = "Saving a bitmap using image processor to "
java.lang.String r3 = java.lang.String.valueOf(r16)
java.lang.String r2 = r2.concat(r3)
com.kofax.mobile.sdk._internal.k.b(r1, r2)
com.kofax.kmc.kut.utilities.error.ErrorInfo r9 = com.kofax.kmc.kut.utilities.error.ErrorInfo.KMC_SUCCESS
com.kofax.kmc.kut.utilities.error.ErrorInfo r10 = com.kofax.kmc.kut.utilities.error.ErrorInfo.KMC_SUCCESS
r1 = 24
r11 = 3
r12 = 1
r3 = r18
if (r3 != r1) goto L23
r2 = r11
goto L24
L23:
r2 = r12
L24:
if (r15 == 0) goto L9d
if (r0 == 0) goto L9d
r13 = 0
com.kofax.kmc.ken.engines.iplib.IpLib r14 = com.kofax.kmc.ken.engines.iplib.IpLib.getInstance() // Catch: java.lang.Throwable -> L7f com.kofax.kmc.kut.utilities.error.KmcException -> L82
r6 = 0
r1 = r15
r3 = r18
r4 = r19
r5 = r19
com.kofax.kmc.ken.engines.iplib.IpImage r13 = a(r1, r2, r3, r4, r5, r6) // Catch: java.lang.Throwable -> L7b com.kofax.kmc.kut.utilities.error.KmcException -> L7d
com.kofax.kmc.kut.utilities.error.ErrorInfo r1 = r13.mErrorInfo // Catch: java.lang.Throwable -> L7b com.kofax.kmc.kut.utilities.error.KmcException -> L7d
int[] r2 = com.kofax.kmc.ken.engines.service.ImageService.AnonymousClass1.iz // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L78 java.lang.Throwable -> L7b
int r3 = r17.ordinal() // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L78 java.lang.Throwable -> L7b
r2 = r2[r3] // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L78 java.lang.Throwable -> L7b
if (r2 == r12) goto L5d
r3 = 2
if (r2 == r3) goto L58
if (r2 == r11) goto L53
com.kofax.kmc.kut.utilities.error.ErrorInfo r9 = com.kofax.kmc.kut.utilities.error.ErrorInfo.KMC_ED_MIMETYPE // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L78 java.lang.Throwable -> L7b
java.lang.String r0 = "saveIpBitmap method does not support MIMETYPE_UNKNOWN"
r9.setErrCause(r0) // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L78 java.lang.Throwable -> L7b
r0 = 0
goto L61
L53:
int r0 = r14.writePngImage(r13, r0) // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L78 java.lang.Throwable -> L7b
goto L61
L58:
int r0 = r14.writeTiffImage(r13, r7, r0, r8) // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L78 java.lang.Throwable -> L7b
goto L61
L5d:
int r0 = r14.writeJpegImage(r13, r7, r0, r8) // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L78 java.lang.Throwable -> L7b
L61:
if (r0 == 0) goto L75
com.kofax.kmc.kut.utilities.IpLibUtil$IpErrHashMap<java.lang.Integer, com.kofax.kmc.kut.utilities.error.ErrorInfo> r2 = com.kofax.kmc.kut.utilities.IpLibUtil.ipErrHashMap // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L78 java.lang.Throwable -> L7b
java.lang.Integer r0 = java.lang.Integer.valueOf(r0) // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L78 java.lang.Throwable -> L7b
java.lang.Object r0 = r2.get(r0) // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L78 java.lang.Throwable -> L7b
r9 = r0
com.kofax.kmc.kut.utilities.error.ErrorInfo r9 = (com.kofax.kmc.kut.utilities.error.ErrorInfo) r9 // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L78 java.lang.Throwable -> L7b
java.lang.String r0 = "saveIpBitmap write to file returned error"
r9.setErrCause(r0) // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L78 java.lang.Throwable -> L7b
L75:
if (r13 == 0) goto L8e
goto L8b
L78:
r0 = move-exception
r10 = r1
goto L84
L7b:
r0 = move-exception
goto L97
L7d:
r0 = move-exception
goto L84
L7f:
r0 = move-exception
r14 = r13
goto L97
L82:
r0 = move-exception
r14 = r13
L84:
com.kofax.kmc.kut.utilities.error.ErrorInfo r9 = r0.getErrorInfo() // Catch: java.lang.Throwable -> L7b
r1 = r10
if (r13 == 0) goto L8e
L8b:
r14.releaseImage(r13)
L8e:
com.kofax.kmc.kut.utilities.error.ErrorInfo r0 = com.kofax.kmc.kut.utilities.error.ErrorInfo.KMC_SUCCESS
if (r9 != r0) goto L95
if (r1 == 0) goto L95
goto L96
L95:
r1 = r9
L96:
return r1
L97:
if (r13 == 0) goto L9c
r14.releaseImage(r13)
L9c:
throw r0
L9d:
if (r15 != 0) goto La2
java.lang.String r0 = "bitmap is null"
goto La4
La2:
java.lang.String r0 = "filename is null"
La4:
com.kofax.kmc.kut.utilities.error.NullPointerException r1 = new com.kofax.kmc.kut.utilities.error.NullPointerException
java.lang.String r2 = "saveIpBitmap: "
java.lang.String r0 = r2.concat(r0)
r1.<init>(r0)
throw r1
*/
throw new UnsupportedOperationException("Method not decompiled: com.kofax.kmc.ken.engines.service.ImageService.saveIpBitmap(android.graphics.Bitmap, java.lang.String, com.kofax.kmc.ken.engines.data.Image$ImageMimeType, int, int, int, java.lang.String):com.kofax.kmc.kut.utilities.error.ErrorInfo");
}
public static int imgMimeTypetoIpFileType(Image.ImageMimeType imageMimeType) {
if (Image.ImageMimeType.MIMETYPE_JPEG == imageMimeType) {
return 2;
}
if (Image.ImageMimeType.MIMETYPE_PNG == imageMimeType) {
return 5;
}
if (Image.ImageMimeType.MIMETYPE_TIFF == imageMimeType) {
return 3;
}
if (imageMimeType == null || Image.ImageMimeType.MIMETYPE_UNKNOWN == imageMimeType) {
return 0;
}
throw new InternalError("ProcessPageOutRep: unable to recognize imageMimeType");
}
public static ErrorInfo saveToFileBuffer(byte[] bArr, IpFileBuffer ipFileBuffer) {
try {
int writeToFileBuffer = IpLib.getInstance().writeToFileBuffer(bArr, ipFileBuffer);
ErrorInfo errorInfo = IpLibUtil.ipErrHashMap.get(Integer.valueOf(writeToFileBuffer));
errorInfo.setErrCause("saveToFileBuffer: writeToFileBuffer returned error ".concat(String.valueOf(writeToFileBuffer)));
return errorInfo;
} catch (KmcException e) {
return e.getErrorInfo();
}
}
/* JADX WARN: Code restructure failed: missing block: B:18:0x003e, code lost:
if (r8 != null) goto L30;
*/
/* JADX WARN: Code restructure failed: missing block: B:20:0x0059, code lost:
if (r0 != com.kofax.kmc.kut.utilities.error.ErrorInfo.KMC_SUCCESS) goto L35;
*/
/* JADX WARN: Code restructure failed: missing block: B:21:0x005b, code lost:
if (r10 == null) goto L35;
*/
/* JADX WARN: Code restructure failed: missing block: B:23:0x0061, code lost:
if (r10 != com.kofax.kmc.kut.utilities.error.ErrorInfo.KMC_EV_MEMORY) goto L51;
*/
/* JADX WARN: Code restructure failed: missing block: B:25:0x0065, code lost:
return com.kofax.kmc.kut.utilities.error.ErrorInfo.KMC_ED_NO_MEMORY_FOR_BUFFERED_FILE;
*/
/* JADX WARN: Code restructure failed: missing block: B:27:?, code lost:
return r10;
*/
/* JADX WARN: Code restructure failed: missing block: B:28:0x005e, code lost:
r10 = r0;
*/
/* JADX WARN: Code restructure failed: missing block: B:29:0x0054, code lost:
r9.releaseImage(r8);
*/
/* JADX WARN: Code restructure failed: missing block: B:34:0x0052, code lost:
if (r8 == null) goto L31;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public static com.kofax.kmc.kut.utilities.error.ErrorInfo saveIpBitmap(android.graphics.Bitmap r10, int r11, com.kofax.kmc.ken.engines.iplib.IpFileBuffer r12) {
/*
java.lang.String r0 = com.kofax.kmc.ken.engines.service.ImageService.TAG
java.lang.String r1 = "Saving a bitmap using image processor to FileBuffer"
com.kofax.mobile.sdk._internal.k.b(r0, r1)
com.kofax.kmc.kut.utilities.error.ErrorInfo r0 = com.kofax.kmc.kut.utilities.error.ErrorInfo.KMC_SUCCESS
com.kofax.kmc.kut.utilities.error.ErrorInfo r1 = com.kofax.kmc.kut.utilities.error.ErrorInfo.KMC_SUCCESS
int r4 = r12.mBitDepth
r2 = 24
if (r4 != r2) goto L13
r2 = 3
goto L14
L13:
r2 = 1
L14:
r3 = r2
if (r10 == 0) goto L6c
r8 = 0
com.kofax.kmc.ken.engines.iplib.IpLib r9 = com.kofax.kmc.ken.engines.iplib.IpLib.getInstance() // Catch: java.lang.Throwable -> L48 com.kofax.kmc.kut.utilities.error.KmcException -> L4b
r7 = 0
r2 = r10
r5 = r11
r6 = r11
com.kofax.kmc.ken.engines.iplib.IpImage r8 = a(r2, r3, r4, r5, r6, r7) // Catch: java.lang.Throwable -> L44 com.kofax.kmc.kut.utilities.error.KmcException -> L46
com.kofax.kmc.kut.utilities.error.ErrorInfo r10 = r8.mErrorInfo // Catch: java.lang.Throwable -> L44 com.kofax.kmc.kut.utilities.error.KmcException -> L46
int r11 = r9.writeImageToFileBuffer(r8, r12) // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L41 java.lang.Throwable -> L44
if (r11 == 0) goto L3e
com.kofax.kmc.kut.utilities.IpLibUtil$IpErrHashMap<java.lang.Integer, com.kofax.kmc.kut.utilities.error.ErrorInfo> r12 = com.kofax.kmc.kut.utilities.IpLibUtil.ipErrHashMap // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L41 java.lang.Throwable -> L44
java.lang.Integer r11 = java.lang.Integer.valueOf(r11) // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L41 java.lang.Throwable -> L44
java.lang.Object r11 = r12.get(r11) // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L41 java.lang.Throwable -> L44
r0 = r11
com.kofax.kmc.kut.utilities.error.ErrorInfo r0 = (com.kofax.kmc.kut.utilities.error.ErrorInfo) r0 // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L41 java.lang.Throwable -> L44
java.lang.String r11 = "saveIpBitmap: writeImageToFileBuffer returned error"
r0.setErrCause(r11) // Catch: com.kofax.kmc.kut.utilities.error.KmcException -> L41 java.lang.Throwable -> L44
L3e:
if (r8 == 0) goto L57
goto L54
L41:
r11 = move-exception
r1 = r10
goto L4d
L44:
r10 = move-exception
goto L66
L46:
r11 = move-exception
goto L4d
L48:
r10 = move-exception
r9 = r8
goto L66
L4b:
r11 = move-exception
r9 = r8
L4d:
com.kofax.kmc.kut.utilities.error.ErrorInfo r0 = r11.getErrorInfo() // Catch: java.lang.Throwable -> L44
r10 = r1
if (r8 == 0) goto L57
L54:
r9.releaseImage(r8)
L57:
com.kofax.kmc.kut.utilities.error.ErrorInfo r11 = com.kofax.kmc.kut.utilities.error.ErrorInfo.KMC_SUCCESS
if (r0 != r11) goto L5e
if (r10 == 0) goto L5e
goto L5f
L5e:
r10 = r0
L5f:
com.kofax.kmc.kut.utilities.error.ErrorInfo r11 = com.kofax.kmc.kut.utilities.error.ErrorInfo.KMC_EV_MEMORY
if (r10 != r11) goto L65
com.kofax.kmc.kut.utilities.error.ErrorInfo r10 = com.kofax.kmc.kut.utilities.error.ErrorInfo.KMC_ED_NO_MEMORY_FOR_BUFFERED_FILE
L65:
return r10
L66:
if (r8 == 0) goto L6b
r9.releaseImage(r8)
L6b:
throw r10
L6c:
com.kofax.kmc.kut.utilities.error.NullPointerException r10 = new com.kofax.kmc.kut.utilities.error.NullPointerException
java.lang.String r11 = "saveIpBitmapToFileBuffer: bitmap is null"
r10.<init>(r11)
throw r10
*/
throw new UnsupportedOperationException("Method not decompiled: com.kofax.kmc.ken.engines.service.ImageService.saveIpBitmap(android.graphics.Bitmap, int, com.kofax.kmc.ken.engines.iplib.IpFileBuffer):com.kofax.kmc.kut.utilities.error.ErrorInfo");
}
public static ErrorInfo deleteImage(File file) {
if (file.exists()) {
String str = TAG;
StringBuilder sb = new StringBuilder("Deleting image from '");
sb.append(file);
sb.append("'");
k.b(str, sb.toString());
return file.delete() ? ErrorInfo.KMC_SUCCESS : ErrorInfo.KMC_ED_FILE_STILL_REMAINS;
}
return ErrorInfo.KMC_GN_FILE_NOT_FOUND;
}
public static Image.KenBitmap createScaledBitmapFromBitmapWithMatrix(Bitmap bitmap, float f) {
Image.KenBitmap kenBitmap = new Image.KenBitmap();
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int round = Math.round(width * f);
int round2 = Math.round(height * f);
Matrix matrix = new Matrix();
matrix.postScale(f, f);
try {
kenBitmap.bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
} catch (OutOfMemoryError e) {
String str = TAG;
StringBuilder sb = new StringBuilder("OOM while creating preview bitmap. width -> ");
sb.append(round);
sb.append(", height -> ");
sb.append(round2);
k.e(str, sb.toString(), (Throwable) e);
ErrorInfo errorInfo = ErrorInfo.KMC_GN_OUT_OF_MEMORY;
errorInfo.setErrCause("Out of memory error creating scaled bitmap from original bitmap with matrix.");
kenBitmap.errInfo = errorInfo;
}
return kenBitmap;
}
/* JADX WARN: Code restructure failed: missing block: B:19:0x0070, code lost:
if (r1 != null) goto L62;
*/
/* JADX WARN: Code restructure failed: missing block: B:23:0x0082, code lost:
r1.close();
*/
/* JADX WARN: Code restructure failed: missing block: B:25:0x0086, code lost:
r8 = move-exception;
*/
/* JADX WARN: Code restructure failed: missing block: B:26:0x0087, code lost:
com.kofax.mobile.sdk._internal.k.e(com.kofax.kmc.ken.engines.service.ImageService.TAG, "Error closing input stream", (java.lang.Throwable) r8);
*/
/* JADX WARN: Code restructure failed: missing block: B:30:0x0080, code lost:
if (r1 == null) goto L37;
*/
/* JADX WARN: Removed duplicated region for block: B:10:0x0056 */
/* JADX WARN: Removed duplicated region for block: B:11:0x0059 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:55:0x00ba A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:10:0x0056 -> B:8:0x0054). Please report as a decompilation issue!!! */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public static android.graphics.Bitmap loadScaledBitmap(android.content.Context r8, android.net.Uri r9, int r10, int r11, int r12) {
/*
long r0 = af()
java.lang.String r2 = com.kofax.kmc.ken.engines.service.FileService.getFileNameByUri(r9, r8)
boolean r3 = o.gjJ.b(r2)
if (r3 != 0) goto L2c
java.io.File r3 = new java.io.File
r3.<init>(r2)
java.lang.String r2 = com.kofax.kmc.ken.engines.service.ImageService.TAG
java.lang.String r4 = "Getting file size..."
com.kofax.mobile.sdk._internal.k.b(r2, r4)
java.lang.String r4 = "... file -> "
java.lang.String r5 = java.lang.String.valueOf(r3)
java.lang.String r4 = r4.concat(r5)
com.kofax.mobile.sdk._internal.k.b(r2, r4)
long r2 = r3.length()
goto L2e
L2c:
r2 = -1
L2e:
r4 = 0
int r4 = (r2 > r4 ? 1 : (r2 == r4 ? 0 : -1))
java.lang.String r5 = "Error closing input stream"
r6 = 1
r7 = 0
if (r4 > 0) goto L42
int r0 = a(r8, r9, r10, r11) // Catch: java.lang.Throwable -> L3d java.lang.Exception -> L40 java.lang.OutOfMemoryError -> L90
goto L54
L3d:
r8 = move-exception
goto Lb7
L40:
r8 = move-exception
goto L78
L42:
int r4 = (r2 > r0 ? 1 : (r2 == r0 ? 0 : -1))
if (r4 <= 0) goto L53
long r0 = java.lang.Math.min(r0, r2) // Catch: java.lang.Throwable -> L3d java.lang.Exception -> L40 java.lang.OutOfMemoryError -> L90
double r0 = (double) r0 // Catch: java.lang.Throwable -> L3d java.lang.Exception -> L40 java.lang.OutOfMemoryError -> L90
r2 = 4611686018427387904(0x4000000000000000, double:2.0)
double r0 = java.lang.Math.pow(r2, r0) // Catch: java.lang.Throwable -> L3d java.lang.Exception -> L40 java.lang.OutOfMemoryError -> L90
int r0 = (int) r0
goto L54
L53:
r0 = r6
L54:
if (r0 > r12) goto L59
int r0 = r0 << 1
goto L54
L59:
android.graphics.BitmapFactory$Options r12 = new android.graphics.BitmapFactory$Options // Catch: java.lang.Throwable -> L3d java.lang.Exception -> L40 java.lang.OutOfMemoryError -> L8f
r12.<init>() // Catch: java.lang.Throwable -> L3d java.lang.Exception -> L40 java.lang.OutOfMemoryError -> L8f
r12.inPurgeable = r6 // Catch: java.lang.Throwable -> L3d java.lang.Exception -> L40 java.lang.OutOfMemoryError -> L8f
if (r0 <= r6) goto L64
r12.inSampleSize = r0 // Catch: java.lang.Throwable -> L3d java.lang.Exception -> L40 java.lang.OutOfMemoryError -> L8f
L64:
android.content.ContentResolver r1 = r8.getContentResolver() // Catch: java.lang.Throwable -> L3d java.lang.Exception -> L40 java.lang.OutOfMemoryError -> L8f
java.io.InputStream r1 = r1.openInputStream(r9) // Catch: java.lang.Throwable -> L3d java.lang.Exception -> L40 java.lang.OutOfMemoryError -> L8f
android.graphics.Bitmap r7 = android.graphics.BitmapFactory.decodeStream(r1, r7, r12) // Catch: java.lang.Exception -> L73 java.lang.OutOfMemoryError -> L75 java.lang.Throwable -> L8d
if (r1 == 0) goto L8c
goto L82
L73:
r8 = move-exception
goto L79
L75:
r6 = r0
r7 = r1
goto L90
L78:
r1 = r7
L79:
java.lang.String r9 = com.kofax.kmc.ken.engines.service.ImageService.TAG // Catch: java.lang.Throwable -> L8d
java.lang.String r10 = "Error decoding image"
com.kofax.mobile.sdk._internal.k.e(r9, r10, r8) // Catch: java.lang.Throwable -> L8d
if (r1 == 0) goto L8c
L82:
r1.close() // Catch: java.lang.Exception -> L86
goto L8c
L86:
r8 = move-exception
java.lang.String r9 = com.kofax.kmc.ken.engines.service.ImageService.TAG
com.kofax.mobile.sdk._internal.k.e(r9, r5, r8)
L8c:
return r7
L8d:
r8 = move-exception
goto Lb8
L8f:
r6 = r0
L90:
java.lang.String r12 = com.kofax.kmc.ken.engines.service.ImageService.TAG // Catch: java.lang.Throwable -> L3d
java.lang.StringBuilder r0 = new java.lang.StringBuilder // Catch: java.lang.Throwable -> L3d
r0.<init>() // Catch: java.lang.Throwable -> L3d
java.lang.String r1 = "Encountered OOM while trying to load scaled bitmap. Increasing minimum scale to "
r0.append(r1) // Catch: java.lang.Throwable -> L3d
r0.append(r6) // Catch: java.lang.Throwable -> L3d
java.lang.String r0 = r0.toString() // Catch: java.lang.Throwable -> L3d
com.kofax.mobile.sdk._internal.k.e(r12, r0) // Catch: java.lang.Throwable -> L3d
android.graphics.Bitmap r8 = loadScaledBitmap(r8, r9, r10, r11, r6) // Catch: java.lang.Throwable -> L3d
if (r7 == 0) goto Lb6
r7.close() // Catch: java.lang.Exception -> Lb0
goto Lb6
Lb0:
r9 = move-exception
java.lang.String r10 = com.kofax.kmc.ken.engines.service.ImageService.TAG
com.kofax.mobile.sdk._internal.k.e(r10, r5, r9)
Lb6:
return r8
Lb7:
r1 = r7
Lb8:
if (r1 == 0) goto Lc4
r1.close() // Catch: java.lang.Exception -> Lbe
goto Lc4
Lbe:
r9 = move-exception
java.lang.String r10 = com.kofax.kmc.ken.engines.service.ImageService.TAG
com.kofax.mobile.sdk._internal.k.e(r10, r5, r9)
Lc4:
throw r8
*/
throw new UnsupportedOperationException("Method not decompiled: com.kofax.kmc.ken.engines.service.ImageService.loadScaledBitmap(android.content.Context, android.net.Uri, int, int, int):android.graphics.Bitmap");
}
private static int a(Context context, Uri uri, int i, int i2) throws FileNotFoundException {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
InputStream openInputStream = context.getContentResolver().openInputStream(uri);
Bitmap decodeStream = BitmapFactory.decodeStream(openInputStream, null, options);
int i3 = options.outHeight;
float f = i / options.outWidth;
float f2 = i2 / i3;
try {
openInputStream.close();
} catch (Exception e) {
k.e(TAG, "Error closing input stream", (Throwable) e);
}
if (decodeStream != null) {
decodeStream.recycle();
}
return (int) Math.pow(2.0d, Math.min(f, f2));
} catch (java.io.FileNotFoundException e2) {
throw new FileNotFoundException(e2);
}
}
private static long af() {
long j = Runtime.getRuntime().totalMemory();
long maxMemory = Runtime.getRuntime().maxMemory();
long j2 = maxMemory / 2;
long min = Math.min(j, j2);
int i = AnonymousClass1.iA[ix.ordinal()];
if (i == 1) {
maxMemory = j2;
} else if (i != 2) {
maxMemory = min;
}
dumpHeapStats("getLargestUseableImage()");
return maxMemory;
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: com.kofax.kmc.ken.engines.service.ImageService$1, reason: invalid class name */
/* loaded from: classes3.dex */
public static /* synthetic */ class AnonymousClass1 {
static final int[] iA;
static final int[] iz;
static {
int[] iArr = new int[UseableImageMemoryLimit.values().length];
iA = iArr;
try {
iArr[UseableImageMemoryLimit.LARGE.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
iA[UseableImageMemoryLimit.MAXIMUM.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
iA[UseableImageMemoryLimit.NORMAL.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
int[] iArr2 = new int[Image.ImageMimeType.values().length];
iz = iArr2;
try {
iArr2[Image.ImageMimeType.MIMETYPE_JPEG.ordinal()] = 1;
} catch (NoSuchFieldError unused4) {
}
try {
iz[Image.ImageMimeType.MIMETYPE_TIFF.ordinal()] = 2;
} catch (NoSuchFieldError unused5) {
}
try {
iz[Image.ImageMimeType.MIMETYPE_PNG.ordinal()] = 3;
} catch (NoSuchFieldError unused6) {
}
}
}
public static void dumpHeapStats(String str) {
String str2 = TAG;
k.b(str2, "*** [START] Dumping heap stats ***");
k.b(str2, "--- msg -> ".concat(String.valueOf(str)));
StringBuilder sb = new StringBuilder("--- native heap size -> ");
sb.append(Debug.getNativeHeapSize());
k.b(str2, sb.toString());
StringBuilder sb2 = new StringBuilder("--- native heap size (free) -> ");
sb2.append(Debug.getNativeHeapFreeSize());
k.b(str2, sb2.toString());
StringBuilder sb3 = new StringBuilder("--- native heap size (allocated) -> ");
sb3.append(Debug.getNativeHeapAllocatedSize());
k.b(str2, sb3.toString());
StringBuilder sb4 = new StringBuilder("--- totalMemory -> ");
sb4.append(Runtime.getRuntime().totalMemory());
k.b(str2, sb4.toString());
StringBuilder sb5 = new StringBuilder("--- maxMemory -> ");
sb5.append(Runtime.getRuntime().maxMemory());
k.b(str2, sb5.toString());
k.b(str2, "*** [END] Dumping heap stats ***");
}
private static boolean g(String str) {
return gjJ.e((CharSequence) str, (CharSequence) ".png");
}
private static boolean h(String str) {
return gjJ.e((CharSequence) str, (CharSequence) ".tif") || gjJ.e((CharSequence) str, (CharSequence) ".tiff");
}
private static boolean i(String str) {
return gjJ.e((CharSequence) str, (CharSequence) ".jpg") || gjJ.e((CharSequence) str, (CharSequence) ".jpeg");
}
public static ImageDimension getImageDimension(String str) throws IOException {
FileInputStream fileInputStream;
if (!g(str) && !h(str) && !i(str)) {
throw new IOException("File format not supported");
}
if (h(str)) {
long length = new File(str).length();
try {
try {
fileInputStream = new FileInputStream(str);
} catch (Throwable th) {
th = th;
fileInputStream = null;
}
} catch (java.io.FileNotFoundException e) {
e = e;
}
try {
ImageDimension a2 = a(fileInputStream, length);
try {
fileInputStream.close();
} catch (java.io.IOException e2) {
k.d(TAG, "Unable to close file", (Throwable) e2);
}
return a2;
} catch (java.io.FileNotFoundException e3) {
e = e3;
throw new FileNotFoundException(e);
} catch (Throwable th2) {
th = th2;
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (java.io.IOException e4) {
k.d(TAG, "Unable to close file", (Throwable) e4);
}
}
throw th;
}
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(str, options);
return new ImageDimension(options.outWidth, options.outHeight);
}
private static ImageDimension a(InputStream inputStream, long j) throws IOException {
ReadableByteChannel newChannel = Channels.newChannel(inputStream);
ByteBuffer allocate = ByteBuffer.allocate(12);
a(newChannel, allocate, 8);
byte b = allocate.get();
if (b != allocate.get() || (b != 73 && b != 77)) {
throw new IOException("Not a tiff file.");
}
allocate.order(b == 73 ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
if (allocate.getShort() != 42) {
throw new IOException("Not a tiff file.");
}
try {
if (allocate.getInt() >= j) {
throw new IOException("Invalid tiff file.");
}
inputStream.skip(r4 - 8);
a(newChannel, allocate, 2);
int i = -1;
int i2 = -1;
int i3 = -1;
for (int i4 = allocate.getShort(); i4 > 0 && (i < 0 || i2 < 0 || i3 < 0); i4--) {
a(newChannel, allocate, 12);
short s = allocate.getShort();
if (s == 256) {
i = a(allocate);
} else if (s == 257) {
i2 = a(allocate);
} else if (s == 259 && (i3 = a(allocate)) == 5) {
throw new IOException("Unsupported tiff compression type - LZW");
}
}
return new ImageDimension(i, i2);
} catch (java.io.IOException e) {
throw new IOException(e);
}
}
private static void a(ReadableByteChannel readableByteChannel, ByteBuffer byteBuffer, int i) throws IOException {
byteBuffer.position(0);
byteBuffer.limit(i);
while (byteBuffer.hasRemaining()) {
try {
readableByteChannel.read(byteBuffer);
} catch (java.io.IOException e) {
throw new IOException(e);
}
}
byteBuffer.flip();
}
private static int a(ByteBuffer byteBuffer) {
short s = byteBuffer.getShort();
if (byteBuffer.getInt() != 1) {
throw new RuntimeException("Expected a count of 1 for the given field.");
}
if (s == 3) {
return byteBuffer.getShort();
}
if (s == 4) {
return byteBuffer.getInt();
}
return byteBuffer.get() & UnsignedBytes.MAX_VALUE;
}
public static Bitmap createScaledBitmap(Bitmap bitmap, boolean z) {
long af = af();
long rowBytes = bitmap.getRowBytes() * bitmap.getHeight();
String str = TAG;
k.b(str, "Creating scaled bitmap...");
k.b(str, "... original bitmap size -> ".concat(String.valueOf(rowBytes)));
if (rowBytes > af) {
dumpHeapStats("createScaledBitmap - preScale");
int width = bitmap.getWidth();
int height = bitmap.getHeight();
float f = ((float) af) / ((float) rowBytes);
int i = (int) (width * f);
int i2 = (int) (height * f);
k.b(str, "... scaling bitmap with factor of ".concat(String.valueOf(f)));
try {
Bitmap createScaledBitmap = Bitmap.createScaledBitmap(bitmap, i, i2, true);
StringBuilder sb = new StringBuilder("... new bitmap size -> ");
sb.append(createScaledBitmap.getRowBytes() * createScaledBitmap.getHeight());
k.b(str, sb.toString());
if (z) {
k.b(str, "... recyling old bitmap");
bitmap.recycle();
bitmap = null;
}
dumpHeapStats("createScaledBitmap - postScale");
return createScaledBitmap;
} catch (OutOfMemoryError e) {
String str2 = TAG;
k.e(str2, "Got OOM while trying to create scaled bitmap", (Throwable) e);
k.e(str2, "... largestImageSize -> ".concat(String.valueOf(af)));
k.e(str2, "... bmSize -> ".concat(String.valueOf(rowBytes)));
StringBuilder sb2 = new StringBuilder("... orgHeight -> ");
sb2.append(height);
sb2.append(", orgWidth -> ");
sb2.append(width);
k.e(str2, sb2.toString());
StringBuilder sb3 = new StringBuilder("... height -> ");
sb3.append(i2);
sb3.append(", width -> ");
sb3.append(i);
k.e(str2, sb3.toString());
}
}
return bitmap;
}
public static Bitmap rotateImage(byte[] bArr, boolean z, boolean z2) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPurgeable = true;
dumpHeapStats("rotateImage - preDecode");
Bitmap decodeByteArray = BitmapFactory.decodeByteArray(bArr, 0, bArr.length, options);
dumpHeapStats("rotateImage - postDecode");
return rotateBitmap(decodeByteArray, z, z2);
}
public static Bitmap rotateBitmap(Bitmap bitmap, boolean z, boolean z2) {
return rotateBitmap(bitmap, z, z2, true);
}
/* JADX WARN: Removed duplicated region for block: B:18:0x00ef */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public static android.graphics.Bitmap rotateBitmap(android.graphics.Bitmap r13, boolean r14, boolean r15, boolean r16) {
/*
java.lang.String r1 = "Error rotating bitmap"
java.lang.String r0 = com.kofax.kmc.ken.engines.service.ImageService.TAG
java.lang.String r2 = "About to scale bitmap. Source information before scaling: "
com.kofax.mobile.sdk._internal.k.b(r0, r2)
java.lang.StringBuilder r2 = new java.lang.StringBuilder
java.lang.String r3 = "... size -> "
r2.<init>(r3)
int r4 = r13.getRowBytes()
int r5 = r13.getHeight()
int r4 = r4 * r5
r2.append(r4)
java.lang.String r2 = r2.toString()
com.kofax.mobile.sdk._internal.k.b(r0, r2)
java.lang.StringBuilder r2 = new java.lang.StringBuilder
java.lang.String r4 = "... height -> "
r2.<init>(r4)
int r5 = r13.getHeight()
r2.append(r5)
java.lang.String r2 = r2.toString()
com.kofax.mobile.sdk._internal.k.b(r0, r2)
java.lang.StringBuilder r2 = new java.lang.StringBuilder
java.lang.String r5 = "... width -> "
r2.<init>(r5)
int r6 = r13.getWidth()
r2.append(r6)
java.lang.String r2 = r2.toString()
com.kofax.mobile.sdk._internal.k.b(r0, r2)
if (r15 == 0) goto L56
r2 = 1
r6 = r13
android.graphics.Bitmap r2 = createScaledBitmap(r13, r2)
goto L58
L56:
r6 = r13
r2 = r6
L58:
android.graphics.Matrix r11 = new android.graphics.Matrix
r11.<init>()
if (r14 == 0) goto L62
r6 = 1119092736(0x42b40000, float:90.0)
goto L64
L62:
r6 = -1028390912(0xffffffffc2b40000, float:-90.0)
L64:
r11.postRotate(r6)
java.lang.String r6 = "rotateImage - preRotate"
dumpHeapStats(r6)
java.lang.String r6 = "About to rotate bitmap. Source information: "
com.kofax.mobile.sdk._internal.k.b(r0, r6)
java.lang.StringBuilder r6 = new java.lang.StringBuilder
r6.<init>(r3)
int r3 = r2.getRowBytes()
int r7 = r2.getHeight()
int r3 = r3 * r7
r6.append(r3)
java.lang.String r3 = r6.toString()
com.kofax.mobile.sdk._internal.k.b(r0, r3)
java.lang.StringBuilder r3 = new java.lang.StringBuilder
r3.<init>(r4)
int r4 = r2.getHeight()
r3.append(r4)
java.lang.String r3 = r3.toString()
com.kofax.mobile.sdk._internal.k.b(r0, r3)
java.lang.StringBuilder r3 = new java.lang.StringBuilder
r3.<init>(r5)
int r4 = r2.getWidth()
r3.append(r4)
java.lang.String r3 = r3.toString()
com.kofax.mobile.sdk._internal.k.b(r0, r3)
r7 = 0
r8 = 0
r3 = 0
int r9 = r2.getWidth() // Catch: java.lang.Exception -> Le0 java.lang.OutOfMemoryError -> Le7
int r10 = r2.getHeight() // Catch: java.lang.Exception -> Le0 java.lang.OutOfMemoryError -> Le7
r12 = 0
r6 = r2
android.graphics.Bitmap r3 = android.graphics.Bitmap.createBitmap(r6, r7, r8, r9, r10, r11, r12) // Catch: java.lang.Exception -> Le0 java.lang.OutOfMemoryError -> Le7
java.lang.StringBuilder r4 = new java.lang.StringBuilder // Catch: java.lang.Exception -> Le0 java.lang.OutOfMemoryError -> Le7
java.lang.String r5 = "... rotated bitmap size -> "
r4.<init>(r5) // Catch: java.lang.Exception -> Le0 java.lang.OutOfMemoryError -> Le7
int r5 = r3.getRowBytes() // Catch: java.lang.Exception -> Le0 java.lang.OutOfMemoryError -> Le7
int r6 = r3.getHeight() // Catch: java.lang.Exception -> Le0 java.lang.OutOfMemoryError -> Le7
int r5 = r5 * r6
r4.append(r5) // Catch: java.lang.Exception -> Le0 java.lang.OutOfMemoryError -> Le7
java.lang.String r4 = r4.toString() // Catch: java.lang.Exception -> Le0 java.lang.OutOfMemoryError -> Le7
com.kofax.mobile.sdk._internal.k.b(r0, r4) // Catch: java.lang.Exception -> Le0 java.lang.OutOfMemoryError -> Le7
if (r16 == 0) goto Ldf
r2.recycle() // Catch: java.lang.Exception -> Le0 java.lang.OutOfMemoryError -> Le7
Ldf:
return r3
Le0:
r0 = move-exception
java.lang.String r4 = com.kofax.kmc.ken.engines.service.ImageService.TAG
com.kofax.mobile.sdk._internal.k.e(r4, r1, r0)
goto Led
Le7:
r0 = move-exception
java.lang.String r4 = com.kofax.kmc.ken.engines.service.ImageService.TAG
com.kofax.mobile.sdk._internal.k.e(r4, r1, r0)
Led:
if (r3 == 0) goto Lf2
r3.recycle()
Lf2:
return r2
*/
throw new UnsupportedOperationException("Method not decompiled: com.kofax.kmc.ken.engines.service.ImageService.rotateBitmap(android.graphics.Bitmap, boolean, boolean, boolean):android.graphics.Bitmap");
}
private static void f(Bitmap bitmap) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put(RttiJsonExactionHelper.HEIGHT, bitmap.getHeight());
jSONObject.put(RttiJsonExactionHelper.WIDTH, bitmap.getWidth());
jSONObject.put("density", bitmap.getDensity());
jSONObject.put("rowBytes", bitmap.getRowBytes());
jSONObject.put("totalBytes", bitmap.getRowBytes() * bitmap.getHeight());
} catch (Exception e) {
k.e(TAG, "Error creating JSON for Bitmap", (Throwable) e);
}
String str = TAG;
StringBuilder sb = new StringBuilder("Bitmap -> ");
sb.append(jSONObject.toString());
k.b(str, sb.toString());
}
private static void a(int i, ProcessPageResults processPageResults) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("resultCode", i);
jSONObject.put("resultStr", processPageResults.resultStr);
jSONObject.put("processedImage", a(processPageResults.processedImg));
} catch (Exception e) {
k.e(TAG, "Error creating JSON for ProcessPageResults", (Throwable) e);
}
String str = TAG;
StringBuilder sb = new StringBuilder("ProcessPageResults -> ");
sb.append(jSONObject.toString());
k.b(str, sb.toString());
}
private static JSONObject a(IpImage ipImage) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put(RttiJsonExactionHelper.WIDTH, ipImage.getWidth());
jSONObject.put(RttiJsonExactionHelper.HEIGHT, ipImage.getHeight());
jSONObject.put("channels", ipImage.getChannels());
jSONObject.put("bitDepth", ipImage.getBitDepth());
jSONObject.put("dpiX", ipImage.getDpiX());
jSONObject.put("dpiY", ipImage.getDpiY());
} catch (Exception e) {
k.e("IpImage", "Error creating JSON", (Throwable) e);
}
return jSONObject;
}
public static Image.KenBitmap readBitmapFromFileUsingIp(String str, float f, IpImageMetadata ipImageMetadata) {
Image.KenBitmap kenBitmap = new Image.KenBitmap();
try {
IpLib ipLib = IpLib.getInstance();
IpImage ipImage = new IpImage();
Integer valueOf = Integer.valueOf(ipLib.readImageFile(ipImage, str, f, ipImageMetadata));
if (valueOf.intValue() != 0) {
kenBitmap.errInfo = IpLibUtil.ipErrHashMap.get(valueOf);
} else {
kenBitmap.bitmap = ipLib.createBitmap(ipImage);
kenBitmap.mDpiX = Integer.valueOf(ipImage.mDpiX);
kenBitmap.mDpiY = Integer.valueOf(ipImage.mDpiY);
ipLib.releaseImage(ipImage);
}
} catch (KmcException e) {
kenBitmap.errInfo = e.getErrorInfo();
}
return kenBitmap;
}
public static Image.KenBitmap loadBitmapFromFileBuffer(IpFileBuffer ipFileBuffer) {
Image.KenBitmap kenBitmap = new Image.KenBitmap();
ByteBuffer byteBuffer = ipFileBuffer.mByteBuffer;
if (byteBuffer.capacity() <= 0) {
throw new InternalError("loadBitmapFromFileBuffer: fileBuffer has no capacity");
}
int capacity = byteBuffer.capacity();
byte[] bArr = new byte[capacity];
byteBuffer.get(bArr);
kenBitmap.bitmap = BitmapFactory.decodeByteArray(bArr, 0, capacity);
if (kenBitmap.bitmap == null) {
kenBitmap.errInfo = ErrorInfo.KMC_ED_BUFFERED_READ_FAILED;
}
return kenBitmap;
}
public static Image.KenBitmap readBitmapFromFileBufferUsingIp(IpFileBuffer ipFileBuffer, float f) {
Image.KenBitmap kenBitmap = new Image.KenBitmap();
try {
IpLib ipLib = IpLib.getInstance();
IpImage ipImage = new IpImage();
Integer valueOf = Integer.valueOf(ipLib.readImageFromFileBuffer(ipImage, f, ipFileBuffer));
if (valueOf.intValue() != 0) {
kenBitmap.errInfo = IpLibUtil.ipErrHashMap.get(valueOf);
} else {
try {
kenBitmap.bitmap = ipLib.createBitmap(ipImage);
} catch (OutOfMemoryError e) {
k.e(TAG, "OOM while creating bitmap.", (Throwable) e);
ErrorInfo errorInfo = ErrorInfo.KMC_GN_OUT_OF_MEMORY;
errorInfo.setErrCause("Out of memory error reading bitmap from file buffer");
kenBitmap.errInfo = errorInfo;
}
if (kenBitmap.errInfo == ErrorInfo.KMC_SUCCESS) {
kenBitmap.mDpiX = Integer.valueOf(ipImage.mDpiX);
kenBitmap.mDpiY = Integer.valueOf(ipImage.mDpiY);
ipLib.releaseImage(ipImage);
}
}
} catch (KmcException e2) {
kenBitmap.errInfo = e2.getErrorInfo();
}
return kenBitmap;
}
public static ErrorInfo clearFileBufferUsingIp(IpFileBuffer ipFileBuffer) throws KmcException {
ErrorInfo errorInfo = ErrorInfo.KMC_SUCCESS;
if (IpLib.getInstance().releaseFileBuffer(ipFileBuffer) == 0) {
return errorInfo;
}
throw new InternalError("clearFileBufferUsingIp: releaseFileBuffer failed");
}
private static IpImage a(Bitmap bitmap, Integer num) throws KmcException {
return createIpImageFromBitmap(bitmap, num, false);
}
public static IpImage createIpImageFromBitmap(Bitmap bitmap, Integer num, boolean z) throws KmcException {
int i;
int i2;
int i3 = z ? 1 : 3;
int i4 = z ? 1 : 24;
int i5 = z ? 200 : 72;
int i6 = z ? 200 : 72;
if (num == null || num.intValue() <= 0) {
i = i6;
i2 = i5;
} else {
i2 = num.intValue();
i = i2;
}
return a(bitmap, i3, i4, i2, i, false);
}
private static IpImage a(Bitmap bitmap, int i, int i2, int i3, int i4, boolean z) throws KmcException {
IpLib ipLib = IpLib.getInstance();
IpImage ipImage = new IpImage();
int createImage = ipLib.createImage(ipImage, bitmap, i, i2, i3, i4);
if (z) {
bitmap.recycle();
}
if (createImage == -9900) {
ipImage.mErrorInfo = ErrorInfo.KMC_ED_IMAGE_WRITTEN_IS_NOT_BITONAL;
} else if (createImage == -9901) {
ipImage.mErrorInfo = ErrorInfo.KMC_ED_IMAGE_WRITTEN_IS_NOT_GRAY;
} else if (createImage < 0) {
k.e(TAG, "Bad return code when creating an image from a bitmap. rc = ".concat(String.valueOf(createImage)));
throw new KmcException(IpLibUtil.ipErrHashMap.get(Integer.valueOf(createImage)));
}
return ipImage;
}
/* loaded from: classes3.dex */
public static class EnhancementResults {
public ErrorInfo errorInfo;
public Image image;
public Image originalImage;
public EnhancementResults(ErrorInfo errorInfo) {
this.errorInfo = errorInfo;
}
public EnhancementResults(Image image, Image image2) {
this.errorInfo = ErrorInfo.KMC_SUCCESS;
this.image = image;
this.originalImage = image2;
}
}
private static EnhancementResults a(Bitmap bitmap, ImagePerfectionProfile imagePerfectionProfile, ImageProcessorConfiguration imageProcessorConfiguration, BoundingTetragon boundingTetragon, Image image, int i, ProcessPageOutRep processPageOutRep, IpLib.ProcessingProgressClient processingProgressClient, Image image2, Integer num) throws KmcException {
boolean z;
f(bitmap);
Integer imageDPI = image.getImageDPI();
if (num == null || num.intValue() <= 0) {
z = false;
} else {
z = true;
imageDPI = num;
}
IpLib ipLib = IpLib.getInstance();
IpImage a2 = a(bitmap, imageDPI);
ProcessPageResults processPageResults = new ProcessPageResults();
String str = TAG;
StringBuilder sb = new StringBuilder("inImg width ------> ");
sb.append(a2.getWidth());
k.b(str, sb.toString());
StringBuilder sb2 = new StringBuilder("inImg height ------> ");
sb2.append(a2.getHeight());
k.b(str, sb2.toString());
a a3 = a(imagePerfectionProfile, imageProcessorConfiguration, boundingTetragon, image, z);
String str2 = a3.iC;
processPageResults.resultStr = a3.iD;
dumpHeapStats("enhanceImage(before processPage)");
int processPage = ipLib.processPage(processPageResults, a2, str2, processPageOutRep, i, processingProgressClient, processPageOutRep);
a(processPage, processPageResults);
ipLib.releaseImage(a2);
dumpHeapStats("enhanceImage(after processPage)");
return a(processPage, ipLib, processPageResults, imagePerfectionProfile, str2, image, processPageOutRep, image2);
}
public static EnhancementResults enhanceImage(Bitmap bitmap, ImagePerfectionProfile imagePerfectionProfile, ImageProcessorConfiguration imageProcessorConfiguration, BoundingTetragon boundingTetragon, Image image, int i, ProcessPageOutRep processPageOutRep, IpLib.ProcessingProgressClient processingProgressClient, Image image2, Integer num) throws KmcException {
return a(bitmap, imagePerfectionProfile, imageProcessorConfiguration, boundingTetragon, image, i, processPageOutRep, processingProgressClient, image2, num);
}
/* JADX WARN: Removed duplicated region for block: B:14:0x00c5 */
/* JADX WARN: Removed duplicated region for block: B:17:0x00d8 */
/* JADX WARN: Removed duplicated region for block: B:20:0x00f1 */
/* JADX WARN: Removed duplicated region for block: B:24:0x00f4 */
/* JADX WARN: Removed duplicated region for block: B:33:0x00a2 */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
private static com.kofax.kmc.ken.engines.service.ImageService.EnhancementResults a(int r7, com.kofax.kmc.ken.engines.iplib.IpLib r8, com.kofax.kmc.ken.engines.iplib.ProcessPageResults r9, com.kofax.kmc.ken.engines.data.ImagePerfectionProfile r10, java.lang.String r11, com.kofax.kmc.ken.engines.data.Image r12, com.kofax.kmc.ken.engines.iplib.ProcessPageOutRep r13, com.kofax.kmc.ken.engines.data.Image r14) throws com.kofax.kmc.kut.utilities.error.KmcException {
/*
Method dump skipped, instructions count: 302
To view this dump add '--comments-level debug' option
*/
throw new UnsupportedOperationException("Method not decompiled: com.kofax.kmc.ken.engines.service.ImageService.a(int, com.kofax.kmc.ken.engines.iplib.IpLib, com.kofax.kmc.ken.engines.iplib.ProcessPageResults, com.kofax.kmc.ken.engines.data.ImagePerfectionProfile, java.lang.String, com.kofax.kmc.ken.engines.data.Image, com.kofax.kmc.ken.engines.iplib.ProcessPageOutRep, com.kofax.kmc.ken.engines.data.Image):com.kofax.kmc.ken.engines.service.ImageService$EnhancementResults");
}
public static File copyToTempImage(Context context, File file, String str) throws IOException {
StringBuilder sb = new StringBuilder();
sb.append(FileService.getLocalPath(context));
sb.append(File.separator);
sb.append(str);
File file2 = new File(sb.toString());
try {
if (FileService.copyFile(file, file2)) {
return file2;
}
return null;
} catch (java.io.IOException e) {
throw new IOException(e);
}
}
public static File createTempImageFile(Context context, String str) {
File file = new File(FileService.getLocalPath(context));
file.mkdir();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("mmddyy-hhMMss", Locale.US);
StringBuilder sb = new StringBuilder();
sb.append(simpleDateFormat.format(new Date()));
sb.append(".");
sb.append(str);
return new File(file, sb.toString());
}
public static String dumpBitmapSize(Bitmap bitmap, String str) {
if (bitmap == null || bitmap.isRecycled()) {
return "Unable to calculate size";
}
StringBuilder sb = new StringBuilder();
StringBuilder sb2 = new StringBuilder("Dumping bitmap data from ");
sb2.append(str);
sb2.append(": ");
sb.append(sb2.toString());
StringBuilder sb3 = new StringBuilder("Height -> ");
sb3.append(bitmap.getHeight());
sb.append(sb3.toString());
StringBuilder sb4 = new StringBuilder(", Width -> ");
sb4.append(bitmap.getWidth());
sb.append(sb4.toString());
StringBuilder sb5 = new StringBuilder(", Density -> ");
sb5.append(bitmap.getDensity());
sb.append(sb5.toString());
StringBuilder sb6 = new StringBuilder(", Size -> ");
sb6.append(bitmap.getRowBytes() * bitmap.getHeight());
sb.append(sb6.toString());
return sb.toString();
}
public static String[] getRawTempFilenames(Activity activity, boolean z) {
String[] strArr = new String[2];
if (z) {
strArr[0] = "temp_raw";
strArr[1] = "temp_raw_thmb";
} else {
StringBuilder sb = new StringBuilder();
sb.append(FileService.getLocalPath(activity));
sb.append(File.separator);
sb.append("temp_raw");
strArr[0] = new File(sb.toString()).getAbsolutePath();
StringBuilder sb2 = new StringBuilder();
sb2.append(FileService.getLocalPath(activity));
sb2.append(File.separator);
sb2.append("temp_raw_thmb");
strArr[1] = new File(sb2.toString()).getAbsolutePath();
}
return strArr;
}
public static String[] getProcessedTempFilenames(Activity activity, boolean z) {
String[] strArr = new String[2];
if (z) {
strArr[0] = "temp_proc";
strArr[1] = "temp_proc_thmb";
} else {
StringBuilder sb = new StringBuilder();
sb.append(FileService.getLocalPath(activity));
sb.append(File.separator);
sb.append("temp_proc");
strArr[0] = new File(sb.toString()).getAbsolutePath();
StringBuilder sb2 = new StringBuilder();
sb2.append(FileService.getLocalPath(activity));
sb2.append(File.separator);
sb2.append("temp_proc_thmb");
strArr[1] = new File(sb2.toString()).getAbsolutePath();
}
return strArr;
}
public static Image.KenBitmap loadBitmapFromFile(String str, int i, boolean z) {
return loadBitmapFromURI(Uri.fromFile(new File(str)), i, -1L, z);
}
public static Image.KenBitmap loadBitmapFromURI(Uri uri, int i, long j, boolean z) {
Image.KenBitmap kenBitmap;
InputStream inputStream;
while (true) {
String str = TAG;
StringBuilder sb = new StringBuilder("Loading bitmap from uri '");
sb.append(uri);
sb.append("' at scale ");
sb.append(i);
sb.append(" with a largest image size of ");
sb.append(j);
k.b(str, sb.toString());
kenBitmap = new Image.KenBitmap();
try {
Context context = AppContextProvider.getContext();
Bitmap bitmap = null;
if (context != null) {
inputStream = context.getContentResolver().openInputStream(uri);
} else {
kenBitmap.errInfo = ErrorInfo.KMC_GN_BAD_APPLICATION_CONTEXT;
inputStream = null;
}
try {
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPurgeable = true;
if (i > 1) {
options.inSampleSize = i;
}
Bitmap decodeStream = BitmapFactory.decodeStream(inputStream, null, options);
if (decodeStream == null) {
kenBitmap.errInfo = ErrorInfo.KMC_ED_BITMAP_READ_FROM_FILE_FAILED;
} else {
kenBitmap.bitmap = decodeStream;
kenBitmap.scaleFactor = i;
kenBitmap.errInfo = i > 1 ? ErrorInfo.KMC_ED_IMAGE_IS_SCALED : ErrorInfo.KMC_SUCCESS;
StringBuilder sb2 = new StringBuilder("bm width=");
sb2.append(decodeStream.getWidth());
k.b(str, sb2.toString());
StringBuilder sb3 = new StringBuilder("bm height=");
sb3.append(decodeStream.getHeight());
k.b(str, sb3.toString());
}
try {
inputStream.close();
} catch (Exception e) {
k.e(TAG, "Error closing input stream", (Throwable) e);
}
if (j <= 0 || decodeStream.getRowBytes() * decodeStream.getHeight() <= j) {
break;
}
if (decodeStream != null) {
decodeStream.recycle();
}
i <<= 1;
} catch (OutOfMemoryError unused) {
String str2 = TAG;
StringBuilder sb4 = new StringBuilder("OOM while loading a bitmap at scale ");
sb4.append(i);
k.e(str2, sb4.toString());
if (0 != 0) {
bitmap.recycle();
}
kenBitmap.errInfo = ErrorInfo.KMC_GN_OUT_OF_MEMORY;
if (z) {
kenBitmap = loadBitmapFromURI(uri, i << 1, j, z);
}
try {
inputStream.close();
} catch (Exception e2) {
k.e(TAG, "Error closing input stream", (Throwable) e2);
}
return kenBitmap;
}
} catch (Throwable th) {
try {
inputStream.close();
} catch (Exception e3) {
k.e(TAG, "Error closing input stream", (Throwable) e3);
}
throw th;
}
} catch (java.io.FileNotFoundException e4) {
k.e(TAG, "Error loading file", (Throwable) e4);
kenBitmap.errInfo = ErrorInfo.KMC_GN_FILE_NOT_FOUND;
kenBitmap.errInfo.setErrCause(e4.getMessage());
return kenBitmap;
}
}
return kenBitmap;
}
public static File saveIpPNG(Context context, IpLib ipLib, IpImage ipImage, File file) {
if (file == null) {
file = createTempImageFile(context, "png");
}
String str = TAG;
StringBuilder sb = new StringBuilder("Using image processor to save a png to ");
sb.append(file.getAbsolutePath());
k.b(str, sb.toString());
k.b(str, "Result code -> ".concat(String.valueOf(ipLib.writePngImage(ipImage, file.getAbsolutePath()))));
return file;
}
public static File saveIpJPG(Context context, IpLib ipLib, IpImage ipImage) {
File createTempImageFile = createTempImageFile(context, "jpg");
String str = TAG;
StringBuilder sb = new StringBuilder("Using image processor to save a jpg to ");
sb.append(createTempImageFile.getAbsolutePath());
k.b(str, sb.toString());
k.b(str, "Result code -> ".concat(String.valueOf(ipLib.writeJpegImage(ipImage, 90, createTempImageFile.getAbsolutePath()))));
return createTempImageFile;
}
public static File saveToGallery(Bitmap bitmap) {
File file = new File(Environment.getExternalStorageDirectory(), "KofaxMobileCapture");
file.mkdir();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("mmddyy-hhMMss", Locale.US);
StringBuilder sb = new StringBuilder();
sb.append(simpleDateFormat.format(new Date()));
sb.append(".png");
File file2 = new File(file, sb.toString());
try {
FileOutputStream fileOutputStream = new FileOutputStream(file2);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
return file2;
} catch (Exception e) {
k.e(TAG, "Error saving image to gallery", (Throwable) e);
return null;
}
}
/* JADX WARN: Removed duplicated region for block: B:29:0x0090 A[Catch: IOException -> 0x008c, TRY_LEAVE, TryCatch #5 {IOException -> 0x008c, blocks: (B:37:0x0088, B:29:0x0090), top: B:36:0x0088 }] */
/* JADX WARN: Removed duplicated region for block: B:36:0x0088 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public static void copyImageToExternalStorage(java.io.File r10) throws com.kofax.kmc.kut.utilities.error.IOException {
/*
java.io.File r0 = new java.io.File
java.lang.StringBuilder r1 = new java.lang.StringBuilder
r1.<init>()
java.io.File r2 = android.os.Environment.getExternalStorageDirectory()
r1.append(r2)
java.lang.String r2 = java.io.File.separator
r1.append(r2)
java.lang.String r2 = r10.getName()
r1.append(r2)
java.lang.String r1 = r1.toString()
r0.<init>(r1)
r1 = 0
r0.createNewFile() // Catch: java.lang.Throwable -> L78 java.io.IOException -> L7c
java.io.FileInputStream r2 = new java.io.FileInputStream // Catch: java.lang.Throwable -> L78 java.io.IOException -> L7c
r2.<init>(r10) // Catch: java.lang.Throwable -> L78 java.io.IOException -> L7c
java.nio.channels.FileChannel r10 = r2.getChannel() // Catch: java.lang.Throwable -> L78 java.io.IOException -> L7c
java.io.FileOutputStream r2 = new java.io.FileOutputStream // Catch: java.lang.Throwable -> L6e java.io.IOException -> L73
r2.<init>(r0) // Catch: java.lang.Throwable -> L6e java.io.IOException -> L73
java.nio.channels.FileChannel r1 = r2.getChannel() // Catch: java.lang.Throwable -> L6e java.io.IOException -> L73
r4 = 0
long r6 = r10.size() // Catch: java.lang.Throwable -> L6e java.io.IOException -> L73
r3 = r10
r8 = r1
r3.transferTo(r4, r6, r8) // Catch: java.lang.Throwable -> L6e java.io.IOException -> L73
java.lang.String r2 = com.kofax.kmc.ken.engines.service.ImageService.TAG // Catch: java.lang.Throwable -> L6e java.io.IOException -> L73
java.lang.StringBuilder r3 = new java.lang.StringBuilder // Catch: java.lang.Throwable -> L6e java.io.IOException -> L73
java.lang.String r4 = "copyImageToExternalStorage(), successfully moved image to external storage Path: "
r3.<init>(r4) // Catch: java.lang.Throwable -> L6e java.io.IOException -> L73
java.lang.String r0 = r0.getAbsolutePath() // Catch: java.lang.Throwable -> L6e java.io.IOException -> L73
r3.append(r0) // Catch: java.lang.Throwable -> L6e java.io.IOException -> L73
java.lang.String r0 = r3.toString() // Catch: java.lang.Throwable -> L6e java.io.IOException -> L73
com.kofax.mobile.sdk._internal.k.c(r2, r0) // Catch: java.lang.Throwable -> L6e java.io.IOException -> L73
if (r10 == 0) goto L61
r10.close() // Catch: java.io.IOException -> L5f
goto L61
L5f:
r10 = move-exception
goto L67
L61:
if (r1 == 0) goto L6d
r1.close() // Catch: java.io.IOException -> L5f
return
L67:
com.kofax.kmc.kut.utilities.error.IOException r0 = new com.kofax.kmc.kut.utilities.error.IOException
r0.<init>(r10)
throw r0
L6d:
return
L6e:
r0 = move-exception
r9 = r1
r1 = r10
r10 = r9
goto L86
L73:
r0 = move-exception
r9 = r1
r1 = r10
r10 = r9
goto L7f
L78:
r10 = move-exception
r0 = r10
r10 = r1
goto L86
L7c:
r10 = move-exception
r0 = r10
r10 = r1
L7f:
com.kofax.kmc.kut.utilities.error.IOException r2 = new com.kofax.kmc.kut.utilities.error.IOException // Catch: java.lang.Throwable -> L85
r2.<init>(r0) // Catch: java.lang.Throwable -> L85
throw r2 // Catch: java.lang.Throwable -> L85
L85:
r0 = move-exception
L86:
if (r1 == 0) goto L8e
r1.close() // Catch: java.io.IOException -> L8c
goto L8e
L8c:
r10 = move-exception
goto L94
L8e:
if (r10 == 0) goto L9a
r10.close() // Catch: java.io.IOException -> L8c
goto L9a
L94:
com.kofax.kmc.kut.utilities.error.IOException r0 = new com.kofax.kmc.kut.utilities.error.IOException
r0.<init>(r10)
throw r0
L9a:
throw r0
*/
throw new UnsupportedOperationException("Method not decompiled: com.kofax.kmc.ken.engines.service.ImageService.copyImageToExternalStorage(java.io.File):void");
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public static class a {
private String iC;
private String iD;
private a() {
}
/* synthetic */ a(AnonymousClass1 anonymousClass1) {
this();
}
}
private static a a(ImagePerfectionProfile imagePerfectionProfile, ImageProcessorConfiguration imageProcessorConfiguration, BoundingTetragon boundingTetragon, Image image, boolean z) throws KmcException {
String str;
a aVar = new a(null);
if (imagePerfectionProfile != null || imageProcessorConfiguration != null) {
if (imageProcessorConfiguration != null) {
StringBuilder sb = new StringBuilder("");
sb.append(c.a(imageProcessorConfiguration, false, z).ippString);
str = sb.toString();
if (boundingTetragon != null) {
StringBuilder sb2 = new StringBuilder();
sb2.append(str);
sb2.append(k(boundingTetragon));
str = sb2.toString();
}
} else if (imagePerfectionProfile != null) {
str = new ImagePerfectionProfile.FriendIPP(imagePerfectionProfile, BuildConfig.APPLICATION_ID).toFinalOpString();
if (boundingTetragon != null) {
StringBuilder sb3 = new StringBuilder();
sb3.append(str);
sb3.append(k(boundingTetragon));
str = sb3.toString();
}
} else {
str = "";
}
if (passBarcodes) {
StringBuilder sb4 = new StringBuilder();
sb4.append(str);
sb4.append(u(image));
str = sb4.toString();
}
aVar.iC = str;
aVar.iD = "";
return aVar;
}
throw new KmcRuntimeException(ErrorInfo.KMC_IP_NO_PROFILE);
}
private static String k(BoundingTetragon boundingTetragon) {
StringBuilder sb = new StringBuilder("_ExternalCornersFront_");
sb.append(boundingTetragon.getTopLeft().x);
sb.append(",");
sb.append(boundingTetragon.getTopLeft().y);
sb.append(",");
sb.append(boundingTetragon.getTopRight().x);
sb.append(",");
sb.append(boundingTetragon.getTopRight().y);
sb.append(",");
sb.append(boundingTetragon.getBottomLeft().x);
sb.append(",");
sb.append(boundingTetragon.getBottomLeft().y);
sb.append(",");
sb.append(boundingTetragon.getBottomRight().x);
sb.append(",");
sb.append(boundingTetragon.getBottomRight().y);
return sb.toString();
}
private static String u(Image image) {
StringBuilder sb = new StringBuilder("");
List<BarCodeResult> imageBarCodes = image.getImageBarCodes();
if (imageBarCodes != null) {
for (int i = 0; i < imageBarCodes.size(); i++) {
BarCodeResult barCodeResult = imageBarCodes.get(i);
sb.append("_ExternalBarcodeFront_");
BoundingTetragon boundingBox = barCodeResult.getBoundingBox();
sb.append(boundingBox.getTopLeft().x);
sb.append(",");
sb.append(boundingBox.getTopLeft().y);
sb.append(",");
sb.append(boundingBox.getTopRight().x);
sb.append(",");
sb.append(boundingBox.getTopRight().y);
sb.append(",");
sb.append(boundingBox.getBottomLeft().x);
sb.append(",");
sb.append(boundingBox.getBottomLeft().y);
sb.append(",");
sb.append(boundingBox.getBottomRight().x);
sb.append(",");
sb.append(boundingBox.getBottomRight().y);
sb.append(",");
sb.append(barCodeResult.getType());
sb.append(",");
sb.append(barCodeResult.getDirection());
sb.append(",");
sb.append(BarCodeDataFormat.ASCII);
sb.append(",");
sb.append(i);
}
}
return sb.toString();
}
public static void checkDateTimeFormat(String str) {
try {
iu.b.a(str);
} catch (ParseException unused) {
throw new KmcRuntimeException(ErrorInfo.KMC_ED_INVALID_ISO_DATE_TIME_FORMAT);
}
}
public static String getTimeStringFromExif(Image image, String str) {
String str2;
String imageMetaData = image.getImageMetaData();
if (isImageProcessingMetadata(imageMetaData)) {
return null;
}
int length = str.length();
String[] split = imageMetaData.split("\n");
int length2 = split.length;
int i = 0;
while (true) {
if (i >= length2) {
str2 = null;
break;
}
String str3 = split[i];
if (str3.contains(str)) {
k.c(TAG, "Found timeTag: ".concat(String.valueOf(str3)));
str2 = str3.substring(length);
break;
}
i++;
}
if (gjJ.b((CharSequence) str2)) {
return null;
}
return str2;
}
private static String j(String str) {
if (str.contains(iv)) {
return "UTC";
}
return null;
}
public static boolean isImageProcessingMetadata(String str) {
return str.startsWith(UrlTreeKt.componentParamPrefix);
}
public static Date exifTimeToDate(String str, String str2) {
if (gjJ.a(str)) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(EXIF_TIME_FORMAT, Locale.US);
if (gjJ.a(str2)) {
simpleDateFormat.setTimeZone(TimeZone.getTimeZone(str2));
}
try {
return simpleDateFormat.parse(str);
} catch (ParseException e) {
k.e(TAG, e.getMessage());
}
}
return null;
}
public static String exifTimeFromDate(Date date, String str) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(EXIF_TIME_FORMAT, Locale.US);
if (gjJ.a(str)) {
simpleDateFormat.setTimeZone(TimeZone.getTimeZone(str));
}
return simpleDateFormat.format(date);
}
public static Date UTCStringToDate(String str) {
if (!gjJ.a(str)) {
return null;
}
try {
return iu.b.a(str);
} catch (ParseException e) {
throw new InternalError(e.getMessage());
}
}
public static String UTCStringFromDate(Date date) {
gjU gju = iu.c;
Calendar calendar = Calendar.getInstance(gju.d, gju.a);
calendar.setTime(date);
return ((StringBuilder) gju.d(calendar, (Calendar) new StringBuilder(gju.c))).toString();
}
public static ErrorInfo verifyRestrictions(Image image, Image.FileRestriction fileRestriction) {
ErrorInfo errorInfo = ErrorInfo.KMC_SUCCESS;
if (Image.FileRestriction.ANSI_X9 != fileRestriction) {
return errorInfo;
}
if (image.getImageMimeType() != Image.ImageMimeType.MIMETYPE_TIFF) {
return ErrorInfo.KMC_ED_FILE_RESTRICTION_MIMETYPE;
}
if (image.getImageOutputColor() != Image.OutputColor.BITDEPTH_BITONAL) {
return ErrorInfo.KMC_ED_FILE_RESTRICTION_BITDEPTH;
}
return (image.getImageDPI().intValue() == 200 || image.getImageDPI().intValue() == 240) ? errorInfo : ErrorInfo.KMC_ED_FILE_RESTRICTION_DPI;
}
public static String createMetadataFromImage(Image image, Image.FileRestriction fileRestriction) throws KmcException {
StringBuilder sb = new StringBuilder();
if (Image.FileRestriction.ANSI_X9 == fileRestriction) {
sb.append(KExifTagDateTimeDigitized);
sb.append(exifTimeFromDate(UTCStringToDate(image.getImageCreateDateTime()), "UTC"));
sb.append(System.getProperty("line.separator"));
return sb.toString();
}
if (image.getImageLatitude() != null && image.getImageLongitude() != null) {
sb.append(createGPSMetadata(image));
}
if (image.getTargetFrame() != null) {
sb.append(createTargetFrameMetadata(image));
}
sb.append(KExifTagDateTimeOriginal);
Image.FriendI friendI = new Image.FriendI(image, BuildConfig.APPLICATION_ID);
sb.append(friendI.getImageOriginalDateTime());
sb.append(System.getProperty("line.separator"));
sb.append(KExifTagDateTime);
sb.append(friendI.getImageOriginalDateTime());
sb.append(System.getProperty("line.separator"));
sb.append(KExifTagDateTimeDigitized);
sb.append(exifTimeFromDate(UTCStringToDate(image.getImageCreateDateTime()), "UTC"));
sb.append(System.getProperty("line.separator"));
sb.append(iv);
sb.append(System.getProperty("line.separator"));
return sb.toString();
}
public static String getCornersJsonFromMetaData(String str) {
if (TextUtils.isEmpty(str)) {
return null;
}
Matcher matcher = Pattern.compile("\\\"Corners\\\"[\\s]*:[\\s]*\\{[^\\{\\}]*\\}", 2).matcher(str);
if (!matcher.find()) {
return null;
}
Matcher matcher2 = Pattern.compile("\\{[^\\{\\}]*\\}").matcher(matcher.group());
if (matcher2.find()) {
return matcher2.group();
}
return null;
}
public static BoundingTetragon getCornersTetragonFromJson(String str) {
if (TextUtils.isEmpty(str)) {
return null;
}
try {
JSONObject jSONObject = new JSONObject(str);
return new BoundingTetragon((int) jSONObject.getDouble("TLx"), (int) jSONObject.getDouble("TLy"), (int) jSONObject.getDouble("TRx"), (int) jSONObject.getDouble("TRy"), (int) jSONObject.getDouble("BLx"), (int) jSONObject.getDouble("BLy"), (int) jSONObject.getDouble("BRx"), (int) jSONObject.getDouble("BRy"));
} catch (JSONException e) {
k.e(e);
return null;
}
}
public static void setUseableImageMemoryLimits(UseableImageMemoryLimit useableImageMemoryLimit) {
ix = useableImageMemoryLimit;
}
public static void setInterimImageFileFormat(InterimImageFileFormat interimImageFileFormat) {
iy = interimImageFileFormat;
}
public static UseableImageMemoryLimit getUseableImageMemoryLimits() {
return ix;
}
public static InterimImageFileFormat getInterimImageFileFormat() {
return iy;
}
}