Add XYZ colorspace to Color class

This commit is contained in:
kappa 2023-09-26 15:45:59 +02:00
parent 70f01a69c4
commit 9edea04d9c

View file

@ -56,7 +56,7 @@ public class Color {
default -> null; default -> null;
}; };
} }
public static Color hsb(Vec3 v) { public static Color hsb(Vec3 v) {
return hsb(v.x(), v.y(), v.z()); return hsb(v.x(), v.y(), v.z());
@ -75,7 +75,7 @@ public class Color {
double cr = 4.0767245293f * cl - 3.3072168827f * cm + 0.2307590544f * cs; double cr = 4.0767245293f * cl - 3.3072168827f * cm + 0.2307590544f * cs;
double cg = -1.2681437731f * cl + 2.6093323231f * cm - 0.3411344290f * cs; double cg = -1.2681437731f * cl + 2.6093323231f * cm - 0.3411344290f * cs;
double cb = -0.0041119885f * cl - 0.7034763098f * cm + 1.7068625689f * cs; double cb = -0.0041119885f * cl - 0.7034763098f * cm + 1.7068625689f * cs;
return return
( (
cr < 0 || cr > 1 || cr < 0 || cr > 1 ||
@ -103,7 +103,15 @@ public class Color {
public static Color oklabPolar(Vec3 v) { public static Color oklabPolar(Vec3 v) {
return oklabPolar(v.x(), v.y(), v.z()); return oklabPolar(v.x(), v.y(), v.z());
} }
public static Color xyz(double x, double y, double z) {
double r = 3.2404542 * x - 1.5371385 * y - 0.4985314 * z;
double g = -0.9692660 * x + 1.8760108 * y + 0.0415560 * z;
double b = 0.0556434 * x - 0.2040259 * y + 1.0572252 * z;
return Color.rgb(r,g,b);
}
public static Color code(int code) { public static Color code(int code) {
return rgb( return rgb(