ColorCurve.java
2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Decompiled with CFR 0_118.
*/
package com.day.image;
import java.awt.*;
public class ColorCurve {
public static final int MAX_LEVEL = 256;
private static final float[] IDENTITY_CURVE = new float[256];
private final Color color;
private final float[] curve;
public ColorCurve(ColorCurve colorCurve) {
this.color = colorCurve.color;
this.curve = colorCurve.curve == null ? null : (float[])colorCurve.curve.clone();
}
public ColorCurve(Color color) {
this.color = color;
this.curve = IDENTITY_CURVE;
}
public ColorCurve(Color color, float[] curve) {
this.color = color;
this.curve = curve == null || curve.length < 2 ? IDENTITY_CURVE : this.evenlySpacedCurve(curve);
}
public ColorCurve(Color color, float[] curve, float[] intervals) {
this.color = color;
this.curve = curve == null || curve.length < 2 ? IDENTITY_CURVE : this.intervalCurve(curve, intervals);
}
public Color getColor() {
return this.color;
}
public float getLevel(int step) {
return this.curve[step];
}
private float[] evenlySpacedCurve(float[] curve) {
float[] intervals = new float[curve.length - 1];
for (int i = 0; i < intervals.length; ++i) {
intervals[i] = 1.0f;
}
return this.intervalCurve(curve, intervals);
}
private float[] intervalCurve(float[] curve, float[] intervals) {
if (intervals == null || intervals.length != curve.length - 1) {
return this.evenlySpacedCurve(curve);
}
float factor = 0.0f;
for (int i = 0; i < intervals.length; ++i) {
factor += intervals[i];
}
float[] res = new float[256];
int resI = 0;
float level1 = curve[0];
for (int i2 = 1; i2 < curve.length; ++i2) {
float level0 = level1;
float interval = intervals[i2 - 1] * 256.0f / factor;
int end = (int)((float)resI + interval + 0.5f);
if (end > 256 || i2 == curve.length - 1) {
end = 256;
}
level1 = curve[i2];
float step = (level1 - level0) / (float)(end - resI);
while (resI < end) {
res[resI] = level0;
level0 += step;
++resI;
}
}
return res;
}
static {
for (int i = 0; i < 256; ++i) {
ColorCurve.IDENTITY_CURVE[i] = (float)i / 256.0f;
}
}
}