76 lines
1.5 KiB
Java
76 lines
1.5 KiB
Java
package io.gitlab.jfronny.ImgJava.util;
|
|
|
|
import java.awt.*;
|
|
|
|
public class MColor {
|
|
public double r;
|
|
public double g;
|
|
public double b;
|
|
public double a;
|
|
|
|
public MColor(Color c) {
|
|
this(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
|
|
}
|
|
|
|
public MColor(int r, int g, int b, int a) {
|
|
this.r = r;
|
|
this.g = g;
|
|
this.b = b;
|
|
this.a = a;
|
|
}
|
|
|
|
public MColor() {
|
|
this(0, 0, 0, 0);
|
|
}
|
|
|
|
public Color get() {
|
|
return new Color(clamp(r), clamp(g), clamp(b), clamp(a));
|
|
}
|
|
|
|
private static int clamp(double d) {
|
|
return (int)Math.round(Math.max(Math.min(d, 255), 0));
|
|
}
|
|
|
|
public MColor add(Color c) {
|
|
return this.add(new MColor(c));
|
|
}
|
|
|
|
public MColor add(MColor m) {
|
|
r += m.r;
|
|
g += m.g;
|
|
b += m.b;
|
|
a += m.a;
|
|
return this;
|
|
}
|
|
|
|
public MColor addM(Color c, double factor) {
|
|
return this.add(new MColor(c).mult(factor));
|
|
}
|
|
|
|
public MColor mult(double factor) {
|
|
r *= factor;
|
|
g *= factor;
|
|
b *= factor;
|
|
a *= factor;
|
|
return this;
|
|
}
|
|
|
|
public MColor div(double factor) {
|
|
r /= factor;
|
|
g /= factor;
|
|
b /= factor;
|
|
a /= factor;
|
|
return this;
|
|
}
|
|
|
|
//Alpha of tint is strength: 255 = equal to base, 0 = no effect
|
|
public MColor tint(Color t) {
|
|
double f = t.getAlpha() / 255d;
|
|
this.mult(1 - f);
|
|
r += t.getRed() * f;
|
|
g += t.getGreen() * f;
|
|
b += t.getBlue() * f;
|
|
return this;
|
|
}
|
|
}
|