package defpackage;

import android.content.res.AssetManager;
import android.media.MediaMetadataRetriever;
import android.system.OsConstants;
import android.util.Log;
import androidx.credentials.exceptions.publickeycredential.DomExceptionUtils;
import androidx.media3.extractor.ts.TsExtractor;
import defpackage.es2;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
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.List;
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;

/* JADX INFO: loaded from: classes.dex */
public class cs2 {
    public static final String[] ad;
    public static final int[] ae;
    public static final byte[] af;
    public static final e ag;
    public static final e[][] ah;
    public static final e[] ai;
    public static final HashMap[] aj;
    public static final HashMap[] ak;
    public static final HashSet al;
    public static final HashMap am;
    public static final Charset an;
    public static final byte[] ao;
    public static final byte[] ap;
    public final FileDescriptor a;
    public final AssetManager.AssetInputStream b;
    public int c;
    public final HashMap[] d;
    public final HashSet e;
    public ByteOrder f;
    public boolean g;
    public int h;
    public int i;
    public int j;
    public int k;
    public static final boolean l = Log.isLoggable("ExifInterface", 3);
    public static final List m = Arrays.asList(1, 6, 3, 8);
    public static final List n = Arrays.asList(2, 7, 4, 5);
    public static final int[] o = {8, 8, 8};
    public static final int[] p = {8};
    public static final byte[] q = {-1, -40, -1};
    public static final byte[] r = {102, 116, 121, 112};
    public static final byte[] s = {109, 105, 102, 49};
    public static final byte[] t = {104, 101, 105, 99};
    public static final byte[] u = {79, 76, 89, 77, 80, 0};
    public static final byte[] v = {79, 76, 89, 77, 80, 85, 83, 0, 73, 73};
    public static final byte[] w = {-119, 80, 78, 71, 13, 10, 26, 10};
    public static final byte[] x = {101, 88, 73, 102};
    public static final byte[] y = {73, 72, 68, 82};
    public static final byte[] z = {73, 69, 78, 68};
    public static final byte[] aa = {82, 73, 70, 70};
    public static final byte[] ab = {87, 69, 66, 80};
    public static final byte[] ac = {69, 88, 73, 70};

    public static class a extends InputStream implements DataInput {
        public static final ByteOrder e = ByteOrder.LITTLE_ENDIAN;
        public static final ByteOrder f = ByteOrder.BIG_ENDIAN;
        public final DataInputStream a;
        public ByteOrder b;
        public int c;
        public byte[] d;

        public a(byte[] bArr) {
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bArr);
            ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
            this(byteArrayInputStream, 0);
        }

        public final void a(int i) throws IOException {
            int i2 = 0;
            while (i2 < i) {
                int i3 = i - i2;
                DataInputStream dataInputStream = this.a;
                int iSkip = (int) dataInputStream.skip(i3);
                if (iSkip <= 0) {
                    if (this.d == null) {
                        this.d = new byte[8192];
                    }
                    iSkip = dataInputStream.read(this.d, 0, Math.min(8192, i3));
                    if (iSkip == -1) {
                        throw new EOFException(n41.i(i, "Reached EOF while skipping ", " bytes."));
                    }
                }
                i2 += iSkip;
            }
            this.c += i2;
        }

        @Override // java.io.InputStream
        public final int available() {
            return this.a.available();
        }

        @Override // java.io.InputStream
        public final void mark(int i) {
            throw new UnsupportedOperationException("Mark is currently unsupported");
        }

        @Override // java.io.InputStream
        public final int read() {
            this.c++;
            return this.a.read();
        }

        @Override // java.io.DataInput
        public final boolean readBoolean() {
            this.c++;
            return this.a.readBoolean();
        }

        @Override // java.io.DataInput
        public final byte readByte() throws IOException {
            this.c++;
            int i = this.a.read();
            if (i >= 0) {
                return (byte) i;
            }
            throw new EOFException();
        }

        @Override // java.io.DataInput
        public final char readChar() {
            this.c += 2;
            return this.a.readChar();
        }

        @Override // java.io.DataInput
        public final double readDouble() {
            return Double.longBitsToDouble(readLong());
        }

        @Override // java.io.DataInput
        public final float readFloat() {
            return Float.intBitsToFloat(readInt());
        }

        @Override // java.io.DataInput
        public final void readFully(byte[] bArr, int i, int i2) throws IOException {
            this.c += i2;
            this.a.readFully(bArr, i, i2);
        }

        @Override // java.io.DataInput
        public final int readInt() throws IOException {
            this.c += 4;
            DataInputStream dataInputStream = this.a;
            int i = dataInputStream.read();
            int i2 = dataInputStream.read();
            int i3 = dataInputStream.read();
            int i4 = dataInputStream.read();
            if ((i | i2 | i3 | i4) < 0) {
                throw new EOFException();
            }
            ByteOrder byteOrder = this.b;
            if (byteOrder == e) {
                return (i4 << 24) + (i3 << 16) + (i2 << 8) + i;
            }
            if (byteOrder == f) {
                return (i << 24) + (i2 << 16) + (i3 << 8) + i4;
            }
            throw new IOException("Invalid byte order: " + this.b);
        }

        @Override // java.io.DataInput
        public final String readLine() {
            return null;
        }

        @Override // java.io.DataInput
        public final long readLong() throws IOException {
            long j;
            long j2;
            this.c += 8;
            DataInputStream dataInputStream = this.a;
            int i = dataInputStream.read();
            int i2 = dataInputStream.read();
            int i3 = dataInputStream.read();
            int i4 = dataInputStream.read();
            int i5 = dataInputStream.read();
            int i6 = dataInputStream.read();
            int i7 = dataInputStream.read();
            int i8 = dataInputStream.read();
            if ((i | i2 | i3 | i4 | i5 | i6 | i7 | i8) < 0) {
                throw new EOFException();
            }
            ByteOrder byteOrder = this.b;
            if (byteOrder == e) {
                j = (((long) i8) << 56) + (((long) i7) << 48) + (((long) i6) << 40) + (((long) i5) << 32) + (((long) i4) << 24) + (((long) i3) << 16) + (((long) i2) << 8);
                j2 = i;
            } else {
                if (byteOrder != f) {
                    throw new IOException("Invalid byte order: " + this.b);
                }
                j = (((long) i) << 56) + (((long) i2) << 48) + (((long) i3) << 40) + (((long) i4) << 32) + (((long) i5) << 24) + (((long) i6) << 16) + (((long) i7) << 8);
                j2 = i8;
            }
            return j + j2;
        }

        @Override // java.io.DataInput
        public final short readShort() throws IOException {
            this.c += 2;
            DataInputStream dataInputStream = this.a;
            int i = dataInputStream.read();
            int i2 = dataInputStream.read();
            if ((i | i2) < 0) {
                throw new EOFException();
            }
            ByteOrder byteOrder = this.b;
            if (byteOrder == e) {
                return (short) ((i2 << 8) + i);
            }
            if (byteOrder == f) {
                return (short) ((i << 8) + i2);
            }
            throw new IOException("Invalid byte order: " + this.b);
        }

        @Override // java.io.DataInput
        public final String readUTF() {
            this.c += 2;
            return this.a.readUTF();
        }

        @Override // java.io.DataInput
        public final int readUnsignedByte() {
            this.c++;
            return this.a.readUnsignedByte();
        }

        @Override // java.io.DataInput
        public final int readUnsignedShort() throws IOException {
            this.c += 2;
            DataInputStream dataInputStream = this.a;
            int i = dataInputStream.read();
            int i2 = dataInputStream.read();
            if ((i | i2) < 0) {
                throw new EOFException();
            }
            ByteOrder byteOrder = this.b;
            if (byteOrder == e) {
                return (i2 << 8) + i;
            }
            if (byteOrder == f) {
                return (i << 8) + i2;
            }
            throw new IOException("Invalid byte order: " + this.b);
        }

        @Override // java.io.InputStream
        public final void reset() {
            throw new UnsupportedOperationException("Reset is currently unsupported");
        }

        @Override // java.io.DataInput
        public final int skipBytes(int i) {
            throw new UnsupportedOperationException("skipBytes is currently unsupported");
        }

        /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
        public a(InputStream inputStream) {
            this(inputStream, 0);
            ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
        }

