ucs: Oklab: Simplify LMS conversion methods
diff --git a/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lab/Oklab.kt b/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lab/Oklab.kt
index 724d65c..782a79f 100644
--- a/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lab/Oklab.kt
+++ b/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lab/Oklab.kt
@@ -30,9 +30,9 @@
* @return Color in linear sRGB
*/
public fun toLinearSrgb(): LinearSrgb {
- val l = oklabToL(this)
- val m = oklabToM(this)
- val s = oklabToS(this)
+ val l = labToL()
+ val m = labToM()
+ val s = labToS()
return LinearSrgb(
r = +4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
@@ -46,10 +46,10 @@
* @see dev.kdrag0n.colorkt.tristimulus.CieXyz
* @return Color in XYZ
*/
- public fun toCieXyz(): CieXyz {
- val l = oklabToL(this)
- val m = oklabToM(this)
- val s = oklabToS(this)
+ public fun toXyz(): CieXyz {
+ val l = labToL()
+ val m = labToM()
+ val s = labToS()
return CieXyz(
x = +1.2270138511 * l - 0.5577999807 * m + 0.2812561490 * s,
@@ -58,6 +58,11 @@
)
}
+ // Avoid arrays to minimize garbage
+ private fun labToL() = cube(L + 0.3963377774 * a + 0.2158037573 * b)
+ private fun labToM() = cube(L - 0.1055613458 * a - 0.0638541728 * b)
+ private fun labToS() = cube(L - 0.0894841775 * a - 1.2914855480 * b)
+
public companion object {
@JvmSynthetic
internal fun register() {
@@ -77,11 +82,6 @@
)
}
- // Avoid arrays to minimize garbage
- private fun oklabToL(lab: Oklab) = cube(lab.L + 0.3963377774 * lab.a + 0.2158037573 * lab.b)
- private fun oklabToM(lab: Oklab) = cube(lab.L - 0.1055613458 * lab.a - 0.0638541728 * lab.b)
- private fun oklabToS(lab: Oklab) = cube(lab.L - 0.0894841775 * lab.a - 1.2914855480 * lab.b)
-
/**
* Convert this color to the Oklab uniform color space.
*