ucs: CieLab: Save reference white for conversion to XYZ
diff --git a/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lab/CieLab.kt b/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lab/CieLab.kt
index b8cfc8c..1322229 100644
--- a/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lab/CieLab.kt
+++ b/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lab/CieLab.kt
@@ -20,10 +20,15 @@
*
* @see <a href="https://en.wikipedia.org/wiki/CIELAB_color_space">Wikipedia</a>
*/
-public data class CieLab(
+public data class CieLab @JvmOverloads constructor(
override val L: Double,
override val a: Double,
override val b: Double,
+
+ /**
+ * Reference white for CIELAB calculations. This affects the converted color.
+ */
+ val referenceWhite: CieXyz = Illuminants.D65,
) : Lab {
/**
* Convert this color to the CIE XYZ color space.
@@ -31,14 +36,13 @@
* @see dev.kdrag0n.colorkt.tristimulus.CieXyz
* @return Color in XYZ
*/
- @JvmOverloads
- public fun toXyz(refWhite: CieXyz = Illuminants.D65): CieXyz {
+ public fun toXyz(): CieXyz {
val lp = (L + 16.0) / 116.0
return CieXyz(
- x = refWhite.x * fInv(lp + (a / 500.0)),
- y = refWhite.y * fInv(lp),
- z = refWhite.z * fInv(lp - (b / 200.0)),
+ x = referenceWhite.x * fInv(lp + (a / 500.0)),
+ y = referenceWhite.y * fInv(lp),
+ z = referenceWhite.z * fInv(lp - (b / 200.0)),
)
}
@@ -75,6 +79,7 @@
L = 116.0 * f(y / refWhite.y) - 16.0,
a = 500.0 * (f(x / refWhite.x) - f(y / refWhite.y)),
b = 200.0 * (f(y / refWhite.y) - f(z / refWhite.z)),
+ referenceWhite = refWhite,
)
}
}
diff --git a/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/CieLch.kt b/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/CieLch.kt
index bba3abb..c4a7f65 100644
--- a/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/CieLch.kt
+++ b/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/CieLch.kt
@@ -1,8 +1,11 @@
package dev.kdrag0n.colorkt.ucs.lch
+import dev.kdrag0n.colorkt.data.Illuminants
+import dev.kdrag0n.colorkt.tristimulus.CieXyz
import dev.kdrag0n.colorkt.ucs.lab.CieLab
import dev.kdrag0n.colorkt.util.conversion.ConversionGraph
import kotlin.jvm.JvmName
+import kotlin.jvm.JvmOverloads
import kotlin.jvm.JvmStatic
import kotlin.jvm.JvmSynthetic
@@ -11,10 +14,15 @@
*
* @see dev.kdrag0n.colorkt.ucs.lch.Lch
*/
-public data class CieLch(
+public data class CieLch @JvmOverloads constructor(
override val L: Double,
override val C: Double,
override val h: Double,
+
+ /**
+ * Reference white for CIELAB calculations. This affects the converted color.
+ */
+ val referenceWhite: CieXyz = Illuminants.D65,
) : Lch {
/**
* Convert this color to the Cartesian (Lab) representation of CIELAB.
@@ -26,6 +34,7 @@
L = L,
a = calcLabA(),
b = calcLabB(),
+ referenceWhite = referenceWhite,
)
public companion object {
@@ -47,6 +56,7 @@
L = L,
C = calcLchC(),
h = calcLchH(),
+ referenceWhite = referenceWhite,
)
}
}