导航菜单

页面标题

页面副标题

Minits v4.9.3.32 - C1889a.java 源代码

正在查看: Minits v4.9.3.32 应用的 C1889a.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package b1;

import android.content.res.AssetManager;
import android.location.Location;
import android.media.MediaDataSource;
import android.media.MediaMetadataRetriever;
import android.os.Build;
import android.system.Os;
import android.system.OsConstants;
import android.util.Log;
import android.util.Pair;
import b1.AbstractC1890b;
import j$.util.DesugarCollections;
import j$.util.DesugarTimeZone;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.CRC32;
import org.mozilla.javascript.Context;

public class C1889a {

    public static final SimpleDateFormat f19967V;

    public static final SimpleDateFormat f19968W;

    public static final e[] f19972a0;

    public static final e[] f19973b0;

    public static final e[] f19974c0;

    public static final e[] f19975d0;

    public static final e[] f19976e0;

    public static final e f19977f0;

    public static final e[] f19978g0;

    public static final e[] f19979h0;

    public static final e[] f19980i0;

    public static final e[] f19981j0;

    public static final e[][] f19982k0;

    public static final e[] f19983l0;

    public static final HashMap[] f19984m0;

    public static final HashMap[] f19985n0;

    public static final Set f19986o0;

    public static final HashMap f19987p0;

    public static final Charset f19988q0;

    public static final byte[] f19989r0;

    public static final byte[] f19990s0;

    public static final Pattern f19991t0;

    public static final Pattern f19992u0;

    public static final Pattern f19993v0;

    public static final Pattern f19995w0;

    public String f19999a;

    public FileDescriptor f20000b;

    public AssetManager.AssetInputStream f20001c;

    public int f20002d;

    public boolean f20003e;

    public final HashMap[] f20004f;

    public Set f20005g;

    public ByteOrder f20006h;

    public boolean f20007i;

    public boolean f20008j;

    public boolean f20009k;

    public int f20010l;

    public int f20011m;

    public byte[] f20012n;

    public int f20013o;

    public int f20014p;

    public int f20015q;

    public int f20016r;

    public int f20017s;

    public boolean f20018t;

    public d f20019u;

    public boolean f20020v;

    public static final boolean f19994w = Log.isLoggable("ExifInterface", 3);

    public static final List f19996x = Arrays.asList(1, 6, 3, 8);

    public static final List f19997y = Arrays.asList(2, 7, 4, 5);

    public static final int[] f19998z = {8, 8, 8};

    public static final int[] f19946A = {4};

    public static final int[] f19947B = {8};

    public static final byte[] f19948C = {-1, -40, -1};

    public static final byte[] f19949D = {102, 116, 121, 112};

    public static final byte[] f19950E = {109, 105, 102, 49};

    public static final byte[] f19951F = {104, 101, 105, 99};

    public static final byte[] f19952G = {97, 118, 105, 102};

    public static final byte[] f19953H = {97, 118, 105, 115};

    public static final byte[] f19954I = {79, 76, 89, 77, 80, 0};

    public static final byte[] f19955J = {79, 76, 89, 77, 80, 85, 83, 0, 73, 73};

    public static final byte[] f19956K = {-119, 80, 78, 71, 13, 10, 26, 10};

    public static final byte[] f19957L = "XML:com.adobe.xmp\u0000\u0000\u0000\u0000\u0000".getBytes(StandardCharsets.UTF_8);

    public static final byte[] f19958M = {82, 73, 70, 70};

    public static final byte[] f19959N = {87, 69, 66, 80};

    public static final byte[] f19960O = {69, 88, 73, 70};

    public static final byte[] f19961P = {-99, 1, 42};

    public static final byte[] f19962Q = "VP8X".getBytes(Charset.defaultCharset());

    public static final byte[] f19963R = "VP8L".getBytes(Charset.defaultCharset());

    public static final byte[] f19964S = "VP8 ".getBytes(Charset.defaultCharset());

    public static final byte[] f19965T = "ANIM".getBytes(Charset.defaultCharset());

    public static final byte[] f19966U = "ANMF".getBytes(Charset.defaultCharset());

    public static final String[] f19969X = {"", "BYTE", "STRING", "USHORT", "ULONG", "URATIONAL", "SBYTE", "UNDEFINED", "SSHORT", "SLONG", "SRATIONAL", "SINGLE", "DOUBLE", "IFD"};

