[orx-color] convert to MPP
This commit is contained in:
@@ -2,10 +2,7 @@ package org.openrndr.extras.color.spaces
|
||||
|
||||
import org.openrndr.color.*
|
||||
import org.openrndr.math.mixAngle
|
||||
import java.util.*
|
||||
import kotlin.math.min
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.sqrt
|
||||
import kotlin.math.*
|
||||
|
||||
private val m = arrayOf(
|
||||
doubleArrayOf(3.240969941904521, -1.537383177570093, -0.498610760293),
|
||||
@@ -42,7 +39,7 @@ private fun distanceFromPole(point: DoubleArray): Double {
|
||||
}
|
||||
|
||||
private fun lengthOfRayUntilIntersect(theta: Double, line: DoubleArray): Length {
|
||||
val length = line[1] / (Math.sin(theta) - line[0] * Math.cos(theta))
|
||||
val length = line[1] / (sin(theta) - line[0] * cos(theta))
|
||||
return Length(length)
|
||||
}
|
||||
|
||||
@@ -65,7 +62,7 @@ private fun maxSafeChromaForL(L100: Double): Double {
|
||||
}
|
||||
|
||||
fun maxChromaForLH(L100: Double, H: Double): Double {
|
||||
val hrad = H / 360 * Math.PI * 2
|
||||
val hrad = H / 360 * PI * 2
|
||||
val bounds = getBounds(L100)
|
||||
var min = Double.MAX_VALUE
|
||||
for (bound in bounds!!) {
|
||||
@@ -1,11 +1,10 @@
|
||||
package org.openrndr.extras.color.spaces
|
||||
|
||||
import org.openrndr.color.*
|
||||
import org.openrndr.math.asDegrees
|
||||
import org.openrndr.math.asRadians
|
||||
import org.openrndr.math.mixAngle
|
||||
import kotlin.math.atan2
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
import kotlin.math.sqrt
|
||||
import kotlin.math.*
|
||||
|
||||
/**
|
||||
* Color in cylindrical OKLab space
|
||||
@@ -24,9 +23,9 @@ data class ColorOKLCHa(val l: Double, val c: Double, val h: Double, val a: Doubl
|
||||
var h = atan2(oklaba.b, oklaba.a)
|
||||
|
||||
if (h < 0) {
|
||||
h += Math.PI * 2
|
||||
h += PI * 2
|
||||
}
|
||||
h = Math.toDegrees(h)
|
||||
h = h.asDegrees
|
||||
return ColorOKLCHa(l, c, h, oklaba.alpha)
|
||||
}
|
||||
}
|
||||
@@ -42,8 +41,8 @@ data class ColorOKLCHa(val l: Double, val c: Double, val h: Double, val a: Doubl
|
||||
override fun mix(other: ColorOKLCHa, factor: Double) = mix(this, other, factor)
|
||||
|
||||
fun toOKLABa(): ColorOKLABa {
|
||||
val a = c * cos(Math.toRadians(h))
|
||||
val b = c * sin(Math.toRadians(h))
|
||||
val a = c * cos(h.asRadians)
|
||||
val b = c * sin(h.asRadians)
|
||||
return ColorOKLABa(l, a, b, alpha = this.a)
|
||||
}
|
||||
|
||||
13
orx-color/src/commonMain/kotlin/statistics/Histogram.kt
Normal file
13
orx-color/src/commonMain/kotlin/statistics/Histogram.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package org.openrndr.extras.color.statistics
|
||||
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.ColorBuffer
|
||||
import kotlin.random.Random
|
||||
|
||||
private fun ColorRGBa.binIndex(binCount: Int): Triple<Int, Int, Int> {
|
||||
val rb = (r * binCount).toInt().coerceIn(0, binCount - 1)
|
||||
val gb = (g * binCount).toInt().coerceIn(0, binCount - 1)
|
||||
val bb = (b * binCount).toInt().coerceIn(0, binCount - 1)
|
||||
return Triple(rb, gb, bb)
|
||||
}
|
||||
|
||||
@@ -1,16 +1,3 @@
|
||||
package org.openrndr.extras.color.statistics
|
||||
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.ColorBuffer
|
||||
import kotlin.random.Random
|
||||
|
||||
private fun ColorRGBa.binIndex(binCount: Int): Triple<Int, Int, Int> {
|
||||
val rb = (r * binCount).toInt().coerceIn(0, binCount - 1)
|
||||
val gb = (g * binCount).toInt().coerceIn(0, binCount - 1)
|
||||
val bb = (b * binCount).toInt().coerceIn(0, binCount - 1)
|
||||
return Triple(rb, gb, bb)
|
||||
}
|
||||
|
||||
fun calculateHistogramRGB(buffer: ColorBuffer,
|
||||
binCount: Int = 16,
|
||||
weighting: ColorRGBa.() -> Double = { 1.0 },
|
||||
@@ -51,7 +38,7 @@ class RGBHistogram(val freqs: Array<Array<DoubleArray>>, val binCount: Int) {
|
||||
}
|
||||
|
||||
fun color(rBin: Int, gBin: Int, bBin: Int): ColorRGBa =
|
||||
ColorRGBa(rBin / (binCount - 1.0), gBin / (binCount - 1.0), bBin / (binCount - 1.0))
|
||||
ColorRGBa(rBin / (binCount - 1.0), gBin / (binCount - 1.0), bBin / (binCount - 1.0))
|
||||
|
||||
fun sample(random: Random = Random.Default): ColorRGBa {
|
||||
val x = random.nextDouble()
|
||||
@@ -75,13 +62,12 @@ class RGBHistogram(val freqs: Array<Array<DoubleArray>>, val binCount: Int) {
|
||||
for (g in 0 until binCount) {
|
||||
for (b in 0 until binCount) {
|
||||
result += Pair(
|
||||
ColorRGBa(r / (binCount - 1.0), g / (binCount - 1.0), b / (binCount - 1.0)),
|
||||
freqs[r][g][b]
|
||||
ColorRGBa(r / (binCount - 1.0), g / (binCount - 1.0), b / (binCount - 1.0)),
|
||||
freqs[r][g][b]
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.sortedByDescending { it.second }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user