package androidx.media3.datasource;

import V1.g;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import androidx.media3.common.ParserException;
import androidx.media3.common.util.UnstableApi;
import com.revenuecat.purchases.ui.revenuecatui.components.SensibleDefaults;
import java.io.ByteArrayInputStream;
import java.io.IOException;

/* JADX INFO: loaded from: classes.dex */
@UnstableApi
public final class BitmapUtil {
    private BitmapUtil() {
    }

    public static Bitmap decode(byte[] bArr, int i6, BitmapFactory.Options options) throws IOException {
        int iE;
        int i7 = 0;
        Bitmap bitmapDecodeByteArray = BitmapFactory.decodeByteArray(bArr, 0, i6, options);
        if (bitmapDecodeByteArray == null) {
            throw ParserException.createForMalformedContainer("Could not decode image data", new IllegalStateException());
        }
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bArr);
        try {
            g gVar = new g(byteArrayInputStream);
            byteArrayInputStream.close();
            V1.c cVarC = gVar.c("Orientation");
            if (cVarC == null) {
                iE = 1;
            } else {
                try {
                    iE = cVarC.e(gVar.f7242f);
                } catch (NumberFormatException unused) {
                    iE = 1;
                }
            }
            switch (iE) {
                case 3:
                case 4:
                    i7 = SensibleDefaults.X_OFFSET;
                    break;
                case 5:
                case 8:
                    i7 = 270;
                    break;
                case 6:
                case 7:
                    i7 = 90;
                    break;
            }
            if (i7 == 0) {
                return bitmapDecodeByteArray;
            }
            Matrix matrix = new Matrix();
            matrix.postRotate(i7);
            return Bitmap.createBitmap(bitmapDecodeByteArray, 0, 0, bitmapDecodeByteArray.getWidth(), bitmapDecodeByteArray.getHeight(), matrix, false);
        } finally {
        }
    }
}
