package e7; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Rect; import android.util.ArrayMap; import android.util.SparseBooleanArray; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; /* loaded from: classes2.dex */ public final class b { /* renamed from: f, reason: collision with root package name */ static final InterfaceC0138b f9374f = new d(); /* renamed from: a, reason: collision with root package name */ private final List f9375a; /* renamed from: b, reason: collision with root package name */ private final List f9376b; /* renamed from: d, reason: collision with root package name */ private final SparseBooleanArray f9378d = new SparseBooleanArray(); /* renamed from: c, reason: collision with root package name */ private final Map f9377c = new ArrayMap(); /* renamed from: e, reason: collision with root package name */ private final c f9379e = a(); public static final class a { /* renamed from: a, reason: collision with root package name */ private final List f9380a; /* renamed from: b, reason: collision with root package name */ private final Bitmap f9381b; /* renamed from: c, reason: collision with root package name */ private final List f9382c; /* renamed from: d, reason: collision with root package name */ private int f9383d; /* renamed from: e, reason: collision with root package name */ private int f9384e; /* renamed from: f, reason: collision with root package name */ private int f9385f; /* renamed from: g, reason: collision with root package name */ private final List f9386g; /* renamed from: h, reason: collision with root package name */ private Rect f9387h; /* renamed from: i, reason: collision with root package name */ private e7.c f9388i; public a(Bitmap bitmap) { ArrayList arrayList = new ArrayList(); this.f9382c = arrayList; this.f9383d = 16; this.f9384e = 12544; this.f9385f = -1; ArrayList arrayList2 = new ArrayList(); this.f9386g = arrayList2; if (bitmap == null || bitmap.isRecycled()) { throw new IllegalArgumentException("Bitmap is not valid"); } arrayList2.add(b.f9374f); this.f9381b = bitmap; this.f9380a = null; arrayList.add(e7.d.f9398e); arrayList.add(e7.d.f9399f); arrayList.add(e7.d.f9400g); arrayList.add(e7.d.f9401h); arrayList.add(e7.d.f9402i); arrayList.add(e7.d.f9403j); } private int[] b(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); int[] iArr = new int[width * height]; bitmap.getPixels(iArr, 0, width, 0, 0, width, height); Rect rect = this.f9387h; if (rect == null) { return iArr; } int width2 = rect.width(); int height2 = this.f9387h.height(); int[] iArr2 = new int[width2 * height2]; for (int i10 = 0; i10 < height2; i10++) { Rect rect2 = this.f9387h; System.arraycopy(iArr, ((rect2.top + i10) * width) + rect2.left, iArr2, i10 * width2, width2); } return iArr2; } private Bitmap c(Bitmap bitmap) { int max; int i10; double d10; if (this.f9384e > 0) { int width = bitmap.getWidth() * bitmap.getHeight(); int i11 = this.f9384e; if (width > i11) { d10 = Math.sqrt(i11 / width); } d10 = -1.0d; } else { if (this.f9385f > 0 && (max = Math.max(bitmap.getWidth(), bitmap.getHeight())) > (i10 = this.f9385f)) { d10 = i10 / max; } d10 = -1.0d; } return d10 <= 0.0d ? bitmap : Bitmap.createScaledBitmap(bitmap, (int) Math.ceil(bitmap.getWidth() * d10), (int) Math.ceil(bitmap.getHeight() * d10), false); } public b a() { List list; InterfaceC0138b[] interfaceC0138bArr; Bitmap bitmap = this.f9381b; if (bitmap != null) { Bitmap c10 = c(bitmap); Rect rect = this.f9387h; if (c10 != this.f9381b && rect != null) { double width = c10.getWidth() / this.f9381b.getWidth(); rect.left = (int) Math.floor(rect.left * width); rect.top = (int) Math.floor(rect.top * width); rect.right = Math.min((int) Math.ceil(rect.right * width), c10.getWidth()); rect.bottom = Math.min((int) Math.ceil(rect.bottom * width), c10.getHeight()); } if (this.f9388i == null) { this.f9388i = new e(); } e7.c cVar = this.f9388i; int[] b10 = b(c10); int i10 = this.f9383d; if (this.f9386g.isEmpty()) { interfaceC0138bArr = null; } else { List list2 = this.f9386g; interfaceC0138bArr = (InterfaceC0138b[]) list2.toArray(new InterfaceC0138b[list2.size()]); } cVar.b(b10, i10, interfaceC0138bArr); if (c10 != this.f9381b) { c10.recycle(); } list = this.f9388i.a(); } else { list = this.f9380a; } b bVar = new b(list, this.f9382c); bVar.c(); return bVar; } } /* renamed from: e7.b$b, reason: collision with other inner class name */ public interface InterfaceC0138b { boolean a(int i10, float[] fArr); } public static final class c { /* renamed from: a, reason: collision with root package name */ private final int f9389a; /* renamed from: b, reason: collision with root package name */ private final int f9390b; /* renamed from: c, reason: collision with root package name */ private final int f9391c; /* renamed from: d, reason: collision with root package name */ private final int f9392d; /* renamed from: e, reason: collision with root package name */ private final int f9393e; /* renamed from: f, reason: collision with root package name */ private boolean f9394f; /* renamed from: g, reason: collision with root package name */ private int f9395g; /* renamed from: h, reason: collision with root package name */ private int f9396h; /* renamed from: i, reason: collision with root package name */ private float[] f9397i; public c(int i10, int i11) { this.f9389a = Color.red(i10); this.f9390b = Color.green(i10); this.f9391c = Color.blue(i10); this.f9392d = i10; this.f9393e = i11; } private void a() { int m10; if (this.f9394f) { return; } int e10 = e7.a.e(-1, this.f9392d, 4.5f); int e11 = e7.a.e(-1, this.f9392d, 3.0f); if (e10 == -1 || e11 == -1) { int e12 = e7.a.e(-16777216, this.f9392d, 4.5f); int e13 = e7.a.e(-16777216, this.f9392d, 3.0f); if (e12 == -1 || e13 == -1) { this.f9396h = e10 != -1 ? e7.a.m(-1, e10) : e7.a.m(-16777216, e12); this.f9395g = e11 != -1 ? e7.a.m(-1, e11) : e7.a.m(-16777216, e13); this.f9394f = true; return; } this.f9396h = e7.a.m(-16777216, e12); m10 = e7.a.m(-16777216, e13); } else { this.f9396h = e7.a.m(-1, e10); m10 = e7.a.m(-1, e11); } this.f9395g = m10; this.f9394f = true; } public int b() { a(); return this.f9396h; } public float[] c() { if (this.f9397i == null) { this.f9397i = new float[3]; } e7.a.a(this.f9389a, this.f9390b, this.f9391c, this.f9397i); return this.f9397i; } public int d() { return this.f9393e; } public int e() { return this.f9392d; } public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || c.class != obj.getClass()) { return false; } c cVar = (c) obj; return this.f9393e == cVar.f9393e && this.f9392d == cVar.f9392d; } public int f() { a(); return this.f9395g; } public int hashCode() { return (this.f9392d * 31) + this.f9393e; } public String toString() { return c.class.getSimpleName() + " [RGB: #" + Integer.toHexString(e()) + "] [HSL: " + Arrays.toString(c()) + "] [Population: " + this.f9393e + "] [Title Text: #" + Integer.toHexString(f()) + "] [Body Text: #" + Integer.toHexString(b()) + ']'; } } class d implements InterfaceC0138b { d() { } private boolean b(float[] fArr) { return fArr[2] <= 0.05f; } private boolean c(float[] fArr) { float f10 = fArr[0]; return f10 >= 10.0f && f10 <= 37.0f && fArr[1] <= 0.82f; } private boolean d(float[] fArr) { return fArr[2] >= 0.95f; } @Override // e7.b.InterfaceC0138b public boolean a(int i10, float[] fArr) { return (d(fArr) || b(fArr) || c(fArr)) ? false : true; } } b(List list, List list2) { this.f9375a = list; this.f9376b = list2; } private c a() { int size = this.f9375a.size(); int i10 = RecyclerView.UNDEFINED_DURATION; c cVar = null; for (int i11 = 0; i11 < size; i11++) { c cVar2 = (c) this.f9375a.get(i11); if (cVar2.d() > i10) { i10 = cVar2.d(); cVar = cVar2; } } return cVar; } public static a b(Bitmap bitmap) { return new a(bitmap); } private float d(c cVar, e7.d dVar) { float[] c10 = cVar.c(); c cVar2 = this.f9379e; return (dVar.g() > 0.0f ? dVar.g() * (1.0f - Math.abs(c10[1] - dVar.i())) : 0.0f) + (dVar.a() > 0.0f ? dVar.a() * (1.0f - Math.abs(c10[2] - dVar.h())) : 0.0f) + (dVar.f() > 0.0f ? dVar.f() * (cVar.d() / (cVar2 != null ? cVar2.d() : 1)) : 0.0f); } private c e(e7.d dVar) { c j10 = j(dVar); if (j10 != null && dVar.j()) { this.f9378d.append(j10.e(), true); } return j10; } private c j(e7.d dVar) { int size = this.f9375a.size(); float f10 = 0.0f; c cVar = null; for (int i10 = 0; i10 < size; i10++) { c cVar2 = (c) this.f9375a.get(i10); if (l(cVar2, dVar)) { float d10 = d(cVar2, dVar); if (cVar == null || d10 > f10) { cVar = cVar2; f10 = d10; } } } return cVar; } private boolean l(c cVar, e7.d dVar) { float[] c10 = cVar.c(); return c10[1] >= dVar.e() && c10[1] <= dVar.c() && c10[2] >= dVar.d() && c10[2] <= dVar.b() && !this.f9378d.get(cVar.e()); } void c() { int size = this.f9376b.size(); for (int i10 = 0; i10 < size; i10++) { e7.d dVar = (e7.d) this.f9376b.get(i10); dVar.k(); this.f9377c.put(dVar, e(dVar)); } this.f9378d.clear(); } public c f() { return k(e7.d.f9403j); } public c g() { return k(e7.d.f9400g); } public c h() { return k(e7.d.f9401h); } public c i() { return k(e7.d.f9398e); } public c k(e7.d dVar) { return (c) this.f9377c.get(dVar); } }