package c.a.h; import android.graphics.Color; import android.util.SparseIntArray; import d0.z.d.m; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.PriorityQueue; import kotlin.jvm.internal.DefaultConstructorMarker; /* compiled from: ColorCutQuantizer.kt */ public final class a { public static final b a = new b(null); public final float[] b = new float[3]; /* renamed from: c reason: collision with root package name */ public final int[] f57c; public final SparseIntArray d; public final List e; /* compiled from: ColorCutQuantizer.kt */ /* renamed from: c.a.h.a$a reason: collision with other inner class name */ public static final class C0026a implements Comparator { public static final C0026a i = new C0026a(); /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.Object] */ @Override // java.util.Comparator public int compare(c cVar, c cVar2) { return cVar2.b() - cVar.b(); } } /* compiled from: ColorCutQuantizer.kt */ public static final class b { public b(DefaultConstructorMarker defaultConstructorMarker) { } } /* compiled from: ColorCutQuantizer.kt */ public final class c { public int a; public int b; /* renamed from: c reason: collision with root package name */ public int f58c; public int d; public int e; public int f; public final int g; public int h; public c(int i, int i2) { this.g = i; this.h = i2; a(); } public final void a() { this.e = 255; this.f58c = 255; this.a = 255; this.f = 0; this.d = 0; this.b = 0; int i = this.g; int i2 = this.h; if (i <= i2) { while (true) { int i3 = a.this.f57c[i]; int red = Color.red(i3); int green = Color.green(i3); int blue = Color.blue(i3); if (red > this.b) { this.b = red; } if (red < this.a) { this.a = red; } if (green > this.d) { this.d = green; } if (green < this.f58c) { this.f58c = green; } if (blue > this.f) { this.f = blue; } if (blue < this.e) { this.e = blue; } if (i != i2) { i++; } else { return; } } } } public final int b() { return ((this.f - this.e) + 1) * ((this.d - this.f58c) + 1) * ((this.b - this.a) + 1); } } /* JADX WARNING: Removed duplicated region for block: B:123:0x025b */ /* JADX WARNING: Removed duplicated region for block: B:134:0x00a7 A[SYNTHETIC] */ /* JADX WARNING: Removed duplicated region for block: B:149:0x0268 A[SYNTHETIC] */ /* JADX WARNING: Removed duplicated region for block: B:152:0x01bb A[SYNTHETIC] */ /* JADX WARNING: Removed duplicated region for block: B:35:0x009b */ /* JADX WARNING: Removed duplicated region for block: B:38:0x00a0 */ public a(b bVar, int i, DefaultConstructorMarker defaultConstructorMarker) { int i2; int i3; int i4; int i5; boolean z2; boolean z3; c cVar; boolean z4; boolean z5; if (i >= 1) { int i6 = bVar.d; int[] iArr = bVar.b; int[] iArr2 = bVar.f59c; this.d = new SparseIntArray(i6); int length = iArr.length; for (int i7 = 0; i7 < length; i7++) { this.d.append(iArr[i7], iArr2[i7]); } this.f57c = new int[i6]; int i8 = 0; for (int i9 : iArr) { int alpha = Color.alpha(i9); c.a(Color.red(i9), Color.green(i9), Color.blue(i9), this.b); if (alpha >= 250) { float[] fArr = this.b; if (!(fArr[2] >= 0.95f)) { if (!(fArr[2] <= 0.05f)) { float f = fArr[0]; if (!(f >= 10.0f && f <= 37.0f && fArr[1] <= 0.82f)) { z5 = false; if (!z5) { z4 = false; if (z4) { this.f57c[i8] = i9; i8++; } } } } } z5 = true; if (!z5) { } } z4 = true; if (z4) { } } if (i8 <= i) { this.e = new ArrayList(); int[] iArr3 = this.f57c; for (int i10 : iArr3) { this.e.add(new d(i10, this.d.get(i10))); } return; } PriorityQueue priorityQueue = new PriorityQueue(i, C0026a.i); priorityQueue.offer(new c(0, i8 - 1)); while (priorityQueue.size() < i && (cVar = (c) priorityQueue.poll()) != null) { int i11 = cVar.h; int i12 = cVar.g; int i13 = i11 - i12; if (!(i13 > 1)) { break; } if (i13 > 1) { int i14 = cVar.b - cVar.a; int i15 = cVar.d - cVar.f58c; int i16 = cVar.f - cVar.e; int i17 = (i14 < i15 || i14 < i16) ? (i15 < i14 || i15 < i16) ? -1 : -2 : -3; a(a.this, i17, i12, i11); Arrays.sort(a.this.f57c, cVar.g, cVar.h + 1); a(a.this, i17, cVar.g, cVar.h); int i18 = i17 != -3 ? i17 != -2 ? i17 != -1 ? (cVar.a + cVar.b) / 2 : (cVar.e + cVar.f) / 2 : (cVar.f58c + cVar.d) / 2 : (cVar.a + cVar.b) / 2; int i19 = cVar.g; int i20 = cVar.h; while (true) { if (i19 >= i20) { i19 = cVar.g; break; } int i21 = a.this.f57c[i19]; if (i17 != -3) { if (i17 != -2) { if (i17 == -1 && Color.blue(i21) > i18) { break; } } else if (Color.green(i21) >= i18) { break; } } else if (Color.red(i21) >= i18) { break; } i19++; } c cVar2 = new c(i19 + 1, cVar.h); cVar.h = i19; cVar.a(); priorityQueue.offer(cVar2); priorityQueue.offer(cVar); } else { throw new IllegalStateException("Can not split a box with only 1 color".toString()); } } ArrayList arrayList = new ArrayList(priorityQueue.size()); Iterator it = priorityQueue.iterator(); while (it.hasNext()) { c cVar3 = (c) it.next(); int i22 = cVar3.g; int i23 = cVar3.h; if (i22 <= i23) { i5 = 0; i4 = 0; i3 = 0; i2 = 0; while (true) { a aVar = a.this; int i24 = aVar.f57c[i22]; int i25 = aVar.d.get(i24); i5 += i25; i4 = (Color.red(i24) * i25) + i4; i3 = (Color.green(i24) * i25) + i3; i2 += Color.blue(i24) * i25; if (i22 == i23) { break; } i22++; } } else { i5 = 0; i4 = 0; i3 = 0; i2 = 0; } float f2 = (float) i5; d dVar = new d(Math.round(((float) i4) / f2), Math.round(((float) i3) / f2), Math.round(((float) i2) / f2), i5); float[] a2 = dVar.a(); m.checkNotNullExpressionValue(a2, "color.hsl"); if (!(a2[2] >= 0.95f)) { if (!(a2[2] <= 0.05f)) { float f3 = a2[0]; if (f3 >= 10.0f) { if (f3 <= 37.0f) { if (a2[1] <= 0.82f) { z3 = true; if (!z3) { z2 = false; if (!z2) { arrayList.add(dVar); } } z2 = true; if (!z2) { } } z3 = false; if (!z3) { } z2 = true; if (!z2) { } } } z3 = false; if (!z3) { } z2 = true; if (!z2) { } } } z2 = true; if (!z2) { } } this.e = arrayList; return; } throw new IllegalArgumentException("maxColors must be 1 or greater".toString()); } public static final void a(a aVar, int i, int i2, int i3) { Objects.requireNonNull(aVar); if (i == -2) { while (i2 <= i3) { int[] iArr = aVar.f57c; int i4 = iArr[i2]; iArr[i2] = Color.rgb((i4 >> 8) & 255, (i4 >> 16) & 255, i4 & 255); i2++; } } else if (i == -1) { while (i2 <= i3) { int[] iArr2 = aVar.f57c; int i5 = iArr2[i2]; iArr2[i2] = Color.rgb(i5 & 255, (i5 >> 8) & 255, (i5 >> 16) & 255); i2++; } } } }