    public static final int[] f19970Y = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 1};

    public static final byte[] f19971Z = {65, 83, 67, 73, 73, 0, 0, 0};

    public static class c extends FilterOutputStream {

        public final DataOutputStream f20029l;

        public ByteOrder f20030m;

        public c(OutputStream outputStream, ByteOrder byteOrder) {
            super(outputStream);
            this.f20029l = new DataOutputStream(outputStream);
            this.f20030m = byteOrder;
        }

        public void a(ByteOrder byteOrder) {
            this.f20030m = byteOrder;
        }

        public void b(int i10) {
            this.f20029l.write(i10);
        }

        public void c(int i10) {
            ByteOrder byteOrder = this.f20030m;
            if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
                this.f20029l.write(i10 & 255);
                this.f20029l.write((i10 >>> 8) & 255);
                this.f20029l.write((i10 >>> 16) & 255);
                this.f20029l.write((i10 >>> 24) & 255);
                return;
            }
            if (byteOrder == ByteOrder.BIG_ENDIAN) {
                this.f20029l.write((i10 >>> 24) & 255);
                this.f20029l.write((i10 >>> 16) & 255);
                this.f20029l.write((i10 >>> 8) & 255);
                this.f20029l.write(i10 & 255);
            }
        }

        public void e(short s10) {
            ByteOrder byteOrder = this.f20030m;
            if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
                this.f20029l.write(s10 & 255);
                this.f20029l.write((s10 >>> 8) & 255);
            } else if (byteOrder == ByteOrder.BIG_ENDIAN) {
                this.f20029l.write((s10 >>> 8) & 255);
                this.f20029l.write(s10 & 255);
            }
        }

        public void f(long j10) {
            if (j10 > 4294967295L) {
                throw new IllegalArgumentException("val is larger than the maximum value of a 32-bit unsigned integer");
            }
            c((int) j10);
        }

        public void h(int i10) {
            if (i10 > 65535) {
                throw new IllegalArgumentException("val is larger than the maximum value of a 16-bit unsigned integer");
            }
            e((short) i10);
        }

        @Override
        public void write(byte[] bArr) {
            this.f20029l.write(bArr);
        }

        @Override
        public void write(byte[] bArr, int i10, int i11) {
            this.f20029l.write(bArr, i10, i11);
        }
    }

    public static class d {

        public final int f20031a;

        public final int f20032b;

        public final long f20033c;

        public final byte[] f20034d;

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

        public static d a(String str) {
            if (str.length() == 1 && str.charAt(0) >= '0' && str.charAt(0) <= '1') {
                return new d(1, 1, new byte[]{(byte) (str.charAt(0) - '0')});
            }
            byte[] bytes = str.getBytes(C1889a.f19988q0);
            return new d(1, bytes.length, bytes);
        }

        public static d b(double[] dArr, ByteOrder byteOrder) {
            ByteBuffer wrap = ByteBuffer.wrap(new byte[C1889a.f19970Y[12] * dArr.length]);
            wrap.order(byteOrder);
            for (double d10 : dArr) {
                wrap.putDouble(d10);
            }
            return new d(12, dArr.length, wrap.array());
        }

        public static d c(int[] iArr, ByteOrder byteOrder) {
            ByteBuffer wrap = ByteBuffer.wrap(new byte[C1889a.f19970Y[9] * iArr.length]);
            wrap.order(byteOrder);
            for (int i10 : iArr) {
                wrap.putInt(i10);
            }
            return new d(9, iArr.length, wrap.array());
        }

        public static d d(f[] fVarArr, ByteOrder byteOrder) {
            ByteBuffer wrap = ByteBuffer.wrap(new byte[C1889a.f19970Y[10] * fVarArr.length]);
            wrap.order(byteOrder);
            for (f fVar : fVarArr) {
                wrap.putInt((int) fVar.f20039a);
                wrap.putInt((int) fVar.f20040b);
            }
            return new d(10, fVarArr.length, wrap.array());
        }

        public static d e(String str) {
            byte[] bytes = (str + (char) 0).getBytes(C1889a.f19988q0);
            return new d(2, bytes.length, bytes);
        }

        public static d f(long j10, ByteOrder byteOrder) {
            return g(new long[]{j10}, byteOrder);
        }

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

        public static d h(f fVar, ByteOrder byteOrder) {
            return i(new f[]{fVar}, byteOrder);
        }

        public static d i(f[] fVarArr, ByteOrder byteOrder) {
            ByteBuffer wrap = ByteBuffer.wrap(new byte[C1889a.f19970Y[5] * fVarArr.length]);
            wrap.order(byteOrder);
            for (f fVar : fVarArr) {
                wrap.putInt((int) fVar.f20039a);
                wrap.putInt((int) fVar.f20040b);
            }
            return new d(5, fVarArr.length, wrap.array());
        }

        public static d j(int i10, ByteOrder byteOrder) {
            return k(new int[]{i10}, byteOrder);
        }

        public static d k(int[] iArr, ByteOrder byteOrder) {
            ByteBuffer wrap = ByteBuffer.wrap(new byte[C1889a.f19970Y[3] * iArr.length]);
            wrap.order(byteOrder);
            for (int i10 : iArr) {
                wrap.putShort((short) i10);
            }
            return new d(3, iArr.length, wrap.array());
        }

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

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

        public String n(ByteOrder byteOrder) {
            Object o10 = o(byteOrder);
            if (o10 == null) {
                return null;
            }
            if (o10 instanceof String) {
                return (String) o10;
            }
            StringBuilder sb2 = new StringBuilder();
            int i10 = 0;
            if (o10 instanceof long[]) {
                long[] jArr = (long[]) o10;
                while (i10 < jArr.length) {
                    sb2.append(jArr[i10]);
                    i10++;
                    if (i10 != jArr.length) {
                        sb2.append(",");
                    }
                }
                return sb2.toString();
            }
            if (o10 instanceof int[]) {
                int[] iArr = (int[]) o10;
                while (i10 < iArr.length) {
                    sb2.append(iArr[i10]);
                    i10++;
                    if (i10 != iArr.length) {
                        sb2.append(",");
                    }
                }
                return sb2.toString();
            }
            if (o10 instanceof double[]) {
                double[] dArr = (double[]) o10;
                while (i10 < dArr.length) {
                    sb2.append(dArr[i10]);
                    i10++;
                    if (i10 != dArr.length) {
                        sb2.append(",");
                    }
                }
                return sb2.toString();
            }
            if (!(o10 instanceof f[])) {
                return null;
            }
            f[] fVarArr = (f[]) o10;
            while (i10 < fVarArr.length) {
                sb2.append(fVarArr[i10].f20039a);
                sb2.append('/');
                sb2.append(fVarArr[i10].f20040b);
                i10++;
                if (i10 != fVarArr.length) {
                    sb2.append(",");
                }
            }
            return sb2.toString();
        }

        public Object o(ByteOrder byteOrder) {
            Throwable th;
            IOException iOException;
            b bVar;
            InputStream inputStream;
            byte b10;
            byte b11;
            String str;
            InputStream inputStream2 = null;
            try {
                try {
                    bVar = new b(this.f20034d);
                    try {
                        bVar.f(byteOrder);
                        int i10 = 0;
                        switch (this.f20031a) {
                            case 1:
                            case 6:
                                byte[] bArr = this.f20034d;
                                if (bArr.length == 1 && (b10 = bArr[0]) >= 0 && b10 <= 1) {
                                    str = new String(new char[]{(char) (b10 + 48)});
                                    break;
                                } else {
                                    String str2 = new String(bArr, C1889a.f19988q0);
                                    try {
                                        bVar.close();
                                        return str2;
                                    } catch (IOException e10) {
                                        Log.e("ExifInterface", "IOException occurred while closing InputStream", e10);
                                        return str2;
                                    }
                                }
                                break;
                            case 2:
                            case Context.FEATURE_DYNAMIC_SCOPE:
                                if (this.f20032b >= C1889a.f19971Z.length) {
                                    int i11 = 0;
                                    while (true) {
                                        if (i11 >= C1889a.f19971Z.length) {
                                            i10 = C1889a.f19971Z.length;
                                        } else if (this.f20034d[i11] == C1889a.f19971Z[i11]) {
                                            i11++;
                                        }
                                    }
                                }
                                StringBuilder sb2 = new StringBuilder();
                                while (i10 < this.f20032b && (b11 = this.f20034d[i10]) != 0) {
                                    if (b11 >= 32) {
                                        sb2.append((char) b11);
                                    } else {
                                        sb2.append('?');
                                    }
                                    i10++;
                                }
                                str = sb2.toString();
                                break;
                            case 3:
                                ?? r13 = new int[this.f20032b];
                                while (true) {
                                    str = r13;
                                    if (i10 < this.f20032b) {
                                        r13[i10] = bVar.readUnsignedShort();
                                        i10++;
                                    }
                                }
                                break;
                            case 4:
                                ?? r132 = new long[this.f20032b];
                                while (true) {
                                    str = r132;
                                    if (i10 < this.f20032b) {
                                        r132[i10] = bVar.e();
                                        i10++;
                                    }
                                }
                                break;
                            case 5:
                                ?? r133 = new f[this.f20032b];
                                while (true) {
                                    str = r133;
                                    if (i10 < this.f20032b) {
                                        r133[i10] = new f(bVar.e(), bVar.e(), null);
                                        i10++;
                                    }
                                }
                                break;
                            case 8:
                                ?? r134 = new int[this.f20032b];
                                while (true) {
                                    str = r134;
                                    if (i10 < this.f20032b) {
                                        r134[i10] = bVar.readShort();
                                        i10++;
                                    }
                                }
                                break;
                            case Context.FEATURE_STRICT_EVAL:
                                ?? r135 = new int[this.f20032b];
                                while (true) {
                                    str = r135;
                                    if (i10 < this.f20032b) {
                                        r135[i10] = bVar.readInt();
                                        i10++;
                                    }
                                }
                                break;
                            case Context.FEATURE_LOCATION_INFORMATION_IN_ERROR:
                                ?? r136 = new f[this.f20032b];
                                while (true) {
                                    str = r136;
                                    if (i10 < this.f20032b) {
                                        r136[i10] = new f(bVar.readInt(), bVar.readInt(), null);
                                        i10++;
                                    }
                                }
                                break;
                            case Context.FEATURE_STRICT_MODE:
                                ?? r137 = new double[this.f20032b];
                                while (true) {
                                    str = r137;
                                    if (i10 < this.f20032b) {
                                        r137[i10] = bVar.readFloat();
                                        i10++;
                                    }
                                }
                                break;
                            case Context.FEATURE_WARNING_AS_ERROR:
                                ?? r138 = new double[this.f20032b];
                                while (true) {
                                    str = r138;
                                    if (i10 < this.f20032b) {
                                        r138[i10] = bVar.readDouble();
                                        i10++;
                                    }
                                }
                                break;
                            default:
                                try {
                                    bVar.close();
                                    return null;
                                } catch (IOException e11) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e11);
                                    return null;
                                }
                        }
                        try {
                            bVar.close();
                            return str;
                        } catch (IOException e12) {
                            Log.e("ExifInterface", "IOException occurred while closing InputStream", e12);
                            return str;
                        }
                    } catch (IOException e13) {
                        iOException = e13;
                        Log.w("ExifInterface", "IOException occurred during reading a value", iOException);
                        if (bVar != null) {
                            try {
                                bVar.close();
                            } catch (IOException e14) {
                                Log.e("ExifInterface", "IOException occurred while closing InputStream", e14);
                            }
                        }
                        return null;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    inputStream2 = inputStream;
                    if (inputStream2 != null) {
                        throw th;
                    }
                    try {
                        inputStream2.close();
                        throw th;
                    } catch (IOException e15) {
                        Log.e("ExifInterface", "IOException occurred while closing InputStream", e15);
                        throw th;
                    }
                }
            } catch (IOException e16) {
                iOException = e16;
                bVar = null;
            } catch (Throwable th3) {
                th = th3;
                if (inputStream2 != null) {
                }
            }
        }

        public int p() {
            return C1889a.f19970Y[this.f20031a] * this.f20032b;
        }

        public String toString() {
            return "(" + C1889a.f19969X[this.f20031a] + ", data length:" + this.f20034d.length + ")";
        }

        public d(int i10, int i11, long j10, byte[] bArr) {
            this.f20031a = i10;
            this.f20032b = i11;
            this.f20033c = j10;
            this.f20034d = bArr;
        }
    }

    public static class f {

        public final long f20039a;

        public final long f20040b;

        public f(long j10, long j11, C0134a c0134a) {
            this(j10, j11);
        }

        public static f b(double d10) {
            long j10;
            long j11;
            long j12 = 1;
            if (d10 >= 9.223372036854776E18d || d10 <= -9.223372036854776E18d) {
                return new f(d10 > 0.0d ? Long.MAX_VALUE : Long.MIN_VALUE, 1L);
            }
            double abs = Math.abs(d10);
            double d11 = 1.0E-8d * abs;
            long j13 = 0;
            double d12 = abs;
            long j14 = 1;
            long j15 = 0;
            while (true) {
                double d13 = d12 % 1.0d;
                long j16 = (long) (d12 - d13);
                j10 = (j16 * j12) + j15;
                j11 = (j16 * j13) + j14;
                double d14 = 1.0d / d13;
                double d15 = abs;
                if (Math.abs(d15 - (j10 / j11)) <= d11) {
                    break;
                }
                j15 = j12;
                j12 = j10;
                j14 = j13;
                j13 = j11;
                d12 = d14;
                abs = d15;
            }
            if (d10 < 0.0d) {
                j10 = -j10;
            }
            return new f(j10, j11);
        }

        public double a() {
            return this.f20039a / this.f20040b;
        }

        public String toString() {
            return this.f20039a + "/" + this.f20040b;
        }

        public f(long j10, long j11) {
            if (j11 == 0) {
                this.f20039a = 0L;
                this.f20040b = 1L;
            } else {
                this.f20039a = j10;
                this.f20040b = j11;
            }
        }
    }

    static {
        e[] eVarArr = {new e("NewSubfileType", 254, 4), new e("SubfileType", 255, 4), new e("ImageWidth", 256, 3, 4), new e("ImageLength", 257, 3, 4), new e("BitsPerSample", 258, 3), new e("Compression", 259, 3), new e("PhotometricInterpretation", 262, 3), new e("ImageDescription", 270, 2), new e("Make", 271, 2), new e("Model", 272, 2), new e("StripOffsets", 273, 3, 4), new e("Orientation", 274, 3), new e("SamplesPerPixel", 277, 3), new e("RowsPerStrip", 278, 3, 4), new e("StripByteCounts", 279, 3, 4), new e("XResolution", 282, 5), new e("YResolution", 283, 5), new e("PlanarConfiguration", 284, 3), new e("ResolutionUnit", 296, 3), new e("TransferFunction", 301, 3), new e("Software", 305, 2), new e("DateTime", 306, 2), new e("Artist", 315, 2), new e("WhitePoint", 318, 5), new e("PrimaryChromaticities", 319, 5), new e("SubIFDPointer", 330, 4), new e("JPEGInterchangeFormat", 513, 4), new e("JPEGInterchangeFormatLength", 514, 4), new e("YCbCrCoefficients", 529, 5), new e("YCbCrSubSampling", 530, 3), new e("YCbCrPositioning", 531, 3), new e("ReferenceBlackWhite", 532, 5), new e("Copyright", 33432, 2), new e("ExifIFDPointer", 34665, 4), new e("GPSInfoIFDPointer", 34853, 4), new e("SensorTopBorder", 4, 4), new e("SensorLeftBorder", 5, 4), new e("SensorBottomBorder", 6, 4), new e("SensorRightBorder", 7, 4), new e("ISO", 23, 3), new e("JpgFromRaw", 46, 7), new e("Xmp", 700, 1)};
        f19972a0 = eVarArr;
        e[] eVarArr2 = {new e("ExposureTime", 33434, 5), new e("FNumber", 33437, 5), new e("ExposureProgram", 34850, 3), new e("SpectralSensitivity", 34852, 2), new e("PhotographicSensitivity", 34855, 3), new e("OECF", 34856, 7), new e("SensitivityType", 34864, 3), new e("StandardOutputSensitivity", 34865, 4), new e("RecommendedExposureIndex", 34866, 4), new e("ISOSpeed", 34867, 4), new e("ISOSpeedLatitudeyyy", 34868, 4), new e("ISOSpeedLatitudezzz", 34869, 4), new e("ExifVersion", 36864, 2), new e("DateTimeOriginal", 36867, 2), new e("DateTimeDigitized", 36868, 2), new e("OffsetTime", 36880, 2), new e("OffsetTimeOriginal", 36881, 2), new e("OffsetTimeDigitized", 36882, 2), new e("ComponentsConfiguration", 37121, 7), new e("CompressedBitsPerPixel", 37122, 5), new e("ShutterSpeedValue", 37377, 10), new e("ApertureValue", 37378, 5), new e("BrightnessValue", 37379, 10), new e("ExposureBiasValue", 37380, 10), new e("MaxApertureValue", 37381, 5), new e("SubjectDistance", 37382, 5), new e("MeteringMode", 37383, 3), new e("LightSource", 37384, 3), new e("Flash", 37385, 3), new e("FocalLength", 37386, 5), new e("SubjectArea", 37396, 3), new e("MakerNote", 37500, 7), new e("UserComment", 37510, 7), new e("SubSecTime", 37520, 2), new e("SubSecTimeOriginal", 37521, 2), new e("SubSecTimeDigitized", 37522, 2), new e("FlashpixVersion", 40960, 7), new e("ColorSpace", 40961, 3), new e("PixelXDimension", 40962, 3, 4), new e("PixelYDimension", 40963, 3, 4), new e("RelatedSoundFile", 40964, 2), new e("InteroperabilityIFDPointer", 40965, 4), new e("FlashEnergy", 41483, 5), new e("SpatialFrequencyResponse", 41484, 7), new e("FocalPlaneXResolution", 41486, 5), new e("FocalPlaneYResolution", 41487, 5), new e("FocalPlaneResolutionUnit", 41488, 3), new e("SubjectLocation", 41492, 3), new e("ExposureIndex", 41493, 5), new e("SensingMethod", 41495, 3), new e("FileSource", 41728, 7), new e("SceneType", 41729, 7), new e("CFAPattern", 41730, 7), new e("CustomRendered", 41985, 3), new e("ExposureMode", 41986, 3), new e("WhiteBalance", 41987, 3), new e("DigitalZoomRatio", 41988, 5), new e("FocalLengthIn35mmFilm", 41989, 3), new e("SceneCaptureType", 41990, 3), new e("GainControl", 41991, 3), new e("Contrast", 41992, 3), new e("Saturation", 41993, 3), new e("Sharpness", 41994, 3), new e("DeviceSettingDescription", 41995, 7), new e("SubjectDistanceRange", 41996, 3), new e("ImageUniqueID", 42016, 2), new e("CameraOwnerName", 42032, 2), new e("BodySerialNumber", 42033, 2), new e("LensSpecification", 42034, 5), new e("LensMake", 42035, 2), new e("LensModel", 42036, 2), new e("Gamma", 42240, 5), new e("DNGVersion", 50706, 1), new e("DefaultCropSize", 50720, 3, 4)};
        f19973b0 = eVarArr2;
        e[] eVarArr3 = {new e("GPSVersionID", 0, 1), new e("GPSLatitudeRef", 1, 2), new e("GPSLatitude", 2, 5, 10), new e("GPSLongitudeRef", 3, 2), new e("GPSLongitude", 4, 5, 10), new e("GPSAltitudeRef", 5, 1), new e("GPSAltitude", 6, 5), new e("GPSTimeStamp", 7, 5), new e("GPSSatellites", 8, 2), new e("GPSStatus", 9, 2), new e("GPSMeasureMode", 10, 2), new e("GPSDOP", 11, 5), new e("GPSSpeedRef", 12, 2), new e("GPSSpeed", 13, 5), new e("GPSTrackRef", 14, 2), new e("GPSTrack", 15, 5), new e("GPSImgDirectionRef", 16, 2), new e("GPSImgDirection", 17, 5), new e("GPSMapDatum", 18, 2), new e("GPSDestLatitudeRef", 19, 2), new e("GPSDestLatitude", 20, 5), new e("GPSDestLongitudeRef", 21, 2), new e("GPSDestLongitude", 22, 5), new e("GPSDestBearingRef", 23, 2), new e("GPSDestBearing", 24, 5), new e("GPSDestDistanceRef", 25, 2), new e("GPSDestDistance", 26, 5), new e("GPSProcessingMethod", 27, 7), new e("GPSAreaInformation", 28, 7), new e("GPSDateStamp", 29, 2), new e("GPSDifferential", 30, 3), new e("GPSHPositioningError", 31, 5)};
        f19974c0 = eVarArr3;
        e[] eVarArr4 = {new e("InteroperabilityIndex", 1, 2)};
        f19975d0 = eVarArr4;
        e[] eVarArr5 = {new e("NewSubfileType", 254, 4), new e("SubfileType", 255, 4), new e("ThumbnailImageWidth", 256, 3, 4), new e("ThumbnailImageLength", 257, 3, 4), new e("BitsPerSample", 258, 3), new e("Compression", 259, 3), new e("PhotometricInterpretation", 262, 3), new e("ImageDescription", 270, 2), new e("Make", 271, 2), new e("Model", 272, 2), new e("StripOffsets", 273, 3, 4), new e("ThumbnailOrientation", 274, 3), new e("SamplesPerPixel", 277, 3), new e("RowsPerStrip", 278, 3, 4), new e("StripByteCounts", 279, 3, 4), new e("XResolution", 282, 5), new e("YResolution", 283, 5), new e("PlanarConfiguration", 284, 3), new e("ResolutionUnit", 296, 3), new e("TransferFunction", 301, 3), new e("Software", 305, 2), new e("DateTime", 306, 2), new e("Artist", 315, 2), new e("WhitePoint", 318, 5), new e("PrimaryChromaticities", 319, 5), new e("SubIFDPointer", 330, 4), new e("JPEGInterchangeFormat", 513, 4), new e("JPEGInterchangeFormatLength", 514, 4), new e("YCbCrCoefficients", 529, 5), new e("YCbCrSubSampling", 530, 3), new e("YCbCrPositioning", 531, 3), new e("ReferenceBlackWhite", 532, 5), new e("Copyright", 33432, 2), new e("ExifIFDPointer", 34665, 4), new e("GPSInfoIFDPointer", 34853, 4), new e("DNGVersion", 50706, 1), new e("DefaultCropSize", 50720, 3, 4)};
        f19976e0 = eVarArr5;
        f19977f0 = new e("StripOffsets", 273, 3);
        e[] eVarArr6 = {new e("ThumbnailImage", 256, 7), new e("CameraSettingsIFDPointer", 8224, 4), new e("ImageProcessingIFDPointer", 8256, 4)};
        f19978g0 = eVarArr6;
        e[] eVarArr7 = {new e("PreviewImageStart", 257, 4), new e("PreviewImageLength", 258, 4)};
        f19979h0 = eVarArr7;
        e[] eVarArr8 = {new e("AspectFrame", 4371, 3)};
        f19980i0 = eVarArr8;
        e[] eVarArr9 = {new e("ColorSpace", 55, 3)};
        f19981j0 = eVarArr9;
        e[][] eVarArr10 = {eVarArr, eVarArr2, eVarArr3, eVarArr4, eVarArr5, eVarArr, eVarArr6, eVarArr7, eVarArr8, eVarArr9};
        f19982k0 = eVarArr10;
        f19983l0 = new e[]{new e("SubIFDPointer", 330, 4), new e("ExifIFDPointer", 34665, 4), new e("GPSInfoIFDPointer", 34853, 4), new e("InteroperabilityIFDPointer", 40965, 4), new e("CameraSettingsIFDPointer", 8224, 1), new e("ImageProcessingIFDPointer", 8256, 1)};
        f19984m0 = new HashMap[eVarArr10.length];
        f19985n0 = new HashMap[eVarArr10.length];
        f19986o0 = DesugarCollections.unmodifiableSet(new HashSet(Arrays.asList("FNumber", "DigitalZoomRatio", "ExposureTime", "SubjectDistance")));
        f19987p0 = new HashMap();
        Charset forName = Charset.forName("US-ASCII");
        f19988q0 = forName;
        f19989r0 = "Exif\u0000\u0000".getBytes(forName);
        f19990s0 = "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);
        f19967V = simpleDateFormat;
        simpleDateFormat.setTimeZone(DesugarTimeZone.getTimeZone("UTC"));
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", locale);
        f19968W = simpleDateFormat2;
        simpleDateFormat2.setTimeZone(DesugarTimeZone.getTimeZone("UTC"));
        int i10 = 0;
        while (true) {
            e[][] eVarArr11 = f19982k0;
            if (i10 >= eVarArr11.length) {
                HashMap hashMap = f19987p0;
                e[] eVarArr12 = f19983l0;
                hashMap.put(Integer.valueOf(eVarArr12[0].f20035a), 5);
                hashMap.put(Integer.valueOf(eVarArr12[1].f20035a), 1);
                hashMap.put(Integer.valueOf(eVarArr12[2].f20035a), 2);
                hashMap.put(Integer.valueOf(eVarArr12[3].f20035a), 3);
                hashMap.put(Integer.valueOf(eVarArr12[4].f20035a), 7);
                hashMap.put(Integer.valueOf(eVarArr12[5].f20035a), 8);
                f19991t0 = Pattern.compile(".*[1-9].*");
                f19992u0 = Pattern.compile("^(\\d{2}):(\\d{2}):(\\d{2})$");
                f19993v0 = Pattern.compile("^(\\d{4}):(\\d{2}):(\\d{2})\\s(\\d{2}):(\\d{2}):(\\d{2})$");
                f19995w0 = Pattern.compile("^(\\d{4})-(\\d{2})-(\\d{2})\\s(\\d{2}):(\\d{2}):(\\d{2})$");
                return;
            }
            f19984m0[i10] = new HashMap();
            f19985n0[i10] = new HashMap();
            for (e eVar : eVarArr11[i10]) {
                f19984m0[i10].put(Integer.valueOf(eVar.f20035a), eVar);
                f19985n0[i10].put(eVar.f20036b, eVar);
            }
            i10++;
        }
    }

    public C1889a(File file) {
        e[][] eVarArr = f19982k0;
        this.f20004f = new HashMap[eVarArr.length];
        this.f20005g = new HashSet(eVarArr.length);
        this.f20006h = ByteOrder.BIG_ENDIAN;
        if (file == null) {
            throw new NullPointerException("file cannot be null");
        }
        F(file.getAbsolutePath());
    }

    public static int B(int i10) {
        if (i10 != 4) {
            return (i10 == 9 || i10 == 15 || i10 == 12 || i10 == 13) ? 2 : 1;
        }
        return 3;
    }

    public static Pair C(String str) {
        if (str.contains(",")) {
            String[] split = str.split(",", -1);
            Pair C10 = C(split[0]);
            if (((Integer) C10.first).intValue() == 2) {
                return C10;
            }
            for (int i10 = 1; i10 < split.length; i10++) {
                Pair C11 = C(split[i10]);
                int intValue = (((Integer) C11.first).equals(C10.first) || ((Integer) C11.second).equals(C10.first)) ? ((Integer) C10.first).intValue() : -1;
                int intValue2 = (((Integer) C10.second).intValue() == -1 || !(((Integer) C11.first).equals(C10.second) || ((Integer) C11.second).equals(C10.second))) ? -1 : ((Integer) C10.second).intValue();
                if (intValue == -1 && intValue2 == -1) {
                    return new Pair(2, -1);
                }
                if (intValue == -1) {
                    C10 = new Pair(Integer.valueOf(intValue2), -1);
                } else if (intValue2 == -1) {
                    C10 = new Pair(Integer.valueOf(intValue), -1);
                }
            }
            return C10;
        }
        if (!str.contains("/")) {
            try {
                try {
                    long parseLong = Long.parseLong(str);
                    return (parseLong < 0 || parseLong > 65535) ? parseLong < 0 ? new Pair(9, -1) : new Pair(4, -1) : new Pair(3, 4);
                } catch (NumberFormatException unused) {
                    return new Pair(2, -1);
                }
            } catch (NumberFormatException unused2) {
                Double.parseDouble(str);
                return new Pair(12, -1);
            }
        }
        String[] split2 = str.split("/", -1);
        if (split2.length == 2) {
            try {
                long parseDouble = (long) Double.parseDouble(split2[0]);
                long parseDouble2 = (long) Double.parseDouble(split2[1]);
                if (parseDouble >= 0 && parseDouble2 >= 0) {
                    if (parseDouble <= 2147483647L && parseDouble2 <= 2147483647L) {
                        return new Pair(10, 5);
                    }
                    return new Pair(5, -1);
                }
                return new Pair(10, -1);
            } catch (NumberFormatException unused3) {
            }
        }
        return new Pair(2, -1);
    }

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

    public static boolean M(FileDescriptor fileDescriptor) {
        try {
            Os.lseek(fileDescriptor, 0L, OsConstants.SEEK_CUR);
            return true;
        } catch (Exception unused) {
            if (!f19994w) {
                return false;
            }
            Log.d("ExifInterface", "The file descriptor for the given input is not seekable");
            return false;
        }
    }

    public static boolean O(int i10) {
        return i10 == 4 || i10 == 13 || i10 == 14;
    }

    public static double g(String str, String str2) {
        try {
            String[] split = str.split(",", -1);
            String[] split2 = split[0].split("/", -1);
            double parseDouble = Double.parseDouble(split2[0].trim()) / Double.parseDouble(split2[1].trim());
            String[] split3 = split[1].split("/", -1);
            double parseDouble2 = Double.parseDouble(split3[0].trim()) / Double.parseDouble(split3[1].trim());
            String[] split4 = split[2].split("/", -1);
            double parseDouble3 = parseDouble + (parseDouble2 / 60.0d) + ((Double.parseDouble(split4[0].trim()) / Double.parseDouble(split4[1].trim())) / 3600.0d);
            if (!str2.equals("S") && !str2.equals("W")) {
                if (!str2.equals("N") && !str2.equals("E")) {
                    throw new IllegalArgumentException();
                }
                return parseDouble3;
            }
            return -parseDouble3;
        } catch (ArrayIndexOutOfBoundsException | NumberFormatException e10) {
            throw new IllegalArgumentException(e10);
        }
    }

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

    public static void m0(CRC32 crc32, int i10) {
        crc32.update(i10 >>> 24);
        crc32.update(i10 >>> 16);
        crc32.update(i10 >>> 8);
        crc32.update(i10);
    }

    public final void A(b bVar) {
        if (f19994w) {
            Log.d("ExifInterface", "getWebpAttributes starting with: " + bVar);
        }
        bVar.f(ByteOrder.LITTLE_ENDIAN);
        bVar.h(f19958M.length);
        int readInt = bVar.readInt() + 8;
        byte[] bArr = f19959N;
        bVar.h(bArr.length);
        int length = bArr.length + 8;
        while (true) {
            try {
                byte[] bArr2 = new byte[4];
                bVar.readFully(bArr2);
                int readInt2 = bVar.readInt();
                int i10 = length + 8;
                if (Arrays.equals(f19960O, bArr2)) {
                    byte[] bArr3 = new byte[readInt2];
                    bVar.readFully(bArr3);
                    byte[] bArr4 = f19989r0;
                    if (AbstractC1890b.f(bArr3, bArr4)) {
                        bArr3 = Arrays.copyOfRange(bArr3, bArr4.length, readInt2);
                    }
                    this.f20014p = i10;
                    V(bArr3, 0);
                    j0(new b(bArr3));
                    return;
                }
                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.h(readInt2);
            } catch (EOFException e10) {
                throw new IOException("Encountered corrupt WebP file.", e10);
            }
        }
    }

    public final void D(b bVar, HashMap hashMap) {
        d dVar = (d) hashMap.get("JPEGInterchangeFormat");
        d dVar2 = (d) hashMap.get("JPEGInterchangeFormatLength");
        if (dVar == null || dVar2 == null) {
            return;
        }
        int m10 = dVar.m(this.f20006h);
        int m11 = dVar2.m(this.f20006h);
        if (this.f20002d == 7) {
            m10 += this.f20015q;
        }
        if (m10 > 0 && m11 > 0) {
            this.f20007i = true;
            if (this.f19999a == null && this.f20001c == null && this.f20000b == null) {
                byte[] bArr = new byte[m11];
                bVar.h(m10);
                bVar.readFully(bArr);
                this.f20012n = bArr;
            }
            this.f20010l = m10;
            this.f20011m = m11;
        }
        if (f19994w) {
            Log.d("ExifInterface", "Setting thumbnail attributes with offset: " + m10 + ", length: " + m11);
        }
    }

    public final void E(b bVar, HashMap hashMap) {
        int i10;
        d dVar = (d) hashMap.get("StripOffsets");
        d dVar2 = (d) hashMap.get("StripByteCounts");
        if (dVar == null || dVar2 == null) {
            return;
        }
        long[] c10 = AbstractC1890b.c(dVar.o(this.f20006h));
        long[] c11 = AbstractC1890b.c(dVar2.o(this.f20006h));
        if (c10 == null || c10.length == 0) {
            Log.w("ExifInterface", "stripOffsets should not be null or have zero length.");
            return;
        }
        if (c11 == null || c11.length == 0) {
            Log.w("ExifInterface", "stripByteCounts should not be null or have zero length.");
            return;
        }
        if (c10.length != c11.length) {
            Log.w("ExifInterface", "stripOffsets and stripByteCounts should have same length.");
            return;
        }
        long j10 = 0;
        for (long j11 : c11) {
            j10 += j11;
        }
        int i11 = (int) j10;
        byte[] bArr = new byte[i11];
        int i12 = 1;
        this.f20009k = true;
        this.f20008j = true;
        this.f20007i = true;
        int i13 = 0;
        int i14 = 0;
        int i15 = 0;
        while (i13 < c10.length) {
            int i16 = (int) c10[i13];
            byte[] bArr2 = bArr;
            int i17 = (int) c11[i13];
            if (i13 < c10.length - i12) {
                i10 = i13;
                if (i16 + i17 != c10[i10 + 1]) {
                    this.f20009k = false;
                }
            } else {
                i10 = i13;
            }
            int i18 = i16 - i14;
            if (i18 < 0) {
                Log.d("ExifInterface", "Invalid strip offset value");
                return;
            }
            try {
                bVar.h(i18);
                int i19 = i14 + i18;
                byte[] bArr3 = new byte[i17];
                try {
                    bVar.readFully(bArr3);
                    i14 = i19 + i17;
                    System.arraycopy(bArr3, 0, bArr2, i15, i17);
                    i15 += i17;
                    i13 = i10 + 1;
                    bArr = bArr2;
                    i12 = 1;
                } catch (EOFException unused) {
                    Log.d("ExifInterface", "Failed to read " + i17 + " bytes.");
                    return;
                }
            } catch (EOFException unused2) {
                Log.d("ExifInterface", "Failed to skip " + i18 + " bytes.");
                return;
            }
        }
        this.f20012n = bArr;
        if (this.f20009k) {
            this.f20010l = (int) c10[0];
            this.f20011m = i11;
        }
    }

    public final void F(String str) {
        FileInputStream fileInputStream;
        if (str == null) {
            throw new NullPointerException("filename cannot be null");
        }
        FileInputStream fileInputStream2 = null;
        this.f20001c = null;
        this.f19999a = str;
        try {
            fileInputStream = new FileInputStream(str);
        } catch (Throwable th) {
            th = th;
        }
        try {
            if (M(fileInputStream.getFD())) {
                this.f20000b = fileInputStream.getFD();
            } else {
                this.f20000b = null;
            }
            R(fileInputStream);
            AbstractC1890b.b(fileInputStream);
        } catch (Throwable th2) {
            th = th2;
            fileInputStream2 = fileInputStream;
            AbstractC1890b.b(fileInputStream2);
            throw th;
        }
    }

    public final int G(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 th) {
            th = th;
        }
        try {
            readInt = bVar.readInt();
            bArr2 = new byte[4];
            bVar.readFully(bArr2);
        } catch (Exception e11) {
            e = e11;
            bVar2 = bVar;
            if (f19994w) {
                Log.d("ExifInterface", "Exception parsing HEIF file type box.", e);
            }
            if (bVar2 != null) {
                bVar2.close();
            }
            return 0;
        } catch (Throwable th2) {
            th = th2;
            bVar2 = bVar;
            if (bVar2 != null) {
                bVar2.close();
            }
            throw th;
        }
        if (!Arrays.equals(bArr2, f19949D)) {
            bVar.close();
            return 0;
        }
        if (readInt == 1) {
            readInt = bVar.readLong();
            j10 = 16;
            if (readInt < 16) {
                bVar.close();
                return 0;
            }
        } else {
            j10 = 8;
        }
        if (readInt > bArr.length) {
            readInt = bArr.length;
        }
        long j11 = readInt - j10;
        if (j11 < 8) {
            bVar.close();
            return 0;
        }
        byte[] bArr3 = new byte[4];
        boolean z10 = false;
        boolean z11 = false;
        boolean z12 = false;
        for (long j12 = 0; j12 < j11 / 4; j12++) {
            try {
                bVar.readFully(bArr3);
                if (j12 != 1) {
                    if (Arrays.equals(bArr3, f19950E)) {
                        z10 = true;
                    } else if (Arrays.equals(bArr3, f19951F)) {
                        z11 = true;
                    } else if (Arrays.equals(bArr3, f19952G) || Arrays.equals(bArr3, f19953H)) {
                        z12 = true;
                    }
                    if (!z10) {
                        continue;
                    } else {
                        if (z11) {
                            bVar.close();
                            return 12;
                        }
                        if (z12) {
                            bVar.close();
                            return 15;
                        }
                    }
                }
            } catch (EOFException unused) {
                bVar.close();
                return 0;
            }
        }
        bVar.close();
        return 0;
    }

    public final boolean I(byte[] bArr) {
        b bVar = null;
        try {
            b bVar2 = new b(bArr);
            try {
                ByteOrder U10 = U(bVar2);
                this.f20006h = U10;
                bVar2.f(U10);
                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 th) {
                th = th;
                bVar = bVar2;
                if (bVar != null) {
                    bVar.close();
                }
                throw th;
            }
        } catch (Exception unused2) {
        } catch (Throwable th2) {
            th = th2;
        }
    }

    public final boolean J(byte[] bArr) {
        int i10 = 0;
        while (true) {
            byte[] bArr2 = f19956K;
            if (i10 >= bArr2.length) {
                return true;
            }
            if (bArr[i10] != bArr2[i10]) {
                return false;
            }
            i10++;
        }
    }

    public final boolean K(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;
    }

    public final boolean L(byte[] bArr) {
        b bVar = null;
        try {
            b bVar2 = new b(bArr);
            try {
                ByteOrder U10 = U(bVar2);
                this.f20006h = U10;
                bVar2.f(U10);
                boolean z10 = bVar2.readShort() == 85;
                bVar2.close();
                return z10;
            } catch (Exception unused) {
                bVar = bVar2;
                if (bVar != null) {
                    bVar.close();
                }
                return false;
            } catch (Throwable th) {
                th = th;
                bVar = bVar2;
                if (bVar != null) {
                    bVar.close();
                }
                throw th;
            }
        } catch (Exception unused2) {
        } catch (Throwable th2) {
            th = th2;
        }
    }

    public final boolean N(HashMap hashMap) {
        d dVar;
        int m10;
        d dVar2 = (d) hashMap.get("BitsPerSample");
        if (dVar2 != null) {
            int[] iArr = (int[]) dVar2.o(this.f20006h);
            int[] iArr2 = f19998z;
            if (Arrays.equals(iArr2, iArr)) {
                return true;
            }
            if (this.f20002d == 3 && (dVar = (d) hashMap.get("PhotometricInterpretation")) != null && (((m10 = dVar.m(this.f20006h)) == 1 && Arrays.equals(iArr, f19947B)) || (m10 == 6 && Arrays.equals(iArr, iArr2)))) {
                return true;
            }
        }
        if (!f19994w) {
            return false;
        }
        Log.d("ExifInterface", "Unsupported data type value");
        return false;
    }

    public final boolean P(HashMap hashMap) {
        d dVar = (d) hashMap.get("ImageLength");
        d dVar2 = (d) hashMap.get("ImageWidth");
        if (dVar == null || dVar2 == null) {
            return false;
        }
        return dVar.m(this.f20006h) <= 512 && dVar2.m(this.f20006h) <= 512;
    }

    public final boolean Q(byte[] bArr) {
        int i10 = 0;
        while (true) {
            byte[] bArr2 = f19958M;
            if (i10 >= bArr2.length) {
                int i11 = 0;
                while (true) {
                    byte[] bArr3 = f19959N;
                    if (i11 >= bArr3.length) {
                        return true;
                    }
                    if (bArr[f19958M.length + i11 + 4] != bArr3[i11]) {
                        return false;
                    }
                    i11++;
                }
            } else {
                if (bArr[i10] != bArr2[i10]) {
                    return false;
                }
                i10++;
            }
        }
    }

    public final void R(InputStream inputStream) {
        boolean z10;
        for (int i10 = 0; i10 < f19982k0.length; i10++) {
            try {
                try {
                    this.f20004f[i10] = new HashMap();
                } catch (Throwable th) {
                    e();
                    if (f19994w) {
                        T();
                    }
                    throw th;
                }
            } catch (IOException e10) {
                e = e10;
                z10 = f19994w;
                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.", e);
                }
                e();
                if (z10) {
                    return;
                }
                T();
                return;
            } catch (UnsupportedOperationException e11) {
                e = e11;
                z10 = f19994w;
                if (z10) {
                }
                e();
                if (z10) {
                }
            }
        }
        if (!this.f20003e) {
            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, 5000);
            this.f20002d = r(bufferedInputStream);
            inputStream = bufferedInputStream;
        }
        if (k0(this.f20002d)) {
            g gVar = new g(inputStream);
            if (!this.f20003e) {
                int i11 = this.f20002d;
                if (i11 != 12 && i11 != 15) {
                    if (i11 == 7) {
                        s(gVar);
                    } else if (i11 == 10) {
                        w(gVar);
                    } else {
                        v(gVar);
                    }
                }
                o(gVar, i11);
            } else if (!x(gVar)) {
                e();
                if (f19994w) {
                    T();
                    return;
                }
                return;
            }
            gVar.i(this.f20014p);
            j0(gVar);
        } else {
            b bVar = new b(inputStream);
            int i12 = this.f20002d;
            if (i12 == 4) {
                p(bVar, 0, 0);
            } else if (i12 == 13) {
                t(bVar);
            } else if (i12 == 9) {
                u(bVar);
            } else if (i12 == 14) {
                A(bVar);
            }
        }
        e();
        if (f19994w) {
            T();
        }
    }

    public final void S(b bVar) {
        ByteOrder U10 = U(bVar);
        this.f20006h = U10;
        bVar.f(U10);
        int readUnsignedShort = bVar.readUnsignedShort();
        int i10 = this.f20002d;
        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.h(i11);
        }
    }

    public final void T() {
        for (int i10 = 0; i10 < this.f20004f.length; i10++) {
            Log.d("ExifInterface", "The size of tag group[" + i10 + "]: " + this.f20004f[i10].size());
            for (Map.Entry entry : this.f20004f[i10].entrySet()) {
                d dVar = (d) entry.getValue();
                Log.d("ExifInterface", "tagName: " + ((String) entry.getKey()) + ", tagType: " + dVar.toString() + ", tagValue: '" + dVar.n(this.f20006h) + "'");
            }
        }
    }

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

    public final void V(byte[] bArr, int i10) {
        g gVar = new g(bArr);
        S(gVar);
        W(gVar, i10);
    }

    public final void W(g gVar, int i10) {
        char c10;
        short s10;
        long j10;
        boolean z10;
        short s11;
        int i11;
        int i12;
        boolean z11;
        int readUnsignedShort;
        long j11;
        int i13 = i10;
        this.f20005g.add(Integer.valueOf(gVar.b()));
        short readShort = gVar.readShort();
        if (f19994w) {
            Log.d("ExifInterface", "numberOfDirectoryEntry: " + ((int) readShort));
        }
        if (readShort <= 0) {
            return;
        }
        short s12 = 0;
        while (s12 < readShort) {
            int readUnsignedShort2 = gVar.readUnsignedShort();
            int readUnsignedShort3 = gVar.readUnsignedShort();
            int readInt = gVar.readInt();
            long b10 = gVar.b() + 4;
            e eVar = (e) f19984m0[i13].get(Integer.valueOf(readUnsignedShort2));
            boolean z12 = f19994w;
            if (z12) {
                c10 = 4;
                Log.d("ExifInterface", String.format("ifdType: %d, tagNumber: %d, tagName: %s, dataFormat: %d, numberOfComponents: %d", Integer.valueOf(i13), Integer.valueOf(readUnsignedShort2), eVar != null ? eVar.f20036b : null, Integer.valueOf(readUnsignedShort3), Integer.valueOf(readInt)));
            } else {
                c10 = 4;
            }
            if (eVar != null) {
                if (readUnsignedShort3 > 0) {
                    if (readUnsignedShort3 < f19970Y.length) {
                        if (eVar.a(readUnsignedShort3)) {
                            if (readUnsignedShort3 == 7) {
                                readUnsignedShort3 = eVar.f20037c;
                            }
                            s10 = s12;
                            j10 = readInt * r8[readUnsignedShort3];
                            if (j10 < 0 || j10 > 2147483647L) {
                                if (z12) {
                                    Log.d("ExifInterface", "Skip the tag entry since the number of components is invalid: " + readInt);
                                }
                                z10 = false;
                                if (z10) {
                                    gVar.i(b10);
                                    s11 = readShort;
                                } else {
                                    if (j10 > 4) {
                                        int readInt2 = gVar.readInt();
                                        s11 = readShort;
                                        if (z12) {
                                            StringBuilder sb2 = new StringBuilder();
                                            i11 = readUnsignedShort2;
                                            sb2.append("seek to data offset: ");
                                            sb2.append(readInt2);
                                            Log.d("ExifInterface", sb2.toString());
                                        } else {
                                            i11 = readUnsignedShort2;
                                        }
                                        if (this.f20002d == 7) {
                                            if ("MakerNote".equals(eVar.f20036b)) {
                                                this.f20015q = readInt2;
                                            } else if (i13 == 6 && "ThumbnailImage".equals(eVar.f20036b)) {
                                                this.f20016r = readInt2;
                                                this.f20017s = readInt;
                                                d j12 = d.j(6, this.f20006h);
                                                i12 = readInt;
                                                z11 = z12;
                                                d f10 = d.f(this.f20016r, this.f20006h);
                                                d f11 = d.f(this.f20017s, this.f20006h);
                                                this.f20004f[c10].put("Compression", j12);
                                                this.f20004f[c10].put("JPEGInterchangeFormat", f10);
                                                this.f20004f[c10].put("JPEGInterchangeFormatLength", f11);
                                                gVar.i(readInt2);
                                            }
                                        }
                                        i12 = readInt;
                                        z11 = z12;
                                        gVar.i(readInt2);
                                    } else {
                                        s11 = readShort;
                                        i11 = readUnsignedShort2;
                                        i12 = readInt;
                                        z11 = z12;
                                    }
                                    Integer num = (Integer) f19987p0.get(Integer.valueOf(i11));
                                    if (z11) {
                                        Log.d("ExifInterface", "nextIfdType: " + num + " byteCount: " + j10);
                                    }
                                    if (num != null) {
                                        if (readUnsignedShort3 != 3) {
                                            if (readUnsignedShort3 == 4) {
                                                j11 = gVar.e();
                                            } else if (readUnsignedShort3 == 8) {
                                                readUnsignedShort = gVar.readShort();
                                            } else if (readUnsignedShort3 == 9 || readUnsignedShort3 == 13) {
                                                readUnsignedShort = gVar.readInt();
                                            } else {
                                                j11 = -1;
                                            }
                                            if (z11) {
                                                Log.d("ExifInterface", String.format("Offset: %d, tagName: %s", Long.valueOf(j11), eVar.f20036b));
                                            }
                                            if (j11 > 0 || (gVar.a() != -1 && j11 >= gVar.a())) {
                                                if (z11) {
                                                    String str = "Skip jump into the IFD since its offset is invalid: " + j11;
                                                    if (gVar.a() != -1) {
                                                        str = str + " (total length: " + gVar.a() + ")";
                                                    }
                                                    Log.d("ExifInterface", str);
                                                }
                                            } else if (!this.f20005g.contains(Integer.valueOf((int) j11))) {
                                                gVar.i(j11);
                                                W(gVar, num.intValue());
                                            } else if (z11) {
                                                Log.d("ExifInterface", "Skip jump into the IFD since it has already been read: IfdType " + num + " (at " + j11 + ")");
                                            }
                                            gVar.i(b10);
                                        } else {
                                            readUnsignedShort = gVar.readUnsignedShort();
                                        }
                                        j11 = readUnsignedShort;
                                        if (z11) {
                                        }
                                        if (j11 > 0) {
                                        }
                                        if (z11) {
                                        }
                                        gVar.i(b10);
                                    } else {
                                        int b11 = gVar.b() + this.f20014p;
                                        byte[] bArr = new byte[(int) j10];
                                        gVar.readFully(bArr);
                                        d dVar = new d(readUnsignedShort3, i12, b11, bArr);
                                        this.f20004f[i10].put(eVar.f20036b, dVar);
                                        if ("DNGVersion".equals(eVar.f20036b)) {
                                            this.f20002d = 3;
                                        }
                                        if ((("Make".equals(eVar.f20036b) || "Model".equals(eVar.f20036b)) && dVar.n(this.f20006h).contains("PENTAX")) || ("Compression".equals(eVar.f20036b) && dVar.m(this.f20006h) == 65535)) {
                                            this.f20002d = 8;
                                        }
                                        if (gVar.b() != b10) {
                                            gVar.i(b10);
                                        }
                                    }
                                }
                                s12 = (short) (s10 + 1);
                                i13 = i10;
                                readShort = s11;
                            } else {
                                z10 = true;
                                if (z10) {
                                }
                                s12 = (short) (s10 + 1);
                                i13 = i10;
                                readShort = s11;
                            }
                        } else if (z12) {
                            Log.d("ExifInterface", "Skip the tag entry since data format (" + f19969X[readUnsignedShort3] + ") is unexpected for tag: " + eVar.f20036b);
                        }
                    }
                }
                s10 = s12;
                if (z12) {
                    Log.d("ExifInterface", "Skip the tag entry since data format is invalid: " + readUnsignedShort3);
                }
                j10 = 0;
                z10 = false;
                if (z10) {
                }
                s12 = (short) (s10 + 1);
                i13 = i10;
                readShort = s11;
            } else if (z12) {
                Log.d("ExifInterface", "Skip the tag entry since tag number is not defined: " + readUnsignedShort2);
            }
            s10 = s12;
            j10 = 0;
            z10 = false;
            if (z10) {
            }
            s12 = (short) (s10 + 1);
            i13 = i10;
            readShort = s11;
        }
        int readInt3 = gVar.readInt();
        boolean z13 = f19994w;
        if (z13) {
            Log.d("ExifInterface", String.format("nextIfdOffset: %d", Integer.valueOf(readInt3)));
        }
        long j13 = readInt3;
        if (j13 <= 0) {
            if (z13) {
                Log.d("ExifInterface", "Stop reading file since a wrong offset may cause an infinite loop: " + readInt3);
                return;
            }
            return;
        }
        if (this.f20005g.contains(Integer.valueOf(readInt3))) {
            if (z13) {
                Log.d("ExifInterface", "Stop reading file since re-reading an IFD may cause an infinite loop: " + readInt3);
                return;
            }
            return;
        }
        gVar.i(j13);
        if (this.f20004f[4].isEmpty()) {
            W(gVar, 4);
        } else if (this.f20004f[5].isEmpty()) {
            W(gVar, 5);
        }
    }

    public final void X(String str) {
        for (int i10 = 0; i10 < f19982k0.length; i10++) {
            this.f20004f[i10].remove(str);
        }
    }

    public final void Y(int i10, String str, String str2) {
        if (this.f20004f[i10].isEmpty() || this.f20004f[i10].get(str) == null) {
            return;
        }
        HashMap hashMap = this.f20004f[i10];
        hashMap.put(str2, (d) hashMap.get(str));
        this.f20004f[i10].remove(str);
    }

    public void Z() {
        g0("Orientation", Integer.toString(1));
    }

    public final void a0(g gVar, int i10) {
        d dVar = (d) this.f20004f[i10].get("ImageLength");
        d dVar2 = (d) this.f20004f[i10].get("ImageWidth");
        if (dVar == null || dVar2 == null) {
            d dVar3 = (d) this.f20004f[i10].get("JPEGInterchangeFormat");
            d dVar4 = (d) this.f20004f[i10].get("JPEGInterchangeFormatLength");
            if (dVar3 == null || dVar4 == null) {
                return;
            }
            int m10 = dVar3.m(this.f20006h);
            int m11 = dVar3.m(this.f20006h);
            gVar.i(m10);
            byte[] bArr = new byte[m11];
            gVar.readFully(bArr);
            p(new b(bArr), m10, i10);
        }
    }

    public void b0() {
        FileOutputStream fileOutputStream;
        File createTempFile;
        FileInputStream fileInputStream;
        Closeable closeable;
        FileOutputStream fileOutputStream2;
        Exception exc;
        FileOutputStream fileOutputStream3;
        InputStream inputStream;
        Exception e10;
        FileOutputStream fileOutputStream4;
        FileInputStream fileInputStream2;
        if (!O(this.f20002d)) {
            throw new IOException("ExifInterface only supports saving attributes for JPEG, PNG, and WebP formats.");
        }
        if (this.f20000b == null && this.f19999a == null) {
            throw new IOException("ExifInterface does not support saving attributes for the current input.");
        }
        if (this.f20007i && this.f20008j && !this.f20009k) {
            throw new IOException("ExifInterface does not support saving attributes when the image file has non-consecutive thumbnail strips");
        }
        this.f20018t = true;
        this.f20012n = y();
        InputStream inputStream2 = null;
        try {
            createTempFile = File.createTempFile("temp", "tmp");
            if (this.f19999a != null) {
                fileInputStream = new FileInputStream(this.f19999a);
            } else {
                Os.lseek(this.f20000b, 0L, OsConstants.SEEK_SET);
                fileInputStream = new FileInputStream(this.f20000b);
            }
            try {
                fileOutputStream = new FileOutputStream(createTempFile);
            } catch (Exception e11) {
                e = e11;
                fileOutputStream = null;
            } catch (Throwable th) {
                th = th;
                fileOutputStream = null;
            }
        } catch (Exception e12) {
            e = e12;
            fileOutputStream = null;
        } catch (Throwable th2) {
            th = th2;
            fileOutputStream = null;
        }
        try {
            AbstractC1890b.d(fileInputStream, fileOutputStream);
            AbstractC1890b.b(fileInputStream);
            AbstractC1890b.b(fileOutputStream);
            try {
            } catch (Throwable th3) {
                th = th3;
            }
            try {
                try {
                    fileInputStream2 = new FileInputStream(createTempFile);
                } catch (Throwable th4) {
                    th = th4;
                    closeable = null;
                    AbstractC1890b.b(inputStream2);
                    AbstractC1890b.b(closeable);
                    if (0 == 0) {
                        createTempFile.delete();
                    }
                    throw th;
                }
                try {
                    if (this.f19999a != null) {
                        fileOutputStream3 = new FileOutputStream(this.f19999a);
                    } else {
                        Os.lseek(this.f20000b, 0L, OsConstants.SEEK_SET);
                        fileOutputStream3 = new FileOutputStream(this.f20000b);
                    }
                    try {
                        BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream2);
                        try {
                            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream3);
                            try {
                                int i10 = this.f20002d;
                                if (i10 == 4) {
                                    c0(bufferedInputStream, bufferedOutputStream);
                                } else if (i10 == 13) {
                                    d0(bufferedInputStream, bufferedOutputStream);
                                } else if (i10 == 14) {
                                    e0(bufferedInputStream, bufferedOutputStream);
                                }
                                AbstractC1890b.b(bufferedInputStream);
                                AbstractC1890b.b(bufferedOutputStream);
                                createTempFile.delete();
                                this.f20012n = null;
                            } catch (Exception e13) {
                                exc = e13;
                                inputStream2 = fileInputStream2;
                                try {
                                    inputStream = new FileInputStream(createTempFile);
                                    try {
                                        if (this.f19999a == null) {
                                            fileOutputStream4 = new FileOutputStream(this.f19999a);
                                        } else {
                                            Os.lseek(this.f20000b, 0L, OsConstants.SEEK_SET);
                                            fileOutputStream4 = new FileOutputStream(this.f20000b);
                                        }
                                        fileOutputStream3 = fileOutputStream4;
                                        AbstractC1890b.d(inputStream, fileOutputStream3);
                                        AbstractC1890b.b(inputStream);
                                        AbstractC1890b.b(fileOutputStream3);
                                        throw new IOException("Failed to save new file", exc);
                                    } catch (Exception e14) {
                                        e10 = e14;
                                        try {
                                            throw new IOException("Failed to save new file. Original file is stored in " + createTempFile.getAbsolutePath(), e10);
                                        } catch (Throwable th5) {
                                            th = th5;
                                            inputStream2 = inputStream;
                                            AbstractC1890b.b(inputStream2);
                                            AbstractC1890b.b(fileOutputStream3);
                                            throw th;
                                        }
                                    } catch (Throwable th6) {
                                        th = th6;
                                        inputStream2 = inputStream;
                                        AbstractC1890b.b(inputStream2);
                                        AbstractC1890b.b(fileOutputStream3);
                                        throw th;
                                    }
                                } catch (Exception e15) {
                                    inputStream = inputStream2;
                                    e10 = e15;
                                } catch (Throwable th7) {
                                    th = th7;
                                }
                            }
                        } catch (Exception e16) {
                            inputStream2 = fileInputStream2;
                            exc = e16;
                        } catch (Throwable th8) {
                            th = th8;
                            closeable = null;
                            inputStream2 = bufferedInputStream;
                            AbstractC1890b.b(inputStream2);
                            AbstractC1890b.b(closeable);
                            if (0 == 0) {
                            }
                            throw th;
                        }
                    } catch (Exception e17) {
                        inputStream2 = fileInputStream2;
                        exc = e17;
                    }
                } catch (Exception e18) {
                    e = e18;
                    fileOutputStream2 = null;
                    inputStream2 = fileInputStream2;
                    exc = e;
                    fileOutputStream3 = fileOutputStream2;
                    inputStream = new FileInputStream(createTempFile);
                    if (this.f19999a == null) {
                    }
                    fileOutputStream3 = fileOutputStream4;
                    AbstractC1890b.d(inputStream, fileOutputStream3);
                    AbstractC1890b.b(inputStream);
                    AbstractC1890b.b(fileOutputStream3);
                    throw new IOException("Failed to save new file", exc);
                }
            } catch (Exception e19) {
                e = e19;
                fileOutputStream2 = null;
            }
        } catch (Exception e20) {
            e = e20;
            inputStream2 = fileInputStream;
            try {
                throw new IOException("Failed to copy original file to temp file", e);
            } catch (Throwable th9) {
                th = th9;
                AbstractC1890b.b(inputStream2);
                AbstractC1890b.b(fileOutputStream);
                throw th;
            }
        } catch (Throwable th10) {
            th = th10;
            inputStream2 = fileInputStream;
            AbstractC1890b.b(inputStream2);
            AbstractC1890b.b(fileOutputStream);
            throw th;
        }
    }

    public final void c0(InputStream inputStream, OutputStream outputStream) {
        byte[] bArr;
        if (f19994w) {
            Log.d("ExifInterface", "saveJpegAttributes starting with (inputStream: " + inputStream + ", outputStream: " + outputStream + ")");
        }
        b bVar = new b(inputStream);
        c cVar = new c(outputStream, ByteOrder.BIG_ENDIAN);
        if (bVar.readByte() != -1) {
            throw new IOException("Invalid marker");
        }
        cVar.b(-1);
        if (bVar.readByte() != -40) {
            throw new IOException("Invalid marker");
        }
        cVar.b(-40);
        cVar.b(-1);
        cVar.b(-31);
        this.f20014p = p0(cVar);
        if (this.f20019u != null) {
            cVar.write(-1);
            cVar.b(-31);
            byte[] bArr2 = f19990s0;
            cVar.h(bArr2.length + 2 + this.f20019u.f20034d.length);
            cVar.write(bArr2);
            cVar.write(this.f20019u.f20034d);
            this.f20020v = true;
        }
        byte[] bArr3 = new byte[4096];
        while (bVar.readByte() == -1) {
            byte readByte = bVar.readByte();
            if (readByte == -39 || readByte == -38) {
                cVar.b(-1);
                cVar.b(readByte);
                AbstractC1890b.d(bVar, cVar);
                return;
            }
            if (readByte != -31) {
                cVar.b(-1);
                cVar.b(readByte);
                int readUnsignedShort = bVar.readUnsignedShort();
                cVar.h(readUnsignedShort);
                int i10 = readUnsignedShort - 2;
                if (i10 < 0) {
                    throw new IOException("Invalid length");
                }
                while (i10 > 0) {
                    int read = bVar.read(bArr3, 0, Math.min(i10, 4096));
                    if (read >= 0) {
                        cVar.write(bArr3, 0, read);
                        i10 -= read;
                    }
                }
            } else {
                int readUnsignedShort2 = bVar.readUnsignedShort();
                int i11 = readUnsignedShort2 - 2;
                if (i11 < 0) {
                    throw new IOException("Invalid length");
                }
                byte[] bArr4 = f19990s0;
                if (i11 >= bArr4.length) {
                    bArr = new byte[bArr4.length];
                } else {
                    byte[] bArr5 = f19989r0;
                    bArr = i11 >= bArr5.length ? new byte[bArr5.length] : null;
                }
                if (bArr != null) {
                    bVar.readFully(bArr);
                    if (AbstractC1890b.f(bArr, f19989r0) || AbstractC1890b.f(bArr, bArr4)) {
                        bVar.h(i11 - bArr.length);
                    }
                }
                cVar.b(-1);
                cVar.b(readByte);
                cVar.h(readUnsignedShort2);
                if (bArr != null) {
                    i11 -= bArr.length;
                    cVar.write(bArr);
                }
                while (i11 > 0) {
                    int read2 = bVar.read(bArr3, 0, Math.min(i11, 4096));
                    if (read2 >= 0) {
                        cVar.write(bArr3, 0, read2);
                        i11 -= read2;
                    }
                }
            }
        }
        throw new IOException("Invalid marker");
    }

    public final void d0(java.io.InputStream r9, java.io.OutputStream r10) {
        throw new UnsupportedOperationException("Method not decompiled: b1.C1889a.d0(java.io.InputStream, java.io.OutputStream):void");
    }

    public final void e() {
        String k10 = k("DateTimeOriginal");
        if (k10 != null && k("DateTime") == null) {
            this.f20004f[0].put("DateTime", d.e(k10));
        }
        if (k("ImageWidth") == null) {
            this.f20004f[0].put("ImageWidth", d.f(0L, this.f20006h));
        }
        if (k("ImageLength") == null) {
            this.f20004f[0].put("ImageLength", d.f(0L, this.f20006h));
        }
        if (k("Orientation") == null) {
            this.f20004f[0].put("Orientation", d.f(0L, this.f20006h));
        }
        if (k("LightSource") == null) {
            this.f20004f[1].put("LightSource", d.f(0L, this.f20006h));
        }
    }

    public final void e0(InputStream inputStream, OutputStream outputStream) {
        ByteArrayOutputStream byteArrayOutputStream;
        int i10;
        int i11;
        int i12;
        int i13;
        int p02;
        boolean z10;
        if (f19994w) {
            Log.d("ExifInterface", "saveWebpAttributes starting with (inputStream: " + inputStream + ", outputStream: " + outputStream + ")");
        }
        ByteOrder byteOrder = ByteOrder.LITTLE_ENDIAN;
        b bVar = new b(inputStream, byteOrder);
        c cVar = new c(outputStream, byteOrder);
        byte[] bArr = f19958M;
        AbstractC1890b.e(bVar, cVar, bArr.length);
        int readInt = bVar.readInt();
        byte[] bArr2 = f19959N;
        bVar.h(bArr2.length);
        ByteArrayOutputStream byteArrayOutputStream2 = null;
        try {
            try {
                byteArrayOutputStream = new ByteArrayOutputStream();
            } catch (Throwable th) {
                th = th;
            }
        } catch (Exception e10) {
            e = e10;
        }
        try {
            c cVar2 = new c(byteArrayOutputStream, byteOrder);
            int i14 = this.f20014p;
            if (i14 != 0) {
                AbstractC1890b.e(bVar, cVar2, (i14 - ((bArr.length + 4) + bArr2.length)) - 8);
                bVar.h(4);
                int readInt2 = bVar.readInt();
                if (readInt2 % 2 != 0) {
                    readInt2++;
                }
                bVar.h(readInt2);
                p02 = p0(cVar2);
            } else {
                byte[] bArr3 = new byte[4];
                bVar.readFully(bArr3);
                byte[] bArr4 = f19962Q;
                boolean z11 = true;
                if (!Arrays.equals(bArr3, bArr4)) {
                    byte[] bArr5 = f19964S;
                    if (!Arrays.equals(bArr3, bArr5) && !Arrays.equals(bArr3, f19963R)) {
                        p02 = -1;
                        AbstractC1890b.e(bVar, cVar2, (readInt + 8) - bVar.b());
                        int size = byteArrayOutputStream.size();
                        byte[] bArr6 = f19959N;
                        cVar.c(size + bArr6.length);
                        cVar.write(bArr6);
                        if (p02 != -1) {
                            this.f20014p = cVar.f20029l.size() + p02;
                        }
                        byteArrayOutputStream.writeTo(cVar);
                        AbstractC1890b.d(bVar, cVar);
                        AbstractC1890b.b(byteArrayOutputStream);
                    }
                    int readInt3 = bVar.readInt();
                    int i15 = readInt3 % 2 == 1 ? readInt3 + 1 : readInt3;
                    byte[] bArr7 = new byte[3];
                    if (Arrays.equals(bArr3, bArr5)) {
                        bVar.readFully(bArr7);
                        byte[] bArr8 = new byte[3];
                        bVar.readFully(bArr8);
                        if (!Arrays.equals(f19961P, bArr8)) {
                            throw new IOException("Error checking VP8 signature");
                        }
                        i12 = bVar.readInt();
                        i11 = (i12 >> 16) & 16383;
                        i10 = i15 - 10;
                        i13 = i12 & 16383;
                        z11 = false;
                    } else if (!Arrays.equals(bArr3, f19963R)) {
                        i10 = i15;
                        i11 = 0;
                        i12 = 0;
                        z11 = false;
                        i13 = 0;
                    } else {
                        if (bVar.readByte() != 47) {
                            throw new IOException("Error checking VP8L signature");
                        }
                        i12 = bVar.readInt();
                        int i16 = (i12 & 16383) + 1;
                        int i17 = ((i12 & 268419072) >>> 14) + 1;
                        if ((i12 & 268435456) == 0) {
                            z11 = false;
                        }
                        i10 = i15 - 5;
                        i13 = i16;
                        i11 = i17;
                    }
                    cVar2.write(bArr4);
                    cVar2.c(10);
                    byte[] bArr9 = new byte[10];
                    if (z11) {
                        bArr9[0] = (byte) (bArr9[0] | 16);
                    }
                    bArr9[0] = (byte) (bArr9[0] | 8);
                    int i18 = i13 - 1;
                    int i19 = i11 - 1;
                    bArr9[4] = (byte) i18;
                    bArr9[5] = (byte) (i18 >> 8);
                    bArr9[6] = (byte) (i18 >> 16);
                    bArr9[7] = (byte) i19;
                    bArr9[8] = (byte) (i19 >> 8);
                    bArr9[9] = (byte) (i19 >> 16);
                    cVar2.write(bArr9);
                    cVar2.write(bArr3);
                    cVar2.c(readInt3);
                    if (Arrays.equals(bArr3, bArr5)) {
                        cVar2.write(bArr7);
                        cVar2.write(f19961P);
                        cVar2.c(i12);
                    } else if (Arrays.equals(bArr3, f19963R)) {
                        cVar2.write(47);
                        cVar2.c(i12);
                    }
                    AbstractC1890b.e(bVar, cVar2, i10);
                    p02 = p0(cVar2);
                    AbstractC1890b.e(bVar, cVar2, (readInt + 8) - bVar.b());
                    int size2 = byteArrayOutputStream.size();
                    byte[] bArr62 = f19959N;
                    cVar.c(size2 + bArr62.length);
                    cVar.write(bArr62);
                    if (p02 != -1) {
                    }
                    byteArrayOutputStream.writeTo(cVar);
                    AbstractC1890b.d(bVar, cVar);
                    AbstractC1890b.b(byteArrayOutputStream);
                }
                int readInt4 = bVar.readInt();
                byte[] bArr10 = new byte[readInt4 % 2 == 1 ? readInt4 + 1 : readInt4];
                bVar.readFully(bArr10);
                byte b10 = (byte) (bArr10[0] | 8);
                bArr10[0] = b10;
                boolean z12 = ((b10 >> 1) & 1) == 1;
                cVar2.write(bArr4);
                cVar2.c(readInt4);
                cVar2.write(bArr10);
                if (z12) {
                    h(bVar, cVar2, f19965T, null);
                    while (true) {
                        byte[] bArr11 = new byte[4];
                        try {
                            bVar.readFully(bArr11);
                            z10 = !Arrays.equals(bArr11, f19966U);
                        } catch (EOFException unused) {
                            z10 = true;
                        }
                        if (z10) {
                            break;
                        } else {
                            i(bVar, cVar2, bArr11);
                        }
                    }
                    p02 = p0(cVar2);
                } else {
                    h(bVar, cVar2, f19964S, f19963R);
                    p02 = p0(cVar2);
                }
            }
            AbstractC1890b.e(bVar, cVar2, (readInt + 8) - bVar.b());
            int size22 = byteArrayOutputStream.size();
            byte[] bArr622 = f19959N;
            cVar.c(size22 + bArr622.length);
            cVar.write(bArr622);
            if (p02 != -1) {
            }
            byteArrayOutputStream.writeTo(cVar);
            AbstractC1890b.d(bVar, cVar);
            AbstractC1890b.b(byteArrayOutputStream);
        } catch (Exception e11) {
            e = e11;
            throw new IOException("Failed to save WebP file", e);
        } catch (Throwable th2) {
            th = th2;
            byteArrayOutputStream2 = byteArrayOutputStream;
            AbstractC1890b.b(byteArrayOutputStream2);
            throw th;
        }
    }

    public final String f(double d10) {
        long j10 = (long) d10;
        double d11 = d10 - j10;
        long j11 = (long) (d11 * 60.0d);
        return j10 + "/1," + j11 + "/1," + Math.round((d11 - (j11 / 60.0d)) * 3600.0d * 1.0E7d) + "/10000000";
    }

    public void f0(double d10) {
        String str = d10 >= 0.0d ? "0" : "1";
        g0("GPSAltitude", f.b(Math.abs(d10)).toString());
        g0("GPSAltitudeRef", str);
    }

    public void g0(String str, String str2) {
        e eVar;
        int i10;
        String str3;
        String str4 = str;
        String str5 = str2;
        if (str4 == null) {
            throw new NullPointerException("tag shouldn't be null");
        }
        if ("ISOSpeedRatings".equals(str4)) {
            if (f19994w) {
                Log.d("ExifInterface", "setAttribute: Replacing TAG_ISO_SPEED_RATINGS with TAG_PHOTOGRAPHIC_SENSITIVITY.");
            }
            str4 = "PhotographicSensitivity";
        }
        int i11 = 2;
        String str6 = "/";
        int i12 = 1;
        if (str5 != null) {
            if (f19986o0.contains(str4) && !str5.contains("/")) {
                try {
                    str5 = f.b(Double.parseDouble(str5)).toString();
                } catch (NumberFormatException unused) {
                    Log.w("ExifInterface", "Invalid value for " + str4 + " : " + str5);
                    return;
                }
            } else if (str4.equals("GPSTimeStamp")) {
                Matcher matcher = f19992u0.matcher(str5);
                if (!matcher.find()) {
                    Log.w("ExifInterface", "Invalid value for " + str4 + " : " + str5);
                    return;
                }
                str5 = Integer.parseInt(matcher.group(1)) + "/1," + Integer.parseInt(matcher.group(2)) + "/1," + Integer.parseInt(matcher.group(3)) + "/1";
            } else if ("DateTime".equals(str4) || "DateTimeOriginal".equals(str4) || "DateTimeDigitized".equals(str4)) {
                boolean find = f19993v0.matcher(str5).find();
                boolean find2 = f19995w0.matcher(str5).find();
                if (str5.length() != 19 || (!find && !find2)) {
                    Log.w("ExifInterface", "Invalid value for " + str4 + " : " + str5);
                    return;
                }
                if (find2) {
                    str5 = str5.replaceAll("-", ":");
                }
            }
        }
        char c10 = 0;
        if ("Xmp".equals(str4)) {
            boolean z10 = this.f20004f[0].containsKey("Xmp") || this.f20004f[5].containsKey("Xmp");
            int B10 = B(this.f20002d);
            if ((B10 == 2 && (this.f20019u != null || !z10)) || (B10 == 3 && !z10)) {
                this.f20019u = str5 != null ? d.a(str5) : null;
                return;
            }
        }
        int i13 = 0;
        while (i13 < f19982k0.length) {
            if ((i13 != 4 || this.f20007i) && (eVar = (e) f19985n0[i13].get(str4)) != null) {
                if (str5 == null) {
                    this.f20004f[i13].remove(str4);
                } else {
                    Pair C10 = C(str5);
                    if (eVar.f20037c == ((Integer) C10.first).intValue() || eVar.f20037c == ((Integer) C10.second).intValue()) {
                        i10 = eVar.f20037c;
                    } else {
                        int i14 = eVar.f20038d;
                        if (i14 == -1 || !(i14 == ((Integer) C10.first).intValue() || eVar.f20038d == ((Integer) C10.second).intValue())) {
                            int i15 = eVar.f20037c;
                            if (i15 == i12 || i15 == 7 || i15 == i11) {
                                i10 = i15;
                            } else if (f19994w) {
                                StringBuilder sb2 = new StringBuilder();
                                sb2.append("Given tag (");
                                sb2.append(str4);
                                sb2.append(") value didn't match with one of expected formats: ");
                                String[] strArr = f19969X;
                                sb2.append(strArr[eVar.f20037c]);
                                sb2.append(eVar.f20038d == -1 ? "" : ", " + strArr[eVar.f20038d]);
                                sb2.append(" (guess: ");
                                sb2.append(strArr[((Integer) C10.first).intValue()]);
                                sb2.append(((Integer) C10.second).intValue() != -1 ? ", " + strArr[((Integer) C10.second).intValue()] : "");
                                sb2.append(")");
                                Log.d("ExifInterface", sb2.toString());
                            }
                        } else {
                            i10 = eVar.f20038d;
                        }
                    }
                    switch (i10) {
                        case 1:
                            str3 = str6;
                            this.f20004f[i13].put(str4, d.a(str5));
                            break;
                        case 2:
                        case Context.FEATURE_DYNAMIC_SCOPE:
                            str3 = str6;
                            this.f20004f[i13].put(str4, d.e(str5));
                            break;
                        case 3:
                            str3 = str6;
                            String[] split = str5.split(",", -1);
                            int[] iArr = new int[split.length];
                            for (int i16 = 0; i16 < split.length; i16++) {
                                iArr[i16] = Integer.parseInt(split[i16]);
                            }
                            this.f20004f[i13].put(str4, d.k(iArr, this.f20006h));
                            break;
                        case 4:
                            str3 = str6;
                            String[] split2 = str5.split(",", -1);
                            long[] jArr = new long[split2.length];
                            for (int i17 = 0; i17 < split2.length; i17++) {
                                jArr[i17] = Long.parseLong(split2[i17]);
                            }
                            this.f20004f[i13].put(str4, d.g(jArr, this.f20006h));
                            break;
                        case 5:
                            String[] split3 = str5.split(",", -1);
                            f[] fVarArr = new f[split3.length];
                            int i18 = 0;
                            while (i18 < split3.length) {
                                String[] split4 = split3[i18].split(str6, -1);
                                fVarArr[i18] = new f((long) Double.parseDouble(split4[0]), (long) Double.parseDouble(split4[1]), null);
                                i18++;
                                str6 = str6;
                            }
                            str3 = str6;
                            this.f20004f[i13].put(str4, d.i(fVarArr, this.f20006h));
                            break;
                        case 6:
                        case 8:
                        case Context.FEATURE_STRICT_MODE:
                        default:
                            if (f19994w) {
                                Log.d("ExifInterface", "Data format isn't one of expected formats: " + i10);
                                break;
                            }
                            break;
                        case Context.FEATURE_STRICT_EVAL:
                            String[] split5 = str5.split(",", -1);
                            int[] iArr2 = new int[split5.length];
                            for (int i19 = 0; i19 < split5.length; i19++) {
                                iArr2[i19] = Integer.parseInt(split5[i19]);
                            }
                            this.f20004f[i13].put(str4, d.c(iArr2, this.f20006h));
                            str3 = str6;
                            break;
                        case Context.FEATURE_LOCATION_INFORMATION_IN_ERROR:
                            String[] split6 = str5.split(",", -1);
                            f[] fVarArr2 = new f[split6.length];
                            int i20 = 0;
                            while (i20 < split6.length) {
                                String[] split7 = split6[i20].split(str6, -1);
                                int i21 = i20;
                                fVarArr2[i21] = new f((long) Double.parseDouble(split7[c10]), (long) Double.parseDouble(split7[1]), null);
                                i20 = i21 + 1;
                                split6 = split6;
                                c10 = 0;
                            }
                            this.f20004f[i13].put(str4, d.d(fVarArr2, this.f20006h));
                            str3 = str6;
                            break;
                        case Context.FEATURE_WARNING_AS_ERROR:
                            String[] split8 = str5.split(",", -1);
                            double[] dArr = new double[split8.length];
                            for (int i22 = 0; i22 < split8.length; i22++) {
                                dArr[i22] = Double.parseDouble(split8[i22]);
                            }
                            this.f20004f[i13].put(str4, d.b(dArr, this.f20006h));
                            break;
                    }
                    i13++;
                    str6 = str3;
                    i11 = 2;
                    i12 = 1;
                    c10 = 0;
                }
            }
            str3 = str6;
            i13++;
            str6 = str3;
            i11 = 2;
            i12 = 1;
            c10 = 0;
        }
    }

    public final void h(b bVar, c cVar, byte[] bArr, byte[] bArr2) {
        while (true) {
            byte[] bArr3 = new byte[4];
            bVar.readFully(bArr3);
            i(bVar, cVar, bArr3);
            if (Arrays.equals(bArr3, bArr)) {
                return;
            }
            if (bArr2 != null && Arrays.equals(bArr3, bArr2)) {
                return;
            }
        }
    }

    public void h0(Location location) {
        if (location == null) {
            return;
        }
        g0("GPSProcessingMethod", location.getProvider());
        i0(location.getLatitude(), location.getLongitude());
        f0(location.getAltitude());
        g0("GPSSpeedRef", "K");
        g0("GPSSpeed", f.b((location.getSpeed() * TimeUnit.HOURS.toSeconds(1L)) / 1000.0f).toString());
        String[] split = f19967V.format(new Date(location.getTime())).split("\\s+", -1);
        g0("GPSDateStamp", split[0]);
        g0("GPSTimeStamp", split[1]);
    }

    public final void i(b bVar, c cVar, byte[] bArr) {
        int readInt = bVar.readInt();
        cVar.write(bArr);
        cVar.c(readInt);
        if (readInt % 2 == 1) {
            readInt++;
        }
        AbstractC1890b.e(bVar, cVar, readInt);
    }

    public void i0(double d10, double d11) {
        if (d10 < -90.0d || d10 > 90.0d || Double.isNaN(d10)) {
            throw new IllegalArgumentException("Latitude value " + d10 + " is not valid.");
        }
        if (d11 < -180.0d || d11 > 180.0d || Double.isNaN(d11)) {
            throw new IllegalArgumentException("Longitude value " + d11 + " is not valid.");
        }
        g0("GPSLatitudeRef", d10 >= 0.0d ? "N" : "S");
        g0("GPSLatitude", f(Math.abs(d10)));
        g0("GPSLongitudeRef", d11 >= 0.0d ? "E" : "W");
        g0("GPSLongitude", f(Math.abs(d11)));
    }

    public double j(double d10) {
        double l10 = l("GPSAltitude", -1.0d);
        int m10 = m("GPSAltitudeRef", -1);
        if (l10 < 0.0d || m10 < 0) {
            return d10;
        }
        return l10 * (m10 != 1 ? 1 : -1);
    }

    public final void j0(b bVar) {
        HashMap hashMap = this.f20004f[4];
        d dVar = (d) hashMap.get("Compression");
        if (dVar == null) {
            this.f20013o = 6;
            D(bVar, hashMap);
            return;
        }
        int m10 = dVar.m(this.f20006h);
        this.f20013o = m10;
        if (m10 != 1) {
            if (m10 == 6) {
                D(bVar, hashMap);
                return;
            } else if (m10 != 7) {
                return;
            }
        }
        if (N(hashMap)) {
            E(bVar, hashMap);
        }
    }

    public String k(String str) {
        if (str == null) {
            throw new NullPointerException("tag shouldn't be null");
        }
        d n10 = n(str);
        if (n10 == null) {
            return null;
        }
        if (!str.equals("GPSTimeStamp")) {
            if (!f19986o0.contains(str)) {
                return n10.n(this.f20006h);
            }
            try {
                return Double.toString(n10.l(this.f20006h));
            } catch (NumberFormatException unused) {
                return null;
            }
        }
        int i10 = n10.f20031a;
        if (i10 != 5 && i10 != 10) {
            Log.w("ExifInterface", "GPS Timestamp format is not rational. format=" + n10.f20031a);
            return null;
        }
        f[] fVarArr = (f[]) n10.o(this.f20006h);
        if (fVarArr == null || fVarArr.length != 3) {
            Log.w("ExifInterface", "Invalid GPS Timestamp array. array=" + Arrays.toString(fVarArr));
            return null;
        }
        f fVar = fVarArr[0];
        Integer valueOf = Integer.valueOf((int) (fVar.f20039a / fVar.f20040b));
        f fVar2 = fVarArr[1];
        Integer valueOf2 = Integer.valueOf((int) (fVar2.f20039a / fVar2.f20040b));
        f fVar3 = fVarArr[2];
        return String.format("%02d:%02d:%02d", valueOf, valueOf2, Integer.valueOf((int) (fVar3.f20039a / fVar3.f20040b)));
    }

    public double l(String str, double d10) {
        if (str == null) {
            throw new NullPointerException("tag shouldn't be null");
        }
        d n10 = n(str);
        if (n10 != null) {
            try {
                return n10.l(this.f20006h);
            } catch (NumberFormatException unused) {
            }
        }
        return d10;
    }

    public final void l0(int i10, int i11) {
        if (this.f20004f[i10].isEmpty() || this.f20004f[i11].isEmpty()) {
            if (f19994w) {
                Log.d("ExifInterface", "Cannot perform swap since only one image data exists");
                return;
            }
            return;
        }
        d dVar = (d) this.f20004f[i10].get("ImageLength");
        d dVar2 = (d) this.f20004f[i10].get("ImageWidth");
        d dVar3 = (d) this.f20004f[i11].get("ImageLength");
        d dVar4 = (d) this.f20004f[i11].get("ImageWidth");
        if (dVar == null || dVar2 == null) {
            if (f19994w) {
                Log.d("ExifInterface", "First image does not contain valid size information");
                return;
            }
            return;
        }
        if (dVar3 == null || dVar4 == null) {
            if (f19994w) {
                Log.d("ExifInterface", "Second image does not contain valid size information");
                return;
            }
            return;
        }
        int m10 = dVar.m(this.f20006h);
        int m11 = dVar2.m(this.f20006h);
        int m12 = dVar3.m(this.f20006h);
        int m13 = dVar4.m(this.f20006h);
        if (m10 >= m12 || m11 >= m13) {
            return;
        }
        HashMap[] hashMapArr = this.f20004f;
        HashMap hashMap = hashMapArr[i10];
        hashMapArr[i10] = hashMapArr[i11];
        hashMapArr[i11] = hashMap;
    }

    public int m(String str, int i10) {
        if (str == null) {
            throw new NullPointerException("tag shouldn't be null");
        }
        d n10 = n(str);
        if (n10 != null) {
            try {
                return n10.m(this.f20006h);
            } catch (NumberFormatException unused) {
            }
        }
        return i10;
    }

    public final d n(String str) {
        d dVar;
        d dVar2;
        if (str == null) {
            throw new NullPointerException("tag shouldn't be null");
        }
        if ("ISOSpeedRatings".equals(str)) {
            if (f19994w) {
                Log.d("ExifInterface", "getExifAttribute: Replacing TAG_ISO_SPEED_RATINGS with TAG_PHOTOGRAPHIC_SENSITIVITY.");
            }
            str = "PhotographicSensitivity";
        }
        if ("Xmp".equals(str) && B(this.f20002d) == 2 && (dVar2 = this.f20019u) != null) {
            return dVar2;
        }
        for (int i10 = 0; i10 < f19982k0.length; i10++) {
            d dVar3 = (d) this.f20004f[i10].get(str);
            if (dVar3 != null) {
                return dVar3;
            }
        }
        if (!"Xmp".equals(str) || (dVar = this.f20019u) == null) {
            return null;
        }
        return dVar;
    }

    public final void n0(g gVar, int i10) {
        d j10;
        d j11;
        d dVar = (d) this.f20004f[i10].get("DefaultCropSize");
        d dVar2 = (d) this.f20004f[i10].get("SensorTopBorder");
        d dVar3 = (d) this.f20004f[i10].get("SensorLeftBorder");
        d dVar4 = (d) this.f20004f[i10].get("SensorBottomBorder");
        d dVar5 = (d) this.f20004f[i10].get("SensorRightBorder");
        if (dVar == null) {
            if (dVar2 == null || dVar3 == null || dVar4 == null || dVar5 == null) {
                a0(gVar, i10);
                return;
            }
            int m10 = dVar2.m(this.f20006h);
            int m11 = dVar4.m(this.f20006h);
            int m12 = dVar5.m(this.f20006h);
            int m13 = dVar3.m(this.f20006h);
            if (m11 <= m10 || m12 <= m13) {
                return;
            }
            d j12 = d.j(m11 - m10, this.f20006h);
            d j13 = d.j(m12 - m13, this.f20006h);
            this.f20004f[i10].put("ImageLength", j12);
            this.f20004f[i10].put("ImageWidth", j13);
            return;
        }
        if (dVar.f20031a == 5) {
            f[] fVarArr = (f[]) dVar.o(this.f20006h);
            if (fVarArr == null || fVarArr.length != 2) {
                Log.w("ExifInterface", "Invalid crop size values. cropSize=" + Arrays.toString(fVarArr));
                return;
            }
            j10 = d.h(fVarArr[0], this.f20006h);
            j11 = d.h(fVarArr[1], this.f20006h);
        } else {
            int[] iArr = (int[]) dVar.o(this.f20006h);
            if (iArr == null || iArr.length != 2) {
                Log.w("ExifInterface", "Invalid crop size values. cropSize=" + Arrays.toString(iArr));
                return;
            }
            j10 = d.j(iArr[0], this.f20006h);
            j11 = d.j(iArr[1], this.f20006h);
        }
        this.f20004f[i10].put("ImageWidth", j10);
        this.f20004f[i10].put("ImageLength", j11);
    }

    public final void o(g gVar, int i10) {
        String str;
        String str2;
        String str3;
        int i11 = Build.VERSION.SDK_INT;
        if (i11 < 28) {
            throw new UnsupportedOperationException("Reading EXIF from HEIC files is supported from SDK 28 and above");
        }
        if (i10 == 15 && i11 < 31) {
            throw new UnsupportedOperationException("Reading EXIF from AVIF files is supported from SDK 31 and above");
        }
        MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
        try {
            try {
                AbstractC1890b.a.a(mediaMetadataRetriever, new C0134a(gVar));
                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);
                    str3 = mediaMetadataRetriever.extractMetadata(30);
                    str2 = mediaMetadataRetriever.extractMetadata(31);
                } else if ("yes".equals(extractMetadata4)) {
                    str = mediaMetadataRetriever.extractMetadata(18);
                    str3 = mediaMetadataRetriever.extractMetadata(19);
                    str2 = mediaMetadataRetriever.extractMetadata(24);
                } else {
                    str = null;
                    str2 = null;
                    str3 = null;
                }
                if (str != null) {
                    this.f20004f[0].put("ImageWidth", d.j(Integer.parseInt(str), this.f20006h));
                }
                if (str3 != null) {
                    this.f20004f[0].put("ImageLength", d.j(Integer.parseInt(str3), this.f20006h));
                }
                if (str2 != null) {
                    int parseInt = Integer.parseInt(str2);
                    this.f20004f[0].put("Orientation", d.j(parseInt != 90 ? parseInt != 180 ? parseInt != 270 ? 1 : 8 : 3 : 6, this.f20006h));
                }
                if (extractMetadata != null && extractMetadata2 != null) {
                    int parseInt2 = Integer.parseInt(extractMetadata);
                    int parseInt3 = Integer.parseInt(extractMetadata2);
                    if (parseInt3 <= 6) {
                        throw new IOException("Invalid exif length");
                    }
                    gVar.i(parseInt2);
                    byte[] bArr = new byte[6];
                    gVar.readFully(bArr);
                    int i12 = parseInt2 + 6;
                    int i13 = parseInt3 - 6;
                    if (!Arrays.equals(bArr, f19989r0)) {
                        throw new IOException("Invalid identifier");
                    }
                    byte[] bArr2 = new byte[i13];
                    gVar.readFully(bArr2);
                    this.f20014p = i12;
                    V(bArr2, 0);
                }
                String extractMetadata5 = mediaMetadataRetriever.extractMetadata(41);
                String extractMetadata6 = mediaMetadataRetriever.extractMetadata(42);
                if (extractMetadata5 != null && extractMetadata6 != null) {
                    int parseInt4 = Integer.parseInt(extractMetadata5);
                    int parseInt5 = Integer.parseInt(extractMetadata6);
                    long j10 = parseInt4;
                    gVar.i(j10);
                    byte[] bArr3 = new byte[parseInt5];
                    gVar.readFully(bArr3);
                    this.f20019u = new d(1, parseInt5, j10, bArr3);
                    this.f20020v = true;
                }
                if (f19994w) {
                    Log.d("ExifInterface", "Heif meta: " + str + "x" + str3 + ", rotation " + str2);
                }
                try {
                    mediaMetadataRetriever.release();
                } catch (IOException unused) {
                }
            } finally {
            }
        } catch (RuntimeException e10) {
            throw new UnsupportedOperationException("Failed to read EXIF from HEIF file. Given stream is either malformed or unsupported.", e10);
        }
    }

    public final void o0() {
        l0(0, 5);
        l0(0, 4);
        l0(5, 4);
        d dVar = (d) this.f20004f[1].get("PixelXDimension");
        d dVar2 = (d) this.f20004f[1].get("PixelYDimension");
        if (dVar != null && dVar2 != null) {
            this.f20004f[0].put("ImageWidth", dVar);
            this.f20004f[0].put("ImageLength", dVar2);
        }
        if (this.f20004f[4].isEmpty() && P(this.f20004f[5])) {
            HashMap[] hashMapArr = this.f20004f;
            hashMapArr[4] = hashMapArr[5];
            hashMapArr[5] = new HashMap();
        }
        if (!P(this.f20004f[4])) {
            Log.d("ExifInterface", "No image meets the size requirements of a thumbnail image.");
        }
        Y(0, "ThumbnailOrientation", "Orientation");
        Y(0, "ThumbnailImageLength", "ImageLength");
        Y(0, "ThumbnailImageWidth", "ImageWidth");
        Y(5, "ThumbnailOrientation", "Orientation");
        Y(5, "ThumbnailImageLength", "ImageLength");
        Y(5, "ThumbnailImageWidth", "ImageWidth");
        Y(4, "Orientation", "ThumbnailOrientation");
        Y(4, "ImageLength", "ThumbnailImageLength");
        Y(4, "ImageWidth", "ThumbnailImageWidth");
    }

    public final void p(b bVar, int i10, int i11) {
        if (f19994w) {
            Log.d("ExifInterface", "getJpegAttributes starting with: " + bVar);
        }
        bVar.f(ByteOrder.BIG_ENDIAN);
        byte readByte = bVar.readByte();
        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;
        while (true) {
            byte readByte2 = bVar.readByte();
            if (readByte2 != -1) {
                throw new IOException("Invalid marker:" + Integer.toHexString(readByte2 & 255));
            }
            byte readByte3 = bVar.readByte();
            boolean z10 = f19994w;
            if (z10) {
                Log.d("ExifInterface", "Found JPEG segment indicator: " + Integer.toHexString(readByte3 & 255));
            }
            if (readByte3 != -39 && readByte3 != -38) {
                int readUnsignedShort = bVar.readUnsignedShort();
                int i13 = readUnsignedShort - 2;
                int i14 = i12 + 4;
                if (z10) {
                    Log.d("ExifInterface", "JPEG segment: " + Integer.toHexString(readByte3 & 255) + " (length: " + readUnsignedShort + ")");
                }
                if (i13 < 0) {
                    throw new IOException("Invalid length");
                }
                if (readByte3 == -31) {
                    byte[] bArr = new byte[i13];
                    bVar.readFully(bArr);
                    int i15 = i14 + i13;
                    byte[] bArr2 = f19989r0;
                    if (AbstractC1890b.f(bArr, bArr2)) {
                        byte[] copyOfRange = Arrays.copyOfRange(bArr, bArr2.length, i13);
                        this.f20014p = i10 + i14 + bArr2.length;
                        V(copyOfRange, i11);
                        j0(new b(copyOfRange));
                    } else {
                        byte[] bArr3 = f19990s0;
                        if (AbstractC1890b.f(bArr, bArr3)) {
                            int length = i14 + bArr3.length;
                            byte[] copyOfRange2 = Arrays.copyOfRange(bArr, bArr3.length, i13);
                            this.f20019u = new d(1, copyOfRange2.length, length, copyOfRange2);
                            this.f20020v = true;
                        }
                    }
                    i14 = i15;
                } else if (readByte3 != -2) {
                    switch (readByte3) {
                        default:
                            switch (readByte3) {
                                default:
                                    switch (readByte3) {
                                        default:
                                            switch (readByte3) {
                                            }
                                        case -55:
                                        case -54:
                                        case -53:
                                            bVar.h(1);
                                            this.f20004f[i11].put(i11 != 4 ? "ImageLength" : "ThumbnailImageLength", d.f(bVar.readUnsignedShort(), this.f20006h));
                                            this.f20004f[i11].put(i11 != 4 ? "ImageWidth" : "ThumbnailImageWidth", d.f(bVar.readUnsignedShort(), this.f20006h));
                                            i13 = readUnsignedShort - 7;
                                            break;
                                    }
                                case -59:
                                case -58:
                                case -57:
                                    break;
                            }
                        case -64:
                        case -63:
                        case -62:
                        case -61:
                            break;
                    }
                    if (i13 >= 0) {
                        throw new IOException("Invalid length");
                    }
                    bVar.h(i13);
                    i12 = i14 + i13;
                } else {
                    byte[] bArr4 = new byte[i13];
                    bVar.readFully(bArr4);
                    if (k("UserComment") == null) {
                        this.f20004f[1].put("UserComment", d.e(new String(bArr4, f19988q0)));
                    }
                }
                i13 = 0;
                if (i13 >= 0) {
                }
            }
        }
    }

    public final int p0(c cVar) {
        char c10;
        char c11;
        int i10;
        int i11;
        int i12;
        int i13;
        long j10;
        e[][] eVarArr = f19982k0;
        int[] iArr = new int[eVarArr.length];
        int[] iArr2 = new int[eVarArr.length];
        for (e eVar : f19983l0) {
            X(eVar.f20036b);
        }
        if (this.f20007i) {
            if (this.f20008j) {
                X("StripOffsets");
                X("StripByteCounts");
            } else {
                X("JPEGInterchangeFormat");
                X("JPEGInterchangeFormatLength");
            }
        }
        for (int i14 = 0; i14 < f19982k0.length; i14++) {
            Iterator it = this.f20004f[i14].entrySet().iterator();
            while (it.hasNext()) {
                if (((Map.Entry) it.next()).getValue() == null) {
                    it.remove();
                }
            }
        }
        long j11 = 0;
        if (!this.f20004f[1].isEmpty()) {
            this.f20004f[0].put(f19983l0[1].f20036b, d.f(0L, this.f20006h));
        }
        if (!this.f20004f[2].isEmpty()) {
            this.f20004f[0].put(f19983l0[2].f20036b, d.f(0L, this.f20006h));
        }
        if (this.f20004f[3].isEmpty()) {
            c10 = 2;
        } else {
            c10 = 2;
            this.f20004f[1].put(f19983l0[3].f20036b, d.f(0L, this.f20006h));
        }
        if (this.f20007i) {
            if (!this.f20008j) {
                this.f20004f[4].put("JPEGInterchangeFormat", d.f(0L, this.f20006h));
                c11 = 3;
                this.f20004f[4].put("JPEGInterchangeFormatLength", d.f(this.f20011m, this.f20006h));
                for (i10 = 0; i10 < f19982k0.length; i10++) {
                    Iterator it2 = this.f20004f[i10].entrySet().iterator();
                    int i15 = 0;
                    while (it2.hasNext()) {
                        int p10 = ((d) ((Map.Entry) it2.next()).getValue()).p();
                        if (p10 > 4) {
                            i15 += p10;
                        }
                    }
                    iArr2[i10] = iArr2[i10] + i15;
                }
                int i16 = 8;
                for (i11 = 0; i11 < f19982k0.length; i11++) {
                    if (!this.f20004f[i11].isEmpty()) {
                        iArr[i11] = i16;
                        i16 += (this.f20004f[i11].size() * 12) + 6 + iArr2[i11];
                    }
                }
                if (this.f20007i) {
                    if (this.f20008j) {
                        this.f20004f[4].put("StripOffsets", d.j(i16, this.f20006h));
                    } else {
                        this.f20004f[4].put("JPEGInterchangeFormat", d.f(i16, this.f20006h));
                    }
                    this.f20010l = i16;
                    i16 += this.f20011m;
                }
                if (this.f20002d == 4) {
                    i16 += 8;
                }
                if (f19994w) {
                    for (int i17 = 0; i17 < f19982k0.length; i17++) {
                        Integer valueOf = Integer.valueOf(i17);
                        Integer valueOf2 = Integer.valueOf(iArr[i17]);
                        Integer valueOf3 = Integer.valueOf(this.f20004f[i17].size());
                        Integer valueOf4 = Integer.valueOf(iArr2[i17]);
                        Integer valueOf5 = Integer.valueOf(i16);
                        Object[] objArr = new Object[5];
                        objArr[0] = valueOf;
                        objArr[1] = valueOf2;
                        objArr[c10] = valueOf3;
                        objArr[c11] = valueOf4;
                        objArr[4] = valueOf5;
                        Log.d("ExifInterface", String.format("index: %d, offsets: %d, tag count: %d, data sizes: %d, total size: %d", objArr));
                    }
                }
                if (!this.f20004f[1].isEmpty()) {
                    this.f20004f[0].put(f19983l0[1].f20036b, d.f(iArr[1], this.f20006h));
                }
                if (!this.f20004f[c10].isEmpty()) {
                    this.f20004f[0].put(f19983l0[c10].f20036b, d.f(iArr[c10], this.f20006h));
                }
                if (!this.f20004f[c11].isEmpty()) {
                    this.f20004f[1].put(f19983l0[c11].f20036b, d.f(iArr[c11], this.f20006h));
                }
                i12 = this.f20002d;
                if (i12 != 4) {
                    if (i16 > 65535) {
                        throw new IllegalStateException("Size of exif data (" + i16 + " bytes) exceeds the max size of a JPEG APP1 segment (65536 bytes)");
                    }
                    cVar.h(i16);
                    cVar.write(f19989r0);
                } else if (i12 == 13) {
                    cVar.c(i16);
                    cVar.c(1700284774);
                } else if (i12 == 14) {
                    cVar.write(f19960O);
                    cVar.c(i16);
                }
                int size = cVar.f20029l.size();
                cVar.e(this.f20006h != ByteOrder.BIG_ENDIAN ? (short) 19789 : (short) 18761);
                cVar.a(this.f20006h);
                cVar.h(42);
                cVar.f(8L);
                i13 = 0;
                while (i13 < f19982k0.length) {
                    if (this.f20004f[i13].isEmpty()) {
                        j10 = j11;
                    } else {
                        cVar.h(this.f20004f[i13].size());
                        int size2 = iArr[i13] + 2 + (this.f20004f[i13].size() * 12) + 4;
                        for (Map.Entry entry : this.f20004f[i13].entrySet()) {
                            int i18 = ((e) f19985n0[i13].get(entry.getKey())).f20035a;
                            d dVar = (d) entry.getValue();
                            int p11 = dVar.p();
                            cVar.h(i18);
                            cVar.h(dVar.f20031a);
                            cVar.c(dVar.f20032b);
                            if (p11 > 4) {
                                cVar.f(size2);
                                size2 += p11;
                            } else {
                                cVar.write(dVar.f20034d);
                                if (p11 < 4) {
                                    while (p11 < 4) {
                                        cVar.b(0);
                                        p11++;
                                    }
                                }
                            }
                        }
                        if (i13 != 0 || this.f20004f[4].isEmpty()) {
                            j10 = 0;
                            cVar.f(0L);
                        } else {
                            cVar.f(iArr[4]);
                            j10 = 0;
                        }
                        Iterator it3 = this.f20004f[i13].entrySet().iterator();
                        while (it3.hasNext()) {
                            byte[] bArr = ((d) ((Map.Entry) it3.next()).getValue()).f20034d;
                            if (bArr.length > 4) {
                                cVar.write(bArr, 0, bArr.length);
                            }
                        }
                    }
                    i13++;
                    j11 = j10;
                }
                if (this.f20007i) {
                    cVar.write(z());
                }
                if (this.f20002d == 14 && i16 % 2 == 1) {
                    cVar.b(0);
                }
                cVar.a(ByteOrder.BIG_ENDIAN);
                return size;
            }
            this.f20004f[4].put("StripOffsets", d.j(0, this.f20006h));
            this.f20004f[4].put("StripByteCounts", d.j(this.f20011m, this.f20006h));
        }
        c11 = 3;
        while (i10 < f19982k0.length) {
        }
        int i162 = 8;
        while (i11 < f19982k0.length) {
        }
        if (this.f20007i) {
        }
        if (this.f20002d == 4) {
        }
        if (f19994w) {
        }
        if (!this.f20004f[1].isEmpty()) {
        }
        if (!this.f20004f[c10].isEmpty()) {
        }
        if (!this.f20004f[c11].isEmpty()) {
        }
        i12 = this.f20002d;
        if (i12 != 4) {
        }
        int size3 = cVar.f20029l.size();
        cVar.e(this.f20006h != ByteOrder.BIG_ENDIAN ? (short) 19789 : (short) 18761);
        cVar.a(this.f20006h);
        cVar.h(42);
        cVar.f(8L);
        i13 = 0;
        while (i13 < f19982k0.length) {
        }
        if (this.f20007i) {
        }
        if (this.f20002d == 14) {
            cVar.b(0);
        }
        cVar.a(ByteOrder.BIG_ENDIAN);
        return size3;
    }

    public double[] q() {
        String k10 = k("GPSLatitude");
        String k11 = k("GPSLatitudeRef");
        String k12 = k("GPSLongitude");
        String k13 = k("GPSLongitudeRef");
        if (k10 == null || k11 == null || k12 == null || k13 == null) {
            return null;
        }
        try {
            return new double[]{g(k10, k11), g(k12, k13)};
        } catch (IllegalArgumentException unused) {
            Log.w("ExifInterface", "Latitude/longitude values are not parsable. " + String.format("latValue=%s, latRef=%s, lngValue=%s, lngRef=%s", k10, k11, k12, k13));
            return null;
        }
    }

    public final void q0(c cVar) {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        this.f20014p = cVar.f20029l.size() + p0(new c(byteArrayOutputStream, ByteOrder.BIG_ENDIAN));
        byte[] byteArray = byteArrayOutputStream.toByteArray();
        cVar.write(byteArray);
        CRC32 crc32 = new CRC32();
        crc32.update(byteArray, 4, byteArray.length - 4);
        cVar.c((int) crc32.getValue());
    }

    public final int r(BufferedInputStream bufferedInputStream) {
        bufferedInputStream.mark(5000);
        byte[] bArr = new byte[5000];
        bufferedInputStream.read(bArr);
        bufferedInputStream.reset();
        if (H(bArr)) {
            return 4;
        }
        if (K(bArr)) {
            return 9;
        }
        int G10 = G(bArr);
        if (G10 != 0) {
            return G10;
        }
        if (I(bArr)) {
            return 7;
        }
        if (L(bArr)) {
            return 10;
        }
        if (J(bArr)) {
            return 13;
        }
        return Q(bArr) ? 14 : 0;
    }

    public final void r0(c cVar) {
        cVar.c(this.f20019u.f20034d.length + 22);
        CRC32 crc32 = new CRC32();
        cVar.c(1767135348);
        m0(crc32, 1767135348);
        byte[] bArr = f19957L;
        cVar.write(bArr);
        crc32.update(bArr);
        cVar.write(this.f20019u.f20034d);
        crc32.update(this.f20019u.f20034d);
        cVar.c((int) crc32.getValue());
        this.f20020v = true;
    }

    public final void s(g gVar) {
        int i10;
        int i11;
        v(gVar);
        d dVar = (d) this.f20004f[1].get("MakerNote");
        if (dVar != null) {
            g gVar2 = new g(dVar.f20034d);
            gVar2.f(this.f20006h);
            byte[] bArr = f19954I;
            byte[] bArr2 = new byte[bArr.length];
            gVar2.readFully(bArr2);
            gVar2.i(0L);
            byte[] bArr3 = f19955J;
            byte[] bArr4 = new byte[bArr3.length];
            gVar2.readFully(bArr4);
            if (Arrays.equals(bArr2, bArr)) {
                gVar2.i(8L);
            } else if (Arrays.equals(bArr4, bArr3)) {
                gVar2.i(12L);
            }
            W(gVar2, 6);
            d dVar2 = (d) this.f20004f[7].get("PreviewImageStart");
            d dVar3 = (d) this.f20004f[7].get("PreviewImageLength");
            if (dVar2 != null && dVar3 != null) {
                this.f20004f[5].put("JPEGInterchangeFormat", dVar2);
                this.f20004f[5].put("JPEGInterchangeFormatLength", dVar3);
            }
            d dVar4 = (d) this.f20004f[8].get("AspectFrame");
            if (dVar4 != null) {
                int[] iArr = (int[]) dVar4.o(this.f20006h);
                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;
                }
                d j10 = d.j(i14, this.f20006h);
                d j11 = d.j(i15, this.f20006h);
                this.f20004f[0].put("ImageWidth", j10);
                this.f20004f[0].put("ImageLength", j11);
            }
        }
    }

    public final void t(b bVar) {
        if (f19994w) {
            Log.d("ExifInterface", "getPngAttributes starting with: " + bVar);
        }
        bVar.f(ByteOrder.BIG_ENDIAN);
        int b10 = bVar.b();
        bVar.h(f19956K.length);
        boolean z10 = false;
        boolean z11 = false;
        while (true) {
            if (z10 && z11) {
                break;
            }
            try {
                int readInt = bVar.readInt();
                int readInt2 = bVar.readInt();
                int b11 = bVar.b() + readInt + 4;
                if (bVar.b() - b10 == 16 && readInt2 != 1229472850) {
                    throw new IOException("Encountered invalid PNG file--IHDR chunk should appear as the first chunk");
                }
                if (readInt2 == 1229278788) {
                    break;
                }
                if (readInt2 == 1700284774 && !z10) {
                    this.f20014p = bVar.b() - b10;
                    byte[] bArr = new byte[readInt];
                    bVar.readFully(bArr);
                    int readInt3 = bVar.readInt();
                    CRC32 crc32 = new CRC32();
                    m0(crc32, readInt2);
                    crc32.update(bArr);
                    if (((int) crc32.getValue()) != readInt3) {
                        throw new IOException("Encountered invalid CRC value for PNG-EXIF chunk.\n recorded CRC value: " + readInt3 + ", calculated CRC value: " + crc32.getValue());
                    }
                    V(bArr, 0);
                    o0();
                    j0(new b(bArr));
                    z10 = true;
                } else if (readInt2 == 1767135348 && !z11) {
                    byte[] bArr2 = f19957L;
                    if (readInt >= bArr2.length) {
                        int length = bArr2.length;
                        byte[] bArr3 = new byte[length];
                        bVar.readFully(bArr3);
                        if (Arrays.equals(bArr3, bArr2)) {
                            int b12 = bVar.b() - b10;
                            int i10 = readInt - length;
                            byte[] bArr4 = new byte[i10];
                            bVar.readFully(bArr4);
                            this.f20019u = new d(1, i10, b12, bArr4);
                            z11 = true;
                        }
                    }
                }
                bVar.h(b11 - bVar.b());
            } catch (EOFException e10) {
                throw new IOException("Encountered corrupt PNG file.", e10);
            }
        }
        this.f20020v = z11;
    }

    public final void u(b bVar) {
        boolean z10 = f19994w;
        if (z10) {
            Log.d("ExifInterface", "getRafAttributes starting with: " + bVar);
        }
        bVar.h(84);
        byte[] bArr = new byte[4];
        byte[] bArr2 = new byte[4];
        byte[] bArr3 = new byte[4];
        bVar.readFully(bArr);
        bVar.readFully(bArr2);
        bVar.readFully(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.h(i10 - bVar.b());
        bVar.readFully(bArr4);
        p(new b(bArr4), i10, 5);
        bVar.h(i12 - bVar.b());
        bVar.f(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 == f19977f0.f20035a) {
                short readShort = bVar.readShort();
                short readShort2 = bVar.readShort();
                d j10 = d.j(readShort, this.f20006h);
                d j11 = d.j(readShort2, this.f20006h);
                this.f20004f[0].put("ImageLength", j10);
                this.f20004f[0].put("ImageWidth", j11);
                if (f19994w) {
                    Log.d("ExifInterface", "Updated to length: " + ((int) readShort) + ", width: " + ((int) readShort2));
                    return;
                }
                return;
            }
            bVar.h(readUnsignedShort2);
        }
    }

    public final void v(g gVar) {
        d dVar;
        S(gVar);
        W(gVar, 0);
        n0(gVar, 0);
        n0(gVar, 5);
        n0(gVar, 4);
        o0();
        if (this.f20002d != 8 || (dVar = (d) this.f20004f[1].get("MakerNote")) == null) {
            return;
        }
        g gVar2 = new g(dVar.f20034d);
        gVar2.f(this.f20006h);
        gVar2.h(6);
        W(gVar2, 9);
        d dVar2 = (d) this.f20004f[9].get("ColorSpace");
        if (dVar2 != null) {
            this.f20004f[1].put("ColorSpace", dVar2);
        }
    }

    public final void w(g gVar) {
        if (f19994w) {
            Log.d("ExifInterface", "getRw2Attributes starting with: " + gVar);
        }
        v(gVar);
        d dVar = (d) this.f20004f[0].get("JpgFromRaw");
        if (dVar != null) {
            p(new b(dVar.f20034d), (int) dVar.f20033c, 5);
        }
        d dVar2 = (d) this.f20004f[0].get("ISO");
        d dVar3 = (d) this.f20004f[1].get("PhotographicSensitivity");
        if (dVar2 == null || dVar3 != null) {
            return;
        }
        this.f20004f[1].put("PhotographicSensitivity", dVar2);
    }

    public final boolean x(g gVar) {
        byte[] bArr = f19989r0;
        byte[] bArr2 = new byte[bArr.length];
        gVar.readFully(bArr2);
        if (!Arrays.equals(bArr2, bArr)) {
            Log.w("ExifInterface", "Given data is not EXIF-only.");
            return false;
        }
        byte[] c10 = gVar.c();
        this.f20014p = bArr.length;
        V(c10, 0);
        return true;
    }

    public byte[] y() {
        int i10 = this.f20013o;
        if (i10 == 6 || i10 == 7) {
            return z();
        }
        return null;
    }

    public byte[] z() {
        FileDescriptor fileDescriptor;
        InputStream inputStream;
        Exception e10;
        InputStream inputStream2 = null;
        if (!this.f20007i) {
            return null;
        }
        byte[] bArr = this.f20012n;
        if (bArr != null) {
            return bArr;
        }
        try {
            inputStream = this.f20001c;
            try {
                try {
                    if (inputStream != null) {
                        try {
                            if (!inputStream.markSupported()) {
                                Log.d("ExifInterface", "Cannot read thumbnail from inputstream without mark/reset support");
                                AbstractC1890b.b(inputStream);
                                return null;
                            }
                            inputStream.reset();
                        } catch (Exception e11) {
                            e10 = e11;
                            fileDescriptor = null;
                            Log.d("ExifInterface", "Encountered exception while getting thumbnail", e10);
                            AbstractC1890b.b(inputStream);
                            if (fileDescriptor != null) {
                            }
                            return null;
                        } catch (Throwable th) {
                            th = th;
                            fileDescriptor = null;
                            inputStream2 = inputStream;
                            AbstractC1890b.b(inputStream2);
                            if (fileDescriptor != null) {
                            }
                            throw th;
                        }
                    } else {
                        if (this.f19999a == null) {
                            FileDescriptor dup = Os.dup(this.f20000b);
                            try {
                                Os.lseek(dup, 0L, OsConstants.SEEK_SET);
                                fileDescriptor = dup;
                                inputStream = new FileInputStream(dup);
                                b bVar = new b(inputStream);
                                bVar.h(this.f20010l + this.f20014p);
                                byte[] bArr2 = new byte[this.f20011m];
                                bVar.readFully(bArr2);
                                this.f20012n = bArr2;
                                AbstractC1890b.b(inputStream);
                                if (fileDescriptor != null) {
                                    AbstractC1890b.a(fileDescriptor);
                                }
                                return bArr2;
                            } catch (Exception e12) {
                                e10 = e12;
                                fileDescriptor = dup;
                                inputStream = null;
                                Log.d("ExifInterface", "Encountered exception while getting thumbnail", e10);
                                AbstractC1890b.b(inputStream);
                                if (fileDescriptor != null) {
                                }
                                return null;
                            } catch (Throwable th2) {
                                th = th2;
                                fileDescriptor = dup;
                                AbstractC1890b.b(inputStream2);
                                if (fileDescriptor != null) {
                                }
                                throw th;
                            }
                        }
                        inputStream = new FileInputStream(this.f19999a);
                    }
                    b bVar2 = new b(inputStream);
                    bVar2.h(this.f20010l + this.f20014p);
                    byte[] bArr22 = new byte[this.f20011m];
                    bVar2.readFully(bArr22);
                    this.f20012n = bArr22;
                    AbstractC1890b.b(inputStream);
                    if (fileDescriptor != null) {
                    }
                    return bArr22;
                } catch (Exception e13) {
                    e10 = e13;
                    Log.d("ExifInterface", "Encountered exception while getting thumbnail", e10);
                    AbstractC1890b.b(inputStream);
                    if (fileDescriptor != null) {
                        AbstractC1890b.a(fileDescriptor);
                    }
                    return null;
                }
            } catch (Throwable th3) {
                th = th3;
                inputStream2 = inputStream;
                AbstractC1890b.b(inputStream2);
                if (fileDescriptor != null) {
                    AbstractC1890b.a(fileDescriptor);
                }
                throw th;
            }
            fileDescriptor = null;
        } catch (Exception e14) {
            inputStream = null;
            e10 = e14;
            fileDescriptor = null;
        } catch (Throwable th4) {
            th = th4;
            fileDescriptor = null;
        }
    }

    public static class b extends InputStream implements DataInput {

        public final DataInputStream f20024l;

        public int f20025m;

        public ByteOrder f20026n;

        public byte[] f20027o;

        public int f20028p;

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

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

        @Override
        public int available() {
            return this.f20024l.available();
        }

        public int b() {
            return this.f20025m;
        }

        public byte[] c() {
            byte[] bArr = new byte[1024];
            int i10 = 0;
            while (true) {
                if (i10 == bArr.length) {
                    bArr = Arrays.copyOf(bArr, bArr.length * 2);
                }
                int read = this.f20024l.read(bArr, i10, bArr.length - i10);
                if (read == -1) {
                    return Arrays.copyOf(bArr, i10);
                }
                i10 += read;
                this.f20025m += read;
            }
        }

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

        public void f(ByteOrder byteOrder) {
            this.f20026n = byteOrder;
        }

        public void h(int i10) {
            int i11 = 0;
            while (i11 < i10) {
                int i12 = i10 - i11;
                int skip = (int) this.f20024l.skip(i12);
                if (skip <= 0) {
                    if (this.f20027o == null) {
                        this.f20027o = new byte[8192];
                    }
                    skip = this.f20024l.read(this.f20027o, 0, Math.min(8192, i12));
                    if (skip == -1) {
                        throw new EOFException("Reached EOF while skipping " + i10 + " bytes.");
                    }
                }
                i11 += skip;
            }
            this.f20025m += i11;
        }

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

        @Override
        public int read() {
            this.f20025m++;
            return this.f20024l.read();
        }

        @Override
        public boolean readBoolean() {
            this.f20025m++;
            return this.f20024l.readBoolean();
        }

        @Override
        public byte readByte() {
            this.f20025m++;
            int read = this.f20024l.read();
            if (read >= 0) {
                return (byte) read;
            }
            throw new EOFException();
        }

        @Override
        public char readChar() {
            this.f20025m += 2;
            return this.f20024l.readChar();
        }

        @Override
        public double readDouble() {
            return Double.longBitsToDouble(readLong());
        }

        @Override
        public float readFloat() {
            return Float.intBitsToFloat(readInt());
        }

        @Override
        public void readFully(byte[] bArr, int i10, int i11) {
            this.f20025m += i11;
            this.f20024l.readFully(bArr, i10, i11);
        }

        @Override
        public int readInt() {
            this.f20025m += 4;
            int read = this.f20024l.read();
            int read2 = this.f20024l.read();
            int read3 = this.f20024l.read();
            int read4 = this.f20024l.read();
            if ((read | read2 | read3 | read4) < 0) {
                throw new EOFException();
            }
            ByteOrder byteOrder = this.f20026n;
            if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
                return (read4 << 24) + (read3 << 16) + (read2 << 8) + read;
            }
            if (byteOrder == ByteOrder.BIG_ENDIAN) {
                return (read << 24) + (read2 << 16) + (read3 << 8) + read4;
            }
            throw new IOException("Invalid byte order: " + this.f20026n);
        }

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

        @Override
        public long readLong() {
            this.f20025m += 8;
            int read = this.f20024l.read();
            int read2 = this.f20024l.read();
            int read3 = this.f20024l.read();
            int read4 = this.f20024l.read();
            int read5 = this.f20024l.read();
            int read6 = this.f20024l.read();
            int read7 = this.f20024l.read();
            int read8 = this.f20024l.read();
            if ((read | read2 | read3 | read4 | read5 | read6 | read7 | read8) < 0) {
                throw new EOFException();
            }
            ByteOrder byteOrder = this.f20026n;
            if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
                return (read8 << 56) + (read7 << 48) + (read6 << 40) + (read5 << 32) + (read4 << 24) + (read3 << 16) + (read2 << 8) + read;
            }
            if (byteOrder == ByteOrder.BIG_ENDIAN) {
                return (read << 56) + (read2 << 48) + (read3 << 40) + (read4 << 32) + (read5 << 24) + (read6 << 16) + (read7 << 8) + read8;
            }
            throw new IOException("Invalid byte order: " + this.f20026n);
        }

        @Override
        public short readShort() {
            this.f20025m += 2;
            int read = this.f20024l.read();
            int read2 = this.f20024l.read();
            if ((read | read2) < 0) {
                throw new EOFException();
            }
            ByteOrder byteOrder = this.f20026n;
            if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
                return (short) ((read2 << 8) + read);
            }
            if (byteOrder == ByteOrder.BIG_ENDIAN) {
                return (short) ((read << 8) + read2);
            }
            throw new IOException("Invalid byte order: " + this.f20026n);
        }

        @Override
        public String readUTF() {
            this.f20025m += 2;
            return this.f20024l.readUTF();
        }

        @Override
        public int readUnsignedByte() {
            this.f20025m++;
            return this.f20024l.readUnsignedByte();
        }

        @Override
        public int readUnsignedShort() {
            this.f20025m += 2;
            int read = this.f20024l.read();
            int read2 = this.f20024l.read();
            if ((read | read2) < 0) {
                throw new EOFException();
            }
            ByteOrder byteOrder = this.f20026n;
            if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
                return (read2 << 8) + read;
            }
            if (byteOrder == ByteOrder.BIG_ENDIAN) {
                return (read << 8) + read2;
            }
            throw new IOException("Invalid byte order: " + this.f20026n);
        }

        @Override
        public void reset() {
            throw new UnsupportedOperationException("Reset is currently unsupported");
        }

        @Override
        public int skipBytes(int i10) {
            throw new UnsupportedOperationException("skipBytes is currently unsupported");
        }

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

        @Override
        public int read(byte[] bArr, int i10, int i11) {
            int read = this.f20024l.read(bArr, i10, i11);
            this.f20025m += read;
            return read;
        }

        @Override
        public void readFully(byte[] bArr) {
            this.f20025m += bArr.length;
            this.f20024l.readFully(bArr);
        }

        public b(InputStream inputStream, ByteOrder byteOrder) {
            DataInputStream dataInputStream = new DataInputStream(inputStream);
            this.f20024l = dataInputStream;
            dataInputStream.mark(0);
            this.f20025m = 0;
            this.f20026n = byteOrder;
            this.f20028p = inputStream instanceof b ? ((b) inputStream).a() : -1;
        }
    }

    public static class g extends b {
        public g(byte[] bArr) {
            super(bArr);
            this.f20024l.mark(Integer.MAX_VALUE);
        }

        public void i(long j10) {
            int i10 = this.f20025m;
            if (i10 > j10) {
                this.f20025m = 0;
                this.f20024l.reset();
            } else {
                j10 -= i10;
            }
            h((int) j10);
        }

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

    public static class e {

        public final int f20035a;

        public final String f20036b;

        public final int f20037c;

        public final int f20038d;

        public e(String str, int i10, int i11) {
            this.f20036b = str;
            this.f20035a = i10;
            this.f20037c = i11;
            this.f20038d = -1;
        }

        public boolean a(int i10) {
            int i11;
            int i12 = this.f20037c;
            if (i12 == 7 || i10 == 7 || i12 == i10 || (i11 = this.f20038d) == 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;
        }

        public e(String str, int i10, int i11, int i12) {
            this.f20036b = str;
            this.f20035a = i10;
            this.f20037c = i11;
            this.f20038d = i12;
        }
    }

    public C1889a(String str) {
        e[][] eVarArr = f19982k0;
        this.f20004f = new HashMap[eVarArr.length];
        this.f20005g = new HashSet(eVarArr.length);
        this.f20006h = ByteOrder.BIG_ENDIAN;
        if (str != null) {
            F(str);
            return;
        }
        throw new NullPointerException("filename cannot be null");
    }

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

    public C1889a(InputStream inputStream, int i10) {
        e[][] eVarArr = f19982k0;
        this.f20004f = new HashMap[eVarArr.length];
        this.f20005g = new HashSet(eVarArr.length);
        this.f20006h = ByteOrder.BIG_ENDIAN;
        if (inputStream != null) {
            this.f19999a = null;
            boolean z10 = i10 == 1;
            this.f20003e = z10;
            if (z10) {
                this.f20001c = null;
                this.f20000b = null;
            } else if (inputStream instanceof AssetManager.AssetInputStream) {
                this.f20001c = (AssetManager.AssetInputStream) inputStream;
                this.f20000b = null;
            } else {
                if (inputStream instanceof FileInputStream) {
                    FileInputStream fileInputStream = (FileInputStream) inputStream;
                    if (M(fileInputStream.getFD())) {
                        this.f20001c = null;
                        this.f20000b = fileInputStream.getFD();
                    }
                }
                this.f20001c = null;
                this.f20000b = null;
            }
            R(inputStream);
            return;
        }
        throw new NullPointerException("inputStream cannot be null");
    }

    public class C0134a extends MediaDataSource {

        public long f20021l;

        public final g f20022m;

        public C0134a(g gVar) {
            this.f20022m = gVar;
        }

        @Override
        public long getSize() {
            return -1L;
        }

        @Override
        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.f20021l;
                if (j11 != j10) {
                    if (j11 >= 0 && j10 >= j11 + this.f20022m.available()) {
                        return -1;
                    }
                    this.f20022m.i(j10);
                    this.f20021l = j10;
                }
                if (i11 > this.f20022m.available()) {
                    i11 = this.f20022m.available();
                }
                int read = this.f20022m.read(bArr, i10, i11);
                if (read >= 0) {
                    this.f20021l += read;
                    return read;
                }
            } catch (IOException unused) {
            }
            this.f20021l = -1L;
            return -1;
        }

        @Override
        public void close() {
        }
    }
}