198 lines
8.4 KiB
Java
198 lines
8.4 KiB
Java
package b0.a.a.e;
|
|
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import android.graphics.Matrix;
|
|
import android.media.ExifInterface;
|
|
import b0.a.a.d;
|
|
import d0.g0.w;
|
|
import d0.o;
|
|
import d0.y.h;
|
|
import d0.z.d.m;
|
|
import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
import kotlin.Pair;
|
|
import kotlin.TypeCastException;
|
|
/* compiled from: DefaultConstraint.kt */
|
|
public final class c implements b {
|
|
public boolean a;
|
|
public final int b;
|
|
|
|
/* renamed from: c reason: collision with root package name */
|
|
public final int f31c;
|
|
public final Bitmap.CompressFormat d;
|
|
public final int e;
|
|
|
|
public c(int i, int i2, Bitmap.CompressFormat compressFormat, int i3) {
|
|
m.checkParameterIsNotNull(compressFormat, "format");
|
|
this.b = i;
|
|
this.f31c = i2;
|
|
this.d = compressFormat;
|
|
this.e = i3;
|
|
}
|
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:34:0x0111 */
|
|
/* JADX WARNING: Removed duplicated region for block: B:35:0x0113 */
|
|
/* JADX WARNING: Removed duplicated region for block: B:43:0x0164 */
|
|
/* JADX WARNING: Removed duplicated region for block: B:54:0x0182 */
|
|
@Override // b0.a.a.e.b
|
|
public File a(File file) {
|
|
int i;
|
|
Bitmap.CompressFormat compressFormat;
|
|
File file2;
|
|
File parentFile;
|
|
Throwable th;
|
|
FileOutputStream fileOutputStream;
|
|
m.checkParameterIsNotNull(file, "imageFile");
|
|
int i2 = this.b;
|
|
int i3 = this.f31c;
|
|
String str = d.a;
|
|
m.checkParameterIsNotNull(file, "imageFile");
|
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
options.inJustDecodeBounds = true;
|
|
BitmapFactory.decodeFile(file.getAbsolutePath(), options);
|
|
m.checkParameterIsNotNull(options, "options");
|
|
Pair pair = o.to(Integer.valueOf(options.outHeight), Integer.valueOf(options.outWidth));
|
|
int intValue = ((Number) pair.component1()).intValue();
|
|
int intValue2 = ((Number) pair.component2()).intValue();
|
|
if (intValue > i3 || intValue2 > i2) {
|
|
int i4 = intValue / 2;
|
|
int i5 = intValue2 / 2;
|
|
i = 1;
|
|
while (i4 / i >= i3 && i5 / i >= i2) {
|
|
i *= 2;
|
|
}
|
|
} else {
|
|
i = 1;
|
|
}
|
|
options.inSampleSize = i;
|
|
options.inJustDecodeBounds = false;
|
|
Bitmap decodeFile = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
|
|
m.checkExpressionValueIsNotNull(decodeFile, "BitmapFactory.decodeFile…eFile.absolutePath, this)");
|
|
m.checkExpressionValueIsNotNull(decodeFile, "BitmapFactory.Options().…absolutePath, this)\n }");
|
|
m.checkParameterIsNotNull(file, "imageFile");
|
|
m.checkParameterIsNotNull(decodeFile, "bitmap");
|
|
int attributeInt = new ExifInterface(file.getAbsolutePath()).getAttributeInt("Orientation", 0);
|
|
Matrix matrix = new Matrix();
|
|
if (attributeInt == 3) {
|
|
matrix.postRotate(180.0f);
|
|
} else if (attributeInt == 6) {
|
|
matrix.postRotate(90.0f);
|
|
} else if (attributeInt == 8) {
|
|
matrix.postRotate(270.0f);
|
|
}
|
|
Bitmap createBitmap = Bitmap.createBitmap(decodeFile, 0, 0, decodeFile.getWidth(), decodeFile.getHeight(), matrix, true);
|
|
m.checkExpressionValueIsNotNull(createBitmap, "Bitmap.createBitmap(bitm…map.height, matrix, true)");
|
|
Bitmap.CompressFormat compressFormat2 = this.d;
|
|
int i6 = this.e;
|
|
m.checkParameterIsNotNull(file, "imageFile");
|
|
m.checkParameterIsNotNull(createBitmap, "bitmap");
|
|
m.checkParameterIsNotNull(compressFormat2, "format");
|
|
m.checkParameterIsNotNull(file, "$this$compressFormat");
|
|
String extension = h.getExtension(file);
|
|
if (extension != null) {
|
|
String lowerCase = extension.toLowerCase();
|
|
m.checkExpressionValueIsNotNull(lowerCase, "(this as java.lang.String).toLowerCase()");
|
|
int hashCode = lowerCase.hashCode();
|
|
String str2 = "webp";
|
|
if (hashCode != 111145) {
|
|
if (hashCode == 3645340 && lowerCase.equals(str2)) {
|
|
compressFormat = Bitmap.CompressFormat.WEBP;
|
|
FileOutputStream fileOutputStream2 = null;
|
|
if (compressFormat2 == compressFormat) {
|
|
file2 = file;
|
|
} else {
|
|
StringBuilder sb = new StringBuilder();
|
|
String absolutePath = file.getAbsolutePath();
|
|
m.checkExpressionValueIsNotNull(absolutePath, "imageFile.absolutePath");
|
|
sb.append(w.substringBeforeLast$default(absolutePath, ".", (String) null, 2, (Object) null));
|
|
sb.append('.');
|
|
m.checkParameterIsNotNull(compressFormat2, "$this$extension");
|
|
int i7 = b0.a.a.c.a[compressFormat2.ordinal()];
|
|
if (i7 == 1) {
|
|
str2 = "png";
|
|
} else if (i7 != 2) {
|
|
str2 = "jpg";
|
|
}
|
|
sb.append(str2);
|
|
file2 = new File(sb.toString());
|
|
}
|
|
file.delete();
|
|
m.checkParameterIsNotNull(createBitmap, "bitmap");
|
|
m.checkParameterIsNotNull(file2, "destination");
|
|
m.checkParameterIsNotNull(compressFormat2, "format");
|
|
parentFile = file2.getParentFile();
|
|
if (parentFile != null) {
|
|
parentFile.mkdirs();
|
|
}
|
|
fileOutputStream = new FileOutputStream(file2.getAbsolutePath());
|
|
createBitmap.compress(compressFormat2, i6, fileOutputStream);
|
|
fileOutputStream.flush();
|
|
fileOutputStream.close();
|
|
this.a = true;
|
|
return file2;
|
|
}
|
|
} else if (lowerCase.equals("png")) {
|
|
compressFormat = Bitmap.CompressFormat.PNG;
|
|
FileOutputStream fileOutputStream2 = null;
|
|
if (compressFormat2 == compressFormat) {
|
|
}
|
|
file.delete();
|
|
m.checkParameterIsNotNull(createBitmap, "bitmap");
|
|
m.checkParameterIsNotNull(file2, "destination");
|
|
m.checkParameterIsNotNull(compressFormat2, "format");
|
|
parentFile = file2.getParentFile();
|
|
if (parentFile != null) {
|
|
}
|
|
fileOutputStream = new FileOutputStream(file2.getAbsolutePath());
|
|
createBitmap.compress(compressFormat2, i6, fileOutputStream);
|
|
fileOutputStream.flush();
|
|
fileOutputStream.close();
|
|
this.a = true;
|
|
return file2;
|
|
}
|
|
compressFormat = Bitmap.CompressFormat.JPEG;
|
|
FileOutputStream fileOutputStream2 = null;
|
|
if (compressFormat2 == compressFormat) {
|
|
}
|
|
file.delete();
|
|
m.checkParameterIsNotNull(createBitmap, "bitmap");
|
|
m.checkParameterIsNotNull(file2, "destination");
|
|
m.checkParameterIsNotNull(compressFormat2, "format");
|
|
parentFile = file2.getParentFile();
|
|
if (parentFile != null) {
|
|
}
|
|
try {
|
|
fileOutputStream = new FileOutputStream(file2.getAbsolutePath());
|
|
try {
|
|
createBitmap.compress(compressFormat2, i6, fileOutputStream);
|
|
fileOutputStream.flush();
|
|
fileOutputStream.close();
|
|
this.a = true;
|
|
return file2;
|
|
} catch (Throwable th2) {
|
|
th = th2;
|
|
fileOutputStream2 = fileOutputStream;
|
|
if (fileOutputStream2 != null) {
|
|
fileOutputStream2.flush();
|
|
fileOutputStream2.close();
|
|
}
|
|
throw th;
|
|
}
|
|
} catch (Throwable th3) {
|
|
th = th3;
|
|
if (fileOutputStream2 != null) {
|
|
}
|
|
throw th;
|
|
}
|
|
} else {
|
|
throw new TypeCastException("null cannot be cast to non-null type java.lang.String");
|
|
}
|
|
}
|
|
|
|
@Override // b0.a.a.e.b
|
|
public boolean b(File file) {
|
|
m.checkParameterIsNotNull(file, "imageFile");
|
|
return this.a;
|
|
}
|
|
}
|