package o; import android.app.ActivityManager; import android.content.Context; import android.content.CursorLoader; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Matrix; import android.media.ExifInterface; import android.net.Uri; import com.drew.imaging.ImageProcessingException; import java.io.File; import java.io.IOException; /* loaded from: classes5.dex */ public final class fJW { public static Bitmap ayM_(Context context, Uri uri, Bitmap bitmap) { ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo(); ((ActivityManager) context.getSystemService("activity")).getMemoryInfo(memoryInfo); if (memoryInfo.availMem < bitmap.getByteCount() * 80) { int byteCount = (int) ((bitmap.getByteCount() * 80) / memoryInfo.availMem); bitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() / byteCount, bitmap.getHeight() / byteCount, true); } Cursor loadInBackground = new CursorLoader(context, uri, new String[]{"_data"}, null, null, null).loadInBackground(); int columnIndexOrThrow = loadInBackground.getColumnIndexOrThrow("_data"); loadInBackground.moveToFirst(); String string = loadInBackground.getString(columnIndexOrThrow); loadInBackground.close(); try { int d = d(string); if (d == 1) { return bitmap; } Matrix matrix = new Matrix(); if (d == 0) { matrix.setRotate(b(string)); } else { switch (d) { case 2: matrix.setScale(-1.0f, 1.0f); break; case 3: matrix.setRotate(180.0f); break; case 4: matrix.setRotate(180.0f); matrix.postScale(-1.0f, 1.0f); break; case 5: matrix.setRotate(90.0f); matrix.postScale(-1.0f, 1.0f); break; case 6: matrix.setRotate(90.0f); break; case 7: matrix.setRotate(-90.0f); matrix.postScale(-1.0f, 1.0f); break; case 8: matrix.setRotate(-90.0f); break; default: return bitmap; } } try { return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } catch (OutOfMemoryError e) { guQ.a(e); return bitmap; } } catch (IOException e2) { guQ.a(e2); return bitmap; } } private static int d(String str) throws IOException { try { return new ExifInterface(str).getAttributeInt("Orientation", 0); } catch (Exception e) { guQ.a(e); return 0; } } private static int b(String str) { int i = 0; try { String o2 = ((C10874eRg) WMj.e(new File(str)).c(C10874eRg.class)).o(274); String[] split = o2.substring(o2.indexOf("(") + 1, o2.indexOf(")")).split(" "); if (split.length != 3) { return 0; } i = Integer.parseInt(split[1]); return split[2].equals("CCW") ? -i : i; } catch (ImageProcessingException | IOException | NullPointerException | StringIndexOutOfBoundsException | VerifyError e) { guQ.e(e); guQ.a(e); return i; } } }