[orx-color] convert to MPP
This commit is contained in:
@@ -22,7 +22,9 @@ def multiplatformModules = [
|
|||||||
"orx-shader-phrases",
|
"orx-shader-phrases",
|
||||||
"orx-parameters",
|
"orx-parameters",
|
||||||
"orx-fx",
|
"orx-fx",
|
||||||
"orx-easing"
|
"orx-easing",
|
||||||
|
"orx-color"
|
||||||
|
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
|
||||||
}
|
|
||||||
96
orx-color/build.gradle.kts
Normal file
96
orx-color/build.gradle.kts
Normal 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"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,10 +2,7 @@ package org.openrndr.extras.color.spaces
|
|||||||
|
|
||||||
import org.openrndr.color.*
|
import org.openrndr.color.*
|
||||||
import org.openrndr.math.mixAngle
|
import org.openrndr.math.mixAngle
|
||||||
import java.util.*
|
import kotlin.math.*
|
||||||
import kotlin.math.min
|
|
||||||
import kotlin.math.pow
|
|
||||||
import kotlin.math.sqrt
|
|
||||||
|
|
||||||
private val m = arrayOf(
|
private val m = arrayOf(
|
||||||
doubleArrayOf(3.240969941904521, -1.537383177570093, -0.498610760293),
|
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 {
|
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)
|
return Length(length)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +62,7 @@ private fun maxSafeChromaForL(L100: Double): Double {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun maxChromaForLH(L100: Double, H: 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)
|
val bounds = getBounds(L100)
|
||||||
var min = Double.MAX_VALUE
|
var min = Double.MAX_VALUE
|
||||||
for (bound in bounds!!) {
|
for (bound in bounds!!) {
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
package org.openrndr.extras.color.spaces
|
package org.openrndr.extras.color.spaces
|
||||||
|
|
||||||
import org.openrndr.color.*
|
import org.openrndr.color.*
|
||||||
|
import org.openrndr.math.asDegrees
|
||||||
|
import org.openrndr.math.asRadians
|
||||||
import org.openrndr.math.mixAngle
|
import org.openrndr.math.mixAngle
|
||||||
import kotlin.math.atan2
|
import kotlin.math.*
|
||||||
import kotlin.math.cos
|
|
||||||
import kotlin.math.sin
|
|
||||||
import kotlin.math.sqrt
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Color in cylindrical OKLab space
|
* 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)
|
var h = atan2(oklaba.b, oklaba.a)
|
||||||
|
|
||||||
if (h < 0) {
|
if (h < 0) {
|
||||||
h += Math.PI * 2
|
h += PI * 2
|
||||||
}
|
}
|
||||||
h = Math.toDegrees(h)
|
h = h.asDegrees
|
||||||
return ColorOKLCHa(l, c, h, oklaba.alpha)
|
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)
|
override fun mix(other: ColorOKLCHa, factor: Double) = mix(this, other, factor)
|
||||||
|
|
||||||
fun toOKLABa(): ColorOKLABa {
|
fun toOKLABa(): ColorOKLABa {
|
||||||
val a = c * cos(Math.toRadians(h))
|
val a = c * cos(h.asRadians)
|
||||||
val b = c * sin(Math.toRadians(h))
|
val b = c * sin(h.asRadians)
|
||||||
return ColorOKLABa(l, a, b, alpha = this.a)
|
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,
|
fun calculateHistogramRGB(buffer: ColorBuffer,
|
||||||
binCount: Int = 16,
|
binCount: Int = 16,
|
||||||
weighting: ColorRGBa.() -> Double = { 1.0 },
|
weighting: ColorRGBa.() -> Double = { 1.0 },
|
||||||
@@ -84,4 +71,3 @@ class RGBHistogram(val freqs: Array<Array<DoubleArray>>, val binCount: Int) {
|
|||||||
return result.sortedByDescending { it.second }
|
return result.sortedByDescending { it.second }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user