mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
AI API
Former-commit-id: 7821931c73c0d90a883b3732eb5a950c2b2a0402 Former-commit-id: b77ed6d9cc3effd183646a7e0c8411b4e125cfd2
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package net.torvald.colourutil
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.colourutil.CIELChUtil.toLCh
|
||||
import net.torvald.colourutil.CIELChUtil.toLab
|
||||
import net.torvald.colourutil.CIELabUtil.toLab
|
||||
import net.torvald.colourutil.CIELabUtil.toRGB
|
||||
import net.torvald.colourutil.CIELabUtil.toXYZ
|
||||
@@ -49,15 +51,15 @@ object CIELChUtil {
|
||||
return CIELab(L, a, b, alpha)
|
||||
}
|
||||
|
||||
fun Color.toLCh() = this.toXYZ().toLab().toLCh()
|
||||
fun CIELCh.toRGB() = this.toLab().toXYZ().toRGB()
|
||||
|
||||
private fun Float.sqr() = this * this
|
||||
private fun Float.sqrt() = Math.sqrt(this.toDouble()).toFloat()
|
||||
|
||||
private fun Float.abs() = FastMath.abs(this)
|
||||
}
|
||||
|
||||
fun Color.toLCh() = this.toXYZ().toLab().toLCh()
|
||||
fun CIELCh.toRGB() = this.toLab().toXYZ().toRGB()
|
||||
|
||||
/**
|
||||
* @param L : Luminosity in 0.0 - 1.0
|
||||
* @param C : Chroma (saturation) in 0.0 - 1.0
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package net.torvald.colourutil
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.colourutil.CIELabUtil.toLab
|
||||
import net.torvald.colourutil.CIELabUtil.toRGB
|
||||
import net.torvald.colourutil.CIELabUtil.toRawRGB
|
||||
import net.torvald.colourutil.CIELabUtil.toXYZ
|
||||
import org.newdawn.slick.Color
|
||||
|
||||
/**
|
||||
@@ -47,11 +51,6 @@ object CIELabUtil {
|
||||
return CIELab(newL, newA, newB, newAlpha).toRGB()
|
||||
}
|
||||
|
||||
fun Color.toLab() = this.toXYZ().toLab()
|
||||
fun RGB.toLab() = this.toXYZ().toLab()
|
||||
fun CIELab.toRGB() = this.toXYZ().toRGB()
|
||||
fun CIELab.toRawRGB() = this.toXYZ().toRawRGB()
|
||||
|
||||
fun RGB.toXYZ(): CIEXYZ {
|
||||
val newR = if (r > 0.04045f)
|
||||
((r + 0.055f) / 1.055f).powerOf(2.4f)
|
||||
@@ -133,6 +132,11 @@ object CIELabUtil {
|
||||
private fun Float.powerOf(exp: Float) = FastMath.pow(this, exp)
|
||||
}
|
||||
|
||||
fun Color.toLab() = this.toXYZ().toLab()
|
||||
fun RGB.toLab() = this.toXYZ().toLab()
|
||||
fun CIELab.toRGB() = this.toXYZ().toRGB()
|
||||
fun CIELab.toRawRGB() = this.toXYZ().toRawRGB()
|
||||
|
||||
internal val D65 = CIEXYZ(0.95047f, 1.00f, 1.08883f)
|
||||
val epsilon = 216f/24389f
|
||||
val kappa = 24389f/27f
|
||||
|
||||
@@ -5,6 +5,8 @@ import org.newdawn.slick.Color
|
||||
import net.torvald.colourutil.CIELabUtil.toXYZ
|
||||
import net.torvald.colourutil.CIELabUtil.toRawRGB
|
||||
import net.torvald.colourutil.CIELabUtil.toRGB
|
||||
import net.torvald.colourutil.CIELuvUtil.toLuv
|
||||
import net.torvald.colourutil.CIELuvUtil.toXYZ
|
||||
|
||||
/**
|
||||
* A modification of CIEXYZ that is useful for additive mixtures of lights.
|
||||
@@ -91,14 +93,14 @@ object CIELuvUtil {
|
||||
return CIEXYZ(X, Y, Z, alpha)
|
||||
}
|
||||
|
||||
fun Color.toLuv() = this.toXYZ().toLuv()
|
||||
fun CIELuv.toRawRGB() = this.toXYZ().toRawRGB()
|
||||
fun CIELuv.toRGB() = this.toXYZ().toRGB()
|
||||
|
||||
private fun Float.cbrt() = FastMath.pow(this, 1f / 3f)
|
||||
private fun Float.cube() = this * this * this
|
||||
}
|
||||
|
||||
fun Color.toLuv() = this.toXYZ().toLuv()
|
||||
fun CIELuv.toRawRGB() = this.toXYZ().toRawRGB()
|
||||
fun CIELuv.toRGB() = this.toXYZ().toRGB()
|
||||
|
||||
/**
|
||||
* Range:
|
||||
* L: 0-100.0
|
||||
|
||||
Reference in New Issue
Block a user