package com.applovin.impl; import android.graphics.Bitmap; import androidx.work.WorkInfo; import com.applovin.impl.b5; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.zip.Inflater; /* loaded from: classes.dex */ public final class jh extends ek { private final bh o; private final bh p; private final a q; private Inflater r; public jh() { super("PgsDecoder"); this.o = new bh(); this.p = new bh(); this.q = new a(); } @Override // com.applovin.impl.ek public nl a(byte[] bArr, int i, boolean z) { this.o.a(bArr, i); a(this.o); this.q.b(); ArrayList arrayList = new ArrayList(); while (this.o.a() >= 3) { b5 a2 = a(this.o, this.q); if (a2 != null) { arrayList.add(a2); } } return new kh(Collections.unmodifiableList(arrayList)); } public static final class a { private final bh a = new bh(); private final int[] b = new int[256]; private boolean c; private int d; private int e; private int f; private int g; private int h; private int i; /* JADX INFO: Access modifiers changed from: private */ public void c(bh bhVar, int i) { if (i % 5 != 2) { return; } bhVar.g(2); Arrays.fill(this.b, 0); int i2 = i / 5; for (int i3 = 0; i3 < i2; i3++) { int w = bhVar.w(); int w2 = bhVar.w(); int w3 = bhVar.w(); int w4 = bhVar.w(); int w5 = bhVar.w(); double d = w2; double d2 = w3 + WorkInfo.STOP_REASON_FOREGROUND_SERVICE_TIMEOUT; double d3 = w4 + WorkInfo.STOP_REASON_FOREGROUND_SERVICE_TIMEOUT; this.b[w] = (xp.a((int) ((d - (0.34414d * d3)) - (d2 * 0.71414d)), 0, 255) << 8) | (w5 << 24) | (xp.a((int) ((1.402d * d2) + d), 0, 255) << 16) | xp.a((int) (d + (d3 * 1.772d)), 0, 255); } this.c = true; } /* JADX INFO: Access modifiers changed from: private */ public void b(bh bhVar, int i) { if (i < 19) { return; } this.d = bhVar.C(); this.e = bhVar.C(); bhVar.g(11); this.f = bhVar.C(); this.g = bhVar.C(); } public b5 a() { int i; if (this.d == 0 || this.e == 0 || this.h == 0 || this.i == 0 || this.a.e() == 0 || this.a.d() != this.a.e() || !this.c) { return null; } this.a.f(0); int i2 = this.h * this.i; int[] iArr = new int[i2]; int i3 = 0; while (i3 < i2) { int w = this.a.w(); if (w != 0) { i = i3 + 1; iArr[i3] = this.b[w]; } else { int w2 = this.a.w(); if (w2 != 0) { i = ((w2 & 64) == 0 ? w2 & 63 : ((w2 & 63) << 8) | this.a.w()) + i3; Arrays.fill(iArr, i3, i, (w2 & 128) == 0 ? 0 : this.b[this.a.w()]); } } i3 = i; } return new b5.b().a(Bitmap.createBitmap(iArr, this.h, this.i, Bitmap.Config.ARGB_8888)).b(this.f / this.d).b(0).a(this.g / this.e, 0).a(0).d(this.h / this.d).a(this.i / this.e).a(); } /* JADX INFO: Access modifiers changed from: private */ public void a(bh bhVar, int i) { int z; if (i < 4) { return; } bhVar.g(3); int i2 = i - 4; if ((bhVar.w() & 128) != 0) { if (i2 < 7 || (z = bhVar.z()) < 4) { return; } this.h = bhVar.C(); this.i = bhVar.C(); this.a.d(z - 4); i2 = i - 11; } int d = this.a.d(); int e = this.a.e(); if (d >= e || i2 <= 0) { return; } int min = Math.min(i2, e - d); bhVar.a(this.a.c(), d, min); this.a.f(d + min); } public void b() { this.d = 0; this.e = 0; this.f = 0; this.g = 0; this.h = 0; this.i = 0; this.a.d(0); this.c = false; } } private void a(bh bhVar) { if (bhVar.a() <= 0 || bhVar.g() != 120) { return; } if (this.r == null) { this.r = new Inflater(); } if (xp.a(bhVar, this.p, this.r)) { bhVar.a(this.p.c(), this.p.e()); } } private static b5 a(bh bhVar, a aVar) { int e = bhVar.e(); int w = bhVar.w(); int C = bhVar.C(); int d = bhVar.d() + C; b5 b5Var = null; if (d > e) { bhVar.f(e); return null; } if (w != 128) { switch (w) { case 20: aVar.c(bhVar, C); break; case 21: aVar.a(bhVar, C); break; case 22: aVar.b(bhVar, C); break; } } else { b5Var = aVar.a(); aVar.b(); } bhVar.f(d); return b5Var; } }