colourutil update

This commit is contained in:
minjaesong
2018-02-16 10:49:13 +09:00
parent e565a9f173
commit dde69d2e7e
6 changed files with 22 additions and 9 deletions

View File

@@ -40,7 +40,7 @@ object CIELabUtil {
return lab.toColor()
}
/** Sweet Lab linear gradient */
/** Tend to have more natural (or less saturated) colour */
fun getGradient(scale: Float, fromCol: Color, toCol: Color): Color {
val from = fromCol.toLab()
val to = toCol.toLab()
@@ -92,9 +92,9 @@ fun RGB.toLab() = this.toXYZ().toLab()
fun CIELab.toColor() = this.toXYZ().toColor()
fun CIELab.toRGB() = this.toXYZ().toRGB()
internal val D65 = CIEXYZ(0.95047f, 1f, 1.08883f)
val epsilon = 216f/24389f
val kappa = 24389f/27f
internal val D65 = CIEXYZ(0.95047f, 1f, 1.08883f) // D50 in this case will make the colour excessively blue, dunno why tho
const val epsilon = 216f/24389f
const val kappa = 24389f/27f
/**
* Range:

View File

@@ -37,6 +37,18 @@ object CIELuvUtil {
return luv.toColor()
}
/** Tend to have more vivid (or saturated) colour */
fun getGradient(scale: Float, fromCol: Color, toCol: Color): Color {
val from = fromCol.toLuv()
val to = toCol.toLuv()
val newL = FastMath.interpolateLinear(scale, from.L, to.L)
val newU = FastMath.interpolateLinear(scale, from.u, to.u)
val newV = FastMath.interpolateLinear(scale, from.v, to.v)
val newAlpha = FastMath.interpolateLinear(scale, from.alpha, to.alpha)
return CIELab(newL, newU, newV, newAlpha).toColor()
}
/**
* Alpha value will be overwritten to 1.0
*/

View File

@@ -23,7 +23,7 @@ object CIEXYZUtil {
return xyz.toColor()
}
@Deprecated("Use one in CIELAB or CIELUV; CIEXYZ is not perceptually uniform")
/*@Deprecated("Use one in CIELAB or CIELUV; CIEXYZ is not perceptually uniform")
fun getGradient(scale: Float, fromCol: Color, toCol: Color): Color {
val from = fromCol.toXYZ()
val to = toCol.toXYZ()
@@ -33,7 +33,7 @@ object CIEXYZUtil {
val newAlpha = FastMath.interpolateLinear(scale, from.alpha, to.alpha)
return CIEXYZ(newX, newY, newZ, newAlpha).toColor()
}
}*/
fun Color.toXYZ(): CIEXYZ = RGB(this).toXYZ()