discord-jadx/app/src/main/java/com/discord/utilities/colors/RepresentativeColors.java

237 lines
8.4 KiB
Java
Raw Normal View History

2021-06-27 20:44:35 +00:00
package com.discord.utilities.colors;
import android.graphics.Bitmap;
import android.graphics.Color;
import androidx.annotation.ColorInt;
import androidx.core.graphics.ColorUtils;
2021-12-21 23:37:30 +00:00
import b.a.g.a;
import b.a.g.b;
import b.a.g.d;
import b.d.b.a.a;
import b.i.a.f.e.o.f;
2021-11-08 18:25:28 +00:00
import d0.z.d.m;
2021-06-27 20:44:35 +00:00
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import kotlin.coroutines.Continuation;
import kotlin.jvm.internal.DefaultConstructorMarker;
2021-07-09 21:07:36 +00:00
import kotlinx.coroutines.CoroutineDispatcher;
2021-06-27 20:44:35 +00:00
import rx.Observable;
import rx.subjects.BehaviorSubject;
2021-11-08 18:25:28 +00:00
import s.a.a.n;
2021-12-17 22:03:14 +00:00
import s.a.k0;
import s.a.x0;
2021-06-27 20:44:35 +00:00
/* compiled from: RepresentativeColors.kt */
2022-03-08 21:11:21 +00:00
/* loaded from: classes2.dex */
2021-06-27 20:44:35 +00:00
public final class RepresentativeColors<T> {
private final HashMap<T, Integer> representativeColors = new HashMap<>();
2021-10-26 23:51:06 +00:00
private final BehaviorSubject<Map<T, Integer>> representativeColorsSubject = BehaviorSubject.k0();
2022-03-02 20:59:20 +00:00
public static final Companion Companion = new Companion(null);
private static final int BLURPLE = Color.parseColor("#5865f2");
2021-06-27 20:44:35 +00:00
/* compiled from: RepresentativeColors.kt */
2022-03-08 21:11:21 +00:00
/* loaded from: classes2.dex */
2021-06-27 20:44:35 +00:00
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
2021-08-18 19:46:22 +00:00
/* compiled from: RepresentativeColors.kt */
2022-03-08 21:11:21 +00:00
/* loaded from: classes2.dex */
2021-08-18 19:46:22 +00:00
public static final class NoSwatchesFoundException extends RuntimeException {
}
2021-06-27 20:44:35 +00:00
/* compiled from: RepresentativeColors.kt */
2022-03-08 21:11:21 +00:00
/* loaded from: classes2.dex */
2021-06-27 20:44:35 +00:00
public static abstract class RepresentativeColorResult {
/* compiled from: RepresentativeColors.kt */
2022-03-08 21:11:21 +00:00
/* loaded from: classes2.dex */
2021-06-27 20:44:35 +00:00
public static final class Failure extends RepresentativeColorResult {
private final Exception exception;
2022-03-02 20:59:20 +00:00
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
2021-06-27 20:44:35 +00:00
public Failure(Exception exc) {
super(null);
m.checkNotNullParameter(exc, "exception");
this.exception = exc;
}
public static /* synthetic */ Failure copy$default(Failure failure, Exception exc, int i, Object obj) {
if ((i & 1) != 0) {
exc = failure.exception;
}
return failure.copy(exc);
}
public final Exception component1() {
return this.exception;
}
public final Failure copy(Exception exc) {
m.checkNotNullParameter(exc, "exception");
return new Failure(exc);
}
public boolean equals(Object obj) {
if (this != obj) {
return (obj instanceof Failure) && m.areEqual(this.exception, ((Failure) obj).exception);
}
return true;
}
public final Exception getException() {
return this.exception;
}
public int hashCode() {
Exception exc = this.exception;
if (exc != null) {
return exc.hashCode();
}
return 0;
}
public String toString() {
2021-11-08 18:25:28 +00:00
StringBuilder R = a.R("Failure(exception=");
R.append(this.exception);
R.append(")");
return R.toString();
2021-06-27 20:44:35 +00:00
}
}
/* compiled from: RepresentativeColors.kt */
2022-03-08 21:11:21 +00:00
/* loaded from: classes2.dex */
2021-06-27 20:44:35 +00:00
public static final class Success extends RepresentativeColorResult {
private final int color;
public Success(@ColorInt int i) {
super(null);
this.color = i;
}
public static /* synthetic */ Success copy$default(Success success, int i, int i2, Object obj) {
if ((i2 & 1) != 0) {
i = success.color;
}
return success.copy(i);
}
public final int component1() {
return this.color;
}
public final Success copy(@ColorInt int i) {
return new Success(i);
}
public boolean equals(Object obj) {
if (this != obj) {
return (obj instanceof Success) && this.color == ((Success) obj).color;
}
return true;
}
public final int getColor() {
return this.color;
}
public int hashCode() {
return this.color;
}
public String toString() {
2021-11-08 18:25:28 +00:00
return a.A(a.R("Success(color="), this.color, ")");
2021-06-27 20:44:35 +00:00
}
}
private RepresentativeColorResult() {
}
public /* synthetic */ RepresentativeColorResult(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
public static final /* synthetic */ int access$getBLURPLE$cp() {
return BLURPLE;
}
public static final /* synthetic */ RepresentativeColorResult access$getRepresentativeColor(RepresentativeColors representativeColors, Bitmap bitmap) {
return representativeColors.getRepresentativeColor(bitmap);
}
public static final /* synthetic */ HashMap access$getRepresentativeColors$p(RepresentativeColors representativeColors) {
return representativeColors.representativeColors;
}
public static final /* synthetic */ BehaviorSubject access$getRepresentativeColorsSubject$p(RepresentativeColors representativeColors) {
return representativeColors.representativeColorsSubject;
}
private final int getColorDistance(int i, int i2) {
int i3 = ((i >> 16) & 255) - ((i2 >> 16) & 255);
int i4 = ((i >> 8) & 255) - ((i2 >> 8) & 255);
int i5 = (i & 255) - (i2 & 255);
return Math.abs((i5 * i5) + (i4 * i4) + (i3 * i3));
}
private final List<Integer> getPrimaryColorsForBitmap(Bitmap bitmap) {
2021-12-21 23:37:30 +00:00
a.b bVar = b.a.g.a.a;
2021-06-27 20:44:35 +00:00
m.checkNotNullParameter(bitmap, "bitmap");
int width = bitmap.getWidth();
int height = bitmap.getHeight();
2022-03-02 20:59:20 +00:00
int[] iArr = new int[width * height];
2021-06-27 20:44:35 +00:00
bitmap.getPixels(iArr, 0, width, 0, 0, width, height);
2021-12-21 23:37:30 +00:00
List<d> list = new b.a.g.a(new b(iArr), 2, null).e;
2021-08-18 19:46:22 +00:00
if (!list.isEmpty()) {
2021-11-08 18:25:28 +00:00
return d0.t.m.listOf(Integer.valueOf(list.get(0).d));
2021-08-18 19:46:22 +00:00
}
throw new NoSwatchesFoundException();
2021-06-27 20:44:35 +00:00
}
private final RepresentativeColorResult getRepresentativeColor(Bitmap bitmap) {
try {
int alphaComponent = ColorUtils.setAlphaComponent(getPrimaryColorsForBitmap(bitmap).get(0).intValue(), 255);
int i = Integer.MAX_VALUE;
int width = bitmap.getWidth();
int i2 = alphaComponent;
for (int i3 = 0; i3 < width; i3++) {
int height = bitmap.getHeight();
for (int i4 = 0; i4 < height; i4++) {
int alphaComponent2 = ColorUtils.setAlphaComponent(bitmap.getPixel(i3, i4), 255);
int colorDistance = getColorDistance(alphaComponent, alphaComponent2);
if (colorDistance < i) {
i2 = alphaComponent2;
i = colorDistance;
}
}
}
return new RepresentativeColorResult.Success(i2);
} catch (Exception e) {
return new RepresentativeColorResult.Failure(e);
}
}
public final Object getRepresentativeColorAsync(Bitmap bitmap, Continuation<? super RepresentativeColorResult> continuation) {
2022-01-27 00:50:41 +00:00
return f.C1(k0.a, new RepresentativeColors$getRepresentativeColorAsync$2(this, bitmap, null), continuation);
2021-06-27 20:44:35 +00:00
}
2021-08-18 19:46:22 +00:00
public final void handleBitmap(T t, Bitmap bitmap, String str) {
2021-06-27 20:44:35 +00:00
m.checkNotNullParameter(bitmap, "bitmap");
2021-12-17 22:03:14 +00:00
x0 x0Var = x0.j;
CoroutineDispatcher coroutineDispatcher = k0.a;
2022-03-02 20:59:20 +00:00
f.H0(x0Var, n.f3804b, null, new RepresentativeColors$handleBitmap$1(this, t, bitmap, str, null), 2, null);
2021-06-27 20:44:35 +00:00
}
public final Observable<Integer> observeRepresentativeColor(T t) {
2021-10-26 23:51:06 +00:00
Observable<Integer> q = this.representativeColorsSubject.F(new RepresentativeColors$observeRepresentativeColor$1(t)).q();
2021-10-19 23:48:27 +00:00
m.checkNotNullExpressionValue(q, "representativeColorsSubj… .distinctUntilChanged()");
return q;
2021-06-27 20:44:35 +00:00
}
}