package androidx.exifinterface.media;

import android.content.res.AssetManager;
import android.media.MediaDataSource;
import android.media.MediaMetadataRetriever;
import android.system.OsConstants;
import android.util.Log;
import androidx.exifinterface.media.b;
import com.fasterxml.jackson.core.JsonPointer;
import com.google.android.gms.common.api.Api;
import com.google.firebase.crashlytics.internal.metadata.UserMetadata;
import com.google.firebase.perf.util.Constants;
import com.google.firebase.sessions.settings.RemoteSettings;
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.IOException;
import java.io.InputStream;
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.Set;
import java.util.TimeZone;
import java.util.regex.Pattern;
import java.util.zip.CRC32;

/* loaded from: classes.dex */
public class a {
    private static SimpleDateFormat T;
    private static SimpleDateFormat U;
    private static final d[] Y;
    private static final d[] Z;

    /* renamed from: a0, reason: collision with root package name */
    private static final d[] f4331a0;

    /* renamed from: b0, reason: collision with root package name */
    private static final d[] f4332b0;

    /* renamed from: c0, reason: collision with root package name */
    private static final d[] f4333c0;

    /* renamed from: d0, reason: collision with root package name */
    private static final d f4334d0;

    /* renamed from: e0, reason: collision with root package name */
    private static final d[] f4335e0;

    /* renamed from: f0, reason: collision with root package name */
    private static final d[] f4336f0;

    /* renamed from: g0, reason: collision with root package name */
    private static final d[] f4337g0;

    /* renamed from: h0, reason: collision with root package name */
    private static final d[] f4338h0;

    /* renamed from: i0, reason: collision with root package name */
    static final d[][] f4339i0;

    /* renamed from: j0, reason: collision with root package name */
    private static final d[] f4340j0;

    /* renamed from: k0, reason: collision with root package name */
    private static final HashMap[] f4341k0;

    /* renamed from: l0, reason: collision with root package name */
    private static final HashMap[] f4342l0;

    /* renamed from: m0, reason: collision with root package name */
    private static final HashSet f4343m0;

    /* renamed from: n0, reason: collision with root package name */
    private static final HashMap f4344n0;

    /* renamed from: o0, reason: collision with root package name */
    static final Charset f4345o0;

    /* renamed from: p0, reason: collision with root package name */
    static final byte[] f4346p0;

    /* renamed from: q0, reason: collision with root package name */
    private static final byte[] f4347q0;

    /* renamed from: r0, reason: collision with root package name */
    private static final Pattern f4348r0;

    /* renamed from: s0, reason: collision with root package name */
    private static final Pattern f4349s0;

    /* renamed from: t0, reason: collision with root package name */
    private static final Pattern f4350t0;

    /* renamed from: u0, reason: collision with root package name */
    private static final Pattern f4352u0;

    /* renamed from: a, reason: collision with root package name */
    private String f4358a;

    /* renamed from: b, reason: collision with root package name */
    private FileDescriptor f4359b;

    /* renamed from: c, reason: collision with root package name */
    private AssetManager.AssetInputStream f4360c;

    /* renamed from: d, reason: collision with root package name */
    private int f4361d;

    /* renamed from: e, reason: collision with root package name */
    private boolean f4362e;

    /* renamed from: f, reason: collision with root package name */
    private final HashMap[] f4363f;

    /* renamed from: g, reason: collision with root package name */
    private Set f4364g;

    /* renamed from: h, reason: collision with root package name */
    private ByteOrder f4365h;

    /* renamed from: i, reason: collision with root package name */
    private boolean f4366i;

    /* renamed from: j, reason: collision with root package name */
    private boolean f4367j;

    /* renamed from: k, reason: collision with root package name */
    private boolean f4368k;

    /* renamed from: l, reason: collision with root package name */
    private int f4369l;

    /* renamed from: m, reason: collision with root package name */
    private int f4370m;

    /* renamed from: n, reason: collision with root package name */
    private byte[] f4371n;

    /* renamed from: o, reason: collision with root package name */
    private int f4372o;

    /* renamed from: p, reason: collision with root package name */
    private int f4373p;

    /* renamed from: q, reason: collision with root package name */
    private int f4374q;

    /* renamed from: r, reason: collision with root package name */
    private int f4375r;

    /* renamed from: s, reason: collision with root package name */
    private int f4376s;

    /* renamed from: t, reason: collision with root package name */
    private boolean f4377t;

    /* renamed from: u, reason: collision with root package name */
    private static final boolean f4351u = Log.isLoggable("ExifInterface", 3);

    /* renamed from: v, reason: collision with root package name */
    private static final List f4353v = Arrays.asList(1, 6, 3, 8);

    /* renamed from: w, reason: collision with root package name */
    private static final List f4354w = Arrays.asList(2, 7, 4, 5);

    /* renamed from: x, reason: collision with root package name */
    public static final int[] f4355x = {8, 8, 8};

    /* renamed from: y, reason: collision with root package name */
    public static final int[] f4356y = {4};

