116 lines
4.5 KiB
Java
116 lines
4.5 KiB
Java
package com.google.maps.android.heatmaps;
|
|
|
|
import android.graphics.Color;
|
|
import java.util.HashMap;
|
|
|
|
/* JADX INFO: loaded from: classes2.dex */
|
|
public class Gradient {
|
|
private static final int DEFAULT_COLOR_MAP_SIZE = 1000;
|
|
public final int mColorMapSize;
|
|
public int[] mColors;
|
|
public float[] mStartPoints;
|
|
|
|
private class ColorInterval {
|
|
private final int color1;
|
|
private final int color2;
|
|
private final float duration;
|
|
|
|
private ColorInterval(int i, int i2, float f) {
|
|
this.color1 = i;
|
|
this.color2 = i2;
|
|
this.duration = f;
|
|
}
|
|
}
|
|
|
|
public Gradient(int[] iArr, float[] fArr) {
|
|
this(iArr, fArr, 1000);
|
|
}
|
|
|
|
public Gradient(int[] iArr, float[] fArr, int i) {
|
|
if (iArr.length != fArr.length) {
|
|
throw new IllegalArgumentException("colors and startPoints should be same length");
|
|
}
|
|
if (iArr.length == 0) {
|
|
throw new IllegalArgumentException("No colors have been defined");
|
|
}
|
|
for (int i2 = 1; i2 < fArr.length; i2++) {
|
|
if (fArr[i2] <= fArr[i2 - 1]) {
|
|
throw new IllegalArgumentException("startPoints should be in increasing order");
|
|
}
|
|
}
|
|
this.mColorMapSize = i;
|
|
int[] iArr2 = new int[iArr.length];
|
|
this.mColors = iArr2;
|
|
this.mStartPoints = new float[fArr.length];
|
|
System.arraycopy(iArr, 0, iArr2, 0, iArr.length);
|
|
System.arraycopy(fArr, 0, this.mStartPoints, 0, fArr.length);
|
|
}
|
|
|
|
private HashMap<Integer, ColorInterval> generateColorIntervals() {
|
|
HashMap<Integer, ColorInterval> map = new HashMap<>();
|
|
if (this.mStartPoints[0] != 0.0f) {
|
|
map.put(0, new ColorInterval(Color.argb(0, Color.red(this.mColors[0]), Color.green(this.mColors[0]), Color.blue(this.mColors[0])), this.mColors[0], this.mColorMapSize * this.mStartPoints[0]));
|
|
}
|
|
for (int i = 1; i < this.mColors.length; i++) {
|
|
int i2 = i - 1;
|
|
Integer numValueOf = Integer.valueOf((int) (this.mColorMapSize * this.mStartPoints[i2]));
|
|
int[] iArr = this.mColors;
|
|
int i3 = iArr[i2];
|
|
int i4 = iArr[i];
|
|
float f = this.mColorMapSize;
|
|
float[] fArr = this.mStartPoints;
|
|
map.put(numValueOf, new ColorInterval(i3, i4, (fArr[i] - fArr[i2]) * f));
|
|
}
|
|
float[] fArr2 = this.mStartPoints;
|
|
if (fArr2[fArr2.length - 1] != 1.0f) {
|
|
int length = fArr2.length - 1;
|
|
Integer numValueOf2 = Integer.valueOf((int) (this.mColorMapSize * fArr2[length]));
|
|
int i5 = this.mColors[length];
|
|
map.put(numValueOf2, new ColorInterval(i5, i5, this.mColorMapSize * (1.0f - this.mStartPoints[length])));
|
|
}
|
|
return map;
|
|
}
|
|
|
|
int[] generateColorMap(double d) {
|
|
HashMap<Integer, ColorInterval> mapGenerateColorIntervals = generateColorIntervals();
|
|
int[] iArr = new int[this.mColorMapSize];
|
|
ColorInterval colorInterval = mapGenerateColorIntervals.get(0);
|
|
int i = 0;
|
|
for (int i2 = 0; i2 < this.mColorMapSize; i2++) {
|
|
if (mapGenerateColorIntervals.containsKey(Integer.valueOf(i2))) {
|
|
colorInterval = mapGenerateColorIntervals.get(Integer.valueOf(i2));
|
|
i = i2;
|
|
}
|
|
iArr[i2] = interpolateColor(colorInterval.color1, colorInterval.color2, (i2 - i) / colorInterval.duration);
|
|
}
|
|
if (d != 1.0d) {
|
|
for (int i3 = 0; i3 < this.mColorMapSize; i3++) {
|
|
int i4 = iArr[i3];
|
|
iArr[i3] = Color.argb((int) (((double) Color.alpha(i4)) * d), Color.red(i4), Color.green(i4), Color.blue(i4));
|
|
}
|
|
}
|
|
return iArr;
|
|
}
|
|
|
|
static int interpolateColor(int i, int i2, float f) {
|
|
int iAlpha = (int) (((Color.alpha(i2) - Color.alpha(i)) * f) + Color.alpha(i));
|
|
float[] fArr = new float[3];
|
|
Color.RGBToHSV(Color.red(i), Color.green(i), Color.blue(i), fArr);
|
|
float[] fArr2 = new float[3];
|
|
Color.RGBToHSV(Color.red(i2), Color.green(i2), Color.blue(i2), fArr2);
|
|
float f2 = fArr[0];
|
|
float f3 = fArr2[0];
|
|
if (f2 - f3 > 180.0f) {
|
|
fArr2[0] = f3 + 360.0f;
|
|
} else if (f3 - f2 > 180.0f) {
|
|
fArr[0] = f2 + 360.0f;
|
|
}
|
|
float[] fArr3 = new float[3];
|
|
for (int i3 = 0; i3 < 3; i3++) {
|
|
float f4 = fArr2[i3];
|
|
float f5 = fArr[i3];
|
|
fArr3[i3] = ((f4 - f5) * f) + f5;
|
|
}
|
|
return Color.HSVToColor(iAlpha, fArr3);
|
|
}
|
|
} |