264 lines
12 KiB
Java
264 lines
12 KiB
Java
|
package com.kofax.mobile.sdk.ae;
|
||
|
|
||
|
import android.text.TextUtils;
|
||
|
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
||
|
import com.kofax.kmc.ken.engines.processing.ColorDepth;
|
||
|
import com.kofax.kmc.ken.engines.processing.CropType;
|
||
|
import com.kofax.kmc.ken.engines.processing.DeskewType;
|
||
|
import com.kofax.kmc.ken.engines.processing.DocumentDimensions;
|
||
|
import com.kofax.kmc.ken.engines.processing.ImageProcessorConfiguration;
|
||
|
import com.kofax.kmc.ken.engines.processing.RotateType;
|
||
|
import com.kofax.kmc.kut.utilities.error.ErrorInfo;
|
||
|
import com.kofax.kmc.kut.utilities.error.KmcException;
|
||
|
import java.util.Locale;
|
||
|
import java.util.regex.Matcher;
|
||
|
import java.util.regex.Pattern;
|
||
|
|
||
|
/* loaded from: classes3.dex */
|
||
|
public class c {
|
||
|
private static final String DO_90_DEGREE_ROTATION = "_Do90DegreeRotation_";
|
||
|
private static final String DO_BINARIZATION = "_DoBinarization_";
|
||
|
private static final String DO_CROP_CORRECTION = "_DoCropCorrection_";
|
||
|
private static final String DO_ENHANCED_BINARIZATION = "_DoEnhancedBinarization_";
|
||
|
private static final String DO_GRAY_OUTPUT = "_DoGrayOutput_";
|
||
|
private static final String DO_SCALE_IMAGE_TO_DPI = "_DoScaleImageToDPI_";
|
||
|
private static final String DO_SKEW_CORRECTION_ALT = "_DoSkewCorrectionAlt_";
|
||
|
private static final String DO_SKEW_CORRECTION_PAGE = "_DoSkewCorrectionPage_";
|
||
|
private static final String TU = "_DeviceType_0";
|
||
|
private static final String TV = "_DoNoPageDetection_";
|
||
|
private static final String TW = "[CROP_AUTO]";
|
||
|
private static final String cm = "_DoScaleBWImageToDPI_";
|
||
|
private static final String cn = "_DoScaleCGImageToDPI_";
|
||
|
private static final String co = "_DocDimLarge_";
|
||
|
private static final String cp = "_DocDimSmall_";
|
||
|
private static final int cr = 300;
|
||
|
|
||
|
public static a a(ImageProcessorConfiguration imageProcessorConfiguration) {
|
||
|
return a(imageProcessorConfiguration, false, false);
|
||
|
}
|
||
|
|
||
|
public static a a(ImageProcessorConfiguration imageProcessorConfiguration, boolean z, boolean z2) {
|
||
|
StringBuilder sb = new StringBuilder();
|
||
|
StringBuilder sb2 = new StringBuilder();
|
||
|
sb.append(imageProcessorConfiguration.ippString);
|
||
|
int i = AnonymousClass1.TX[imageProcessorConfiguration.rotateType.ordinal()];
|
||
|
if (i == 1 || i == 2 || i == 3 || i == 4) {
|
||
|
sb.append(String.format(Locale.US, "%s%d", "_Do90DegreeRotation_", Integer.valueOf(imageProcessorConfiguration.rotateType.type)));
|
||
|
}
|
||
|
int i2 = AnonymousClass1.TY[imageProcessorConfiguration.deskewType.ordinal()];
|
||
|
if (i2 == 1) {
|
||
|
sb.append("_DoSkewCorrectionPage_");
|
||
|
} else if (i2 == 2) {
|
||
|
sb.append("_DoSkewCorrectionAlt_");
|
||
|
}
|
||
|
if (imageProcessorConfiguration.cropType == CropType.CROP_AUTO) {
|
||
|
if (z) {
|
||
|
sb.append("_DoCropCorrection_");
|
||
|
} else {
|
||
|
sb.append(TV);
|
||
|
sb2.append(TW);
|
||
|
}
|
||
|
}
|
||
|
if (imageProcessorConfiguration.outputDPI != null && imageProcessorConfiguration.outputDPI.intValue() > 0) {
|
||
|
r2 = imageProcessorConfiguration.outputDPI.intValue() >= cr;
|
||
|
sb.append(String.format(Locale.US, "%s%d", cm, imageProcessorConfiguration.outputDPI));
|
||
|
sb.append(String.format(Locale.US, "%s%d", cn, imageProcessorConfiguration.outputDPI));
|
||
|
}
|
||
|
int i3 = AnonymousClass1.TZ[imageProcessorConfiguration.outputColorDepth.ordinal()];
|
||
|
if (i3 != 1) {
|
||
|
if (i3 == 2) {
|
||
|
sb.append("_DoGrayOutput_");
|
||
|
}
|
||
|
} else if (r2) {
|
||
|
sb.append("_DoEnhancedBinarization_");
|
||
|
} else {
|
||
|
sb.append("_DoBinarization_");
|
||
|
}
|
||
|
DocumentDimensions documentDimensions = imageProcessorConfiguration.documentDimensions;
|
||
|
if (documentDimensions != null) {
|
||
|
if (documentDimensions.getShortEdge() != null && documentDimensions.getShortEdge().floatValue() > BitmapDescriptorFactory.HUE_RED) {
|
||
|
sb.append(String.format(Locale.US, "%s%f", cp, documentDimensions.getShortEdge()));
|
||
|
}
|
||
|
if (documentDimensions.getLongEdge() != null && documentDimensions.getLongEdge().floatValue() > BitmapDescriptorFactory.HUE_RED) {
|
||
|
sb.append(String.format(Locale.US, "%s%f", co, documentDimensions.getLongEdge()));
|
||
|
}
|
||
|
}
|
||
|
if (z2) {
|
||
|
sb.append(TU);
|
||
|
}
|
||
|
a aVar = new a();
|
||
|
aVar.ippString = sb.toString();
|
||
|
if (TextUtils.isEmpty(aVar.ippString)) {
|
||
|
aVar.ippString = TV;
|
||
|
}
|
||
|
StringBuilder sb3 = new StringBuilder();
|
||
|
sb3.append(sb2.toString());
|
||
|
sb3.append(aVar.ippString);
|
||
|
aVar.TP = sb3.toString();
|
||
|
return aVar;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* renamed from: com.kofax.mobile.sdk.ae.c$1, reason: invalid class name */
|
||
|
/* loaded from: classes3.dex */
|
||
|
public static /* synthetic */ class AnonymousClass1 {
|
||
|
static final int[] TX;
|
||
|
static final int[] TY;
|
||
|
static final int[] TZ;
|
||
|
|
||
|
static {
|
||
|
int[] iArr = new int[ColorDepth.values().length];
|
||
|
TZ = iArr;
|
||
|
try {
|
||
|
iArr[ColorDepth.BITONAL.ordinal()] = 1;
|
||
|
} catch (NoSuchFieldError unused) {
|
||
|
}
|
||
|
try {
|
||
|
TZ[ColorDepth.GRAYSCALE.ordinal()] = 2;
|
||
|
} catch (NoSuchFieldError unused2) {
|
||
|
}
|
||
|
try {
|
||
|
TZ[ColorDepth.COLOR.ordinal()] = 3;
|
||
|
} catch (NoSuchFieldError unused3) {
|
||
|
}
|
||
|
int[] iArr2 = new int[DeskewType.values().length];
|
||
|
TY = iArr2;
|
||
|
try {
|
||
|
iArr2[DeskewType.DESKEW_BY_DOCUMENT_EDGES.ordinal()] = 1;
|
||
|
} catch (NoSuchFieldError unused4) {
|
||
|
}
|
||
|
try {
|
||
|
TY[DeskewType.DESKEW_BY_DOCUMENT_CONTENT.ordinal()] = 2;
|
||
|
} catch (NoSuchFieldError unused5) {
|
||
|
}
|
||
|
int[] iArr3 = new int[RotateType.values().length];
|
||
|
TX = iArr3;
|
||
|
try {
|
||
|
iArr3[RotateType.ROTATE_90.ordinal()] = 1;
|
||
|
} catch (NoSuchFieldError unused6) {
|
||
|
}
|
||
|
try {
|
||
|
TX[RotateType.ROTATE_180.ordinal()] = 2;
|
||
|
} catch (NoSuchFieldError unused7) {
|
||
|
}
|
||
|
try {
|
||
|
TX[RotateType.ROTATE_270.ordinal()] = 3;
|
||
|
} catch (NoSuchFieldError unused8) {
|
||
|
}
|
||
|
try {
|
||
|
TX[RotateType.ROTATE_AUTO.ordinal()] = 4;
|
||
|
} catch (NoSuchFieldError unused9) {
|
||
|
}
|
||
|
try {
|
||
|
TX[RotateType.ROTATE_NONE.ordinal()] = 5;
|
||
|
} catch (NoSuchFieldError unused10) {
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static String a(ImageProcessorConfiguration imageProcessorConfiguration, String str) throws KmcException {
|
||
|
return TextUtils.isEmpty(str) ? "" : g(imageProcessorConfiguration, f(imageProcessorConfiguration, e(imageProcessorConfiguration, d(imageProcessorConfiguration, c(imageProcessorConfiguration, b(imageProcessorConfiguration, str))))));
|
||
|
}
|
||
|
|
||
|
private static String b(ImageProcessorConfiguration imageProcessorConfiguration, String str) {
|
||
|
if (I("_DoCropCorrection_", str).find()) {
|
||
|
imageProcessorConfiguration.cropType = CropType.CROP_AUTO;
|
||
|
}
|
||
|
return D("_DoCropCorrection_", str);
|
||
|
}
|
||
|
|
||
|
private static String c(ImageProcessorConfiguration imageProcessorConfiguration, String str) {
|
||
|
Matcher I = I("(_DoBinarization_|_DoEnhancedBinarization_|_DoGrayOutput_)", str);
|
||
|
if (I.find()) {
|
||
|
if (I.group().equalsIgnoreCase("_DoGrayOutput_")) {
|
||
|
imageProcessorConfiguration.outputColorDepth = ColorDepth.GRAYSCALE;
|
||
|
} else {
|
||
|
imageProcessorConfiguration.outputColorDepth = ColorDepth.BITONAL;
|
||
|
}
|
||
|
}
|
||
|
return D("(_DoBinarization_|_DoEnhancedBinarization_|_DoGrayOutput_)", str);
|
||
|
}
|
||
|
|
||
|
private static String d(ImageProcessorConfiguration imageProcessorConfiguration, String str) {
|
||
|
Matcher I = I("(_DoSkewCorrectionPage_|_DoSkewCorrectionAlt_)", str);
|
||
|
if (I.find()) {
|
||
|
if (I.group().equalsIgnoreCase("_DoSkewCorrectionPage_")) {
|
||
|
imageProcessorConfiguration.deskewType = DeskewType.DESKEW_BY_DOCUMENT_EDGES;
|
||
|
} else {
|
||
|
imageProcessorConfiguration.deskewType = DeskewType.DESKEW_BY_DOCUMENT_CONTENT;
|
||
|
}
|
||
|
}
|
||
|
return D("(_DoSkewCorrectionPage_|_DoSkewCorrectionAlt_)", str);
|
||
|
}
|
||
|
|
||
|
private static String e(ImageProcessorConfiguration imageProcessorConfiguration, String str) throws KmcException {
|
||
|
try {
|
||
|
Matcher I = I("(_DoScaleBWImageToDPI_|_DoScaleCGImageToDPI_|_DoScaleImageToDPI_)(\\d*)", str);
|
||
|
if (I.find()) {
|
||
|
imageProcessorConfiguration.outputDPI = Integer.valueOf(I.group(2));
|
||
|
}
|
||
|
return D("(_DoScaleBWImageToDPI_|_DoScaleCGImageToDPI_|_DoScaleImageToDPI_)(\\d*)", str);
|
||
|
} catch (NumberFormatException unused) {
|
||
|
throw new KmcException(ErrorInfo.KMC_EV_OP_STRING_ERROR);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static String f(ImageProcessorConfiguration imageProcessorConfiguration, String str) throws KmcException {
|
||
|
Matcher I = I("(_Do90DegreeRotation_)([01234])", str);
|
||
|
try {
|
||
|
if (I.find()) {
|
||
|
int intValue = Integer.valueOf(I.group(2)).intValue();
|
||
|
if (intValue == 0) {
|
||
|
imageProcessorConfiguration.rotateType = RotateType.ROTATE_NONE;
|
||
|
} else if (intValue == 1) {
|
||
|
imageProcessorConfiguration.rotateType = RotateType.ROTATE_270;
|
||
|
} else if (intValue == 2) {
|
||
|
imageProcessorConfiguration.rotateType = RotateType.ROTATE_180;
|
||
|
} else if (intValue == 3) {
|
||
|
imageProcessorConfiguration.rotateType = RotateType.ROTATE_90;
|
||
|
} else if (intValue == 4) {
|
||
|
imageProcessorConfiguration.rotateType = RotateType.ROTATE_AUTO;
|
||
|
}
|
||
|
}
|
||
|
return D("(_Do90DegreeRotation_)([01234])", str);
|
||
|
} catch (NumberFormatException unused) {
|
||
|
throw new KmcException(ErrorInfo.KMC_EV_OP_STRING_ERROR);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static String g(ImageProcessorConfiguration imageProcessorConfiguration, String str) throws KmcException {
|
||
|
Matcher I = I("_DocDimSmall_([\\d\\.]*)", str);
|
||
|
Matcher I2 = I("_DocDimLarge_([\\d\\.]*)", str);
|
||
|
try {
|
||
|
Float valueOf = I.find() ? Float.valueOf(I.group(1)) : null;
|
||
|
String D = D("_DocDimSmall_([\\d\\.]*)", str);
|
||
|
Float valueOf2 = I2.find() ? Float.valueOf(I2.group(1)) : null;
|
||
|
if (valueOf != null || valueOf2 != null) {
|
||
|
imageProcessorConfiguration.documentDimensions = new DocumentDimensions(valueOf, valueOf2);
|
||
|
}
|
||
|
return D("_DocDimLarge_([\\d\\.]*)", D);
|
||
|
} catch (NumberFormatException unused) {
|
||
|
throw new KmcException(ErrorInfo.KMC_EV_OP_STRING_ERROR);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static String D(String str, String str2) {
|
||
|
Matcher matcher = Pattern.compile(str, 2).matcher(str2);
|
||
|
StringBuffer stringBuffer = new StringBuffer(str2.length());
|
||
|
while (matcher.find()) {
|
||
|
matcher.appendReplacement(stringBuffer, (matcher.end() >= str2.length() || str2.charAt(matcher.end()) == '_') ? "" : "_");
|
||
|
}
|
||
|
matcher.appendTail(stringBuffer);
|
||
|
return stringBuffer.toString();
|
||
|
}
|
||
|
|
||
|
private static Matcher I(String str, String str2) {
|
||
|
StringBuilder sb = new StringBuilder();
|
||
|
sb.append(str);
|
||
|
sb.append("(?!.*");
|
||
|
sb.append(str);
|
||
|
sb.append(")");
|
||
|
return Pattern.compile(sb.toString(), 2).matcher(str2);
|
||
|
}
|
||
|
}
|