package o;

import android.media.MediaMetadataRetriever;
import android.os.Build;
import android.util.Log;
import java.io.BufferedInputStream;
import java.io.EOFException;
import java.io.FileDescriptor;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.TimeZone;
import java.util.regex.Pattern;
import java.util.zip.CRC32;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.jx, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C1627jx {
    public static final String[] A;
    public static final int[] B;
    public static final byte[] C;
    public static final C1342gx D;
    public static final C1342gx[][] E;
    public static final C1342gx[] F;
    public static final HashMap[] G;
    public static final HashMap[] H;
    public static final HashSet I;
    public static final HashMap J;
    public static final Charset K;
    public static final byte[] L;
    public static final byte[] M;
    public static final boolean k = Log.isLoggable("ExifInterface", 3);
    public static final int[] l;
    public static final int[] m;
    public static final byte[] n;

    /* renamed from: o, reason: collision with root package name */
    public static final byte[] f603o;
    public static final byte[] p;
    public static final byte[] q;
    public static final byte[] r;
    public static final byte[] s;
    public static final byte[] t;
    public static final byte[] u;
    public static final byte[] v;
    public static final byte[] w;
    public static final byte[] x;
    public static final byte[] y;
    public static final byte[] z;
    public final FileDescriptor a;
    public int b;
    public final HashMap[] c;
    public final HashSet d;
    public ByteOrder e;
    public boolean f;
    public int g;
    public int h;
    public int i;
    public int j;

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

    public C1627jx(C1722kx c1722kx) throws Throwable {
        C1342gx[][] c1342gxArr = E;
        this.c = new HashMap[c1342gxArr.length];
        this.d = new HashSet(c1342gxArr.length);
        this.e = ByteOrder.BIG_ENDIAN;
        this.a = null;
        boolean z2 = k;
        for (int i = 0; i < c1342gxArr.length; i++) {
            try {
                this.c[i] = new HashMap();
            } catch (IOException | UnsupportedOperationException unused) {
                a();
                if (!z2) {
                    return;
                }
            } catch (Throwable th) {
                a();
                if (z2) {
                    p();
                }
                throw th;
            }
        }
        BufferedInputStream bufferedInputStream = new BufferedInputStream(c1722kx, 5000);
        int iF = f(bufferedInputStream);
        this.b = iF;
        if (iF == 4 || iF == 9 || iF == 13 || iF == 14) {
            C1150ex c1150ex = new C1150ex(bufferedInputStream);
            int i2 = this.b;
            if (i2 == 4) {
                e(c1150ex, 0, 0);
            } else if (i2 == 13) {
                h(c1150ex);
            } else if (i2 == 9) {
                i(c1150ex);
            } else if (i2 == 14) {
                l(c1150ex);
            }
        } else {
            C1532ix c1532ix = new C1532ix(bufferedInputStream);
            int i3 = this.b;
            if (i3 == 12) {
                d(c1532ix);
            } else if (i3 == 7) {
                g(c1532ix);
            } else if (i3 == 10) {
                k(c1532ix);
            } else {
                j(c1532ix);
            }
            c1532ix.c(this.g);
            u(c1532ix);
        }
        a();
        if (!z2) {
            return;
        }
        p();
    }

    public static ByteOrder q(C1150ex c1150ex) throws IOException {
        short s2 = c1150ex.readShort();
        if (s2 == 18761) {
            return ByteOrder.LITTLE_ENDIAN;
        }
        if (s2 == 19789) {
            return ByteOrder.BIG_ENDIAN;
        }
        throw new IOException("Invalid byte order: " + Integer.toHexString(s2));
    }

    public final void a() {
        String strB = b("DateTimeOriginal");
        HashMap[] mapArr = this.c;
        if (strB != null && b("DateTime") == null) {
            HashMap map = mapArr[0];
            byte[] bytes = strB.concat("\u0000").getBytes(K);
            map.put("DateTime", new C1246fx(bytes, 2, bytes.length));
        }
        if (b("ImageWidth") == null) {
            mapArr[0].put("ImageWidth", C1246fx.a(0L, this.e));
        }
        if (b("ImageLength") == null) {
            mapArr[0].put("ImageLength", C1246fx.a(0L, this.e));
        }
        if (b("Orientation") == null) {
            mapArr[0].put("Orientation", C1246fx.a(0L, this.e));
        }
        if (b("LightSource") == null) {
            mapArr[1].put("LightSource", C1246fx.a(0L, this.e));
        }
    }

    public final String b(String str) {
        C1246fx c1246fxC = c(str);
        if (c1246fxC != null) {
            if (!I.contains(str)) {
                return c1246fxC.f(this.e);
            }
            if (str.equals("GPSTimeStamp")) {
                int i = c1246fxC.a;
                if (i == 5 || i == 10) {
                    C1438hx[] c1438hxArr = (C1438hx[]) c1246fxC.g(this.e);
                    if (c1438hxArr == null || c1438hxArr.length != 3) {
                        Arrays.toString(c1438hxArr);
                        return null;
                    }
                    C1438hx c1438hx = c1438hxArr[0];
                    Integer numValueOf = Integer.valueOf((int) (c1438hx.a / c1438hx.b));
                    C1438hx c1438hx2 = c1438hxArr[1];
                    Integer numValueOf2 = Integer.valueOf((int) (c1438hx2.a / c1438hx2.b));
                    C1438hx c1438hx3 = c1438hxArr[2];
                    return String.format("%02d:%02d:%02d", numValueOf, numValueOf2, Integer.valueOf((int) (c1438hx3.a / c1438hx3.b)));
                }
            } else {
                try {
                    return Double.toString(c1246fxC.d(this.e));
                } catch (NumberFormatException unused) {
                }
            }
        }
        return null;
    }

    public final C1246fx c(String str) {
        if ("ISOSpeedRatings".equals(str)) {
            str = "PhotographicSensitivity";
        }
        for (int i = 0; i < E.length; i++) {
            C1246fx c1246fx = (C1246fx) this.c[i].get(str);
            if (c1246fx != null) {
                return c1246fx;
            }
        }
        return null;
    }

    public final void d(C1532ix c1532ix) 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 {
                AbstractC1912mx.a(mediaMetadataRetriever, new C1054dx(c1532ix));
                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.c;
                if (strExtractMetadata != null) {
                    mapArr[0].put("ImageWidth", C1246fx.c(Integer.parseInt(strExtractMetadata), this.e));
                }
                if (strExtractMetadata2 != null) {
                    mapArr[0].put("ImageLength", C1246fx.c(Integer.parseInt(strExtractMetadata2), this.e));
                }
                if (strExtractMetadata3 != null) {
                    int i = Integer.parseInt(strExtractMetadata3);
                    mapArr[0].put("Orientation", C1246fx.c(i != 90 ? i != 180 ? i != 270 ? 1 : 8 : 3 : 6, this.e));
                }
                if (strExtractMetadata4 != null && strExtractMetadata5 != null) {
                    int i2 = Integer.parseInt(strExtractMetadata4);
                    int i3 = Integer.parseInt(strExtractMetadata5);
                    if (i3 <= 6) {
                        throw new IOException("Invalid exif length");
                    }
                    c1532ix.c(i2);
                    byte[] bArr = new byte[6];
                    if (c1532ix.read(bArr) != 6) {
                        throw new IOException("Can't read identifier");
                    }
                    int i4 = i2 + 6;
                    int i5 = i3 - 6;
                    if (!Arrays.equals(bArr, L)) {
                        throw new IOException("Invalid identifier");
                    }
                    byte[] bArr2 = new byte[i5];
                    if (c1532ix.read(bArr2) != i5) {
                        throw new IOException("Can't read exif");
                    }
                    this.g = i4;
                    r(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: Code restructure failed: missing block: B:87:0x015f, code lost:
    
        r23.m = r22.e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:88:0x0163, code lost:
    
        return;
     */
    /* JADX WARN: Removed duplicated region for block: B:100:0x0153 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:103:0x0108 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:34:0x006b A[FALL_THROUGH] */
    /* JADX WARN: Removed duplicated region for block: B:71:0x00fe  */
    /* JADX WARN: Removed duplicated region for block: B:82:0x014c A[LOOP:0: B:10:0x0024->B:82:0x014c, LOOP_END] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void e(o.C1150ex r23, int r24, int r25) throws java.lang.Throwable {
        /*
            Method dump skipped, instructions count: 472
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C1627jx.e(o.ex, int, int):void");
    }

    /* JADX WARN: Removed duplicated region for block: B:102:0x0126 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:104:0x0129  */
    /* JADX WARN: Removed duplicated region for block: B:146:0x00f2 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:66:0x00d5  */
    /* JADX WARN: Removed duplicated region for block: B:80:0x00f0 A[RETURN] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final int f(java.io.BufferedInputStream r18) throws java.lang.Throwable {
        /*
            Method dump skipped, instructions count: 374
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C1627jx.f(java.io.BufferedInputStream):int");
    }

    public final void g(C1532ix c1532ix) throws Throwable {
        int i;
        int i2;
        j(c1532ix);
        HashMap[] mapArr = this.c;
        C1246fx c1246fx = (C1246fx) mapArr[1].get("MakerNote");
        if (c1246fx != null) {
            C1532ix c1532ix2 = new C1532ix(c1246fx.d);
            c1532ix2.m = this.e;
            byte[] bArr = r;
            byte[] bArr2 = new byte[bArr.length];
            c1532ix2.readFully(bArr2);
            c1532ix2.c(0L);
            byte[] bArr3 = s;
            byte[] bArr4 = new byte[bArr3.length];
            c1532ix2.readFully(bArr4);
            if (Arrays.equals(bArr2, bArr)) {
                c1532ix2.c(8L);
            } else if (Arrays.equals(bArr4, bArr3)) {
                c1532ix2.c(12L);
            }
            s(c1532ix2, 6);
            C1246fx c1246fx2 = (C1246fx) mapArr[7].get("PreviewImageStart");
            C1246fx c1246fx3 = (C1246fx) mapArr[7].get("PreviewImageLength");
            if (c1246fx2 != null && c1246fx3 != null) {
                mapArr[5].put("JPEGInterchangeFormat", c1246fx2);
                mapArr[5].put("JPEGInterchangeFormatLength", c1246fx3);
            }
            C1246fx c1246fx4 = (C1246fx) mapArr[8].get("AspectFrame");
            if (c1246fx4 != null) {
                int[] iArr = (int[]) c1246fx4.g(this.e);
                if (iArr == null || iArr.length != 4) {
                    Arrays.toString(iArr);
                    return;
                }
                int i3 = iArr[2];
                int i4 = iArr[0];
                if (i3 <= i4 || (i = iArr[3]) <= (i2 = iArr[1])) {
                    return;
                }
                int i5 = (i3 - i4) + 1;
                int i6 = (i - i2) + 1;
                if (i5 < i6) {
                    int i7 = i5 + i6;
                    i6 = i7 - i6;
                    i5 = i7 - i6;
                }
                C1246fx c1246fxC = C1246fx.c(i5, this.e);
                C1246fx c1246fxC2 = C1246fx.c(i6, this.e);
                mapArr[0].put("ImageWidth", c1246fxC);
                mapArr[0].put("ImageLength", c1246fxC2);
            }
        }
    }

    public final void h(C1150ex c1150ex) throws Throwable {
        if (k) {
            Objects.toString(c1150ex);
        }
        c1150ex.m = ByteOrder.BIG_ENDIAN;
        byte[] bArr = t;
        c1150ex.b(bArr.length);
        int length = bArr.length;
        while (true) {
            try {
                int i = c1150ex.readInt();
                byte[] bArr2 = new byte[4];
                if (c1150ex.read(bArr2) != 4) {
                    throw new IOException("Encountered invalid length while parsing PNG chunktype");
                }
                int i2 = length + 8;
                if (i2 == 16 && !Arrays.equals(bArr2, v)) {
                    throw new IOException("Encountered invalid PNG file--IHDR chunk should appearas the first chunk");
                }
                if (Arrays.equals(bArr2, w)) {
                    return;
                }
                if (Arrays.equals(bArr2, u)) {
                    byte[] bArr3 = new byte[i];
                    if (c1150ex.read(bArr3) != i) {
                        throw new IOException("Failed to read given length for given PNG chunk type: " + AbstractC1692kh0.m(bArr2));
                    }
                    int i3 = c1150ex.readInt();
                    CRC32 crc32 = new CRC32();
                    crc32.update(bArr2);
                    crc32.update(bArr3);
                    if (((int) crc32.getValue()) == i3) {
                        this.g = i2;
                        r(0, bArr3);
                        x();
                        u(new C1150ex(bArr3));
                        return;
                    }
                    throw new IOException("Encountered invalid CRC value for PNG-EXIF chunk.\n recorded CRC value: " + i3 + ", calculated CRC value: " + crc32.getValue());
                }
                int i4 = i + 4;
                c1150ex.b(i4);
                length = i2 + i4;
            } catch (EOFException unused) {
                throw new IOException("Encountered corrupt PNG file.");
            }
        }
    }

    public final void i(C1150ex c1150ex) throws Throwable {
        if (k) {
            Objects.toString(c1150ex);
        }
        c1150ex.b(84);
        byte[] bArr = new byte[4];
        byte[] bArr2 = new byte[4];
        byte[] bArr3 = new byte[4];
        c1150ex.read(bArr);
        c1150ex.read(bArr2);
        c1150ex.read(bArr3);
        int i = ByteBuffer.wrap(bArr).getInt();
        int i2 = ByteBuffer.wrap(bArr2).getInt();
        int i3 = ByteBuffer.wrap(bArr3).getInt();
        byte[] bArr4 = new byte[i2];
        c1150ex.b(i - c1150ex.n);
        c1150ex.read(bArr4);
        e(new C1150ex(bArr4), i, 5);
        c1150ex.b(i3 - c1150ex.n);
        c1150ex.m = ByteOrder.BIG_ENDIAN;
        int i4 = c1150ex.readInt();
        for (int i5 = 0; i5 < i4; i5++) {
            int unsignedShort = c1150ex.readUnsignedShort();
            int unsignedShort2 = c1150ex.readUnsignedShort();
            if (unsignedShort == D.a) {
                short s2 = c1150ex.readShort();
                short s3 = c1150ex.readShort();
                C1246fx c1246fxC = C1246fx.c(s2, this.e);
                C1246fx c1246fxC2 = C1246fx.c(s3, this.e);
                HashMap[] mapArr = this.c;
                mapArr[0].put("ImageLength", c1246fxC);
                mapArr[0].put("ImageWidth", c1246fxC2);
                return;
            }
            c1150ex.b(unsignedShort2);
        }
    }

    public final void j(C1532ix c1532ix) throws Throwable {
        o(c1532ix);
        s(c1532ix, 0);
        w(c1532ix, 0);
        w(c1532ix, 5);
        w(c1532ix, 4);
        x();
        if (this.b == 8) {
            HashMap[] mapArr = this.c;
            C1246fx c1246fx = (C1246fx) mapArr[1].get("MakerNote");
            if (c1246fx != null) {
                C1532ix c1532ix2 = new C1532ix(c1246fx.d);
                c1532ix2.m = this.e;
                c1532ix2.b(6);
                s(c1532ix2, 9);
                C1246fx c1246fx2 = (C1246fx) mapArr[9].get("ColorSpace");
                if (c1246fx2 != null) {
                    mapArr[1].put("ColorSpace", c1246fx2);
                }
            }
        }
    }

    public final void k(C1532ix c1532ix) throws Throwable {
        if (k) {
            Objects.toString(c1532ix);
        }
        j(c1532ix);
        HashMap[] mapArr = this.c;
        C1246fx c1246fx = (C1246fx) mapArr[0].get("JpgFromRaw");
        if (c1246fx != null) {
            e(new C1150ex(c1246fx.d), (int) c1246fx.c, 5);
        }
        C1246fx c1246fx2 = (C1246fx) mapArr[0].get("ISO");
        C1246fx c1246fx3 = (C1246fx) mapArr[1].get("PhotographicSensitivity");
        if (c1246fx2 == null || c1246fx3 != null) {
            return;
        }
        mapArr[1].put("PhotographicSensitivity", c1246fx2);
    }

    public final void l(C1150ex c1150ex) throws Throwable {
        if (k) {
            Objects.toString(c1150ex);
        }
        c1150ex.m = ByteOrder.LITTLE_ENDIAN;
        c1150ex.b(x.length);
        int i = c1150ex.readInt() + 8;
        byte[] bArr = y;
        c1150ex.b(bArr.length);
        int length = bArr.length + 8;
        while (true) {
            try {
                byte[] bArr2 = new byte[4];
                if (c1150ex.read(bArr2) != 4) {
                    throw new IOException("Encountered invalid length while parsing WebP chunktype");
                }
                int i2 = c1150ex.readInt();
                int i3 = length + 8;
                if (Arrays.equals(z, bArr2)) {
                    byte[] bArr3 = new byte[i2];
                    if (c1150ex.read(bArr3) == i2) {
                        this.g = i3;
                        r(0, bArr3);
                        u(new C1150ex(bArr3));
                        return;
                    } else {
                        throw new IOException("Failed to read given length for given PNG chunk type: " + AbstractC1692kh0.m(bArr2));
                    }
                }
                if (i2 % 2 == 1) {
                    i2++;
                }
                length = i3 + i2;
                if (length == i) {
                    return;
                }
                if (length > i) {
                    throw new IOException("Encountered WebP file with invalid chunk size");
                }
                c1150ex.b(i2);
            } catch (EOFException unused) {
                throw new IOException("Encountered corrupt WebP file.");
            }
        }
    }

    public final void m(C1150ex c1150ex, HashMap map) throws Throwable {
        C1246fx c1246fx = (C1246fx) map.get("JPEGInterchangeFormat");
        C1246fx c1246fx2 = (C1246fx) map.get("JPEGInterchangeFormatLength");
        if (c1246fx == null || c1246fx2 == null) {
            return;
        }
        int iE = c1246fx.e(this.e);
        int iE2 = c1246fx2.e(this.e);
        if (this.b == 7) {
            iE += this.h;
        }
        if (iE <= 0 || iE2 <= 0 || this.a != null) {
            return;
        }
        c1150ex.skip(iE);
        c1150ex.read(new byte[iE2]);
    }

    public final boolean n(HashMap map) {
        C1246fx c1246fx = (C1246fx) map.get("ImageLength");
        C1246fx c1246fx2 = (C1246fx) map.get("ImageWidth");
        if (c1246fx == null || c1246fx2 == null) {
            return false;
        }
        return c1246fx.e(this.e) <= 512 && c1246fx2.e(this.e) <= 512;
    }

    public final void o(C1532ix c1532ix) throws IOException {
        ByteOrder byteOrderQ = q(c1532ix);
        this.e = byteOrderQ;
        c1532ix.m = byteOrderQ;
        int unsignedShort = c1532ix.readUnsignedShort();
        int i = this.b;
        if (i != 7 && i != 10 && unsignedShort != 42) {
            throw new IOException("Invalid start code: " + Integer.toHexString(unsignedShort));
        }
        int i2 = c1532ix.readInt();
        if (i2 < 8) {
            throw new IOException(AbstractC0126Ew.j(i2, "Invalid first Ifd offset: "));
        }
        int i3 = i2 - 8;
        if (i3 > 0) {
            c1532ix.b(i3);
        }
    }

    public final void p() throws Throwable {
        int i = 0;
        while (true) {
            HashMap[] mapArr = this.c;
            if (i >= mapArr.length) {
                return;
            }
            mapArr[i].size();
            for (Map.Entry entry : mapArr[i].entrySet()) {
                C1246fx c1246fx = (C1246fx) entry.getValue();
                c1246fx.toString();
                c1246fx.f(this.e);
            }
            i++;
        }
    }

    public final void r(int i, byte[] bArr) throws IOException {
        C1532ix c1532ix = new C1532ix(bArr);
        o(c1532ix);
        s(c1532ix, i);
    }

    /* JADX WARN: Removed duplicated region for block: B:100:0x019c  */
    /* JADX WARN: Removed duplicated region for block: B:19:0x0077  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void s(o.C1532ix r27, int r28) throws java.io.IOException {
        /*
            Method dump skipped, instructions count: 638
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C1627jx.s(o.ix, int):void");
    }

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

    public final void u(C1150ex c1150ex) throws Throwable {
        C1246fx c1246fx;
        HashMap map = this.c[4];
        C1246fx c1246fx2 = (C1246fx) map.get("Compression");
        if (c1246fx2 == null) {
            m(c1150ex, map);
            return;
        }
        int iE = c1246fx2.e(this.e);
        if (iE != 1) {
            if (iE == 6) {
                m(c1150ex, map);
                return;
            } else if (iE != 7) {
                return;
            }
        }
        C1246fx c1246fx3 = (C1246fx) map.get("BitsPerSample");
        if (c1246fx3 != null) {
            int[] iArr = (int[]) c1246fx3.g(this.e);
            int[] iArr2 = l;
            if (!Arrays.equals(iArr2, iArr)) {
                if (this.b != 3 || (c1246fx = (C1246fx) map.get("PhotometricInterpretation")) == null) {
                    return;
                }
                int iE2 = c1246fx.e(this.e);
                if ((iE2 != 1 || !Arrays.equals(iArr, m)) && (iE2 != 6 || !Arrays.equals(iArr, iArr2))) {
                    return;
                }
            }
            C1246fx c1246fx4 = (C1246fx) map.get("StripOffsets");
            C1246fx c1246fx5 = (C1246fx) map.get("StripByteCounts");
            if (c1246fx4 == null || c1246fx5 == null) {
                return;
            }
            long[] jArrP = AbstractC1692kh0.p(c1246fx4.g(this.e));
            long[] jArrP2 = AbstractC1692kh0.p(c1246fx5.g(this.e));
            if (jArrP == null || jArrP.length == 0 || jArrP2 == null || jArrP2.length == 0 || jArrP.length != jArrP2.length) {
                return;
            }
            long j = 0;
            for (long j2 : jArrP2) {
                j += j2;
            }
            byte[] bArr = new byte[(int) j];
            this.f = true;
            int i = 0;
            int i2 = 0;
            for (int i3 = 0; i3 < jArrP.length; i3++) {
                int i4 = (int) jArrP[i3];
                int i5 = (int) jArrP2[i3];
                if (i3 < jArrP.length - 1 && i4 + i5 != jArrP[i3 + 1]) {
                    this.f = false;
                }
                int i6 = i4 - i;
                if (i6 < 0) {
                    return;
                }
                long j3 = i6;
                if (c1150ex.skip(j3) != j3) {
                    return;
                }
                int i7 = i + i6;
                byte[] bArr2 = new byte[i5];
                if (c1150ex.read(bArr2) != i5) {
                    return;
                }
                i = i7 + i5;
                System.arraycopy(bArr2, 0, bArr, i2, i5);
                i2 += i5;
            }
            if (this.f) {
                long j4 = jArrP[0];
            }
        }
    }

    public final void v(int i, int i2) throws Throwable {
        HashMap[] mapArr = this.c;
        if (mapArr[i].isEmpty() || mapArr[i2].isEmpty()) {
            return;
        }
        C1246fx c1246fx = (C1246fx) mapArr[i].get("ImageLength");
        C1246fx c1246fx2 = (C1246fx) mapArr[i].get("ImageWidth");
        C1246fx c1246fx3 = (C1246fx) mapArr[i2].get("ImageLength");
        C1246fx c1246fx4 = (C1246fx) mapArr[i2].get("ImageWidth");
        if (c1246fx == null || c1246fx2 == null || c1246fx3 == null || c1246fx4 == null) {
            return;
        }
        int iE = c1246fx.e(this.e);
        int iE2 = c1246fx2.e(this.e);
        int iE3 = c1246fx3.e(this.e);
        int iE4 = c1246fx4.e(this.e);
        if (iE >= iE3 || iE2 >= iE4) {
            return;
        }
        HashMap map = mapArr[i];
        mapArr[i] = mapArr[i2];
        mapArr[i2] = map;
    }

    public final void w(C1532ix c1532ix, int i) throws Throwable {
        C1246fx c1246fxC;
        C1246fx c1246fxC2;
        HashMap[] mapArr = this.c;
        C1246fx c1246fx = (C1246fx) mapArr[i].get("DefaultCropSize");
        C1246fx c1246fx2 = (C1246fx) mapArr[i].get("SensorTopBorder");
        C1246fx c1246fx3 = (C1246fx) mapArr[i].get("SensorLeftBorder");
        C1246fx c1246fx4 = (C1246fx) mapArr[i].get("SensorBottomBorder");
        C1246fx c1246fx5 = (C1246fx) mapArr[i].get("SensorRightBorder");
        if (c1246fx != null) {
            if (c1246fx.a == 5) {
                C1438hx[] c1438hxArr = (C1438hx[]) c1246fx.g(this.e);
                if (c1438hxArr == null || c1438hxArr.length != 2) {
                    Arrays.toString(c1438hxArr);
                    return;
                } else {
                    c1246fxC = C1246fx.b(c1438hxArr[0], this.e);
                    c1246fxC2 = C1246fx.b(c1438hxArr[1], this.e);
                }
            } else {
                int[] iArr = (int[]) c1246fx.g(this.e);
                if (iArr == null || iArr.length != 2) {
                    Arrays.toString(iArr);
                    return;
                } else {
                    c1246fxC = C1246fx.c(iArr[0], this.e);
                    c1246fxC2 = C1246fx.c(iArr[1], this.e);
                }
            }
            mapArr[i].put("ImageWidth", c1246fxC);
            mapArr[i].put("ImageLength", c1246fxC2);
            return;
        }
        if (c1246fx2 != null && c1246fx3 != null && c1246fx4 != null && c1246fx5 != null) {
            int iE = c1246fx2.e(this.e);
            int iE2 = c1246fx4.e(this.e);
            int iE3 = c1246fx5.e(this.e);
            int iE4 = c1246fx3.e(this.e);
            if (iE2 <= iE || iE3 <= iE4) {
                return;
            }
            C1246fx c1246fxC3 = C1246fx.c(iE2 - iE, this.e);
            C1246fx c1246fxC4 = C1246fx.c(iE3 - iE4, this.e);
            mapArr[i].put("ImageLength", c1246fxC3);
            mapArr[i].put("ImageWidth", c1246fxC4);
            return;
        }
        C1246fx c1246fx6 = (C1246fx) mapArr[i].get("ImageLength");
        C1246fx c1246fx7 = (C1246fx) mapArr[i].get("ImageWidth");
        if (c1246fx6 == null || c1246fx7 == null) {
            C1246fx c1246fx8 = (C1246fx) mapArr[i].get("JPEGInterchangeFormat");
            C1246fx c1246fx9 = (C1246fx) mapArr[i].get("JPEGInterchangeFormatLength");
            if (c1246fx8 == null || c1246fx9 == null) {
                return;
            }
            int iE5 = c1246fx8.e(this.e);
            int iE6 = c1246fx8.e(this.e);
            c1532ix.c(iE5);
            byte[] bArr = new byte[iE6];
            c1532ix.read(bArr);
            e(new C1150ex(bArr), iE5, i);
        }
    }

    public final void x() throws Throwable {
        v(0, 5);
        v(0, 4);
        v(5, 4);
        HashMap[] mapArr = this.c;
        C1246fx c1246fx = (C1246fx) mapArr[1].get("PixelXDimension");
        C1246fx c1246fx2 = (C1246fx) mapArr[1].get("PixelYDimension");
        if (c1246fx != null && c1246fx2 != null) {
            mapArr[0].put("ImageWidth", c1246fx);
            mapArr[0].put("ImageLength", c1246fx2);
        }
        if (mapArr[4].isEmpty() && n(mapArr[5])) {
            mapArr[4] = mapArr[5];
            mapArr[5] = new HashMap();
        }
        n(mapArr[4]);
        t(0, "ThumbnailOrientation", "Orientation");
        t(0, "ThumbnailImageLength", "ImageLength");
        t(0, "ThumbnailImageWidth", "ImageWidth");
        t(5, "ThumbnailOrientation", "Orientation");
        t(5, "ThumbnailImageLength", "ImageLength");
        t(5, "ThumbnailImageWidth", "ImageWidth");
        t(4, "Orientation", "ThumbnailOrientation");
        t(4, "ImageLength", "ThumbnailImageLength");
        t(4, "ImageWidth", "ThumbnailImageWidth");
    }
}
