[orx-color] convert to MPP

This commit is contained in:
Edwin Jakobs
2021-06-29 13:47:25 +02:00
parent 7360b64def
commit f85de6c163
12 changed files with 126 additions and 54 deletions

View File

@@ -22,7 +22,9 @@ def multiplatformModules = [
"orx-shader-phrases",
"orx-parameters",
"orx-fx",
"orx-easing"
"orx-easing",
"orx-color"
]

View File

@@ -1,21 +0,0 @@
sourceSets {
demo {
java {
srcDirs = ["src/demo/kotlin"]
compileClasspath += main.getCompileClasspath()
runtimeClasspath += main.getRuntimeClasspath()
}
}
}
dependencies {
implementation(project(":orx-shader-phrases"))
demoImplementation(project(":orx-camera"))
demoImplementation(project(":orx-mesh-generators"))
demoImplementation("org.openrndr:openrndr-application:$openrndrVersion")
demoImplementation("org.openrndr:openrndr-extensions:$openrndrVersion")
demoRuntimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion")
demoRuntimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion")
demoImplementation(sourceSets.getByName("main").output)
}

View File

@@ -0,0 +1,96 @@
import Orx_embed_shaders_gradle.EmbedShadersTask
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
id("orx.embed-shaders")
}
val kotlinxSerializationVersion: String by rootProject.extra
val kotestVersion: String by rootProject.extra
val junitJupiterVersion: String by rootProject.extra
val jvmTarget: String by rootProject.extra
val kotlinApiVersion: String by rootProject.extra
val kotlinVersion: String by rootProject.extra
val kotlinLoggingVersion: String by rootProject.extra
val kluentVersion: String by rootProject.extra
val openrndrVersion: String by rootProject.extra
val openrndrOS: String by rootProject.extra
val spekVersion: String by rootProject.extra
kotlin {
jvm {
compilations {
val demo by creating {
defaultSourceSet {
kotlin.srcDir("src/demo")
dependencies {
implementation(project(":orx-camera"))
implementation("org.openrndr:openrndr-application:$openrndrVersion")
implementation("org.openrndr:openrndr-extensions:$openrndrVersion")
runtimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion")
runtimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion")
implementation(compilations["main"]!!.output.allOutputs)
}
}
}
}
compilations.all {
kotlinOptions.jvmTarget = jvmTarget
kotlinOptions.apiVersion = kotlinApiVersion
}
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
js(IR) {
browser()
nodejs()
}
sourceSets {
@Suppress("UNUSED_VARIABLE")
val commonMain by getting {
dependencies {
implementation(project(":orx-parameters"))
implementation(project(":orx-shader-phrases"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlinxSerializationVersion")
implementation("org.openrndr:openrndr-application:$openrndrVersion")
implementation("org.openrndr:openrndr-draw:$openrndrVersion")
implementation("org.openrndr:openrndr-filter:$openrndrVersion")
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
implementation("io.github.microutils:kotlin-logging:$kotlinLoggingVersion")
}
}
@Suppress("UNUSED_VARIABLE")
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion")
implementation("io.kotest:kotest-assertions-core:$kotestVersion")
}
}
@Suppress("UNUSED_VARIABLE")
val jvmTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
implementation(kotlin("test-junit5"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion")
runtimeOnly("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion")
runtimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion")
implementation("org.spekframework.spek2:spek-dsl-jvm:$spekVersion")
implementation("org.amshove.kluent:kluent:$kluentVersion")
}
}
@Suppress("UNUSED_VARIABLE")
val jsTest by getting {
dependencies {
implementation(kotlin("test-js"))
}
}
}
}

View File

@@ -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!!) {

View File

@@ -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)
}

View 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)
}

View File

@@ -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 }
}
}
}