    /* renamed from: z, reason: collision with root package name */
    public static final int[] f4357z = {8};
    static final byte[] A = {-1, -40, -1};
    private static final byte[] B = {102, 116, 121, 112};
    private static final byte[] C = {109, 105, 102, 49};
    private static final byte[] D = {104, 101, 105, 99};
    private static final byte[] E = {79, 76, 89, 77, 80, 0};
    private static final byte[] F = {79, 76, 89, 77, 80, 85, 83, 0, 73, 73};
    private static final byte[] G = {-119, 80, 78, 71, 13, 10, 26, 10};
    private static final byte[] H = {101, 88, 73, 102};
    private static final byte[] I = {73, 72, 68, 82};
    private static final byte[] J = {73, 69, 78, 68};
    private static final byte[] K = {82, 73, 70, 70};
    private static final byte[] L = {87, 69, 66, 80};
    private static final byte[] M = {69, 88, 73, 70};
    private static final byte[] N = {-99, 1, 42};
    private static final byte[] O = "VP8X".getBytes(Charset.defaultCharset());
    private static final byte[] P = "VP8L".getBytes(Charset.defaultCharset());
    private static final byte[] Q = "VP8 ".getBytes(Charset.defaultCharset());
    private static final byte[] R = "ANIM".getBytes(Charset.defaultCharset());
    private static final byte[] S = "ANMF".getBytes(Charset.defaultCharset());
    static final String[] V = {"", "BYTE", "STRING", "USHORT", "ULONG", "URATIONAL", "SBYTE", "UNDEFINED", "SSHORT", "SLONG", "SRATIONAL", "SINGLE", "DOUBLE", "IFD"};
    static final int[] W = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 1};
    static final byte[] X = {65, 83, 67, 73, 73, 0, 0, 0};

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: androidx.exifinterface.media.a$a, reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public class C0112a extends MediaDataSource {

        /* renamed from: p, reason: collision with root package name */
        long f4378p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ f f4379q;

        C0112a(f fVar) {
            this.f4379q = fVar;
        }

        @Override // java.io.Closeable, java.lang.AutoCloseable
        public void close() {
        }

        @Override // android.media.MediaDataSource
        public long getSize() {
            return -1L;
        }

        @Override // android.media.MediaDataSource
        public int readAt(long j10, byte[] bArr, int i10, int i11) {
            if (i11 == 0) {
                return 0;
            }
            if (j10 < 0) {
                return -1;
            }
            try {
                long j11 = this.f4378p;
                if (j11 != j10) {
                    if (j11 >= 0 && j10 >= j11 + this.f4379q.available()) {
                        return -1;
                    }
                    this.f4379q.e(j10);
                    this.f4378p = j10;
                }
                if (i11 > this.f4379q.available()) {
                    i11 = this.f4379q.available();
                }
                int read = this.f4379q.read(bArr, i10, i11);
                if (read >= 0) {
                    this.f4378p += read;
                    return read;
                }
            } catch (IOException unused) {
            }
            this.f4378p = -1L;
            return -1;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class b extends InputStream implements DataInput {

        /* renamed from: t, reason: collision with root package name */
        private static final ByteOrder f4381t = ByteOrder.LITTLE_ENDIAN;

        /* renamed from: u, reason: collision with root package name */
        private static final ByteOrder f4382u = ByteOrder.BIG_ENDIAN;

        /* renamed from: p, reason: collision with root package name */
        final DataInputStream f4383p;

        /* renamed from: q, reason: collision with root package name */
        private ByteOrder f4384q;

        /* renamed from: r, reason: collision with root package name */
        int f4385r;

        /* renamed from: s, reason: collision with root package name */
        private byte[] f4386s;

        b(byte[] bArr) {
            this(new ByteArrayInputStream(bArr), ByteOrder.BIG_ENDIAN);
        }

        public int a() {
            return this.f4385r;
        }

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

        public long b() {
            return readInt() & 4294967295L;
        }

        public void c(ByteOrder byteOrder) {
            this.f4384q = byteOrder;
        }

        public void d(int i10) {
            int i11 = 0;
            while (i11 < i10) {
                int i12 = i10 - i11;
                int skip = (int) this.f4383p.skip(i12);
                if (skip <= 0) {
                    if (this.f4386s == null) {
                        this.f4386s = new byte[UserMetadata.MAX_INTERNAL_KEY_SIZE];
                    }
                    skip = this.f4383p.read(this.f4386s, 0, Math.min(UserMetadata.MAX_INTERNAL_KEY_SIZE, i12));
                    if (skip == -1) {
                        throw new EOFException("Reached EOF while skipping " + i10 + " bytes.");
                    }
                }
                i11 += skip;
            }
            this.f4385r += i11;
        }

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

        @Override // java.io.InputStream
        public int read() {
            this.f4385r++;
            return this.f4383p.read();
        }

        @Override // java.io.DataInput
        public boolean readBoolean() {
            this.f4385r++;
            return this.f4383p.readBoolean();
        }

        @Override // java.io.DataInput
        public byte readByte() {
            this.f4385r++;
            int read = this.f4383p.read();
            if (read >= 0) {
                return (byte) read;
            }
            throw new EOFException();
        }

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

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

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

        @Override // java.io.DataInput
        public void readFully(byte[] bArr, int i10, int i11) {
            this.f4385r += i11;
            this.f4383p.readFully(bArr, i10, i11);
        }

        @Override // java.io.DataInput
        public int readInt() {
            this.f4385r += 4;
            int read = this.f4383p.read();
            int read2 = this.f4383p.read();
            int read3 = this.f4383p.read();
            int read4 = this.f4383p.read();
            if ((read | read2 | read3 | read4) < 0) {
                throw new EOFException();
            }
            ByteOrder byteOrder = this.f4384q;
            if (byteOrder == f4381t) {
                return (read4 << 24) + (read3 << 16) + (read2 << 8) + read;
            }
            if (byteOrder == f4382u) {
                return (read << 24) + (read2 << 16) + (read3 << 8) + read4;
            }
            throw new IOException("Invalid byte order: " + this.f4384q);
        }

        @Override // java.io.DataInput
        public String readLine() {
            Log.d("ExifInterface", "Currently unsupported");
            return null;
        }

        @Override // java.io.DataInput
        public long readLong() {
            this.f4385r += 8;
            int read = this.f4383p.read();
            int read2 = this.f4383p.read();
            int read3 = this.f4383p.read();
            int read4 = this.f4383p.read();
            int read5 = this.f4383p.read();
            int read6 = this.f4383p.read();
            int read7 = this.f4383p.read();
            int read8 = this.f4383p.read();
            if ((read | read2 | read3 | read4 | read5 | read6 | read7 | read8) < 0) {
                throw new EOFException();
            }
            ByteOrder byteOrder = this.f4384q;
            if (byteOrder == f4381t) {
                return (read8 << 56) + (read7 << 48) + (read6 << 40) + (read5 << 32) + (read4 << 24) + (read3 << 16) + (read2 << 8) + read;
            }
            if (byteOrder == f4382u) {
                return (read << 56) + (read2 << 48) + (read3 << 40) + (read4 << 32) + (read5 << 24) + (read6 << 16) + (read7 << 8) + read8;
            }
            throw new IOException("Invalid byte order: " + this.f4384q);
        }

        @Override // java.io.DataInput
        public short readShort() {
            int i10;
            this.f4385r += 2;
            int read = this.f4383p.read();
            int read2 = this.f4383p.read();
            if ((read | read2) < 0) {
                throw new EOFException();
            }
            ByteOrder byteOrder = this.f4384q;
            if (byteOrder == f4381t) {
                i10 = (read2 << 8) + read;
            } else {
                if (byteOrder != f4382u) {
                    throw new IOException("Invalid byte order: " + this.f4384q);
                }
                i10 = (read << 8) + read2;
            }
            return (short) i10;
        }

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

        @Override // java.io.DataInput
        public int readUnsignedByte() {
            this.f4385r++;
            return this.f4383p.readUnsignedByte();
        }

        @Override // java.io.DataInput
        public int readUnsignedShort() {
            this.f4385r += 2;
            int read = this.f4383p.read();
            int read2 = this.f4383p.read();
            if ((read | read2) < 0) {
                throw new EOFException();
            }
            ByteOrder byteOrder = this.f4384q;
            if (byteOrder == f4381t) {
                return (read2 << 8) + read;
            }
            if (byteOrder == f4382u) {
                return (read << 8) + read2;
            }
            throw new IOException("Invalid byte order: " + this.f4384q);
        }

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

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

        b(InputStream inputStream) {
            this(inputStream, ByteOrder.BIG_ENDIAN);
        }

        b(InputStream inputStream, ByteOrder byteOrder) {
            this.f4384q = ByteOrder.BIG_ENDIAN;
            DataInputStream dataInputStream = new DataInputStream(inputStream);
            this.f4383p = dataInputStream;
            dataInputStream.mark(0);
            this.f4385r = 0;
            this.f4384q = byteOrder;
        }

        @Override // java.io.InputStream
        public int read(byte[] bArr, int i10, int i11) {
            int read = this.f4383p.read(bArr, i10, i11);
            this.f4385r += read;
            return read;
        }

        @Override // java.io.DataInput
        public void readFully(byte[] bArr) {
            this.f4385r += bArr.length;
            this.f4383p.readFully(bArr);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class c {

        /* renamed from: a, reason: collision with root package name */
        public final int f4387a;

        /* renamed from: b, reason: collision with root package name */
        public final int f4388b;

        /* renamed from: c, reason: collision with root package name */
        public final long f4389c;

        /* renamed from: d, reason: collision with root package name */
        public final byte[] f4390d;

        c(int i10, int i11, byte[] bArr) {
            this(i10, i11, -1L, bArr);
        }

        public static c a(String str) {
            byte[] bytes = (str + (char) 0).getBytes(a.f4345o0);
            return new c(2, bytes.length, bytes);
        }

        public static c b(long j10, ByteOrder byteOrder) {
            return c(new long[]{j10}, byteOrder);
        }

        public static c c(long[] jArr, ByteOrder byteOrder) {
            ByteBuffer wrap = ByteBuffer.wrap(new byte[a.W[4] * jArr.length]);
            wrap.order(byteOrder);
            for (long j10 : jArr) {
                wrap.putInt((int) j10);
            }
            return new c(4, jArr.length, wrap.array());
        }

        public static c d(e eVar, ByteOrder byteOrder) {
            return e(new e[]{eVar}, byteOrder);
        }

        public static c e(e[] eVarArr, ByteOrder byteOrder) {
            ByteBuffer wrap = ByteBuffer.wrap(new byte[a.W[5] * eVarArr.length]);
            wrap.order(byteOrder);
            for (e eVar : eVarArr) {
                wrap.putInt((int) eVar.f4395a);
                wrap.putInt((int) eVar.f4396b);
            }
            return new c(5, eVarArr.length, wrap.array());
        }

        public static c f(int i10, ByteOrder byteOrder) {
            return g(new int[]{i10}, byteOrder);
        }

        public static c g(int[] iArr, ByteOrder byteOrder) {
            ByteBuffer wrap = ByteBuffer.wrap(new byte[a.W[3] * iArr.length]);
            wrap.order(byteOrder);
            for (int i10 : iArr) {
                wrap.putShort((short) i10);
            }
            return new c(3, iArr.length, wrap.array());
        }

        public double h(ByteOrder byteOrder) {
            Object k10 = k(byteOrder);
            if (k10 == null) {
                throw new NumberFormatException("NULL can't be converted to a double value");
            }
            if (k10 instanceof String) {
                return Double.parseDouble((String) k10);
            }
            if (k10 instanceof long[]) {
                if (((long[]) k10).length == 1) {
                    return r3[0];
                }
                throw new NumberFormatException("There are more than one component");
            }
            if (k10 instanceof int[]) {
                if (((int[]) k10).length == 1) {
                    return r3[0];
                }
                throw new NumberFormatException("There are more than one component");
            }
            if (k10 instanceof double[]) {
                double[] dArr = (double[]) k10;
                if (dArr.length == 1) {
                    return dArr[0];
                }
                throw new NumberFormatException("There are more than one component");
            }
            if (!(k10 instanceof e[])) {
                throw new NumberFormatException("Couldn't find a double value");
            }
            e[] eVarArr = (e[]) k10;
            if (eVarArr.length == 1) {
                return eVarArr[0].a();
            }
            throw new NumberFormatException("There are more than one component");
        }

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

        public String j(ByteOrder byteOrder) {
            Object k10 = k(byteOrder);
            if (k10 == null) {
                return null;
            }
            if (k10 instanceof String) {
                return (String) k10;
            }
            StringBuilder sb2 = new StringBuilder();
            int i10 = 0;
            if (k10 instanceof long[]) {
                long[] jArr = (long[]) k10;
                while (i10 < jArr.length) {
                    sb2.append(jArr[i10]);
                    i10++;
                    if (i10 != jArr.length) {
                        sb2.append(",");
                    }
                }
                return sb2.toString();
            }
            if (k10 instanceof int[]) {
                int[] iArr = (int[]) k10;
                while (i10 < iArr.length) {
                    sb2.append(iArr[i10]);
                    i10++;
                    if (i10 != iArr.length) {
                        sb2.append(",");
                    }
                }
                return sb2.toString();
            }
            if (k10 instanceof double[]) {
                double[] dArr = (double[]) k10;
                while (i10 < dArr.length) {
                    sb2.append(dArr[i10]);
                    i10++;
                    if (i10 != dArr.length) {
                        sb2.append(",");
                    }
                }
                return sb2.toString();
            }
            if (!(k10 instanceof e[])) {
                return null;
            }
            e[] eVarArr = (e[]) k10;
            while (i10 < eVarArr.length) {
                sb2.append(eVarArr[i10].f4395a);
                sb2.append(JsonPointer.SEPARATOR);
                sb2.append(eVarArr[i10].f4396b);
                i10++;
                if (i10 != eVarArr.length) {
                    sb2.append(",");
                }
            }
            return sb2.toString();
        }

        /* JADX WARN: Not initialized variable reg: 3, insn: 0x0198: MOVE (r2 I:??[OBJECT, ARRAY]) = (r3 I:??[OBJECT, ARRAY]), block:B:168:0x0198 */
        /* JADX WARN: Removed duplicated region for block: B:171:0x019b A[EXC_TOP_SPLITTER, SYNTHETIC] */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        Object k(ByteOrder byteOrder) {
            b bVar;
            InputStream inputStream;
            byte b10;
            byte b11;
            byte[] bArr;
            InputStream inputStream2 = null;
            try {
                try {
                    bVar = new b(this.f4390d);
                    try {
                        bVar.c(byteOrder);
                        int i10 = 0;
                        boolean z10 = true;
                        switch (this.f4387a) {
                            case 1:
                            case 6:
                                byte[] bArr2 = this.f4390d;
                                if (bArr2.length != 1 || (b10 = bArr2[0]) < 0 || b10 > 1) {
                                    String str = new String(bArr2, a.f4345o0);
                                    try {
                                        bVar.close();
                                    } catch (IOException e10) {
                                        Log.e("ExifInterface", "IOException occurred while closing InputStream", e10);
                                    }
                                    return str;
                                }
                                String str2 = new String(new char[]{(char) (b10 + 48)});
                                try {
                                    bVar.close();
                                } catch (IOException e11) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e11);
                                }
                                return str2;
                            case 2:
                            case 7:
                                if (this.f4388b >= a.X.length) {
                                    int i11 = 0;
                                    while (true) {
                                        bArr = a.X;
                                        if (i11 < bArr.length) {
                                            if (this.f4390d[i11] != bArr[i11]) {
                                                z10 = false;
                                            } else {
                                                i11++;
                                            }
                                        }
                                    }
                                    if (z10) {
                                        i10 = bArr.length;
                                    }
                                }
                                StringBuilder sb2 = new StringBuilder();
                                while (i10 < this.f4388b && (b11 = this.f4390d[i10]) != 0) {
                                    if (b11 >= 32) {
                                        sb2.append((char) b11);
                                    } else {
                                        sb2.append('?');
                                    }
                                    i10++;
                                }
                                String sb3 = sb2.toString();
                                try {
                                    bVar.close();
                                } catch (IOException e12) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e12);
                                }
                                return sb3;
                            case 3:
                                int[] iArr = new int[this.f4388b];
                                while (i10 < this.f4388b) {
                                    iArr[i10] = bVar.readUnsignedShort();
                                    i10++;
                                }
                                try {
                                    bVar.close();
                                } catch (IOException e13) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e13);
                                }
                                return iArr;
                            case 4:
                                long[] jArr = new long[this.f4388b];
                                while (i10 < this.f4388b) {
                                    jArr[i10] = bVar.b();
                                    i10++;
                                }
                                try {
                                    bVar.close();
                                } catch (IOException e14) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e14);
                                }
                                return jArr;
                            case 5:
                                e[] eVarArr = new e[this.f4388b];
                                while (i10 < this.f4388b) {
                                    eVarArr[i10] = new e(bVar.b(), bVar.b());
                                    i10++;
                                }
                                try {
                                    bVar.close();
                                } catch (IOException e15) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e15);
                                }
                                return eVarArr;
                            case 8:
                                int[] iArr2 = new int[this.f4388b];
                                while (i10 < this.f4388b) {
                                    iArr2[i10] = bVar.readShort();
                                    i10++;
                                }
                                try {
                                    bVar.close();
                                } catch (IOException e16) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e16);
                                }
                                return iArr2;
                            case 9:
                                int[] iArr3 = new int[this.f4388b];
                                while (i10 < this.f4388b) {
                                    iArr3[i10] = bVar.readInt();
                                    i10++;
                                }
                                try {
                                    bVar.close();
                                } catch (IOException e17) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e17);
                                }
                                return iArr3;
                            case 10:
                                e[] eVarArr2 = new e[this.f4388b];
                                while (i10 < this.f4388b) {
                                    eVarArr2[i10] = new e(bVar.readInt(), bVar.readInt());
                                    i10++;
                                }
                                try {
                                    bVar.close();
                                } catch (IOException e18) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e18);
                                }
                                return eVarArr2;
                            case 11:
                                double[] dArr = new double[this.f4388b];
                                while (i10 < this.f4388b) {
                                    dArr[i10] = bVar.readFloat();
                                    i10++;
                                }
                                try {
                                    bVar.close();
                                } catch (IOException e19) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e19);
                                }
                                return dArr;
                            case 12:
                                double[] dArr2 = new double[this.f4388b];
                                while (i10 < this.f4388b) {
                                    dArr2[i10] = bVar.readDouble();
                                    i10++;
                                }
                                try {
                                    bVar.close();
                                } catch (IOException e20) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e20);
                                }
                                return dArr2;
                            default:
                                try {
                                    bVar.close();
                                } catch (IOException e21) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e21);
                                }
                                return null;
                        }
                    } catch (IOException e22) {
                        e = e22;
                        Log.w("ExifInterface", "IOException occurred during reading a value", e);
                        if (bVar != null) {
                            try {
                                bVar.close();
                            } catch (IOException e23) {
                                Log.e("ExifInterface", "IOException occurred while closing InputStream", e23);
                            }
                        }
                        return null;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    inputStream2 = inputStream;
                    if (inputStream2 != null) {
                        try {
                            inputStream2.close();
                        } catch (IOException e24) {
                            Log.e("ExifInterface", "IOException occurred while closing InputStream", e24);
                        }
                    }
                    throw th;
                }
            } catch (IOException e25) {
                e = e25;
                bVar = null;
            } catch (Throwable th3) {
                th = th3;
                if (inputStream2 != null) {
                }
                throw th;
            }
        }

        public String toString() {
            return "(" + a.V[this.f4387a] + ", data length:" + this.f4390d.length + ")";
        }

        c(int i10, int i11, long j10, byte[] bArr) {
            this.f4387a = i10;
            this.f4388b = i11;
            this.f4389c = j10;
            this.f4390d = bArr;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class e {

        /* renamed from: a, reason: collision with root package name */
        public final long f4395a;

        /* renamed from: b, reason: collision with root package name */
        public final long f4396b;

        e(long j10, long j11) {
            if (j11 == 0) {
                this.f4395a = 0L;
                this.f4396b = 1L;
            } else {
                this.f4395a = j10;
                this.f4396b = j11;
            }
        }

        public double a() {
            return this.f4395a / this.f4396b;
        }

        public String toString() {
            return this.f4395a + RemoteSettings.FORWARD_SLASH_STRING + this.f4396b;
        }
    }

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

    public a(InputStream inputStream) {
        this(inputStream, 0);
    }

    private boolean A(byte[] bArr) {
        int i10 = 0;
        while (true) {
            byte[] bArr2 = K;
            if (i10 >= bArr2.length) {
                int i11 = 0;
                while (true) {
                    byte[] bArr3 = L;
                    if (i11 >= bArr3.length) {
                        return true;
                    }
                    if (bArr[K.length + i11 + 4] != bArr3[i11]) {
                        return false;
                    }
                    i11++;
                }
            } else {
                if (bArr[i10] != bArr2[i10]) {
                    return false;
                }
                i10++;
            }
        }
    }

    private void B(InputStream inputStream) {
        if (inputStream == null) {
            throw new NullPointerException("inputstream shouldn't be null");
        }
        for (int i10 = 0; i10 < f4339i0.length; i10++) {
            try {
                try {
                    this.f4363f[i10] = new HashMap();
                } catch (IOException | UnsupportedOperationException e10) {
                    boolean z10 = f4351u;
                    if (z10) {
                        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.", e10);
                    }
                    a();
                    if (!z10) {
                        return;
                    }
                }
            } finally {
                a();
                if (f4351u) {
                    D();
                }
            }
        }
        if (!this.f4362e) {
            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, 5000);
            this.f4361d = g(bufferedInputStream);
            inputStream = bufferedInputStream;
        }
        if (K(this.f4361d)) {
            f fVar = new f(inputStream);
            if (this.f4362e) {
                m(fVar);
            } else {
                int i11 = this.f4361d;
                if (i11 == 12) {
                    e(fVar);
                } else if (i11 == 7) {
                    h(fVar);
                } else if (i11 == 10) {
                    l(fVar);
                } else {
                    k(fVar);
                }
            }
            fVar.e(this.f4373p);
            J(fVar);
        } else {
            b bVar = new b(inputStream);
            int i12 = this.f4361d;
            if (i12 == 4) {
                f(bVar, 0, 0);
            } else if (i12 == 13) {
                i(bVar);
            } else if (i12 == 9) {
                j(bVar);
            } else if (i12 == 14) {
                n(bVar);
            }
        }
    }

    private void C(b bVar) {
        ByteOrder E2 = E(bVar);
        this.f4365h = E2;
        bVar.c(E2);
        int readUnsignedShort = bVar.readUnsignedShort();
        int i10 = this.f4361d;
        if (i10 != 7 && i10 != 10 && readUnsignedShort != 42) {
            throw new IOException("Invalid start code: " + Integer.toHexString(readUnsignedShort));
        }
        int readInt = bVar.readInt();
        if (readInt < 8) {
            throw new IOException("Invalid first Ifd offset: " + readInt);
        }
        int i11 = readInt - 8;
        if (i11 > 0) {
            bVar.d(i11);
        }
    }

    private void D() {
        for (int i10 = 0; i10 < this.f4363f.length; i10++) {
            Log.d("ExifInterface", "The size of tag group[" + i10 + "]: " + this.f4363f[i10].size());
            for (Map.Entry entry : this.f4363f[i10].entrySet()) {
                c cVar = (c) entry.getValue();
                Log.d("ExifInterface", "tagName: " + ((String) entry.getKey()) + ", tagType: " + cVar.toString() + ", tagValue: '" + cVar.j(this.f4365h) + "'");
            }
        }
    }

    private ByteOrder E(b bVar) {
        short readShort = bVar.readShort();
        if (readShort == 18761) {
            if (f4351u) {
                Log.d("ExifInterface", "readExifSegment: Byte Align II");
            }
            return ByteOrder.LITTLE_ENDIAN;
        }
        if (readShort == 19789) {
            if (f4351u) {
                Log.d("ExifInterface", "readExifSegment: Byte Align MM");
            }
            return ByteOrder.BIG_ENDIAN;
        }
        throw new IOException("Invalid byte order: " + Integer.toHexString(readShort));
    }

    private void F(byte[] bArr, int i10) {
        f fVar = new f(bArr);
        C(fVar);
        G(fVar, i10);
    }

    /* JADX WARN: Removed duplicated region for block: B:25:0x0130  */
    /* JADX WARN: Removed duplicated region for block: B:28:0x0137  */
    /* JADX WARN: Removed duplicated region for block: B:60:0x021a  */
    /* JADX WARN: Removed duplicated region for block: B:63:0x0233  */
    /* JADX WARN: Removed duplicated region for block: B:70:0x026f  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private void G(f fVar, int i10) {
        String str;
        short s10;
        long j10;
        short s11;
        long j11;
        int i11;
        int readUnsignedShort;
        long j12;
        int i12 = i10;
        this.f4364g.add(Integer.valueOf(fVar.f4385r));
        short readShort = fVar.readShort();
        String str2 = "ExifInterface";
        if (f4351u) {
            Log.d("ExifInterface", "numberOfDirectoryEntry: " + ((int) readShort));
        }
        if (readShort <= 0) {
            return;
        }
        char c10 = 0;
        short s12 = 0;
        while (s12 < readShort) {
            int readUnsignedShort2 = fVar.readUnsignedShort();
            int readUnsignedShort3 = fVar.readUnsignedShort();
            int readInt = fVar.readInt();
            long a10 = fVar.a() + 4;
            d dVar = (d) f4341k0[i12].get(Integer.valueOf(readUnsignedShort2));
            boolean z10 = f4351u;
            boolean z11 = true;
            if (z10) {
                Object[] objArr = new Object[5];
                objArr[c10] = Integer.valueOf(i10);
                objArr[1] = Integer.valueOf(readUnsignedShort2);
                objArr[2] = dVar != null ? dVar.f4392b : null;
                objArr[3] = Integer.valueOf(readUnsignedShort3);
                objArr[4] = Integer.valueOf(readInt);
                Log.d(str2, String.format("ifdType: %d, tagNumber: %d, tagName: %s, dataFormat: %d, numberOfComponents: %d", objArr));
            }
            if (dVar != null) {
                if (readUnsignedShort3 > 0) {
                    if (readUnsignedShort3 < W.length) {
                        if (dVar.a(readUnsignedShort3)) {
                            if (readUnsignedShort3 == 7) {
                                readUnsignedShort3 = dVar.f4393c;
                            }
                            str = str2;
                            s10 = s12;
                            j10 = readInt * r7[readUnsignedShort3];
                            if (j10 < 0 || j10 > 2147483647L) {
                                if (z10) {
                                    Log.d(str, "Skip the tag entry since the number of components is invalid: " + readInt);
                                }
                                z11 = false;
                            }
                            if (z11) {
                                if (j10 > 4) {
                                    int readInt2 = fVar.readInt();
                                    s11 = readShort;
                                    if (z10) {
                                        StringBuilder sb2 = new StringBuilder();
                                        j11 = a10;
                                        sb2.append("seek to data offset: ");
                                        sb2.append(readInt2);
                                        Log.d(str, sb2.toString());
                                    } else {
                                        j11 = a10;
                                    }
                                    if (this.f4361d == 7) {
                                        if ("MakerNote".equals(dVar.f4392b)) {
                                            this.f4374q = readInt2;
                                        } else if (i12 == 6 && "ThumbnailImage".equals(dVar.f4392b)) {
                                            this.f4375r = readInt2;
                                            this.f4376s = readInt;
                                            c f10 = c.f(6, this.f4365h);
                                            c b10 = c.b(this.f4375r, this.f4365h);
                                            i11 = readInt;
                                            c b11 = c.b(this.f4376s, this.f4365h);
                                            this.f4363f[4].put("Compression", f10);
                                            this.f4363f[4].put("JPEGInterchangeFormat", b10);
                                            this.f4363f[4].put("JPEGInterchangeFormatLength", b11);
                                            fVar.e(readInt2);
                                        }
                                    }
                                    i11 = readInt;
                                    fVar.e(readInt2);
                                } else {
                                    s11 = readShort;
                                    j11 = a10;
                                    i11 = readInt;
                                }
                                Integer num = (Integer) f4344n0.get(Integer.valueOf(readUnsignedShort2));
                                if (z10) {
                                    Log.d(str, "nextIfdType: " + num + " byteCount: " + j10);
                                }
                                if (num != null) {
                                    if (readUnsignedShort3 != 3) {
                                        if (readUnsignedShort3 == 4) {
                                            j12 = fVar.b();
                                        } else if (readUnsignedShort3 == 8) {
                                            readUnsignedShort = fVar.readShort();
                                        } else if (readUnsignedShort3 == 9 || readUnsignedShort3 == 13) {
                                            readUnsignedShort = fVar.readInt();
                                        } else {
                                            j12 = -1;
                                        }
                                        if (z10) {
                                            Log.d(str, String.format("Offset: %d, tagName: %s", Long.valueOf(j12), dVar.f4392b));
                                        }
                                        if (j12 <= 0) {
                                            if (!this.f4364g.contains(Integer.valueOf((int) j12))) {
                                                fVar.e(j12);
                                                G(fVar, num.intValue());
                                            } else if (z10) {
                                                Log.d(str, "Skip jump into the IFD since it has already been read: IfdType " + num + " (at " + j12 + ")");
                                            }
                                        } else if (z10) {
                                            Log.d(str, "Skip jump into the IFD since its offset is invalid: " + j12);
                                        }
                                        fVar.e(j11);
                                    } else {
                                        readUnsignedShort = fVar.readUnsignedShort();
                                    }
                                    j12 = readUnsignedShort;
                                    if (z10) {
                                    }
                                    if (j12 <= 0) {
                                    }
                                    fVar.e(j11);
                                } else {
                                    long j13 = j11;
                                    int a11 = fVar.a() + this.f4373p;
                                    byte[] bArr = new byte[(int) j10];
                                    fVar.readFully(bArr);
                                    c cVar = new c(readUnsignedShort3, i11, a11, bArr);
                                    this.f4363f[i10].put(dVar.f4392b, cVar);
                                    if ("DNGVersion".equals(dVar.f4392b)) {
                                        this.f4361d = 3;
                                    }
                                    if ((("Make".equals(dVar.f4392b) || "Model".equals(dVar.f4392b)) && cVar.j(this.f4365h).contains("PENTAX")) || ("Compression".equals(dVar.f4392b) && cVar.i(this.f4365h) == 65535)) {
                                        this.f4361d = 8;
                                    }
                                    if (fVar.a() != j13) {
                                        fVar.e(j13);
                                    }
                                }
                            } else {
                                fVar.e(a10);
                                s11 = readShort;
                            }
                            s12 = (short) (s10 + 1);
                            i12 = i10;
                            str2 = str;
                            readShort = s11;
                            c10 = 0;
                        } else if (z10) {
                            Log.d(str2, "Skip the tag entry since data format (" + V[readUnsignedShort3] + ") is unexpected for tag: " + dVar.f4392b);
                        }
                    }
                }
                str = str2;
                s10 = s12;
                if (z10) {
                    Log.d(str, "Skip the tag entry since data format is invalid: " + readUnsignedShort3);
                }
                j10 = 0;
                z11 = false;
                if (z11) {
                }
                s12 = (short) (s10 + 1);
                i12 = i10;
                str2 = str;
                readShort = s11;
                c10 = 0;
            } else if (z10) {
                Log.d(str2, "Skip the tag entry since tag number is not defined: " + readUnsignedShort2);
            }
            str = str2;
            s10 = s12;
            j10 = 0;
            z11 = false;
            if (z11) {
            }
            s12 = (short) (s10 + 1);
            i12 = i10;
            str2 = str;
            readShort = s11;
            c10 = 0;
        }
        String str3 = str2;
        int readInt3 = fVar.readInt();
        boolean z12 = f4351u;
        if (z12) {
            Log.d(str3, String.format("nextIfdOffset: %d", Integer.valueOf(readInt3)));
        }
        long j14 = readInt3;
        if (j14 <= 0) {
            if (z12) {
                Log.d(str3, "Stop reading file since a wrong offset may cause an infinite loop: " + readInt3);
                return;
            }
            return;
        }
        if (this.f4364g.contains(Integer.valueOf(readInt3))) {
            if (z12) {
                Log.d(str3, "Stop reading file since re-reading an IFD may cause an infinite loop: " + readInt3);
                return;
            }
            return;
        }
        fVar.e(j14);
        if (this.f4363f[4].isEmpty()) {
            G(fVar, 4);
        } else if (this.f4363f[5].isEmpty()) {
            G(fVar, 5);
        }
    }

    private void H(int i10, String str, String str2) {
        if (this.f4363f[i10].isEmpty() || this.f4363f[i10].get(str) == null) {
            return;
        }
        HashMap hashMap = this.f4363f[i10];
        hashMap.put(str2, hashMap.get(str));
        this.f4363f[i10].remove(str);
    }

    private void I(f fVar, int i10) {
        c cVar = (c) this.f4363f[i10].get("ImageLength");
        c cVar2 = (c) this.f4363f[i10].get("ImageWidth");
        if (cVar == null || cVar2 == null) {
            c cVar3 = (c) this.f4363f[i10].get("JPEGInterchangeFormat");
            c cVar4 = (c) this.f4363f[i10].get("JPEGInterchangeFormatLength");
            if (cVar3 == null || cVar4 == null) {
                return;
            }
            int i11 = cVar3.i(this.f4365h);
            int i12 = cVar3.i(this.f4365h);
            fVar.e(i11);
            byte[] bArr = new byte[i12];
            fVar.read(bArr);
            f(new b(bArr), i11, i10);
        }
    }

    private void J(b bVar) {
        HashMap hashMap = this.f4363f[4];
        c cVar = (c) hashMap.get("Compression");
        if (cVar == null) {
            this.f4372o = 6;
            o(bVar, hashMap);
            return;
        }
        int i10 = cVar.i(this.f4365h);
        this.f4372o = i10;
        if (i10 != 1) {
            if (i10 == 6) {
                o(bVar, hashMap);
                return;
            } else if (i10 != 7) {
                return;
            }
        }
        if (y(hashMap)) {
            p(bVar, hashMap);
        }
    }

    private static boolean K(int i10) {
        return (i10 == 4 || i10 == 9 || i10 == 13 || i10 == 14) ? false : true;
    }

    private void L(int i10, int i11) {
        if (this.f4363f[i10].isEmpty() || this.f4363f[i11].isEmpty()) {
            if (f4351u) {
                Log.d("ExifInterface", "Cannot perform swap since only one image data exists");
                return;
            }
            return;
        }
        c cVar = (c) this.f4363f[i10].get("ImageLength");
        c cVar2 = (c) this.f4363f[i10].get("ImageWidth");
        c cVar3 = (c) this.f4363f[i11].get("ImageLength");
        c cVar4 = (c) this.f4363f[i11].get("ImageWidth");
        if (cVar == null || cVar2 == null) {
            if (f4351u) {
                Log.d("ExifInterface", "First image does not contain valid size information");
                return;
            }
            return;
        }
        if (cVar3 == null || cVar4 == null) {
            if (f4351u) {
                Log.d("ExifInterface", "Second image does not contain valid size information");
                return;
            }
            return;
        }
        int i12 = cVar.i(this.f4365h);
        int i13 = cVar2.i(this.f4365h);
        int i14 = cVar3.i(this.f4365h);
        int i15 = cVar4.i(this.f4365h);
        if (i12 >= i14 || i13 >= i15) {
            return;
        }
        HashMap[] hashMapArr = this.f4363f;
        HashMap hashMap = hashMapArr[i10];
        hashMapArr[i10] = hashMapArr[i11];
        hashMapArr[i11] = hashMap;
    }

    private void M(f fVar, int i10) {
        c f10;
        c f11;
        c cVar = (c) this.f4363f[i10].get("DefaultCropSize");
        c cVar2 = (c) this.f4363f[i10].get("SensorTopBorder");
        c cVar3 = (c) this.f4363f[i10].get("SensorLeftBorder");
        c cVar4 = (c) this.f4363f[i10].get("SensorBottomBorder");
        c cVar5 = (c) this.f4363f[i10].get("SensorRightBorder");
        if (cVar == null) {
            if (cVar2 == null || cVar3 == null || cVar4 == null || cVar5 == null) {
                I(fVar, i10);
                return;
            }
            int i11 = cVar2.i(this.f4365h);
            int i12 = cVar4.i(this.f4365h);
            int i13 = cVar5.i(this.f4365h);
            int i14 = cVar3.i(this.f4365h);
            if (i12 <= i11 || i13 <= i14) {
                return;
            }
            c f12 = c.f(i12 - i11, this.f4365h);
            c f13 = c.f(i13 - i14, this.f4365h);
            this.f4363f[i10].put("ImageLength", f12);
            this.f4363f[i10].put("ImageWidth", f13);
            return;
        }
        if (cVar.f4387a == 5) {
            e[] eVarArr = (e[]) cVar.k(this.f4365h);
            if (eVarArr == null || eVarArr.length != 2) {
                Log.w("ExifInterface", "Invalid crop size values. cropSize=" + Arrays.toString(eVarArr));
                return;
            }
            f10 = c.d(eVarArr[0], this.f4365h);
            f11 = c.d(eVarArr[1], this.f4365h);
        } else {
            int[] iArr = (int[]) cVar.k(this.f4365h);
            if (iArr == null || iArr.length != 2) {
                Log.w("ExifInterface", "Invalid crop size values. cropSize=" + Arrays.toString(iArr));
                return;
            }
            f10 = c.f(iArr[0], this.f4365h);
            f11 = c.f(iArr[1], this.f4365h);
        }
        this.f4363f[i10].put("ImageWidth", f10);
        this.f4363f[i10].put("ImageLength", f11);
    }

    private void N() {
        L(0, 5);
        L(0, 4);
        L(5, 4);
        c cVar = (c) this.f4363f[1].get("PixelXDimension");
        c cVar2 = (c) this.f4363f[1].get("PixelYDimension");
        if (cVar != null && cVar2 != null) {
            this.f4363f[0].put("ImageWidth", cVar);
            this.f4363f[0].put("ImageLength", cVar2);
        }
        if (this.f4363f[4].isEmpty() && z(this.f4363f[5])) {
            HashMap[] hashMapArr = this.f4363f;
            hashMapArr[4] = hashMapArr[5];
            hashMapArr[5] = new HashMap();
        }
        if (!z(this.f4363f[4])) {
            Log.d("ExifInterface", "No image meets the size requirements of a thumbnail image.");
        }
        H(0, "ThumbnailOrientation", "Orientation");
        H(0, "ThumbnailImageLength", "ImageLength");
        H(0, "ThumbnailImageWidth", "ImageWidth");
        H(5, "ThumbnailOrientation", "Orientation");
        H(5, "ThumbnailImageLength", "ImageLength");
        H(5, "ThumbnailImageWidth", "ImageWidth");
        H(4, "Orientation", "ThumbnailOrientation");
        H(4, "ImageLength", "ThumbnailImageLength");
        H(4, "ImageWidth", "ThumbnailImageWidth");
    }

    private void a() {
        String b10 = b("DateTimeOriginal");
        if (b10 != null && b("DateTime") == null) {
            this.f4363f[0].put("DateTime", c.a(b10));
        }
        if (b("ImageWidth") == null) {
            this.f4363f[0].put("ImageWidth", c.b(0L, this.f4365h));
        }
        if (b("ImageLength") == null) {
            this.f4363f[0].put("ImageLength", c.b(0L, this.f4365h));
        }
        if (b("Orientation") == null) {
            this.f4363f[0].put("Orientation", c.b(0L, this.f4365h));
        }
        if (b("LightSource") == null) {
            this.f4363f[1].put("LightSource", c.b(0L, this.f4365h));
        }
    }

    private c d(String str) {
        if (str == null) {
            throw new NullPointerException("tag shouldn't be null");
        }
        if ("ISOSpeedRatings".equals(str)) {
            if (f4351u) {
                Log.d("ExifInterface", "getExifAttribute: Replacing TAG_ISO_SPEED_RATINGS with TAG_PHOTOGRAPHIC_SENSITIVITY.");
            }
            str = "PhotographicSensitivity";
        }
        for (int i10 = 0; i10 < f4339i0.length; i10++) {
            c cVar = (c) this.f4363f[i10].get(str);
            if (cVar != null) {
                return cVar;
            }
        }
        return null;
    }

    private void e(f fVar) {
        String str;
        String str2;
        String str3;
        MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
        try {
            try {
                b.C0113b.a(mediaMetadataRetriever, new C0112a(fVar));
                String extractMetadata = mediaMetadataRetriever.extractMetadata(33);
                String extractMetadata2 = mediaMetadataRetriever.extractMetadata(34);
                String extractMetadata3 = mediaMetadataRetriever.extractMetadata(26);
                String extractMetadata4 = mediaMetadataRetriever.extractMetadata(17);
                if ("yes".equals(extractMetadata3)) {
                    str = mediaMetadataRetriever.extractMetadata(29);
                    str2 = mediaMetadataRetriever.extractMetadata(30);
                    str3 = mediaMetadataRetriever.extractMetadata(31);
                } else if ("yes".equals(extractMetadata4)) {
                    str = mediaMetadataRetriever.extractMetadata(18);
                    str2 = mediaMetadataRetriever.extractMetadata(19);
                    str3 = mediaMetadataRetriever.extractMetadata(24);
                } else {
                    str = null;
                    str2 = null;
                    str3 = null;
                }
                if (str != null) {
                    this.f4363f[0].put("ImageWidth", c.f(Integer.parseInt(str), this.f4365h));
                }
                if (str2 != null) {
                    this.f4363f[0].put("ImageLength", c.f(Integer.parseInt(str2), this.f4365h));
                }
                if (str3 != null) {
                    int parseInt = Integer.parseInt(str3);
                    this.f4363f[0].put("Orientation", c.f(parseInt != 90 ? parseInt != 180 ? parseInt != 270 ? 1 : 8 : 3 : 6, this.f4365h));
                }
                if (extractMetadata != null && extractMetadata2 != null) {
                    int parseInt2 = Integer.parseInt(extractMetadata);
                    int parseInt3 = Integer.parseInt(extractMetadata2);
                    if (parseInt3 <= 6) {
                        throw new IOException("Invalid exif length");
                    }
                    fVar.e(parseInt2);
                    byte[] bArr = new byte[6];
                    if (fVar.read(bArr) != 6) {
                        throw new IOException("Can't read identifier");
                    }
                    int i10 = parseInt2 + 6;
                    int i11 = parseInt3 - 6;
                    if (!Arrays.equals(bArr, f4346p0)) {
                        throw new IOException("Invalid identifier");
                    }
                    byte[] bArr2 = new byte[i11];
                    if (fVar.read(bArr2) != i11) {
                        throw new IOException("Can't read exif");
                    }
                    this.f4373p = i10;
                    F(bArr2, 0);
                }
                if (f4351u) {
                    Log.d("ExifInterface", "Heif meta: " + str + "x" + str2 + ", rotation " + str3);
                }
            } catch (RuntimeException unused) {
                throw new UnsupportedOperationException("Failed to read EXIF from HEIF file. Given stream is either malformed or unsupported.");
            }
        } finally {
            mediaMetadataRetriever.release();
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:71:0x019a, code lost:
    
        r22.c(r21.f4365h);
     */
    /* JADX WARN: Code restructure failed: missing block: B:72:0x019f, code lost:
    
        return;
     */
    /* JADX WARN: Removed duplicated region for block: B:33:0x0184 A[LOOP:0: B:9:0x0038->B:33:0x0184, LOOP_END] */
    /* JADX WARN: Removed duplicated region for block: B:34:0x018e A[SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private void f(b bVar, int i10, int i11) {
        String str;
        String str2 = "ExifInterface";
        if (f4351u) {
            Log.d("ExifInterface", "getJpegAttributes starting with: " + bVar);
        }
        bVar.c(ByteOrder.BIG_ENDIAN);
        byte readByte = bVar.readByte();
        byte b10 = -1;
        if (readByte != -1) {
            throw new IOException("Invalid marker: " + Integer.toHexString(readByte & 255));
        }
        if (bVar.readByte() != -40) {
            throw new IOException("Invalid marker: " + Integer.toHexString(readByte & 255));
        }
        int i12 = 2;
        int i13 = 2;
        while (true) {
            byte readByte2 = bVar.readByte();
            if (readByte2 != b10) {
                throw new IOException("Invalid marker:" + Integer.toHexString(readByte2 & 255));
            }
            int i14 = i13 + 1;
            byte readByte3 = bVar.readByte();
            boolean z10 = f4351u;
            if (z10) {
                Log.d(str2, "Found JPEG segment indicator: " + Integer.toHexString(readByte3 & 255));
            }
            int i15 = i14 + 1;
            if (readByte3 != -39 && readByte3 != -38) {
                int readUnsignedShort = bVar.readUnsignedShort() - i12;
                int i16 = i15 + i12;
                if (z10) {
                    Log.d(str2, "JPEG segment: " + Integer.toHexString(readByte3 & 255) + " (length: " + (readUnsignedShort + 2) + ")");
                }
                if (readUnsignedShort < 0) {
                    throw new IOException("Invalid length");
                }
                if (readByte3 == -31) {
                    byte[] bArr = new byte[readUnsignedShort];
                    bVar.readFully(bArr);
                    int i17 = i16 + readUnsignedShort;
                    byte[] bArr2 = f4346p0;
                    if (androidx.exifinterface.media.b.c(bArr, bArr2)) {
                        byte[] copyOfRange = Arrays.copyOfRange(bArr, bArr2.length, readUnsignedShort);
                        this.f4373p = i10 + i16 + bArr2.length;
                        F(copyOfRange, i11);
                        J(new b(copyOfRange));
                    } else {
                        byte[] bArr3 = f4347q0;
                        if (androidx.exifinterface.media.b.c(bArr, bArr3)) {
                            int length = i16 + bArr3.length;
                            byte[] copyOfRange2 = Arrays.copyOfRange(bArr, bArr3.length, readUnsignedShort);
                            if (b("Xmp") == null) {
                                str = str2;
                                this.f4363f[0].put("Xmp", new c(1, copyOfRange2.length, length, copyOfRange2));
                                this.f4377t = true;
                                i16 = i17;
                            }
                        }
                    }
                    str = str2;
                    i16 = i17;
                } else if (readByte3 != -2) {
                    switch (readByte3) {
                        case -64:
                        case -63:
                        case -62:
                        case -61:
                            break;
                        default:
                            switch (readByte3) {
                                case -59:
                                case -58:
                                case -57:
                                    break;
                                default:
                                    switch (readByte3) {
                                        case -55:
                                        case -54:
                                        case -53:
                                            break;
                                        default:
                                            switch (readByte3) {
                                            }
                                            if (readUnsignedShort < 0) {
                                                throw new IOException("Invalid length");
                                            }
                                            bVar.d(readUnsignedShort);
                                            i13 = i16 + readUnsignedShort;
                                            str2 = str;
                                            i12 = 2;
                                            b10 = -1;
                                            break;
                                    }
                            }
                    }
                    bVar.d(1);
                    this.f4363f[i11].put(i11 != 4 ? "ImageLength" : "ThumbnailImageLength", c.b(bVar.readUnsignedShort(), this.f4365h));
                    this.f4363f[i11].put(i11 != 4 ? "ImageWidth" : "ThumbnailImageWidth", c.b(bVar.readUnsignedShort(), this.f4365h));
                    readUnsignedShort -= 5;
                    str = str2;
                    if (readUnsignedShort < 0) {
                    }
                } else {
                    byte[] bArr4 = new byte[readUnsignedShort];
                    if (bVar.read(bArr4) != readUnsignedShort) {
                        throw new IOException("Invalid exif");
                    }
                    if (b("UserComment") == null) {
                        this.f4363f[1].put("UserComment", c.a(new String(bArr4, f4345o0)));
                    }
                    str = str2;
                }
                readUnsignedShort = 0;
                if (readUnsignedShort < 0) {
                }
            }
        }
    }

    private int g(BufferedInputStream bufferedInputStream) {
        bufferedInputStream.mark(5000);
        byte[] bArr = new byte[5000];
        bufferedInputStream.read(bArr);
        bufferedInputStream.reset();
        if (s(bArr)) {
            return 4;
        }
        if (v(bArr)) {
            return 9;
        }
        if (r(bArr)) {
            return 12;
        }
        if (t(bArr)) {
            return 7;
        }
        if (w(bArr)) {
            return 10;
        }
        if (u(bArr)) {
            return 13;
        }
        return A(bArr) ? 14 : 0;
    }

    private void h(f fVar) {
        int i10;
        int i11;
        k(fVar);
        c cVar = (c) this.f4363f[1].get("MakerNote");
        if (cVar != null) {
            f fVar2 = new f(cVar.f4390d);
            fVar2.c(this.f4365h);
            byte[] bArr = E;
            byte[] bArr2 = new byte[bArr.length];
            fVar2.readFully(bArr2);
            fVar2.e(0L);
            byte[] bArr3 = F;
            byte[] bArr4 = new byte[bArr3.length];
            fVar2.readFully(bArr4);
            if (Arrays.equals(bArr2, bArr)) {
                fVar2.e(8L);
            } else if (Arrays.equals(bArr4, bArr3)) {
                fVar2.e(12L);
            }
            G(fVar2, 6);
            c cVar2 = (c) this.f4363f[7].get("PreviewImageStart");
            c cVar3 = (c) this.f4363f[7].get("PreviewImageLength");
            if (cVar2 != null && cVar3 != null) {
                this.f4363f[5].put("JPEGInterchangeFormat", cVar2);
                this.f4363f[5].put("JPEGInterchangeFormatLength", cVar3);
            }
            c cVar4 = (c) this.f4363f[8].get("AspectFrame");
            if (cVar4 != null) {
                int[] iArr = (int[]) cVar4.k(this.f4365h);
                if (iArr == null || iArr.length != 4) {
                    Log.w("ExifInterface", "Invalid aspect frame values. frame=" + Arrays.toString(iArr));
                    return;
                }
                int i12 = iArr[2];
                int i13 = iArr[0];
                if (i12 <= i13 || (i10 = iArr[3]) <= (i11 = iArr[1])) {
                    return;
                }
                int i14 = (i12 - i13) + 1;
                int i15 = (i10 - i11) + 1;
                if (i14 < i15) {
                    int i16 = i14 + i15;
                    i15 = i16 - i15;
                    i14 = i16 - i15;
                }
                c f10 = c.f(i14, this.f4365h);
                c f11 = c.f(i15, this.f4365h);
                this.f4363f[0].put("ImageWidth", f10);
                this.f4363f[0].put("ImageLength", f11);
            }
        }
    }

    private void i(b bVar) {
        if (f4351u) {
            Log.d("ExifInterface", "getPngAttributes starting with: " + bVar);
        }
        bVar.c(ByteOrder.BIG_ENDIAN);
        byte[] bArr = G;
        bVar.d(bArr.length);
        int length = bArr.length + 0;
        while (true) {
            try {
                int readInt = bVar.readInt();
                int i10 = length + 4;
                byte[] bArr2 = new byte[4];
                if (bVar.read(bArr2) != 4) {
                    throw new IOException("Encountered invalid length while parsing PNG chunktype");
                }
                int i11 = i10 + 4;
                if (i11 == 16 && !Arrays.equals(bArr2, I)) {
                    throw new IOException("Encountered invalid PNG file--IHDR chunk should appearas the first chunk");
                }
                if (Arrays.equals(bArr2, J)) {
                    return;
                }
                if (Arrays.equals(bArr2, H)) {
                    byte[] bArr3 = new byte[readInt];
                    if (bVar.read(bArr3) != readInt) {
                        throw new IOException("Failed to read given length for given PNG chunk type: " + androidx.exifinterface.media.b.a(bArr2));
                    }
                    int readInt2 = bVar.readInt();
                    CRC32 crc32 = new CRC32();
                    crc32.update(bArr2);
                    crc32.update(bArr3);
                    if (((int) crc32.getValue()) == readInt2) {
                        this.f4373p = i11;
                        F(bArr3, 0);
                        N();
                        J(new b(bArr3));
                        return;
                    }
                    throw new IOException("Encountered invalid CRC value for PNG-EXIF chunk.\n recorded CRC value: " + readInt2 + ", calculated CRC value: " + crc32.getValue());
                }
                int i12 = readInt + 4;
                bVar.d(i12);
                length = i11 + i12;
            } catch (EOFException unused) {
                throw new IOException("Encountered corrupt PNG file.");
            }
        }
    }

    private void j(b bVar) {
        boolean z10 = f4351u;
        if (z10) {
            Log.d("ExifInterface", "getRafAttributes starting with: " + bVar);
        }
        bVar.d(84);
        byte[] bArr = new byte[4];
        byte[] bArr2 = new byte[4];
        byte[] bArr3 = new byte[4];
        bVar.read(bArr);
        bVar.read(bArr2);
        bVar.read(bArr3);
        int i10 = ByteBuffer.wrap(bArr).getInt();
        int i11 = ByteBuffer.wrap(bArr2).getInt();
        int i12 = ByteBuffer.wrap(bArr3).getInt();
        byte[] bArr4 = new byte[i11];
        bVar.d(i10 - bVar.a());
        bVar.read(bArr4);
        f(new b(bArr4), i10, 5);
        bVar.d(i12 - bVar.a());
        bVar.c(ByteOrder.BIG_ENDIAN);
        int readInt = bVar.readInt();
        if (z10) {
            Log.d("ExifInterface", "numberOfDirectoryEntry: " + readInt);
        }
        for (int i13 = 0; i13 < readInt; i13++) {
            int readUnsignedShort = bVar.readUnsignedShort();
            int readUnsignedShort2 = bVar.readUnsignedShort();
            if (readUnsignedShort == f4334d0.f4391a) {
                short readShort = bVar.readShort();
                short readShort2 = bVar.readShort();
                c f10 = c.f(readShort, this.f4365h);
                c f11 = c.f(readShort2, this.f4365h);
                this.f4363f[0].put("ImageLength", f10);
                this.f4363f[0].put("ImageWidth", f11);
                if (f4351u) {
                    Log.d("ExifInterface", "Updated to length: " + ((int) readShort) + ", width: " + ((int) readShort2));
                    return;
                }
                return;
            }
            bVar.d(readUnsignedShort2);
        }
    }

    private void k(f fVar) {
        c cVar;
        C(fVar);
        G(fVar, 0);
        M(fVar, 0);
        M(fVar, 5);
        M(fVar, 4);
        N();
        if (this.f4361d != 8 || (cVar = (c) this.f4363f[1].get("MakerNote")) == null) {
            return;
        }
        f fVar2 = new f(cVar.f4390d);
        fVar2.c(this.f4365h);
        fVar2.d(6);
        G(fVar2, 9);
        c cVar2 = (c) this.f4363f[9].get("ColorSpace");
        if (cVar2 != null) {
            this.f4363f[1].put("ColorSpace", cVar2);
        }
    }

    private void l(f fVar) {
        if (f4351u) {
            Log.d("ExifInterface", "getRw2Attributes starting with: " + fVar);
        }
        k(fVar);
        c cVar = (c) this.f4363f[0].get("JpgFromRaw");
        if (cVar != null) {
            f(new b(cVar.f4390d), (int) cVar.f4389c, 5);
        }
        c cVar2 = (c) this.f4363f[0].get("ISO");
        c cVar3 = (c) this.f4363f[1].get("PhotographicSensitivity");
        if (cVar2 == null || cVar3 != null) {
            return;
        }
        this.f4363f[1].put("PhotographicSensitivity", cVar2);
    }

    private void m(f fVar) {
        byte[] bArr = f4346p0;
        fVar.d(bArr.length);
        byte[] bArr2 = new byte[fVar.available()];
        fVar.readFully(bArr2);
        this.f4373p = bArr.length;
        F(bArr2, 0);
    }

    private void n(b bVar) {
        if (f4351u) {
            Log.d("ExifInterface", "getWebpAttributes starting with: " + bVar);
        }
        bVar.c(ByteOrder.LITTLE_ENDIAN);
        bVar.d(K.length);
        int readInt = bVar.readInt() + 8;
        byte[] bArr = L;
        bVar.d(bArr.length);
        int length = bArr.length + 8;
        while (true) {
            try {
                byte[] bArr2 = new byte[4];
                if (bVar.read(bArr2) != 4) {
                    throw new IOException("Encountered invalid length while parsing WebP chunktype");
                }
                int readInt2 = bVar.readInt();
                int i10 = length + 4 + 4;
                if (Arrays.equals(M, bArr2)) {
                    byte[] bArr3 = new byte[readInt2];
                    if (bVar.read(bArr3) == readInt2) {
                        this.f4373p = i10;
                        F(bArr3, 0);
                        J(new b(bArr3));
                        return;
                    } else {
                        throw new IOException("Failed to read given length for given PNG chunk type: " + androidx.exifinterface.media.b.a(bArr2));
                    }
                }
                if (readInt2 % 2 == 1) {
                    readInt2++;
                }
                length = i10 + readInt2;
                if (length == readInt) {
                    return;
                }
                if (length > readInt) {
                    throw new IOException("Encountered WebP file with invalid chunk size");
                }
                bVar.d(readInt2);
            } catch (EOFException unused) {
                throw new IOException("Encountered corrupt WebP file.");
            }
        }
    }

    private void o(b bVar, HashMap hashMap) {
        c cVar = (c) hashMap.get("JPEGInterchangeFormat");
        c cVar2 = (c) hashMap.get("JPEGInterchangeFormatLength");
        if (cVar == null || cVar2 == null) {
            return;
        }
        int i10 = cVar.i(this.f4365h);
        int i11 = cVar2.i(this.f4365h);
        if (this.f4361d == 7) {
            i10 += this.f4374q;
        }
        if (i10 > 0 && i11 > 0) {
            this.f4366i = true;
            if (this.f4358a == null && this.f4360c == null && this.f4359b == null) {
                byte[] bArr = new byte[i11];
                bVar.skip(i10);
                bVar.read(bArr);
                this.f4371n = bArr;
            }
            this.f4369l = i10;
            this.f4370m = i11;
        }
        if (f4351u) {
            Log.d("ExifInterface", "Setting thumbnail attributes with offset: " + i10 + ", length: " + i11);
        }
    }

    private void p(b bVar, HashMap hashMap) {
        c cVar = (c) hashMap.get("StripOffsets");
        c cVar2 = (c) hashMap.get("StripByteCounts");
        if (cVar == null || cVar2 == null) {
            return;
        }
        long[] b10 = androidx.exifinterface.media.b.b(cVar.k(this.f4365h));
        long[] b11 = androidx.exifinterface.media.b.b(cVar2.k(this.f4365h));
        if (b10 == null || b10.length == 0) {
            Log.w("ExifInterface", "stripOffsets should not be null or have zero length.");
            return;
        }
        if (b11 == null || b11.length == 0) {
            Log.w("ExifInterface", "stripByteCounts should not be null or have zero length.");
            return;
        }
        if (b10.length != b11.length) {
            Log.w("ExifInterface", "stripOffsets and stripByteCounts should have same length.");
            return;
        }
        long j10 = 0;
        for (long j11 : b11) {
            j10 += j11;
        }
        int i10 = (int) j10;
        byte[] bArr = new byte[i10];
        this.f4368k = true;
        this.f4367j = true;
        this.f4366i = true;
        int i11 = 0;
        int i12 = 0;
        for (int i13 = 0; i13 < b10.length; i13++) {
            int i14 = (int) b10[i13];
            int i15 = (int) b11[i13];
            if (i13 < b10.length - 1 && i14 + i15 != b10[i13 + 1]) {
                this.f4368k = false;
            }
            int i16 = i14 - i11;
            if (i16 < 0) {
                Log.d("ExifInterface", "Invalid strip offset value");
                return;
            }
            long j12 = i16;
            if (bVar.skip(j12) != j12) {
                Log.d("ExifInterface", "Failed to skip " + i16 + " bytes.");
                return;
            }
            int i17 = i11 + i16;
            byte[] bArr2 = new byte[i15];
            if (bVar.read(bArr2) != i15) {
                Log.d("ExifInterface", "Failed to read " + i15 + " bytes.");
                return;
            }
            i11 = i17 + i15;
            System.arraycopy(bArr2, 0, bArr, i12, i15);
            i12 += i15;
        }
        this.f4371n = bArr;
        if (this.f4368k) {
            this.f4369l = (int) b10[0];
            this.f4370m = i10;
        }
    }

    private static boolean q(BufferedInputStream bufferedInputStream) {
        byte[] bArr = f4346p0;
        bufferedInputStream.mark(bArr.length);
        byte[] bArr2 = new byte[bArr.length];
        bufferedInputStream.read(bArr2);
        bufferedInputStream.reset();
        int i10 = 0;
        while (true) {
            byte[] bArr3 = f4346p0;
            if (i10 >= bArr3.length) {
                return true;
            }
            if (bArr2[i10] != bArr3[i10]) {
                return false;
            }
            i10++;
        }
    }

    private boolean r(byte[] bArr) {
        b bVar;
        long readInt;
        byte[] bArr2;
        long j10;
        b bVar2 = null;
        try {
            try {
                bVar = new b(bArr);
            } catch (Exception e10) {
                e = e10;
            }
        } catch (Throwable th2) {
            th = th2;
        }
        try {
            readInt = bVar.readInt();
            bArr2 = new byte[4];
            bVar.read(bArr2);
        } catch (Exception e11) {
            e = e11;
            bVar2 = bVar;
            if (f4351u) {
                Log.d("ExifInterface", "Exception parsing HEIF file type box.", e);
            }
            if (bVar2 != null) {
                bVar2.close();
            }
            return false;
        } catch (Throwable th3) {
            th = th3;
            bVar2 = bVar;
            if (bVar2 != null) {
                bVar2.close();
            }
            throw th;
        }
        if (!Arrays.equals(bArr2, B)) {
            bVar.close();
            return false;
        }
        if (readInt == 1) {
            readInt = bVar.readLong();
            j10 = 16;
            if (readInt < 16) {
                bVar.close();
                return false;
            }
        } else {
            j10 = 8;
        }
        if (readInt > bArr.length) {
            readInt = bArr.length;
        }
        long j11 = readInt - j10;
        if (j11 < 8) {
            bVar.close();
            return false;
        }
        byte[] bArr3 = new byte[4];
        boolean z10 = false;
        boolean z11 = false;
        for (long j12 = 0; j12 < j11 / 4; j12++) {
            if (bVar.read(bArr3) != 4) {
                bVar.close();
                return false;
            }
            if (j12 != 1) {
                if (Arrays.equals(bArr3, C)) {
                    z10 = true;
                } else if (Arrays.equals(bArr3, D)) {
                    z11 = true;
                }
                if (z10 && z11) {
                    bVar.close();
                    return true;
                }
            }
        }
        bVar.close();
        return false;
    }

    private static boolean s(byte[] bArr) {
        int i10 = 0;
        while (true) {
            byte[] bArr2 = A;
            if (i10 >= bArr2.length) {
                return true;
            }
            if (bArr[i10] != bArr2[i10]) {
                return false;
            }
            i10++;
        }
    }

    private boolean t(byte[] bArr) {
        b bVar = null;
        try {
            b bVar2 = new b(bArr);
            try {
                ByteOrder E2 = E(bVar2);
                this.f4365h = E2;
                bVar2.c(E2);
                short readShort = bVar2.readShort();
                boolean z10 = readShort == 20306 || readShort == 21330;
                bVar2.close();
                return z10;
            } catch (Exception unused) {
                bVar = bVar2;
                if (bVar != null) {
                    bVar.close();
                }
                return false;
            } catch (Throwable th2) {
                th = th2;
                bVar = bVar2;
                if (bVar != null) {
                    bVar.close();
                }
                throw th;
            }
        } catch (Exception unused2) {
        } catch (Throwable th3) {
            th = th3;
        }
    }

    private boolean u(byte[] bArr) {
        int i10 = 0;
        while (true) {
            byte[] bArr2 = G;
            if (i10 >= bArr2.length) {
                return true;
            }
            if (bArr[i10] != bArr2[i10]) {
                return false;
            }
            i10++;
        }
    }

    private boolean v(byte[] bArr) {
        byte[] bytes = "FUJIFILMCCD-RAW".getBytes(Charset.defaultCharset());
        for (int i10 = 0; i10 < bytes.length; i10++) {
            if (bArr[i10] != bytes[i10]) {
                return false;
            }
        }
        return true;
    }

    private boolean w(byte[] bArr) {
        b bVar = null;
        try {
            b bVar2 = new b(bArr);
            try {
                ByteOrder E2 = E(bVar2);
                this.f4365h = E2;
                bVar2.c(E2);
                boolean z10 = bVar2.readShort() == 85;
                bVar2.close();
                return z10;
            } catch (Exception unused) {
                bVar = bVar2;
                if (bVar != null) {
                    bVar.close();
                }
                return false;
            } catch (Throwable th2) {
                th = th2;
                bVar = bVar2;
                if (bVar != null) {
                    bVar.close();
                }
                throw th;
            }
        } catch (Exception unused2) {
        } catch (Throwable th3) {
            th = th3;
        }
    }

    private static boolean x(FileDescriptor fileDescriptor) {
        try {
            b.a.c(fileDescriptor, 0L, OsConstants.SEEK_CUR);
            return true;
        } catch (Exception unused) {
            if (!f4351u) {
                return false;
            }
            Log.d("ExifInterface", "The file descriptor for the given input is not seekable");
            return false;
        }
    }

    private boolean y(HashMap hashMap) {
        c cVar;
        int i10;
        c cVar2 = (c) hashMap.get("BitsPerSample");
        if (cVar2 != null) {
            int[] iArr = (int[]) cVar2.k(this.f4365h);
            int[] iArr2 = f4355x;
            if (Arrays.equals(iArr2, iArr)) {
                return true;
            }
            if (this.f4361d == 3 && (cVar = (c) hashMap.get("PhotometricInterpretation")) != null && (((i10 = cVar.i(this.f4365h)) == 1 && Arrays.equals(iArr, f4357z)) || (i10 == 6 && Arrays.equals(iArr, iArr2)))) {
                return true;
            }
        }
        if (!f4351u) {
            return false;
        }
        Log.d("ExifInterface", "Unsupported data type value");
        return false;
    }

    private boolean z(HashMap hashMap) {
        c cVar = (c) hashMap.get("ImageLength");
        c cVar2 = (c) hashMap.get("ImageWidth");
        if (cVar == null || cVar2 == null) {
            return false;
        }
        return cVar.i(this.f4365h) <= 512 && cVar2.i(this.f4365h) <= 512;
    }

    public String b(String str) {
        if (str == null) {
            throw new NullPointerException("tag shouldn't be null");
        }
        c d10 = d(str);
        if (d10 != null) {
            if (!f4343m0.contains(str)) {
                return d10.j(this.f4365h);
            }
            if (str.equals("GPSTimeStamp")) {
                int i10 = d10.f4387a;
                if (i10 != 5 && i10 != 10) {
                    Log.w("ExifInterface", "GPS Timestamp format is not rational. format=" + d10.f4387a);
                    return null;
                }
                e[] eVarArr = (e[]) d10.k(this.f4365h);
                if (eVarArr == null || eVarArr.length != 3) {
                    Log.w("ExifInterface", "Invalid GPS Timestamp array. array=" + Arrays.toString(eVarArr));
                    return null;
                }
                e eVar = eVarArr[0];
                Integer valueOf = Integer.valueOf((int) (((float) eVar.f4395a) / ((float) eVar.f4396b)));
                e eVar2 = eVarArr[1];
                Integer valueOf2 = Integer.valueOf((int) (((float) eVar2.f4395a) / ((float) eVar2.f4396b)));
                e eVar3 = eVarArr[2];
                return String.format("%02d:%02d:%02d", valueOf, valueOf2, Integer.valueOf((int) (((float) eVar3.f4395a) / ((float) eVar3.f4396b))));
            }
            try {
                return Double.toString(d10.h(this.f4365h));
            } catch (NumberFormatException unused) {
            }
        }
        return null;
    }

    public int c(String str, int i10) {
        if (str == null) {
            throw new NullPointerException("tag shouldn't be null");
        }
        c d10 = d(str);
        if (d10 == null) {
            return i10;
        }
        try {
            return d10.i(this.f4365h);
        } catch (NumberFormatException unused) {
            return i10;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class f extends b {
        f(byte[] bArr) {
            super(bArr);
            this.f4383p.mark(Api.BaseClientBuilder.API_PRIORITY_OTHER);
        }

        public void e(long j10) {
            int i10 = this.f4385r;
            if (i10 > j10) {
                this.f4385r = 0;
                this.f4383p.reset();
            } else {
                j10 -= i10;
            }
            d((int) j10);
        }

        f(InputStream inputStream) {
            super(inputStream);
            if (inputStream.markSupported()) {
                this.f4383p.mark(Api.BaseClientBuilder.API_PRIORITY_OTHER);
                return;
            }
            throw new IllegalArgumentException("Cannot create SeekableByteOrderedDataInputStream with stream that does not support mark/reset");
        }
    }

    public a(InputStream inputStream, int i10) {
        d[][] dVarArr = f4339i0;
        this.f4363f = new HashMap[dVarArr.length];
        this.f4364g = new HashSet(dVarArr.length);
        this.f4365h = ByteOrder.BIG_ENDIAN;
        if (inputStream != null) {
            this.f4358a = null;
            if (i10 == 1) {
                BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, f4346p0.length);
                if (!q(bufferedInputStream)) {
                    Log.w("ExifInterface", "Given data does not follow the structure of an Exif-only data.");
                    return;
                }
                this.f4362e = true;
                this.f4360c = null;
                this.f4359b = null;
                inputStream = bufferedInputStream;
            } else if (inputStream instanceof AssetManager.AssetInputStream) {
                this.f4360c = (AssetManager.AssetInputStream) inputStream;
                this.f4359b = null;
            } else {
                if (inputStream instanceof FileInputStream) {
                    FileInputStream fileInputStream = (FileInputStream) inputStream;
                    if (x(fileInputStream.getFD())) {
                        this.f4360c = null;
                        this.f4359b = fileInputStream.getFD();
                    }
                }
                this.f4360c = null;
                this.f4359b = null;
            }
            B(inputStream);
            return;
        }
        throw new NullPointerException("inputStream cannot be null");
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class d {

        /* renamed from: a, reason: collision with root package name */
        public final int f4391a;

        /* renamed from: b, reason: collision with root package name */
        public final String f4392b;

        /* renamed from: c, reason: collision with root package name */
        public final int f4393c;

        /* renamed from: d, reason: collision with root package name */
        public final int f4394d;

        d(String str, int i10, int i11) {
            this.f4392b = str;
            this.f4391a = i10;
            this.f4393c = i11;
            this.f4394d = -1;
        }

        boolean a(int i10) {
            int i11;
            int i12 = this.f4393c;
            if (i12 == 7 || i10 == 7 || i12 == i10 || (i11 = this.f4394d) == i10) {
                return true;
            }
            if ((i12 == 4 || i11 == 4) && i10 == 3) {
                return true;
            }
            if ((i12 == 9 || i11 == 9) && i10 == 8) {
                return true;
            }
            return (i12 == 12 || i11 == 12) && i10 == 11;
        }

        d(String str, int i10, int i11, int i12) {
            this.f4392b = str;
            this.f4391a = i10;
            this.f4393c = i11;
            this.f4394d = i12;
        }
    }
}
