package h1;

import android.annotation.SuppressLint;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaMetadataRetriever;
import android.os.Build;
import android.system.OsConstants;
import android.util.Log;
import android.util.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import com.google.android.gms.measurement.internal.u1;
import java.io.BufferedInputStream;
import java.io.EOFException;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.CRC32;
import okhttp3.internal.ws.WebSocketProtocol;

/* JADX INFO: loaded from: classes.dex */
public final class g {
    public static final SimpleDateFormat J;
    public static final SimpleDateFormat K;
    public static final String[] L;
    public static final int[] M;
    public static final byte[] N;
    public static final d O;
    public static final d[][] P;
    public static final d[] Q;
    public static final HashMap[] R;
    public static final HashMap[] S;
    public static final HashSet T;
    public static final HashMap U;
    public static final Charset V;
    public static final byte[] W;
    public static final byte[] X;
    public static final Pattern Y;
    public static final Pattern Z;

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    public static final Pattern f26368a0;

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public static final Pattern f26369b0;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final FileDescriptor f26379a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final AssetManager.AssetInputStream f26380b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f26381c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final HashMap[] f26382d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final HashSet f26383e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public ByteOrder f26384f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public boolean f26385g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public boolean f26386h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public boolean f26387i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public int f26388j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public int f26389k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public byte[] f26390l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public int f26391m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public int f26392n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public int f26393o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public int f26394p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public int f26395q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public static final boolean f26370r = Log.isLoggable("ExifInterface", 3);

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public static final List f26371s = Arrays.asList(1, 6, 3, 8);

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public static final List f26372t = Arrays.asList(2, 7, 4, 5);

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public static final int[] f26373u = {8, 8, 8};

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public static final int[] f26374v = {8};

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public static final byte[] f26375w = {-1, -40, -1};

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public static final byte[] f26376x = {102, 116, 121, 112};

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public static final byte[] f26377y = {109, 105, 102, 49};

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public static final byte[] f26378z = {104, 101, 105, 99};
    public static final byte[] A = {79, 76, 89, 77, 80, 0};
    public static final byte[] B = {79, 76, 89, 77, 80, 85, 83, 0, 73, 73};
    public static final byte[] C = {-119, 80, 78, 71, 13, 10, 26, 10};
    public static final byte[] D = {101, 88, 73, 102};
    public static final byte[] E = {73, 72, 68, 82};
    public static final byte[] F = {73, 69, 78, 68};
    public static final byte[] G = {82, 73, 70, 70};
    public static final byte[] H = {87, 69, 66, 80};
    public static final byte[] I = {69, 88, 73, 70};

    static {
        "VP8X".getBytes(Charset.defaultCharset());
        "VP8L".getBytes(Charset.defaultCharset());
        "VP8 ".getBytes(Charset.defaultCharset());
        "ANIM".getBytes(Charset.defaultCharset());
        "ANMF".getBytes(Charset.defaultCharset());
        L = new String[]{"", "BYTE", "STRING", "USHORT", "ULONG", "URATIONAL", "SBYTE", "UNDEFINED", "SSHORT", "SLONG", "SRATIONAL", "SINGLE", "DOUBLE", "IFD"};
        M = new int[]{0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 1};
        N = new byte[]{65, 83, 67, 73, 73, 0, 0, 0};
        d[] dVarArr = {new d("NewSubfileType", 254, 4), new d("SubfileType", 255, 4), new d(256, 3, 4, "ImageWidth"), new d(257, 3, 4, "ImageLength"), new d("BitsPerSample", 258, 3), new d("Compression", 259, 3), new d("PhotometricInterpretation", 262, 3), new d("ImageDescription", 270, 2), new d("Make", 271, 2), new d("Model", 272, 2), new d(273, 3, 4, "StripOffsets"), new d("Orientation", 274, 3), new d("SamplesPerPixel", 277, 3), new d(278, 3, 4, "RowsPerStrip"), new d(279, 3, 4, "StripByteCounts"), new d("XResolution", 282, 5), new d("YResolution", 283, 5), new d("PlanarConfiguration", 284, 3), new d("ResolutionUnit", 296, 3), new d("TransferFunction", 301, 3), new d("Software", 305, 2), new d("DateTime", 306, 2), new d("Artist", 315, 2), new d("WhitePoint", 318, 5), new d("PrimaryChromaticities", 319, 5), new d("SubIFDPointer", 330, 4), new d("JPEGInterchangeFormat", 513, 4), new d("JPEGInterchangeFormatLength", 514, 4), new d("YCbCrCoefficients", 529, 5), new d("YCbCrSubSampling", 530, 3), new d("YCbCrPositioning", 531, 3), new d("ReferenceBlackWhite", 532, 5), new d("Copyright", 33432, 2), new d("ExifIFDPointer", 34665, 4), new d("GPSInfoIFDPointer", 34853, 4), new d("SensorTopBorder", 4, 4), new d("SensorLeftBorder", 5, 4), new d("SensorBottomBorder", 6, 4), new d("SensorRightBorder", 7, 4), new d("ISO", 23, 3), new d("JpgFromRaw", 46, 7), new d("Xmp", 700, 1)};
        d[] dVarArr2 = {new d("ExposureTime", 33434, 5), new d("FNumber", 33437, 5), new d("ExposureProgram", 34850, 3), new d("SpectralSensitivity", 34852, 2), new d("PhotographicSensitivity", 34855, 3), new d("OECF", 34856, 7), new d("SensitivityType", 34864, 3), new d("StandardOutputSensitivity", 34865, 4), new d("RecommendedExposureIndex", 34866, 4), new d("ISOSpeed", 34867, 4), new d("ISOSpeedLatitudeyyy", 34868, 4), new d("ISOSpeedLatitudezzz", 34869, 4), new d("ExifVersion", 36864, 2), new d("DateTimeOriginal", 36867, 2), new d("DateTimeDigitized", 36868, 2), new d("OffsetTime", 36880, 2), new d("OffsetTimeOriginal", 36881, 2), new d("OffsetTimeDigitized", 36882, 2), new d("ComponentsConfiguration", 37121, 7), new d("CompressedBitsPerPixel", 37122, 5), new d("ShutterSpeedValue", 37377, 10), new d("ApertureValue", 37378, 5), new d("BrightnessValue", 37379, 10), new d("ExposureBiasValue", 37380, 10), new d("MaxApertureValue", 37381, 5), new d("SubjectDistance", 37382, 5), new d("MeteringMode", 37383, 3), new d("LightSource", 37384, 3), new d("Flash", 37385, 3), new d("FocalLength", 37386, 5), new d("SubjectArea", 37396, 3), new d("MakerNote", 37500, 7), new d("UserComment", 37510, 7), new d("SubSecTime", 37520, 2), new d("SubSecTimeOriginal", 37521, 2), new d("SubSecTimeDigitized", 37522, 2), new d("FlashpixVersion", 40960, 7), new d("ColorSpace", 40961, 3), new d(40962, 3, 4, "PixelXDimension"), new d(40963, 3, 4, "PixelYDimension"), new d("RelatedSoundFile", 40964, 2), new d("InteroperabilityIFDPointer", 40965, 4), new d("FlashEnergy", 41483, 5), new d("SpatialFrequencyResponse", 41484, 7), new d("FocalPlaneXResolution", 41486, 5), new d("FocalPlaneYResolution", 41487, 5), new d("FocalPlaneResolutionUnit", 41488, 3), new d("SubjectLocation", 41492, 3), new d("ExposureIndex", 41493, 5), new d("SensingMethod", 41495, 3), new d("FileSource", 41728, 7), new d("SceneType", 41729, 7), new d("CFAPattern", 41730, 7), new d("CustomRendered", 41985, 3), new d("ExposureMode", 41986, 3), new d("WhiteBalance", 41987, 3), new d("DigitalZoomRatio", 41988, 5), new d("FocalLengthIn35mmFilm", 41989, 3), new d("SceneCaptureType", 41990, 3), new d("GainControl", 41991, 3), new d("Contrast", 41992, 3), new d("Saturation", 41993, 3), new d("Sharpness", 41994, 3), new d("DeviceSettingDescription", 41995, 7), new d("SubjectDistanceRange", 41996, 3), new d("ImageUniqueID", 42016, 2), new d("CameraOwnerName", 42032, 2), new d("BodySerialNumber", 42033, 2), new d("LensSpecification", 42034, 5), new d("LensMake", 42035, 2), new d("LensModel", 42036, 2), new d("Gamma", 42240, 5), new d("DNGVersion", 50706, 1), new d(50720, 3, 4, "DefaultCropSize")};
        d[] dVarArr3 = {new d("GPSVersionID", 0, 1), new d("GPSLatitudeRef", 1, 2), new d(2, 5, 10, "GPSLatitude"), new d("GPSLongitudeRef", 3, 2), new d(4, 5, 10, "GPSLongitude"), new d("GPSAltitudeRef", 5, 1), new d("GPSAltitude", 6, 5), new d("GPSTimeStamp", 7, 5), new d("GPSSatellites", 8, 2), new d("GPSStatus", 9, 2), new d("GPSMeasureMode", 10, 2), new d("GPSDOP", 11, 5), new d("GPSSpeedRef", 12, 2), new d("GPSSpeed", 13, 5), new d("GPSTrackRef", 14, 2), new d("GPSTrack", 15, 5), new d("GPSImgDirectionRef", 16, 2), new d("GPSImgDirection", 17, 5), new d("GPSMapDatum", 18, 2), new d("GPSDestLatitudeRef", 19, 2), new d("GPSDestLatitude", 20, 5), new d("GPSDestLongitudeRef", 21, 2), new d("GPSDestLongitude", 22, 5), new d("GPSDestBearingRef", 23, 2), new d("GPSDestBearing", 24, 5), new d("GPSDestDistanceRef", 25, 2), new d("GPSDestDistance", 26, 5), new d("GPSProcessingMethod", 27, 7), new d("GPSAreaInformation", 28, 7), new d("GPSDateStamp", 29, 2), new d("GPSDifferential", 30, 3), new d("GPSHPositioningError", 31, 5)};
        d[] dVarArr4 = {new d("InteroperabilityIndex", 1, 2)};
        d[] dVarArr5 = {new d("NewSubfileType", 254, 4), new d("SubfileType", 255, 4), new d(256, 3, 4, "ThumbnailImageWidth"), new d(257, 3, 4, "ThumbnailImageLength"), new d("BitsPerSample", 258, 3), new d("Compression", 259, 3), new d("PhotometricInterpretation", 262, 3), new d("ImageDescription", 270, 2), new d("Make", 271, 2), new d("Model", 272, 2), new d(273, 3, 4, "StripOffsets"), new d("ThumbnailOrientation", 274, 3), new d("SamplesPerPixel", 277, 3), new d(278, 3, 4, "RowsPerStrip"), new d(279, 3, 4, "StripByteCounts"), new d("XResolution", 282, 5), new d("YResolution", 283, 5), new d("PlanarConfiguration", 284, 3), new d("ResolutionUnit", 296, 3), new d("TransferFunction", 301, 3), new d("Software", 305, 2), new d("DateTime", 306, 2), new d("Artist", 315, 2), new d("WhitePoint", 318, 5), new d("PrimaryChromaticities", 319, 5), new d("SubIFDPointer", 330, 4), new d("JPEGInterchangeFormat", 513, 4), new d("JPEGInterchangeFormatLength", 514, 4), new d("YCbCrCoefficients", 529, 5), new d("YCbCrSubSampling", 530, 3), new d("YCbCrPositioning", 531, 3), new d("ReferenceBlackWhite", 532, 5), new d("Copyright", 33432, 2), new d("ExifIFDPointer", 34665, 4), new d("GPSInfoIFDPointer", 34853, 4), new d("DNGVersion", 50706, 1), new d(50720, 3, 4, "DefaultCropSize")};
        O = new d("StripOffsets", 273, 3);
        P = new d[][]{dVarArr, dVarArr2, dVarArr3, dVarArr4, dVarArr5, dVarArr, new d[]{new d("ThumbnailImage", 256, 7), new d("CameraSettingsIFDPointer", 8224, 4), new d("ImageProcessingIFDPointer", 8256, 4)}, new d[]{new d("PreviewImageStart", 257, 4), new d("PreviewImageLength", 258, 4)}, new d[]{new d("AspectFrame", 4371, 3)}, new d[]{new d("ColorSpace", 55, 3)}};
        Q = new d[]{new d("SubIFDPointer", 330, 4), new d("ExifIFDPointer", 34665, 4), new d("GPSInfoIFDPointer", 34853, 4), new d("InteroperabilityIFDPointer", 40965, 4), new d("CameraSettingsIFDPointer", 8224, 1), new d("ImageProcessingIFDPointer", 8256, 1)};
        R = new HashMap[10];
        S = new HashMap[10];
        T = new HashSet(Arrays.asList("FNumber", "DigitalZoomRatio", "ExposureTime", "SubjectDistance", "GPSTimeStamp"));
        U = new HashMap();
        Charset charsetForName = Charset.forName("US-ASCII");
        V = charsetForName;
        W = "Exif\u0000\u0000".getBytes(charsetForName);
        X = "http://ns.adobe.com/xap/1.0/\u0000".getBytes(charsetForName);
        Locale locale = Locale.US;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", locale);
        J = simpleDateFormat;
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", locale);
        K = simpleDateFormat2;
        simpleDateFormat2.setTimeZone(TimeZone.getTimeZone("UTC"));
        int i10 = 0;
        while (true) {
            d[][] dVarArr6 = P;
            if (i10 >= dVarArr6.length) {
                HashMap map = U;
                d[] dVarArr7 = Q;
                map.put(Integer.valueOf(dVarArr7[0].f26362a), 5);
                map.put(Integer.valueOf(dVarArr7[1].f26362a), 1);
                map.put(Integer.valueOf(dVarArr7[2].f26362a), 2);
                map.put(Integer.valueOf(dVarArr7[3].f26362a), 3);
                map.put(Integer.valueOf(dVarArr7[4].f26362a), 7);
                map.put(Integer.valueOf(dVarArr7[5].f26362a), 8);
                Y = Pattern.compile(".*[1-9].*");
                Z = Pattern.compile("^(\\d{2}):(\\d{2}):(\\d{2})$");
                f26368a0 = Pattern.compile("^(\\d{4}):(\\d{2}):(\\d{2})\\s(\\d{2}):(\\d{2}):(\\d{2})$");
                f26369b0 = Pattern.compile("^(\\d{4})-(\\d{2})-(\\d{2})\\s(\\d{2}):(\\d{2}):(\\d{2})$");
                return;
            }
            R[i10] = new HashMap();
            S[i10] = new HashMap();
            for (d dVar : dVarArr6[i10]) {
                R[i10].put(Integer.valueOf(dVar.f26362a), dVar);
                S[i10].put(dVar.f26363b, dVar);
            }
            i10++;
        }
    }

