package Y;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.util.SparseArray;
import androidx.core.view.ViewCompat;
import b0.o;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class c {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private int[] f1834a;

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private int f1839f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private int f1840g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private int f1841h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private int f1842i;

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

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public long f1845l;

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

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

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

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

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    private byte[] f1850q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    int f1851r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    int f1852s;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    SparseArray f1855v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    IntBuffer f1856w;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private int[] f1835b = new int[4];

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    boolean f1853t = false;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    boolean f1854u = true;

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

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    int f1857x = this.f1837d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private int f1838e;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    int f1858y = this.f1838e;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    int f1859z = 0;

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    int f1832A = 0;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    boolean f1833B = true;

    class a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public List f1860a;

        public a(List list) {
            this.f1860a = list;
        }

        public String toString() {
            return "BitmapLine [items=" + this.f1860a + "]";
        }
    }

    class b {

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

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

        public b(int i2, int i3) {
            this.f1862a = i2;
            this.f1863b = i3;
        }

        public String toString() {
            return "ColorItem [colorNum=" + this.f1862a + ", colorIndex=" + this.f1863b + "]";
        }
    }

    public c(int[] iArr, long j2, byte[] bArr) {
        this.f1834a = iArr;
        this.f1850q = bArr;
        this.f1845l = j2;
        c();
    }

    public static int a(byte[] bArr, int i2, int i3) {
        int i4 = i3 - 1;
        int i5 = 0;
        for (int i6 = i2; i6 < i2 + i3; i6++) {
            i5 += (bArr[i6] & 255) << (i4 * 8);
            i4--;
        }
        return i5;
    }

    private void c() {
        f();
    }

    private void d() {
        o.c("VobSubBitmapFactory", 16, "Default color table 1 = ", Integer.toHexString(this.f1835b[0]), " 2 = ", Integer.toHexString(this.f1835b[1]), " 3 = ", Integer.toHexString(this.f1835b[2]), " 4 = ", Integer.toHexString(this.f1835b[3]));
        int[] iArr = this.f1835b;
        iArr[0] = 0;
        int i2 = iArr[1];
        if (i2 == 0) {
            iArr[1] = -1;
        } else {
            if ((i2 & ViewCompat.MEASURED_STATE_MASK) <= 0) {
                i2 |= ViewCompat.MEASURED_STATE_MASK;
            }
            iArr[1] = i2;
        }
        int i3 = iArr[2];
        if ((i3 & ViewCompat.MEASURED_STATE_MASK) <= 0) {
            i3 |= ViewCompat.MEASURED_STATE_MASK;
        }
        iArr[2] = i3;
        int i4 = iArr[3];
        if ((i4 & ViewCompat.MEASURED_STATE_MASK) <= 0) {
            i4 |= ViewCompat.MEASURED_STATE_MASK;
        }
        iArr[3] = i4;
        iArr[3] = 0;
        o.c("VobSubBitmapFactory", 16, "Adapter color table 1 = ", Integer.toHexString(0), " 2 = ", Integer.toHexString(this.f1835b[1]), " 3 = ", Integer.toHexString(this.f1835b[2]), " 4 = ", Integer.toHexString(this.f1835b[3]));
    }

    private void e(Bitmap bitmap) {
        int i2 = this.f1837d * this.f1838e;
        this.f1855v = new SparseArray();
        ArrayList arrayList = new ArrayList();
        this.f1855v.put(0, new a(arrayList));
        int i3 = 0;
        int i4 = 0;
        while (true) {
            boolean z2 = this.f1854u;
            if ((!z2 || this.f1846m >= this.f1848o) && (z2 || this.f1847n >= this.f1849p)) {
                return;
            }
            int iG = g();
            if (iG >= 4 || (iG = (iG << 4) | g()) >= 16 || (iG = (iG << 4) | g()) >= 64 || (iG = (iG << 4) | g()) >= 256) {
                int i5 = iG >> 2;
                int i6 = iG & 3;
                int i7 = i3 + i5;
                int i8 = this.f1837d;
                if (i7 > i8) {
                    i5 = i8 - i3;
                }
                int i9 = i8 * i4;
                arrayList.add(new b(i5, i6));
                if (Color.alpha(this.f1835b[i6]) != 0) {
                    this.f1857x = Math.min(this.f1857x, i3);
                    this.f1858y = Math.min(this.f1858y, i4);
                    this.f1859z = Math.max(this.f1859z, (i3 + i5) - 1);
                    this.f1832A = Math.max(this.f1832A, i4);
                }
                i3 += i5;
                if (i9 + i3 >= i2) {
                    o.c("VobSubBitmapFactory", 16, "finish  1 break");
                    return;
                } else if (i3 < this.f1837d) {
                    continue;
                }
            }
            int i10 = iG & 3;
            int i11 = this.f1837d;
            int i12 = i11 - i3;
            if (i12 > 0) {
                int i13 = i11 * i4;
                arrayList.add(new b(i12, i10));
                if (Color.alpha(this.f1835b[i10]) != 0) {
                    this.f1857x = Math.min(this.f1857x, i3);
                    this.f1858y = Math.min(this.f1858y, i4);
                    this.f1859z = Math.max(this.f1859z, (i3 + i12) - 1);
                    this.f1832A = Math.max(this.f1832A, i4);
                }
                if (i13 + i3 + i12 >= i2) {
                    o.c("VobSubBitmapFactory", 16, "finish  2 break");
                    return;
                }
            }
            if (this.f1853t) {
                o.c("VobSubBitmapFactory", 16, "need read left byte~~");
                g();
            }
            i4++;
            this.f1854u = !this.f1854u;
            arrayList = new ArrayList();
            this.f1855v.put(i4, new a(arrayList));
            i3 = 0;
        }
    }

    private void f() {
        int i2;
        int i3;
        int i4;
        int i5;
        int i6;
        int i7 = 0;
        this.f1851r = a(this.f1850q, 0, 2);
        this.f1852s = a(this.f1850q, 2, 2);
        o.c("VobSubBitmapFactory", 16, "mPackageSize  = ", Integer.valueOf(this.f1851r), " mDataSize = ", Integer.valueOf(this.f1852s));
        int i8 = this.f1852s;
        int iA = 0;
        while (true) {
            int iA2 = a(this.f1850q, i8, 2);
            int iA3 = a(this.f1850q, i8 + 2, 2);
            int i9 = i8 + 4;
            o.c("VobSubBitmapFactory", 16, "dcsqStm = ", Integer.valueOf(iA2), " nextDcsq = ", Integer.valueOf(iA3), " index = ", Integer.valueOf(i9));
            int i10 = i7;
            while (true) {
                if (i10 == 0) {
                    int iH = h(this.f1850q[i9], 8);
                    o.c("VobSubBitmapFactory", 16, " mData[", Integer.valueOf(i9), "] = ", Integer.valueOf(iH));
                    switch (iH) {
                        case 0:
                        case 1:
                        case 2:
                        default:
                            i4 = i7;
                            break;
                        case 3:
                        case 4:
                            i4 = 2;
                            break;
                        case 5:
                            i4 = 6;
                            break;
                        case 6:
                            i4 = 4;
                            break;
                    }
                    if (i4 + i9 < this.f1851r) {
                        int i11 = i9 + 1;
                        int iH2 = h(this.f1850q[i9], 8);
                        o.c("VobSubBitmapFactory", 16, " mData[", Integer.valueOf(i11), "] = ", Integer.valueOf(iH2));
                        switch (iH2) {
                            case -1:
                                i10 = 1;
                                i9 = i11;
                                i7 = 0;
                                break;
                            case 0:
                                i5 = 0;
                                i7 = i5;
                                break;
                            case 1:
                                i5 = 0;
                                long j2 = this.f1845l + ((long) (((iA2 << 10) / 90) * 1000));
                                this.f1843j = j2;
                                o.c("VobSubBitmapFactory", 16, " startTime = ", Long.valueOf(j2));
                                i7 = i5;
                                break;
                            case 2:
                                i5 = 0;
                                long j3 = this.f1845l + ((long) (((iA2 << 10) / 90) * 1000));
                                this.f1844k = j3;
                                o.c("VobSubBitmapFactory", 16, " endTime = ", Long.valueOf(j3));
                                i7 = i5;
                                break;
                            case 3:
                                i5 = 0;
                                i9 += 3;
                                iA = a(this.f1850q, i11, 2);
                                i7 = i5;
                                break;
                            case 4:
                                i5 = 0;
                                this.f1836c = a(this.f1850q, i11, 2);
                                i9 += 3;
                                i7 = i5;
                                break;
                            case 5:
                                int[] iArr = new int[6];
                                int i12 = i11;
                                int i13 = 0;
                                while (true) {
                                    int i14 = i9 + 7;
                                    if (i12 >= i14) {
                                        i5 = 0;
                                        int i15 = iArr[0] << 4;
                                        int i16 = iArr[1];
                                        this.f1839f = i15 + (i16 >>> 4);
                                        int i17 = iArr[3] << 4;
                                        int i18 = iArr[4];
                                        this.f1842i = i17 + (i18 >>> 4);
                                        int i19 = ((i16 & 15) << 8) + iArr[2];
                                        this.f1840g = i19;
                                        this.f1841h = ((i18 & 15) << 8) + iArr[5];
                                        o.c("VobSubBitmapFactory", 16, " i4_right = ", Integer.valueOf(i19), " i4_left = ", Integer.valueOf(this.f1839f));
                                        o.c("VobSubBitmapFactory", 16, " i4_bottom = ", Integer.valueOf(this.f1841h), " i4_top = ", Integer.valueOf(this.f1842i));
                                        int i20 = (this.f1840g - this.f1839f) + 1;
                                        this.f1837d = i20;
                                        this.f1838e = (this.f1841h - this.f1842i) + 1;
                                        o.c("VobSubBitmapFactory", 16, " width = ", Integer.valueOf(i20), " height = ", Integer.valueOf(this.f1838e));
                                        i9 = (this.f1837d <= 2 || this.f1838e <= 2) ? i11 : i14;
                                        i7 = i5;
                                    } else {
                                        iArr[i13] = h(this.f1850q[i12], 8);
                                        i13++;
                                        i12++;
                                    }
                                    break;
                                }
                                break;
                            case 6:
                                this.f1846m = a(this.f1850q, i11, 2);
                                this.f1847n = a(this.f1850q, i9 + 3, 2);
                                i9 += 5;
                                o.c("VobSubBitmapFactory", 16, "evenIndex = ", Integer.valueOf(this.f1846m), " unevenIndex = ", Integer.valueOf(this.f1847n), " mDataSize = ", Integer.valueOf(this.f1852s));
                                int i21 = this.f1846m;
                                int i22 = this.f1847n;
                                if (i21 < i22 && i22 < (i6 = this.f1852s)) {
                                    this.f1848o = i22;
                                    this.f1849p = i6;
                                    o.c("VobSubBitmapFactory", 16, "eventOff = ", Integer.valueOf(i22 - i21), " totalOff = ", Integer.valueOf(i6 - i21));
                                }
                                i5 = 0;
                                i7 = i5;
                                break;
                            default:
                                i10 = 1;
                                i9 = i11;
                                i5 = 0;
                                i7 = i5;
                                break;
                        }
                    } else {
                        o.c("VobSubBitmapFactory", 16, "index+skipLen >= mPackageSize");
                    }
                }
            }
            i2 = i7;
            if (i9 <= iA3 && i9 < (i3 = this.f1851r) && iA3 < i3 - 4) {
                i8 = iA3;
                i7 = i2;
            }
        }
        for (int i23 = i2; i23 < 4; i23++) {
            if (iA > 0) {
                int i24 = (iA >> (i23 << 2)) & 15;
                o.c("VobSubBitmapFactory", 16, "color table index = ", Integer.valueOf(i24), " color = ", Integer.toHexString(this.f1834a[i24]));
                this.f1835b[i23] = this.f1834a[i24];
            } else {
                this.f1835b[i23] = this.f1834a[i23];
            }
        }
        d();
    }

    public static int h(int i2, int i3) {
        return i2 >= 0 ? i2 : i2 + ((int) Math.pow(2.0d, i3));
    }

    public Bitmap b() {
        int i2 = this.f1837d;
        this.f1857x = i2;
        int i3 = this.f1838e;
        this.f1858y = i3;
        this.f1859z = 0;
        this.f1832A = 0;
        Bitmap.Config config = Bitmap.Config.ARGB_8888;
        Bitmap bitmapCreateBitmap = Bitmap.createBitmap(i2, i3, config);
        e(bitmapCreateBitmap);
        int i4 = (this.f1859z - this.f1857x) + 1;
        int i5 = (this.f1832A - this.f1858y) + 1;
        if (i4 <= 1 || i5 <= 1 || !this.f1833B) {
            this.f1856w = IntBuffer.allocate(this.f1837d * this.f1838e);
            for (int i6 = 0; i6 < this.f1838e; i6++) {
                for (b bVar : ((a) this.f1855v.get(i6)).f1860a) {
                    for (int i7 = 0; i7 < bVar.f1862a; i7++) {
                        this.f1856w.put(this.f1835b[bVar.f1863b]);
                    }
                }
            }
        } else {
            bitmapCreateBitmap = Bitmap.createBitmap(i4, i5, config);
            this.f1856w = IntBuffer.allocate(i4 * i5);
            for (int i8 = 0; i8 < this.f1838e; i8++) {
                int i9 = 0;
                for (b bVar2 : ((a) this.f1855v.get(i8)).f1860a) {
                    int i10 = this.f1835b[bVar2.f1863b];
                    for (int i11 = 0; i11 < bVar2.f1862a; i11++) {
                        if (i9 >= this.f1857x && i8 >= this.f1858y && i9 <= this.f1859z && i8 <= this.f1832A) {
                            this.f1856w.put(i10);
                        }
                        i9++;
                    }
                }
            }
            o.c("VobSubBitmapFactory", 16, "get new non transparent bitmap w= ", i4 + ", h= ", Integer.valueOf(i5), ", oldw=", Integer.valueOf(this.f1837d), ",oldh=", Integer.valueOf(this.f1838e));
        }
        this.f1856w.rewind();
        bitmapCreateBitmap.copyPixelsFromBuffer(this.f1856w);
        return bitmapCreateBitmap;
    }

    public int g() {
        int iH = h(this.f1850q[this.f1854u ? this.f1846m : this.f1847n], 8);
        boolean z2 = this.f1853t;
        int i2 = (iH >> (z2 ? 0 : 4)) & 15;
        if (z2) {
            if (this.f1854u) {
                this.f1846m++;
            } else {
                this.f1847n++;
            }
        }
        this.f1853t = !z2;
        return i2;
    }
}