        public a(InputStream inputStream, int i) {
            ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
            this.b = byteOrder;
            DataInputStream dataInputStream = new DataInputStream(inputStream);
            this.a = dataInputStream;
            dataInputStream.mark(0);
            this.c = 0;
            this.b = byteOrder;
        }

        @Override // java.io.InputStream
        public final int read(byte[] bArr, int i, int i2) {
            int i3 = this.a.read(bArr, i, i2);
            this.c += i3;
            return i3;
        }

        @Override // java.io.DataInput
        public final void readFully(byte[] bArr) throws IOException {
            this.c += bArr.length;
            this.a.readFully(bArr);
        }
    }

    public static class b extends FilterOutputStream {
        @Override // java.io.FilterOutputStream, java.io.OutputStream
        public final void write(byte[] bArr) {
            throw null;
        }

        @Override // java.io.FilterOutputStream, java.io.OutputStream
        public final void write(byte[] bArr, int i, int i2) {
            throw null;
        }
    }

    public static class c {
        public final int a;
        public final int b;
        public final long c;
        public final byte[] d;

        public c(byte[] bArr, int i, int i2) {
            this(-1L, bArr, i, i2);
        }

        public static c a(long j, ByteOrder byteOrder) {
            long[] jArr = {j};
            ByteBuffer byteBufferWrap = ByteBuffer.wrap(new byte[cs2.ae[4]]);
            byteBufferWrap.order(byteOrder);
            byteBufferWrap.putInt((int) jArr[0]);
            return new c(byteBufferWrap.array(), 4, 1);
        }

        public static c b(g gVar, ByteOrder byteOrder) {
            ByteBuffer byteBufferWrap = ByteBuffer.wrap(new byte[cs2.ae[5]]);
            byteBufferWrap.order(byteOrder);
            g gVar2 = new g[]{gVar}[0];
            byteBufferWrap.putInt((int) gVar2.a);
            byteBufferWrap.putInt((int) gVar2.b);
            return new c(byteBufferWrap.array(), 5, 1);
        }

        public static c c(int i, ByteOrder byteOrder) {
            ByteBuffer byteBufferWrap = ByteBuffer.wrap(new byte[cs2.ae[3]]);
            byteBufferWrap.order(byteOrder);
            byteBufferWrap.putShort((short) new int[]{i}[0]);
            return new c(byteBufferWrap.array(), 3, 1);
        }

        public final double d(ByteOrder byteOrder) throws Throwable {
            Object objG = g(byteOrder);
            if (objG == null) {
                throw new NumberFormatException("NULL can't be converted to a double value");
            }
            if (objG instanceof String) {
                return Double.parseDouble((String) objG);
            }
            if (objG instanceof long[]) {
                if (((long[]) objG).length == 1) {
                    return r5[0];
                }
                throw new NumberFormatException("There are more than one component");
            }
            if (objG instanceof int[]) {
                if (((int[]) objG).length == 1) {
                    return r5[0];
                }
                throw new NumberFormatException("There are more than one component");
            }
            if (objG instanceof double[]) {
                double[] dArr = (double[]) objG;
                if (dArr.length == 1) {
                    return dArr[0];
                }
                throw new NumberFormatException("There are more than one component");
            }
            if (!(objG instanceof g[])) {
                throw new NumberFormatException("Couldn't find a double value");
            }
            g[] gVarArr = (g[]) objG;
            if (gVarArr.length != 1) {
                throw new NumberFormatException("There are more than one component");
            }
            g gVar = gVarArr[0];
            return gVar.a / gVar.b;
        }

        public final int e(ByteOrder byteOrder) throws Throwable {
            Object objG = g(byteOrder);
            if (objG == null) {
                throw new NumberFormatException("NULL can't be converted to a integer value");
            }
            if (objG instanceof String) {
                return Integer.parseInt((String) objG);
            }
            if (objG instanceof long[]) {
                long[] jArr = (long[]) objG;
                if (jArr.length == 1) {
                    return (int) jArr[0];
                }
                throw new NumberFormatException("There are more than one component");
            }
            if (!(objG instanceof int[])) {
                throw new NumberFormatException("Couldn't find a integer value");
            }
            int[] iArr = (int[]) objG;
            if (iArr.length == 1) {
                return iArr[0];
            }
            throw new NumberFormatException("There are more than one component");
        }

        public final String f(ByteOrder byteOrder) throws Throwable {
            Object objG = g(byteOrder);
            if (objG == null) {
                return null;
            }
            if (objG instanceof String) {
                return (String) objG;
            }
            StringBuilder sb = new StringBuilder();
            int i = 0;
            if (objG instanceof long[]) {
                long[] jArr = (long[]) objG;
                while (i < jArr.length) {
                    sb.append(jArr[i]);
                    i++;
                    if (i != jArr.length) {
                        sb.append(",");
                    }
                }
                return sb.toString();
            }
            if (objG instanceof int[]) {
                int[] iArr = (int[]) objG;
                while (i < iArr.length) {
                    sb.append(iArr[i]);
                    i++;
                    if (i != iArr.length) {
                        sb.append(",");
                    }
                }
                return sb.toString();
            }
            if (objG instanceof double[]) {
                double[] dArr = (double[]) objG;
                while (i < dArr.length) {
                    sb.append(dArr[i]);
                    i++;
                    if (i != dArr.length) {
                        sb.append(",");
                    }
                }
                return sb.toString();
            }
            if (!(objG instanceof g[])) {
                return null;
            }
            g[] gVarArr = (g[]) objG;
            while (i < gVarArr.length) {
                sb.append(gVarArr[i].a);
                sb.append('/');
                sb.append(gVarArr[i].b);
                i++;
                if (i != gVarArr.length) {
                    sb.append(",");
                }
            }
            return sb.toString();
        }

        /* JADX WARN: Multi-variable type inference failed */
        /* JADX WARN: Not initialized variable reg: 4, insn: 0x0032: MOVE (r3 I:??[OBJECT, ARRAY]) = (r4 I:??[OBJECT, ARRAY]), block:B:17:0x0032 */
        /* JADX WARN: Removed duplicated region for block: B:103:0x012e A[EXC_TOP_SPLITTER, SYNTHETIC] */
        /* JADX WARN: Type inference failed for: r14v11, types: [java.lang.String] */
        /* JADX WARN: Type inference failed for: r14v19, types: [java.lang.String] */
        /* JADX WARN: Type inference failed for: r14v23, types: [int[]] */
        /* JADX WARN: Type inference failed for: r14v24, types: [long[]] */
        /* JADX WARN: Type inference failed for: r14v25, types: [cs2$g[]] */
        /* JADX WARN: Type inference failed for: r14v26, types: [int[]] */
        /* JADX WARN: Type inference failed for: r14v27, types: [int[]] */
        /* JADX WARN: Type inference failed for: r14v28, types: [cs2$g[]] */
        /* JADX WARN: Type inference failed for: r14v29, types: [double[]] */
        /* JADX WARN: Type inference failed for: r14v30, types: [java.io.Serializable] */
        /* JADX WARN: Type inference failed for: r14v31, types: [double[]] */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final Serializable g(ByteOrder byteOrder) throws Throwable {
            a aVar;
            InputStream inputStream;
            ?? str;
            byte b;
            byte[] bArr = this.d;
            InputStream inputStream2 = null;
            try {
                try {
                    aVar = new a(bArr);
                    try {
                        aVar.b = byteOrder;
                        int i = this.a;
                        int length = 0;
                        int i2 = this.b;
                        switch (i) {
                            case 1:
                            case 6:
                                if (bArr.length == 1 && (b = bArr[0]) >= 0 && b <= 1) {
                                    String str2 = new String(new char[]{(char) (b + 48)});
                                    try {
                                        aVar.close();
                                        return str2;
                                    } catch (IOException e) {
                                        Log.e("ExifInterface", "IOException occurred while closing InputStream", e);
                                        return str2;
                                    }
                                }
                                str = new String(bArr, cs2.an);
                                break;
                                break;
                            case 2:
                            case 7:
                                if (i2 >= cs2.af.length) {
                                    int i3 = 0;
                                    while (true) {
                                        byte[] bArr2 = cs2.af;
                                        if (i3 >= bArr2.length) {
                                            length = bArr2.length;
                                        } else if (bArr[i3] == bArr2[i3]) {
                                            i3++;
                                        }
                                    }
                                }
                                StringBuilder sb = new StringBuilder();
                                while (length < i2) {
                                    byte b2 = bArr[length];
                                    if (b2 == 0) {
                                        str = sb.toString();
                                    } else {
                                        if (b2 >= 32) {
                                            sb.append((char) b2);
                                        } else {
                                            sb.append('?');
                                        }
                                        length++;
                                    }
                                    break;
                                }
                                str = sb.toString();
                                break;
                            case 3:
                                str = new int[i2];
                                while (length < i2) {
                                    str[length] = aVar.readUnsignedShort();
                                    length++;
                                }
                                break;
                            case 4:
                                str = new long[i2];
                                while (length < i2) {
                                    str[length] = ((long) aVar.readInt()) & 4294967295L;
                                    length++;
                                }
                                break;
                            case 5:
                                str = new g[i2];
                                while (length < i2) {
                                    str[length] = new g(((long) aVar.readInt()) & 4294967295L, ((long) aVar.readInt()) & 4294967295L);
                                    length++;
                                }
                                break;
                            case 8:
                                str = new int[i2];
                                while (length < i2) {
                                    str[length] = aVar.readShort();
                                    length++;
                                }
                                break;
                            case 9:
                                str = new int[i2];
                                while (length < i2) {
                                    str[length] = aVar.readInt();
                                    length++;
                                }
                                break;
                            case 10:
                                str = new g[i2];
                                while (length < i2) {
                                    str[length] = new g(aVar.readInt(), aVar.readInt());
                                    length++;
                                }
                                break;
                            case 11:
                                str = new double[i2];
                                while (length < i2) {
                                    str[length] = aVar.readFloat();
                                    length++;
                                }
                                break;
                            case 12:
                                str = new double[i2];
                                while (length < i2) {
                                    str[length] = aVar.readDouble();
                                    length++;
                                }
                                break;
                            default:
                                try {
                                    aVar.close();
                                    return null;
                                } catch (IOException e2) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e2);
                                    return null;
                                }
                        }
                        try {
                            aVar.close();
                            return str;
                        } catch (IOException e3) {
                            Log.e("ExifInterface", "IOException occurred while closing InputStream", e3);
                            return str;
                        }
                    } catch (IOException e4) {
                        e = e4;
                        Log.w("ExifInterface", "IOException occurred during reading a value", e);
                        if (aVar != null) {
                            try {
                                aVar.close();
                            } catch (IOException e5) {
                                Log.e("ExifInterface", "IOException occurred while closing InputStream", e5);
                            }
                        }
                        return null;
                    }
                } catch (Throwable th) {
                    th = th;
                    inputStream2 = inputStream;
                    if (inputStream2 != null) {
                        try {
                            inputStream2.close();
                        } catch (IOException e6) {
                            Log.e("ExifInterface", "IOException occurred while closing InputStream", e6);
                        }
                    }
                    throw th;
                }
            } catch (IOException e7) {
                e = e7;
                aVar = null;
            } catch (Throwable th2) {
                th = th2;
                if (inputStream2 != null) {
                }
                throw th;
            }
        }

        public final String toString() {
            StringBuilder sb = new StringBuilder("(");
            sb.append(cs2.ad[this.a]);
            sb.append(", data length:");
            return n41.q(sb, this.d.length, ")");
        }

        public c(long j, byte[] bArr, int i, int i2) {
            this.a = i;
            this.b = i2;
            this.c = j;
            this.d = bArr;
        }
    }

    @m38
    @Retention(RetentionPolicy.SOURCE)
    public @interface d {
    }

    @m38
    @Retention(RetentionPolicy.SOURCE)
    public @interface f {
    }

    public static class g {
        public final long a;
        public final long b;

        public g(long j, long j2) {
            if (j2 == 0) {
                this.a = 0L;
                this.b = 1L;
            } else {
                this.a = j;
                this.b = j2;
            }
        }

        public final String toString() {
            return this.a + DomExceptionUtils.SEPARATOR + this.b;
        }
    }

    static {
        "VP8X".getBytes(Charset.defaultCharset());
        "VP8L".getBytes(Charset.defaultCharset());
        "VP8 ".getBytes(Charset.defaultCharset());
        "ANIM".getBytes(Charset.defaultCharset());
        "ANMF".getBytes(Charset.defaultCharset());
        ad = new String[]{"", "BYTE", "STRING", "USHORT", "ULONG", "URATIONAL", "SBYTE", "UNDEFINED", "SSHORT", "SLONG", "SRATIONAL", "SINGLE", "DOUBLE", "IFD"};
        ae = new int[]{0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 1};
        af = new byte[]{65, 83, 67, 73, 73, 0, 0, 0};
        e[] eVarArr = {new e("NewSubfileType", 254, 4), new e("SubfileType", 255, 4), new e("ImageWidth", 256, 3, 4), new e("ImageLength", TsExtractor.TS_STREAM_TYPE_AIT, 3, 4), new e("BitsPerSample", 258, 3), new e("Compression", 259, 3), new e("PhotometricInterpretation", 262, 3), new e("ImageDescription", 270, 2), new e("Make", 271, 2), new e("Model", 272, 2), new e("StripOffsets", 273, 3, 4), new e("Orientation", 274, 3), new e("SamplesPerPixel", 277, 3), new e("RowsPerStrip", 278, 3, 4), new e("StripByteCounts", 279, 3, 4), new e("XResolution", 282, 5), new e("YResolution", 283, 5), new e("PlanarConfiguration", 284, 3), new e("ResolutionUnit", 296, 3), new e("TransferFunction", 301, 3), new e("Software", 305, 2), new e("DateTime", 306, 2), new e("Artist", 315, 2), new e("WhitePoint", 318, 5), new e("PrimaryChromaticities", 319, 5), new e("SubIFDPointer", 330, 4), new e("JPEGInterchangeFormat", 513, 4), new e("JPEGInterchangeFormatLength", 514, 4), new e("YCbCrCoefficients", 529, 5), new e("YCbCrSubSampling", 530, 3), new e("YCbCrPositioning", 531, 3), new e("ReferenceBlackWhite", 532, 5), new e("Copyright", 33432, 2), new e("ExifIFDPointer", 34665, 4), new e("GPSInfoIFDPointer", 34853, 4), new e("SensorTopBorder", 4, 4), new e("SensorLeftBorder", 5, 4), new e("SensorBottomBorder", 6, 4), new e("SensorRightBorder", 7, 4), new e("ISO", 23, 3), new e("JpgFromRaw", 46, 7), new e("Xmp", 700, 1)};
        e[] eVarArr2 = {new e("ExposureTime", 33434, 5), new e("FNumber", 33437, 5), new e("ExposureProgram", 34850, 3), new e("SpectralSensitivity", 34852, 2), new e("PhotographicSensitivity", 34855, 3), new e("OECF", 34856, 7), new e("SensitivityType", 34864, 3), new e("StandardOutputSensitivity", 34865, 4), new e("RecommendedExposureIndex", 34866, 4), new e("ISOSpeed", 34867, 4), new e("ISOSpeedLatitudeyyy", 34868, 4), new e("ISOSpeedLatitudezzz", 34869, 4), new e("ExifVersion", 36864, 2), new e("DateTimeOriginal", 36867, 2), new e("DateTimeDigitized", 36868, 2), new e("OffsetTime", 36880, 2), new e("OffsetTimeOriginal", 36881, 2), new e("OffsetTimeDigitized", 36882, 2), new e("ComponentsConfiguration", 37121, 7), new e("CompressedBitsPerPixel", 37122, 5), new e("ShutterSpeedValue", 37377, 10), new e("ApertureValue", 37378, 5), new e("BrightnessValue", 37379, 10), new e("ExposureBiasValue", 37380, 10), new e("MaxApertureValue", 37381, 5), new e("SubjectDistance", 37382, 5), new e("MeteringMode", 37383, 3), new e("LightSource", 37384, 3), new e("Flash", 37385, 3), new e("FocalLength", 37386, 5), new e("SubjectArea", 37396, 3), new e("MakerNote", 37500, 7), new e("UserComment", 37510, 7), new e("SubSecTime", 37520, 2), new e("SubSecTimeOriginal", 37521, 2), new e("SubSecTimeDigitized", 37522, 2), new e("FlashpixVersion", 40960, 7), new e("ColorSpace", 40961, 3), new e("PixelXDimension", 40962, 3, 4), new e("PixelYDimension", 40963, 3, 4), new e("RelatedSoundFile", 40964, 2), new e("InteroperabilityIFDPointer", 40965, 4), new e("FlashEnergy", 41483, 5), new e("SpatialFrequencyResponse", 41484, 7), new e("FocalPlaneXResolution", 41486, 5), new e("FocalPlaneYResolution", 41487, 5), new e("FocalPlaneResolutionUnit", 41488, 3), new e("SubjectLocation", 41492, 3), new e("ExposureIndex", 41493, 5), new e("SensingMethod", 41495, 3), new e("FileSource", 41728, 7), new e("SceneType", 41729, 7), new e("CFAPattern", 41730, 7), new e("CustomRendered", 41985, 3), new e("ExposureMode", 41986, 3), new e("WhiteBalance", 41987, 3), new e("DigitalZoomRatio", 41988, 5), new e("FocalLengthIn35mmFilm", 41989, 3), new e("SceneCaptureType", 41990, 3), new e("GainControl", 41991, 3), new e("Contrast", 41992, 3), new e("Saturation", 41993, 3), new e("Sharpness", 41994, 3), new e("DeviceSettingDescription", 41995, 7), new e("SubjectDistanceRange", 41996, 3), new e("ImageUniqueID", 42016, 2), new e("CameraOwnerName", 42032, 2), new e("BodySerialNumber", 42033, 2), new e("LensSpecification", 42034, 5), new e("LensMake", 42035, 2), new e("LensModel", 42036, 2), new e("Gamma", 42240, 5), new e("DNGVersion", 50706, 1), new e("DefaultCropSize", 50720, 3, 4)};
        e[] eVarArr3 = {new e("GPSVersionID", 0, 1), new e("GPSLatitudeRef", 1, 2), new e("GPSLatitude", 2, 5, 10), new e("GPSLongitudeRef", 3, 2), new e("GPSLongitude", 4, 5, 10), new e("GPSAltitudeRef", 5, 1), new e("GPSAltitude", 6, 5), new e("GPSTimeStamp", 7, 5), new e("GPSSatellites", 8, 2), new e("GPSStatus", 9, 2), new e("GPSMeasureMode", 10, 2), new e("GPSDOP", 11, 5), new e("GPSSpeedRef", 12, 2), new e("GPSSpeed", 13, 5), new e("GPSTrackRef", 14, 2), new e("GPSTrack", 15, 5), new e("GPSImgDirectionRef", 16, 2), new e("GPSImgDirection", 17, 5), new e("GPSMapDatum", 18, 2), new e("GPSDestLatitudeRef", 19, 2), new e("GPSDestLatitude", 20, 5), new e("GPSDestLongitudeRef", 21, 2), new e("GPSDestLongitude", 22, 5), new e("GPSDestBearingRef", 23, 2), new e("GPSDestBearing", 24, 5), new e("GPSDestDistanceRef", 25, 2), new e("GPSDestDistance", 26, 5), new e("GPSProcessingMethod", 27, 7), new e("GPSAreaInformation", 28, 7), new e("GPSDateStamp", 29, 2), new e("GPSDifferential", 30, 3), new e("GPSHPositioningError", 31, 5)};
        e[] eVarArr4 = {new e("InteroperabilityIndex", 1, 2)};
        e[] eVarArr5 = {new e("NewSubfileType", 254, 4), new e("SubfileType", 255, 4), new e("ThumbnailImageWidth", 256, 3, 4), new e("ThumbnailImageLength", TsExtractor.TS_STREAM_TYPE_AIT, 3, 4), new e("BitsPerSample", 258, 3), new e("Compression", 259, 3), new e("PhotometricInterpretation", 262, 3), new e("ImageDescription", 270, 2), new e("Make", 271, 2), new e("Model", 272, 2), new e("StripOffsets", 273, 3, 4), new e("ThumbnailOrientation", 274, 3), new e("SamplesPerPixel", 277, 3), new e("RowsPerStrip", 278, 3, 4), new e("StripByteCounts", 279, 3, 4), new e("XResolution", 282, 5), new e("YResolution", 283, 5), new e("PlanarConfiguration", 284, 3), new e("ResolutionUnit", 296, 3), new e("TransferFunction", 301, 3), new e("Software", 305, 2), new e("DateTime", 306, 2), new e("Artist", 315, 2), new e("WhitePoint", 318, 5), new e("PrimaryChromaticities", 319, 5), new e("SubIFDPointer", 330, 4), new e("JPEGInterchangeFormat", 513, 4), new e("JPEGInterchangeFormatLength", 514, 4), new e("YCbCrCoefficients", 529, 5), new e("YCbCrSubSampling", 530, 3), new e("YCbCrPositioning", 531, 3), new e("ReferenceBlackWhite", 532, 5), new e("Copyright", 33432, 2), new e("ExifIFDPointer", 34665, 4), new e("GPSInfoIFDPointer", 34853, 4), new e("DNGVersion", 50706, 1), new e("DefaultCropSize", 50720, 3, 4)};
        ag = new e("StripOffsets", 273, 3);
        ah = new e[][]{eVarArr, eVarArr2, eVarArr3, eVarArr4, eVarArr5, eVarArr, new e[]{new e("ThumbnailImage", 256, 7), new e("CameraSettingsIFDPointer", 8224, 4), new e("ImageProcessingIFDPointer", 8256, 4)}, new e[]{new e("PreviewImageStart", TsExtractor.TS_STREAM_TYPE_AIT, 4), new e("PreviewImageLength", 258, 4)}, new e[]{new e("AspectFrame", 4371, 3)}, new e[]{new e("ColorSpace", 55, 3)}};
        ai = new e[]{new e("SubIFDPointer", 330, 4), new e("ExifIFDPointer", 34665, 4), new e("GPSInfoIFDPointer", 34853, 4), new e("InteroperabilityIFDPointer", 40965, 4), new e("CameraSettingsIFDPointer", 8224, 1), new e("ImageProcessingIFDPointer", 8256, 1)};
        aj = new HashMap[10];
        ak = new HashMap[10];
        al = new HashSet(Arrays.asList("FNumber", "DigitalZoomRatio", "ExposureTime", "SubjectDistance", "GPSTimeStamp"));
        am = new HashMap();
        Charset charsetForName = Charset.forName("US-ASCII");
        an = charsetForName;
        ao = "Exif\u0000\u0000".getBytes(charsetForName);
        ap = "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) {
            e[][] eVarArr6 = ah;
            if (i >= eVarArr6.length) {
                HashMap map = am;
                e[] eVarArr7 = ai;
                map.put(Integer.valueOf(eVarArr7[0].a), 5);
                map.put(Integer.valueOf(eVarArr7[1].a), 1);
                map.put(Integer.valueOf(eVarArr7[2].a), 2);
                map.put(Integer.valueOf(eVarArr7[3].a), 3);
                map.put(Integer.valueOf(eVarArr7[4].a), 7);
                map.put(Integer.valueOf(eVarArr7[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;
            }
            aj[i] = new HashMap();
            ak[i] = new HashMap();
            for (e eVar : eVarArr6[i]) {
                aj[i].put(Integer.valueOf(eVar.a), eVar);
                ak[i].put(eVar.b, eVar);
            }
            i++;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:51:0x00d1 A[Catch: all -> 0x0057, TRY_ENTER, TRY_LEAVE, TryCatch #1 {all -> 0x0057, blocks: (B:12:0x0048, B:14:0x004b, B:21:0x0060, B:27:0x007d, B:29:0x0088, B:37:0x009e, B:32:0x008f, B:35:0x0097, B:36:0x009b, B:38:0x00a8, B:40:0x00b1, B:42:0x00b7, B:44:0x00bd, B:46:0x00c3, B:51:0x00d1), top: B:64:0x0048 }] */
    /* JADX WARN: Removed duplicated region for block: B:67:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public cs2(InputStream inputStream) throws Throwable {
        e[][] eVarArr = ah;
        this.d = new HashMap[eVarArr.length];
        this.e = new HashSet(eVarArr.length);
        this.f = ByteOrder.BIG_ENDIAN;
        if (inputStream instanceof AssetManager.AssetInputStream) {
            this.b = (AssetManager.AssetInputStream) inputStream;
            this.a = null;
        } else if (inputStream instanceof FileInputStream) {
            FileInputStream fileInputStream = (FileInputStream) inputStream;
            try {
                es2.a.c(fileInputStream.getFD(), 0L, OsConstants.SEEK_CUR);
                this.b = null;
                this.a = fileInputStream.getFD();
            } catch (Exception unused) {
                this.b = null;
                this.a = null;
            }
        } else {
            this.b = null;
            this.a = null;
        }
        boolean z2 = l;
        for (int i = 0; i < eVarArr.length; i++) {
            try {
                try {
                    this.d[i] = new HashMap();
                } catch (Throwable th) {
                    a();
                    if (z2) {
                        q();
                    }
                    throw th;
                }
            } catch (IOException e2) {
                e = e2;
                if (z2) {
                    Log.w("ExifInterface", "Invalid image: ExifInterface got an unsupported image format file(ExifInterface supports JPEG and some RAW image formats only) or a corrupted JPEG file to ExifInterface.", e);
                }
                a();
                if (!z2) {
                    return;
                }
            } catch (UnsupportedOperationException e3) {
                e = e3;
                if (z2) {
                }
                a();
                if (!z2) {
                }
            }
        }
        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, 5000);
        int iG = g(bufferedInputStream);
        this.c = iG;
        if (iG == 4 || iG == 9 || iG == 13 || iG == 14) {
            a aVar = new a(bufferedInputStream);
            int i2 = this.c;
            if (i2 == 4) {
                f(aVar, 0, 0);
            } else if (i2 == 13) {
                i(aVar);
            } else if (i2 == 9) {
                j(aVar);
            } else if (i2 == 14) {
                m(aVar);
            }
        } else {
            h hVar = new h(bufferedInputStream);
            int i3 = this.c;
            if (i3 == 12) {
                e(hVar);
            } else if (i3 == 7) {
                h(hVar);
            } else if (i3 == 10) {
                l(hVar);
            } else {
                k(hVar);
            }
            hVar.b(this.h);
            v(hVar);
        }
        a();
        if (!z2) {
            return;
        }
        q();
    }

    public static ByteOrder r(a aVar) throws IOException {
        short s2 = aVar.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.d;
        if (strB != null && b("DateTime") == null) {
            HashMap map = mapArr[0];
            byte[] bytes = strB.concat("\u0000").getBytes(an);
            map.put("DateTime", new c(bytes, 2, bytes.length));
        }
        if (b("ImageWidth") == null) {
            mapArr[0].put("ImageWidth", c.a(0L, this.f));
        }
        if (b("ImageLength") == null) {
            mapArr[0].put("ImageLength", c.a(0L, this.f));
        }
        if (b("Orientation") == null) {
            mapArr[0].put("Orientation", c.a(0L, this.f));
        }
        if (b("LightSource") == null) {
            mapArr[1].put("LightSource", c.a(0L, this.f));
        }
    }

    public final String b(String str) {
        c cVarD = d(str);
        if (cVarD != null) {
            int i = cVarD.a;
            if (!al.contains(str)) {
                return cVarD.f(this.f);
            }
            if (str.equals("GPSTimeStamp")) {
                if (i != 5 && i != 10) {
                    n41.x(i, "GPS Timestamp format is not rational. format=", "ExifInterface");
                    return null;
                }
                g[] gVarArr = (g[]) cVarD.g(this.f);
                if (gVarArr == null || gVarArr.length != 3) {
                    Log.w("ExifInterface", "Invalid GPS Timestamp array. array=" + Arrays.toString(gVarArr));
                    return null;
                }
                g gVar = gVarArr[0];
                Integer numValueOf = Integer.valueOf((int) (gVar.a / gVar.b));
                g gVar2 = gVarArr[1];
                Integer numValueOf2 = Integer.valueOf((int) (gVar2.a / gVar2.b));
                g gVar3 = gVarArr[2];
                return String.format("%02d:%02d:%02d", numValueOf, numValueOf2, Integer.valueOf((int) (gVar3.a / gVar3.b)));
            }
            try {
                return Double.toString(cVarD.d(this.f));
            } catch (NumberFormatException unused) {
            }
        }
        return null;
    }

    public final int c() {
        c cVarD = d("Orientation");
        if (cVarD == null) {
            return 1;
        }
        try {
            return cVarD.e(this.f);
        } catch (NumberFormatException unused) {
            return 1;
        }
    }

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

    public final void e(h hVar) throws IOException {
        String strExtractMetadata;
        String strExtractMetadata2;
        String strExtractMetadata3;
        MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
        try {
            try {
                es2.b.a(mediaMetadataRetriever, new bs2(hVar));
                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.d;
                if (strExtractMetadata != null) {
                    mapArr[0].put("ImageWidth", c.c(Integer.parseInt(strExtractMetadata), this.f));
                }
                if (strExtractMetadata2 != null) {
                    mapArr[0].put("ImageLength", c.c(Integer.parseInt(strExtractMetadata2), this.f));
                }
                if (strExtractMetadata3 != null) {
                    int i = Integer.parseInt(strExtractMetadata3);
                    mapArr[0].put("Orientation", c.c(i != 90 ? i != 180 ? i != 270 ? 1 : 8 : 3 : 6, this.f));
                }
                if (strExtractMetadata4 != null && strExtractMetadata5 != null) {
                    int i2 = Integer.parseInt(strExtractMetadata4);
                    int i3 = Integer.parseInt(strExtractMetadata5);
                    if (i3 <= 6) {
                        throw new IOException("Invalid exif length");
                    }
                    hVar.b(i2);
                    byte[] bArr = new byte[6];
                    if (hVar.read(bArr) != 6) {
                        throw new IOException("Can't read identifier");
                    }
                    int i4 = i2 + 6;
                    int i5 = i3 - 6;
                    if (!Arrays.equals(bArr, ao)) {
                        throw new IOException("Invalid identifier");
                    }
                    byte[] bArr2 = new byte[i5];
                    if (hVar.read(bArr2) != i5) {
                        throw new IOException("Can't read exif");
                    }
                    this.h = i4;
                    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: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] */
    /*  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 f(cs2.a r23, int r24, int r25) throws java.lang.Throwable {
        /*
            Method dump skipped, instruction units count: 472
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.cs2.f(cs2$a, int, int):void");
    }

    /* 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.
    */
    public final int g(BufferedInputStream bufferedInputStream) throws Throwable {
        a aVar;
        a aVar2;
        a aVar3;
        a aVar4;
        boolean z2;
        a aVar5;
        a aVar6;
        boolean z3;
        boolean z4;
        boolean z5;
        a aVar7;
        long j;
        bufferedInputStream.mark(5000);
        byte[] bArr = new byte[5000];
        bufferedInputStream.read(bArr);
        bufferedInputStream.reset();
        int i = 0;
        while (true) {
            byte[] bArr2 = q;
            if (i >= bArr2.length) {
                return 4;
            }
            if (bArr[i] != bArr2[i]) {
                byte[] bytes = "FUJIFILMCCD-RAW".getBytes(Charset.defaultCharset());
                for (int i2 = 0; i2 < bytes.length; i2++) {
                    if (bArr[i2] != bytes[i2]) {
                        try {
                            aVar2 = new a(bArr);
                            try {
                                long j2 = aVar2.readInt();
                                byte[] bArr3 = new byte[4];
                                aVar2.read(bArr3);
                                if (Arrays.equals(bArr3, r)) {
                                    if (j2 == 1) {
                                        j2 = aVar2.readLong();
                                        j = 16;
                                        if (j2 < 16) {
                                        }
                                    } else {
                                        j = 8;
                                    }
                                    long j3 = 5000;
                                    if (j2 > j3) {
                                        j2 = j3;
                                    }
                                    long j4 = j2 - j;
                                    if (j4 >= 8) {
                                        byte[] bArr4 = new byte[4];
                                        boolean z6 = false;
                                        boolean z7 = false;
                                        for (long j5 = 0; j5 < j4 / 4 && aVar2.read(bArr4) == 4; j5++) {
                                            if (j5 != 1) {
                                                if (Arrays.equals(bArr4, s)) {
                                                    z6 = true;
                                                } else if (Arrays.equals(bArr4, t)) {
                                                    z7 = true;
                                                }
                                                if (z6 && z7) {
                                                    aVar2.close();
                                                    return 12;
                                                }
                                            }
                                        }
                                    }
                                }
                            } catch (Exception unused) {
                                if (aVar2 != null) {
                                }
                                aVar4 = new a(bArr);
                                ByteOrder byteOrderR = r(aVar4);
                                this.f = byteOrderR;
                                aVar4.b = byteOrderR;
                                short s2 = aVar4.readShort();
                                if (s2 != 20306) {
                                    aVar4.close();
                                }
                                if (!z2) {
                                }
                            } catch (Throwable th) {
                                th = th;
                                aVar = aVar2;
                                if (aVar != null) {
                                    aVar.close();
                                }
                                throw th;
                            }
                        } catch (Exception unused2) {
                            aVar2 = null;
                        } catch (Throwable th2) {
                            th = th2;
                            aVar = null;
                        }
                        aVar2.close();
                        try {
                            aVar4 = new a(bArr);
                        } catch (Exception unused3) {
                            aVar4 = null;
                        } catch (Throwable th3) {
                            th = th3;
                            aVar3 = null;
                        }
                        try {
                            ByteOrder byteOrderR2 = r(aVar4);
                            this.f = byteOrderR2;
                            aVar4.b = byteOrderR2;
                            short s22 = aVar4.readShort();
                            z2 = s22 != 20306 || s22 == 21330;
                            aVar4.close();
                        } catch (Exception unused4) {
                            if (aVar4 != null) {
                                aVar4.close();
                            }
                            z2 = false;
                        } catch (Throwable th4) {
                            th = th4;
                            aVar3 = aVar4;
                            if (aVar3 != null) {
                                aVar3.close();
                            }
                            throw th;
                        }
                        if (!z2) {
                            return 7;
                        }
                        try {
                            aVar7 = new a(bArr);
                        } catch (Exception unused5) {
                            aVar6 = null;
                        } catch (Throwable th5) {
                            th = th5;
                            aVar5 = null;
                        }
                        try {
                            ByteOrder byteOrderR3 = r(aVar7);
                            this.f = byteOrderR3;
                            aVar7.b = byteOrderR3;
                            z3 = aVar7.readShort() == 85;
                            aVar7.close();
                        } catch (Exception unused6) {
                            aVar6 = aVar7;
                            if (aVar6 != null) {
                                aVar6.close();
                            }
                            z3 = false;
                        } catch (Throwable th6) {
                            th = th6;
                            aVar5 = aVar7;
                            if (aVar5 != null) {
                                aVar5.close();
                            }
                            throw th;
                        }
                        if (z3) {
                            return 10;
                        }
                        int i3 = 0;
                        while (true) {
                            byte[] bArr5 = w;
                            if (i3 >= bArr5.length) {
                                z4 = true;
                                break;
                            }
                            if (bArr[i3] != bArr5[i3]) {
                                z4 = false;
                                break;
                            }
                            i3++;
                        }
                        if (z4) {
                            return 13;
                        }
                        int i4 = 0;
                        while (true) {
                            byte[] bArr6 = aa;
                            if (i4 >= bArr6.length) {
                                int i5 = 0;
                                while (true) {
                                    byte[] bArr7 = ab;
                                    if (i5 >= bArr7.length) {
                                        z5 = true;
                                        break;
                                    }
                                    if (bArr[bArr6.length + i5 + 4] != bArr7[i5]) {
                                        break;
                                    }
                                    i5++;
                                }
                            } else {
                                if (bArr[i4] != bArr6[i4]) {
                                    break;
                                }
                                i4++;
                            }
                        }
                        z5 = false;
                        return z5 ? 14 : 0;
                    }
                }
                return 9;
            }
            i++;
        }
    }

    public final void h(h hVar) throws Throwable {
        int i;
        int i2;
        k(hVar);
        HashMap[] mapArr = this.d;
        c cVar = (c) mapArr[1].get("MakerNote");
        if (cVar != null) {
            h hVar2 = new h(cVar.d);
            hVar2.b = this.f;
            byte[] bArr = u;
            byte[] bArr2 = new byte[bArr.length];
            hVar2.readFully(bArr2);
            hVar2.b(0L);
            byte[] bArr3 = v;
            byte[] bArr4 = new byte[bArr3.length];
            hVar2.readFully(bArr4);
            if (Arrays.equals(bArr2, bArr)) {
                hVar2.b(8L);
            } else if (Arrays.equals(bArr4, bArr3)) {
                hVar2.b(12L);
            }
            t(hVar2, 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.g(this.f);
                if (iArr == null || iArr.length != 4) {
                    Log.w("ExifInterface", "Invalid aspect frame values. frame=" + 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;
                }
                c cVarC = c.c(i5, this.f);
                c cVarC2 = c.c(i6, this.f);
                mapArr[0].put("ImageWidth", cVarC);
                mapArr[0].put("ImageLength", cVarC2);
            }
        }
    }

    public final void i(a aVar) throws Throwable {
        if (l) {
            Objects.toString(aVar);
        }
        aVar.b = ByteOrder.BIG_ENDIAN;
        byte[] bArr = w;
        aVar.a(bArr.length);
        int length = bArr.length;
        while (true) {
            try {
                int i = aVar.readInt();
                byte[] bArr2 = new byte[4];
                if (aVar.read(bArr2) != 4) {
                    throw new IOException("Encountered invalid length while parsing PNG chunktype");
                }
                int i2 = length + 8;
                if (i2 == 16 && !Arrays.equals(bArr2, y)) {
                    throw new IOException("Encountered invalid PNG file--IHDR chunk should appearas the first chunk");
                }
                if (Arrays.equals(bArr2, z)) {
                    return;
                }
                if (Arrays.equals(bArr2, x)) {
                    byte[] bArr3 = new byte[i];
                    if (aVar.read(bArr3) != i) {
                        throw new IOException("Failed to read given length for given PNG chunk type: " + es2.a(bArr2));
                    }
                    int i3 = aVar.readInt();
                    CRC32 crc32 = new CRC32();
                    crc32.update(bArr2);
                    crc32.update(bArr3);
                    if (((int) crc32.getValue()) == i3) {
                        this.h = i2;
                        s(0, bArr3);
                        y();
                        v(new a(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;
                aVar.a(i4);
                length = i2 + i4;
            } catch (EOFException unused) {
                throw new IOException("Encountered corrupt PNG file.");
            }
        }
    }

    public final void j(a aVar) throws Throwable {
        if (l) {
            Objects.toString(aVar);
        }
        aVar.a(84);
        byte[] bArr = new byte[4];
        byte[] bArr2 = new byte[4];
        byte[] bArr3 = new byte[4];
        aVar.read(bArr);
        aVar.read(bArr2);
        aVar.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];
        aVar.a(i - aVar.c);
        aVar.read(bArr4);
        f(new a(bArr4), i, 5);
        aVar.a(i3 - aVar.c);
        aVar.b = ByteOrder.BIG_ENDIAN;
        int i4 = aVar.readInt();
        for (int i5 = 0; i5 < i4; i5++) {
            int unsignedShort = aVar.readUnsignedShort();
            int unsignedShort2 = aVar.readUnsignedShort();
            if (unsignedShort == ag.a) {
                short s2 = aVar.readShort();
                short s3 = aVar.readShort();
                c cVarC = c.c(s2, this.f);
                c cVarC2 = c.c(s3, this.f);
                HashMap[] mapArr = this.d;
                mapArr[0].put("ImageLength", cVarC);
                mapArr[0].put("ImageWidth", cVarC2);
                return;
            }
            aVar.a(unsignedShort2);
        }
    }

    public final void k(h hVar) throws Throwable {
        p(hVar);
        t(hVar, 0);
        x(hVar, 0);
        x(hVar, 5);
        x(hVar, 4);
        y();
        if (this.c == 8) {
            HashMap[] mapArr = this.d;
            c cVar = (c) mapArr[1].get("MakerNote");
            if (cVar != null) {
                h hVar2 = new h(cVar.d);
                hVar2.b = this.f;
                hVar2.a(6);
                t(hVar2, 9);
                c cVar2 = (c) mapArr[9].get("ColorSpace");
                if (cVar2 != null) {
                    mapArr[1].put("ColorSpace", cVar2);
                }
            }
        }
    }

    public final void l(h hVar) throws Throwable {
        if (l) {
            Objects.toString(hVar);
        }
        k(hVar);
        HashMap[] mapArr = this.d;
        c cVar = (c) mapArr[0].get("JpgFromRaw");
        if (cVar != null) {
            f(new a(cVar.d), (int) cVar.c, 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 m(a aVar) throws Throwable {
        if (l) {
            Objects.toString(aVar);
        }
        aVar.b = ByteOrder.LITTLE_ENDIAN;
        aVar.a(aa.length);
        int i = aVar.readInt() + 8;
        byte[] bArr = ab;
        aVar.a(bArr.length);
        int length = bArr.length + 8;
        while (true) {
            try {
                byte[] bArr2 = new byte[4];
                if (aVar.read(bArr2) != 4) {
                    throw new IOException("Encountered invalid length while parsing WebP chunktype");
                }
                int i2 = aVar.readInt();
                int i3 = length + 8;
                if (Arrays.equals(ac, bArr2)) {
                    byte[] bArr3 = new byte[i2];
                    if (aVar.read(bArr3) == i2) {
                        this.h = i3;
                        s(0, bArr3);
                        v(new a(bArr3));
                        return;
                    } else {
                        throw new IOException("Failed to read given length for given PNG chunk type: " + es2.a(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");
                }
                aVar.a(i2);
            } catch (EOFException unused) {
                throw new IOException("Encountered corrupt WebP file.");
            }
        }
    }

    public final void n(a aVar, HashMap map) throws Throwable {
        c cVar = (c) map.get("JPEGInterchangeFormat");
        c cVar2 = (c) map.get("JPEGInterchangeFormatLength");
        if (cVar == null || cVar2 == null) {
            return;
        }
        int iE = cVar.e(this.f);
        int iE2 = cVar2.e(this.f);
        if (this.c == 7) {
            iE += this.i;
        }
        if (iE <= 0 || iE2 <= 0 || this.b != null || this.a != null) {
            return;
        }
        aVar.skip(iE);
        aVar.read(new byte[iE2]);
    }

    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.e(this.f) <= 512 && cVar2.e(this.f) <= 512;
    }

    public final void p(h hVar) throws IOException {
        ByteOrder byteOrderR = r(hVar);
        this.f = byteOrderR;
        hVar.b = byteOrderR;
        int unsignedShort = hVar.readUnsignedShort();
        int i = this.c;
        if (i != 7 && i != 10 && unsignedShort != 42) {
            throw new IOException("Invalid start code: " + Integer.toHexString(unsignedShort));
        }
        int i2 = hVar.readInt();
        if (i2 < 8) {
            throw new IOException(n41.k("Invalid first Ifd offset: ", i2));
        }
        int i3 = i2 - 8;
        if (i3 > 0) {
            hVar.a(i3);
        }
    }

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

    public final void s(int i, byte[] bArr) throws IOException {
        h hVar = new h(bArr);
        p(hVar);
        t(hVar, 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.
    */
    public final void t(h hVar, int i) throws IOException {
        boolean z2;
        HashMap[] mapArr;
        short s2;
        boolean z3;
        long j;
        HashMap[] mapArr2;
        e eVar;
        long j2;
        int i2;
        boolean z4;
        HashMap[] mapArr3;
        int i3;
        e eVar2;
        int i4;
        int unsignedShort;
        long j3;
        int i5 = i;
        Integer numValueOf = Integer.valueOf(hVar.c);
        HashSet hashSet = this.e;
        hashSet.add(numValueOf);
        short s3 = hVar.readShort();
        if (s3 <= 0) {
            return;
        }
        short s4 = 0;
        while (true) {
            z2 = l;
            mapArr = this.d;
            if (s4 >= s3) {
                break;
            }
            int unsignedShort2 = hVar.readUnsignedShort();
            int unsignedShort3 = hVar.readUnsignedShort();
            int i6 = hVar.readInt();
            short s5 = s4;
            long j4 = ((long) hVar.c) + 4;
            e eVar3 = (e) aj[i5].get(Integer.valueOf(unsignedShort2));
            if (z2) {
                j = 4;
                s2 = s3;
                z3 = z2;
                String.format("ifdType: %d, tagNumber: %d, tagName: %s, dataFormat: %d, numberOfComponents: %d", Integer.valueOf(i5), Integer.valueOf(unsignedShort2), eVar3 != null ? eVar3.b : null, Integer.valueOf(unsignedShort3), Integer.valueOf(i6));
            } else {
                s2 = s3;
                z3 = z2;
                j = 4;
            }
            if (eVar3 != null && unsignedShort3 > 0) {
                int[] iArr = ae;
                if (unsignedShort3 < iArr.length) {
                    int i7 = eVar3.c;
                    if (i7 == 7 || unsignedShort3 == 7 || i7 == unsignedShort3 || (i2 = eVar3.d) == unsignedShort3 || (((i7 == 4 || i2 == 4) && unsignedShort3 == 3) || (((i7 == 9 || i2 == 9) && unsignedShort3 == 8) || ((i7 == 12 || i2 == 12) && unsignedShort3 == 11)))) {
                        if (unsignedShort3 == 7) {
                            unsignedShort3 = i7;
                        }
                        mapArr2 = mapArr;
                        eVar = eVar3;
                        j2 = ((long) i6) * ((long) iArr[unsignedShort3]);
                        z4 = j2 >= 0 && j2 <= 2147483647L;
                    } else {
                        if (z3) {
                            String str = ad[unsignedShort3];
                        }
                        eVar = eVar3;
                        mapArr2 = mapArr;
                        j2 = 0;
                    }
                } else {
                    eVar = eVar3;
                    mapArr2 = mapArr;
                    j2 = 0;
                }
            }
            if (z4) {
                if (j2 > j) {
                    int i8 = hVar.readInt();
                    if (this.c == 7) {
                        mapArr3 = mapArr2;
                        eVar2 = eVar;
                        if ("MakerNote".equals(eVar2.b)) {
                            this.i = i8;
                        } else if (i5 == 6 && "ThumbnailImage".equals(eVar2.b)) {
                            this.j = i8;
                            this.k = i6;
                            c cVarC = c.c(6, this.f);
                            i3 = unsignedShort2;
                            c cVarA = c.a(this.j, this.f);
                            i4 = i6;
                            c cVarA2 = c.a(this.k, this.f);
                            mapArr3[4].put("Compression", cVarC);
                            mapArr3[4].put("JPEGInterchangeFormat", cVarA);
                            mapArr3[4].put("JPEGInterchangeFormatLength", cVarA2);
                            hVar.b(i8);
                        }
                        i3 = unsignedShort2;
                    } else {
                        mapArr3 = mapArr2;
                        i3 = unsignedShort2;
                        eVar2 = eVar;
                    }
                    i4 = i6;
                    hVar.b(i8);
                } else {
                    mapArr3 = mapArr2;
                    i3 = unsignedShort2;
                    eVar2 = eVar;
                    i4 = i6;
                }
                Integer num = (Integer) am.get(Integer.valueOf(i3));
                if (num != null) {
                    if (unsignedShort3 != 3) {
                        if (unsignedShort3 == 4) {
                            j3 = ((long) hVar.readInt()) & 4294967295L;
                        } else if (unsignedShort3 == 8) {
                            unsignedShort = hVar.readShort();
                        } else if (unsignedShort3 == 9 || unsignedShort3 == 13) {
                            unsignedShort = hVar.readInt();
                        } else {
                            j3 = -1;
                        }
                        if (z3) {
                            String.format("Offset: %d, tagName: %s", Long.valueOf(j3), eVar2.b);
                        }
                        if (j3 > 0 && !hashSet.contains(Integer.valueOf((int) j3))) {
                            hVar.b(j3);
                            t(hVar, num.intValue());
                        }
                        hVar.b(j4);
                    } else {
                        unsignedShort = hVar.readUnsignedShort();
                    }
                    j3 = unsignedShort;
                    if (z3) {
                    }
                    if (j3 > 0) {
                        hVar.b(j3);
                        t(hVar, num.intValue());
                    }
                    hVar.b(j4);
                } else {
                    int i9 = hVar.c + this.h;
                    byte[] bArr = new byte[(int) j2];
                    hVar.readFully(bArr);
                    c cVar = new c(i9, bArr, unsignedShort3, i4);
                    HashMap map = mapArr3[i];
                    String str2 = eVar2.b;
                    map.put(str2, cVar);
                    if ("DNGVersion".equals(str2)) {
                        this.c = 3;
                    }
                    if ((("Make".equals(str2) || "Model".equals(str2)) && cVar.f(this.f).contains("PENTAX")) || ("Compression".equals(str2) && cVar.e(this.f) == 65535)) {
                        this.c = 8;
                    }
                    if (hVar.c != j4) {
                        hVar.b(j4);
                    }
                }
            } else {
                hVar.b(j4);
            }
            s4 = (short) (s5 + 1);
            i5 = i;
            s3 = s2;
        }
        int i10 = hVar.readInt();
        if (z2) {
            String.format("nextIfdOffset: %d", Integer.valueOf(i10));
        }
        long j5 = i10;
        if (j5 <= 0 || hashSet.contains(Integer.valueOf(i10))) {
            return;
        }
        hVar.b(j5);
        if (mapArr[4].isEmpty()) {
            t(hVar, 4);
        } else if (mapArr[5].isEmpty()) {
            t(hVar, 5);
        }
    }

    public final void u(int i, String str, String str2) {
        HashMap[] mapArr = this.d;
        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 v(a aVar) throws Throwable {
        c cVar;
        HashMap map = this.d[4];
        c cVar2 = (c) map.get("Compression");
        if (cVar2 == null) {
            n(aVar, map);
            return;
        }
        int iE = cVar2.e(this.f);
        if (iE != 1) {
            if (iE == 6) {
                n(aVar, map);
                return;
            } else if (iE != 7) {
                return;
            }
        }
        c cVar3 = (c) map.get("BitsPerSample");
        if (cVar3 != null) {
            int[] iArr = (int[]) cVar3.g(this.f);
            int[] iArr2 = o;
            if (!Arrays.equals(iArr2, iArr)) {
                if (this.c != 3 || (cVar = (c) map.get("PhotometricInterpretation")) == null) {
                    return;
                }
                int iE2 = cVar.e(this.f);
                if ((iE2 != 1 || !Arrays.equals(iArr, p)) && (iE2 != 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[] jArrB = es2.b(cVar4.g(this.f));
            long[] jArrB2 = es2.b(cVar5.g(this.f));
            if (jArrB == null || jArrB.length == 0) {
                Log.w("ExifInterface", "stripOffsets should not be null or have zero length.");
                return;
            }
            if (jArrB2 == null || jArrB2.length == 0) {
                Log.w("ExifInterface", "stripByteCounts should not be null or have zero length.");
                return;
            }
            if (jArrB.length != jArrB2.length) {
                Log.w("ExifInterface", "stripOffsets and stripByteCounts should have same length.");
                return;
            }
            long j = 0;
            for (long j2 : jArrB2) {
                j += j2;
            }
            byte[] bArr = new byte[(int) j];
            this.g = true;
            int i = 0;
            int i2 = 0;
            for (int i3 = 0; i3 < jArrB.length; i3++) {
                int i4 = (int) jArrB[i3];
                int i5 = (int) jArrB2[i3];
                if (i3 < jArrB.length - 1 && i4 + i5 != jArrB[i3 + 1]) {
                    this.g = false;
                }
                int i6 = i4 - i;
                if (i6 < 0) {
                    return;
                }
                long j3 = i6;
                if (aVar.skip(j3) != j3) {
                    return;
                }
                int i7 = i + i6;
                byte[] bArr2 = new byte[i5];
                if (aVar.read(bArr2) != i5) {
                    return;
                }
                i = i7 + i5;
                System.arraycopy(bArr2, 0, bArr, i2, i5);
                i2 += i5;
            }
            if (this.g) {
                long j4 = jArrB[0];
            }
        }
    }

    public final void w(int i, int i2) throws Throwable {
        HashMap[] mapArr = this.d;
        if (mapArr[i].isEmpty() || mapArr[i2].isEmpty()) {
            return;
        }
        c cVar = (c) mapArr[i].get("ImageLength");
        c cVar2 = (c) mapArr[i].get("ImageWidth");
        c cVar3 = (c) mapArr[i2].get("ImageLength");
        c cVar4 = (c) mapArr[i2].get("ImageWidth");
        if (cVar == null || cVar2 == null || cVar3 == null || cVar4 == null) {
            return;
        }
        int iE = cVar.e(this.f);
        int iE2 = cVar2.e(this.f);
        int iE3 = cVar3.e(this.f);
        int iE4 = cVar4.e(this.f);
        if (iE >= iE3 || iE2 >= iE4) {
            return;
        }
        HashMap map = mapArr[i];
        mapArr[i] = mapArr[i2];
        mapArr[i2] = map;
    }

    public final void x(h hVar, int i) throws Throwable {
        c cVarC;
        c cVarC2;
        HashMap[] mapArr = this.d;
        c cVar = (c) mapArr[i].get("DefaultCropSize");
        c cVar2 = (c) mapArr[i].get("SensorTopBorder");
        c cVar3 = (c) mapArr[i].get("SensorLeftBorder");
        c cVar4 = (c) mapArr[i].get("SensorBottomBorder");
        c cVar5 = (c) mapArr[i].get("SensorRightBorder");
        if (cVar != null) {
            if (cVar.a == 5) {
                g[] gVarArr = (g[]) cVar.g(this.f);
                if (gVarArr == null || gVarArr.length != 2) {
                    Log.w("ExifInterface", "Invalid crop size values. cropSize=" + Arrays.toString(gVarArr));
                    return;
                }
                cVarC = c.b(gVarArr[0], this.f);
                cVarC2 = c.b(gVarArr[1], this.f);
            } else {
                int[] iArr = (int[]) cVar.g(this.f);
                if (iArr == null || iArr.length != 2) {
                    Log.w("ExifInterface", "Invalid crop size values. cropSize=" + Arrays.toString(iArr));
                    return;
                }
                cVarC = c.c(iArr[0], this.f);
                cVarC2 = c.c(iArr[1], this.f);
            }
            mapArr[i].put("ImageWidth", cVarC);
            mapArr[i].put("ImageLength", cVarC2);
            return;
        }
        if (cVar2 != null && cVar3 != null && cVar4 != null && cVar5 != null) {
            int iE = cVar2.e(this.f);
            int iE2 = cVar4.e(this.f);
            int iE3 = cVar5.e(this.f);
            int iE4 = cVar3.e(this.f);
            if (iE2 <= iE || iE3 <= iE4) {
                return;
            }
            c cVarC3 = c.c(iE2 - iE, this.f);
            c cVarC4 = c.c(iE3 - iE4, this.f);
            mapArr[i].put("ImageLength", cVarC3);
            mapArr[i].put("ImageWidth", cVarC4);
            return;
        }
        c cVar6 = (c) mapArr[i].get("ImageLength");
        c cVar7 = (c) mapArr[i].get("ImageWidth");
        if (cVar6 == null || cVar7 == null) {
            c cVar8 = (c) mapArr[i].get("JPEGInterchangeFormat");
            c cVar9 = (c) mapArr[i].get("JPEGInterchangeFormatLength");
            if (cVar8 == null || cVar9 == null) {
                return;
            }
            int iE5 = cVar8.e(this.f);
            int iE6 = cVar8.e(this.f);
            hVar.b(iE5);
            byte[] bArr = new byte[iE6];
            hVar.read(bArr);
            f(new a(bArr), iE5, i);
        }
    }

    public final void y() throws Throwable {
        w(0, 5);
        w(0, 4);
        w(5, 4);
        HashMap[] mapArr = this.d;
        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");
    }

    public static class h extends a {
        public h(byte[] bArr) {
            super(bArr);
            this.a.mark(Integer.MAX_VALUE);
        }

        public final void b(long j) {
            int i = this.c;
            if (i > j) {
                this.c = 0;
                this.a.reset();
            } else {
                j -= (long) i;
            }
            a((int) j);
        }

        public h(InputStream inputStream) {
            super(inputStream);
            if (inputStream.markSupported()) {
                this.a.mark(Integer.MAX_VALUE);
                return;
            }
            throw new IllegalArgumentException("Cannot create SeekableByteOrderedDataInputStream with stream that does not support mark/reset");
        }
    }

    public static class e {
        public final int a;
        public final String b;
        public final int c;
        public final int d;

        public e(String str, int i, int i2) {
            this.b = str;
            this.a = i;
            this.c = i2;
            this.d = -1;
        }

        public e(String str, int i, int i2, int i3) {
            this.b = str;
            this.a = i;
            this.c = i2;
            this.d = i3;
        }
    }
}