    public g(InputStream inputStream) throws Throwable {
        d[][] dVarArr = P;
        this.f26382d = new HashMap[dVarArr.length];
        this.f26383e = new HashSet(dVarArr.length);
        this.f26384f = ByteOrder.BIG_ENDIAN;
        if (inputStream == null) {
            throw new NullPointerException("inputStream cannot be null");
        }
        if (inputStream instanceof AssetManager.AssetInputStream) {
            this.f26380b = (AssetManager.AssetInputStream) inputStream;
            this.f26379a = null;
        } else if (inputStream instanceof FileInputStream) {
            FileInputStream fileInputStream = (FileInputStream) inputStream;
            try {
                h.c(fileInputStream.getFD(), 0L, OsConstants.SEEK_CUR);
                this.f26380b = null;
                this.f26379a = fileInputStream.getFD();
            } catch (Exception unused) {
                this.f26380b = null;
                this.f26379a = null;
            }
        } else {
            this.f26380b = null;
            this.f26379a = null;
        }
        boolean z10 = f26370r;
        for (int i10 = 0; i10 < dVarArr.length; i10++) {
            try {
                this.f26382d[i10] = new HashMap();
            } catch (IOException | UnsupportedOperationException unused2) {
                a();
                if (!z10) {
                    return;
                }
            } catch (Throwable th) {
                a();
                if (z10) {
                    q();
                }
                throw th;
            }
        }
        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, 5000);
        int iF = f(bufferedInputStream);
        this.f26381c = iF;
        if (iF == 4 || iF == 9 || iF == 13 || iF == 14) {
            b bVar = new b(bufferedInputStream);
            int i11 = this.f26381c;
            if (i11 == 4) {
                e(bVar, 0, 0);
            } else if (i11 == 13) {
                h(bVar);
            } else if (i11 == 9) {
                i(bVar);
            } else if (i11 == 14) {
                l(bVar);
            }
        } else {
            f fVar = new f(bufferedInputStream);
            int i12 = this.f26381c;
            if (i12 == 12) {
                d(fVar);
            } else if (i12 == 7) {
                g(fVar);
            } else if (i12 == 10) {
                k(fVar);
            } else {
                j(fVar);
            }
            fVar.g(this.f26392n);
            v(fVar);
        }
        a();
        if (!z10) {
            return;
        }
        q();
    }

    public static double b(String str, String str2) {
        try {
            String[] strArrSplit = str.split(",", -1);
            String[] strArrSplit2 = strArrSplit[0].split("/", -1);
            double d10 = Double.parseDouble(strArrSplit2[0].trim()) / Double.parseDouble(strArrSplit2[1].trim());
            String[] strArrSplit3 = strArrSplit[1].split("/", -1);
            double d11 = Double.parseDouble(strArrSplit3[0].trim()) / Double.parseDouble(strArrSplit3[1].trim());
            String[] strArrSplit4 = strArrSplit[2].split("/", -1);
            double d12 = ((Double.parseDouble(strArrSplit4[0].trim()) / Double.parseDouble(strArrSplit4[1].trim())) / 3600.0d) + (d11 / 60.0d) + d10;
            if (!str2.equals("S") && !str2.equals("W")) {
                if (!str2.equals("N") && !str2.equals("E")) {
                    throw new IllegalArgumentException();
                }
                return d12;
            }
            return -d12;
        } catch (ArrayIndexOutOfBoundsException | NumberFormatException unused) {
            throw new IllegalArgumentException();
        }
    }

    @Nullable
    private c getExifAttribute(@NonNull String str) {
        if (str == null) {
            throw new NullPointerException("tag shouldn't be null");
        }
        if ("ISOSpeedRatings".equals(str)) {
            str = "PhotographicSensitivity";
        }
        for (int i10 = 0; i10 < P.length; i10++) {
            c cVar = (c) this.f26382d[i10].get(str);
            if (cVar != null) {
                return cVar;
            }
        }
        return null;
    }

    public static Pair m(String str) {
        if (str.contains(",")) {
            String[] strArrSplit = str.split(",", -1);
            Pair pairM = m(strArrSplit[0]);
            if (((Integer) pairM.first).intValue() == 2) {
                return pairM;
            }
            for (int i10 = 1; i10 < strArrSplit.length; i10++) {
                Pair pairM2 = m(strArrSplit[i10]);
                int iIntValue = (((Integer) pairM2.first).equals(pairM.first) || ((Integer) pairM2.second).equals(pairM.first)) ? ((Integer) pairM.first).intValue() : -1;
                int iIntValue2 = (((Integer) pairM.second).intValue() == -1 || !(((Integer) pairM2.first).equals(pairM.second) || ((Integer) pairM2.second).equals(pairM.second))) ? -1 : ((Integer) pairM.second).intValue();
                if (iIntValue == -1 && iIntValue2 == -1) {
                    return new Pair(2, -1);
                }
                if (iIntValue == -1) {
                    pairM = new Pair(Integer.valueOf(iIntValue2), -1);
                } else if (iIntValue2 == -1) {
                    pairM = new Pair(Integer.valueOf(iIntValue), -1);
                }
            }
            return pairM;
        }
        if (!str.contains("/")) {
            try {
                try {
                    Long lValueOf = Long.valueOf(Long.parseLong(str));
                    return (lValueOf.longValue() < 0 || lValueOf.longValue() > WebSocketProtocol.PAYLOAD_SHORT_MAX) ? lValueOf.longValue() < 0 ? new Pair(9, -1) : new Pair(4, -1) : new Pair(3, 4);
                } catch (NumberFormatException unused) {
                    return new Pair(2, -1);
                }
            } catch (NumberFormatException unused2) {
                Double.parseDouble(str);
                return new Pair(12, -1);
            }
        }
        String[] strArrSplit2 = str.split("/", -1);
        if (strArrSplit2.length == 2) {
            try {
                long j10 = (long) Double.parseDouble(strArrSplit2[0]);
                long j11 = (long) Double.parseDouble(strArrSplit2[1]);
                if (j10 >= 0 && j11 >= 0) {
                    if (j10 <= 2147483647L && j11 <= 2147483647L) {
                        return new Pair(10, 5);
                    }
                    return new Pair(5, -1);
                }
                return new Pair(10, -1);
            } catch (NumberFormatException unused3) {
            }
        }
        return new Pair(2, -1);
    }

    private static Long parseDateTime(@Nullable String str, @Nullable String str2, @Nullable String str3) {
        long j10;
        if (str != null && Y.matcher(str).matches()) {
            ParsePosition parsePosition = new ParsePosition(0);
            try {
                Date date = J.parse(str, parsePosition);
                if (date == null && (date = K.parse(str, parsePosition)) == null) {
                    return null;
                }
                long time = date.getTime();
                if (str3 != null) {
                    String strSubstring = str3.substring(0, 1);
                    int i10 = Integer.parseInt(str3.substring(1, 3));
                    int i11 = Integer.parseInt(str3.substring(4, 6));
                    if (("+".equals(strSubstring) || "-".equals(strSubstring)) && ":".equals(str3.substring(3, 4)) && i10 <= 14) {
                        time += (long) (((i10 * 60) + i11) * 60000 * ("-".equals(strSubstring) ? 1 : -1));
                    }
                }
                if (str2 != null) {
                    try {
                        int iMin = Math.min(str2.length(), 3);
                        j10 = Long.parseLong(str2.substring(0, iMin));
                        while (iMin < 3) {
                            j10 *= 10;
                            iMin++;
                        }
                    } catch (NumberFormatException unused) {
                        j10 = 0;
                    }
                    time += j10;
                }
                return Long.valueOf(time);
            } catch (IllegalArgumentException unused2) {
            }
        }
        return null;
    }

    public static ByteOrder r(b bVar) throws IOException {
        short s10 = bVar.readShort();
        if (s10 == 18761) {
            return ByteOrder.LITTLE_ENDIAN;
        }
        if (s10 == 19789) {
            return ByteOrder.BIG_ENDIAN;
        }
        throw new IOException("Invalid byte order: " + Integer.toHexString(s10));
    }

    public final void a() {
        String attribute = getAttribute("DateTimeOriginal");
        HashMap[] mapArr = this.f26382d;
        if (attribute != null && getAttribute("DateTime") == null) {
            mapArr[0].put("DateTime", c.a(attribute));
        }
        if (getAttribute("ImageWidth") == null) {
            mapArr[0].put("ImageWidth", c.b(0L, this.f26384f));
        }
        if (getAttribute("ImageLength") == null) {
            mapArr[0].put("ImageLength", c.b(0L, this.f26384f));
        }
        if (getAttribute("Orientation") == null) {
            mapArr[0].put("Orientation", c.b(0L, this.f26384f));
        }
        if (getAttribute("LightSource") == null) {
            mapArr[1].put("LightSource", c.b(0L, this.f26384f));
        }
    }

    public final int c() {
        c exifAttribute = getExifAttribute("Orientation");
        if (exifAttribute == null) {
            return 1;
        }
        try {
            return exifAttribute.h(this.f26384f);
        } catch (NumberFormatException unused) {
            return 1;
        }
    }

    public final void d(f fVar) throws IOException {
        String strExtractMetadata;
        String strExtractMetadata2;
        String strExtractMetadata3;
        if (Build.VERSION.SDK_INT < 28) {
            throw new UnsupportedOperationException("Reading EXIF from HEIF files is supported from SDK 28 and above");
        }
        MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
        try {
            try {
                i.a(mediaMetadataRetriever, new a(fVar));
                String strExtractMetadata4 = mediaMetadataRetriever.extractMetadata(33);
                String strExtractMetadata5 = mediaMetadataRetriever.extractMetadata(34);
                String strExtractMetadata6 = mediaMetadataRetriever.extractMetadata(26);
                String strExtractMetadata7 = mediaMetadataRetriever.extractMetadata(17);
                if ("yes".equals(strExtractMetadata6)) {
                    strExtractMetadata = mediaMetadataRetriever.extractMetadata(29);
                    strExtractMetadata2 = mediaMetadataRetriever.extractMetadata(30);
                    strExtractMetadata3 = mediaMetadataRetriever.extractMetadata(31);
                } else if ("yes".equals(strExtractMetadata7)) {
                    strExtractMetadata = mediaMetadataRetriever.extractMetadata(18);
                    strExtractMetadata2 = mediaMetadataRetriever.extractMetadata(19);
                    strExtractMetadata3 = mediaMetadataRetriever.extractMetadata(24);
                } else {
                    strExtractMetadata = null;
                    strExtractMetadata2 = null;
                    strExtractMetadata3 = null;
                }
                HashMap[] mapArr = this.f26382d;
                if (strExtractMetadata != null) {
                    mapArr[0].put("ImageWidth", c.e(Integer.parseInt(strExtractMetadata), this.f26384f));
                }
                if (strExtractMetadata2 != null) {
                    mapArr[0].put("ImageLength", c.e(Integer.parseInt(strExtractMetadata2), this.f26384f));
                }
                if (strExtractMetadata3 != null) {
                    int i10 = Integer.parseInt(strExtractMetadata3);
                    mapArr[0].put("Orientation", c.e(i10 != 90 ? i10 != 180 ? i10 != 270 ? 1 : 8 : 3 : 6, this.f26384f));
                }
                if (strExtractMetadata4 != null && strExtractMetadata5 != null) {
                    int i11 = Integer.parseInt(strExtractMetadata4);
                    int i12 = Integer.parseInt(strExtractMetadata5);
                    if (i12 <= 6) {
                        throw new IOException("Invalid exif length");
                    }
                    fVar.g(i11);
                    byte[] bArr = new byte[6];
                    if (fVar.read(bArr) != 6) {
                        throw new IOException("Can't read identifier");
                    }
                    int i13 = i11 + 6;
                    int i14 = i12 - 6;
                    if (!Arrays.equals(bArr, W)) {
                        throw new IOException("Invalid identifier");
                    }
                    byte[] bArr2 = new byte[i14];
                    if (fVar.read(bArr2) != i14) {
                        throw new IOException("Can't read exif");
                    }
                    this.f26392n = i13;
                    s(0, bArr2);
                }
                mediaMetadataRetriever.release();
            } catch (RuntimeException unused) {
                throw new UnsupportedOperationException("Failed to read EXIF from HEIF file. Given stream is either malformed or unsupported.");
            }
        } catch (Throwable th) {
            mediaMetadataRetriever.release();
            throw th;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:100:0x0142 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:103:0x00fb A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:34:0x006a A[FALL_THROUGH] */
    /* JADX WARN: Removed duplicated region for block: B:71:0x00f1  */
    /* JADX WARN: Removed duplicated region for block: B:82:0x013c A[LOOP:0: B:10:0x0023->B:82:0x013c, LOOP_END] */
    /*  JADX ERROR: UnsupportedOperationException in pass: RegionMakerVisitor
        java.lang.UnsupportedOperationException
        	at java.base/java.util.Collections$UnmodifiableCollection.add(Collections.java:1092)
        	at jadx.core.dex.visitors.regions.maker.SwitchRegionMaker$1.leaveRegion(SwitchRegionMaker.java:390)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:70)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverse(DepthRegionTraversal.java:23)
        	at jadx.core.dex.visitors.regions.maker.SwitchRegionMaker.insertBreaksForCase(SwitchRegionMaker.java:370)
        	at jadx.core.dex.visitors.regions.maker.SwitchRegionMaker.insertBreaks(SwitchRegionMaker.java:85)
        	at jadx.core.dex.visitors.regions.PostProcessRegions.leaveRegion(PostProcessRegions.java:33)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:70)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1117)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1117)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1117)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1117)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1117)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1117)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1117)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1117)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1117)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverse(DepthRegionTraversal.java:19)
        	at jadx.core.dex.visitors.regions.PostProcessRegions.process(PostProcessRegions.java:23)
        	at jadx.core.dex.visitors.regions.RegionMakerVisitor.visit(RegionMakerVisitor.java:31)
        */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void e(h1.b r21, int r22, int r23) throws java.lang.Throwable {
        /*
            Method dump skipped, instruction units count: 456
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: h1.g.e(h1.b, int, int):void");
    }

    /* JADX WARN: Removed duplicated region for block: B:105:0x012b  */
    /* JADX WARN: Removed duplicated region for block: B:148:0x015a A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:66:0x00d5  */
    /* JADX WARN: Removed duplicated region for block: B:69:0x00db A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:85:0x0105  */
    /* JADX WARN: Removed duplicated region for block: B:86:0x0107  */
    /* JADX WARN: Removed duplicated region for block: B:89:0x010d A[RETURN] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int f(BufferedInputStream bufferedInputStream) throws Throwable {
        b bVar;
        b bVar2;
        b bVar3;
        b bVar4;
        b bVar5;
        b bVar6;
        int i10;
        byte[] bArr;
        b bVar7;
        boolean z10;
        boolean z11;
        long j10;
        bufferedInputStream.mark(5000);
        byte[] bArr2 = new byte[5000];
        bufferedInputStream.read(bArr2);
        bufferedInputStream.reset();
        int i11 = 0;
        while (true) {
            byte[] bArr3 = f26375w;
            if (i11 >= bArr3.length) {
                return 4;
            }
            if (bArr2[i11] != bArr3[i11]) {
                byte[] bytes = "FUJIFILMCCD-RAW".getBytes(Charset.defaultCharset());
                for (int i12 = 0; i12 < bytes.length; i12++) {
                    if (bArr2[i12] != bytes[i12]) {
                        try {
                            bVar2 = new b(bArr2);
                            try {
                                long j11 = bVar2.readInt();
                                byte[] bArr4 = new byte[4];
                                bVar2.read(bArr4);
                                if (Arrays.equals(bArr4, f26376x)) {
                                    if (j11 == 1) {
                                        j11 = bVar2.readLong();
                                        j10 = 16;
                                        if (j11 < 16) {
                                        }
                                    } else {
                                        j10 = 8;
                                    }
                                    long j12 = 5000;
                                    if (j11 > j12) {
                                        j11 = j12;
                                    }
                                    long j13 = j11 - j10;
                                    if (j13 >= 8) {
                                        byte[] bArr5 = new byte[4];
                                        boolean z12 = false;
                                        boolean z13 = false;
                                        for (long j14 = 0; j14 < j13 / 4 && bVar2.read(bArr5) == 4; j14++) {
                                            if (j14 != 1) {
                                                if (Arrays.equals(bArr5, f26377y)) {
                                                    z12 = true;
                                                } else if (Arrays.equals(bArr5, f26378z)) {
                                                    z13 = true;
                                                }
                                                if (z12 && z13) {
                                                    bVar2.close();
                                                    return 12;
                                                }
                                            }
                                        }
                                    }
                                }
                            } catch (Exception unused) {
                                if (bVar2 != null) {
                                }
                                bVar4 = new b(bArr2);
                                ByteOrder byteOrderR = r(bVar4);
                                this.f26384f = byteOrderR;
                                bVar4.f26355b = byteOrderR;
                                short s10 = bVar4.readShort();
                                if (s10 != 20306) {
                                    bVar4.close();
                                    if (z11) {
                                    }
                                }
                                bVar7 = new b(bArr2);
                                try {
                                    ByteOrder byteOrderR2 = r(bVar7);
                                    this.f26384f = byteOrderR2;
                                    bVar7.f26355b = byteOrderR2;
                                    if (bVar7.readShort() != 85) {
                                    }
                                    bVar7.close();
                                    if (z10) {
                                    }
                                } catch (Exception unused2) {
                                    bVar6 = bVar7;
                                    if (bVar6 != null) {
                                        bVar6.close();
                                    }
                                } catch (Throwable th) {
                                    th = th;
                                    bVar5 = bVar7;
                                    if (bVar5 != null) {
                                        bVar5.close();
                                    }
                                    throw th;
                                }
                                i10 = 0;
                                while (true) {
                                    bArr = C;
                                    if (i10 < bArr.length) {
                                    }
                                    i10++;
                                }
                            } catch (Throwable th2) {
                                th = th2;
                                bVar = bVar2;
                                if (bVar != null) {
                                    bVar.close();
                                }
                                throw th;
                            }
                        } catch (Exception unused3) {
                            bVar2 = null;
                        } catch (Throwable th3) {
                            th = th3;
                            bVar = null;
                        }
                        bVar2.close();
                        try {
                            bVar4 = new b(bArr2);
                        } catch (Exception unused4) {
                            bVar4 = null;
                        } catch (Throwable th4) {
                            th = th4;
                            bVar3 = null;
                        }
                        try {
                            ByteOrder byteOrderR3 = r(bVar4);
                            this.f26384f = byteOrderR3;
                            bVar4.f26355b = byteOrderR3;
                            short s102 = bVar4.readShort();
                            z11 = s102 != 20306 || s102 == 21330;
                            bVar4.close();
                            if (z11) {
                                return 7;
                            }
                        } catch (Exception unused5) {
                            if (bVar4 != null) {
                                bVar4.close();
                            }
                        } catch (Throwable th5) {
                            th = th5;
                            bVar3 = bVar4;
                            if (bVar3 != null) {
                                bVar3.close();
                            }
                            throw th;
                        }
                        try {
                            bVar7 = new b(bArr2);
                            ByteOrder byteOrderR22 = r(bVar7);
                            this.f26384f = byteOrderR22;
                            bVar7.f26355b = byteOrderR22;
                            z10 = bVar7.readShort() != 85;
                            bVar7.close();
                            if (z10) {
                                return 10;
                            }
                        } catch (Exception unused6) {
                            bVar6 = null;
                        } catch (Throwable th6) {
                            th = th6;
                            bVar5 = null;
                        }
                        i10 = 0;
                        while (true) {
                            bArr = C;
                            if (i10 < bArr.length) {
                                return 13;
                            }
                            if (bArr2[i10] != bArr[i10]) {
                                int i13 = 0;
                                while (true) {
                                    byte[] bArr6 = G;
                                    if (i13 >= bArr6.length) {
                                        int i14 = 0;
                                        while (true) {
                                            byte[] bArr7 = H;
                                            if (i14 >= bArr7.length) {
                                                return 14;
                                            }
                                            if (bArr2[bArr6.length + i14 + 4] != bArr7[i14]) {
                                                break;
                                            }
                                            i14++;
                                        }
                                    } else {
                                        if (bArr2[i13] != bArr6[i13]) {
                                            break;
                                        }
                                        i13++;
                                    }
                                }
                                return 0;
                            }
                            i10++;
                        }
                    }
                }
                return 9;
            }
            i11++;
        }
    }

    public final void g(f fVar) throws Throwable {
        int i10;
        int i11;
        j(fVar);
        HashMap[] mapArr = this.f26382d;
        c cVar = (c) mapArr[1].get("MakerNote");
        if (cVar != null) {
            f fVar2 = new f(cVar.f26361d);
            fVar2.f26355b = this.f26384f;
            byte[] bArr = A;
            byte[] bArr2 = new byte[bArr.length];
            fVar2.readFully(bArr2);
            fVar2.g(0L);
            byte[] bArr3 = B;
            byte[] bArr4 = new byte[bArr3.length];
            fVar2.readFully(bArr4);
            if (Arrays.equals(bArr2, bArr)) {
                fVar2.g(8L);
            } else if (Arrays.equals(bArr4, bArr3)) {
                fVar2.g(12L);
            }
            t(fVar2, 6);
            c cVar2 = (c) mapArr[7].get("PreviewImageStart");
            c cVar3 = (c) mapArr[7].get("PreviewImageLength");
            if (cVar2 != null && cVar3 != null) {
                mapArr[5].put("JPEGInterchangeFormat", cVar2);
                mapArr[5].put("JPEGInterchangeFormatLength", cVar3);
            }
            c cVar4 = (c) mapArr[8].get("AspectFrame");
            if (cVar4 != null) {
                int[] iArr = (int[]) cVar4.j(this.f26384f);
                if (iArr == null || iArr.length != 4) {
                    Arrays.toString(iArr);
                    return;
                }
                int i12 = iArr[2];
                int i13 = iArr[0];
                if (i12 <= i13 || (i10 = iArr[3]) <= (i11 = iArr[1])) {
                    return;
                }
                int i14 = (i12 - i13) + 1;
                int i15 = (i10 - i11) + 1;
                if (i14 < i15) {
                    int i16 = i14 + i15;
                    i15 = i16 - i15;
                    i14 = i16 - i15;
                }
                c cVarE = c.e(i14, this.f26384f);
                c cVarE2 = c.e(i15, this.f26384f);
                mapArr[0].put("ImageWidth", cVarE);
                mapArr[0].put("ImageLength", cVarE2);
            }
        }
    }

    @Nullable
    public String getAttribute(@NonNull String str) {
        if (str == null) {
            throw new NullPointerException("tag shouldn't be null");
        }
        c exifAttribute = getExifAttribute(str);
        if (exifAttribute != null) {
            if (!T.contains(str)) {
                return exifAttribute.i(this.f26384f);
            }
            if (str.equals("GPSTimeStamp")) {
                int i10 = exifAttribute.f26358a;
                if (i10 != 5 && i10 != 10) {
                    return null;
                }
                e[] eVarArr = (e[]) exifAttribute.j(this.f26384f);
                if (eVarArr == null || eVarArr.length != 3) {
                    Arrays.toString(eVarArr);
                    return null;
                }
                e eVar = eVarArr[0];
                Integer numValueOf = Integer.valueOf((int) (eVar.f26366a / eVar.f26367b));
                e eVar2 = eVarArr[1];
                Integer numValueOf2 = Integer.valueOf((int) (eVar2.f26366a / eVar2.f26367b));
                e eVar3 = eVarArr[2];
                return String.format("%02d:%02d:%02d", numValueOf, numValueOf2, Integer.valueOf((int) (eVar3.f26366a / eVar3.f26367b)));
            }
            try {
                return Double.toString(exifAttribute.g(this.f26384f));
            } catch (NumberFormatException unused) {
            }
        }
        return null;
    }

    @Nullable
    public byte[] getAttributeBytes(@NonNull String str) {
        if (str == null) {
            throw new NullPointerException("tag shouldn't be null");
        }
        c exifAttribute = getExifAttribute(str);
        if (exifAttribute != null) {
            return exifAttribute.f26361d;
        }
        return null;
    }

    @Nullable
    public long[] getAttributeRange(@NonNull String str) {
        if (str == null) {
            throw new NullPointerException("tag shouldn't be null");
        }
        c exifAttribute = getExifAttribute(str);
        if (exifAttribute != null) {
            return new long[]{exifAttribute.f26360c, exifAttribute.f26361d.length};
        }
        return null;
    }

    @Nullable
    @RestrictTo({RestrictTo.Scope.f555a})
    public Long getDateTime() {
        return parseDateTime(getAttribute("DateTime"), getAttribute("SubSecTime"), getAttribute("OffsetTime"));
    }

    @Nullable
    @RestrictTo({RestrictTo.Scope.f555a})
    public Long getDateTimeDigitized() {
        return parseDateTime(getAttribute("DateTimeDigitized"), getAttribute("SubSecTimeDigitized"), getAttribute("OffsetTimeDigitized"));
    }

    @Nullable
    @RestrictTo({RestrictTo.Scope.f555a})
    public Long getDateTimeOriginal() {
        return parseDateTime(getAttribute("DateTimeOriginal"), getAttribute("SubSecTimeOriginal"), getAttribute("OffsetTimeOriginal"));
    }

    @Nullable
    @SuppressLint({"AutoBoxing"})
    public Long getGpsDateTime() {
        String attribute = getAttribute("GPSDateStamp");
        String attribute2 = getAttribute("GPSTimeStamp");
        if (attribute != null && attribute2 != null) {
            Pattern pattern = Y;
            if (pattern.matcher(attribute).matches() || pattern.matcher(attribute2).matches()) {
                String str = attribute + ' ' + attribute2;
                ParsePosition parsePosition = new ParsePosition(0);
                try {
                    Date date = J.parse(str, parsePosition);
                    if (date == null && (date = K.parse(str, parsePosition)) == null) {
                        return null;
                    }
                    return Long.valueOf(date.getTime());
                } catch (IllegalArgumentException unused) {
                }
            }
        }
        return null;
    }

    @Nullable
    public double[] getLatLong() {
        String attribute = getAttribute("GPSLatitude");
        String attribute2 = getAttribute("GPSLatitudeRef");
        String attribute3 = getAttribute("GPSLongitude");
        String attribute4 = getAttribute("GPSLongitudeRef");
        if (attribute == null || attribute2 == null || attribute3 == null || attribute4 == null) {
            return null;
        }
        try {
            return new double[]{b(attribute, attribute2), b(attribute3, attribute4)};
        } catch (IllegalArgumentException unused) {
            String.format("latValue=%s, latRef=%s, lngValue=%s, lngRef=%s", attribute, attribute2, attribute3, attribute4);
            return null;
        }
    }

    @Nullable
    public byte[] getThumbnail() {
        int i10 = this.f26391m;
        if (i10 == 6 || i10 == 7) {
            return getThumbnailBytes();
        }
        return null;
    }

    @Nullable
    public Bitmap getThumbnailBitmap() throws Throwable {
        if (!this.f26385g) {
            return null;
        }
        if (this.f26390l == null) {
            this.f26390l = getThumbnailBytes();
        }
        int i10 = this.f26391m;
        if (i10 == 6 || i10 == 7) {
            return BitmapFactory.decodeByteArray(this.f26390l, 0, this.f26389k);
        }
        if (i10 == 1) {
            int length = this.f26390l.length / 3;
            int[] iArr = new int[length];
            for (int i11 = 0; i11 < length; i11++) {
                byte[] bArr = this.f26390l;
                int i12 = i11 * 3;
                iArr[i11] = (bArr[i12] << 16) + (bArr[i12 + 1] << 8) + bArr[i12 + 2];
            }
            HashMap[] mapArr = this.f26382d;
            c cVar = (c) mapArr[4].get("ThumbnailImageLength");
            c cVar2 = (c) mapArr[4].get("ThumbnailImageWidth");
            if (cVar != null && cVar2 != null) {
                return Bitmap.createBitmap(iArr, cVar2.h(this.f26384f), cVar.h(this.f26384f), Bitmap.Config.ARGB_8888);
            }
        }
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:27:0x0055 A[Catch: all -> 0x006e, Exception -> 0x009b, TRY_ENTER, TryCatch #16 {Exception -> 0x009b, all -> 0x006e, blocks: (B:24:0x003f, B:27:0x0055, B:29:0x0061, B:39:0x0073, B:40:0x0078, B:41:0x0079, B:42:0x007e), top: B:85:0x003f }] */
    /* JADX WARN: Removed duplicated region for block: B:41:0x0079 A[Catch: all -> 0x006e, Exception -> 0x009b, TryCatch #16 {Exception -> 0x009b, all -> 0x006e, blocks: (B:24:0x003f, B:27:0x0055, B:29:0x0061, B:39:0x0073, B:40:0x0078, B:41:0x0079, B:42:0x007e), top: B:85:0x003f }] */
    /* JADX WARN: Removed duplicated region for block: B:75:0x0097 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:81:0x008f A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:94:? A[SYNTHETIC] */
    @Nullable
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public byte[] getThumbnailBytes() throws Throwable {
        Throwable th;
        FileDescriptor fileDescriptor;
        InputStream fileInputStream;
        Throwable th2;
        InputStream inputStream = null;
        if (!this.f26385g) {
            return null;
        }
        byte[] bArr = this.f26390l;
        if (bArr != null) {
            return bArr;
        }
        try {
            fileInputStream = this.f26380b;
        } catch (Exception unused) {
            fileInputStream = null;
            fileDescriptor = null;
        } catch (Throwable th3) {
            th = th3;
            fileDescriptor = null;
        }
        if (fileInputStream != null) {
            try {
                if (!fileInputStream.markSupported()) {
                    try {
                        fileInputStream.close();
                    } catch (RuntimeException e10) {
                        throw e10;
                    } catch (Exception unused2) {
                    }
                    return null;
                }
                fileInputStream.reset();
                fileDescriptor = null;
                try {
                    if (fileInputStream.skip(this.f26388j + this.f26392n) == this.f26388j + this.f26392n) {
                        throw new IOException("Corrupted image");
                    }
                    byte[] bArr2 = new byte[this.f26389k];
                    if (fileInputStream.read(bArr2) != this.f26389k) {
                        throw new IOException("Corrupted image");
                    }
                    this.f26390l = bArr2;
                    try {
                        fileInputStream.close();
                    } catch (RuntimeException e11) {
                        throw e11;
                    } catch (Exception unused3) {
                    }
                    if (fileDescriptor != null) {
                        try {
                            h.a(fileDescriptor);
                        } catch (Exception unused4) {
                        }
                    }
                    return bArr2;
                } catch (Exception unused5) {
                } catch (Throwable th4) {
                    th2 = th4;
                    inputStream = fileInputStream;
                    th = th2;
                    if (inputStream != null) {
                    }
                    if (fileDescriptor == null) {
                    }
                }
            } catch (Exception unused6) {
                fileDescriptor = null;
            } catch (Throwable th5) {
                inputStream = fileInputStream;
                th = th5;
                fileDescriptor = null;
            }
            if (fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch (RuntimeException e12) {
                    throw e12;
                } catch (Exception unused7) {
                }
            }
            if (fileDescriptor != null) {
                try {
                    h.a(fileDescriptor);
                } catch (Exception unused8) {
                }
            }
            return null;
        }
        FileDescriptor fileDescriptorB = h.b(this.f26379a);
        try {
            h.c(fileDescriptorB, 0L, OsConstants.SEEK_SET);
            fileDescriptor = fileDescriptorB;
            fileInputStream = new FileInputStream(fileDescriptorB);
            if (fileInputStream.skip(this.f26388j + this.f26392n) == this.f26388j + this.f26392n) {
            }
        } catch (Exception unused9) {
            fileDescriptor = fileDescriptorB;
            fileInputStream = null;
        } catch (Throwable th6) {
            th2 = th6;
            fileDescriptor = fileDescriptorB;
            th = th2;
            if (inputStream != null) {
            }
            if (fileDescriptor == null) {
            }
        }
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (RuntimeException e13) {
                throw e13;
            } catch (Exception unused10) {
            }
        }
        if (fileDescriptor == null) {
            throw th;
        }
        try {
            h.a(fileDescriptor);
            throw th;
        } catch (Exception unused11) {
            throw th;
        }
    }

    @Nullable
    public long[] getThumbnailRange() {
        if (!this.f26385g) {
            return null;
        }
        if (!this.f26386h || this.f26387i) {
            return new long[]{this.f26388j + this.f26392n, this.f26389k};
        }
        return null;
    }

    public final void h(b bVar) throws Throwable {
        if (f26370r) {
            Objects.toString(bVar);
        }
        bVar.f26355b = ByteOrder.BIG_ENDIAN;
        byte[] bArr = C;
        bVar.e(bArr.length);
        int length = bArr.length;
        while (true) {
            try {
                int i10 = bVar.readInt();
                byte[] bArr2 = new byte[4];
                if (bVar.read(bArr2) != 4) {
                    throw new IOException("Encountered invalid length while parsing PNG chunktype");
                }
                int i11 = length + 8;
                if (i11 == 16 && !Arrays.equals(bArr2, E)) {
                    throw new IOException("Encountered invalid PNG file--IHDR chunk should appearas the first chunk");
                }
                if (Arrays.equals(bArr2, F)) {
                    return;
                }
                if (Arrays.equals(bArr2, D)) {
                    byte[] bArr3 = new byte[i10];
                    if (bVar.read(bArr3) != i10) {
                        throw new IOException("Failed to read given length for given PNG chunk type: " + ua.b.d(bArr2));
                    }
                    int i12 = bVar.readInt();
                    CRC32 crc32 = new CRC32();
                    crc32.update(bArr2);
                    crc32.update(bArr3);
                    if (((int) crc32.getValue()) == i12) {
                        this.f26392n = i11;
                        s(0, bArr3);
                        y();
                        v(new b(bArr3));
                        return;
                    }
                    throw new IOException("Encountered invalid CRC value for PNG-EXIF chunk.\n recorded CRC value: " + i12 + ", calculated CRC value: " + crc32.getValue());
                }
                int i13 = i10 + 4;
                bVar.e(i13);
                length = i11 + i13;
            } catch (EOFException unused) {
                throw new IOException("Encountered corrupt PNG file.");
            }
        }
    }

    public final void i(b bVar) throws Throwable {
        if (f26370r) {
            Objects.toString(bVar);
        }
        bVar.e(84);
        byte[] bArr = new byte[4];
        byte[] bArr2 = new byte[4];
        byte[] bArr3 = new byte[4];
        bVar.read(bArr);
        bVar.read(bArr2);
        bVar.read(bArr3);
        int i10 = ByteBuffer.wrap(bArr).getInt();
        int i11 = ByteBuffer.wrap(bArr2).getInt();
        int i12 = ByteBuffer.wrap(bArr3).getInt();
        byte[] bArr4 = new byte[i11];
        bVar.e(i10 - bVar.f26356c);
        bVar.read(bArr4);
        e(new b(bArr4), i10, 5);
        bVar.e(i12 - bVar.f26356c);
        bVar.f26355b = ByteOrder.BIG_ENDIAN;
        int i13 = bVar.readInt();
        for (int i14 = 0; i14 < i13; i14++) {
            int unsignedShort = bVar.readUnsignedShort();
            int unsignedShort2 = bVar.readUnsignedShort();
            if (unsignedShort == O.f26362a) {
                short s10 = bVar.readShort();
                short s11 = bVar.readShort();
                c cVarE = c.e(s10, this.f26384f);
                c cVarE2 = c.e(s11, this.f26384f);
                HashMap[] mapArr = this.f26382d;
                mapArr[0].put("ImageLength", cVarE);
                mapArr[0].put("ImageWidth", cVarE2);
                return;
            }
            bVar.e(unsignedShort2);
        }
    }

    public final void j(f fVar) throws Throwable {
        p(fVar);
        t(fVar, 0);
        x(fVar, 0);
        x(fVar, 5);
        x(fVar, 4);
        y();
        if (this.f26381c == 8) {
            HashMap[] mapArr = this.f26382d;
            c cVar = (c) mapArr[1].get("MakerNote");
            if (cVar != null) {
                f fVar2 = new f(cVar.f26361d);
                fVar2.f26355b = this.f26384f;
                fVar2.e(6);
                t(fVar2, 9);
                c cVar2 = (c) mapArr[9].get("ColorSpace");
                if (cVar2 != null) {
                    mapArr[1].put("ColorSpace", cVar2);
                }
            }
        }
    }

    public final void k(f fVar) throws Throwable {
        if (f26370r) {
            Objects.toString(fVar);
        }
        j(fVar);
        HashMap[] mapArr = this.f26382d;
        c cVar = (c) mapArr[0].get("JpgFromRaw");
        if (cVar != null) {
            e(new b(cVar.f26361d), (int) cVar.f26360c, 5);
        }
        c cVar2 = (c) mapArr[0].get("ISO");
        c cVar3 = (c) mapArr[1].get("PhotographicSensitivity");
        if (cVar2 == null || cVar3 != null) {
            return;
        }
        mapArr[1].put("PhotographicSensitivity", cVar2);
    }

    public final void l(b bVar) throws Throwable {
        if (f26370r) {
            Objects.toString(bVar);
        }
        bVar.f26355b = ByteOrder.LITTLE_ENDIAN;
        bVar.e(G.length);
        int i10 = bVar.readInt() + 8;
        byte[] bArr = H;
        bVar.e(bArr.length);
        int length = bArr.length + 8;
        while (true) {
            try {
                byte[] bArr2 = new byte[4];
                if (bVar.read(bArr2) != 4) {
                    throw new IOException("Encountered invalid length while parsing WebP chunktype");
                }
                int i11 = bVar.readInt();
                int i12 = length + 8;
                if (Arrays.equals(I, bArr2)) {
                    byte[] bArr3 = new byte[i11];
                    if (bVar.read(bArr3) == i11) {
                        this.f26392n = i12;
                        s(0, bArr3);
                        v(new b(bArr3));
                        return;
                    } else {
                        throw new IOException("Failed to read given length for given PNG chunk type: " + ua.b.d(bArr2));
                    }
                }
                if (i11 % 2 == 1) {
                    i11++;
                }
                length = i12 + i11;
                if (length == i10) {
                    return;
                }
                if (length > i10) {
                    throw new IOException("Encountered WebP file with invalid chunk size");
                }
                bVar.e(i11);
            } catch (EOFException unused) {
                throw new IOException("Encountered corrupt WebP file.");
            }
        }
    }

    public final void n(b bVar, HashMap map) throws Throwable {
        c cVar = (c) map.get("JPEGInterchangeFormat");
        c cVar2 = (c) map.get("JPEGInterchangeFormatLength");
        if (cVar == null || cVar2 == null) {
            return;
        }
        int iH = cVar.h(this.f26384f);
        int iH2 = cVar2.h(this.f26384f);
        if (this.f26381c == 7) {
            iH += this.f26393o;
        }
        if (iH <= 0 || iH2 <= 0) {
            return;
        }
        this.f26385g = true;
        if (this.f26380b == null && this.f26379a == null) {
            byte[] bArr = new byte[iH2];
            bVar.skip(iH);
            bVar.read(bArr);
            this.f26390l = bArr;
        }
        this.f26388j = iH;
        this.f26389k = iH2;
    }

    public final boolean o(HashMap map) {
        c cVar = (c) map.get("ImageLength");
        c cVar2 = (c) map.get("ImageWidth");
        if (cVar == null || cVar2 == null) {
            return false;
        }
        return cVar.h(this.f26384f) <= 512 && cVar2.h(this.f26384f) <= 512;
    }

    public final void p(b bVar) throws IOException {
        ByteOrder byteOrderR = r(bVar);
        this.f26384f = byteOrderR;
        bVar.f26355b = byteOrderR;
        int unsignedShort = bVar.readUnsignedShort();
        int i10 = this.f26381c;
        if (i10 != 7 && i10 != 10 && unsignedShort != 42) {
            throw new IOException("Invalid start code: " + Integer.toHexString(unsignedShort));
        }
        int i11 = bVar.readInt();
        if (i11 < 8) {
            throw new IOException(u1.g("Invalid first Ifd offset: ", i11));
        }
        int i12 = i11 - 8;
        if (i12 > 0) {
            bVar.e(i12);
        }
    }

    public final void q() throws Throwable {
        int i10 = 0;
        while (true) {
            HashMap[] mapArr = this.f26382d;
            if (i10 >= mapArr.length) {
                return;
            }
            mapArr[i10].size();
            for (Map.Entry entry : mapArr[i10].entrySet()) {
                c cVar = (c) entry.getValue();
                cVar.toString();
                cVar.i(this.f26384f);
            }
            i10++;
        }
    }

    public final void s(int i10, byte[] bArr) throws IOException {
        f fVar = new f(bArr);
        p(fVar);
        t(fVar, i10);
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Removed duplicated region for block: B:103:0x026e  */
    /* JADX WARN: Removed duplicated region for block: B:108:0x02a7  */
    /* JADX WARN: Removed duplicated region for block: B:113:0x02cb  */
    /* JADX WARN: Removed duplicated region for block: B:118:0x02ef  */
    /* JADX WARN: Removed duplicated region for block: B:119:0x02fa  */
    /* JADX WARN: Removed duplicated region for block: B:78:0x0180  */
    /* JADX WARN: Removed duplicated region for block: B:86:0x01c1  */
    /* JADX WARN: Removed duplicated region for block: B:95:0x022d  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void setAttribute(@NonNull String str, @Nullable String str2) {
        d dVar;
        int i10;
        int i11;
        c cVar;
        String str3 = str;
        String strReplaceAll = str2;
        if (str3 == null) {
            throw new NullPointerException("tag shouldn't be null");
        }
        if (("DateTime".equals(str3) || "DateTimeOriginal".equals(str3) || "DateTimeDigitized".equals(str3)) && strReplaceAll != null) {
            boolean zFind = f26368a0.matcher(strReplaceAll).find();
            boolean zFind2 = f26369b0.matcher(strReplaceAll).find();
            if (str2.length() != 19) {
                return;
            }
            if (!zFind && !zFind2) {
                return;
            }
            if (zFind2) {
                strReplaceAll = strReplaceAll.replaceAll("-", ":");
            }
        }
        if ("ISOSpeedRatings".equals(str3)) {
            str3 = "PhotographicSensitivity";
        }
        int i12 = 2;
        int i13 = 1;
        if (strReplaceAll != null && T.contains(str3)) {
            if (str3.equals("GPSTimeStamp")) {
                Matcher matcher = Z.matcher(strReplaceAll);
                if (!matcher.find()) {
                    return;
                }
                strReplaceAll = Integer.parseInt(matcher.group(1)) + "/1," + Integer.parseInt(matcher.group(2)) + "/1," + Integer.parseInt(matcher.group(3)) + "/1";
            } else {
                try {
                    strReplaceAll = new e((long) (Double.parseDouble(strReplaceAll) * 10000.0d), 10000L).toString();
                } catch (NumberFormatException unused) {
                    return;
                }
            }
        }
        int i14 = 0;
        int i15 = 0;
        while (i15 < P.length) {
            if ((i15 != 4 || this.f26385g) && (dVar = (d) S[i15].get(str3)) != null) {
                HashMap[] mapArr = this.f26382d;
                if (strReplaceAll == null) {
                    mapArr[i15].remove(str3);
                } else {
                    Pair pairM = m(strReplaceAll);
                    int iIntValue = ((Integer) pairM.first).intValue();
                    int i16 = -1;
                    int i17 = dVar.f26364c;
                    if (i17 == iIntValue || i17 == ((Integer) pairM.second).intValue()) {
                        int[] iArr = M;
                        switch (i17) {
                            case 1:
                                HashMap map = mapArr[i15];
                                i10 = 1;
                                if (strReplaceAll.length() == 1) {
                                    i11 = 0;
                                    if (strReplaceAll.charAt(0) >= '0' && strReplaceAll.charAt(0) <= '1') {
                                        cVar = new c(1, 1, new byte[]{(byte) (strReplaceAll.charAt(0) - '0')});
                                    }
                                    map.put(str3, cVar);
                                } else {
                                    i11 = 0;
                                }
                                byte[] bytes = strReplaceAll.getBytes(V);
                                cVar = new c(1, bytes.length, bytes);
                                map.put(str3, cVar);
                                break;
                            case 2:
                            case 7:
                                mapArr[i15].put(str3, c.a(strReplaceAll));
                                i11 = 0;
                                i10 = 1;
                                break;
                            case 3:
                                String[] strArrSplit = strReplaceAll.split(",", -1);
                                int[] iArr2 = new int[strArrSplit.length];
                                for (int i18 = 0; i18 < strArrSplit.length; i18++) {
                                    iArr2[i18] = Integer.parseInt(strArrSplit[i18]);
                                }
                                mapArr[i15].put(str3, c.f(iArr2, this.f26384f));
                                i11 = 0;
                                i10 = 1;
                                break;
                            case 4:
                                String[] strArrSplit2 = strReplaceAll.split(",", -1);
                                long[] jArr = new long[strArrSplit2.length];
                                for (int i19 = 0; i19 < strArrSplit2.length; i19++) {
                                    jArr[i19] = Long.parseLong(strArrSplit2[i19]);
                                }
                                mapArr[i15].put(str3, c.c(jArr, this.f26384f));
                                i11 = 0;
                                i10 = 1;
                                break;
                            case 5:
                                int i20 = -1;
                                String[] strArrSplit3 = strReplaceAll.split(",", -1);
                                e[] eVarArr = new e[strArrSplit3.length];
                                int i21 = 0;
                                while (i21 < strArrSplit3.length) {
                                    String[] strArrSplit4 = strArrSplit3[i21].split("/", i20);
                                    eVarArr[i21] = new e((long) Double.parseDouble(strArrSplit4[0]), (long) Double.parseDouble(strArrSplit4[1]));
                                    i21++;
                                    i20 = -1;
                                }
                                mapArr[i15].put(str3, c.d(eVarArr, this.f26384f));
                                i11 = 0;
                                i10 = 1;
                                break;
                            case 9:
                                String[] strArrSplit5 = strReplaceAll.split(",", -1);
                                int length = strArrSplit5.length;
                                int[] iArr3 = new int[length];
                                for (int i22 = 0; i22 < strArrSplit5.length; i22++) {
                                    iArr3[i22] = Integer.parseInt(strArrSplit5[i22]);
                                }
                                HashMap map2 = mapArr[i15];
                                ByteOrder byteOrder = this.f26384f;
                                ByteBuffer byteBufferWrap = ByteBuffer.wrap(new byte[iArr[9] * length]);
                                byteBufferWrap.order(byteOrder);
                                for (int i23 = 0; i23 < length; i23++) {
                                    byteBufferWrap.putInt(iArr3[i23]);
                                }
                                map2.put(str3, new c(9, length, byteBufferWrap.array()));
                                i11 = 0;
                                i10 = 1;
                                break;
                            case 10:
                                String[] strArrSplit6 = strReplaceAll.split(",", -1);
                                int length2 = strArrSplit6.length;
                                e[] eVarArr2 = new e[length2];
                                int i24 = i14;
                                while (i24 < strArrSplit6.length) {
                                    String[] strArrSplit7 = strArrSplit6[i24].split("/", i16);
                                    eVarArr2[i24] = new e((long) Double.parseDouble(strArrSplit7[i14]), (long) Double.parseDouble(strArrSplit7[i13]));
                                    i24++;
                                    length2 = length2;
                                    i13 = 1;
                                    i14 = 0;
                                    i16 = -1;
                                }
                                int i25 = length2;
                                HashMap map3 = mapArr[i15];
                                ByteOrder byteOrder2 = this.f26384f;
                                ByteBuffer byteBufferWrap2 = ByteBuffer.wrap(new byte[iArr[10] * i25]);
                                byteBufferWrap2.order(byteOrder2);
                                for (int i26 = 0; i26 < i25; i26++) {
                                    e eVar = eVarArr2[i26];
                                    byteBufferWrap2.putInt((int) eVar.f26366a);
                                    byteBufferWrap2.putInt((int) eVar.f26367b);
                                }
                                map3.put(str3, new c(10, i25, byteBufferWrap2.array()));
                                i11 = 0;
                                i10 = 1;
                                break;
                            case 12:
                                String[] strArrSplit8 = strReplaceAll.split(",", -1);
                                int length3 = strArrSplit8.length;
                                double[] dArr = new double[length3];
                                for (int i27 = i14; i27 < strArrSplit8.length; i27++) {
                                    dArr[i27] = Double.parseDouble(strArrSplit8[i27]);
                                }
                                HashMap map4 = mapArr[i15];
                                ByteOrder byteOrder3 = this.f26384f;
                                ByteBuffer byteBufferWrap3 = ByteBuffer.wrap(new byte[iArr[12] * length3]);
                                byteBufferWrap3.order(byteOrder3);
                                for (int i28 = i14; i28 < length3; i28++) {
                                    byteBufferWrap3.putDouble(dArr[i28]);
                                }
                                map4.put(str3, new c(12, length3, byteBufferWrap3.array()));
                                break;
                        }
                    } else {
                        int i29 = dVar.f26365d;
                        if (i29 != -1 && (i29 == ((Integer) pairM.first).intValue() || i29 == ((Integer) pairM.second).intValue())) {
                            i17 = i29;
                        } else if (i17 != i13 && i17 != 7 && i17 != i12) {
                            if (f26370r) {
                                String[] strArr = L;
                                String str4 = strArr[i17];
                                if (i29 != -1) {
                                    new StringBuilder(", ").append(strArr[i29]);
                                }
                                String str5 = strArr[((Integer) pairM.first).intValue()];
                                if (((Integer) pairM.second).intValue() != -1) {
                                    new StringBuilder(", ").append(strArr[((Integer) pairM.second).intValue()]);
                                }
                            }
                        }
                        int[] iArr4 = M;
                        switch (i17) {
                        }
                    }
                }
                int i30 = i14;
                i10 = i13;
                i11 = i30;
            } else {
                int i302 = i14;
                i10 = i13;
                i11 = i302;
            }
            i15++;
            i12 = 2;
            int i31 = i10;
            i14 = i11;
            i13 = i31;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:100:0x01b3  */
    /* JADX WARN: Removed duplicated region for block: B:104:0x01cd  */
    /* JADX WARN: Removed duplicated region for block: B:17:0x007b  */
    /* JADX WARN: Removed duplicated region for block: B:97:0x019e  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void t(f fVar, int i10) throws IOException {
        boolean z10;
        HashMap[] mapArr;
        boolean z11;
        boolean z12;
        short s10;
        short s11;
        HashSet hashSet;
        boolean z13;
        long j10;
        int i11;
        long j11;
        long j12;
        HashSet hashSet2;
        int unsignedShort;
        long j13;
        Integer numValueOf = Integer.valueOf(fVar.f26356c);
        HashSet hashSet3 = this.f26383e;
        hashSet3.add(numValueOf);
        short s12 = fVar.readShort();
        if (s12 <= 0) {
            return;
        }
        short s13 = 0;
        while (true) {
            z10 = f26370r;
            mapArr = this.f26382d;
            if (s13 >= s12) {
                break;
            }
            int unsignedShort2 = fVar.readUnsignedShort();
            int unsignedShort3 = fVar.readUnsignedShort();
            int i12 = fVar.readInt();
            long j14 = ((long) fVar.f26356c) + 4;
            d dVar = (d) R[i10].get(Integer.valueOf(unsignedShort2));
            if (z10) {
                Object[] objArr = new Object[5];
                z12 = false;
                objArr[0] = Integer.valueOf(i10);
                z11 = true;
                objArr[1] = Integer.valueOf(unsignedShort2);
                objArr[2] = dVar != null ? dVar.f26363b : null;
                objArr[3] = Integer.valueOf(unsignedShort3);
                objArr[4] = Integer.valueOf(i12);
                String.format("ifdType: %d, tagNumber: %d, tagName: %s, dataFormat: %d, numberOfComponents: %d", objArr);
            } else {
                z11 = true;
                z12 = false;
            }
            if (dVar != null && unsignedShort3 > 0) {
                int[] iArr = M;
                if (unsignedShort3 >= iArr.length) {
                    s10 = s12;
                    hashSet = hashSet3;
                    s11 = s13;
                } else {
                    int i13 = dVar.f26364c;
                    s10 = s12;
                    if (i13 == 7 || unsignedShort3 == 7 || i13 == unsignedShort3 || (i11 = dVar.f26365d) == unsignedShort3) {
                        s11 = s13;
                    } else {
                        s11 = s13;
                        if (((i13 != 4 && i11 != 4) || unsignedShort3 != 3) && (((i13 != 9 && i11 != 9) || unsignedShort3 != 8) && ((i13 != 12 && i11 != 12) || unsignedShort3 != 11))) {
                            if (z10) {
                                String str = L[unsignedShort3];
                            }
                            hashSet = hashSet3;
                        }
                    }
                    HashSet hashSet4 = hashSet3;
                    if (unsignedShort3 == 7) {
                        unsignedShort3 = i13;
                    }
                    hashSet = hashSet4;
                    z13 = z10;
                    j10 = ((long) i12) * ((long) iArr[unsignedShort3]);
                    if (j10 < 0 || j10 > 2147483647L) {
                        z11 = z12;
                    }
                }
                z13 = z10;
                z11 = z12;
                j10 = 0;
            }
            if (z11) {
                if (j10 > 4) {
                    int i14 = fVar.readInt();
                    j11 = j10;
                    if (this.f26381c != 7) {
                        j12 = j14;
                        fVar.g(i14);
                    } else {
                        if ("MakerNote".equals(dVar.f26363b)) {
                            this.f26393o = i14;
                        } else {
                            if (i10 == 6 && "ThumbnailImage".equals(dVar.f26363b)) {
                                this.f26394p = i14;
                                this.f26395q = i12;
                                c cVarE = c.e(6, this.f26384f);
                                j12 = j14;
                                c cVarB = c.b(this.f26394p, this.f26384f);
                                c cVarB2 = c.b(this.f26395q, this.f26384f);
                                mapArr[4].put("Compression", cVarE);
                                mapArr[4].put("JPEGInterchangeFormat", cVarB);
                                mapArr[4].put("JPEGInterchangeFormatLength", cVarB2);
                            }
                            fVar.g(i14);
                        }
                        j12 = j14;
                        fVar.g(i14);
                    }
                } else {
                    j11 = j10;
                    j12 = j14;
                }
                Integer num = (Integer) U.get(Integer.valueOf(unsignedShort2));
                if (num != null) {
                    if (unsignedShort3 != 3) {
                        if (unsignedShort3 == 4) {
                            j13 = ((long) fVar.readInt()) & 4294967295L;
                        } else if (unsignedShort3 == 8) {
                            unsignedShort = fVar.readShort();
                        } else if (unsignedShort3 == 9 || unsignedShort3 == 13) {
                            unsignedShort = fVar.readInt();
                        } else {
                            j13 = -1;
                        }
                        if (z13) {
                            String.format("Offset: %d, tagName: %s", Long.valueOf(j13), dVar.f26363b);
                        }
                        if (j13 <= 0) {
                            hashSet2 = hashSet;
                            if (!hashSet2.contains(Integer.valueOf((int) j13))) {
                                fVar.g(j13);
                                t(fVar, num.intValue());
                            }
                        } else {
                            hashSet2 = hashSet;
                        }
                        fVar.g(j12);
                    } else {
                        unsignedShort = fVar.readUnsignedShort();
                    }
                    j13 = unsignedShort;
                    if (z13) {
                    }
                    if (j13 <= 0) {
                    }
                    fVar.g(j12);
                } else {
                    hashSet2 = hashSet;
                    long j15 = j12;
                    int i15 = fVar.f26356c + this.f26392n;
                    byte[] bArr = new byte[(int) j11];
                    fVar.readFully(bArr);
                    c cVar = new c(i15, bArr, unsignedShort3, i12);
                    mapArr[i10].put(dVar.f26363b, cVar);
                    String str2 = dVar.f26363b;
                    if ("DNGVersion".equals(str2)) {
                        this.f26381c = 3;
                    }
                    if ((("Make".equals(str2) || "Model".equals(str2)) && cVar.i(this.f26384f).contains("PENTAX")) || ("Compression".equals(str2) && cVar.h(this.f26384f) == 65535)) {
                        this.f26381c = 8;
                    }
                    if (fVar.f26356c != j15) {
                        fVar.g(j15);
                    }
                }
            } else {
                fVar.g(j14);
                hashSet2 = hashSet;
            }
            s13 = (short) (s11 + 1);
            hashSet3 = hashSet2;
            s12 = s10;
        }
        HashSet hashSet5 = hashSet3;
        int i16 = fVar.readInt();
        if (z10) {
            String.format("nextIfdOffset: %d", Integer.valueOf(i16));
        }
        long j16 = i16;
        if (j16 <= 0 || hashSet5.contains(Integer.valueOf(i16))) {
            return;
        }
        fVar.g(j16);
        if (mapArr[4].isEmpty()) {
            t(fVar, 4);
        } else if (mapArr[5].isEmpty()) {
            t(fVar, 5);
        }
    }

    public final void u(int i10, String str, String str2) {
        HashMap[] mapArr = this.f26382d;
        if (mapArr[i10].isEmpty() || mapArr[i10].get(str) == null) {
            return;
        }
        HashMap map = mapArr[i10];
        map.put(str2, map.get(str));
        mapArr[i10].remove(str);
    }

    public final void v(b bVar) throws Throwable {
        c cVar;
        HashMap map = this.f26382d[4];
        c cVar2 = (c) map.get("Compression");
        if (cVar2 == null) {
            this.f26391m = 6;
            n(bVar, map);
            return;
        }
        int iH = cVar2.h(this.f26384f);
        this.f26391m = iH;
        if (iH != 1) {
            if (iH == 6) {
                n(bVar, map);
                return;
            } else if (iH != 7) {
                return;
            }
        }
        c cVar3 = (c) map.get("BitsPerSample");
        if (cVar3 != null) {
            int[] iArr = (int[]) cVar3.j(this.f26384f);
            int[] iArr2 = f26373u;
            if (!Arrays.equals(iArr2, iArr)) {
                if (this.f26381c != 3 || (cVar = (c) map.get("PhotometricInterpretation")) == null) {
                    return;
                }
                int iH2 = cVar.h(this.f26384f);
                if ((iH2 != 1 || !Arrays.equals(iArr, f26374v)) && (iH2 != 6 || !Arrays.equals(iArr, iArr2))) {
                    return;
                }
            }
            c cVar4 = (c) map.get("StripOffsets");
            c cVar5 = (c) map.get("StripByteCounts");
            if (cVar4 == null || cVar5 == null) {
                return;
            }
            long[] jArrN = ua.b.n(cVar4.j(this.f26384f));
            long[] jArrN2 = ua.b.n(cVar5.j(this.f26384f));
            if (jArrN == null || jArrN.length == 0 || jArrN2 == null || jArrN2.length == 0 || jArrN.length != jArrN2.length) {
                return;
            }
            long j10 = 0;
            for (long j11 : jArrN2) {
                j10 += j11;
            }
            int i10 = (int) j10;
            byte[] bArr = new byte[i10];
            this.f26387i = true;
            this.f26386h = true;
            this.f26385g = true;
            int i11 = 0;
            int i12 = 0;
            for (int i13 = 0; i13 < jArrN.length; i13++) {
                int i14 = (int) jArrN[i13];
                int i15 = (int) jArrN2[i13];
                if (i13 < jArrN.length - 1 && i14 + i15 != jArrN[i13 + 1]) {
                    this.f26387i = false;
                }
                int i16 = i14 - i11;
                if (i16 < 0) {
                    return;
                }
                long j12 = i16;
                if (bVar.skip(j12) != j12) {
                    return;
                }
                int i17 = i11 + i16;
                byte[] bArr2 = new byte[i15];
                if (bVar.read(bArr2) != i15) {
                    return;
                }
                i11 = i17 + i15;
                System.arraycopy(bArr2, 0, bArr, i12, i15);
                i12 += i15;
            }
            this.f26390l = bArr;
            if (this.f26387i) {
                this.f26388j = (int) jArrN[0];
                this.f26389k = i10;
            }
        }
    }

    public final void w(int i10, int i11) throws Throwable {
        HashMap[] mapArr = this.f26382d;
        if (mapArr[i10].isEmpty() || mapArr[i11].isEmpty()) {
            return;
        }
        c cVar = (c) mapArr[i10].get("ImageLength");
        c cVar2 = (c) mapArr[i10].get("ImageWidth");
        c cVar3 = (c) mapArr[i11].get("ImageLength");
        c cVar4 = (c) mapArr[i11].get("ImageWidth");
        if (cVar == null || cVar2 == null || cVar3 == null || cVar4 == null) {
            return;
        }
        int iH = cVar.h(this.f26384f);
        int iH2 = cVar2.h(this.f26384f);
        int iH3 = cVar3.h(this.f26384f);
        int iH4 = cVar4.h(this.f26384f);
        if (iH >= iH3 || iH2 >= iH4) {
            return;
        }
        HashMap map = mapArr[i10];
        mapArr[i10] = mapArr[i11];
        mapArr[i11] = map;
    }

    public final void x(f fVar, int i10) throws Throwable {
        c cVarE;
        c cVarE2;
        HashMap[] mapArr = this.f26382d;
        c cVar = (c) mapArr[i10].get("DefaultCropSize");
        c cVar2 = (c) mapArr[i10].get("SensorTopBorder");
        c cVar3 = (c) mapArr[i10].get("SensorLeftBorder");
        c cVar4 = (c) mapArr[i10].get("SensorBottomBorder");
        c cVar5 = (c) mapArr[i10].get("SensorRightBorder");
        if (cVar != null) {
            if (cVar.f26358a == 5) {
                e[] eVarArr = (e[]) cVar.j(this.f26384f);
                if (eVarArr == null || eVarArr.length != 2) {
                    Arrays.toString(eVarArr);
                    return;
                }
                cVarE = c.d(new e[]{eVarArr[0]}, this.f26384f);
                cVarE2 = c.d(new e[]{eVarArr[1]}, this.f26384f);
            } else {
                int[] iArr = (int[]) cVar.j(this.f26384f);
                if (iArr == null || iArr.length != 2) {
                    Arrays.toString(iArr);
                    return;
                } else {
                    cVarE = c.e(iArr[0], this.f26384f);
                    cVarE2 = c.e(iArr[1], this.f26384f);
                }
            }
            mapArr[i10].put("ImageWidth", cVarE);
            mapArr[i10].put("ImageLength", cVarE2);
            return;
        }
        if (cVar2 != null && cVar3 != null && cVar4 != null && cVar5 != null) {
            int iH = cVar2.h(this.f26384f);
            int iH2 = cVar4.h(this.f26384f);
            int iH3 = cVar5.h(this.f26384f);
            int iH4 = cVar3.h(this.f26384f);
            if (iH2 <= iH || iH3 <= iH4) {
                return;
            }
            c cVarE3 = c.e(iH2 - iH, this.f26384f);
            c cVarE4 = c.e(iH3 - iH4, this.f26384f);
            mapArr[i10].put("ImageLength", cVarE3);
            mapArr[i10].put("ImageWidth", cVarE4);
            return;
        }
        c cVar6 = (c) mapArr[i10].get("ImageLength");
        c cVar7 = (c) mapArr[i10].get("ImageWidth");
        if (cVar6 == null || cVar7 == null) {
            c cVar8 = (c) mapArr[i10].get("JPEGInterchangeFormat");
            c cVar9 = (c) mapArr[i10].get("JPEGInterchangeFormatLength");
            if (cVar8 == null || cVar9 == null) {
                return;
            }
            int iH5 = cVar8.h(this.f26384f);
            int iH6 = cVar8.h(this.f26384f);
            fVar.g(iH5);
            byte[] bArr = new byte[iH6];
            fVar.read(bArr);
            e(new b(bArr), iH5, i10);
        }
    }

    public final void y() throws Throwable {
        w(0, 5);
        w(0, 4);
        w(5, 4);
        HashMap[] mapArr = this.f26382d;
        c cVar = (c) mapArr[1].get("PixelXDimension");
        c cVar2 = (c) mapArr[1].get("PixelYDimension");
        if (cVar != null && cVar2 != null) {
            mapArr[0].put("ImageWidth", cVar);
            mapArr[0].put("ImageLength", cVar2);
        }
        if (mapArr[4].isEmpty() && o(mapArr[5])) {
            mapArr[4] = mapArr[5];
            mapArr[5] = new HashMap();
        }
        o(mapArr[4]);
        u(0, "ThumbnailOrientation", "Orientation");
        u(0, "ThumbnailImageLength", "ImageLength");
        u(0, "ThumbnailImageWidth", "ImageWidth");
        u(5, "ThumbnailOrientation", "Orientation");
        u(5, "ThumbnailImageLength", "ImageLength");
        u(5, "ThumbnailImageWidth", "ImageWidth");
        u(4, "Orientation", "ThumbnailOrientation");
        u(4, "ImageLength", "ThumbnailImageLength");
        u(4, "ImageWidth", "ThumbnailImageWidth");
    }
}
