From ee8a80a0b18dfccaf44566e46ac51af70c5c0e62 Mon Sep 17 00:00:00 2001 From: AJ Date: Thu, 25 Jan 2024 11:21:43 -0800 Subject: [PATCH 1/3] Add wasm target --- .github/workflows/publish.yml | 19 ++++---- .github/workflows/test.yml | 21 +++++---- README.md | 8 ++-- colormath/build.gradle.kts | 4 +- .../ajalt/colormath/internal/MatrixTest.kt | 7 ++- gradle/libs.versions.toml | 6 +-- settings.gradle.kts | 1 + test/build.gradle.kts | 46 +++++++++++++++++++ test/gradle.properties | 2 + .../github/ajalt/colormath/CssParseTest.kt | 0 .../github/ajalt/colormath/CssRenderTest.kt | 0 .../github/ajalt/colormath/HueColorTest.kt | 0 .../com/github/ajalt/colormath/TestUtils.kt | 0 .../ajalt/colormath/calculate/ContrastTest.kt | 0 .../colormath/calculate/DifferenceTest.kt | 0 .../ajalt/colormath/calculate/GamutTest.kt | 0 .../ajalt/colormath/model/Ansi16Test.kt | 0 .../ajalt/colormath/model/Ansi256Test.kt | 0 .../github/ajalt/colormath/model/CMYKTest.kt | 0 .../github/ajalt/colormath/model/HPLuvTest.kt | 0 .../github/ajalt/colormath/model/HSLTest.kt | 0 .../github/ajalt/colormath/model/HSLuvTest.kt | 0 .../github/ajalt/colormath/model/HSVTest.kt | 0 .../github/ajalt/colormath/model/HWBTest.kt | 0 .../github/ajalt/colormath/model/ICtCpTest.kt | 0 .../ajalt/colormath/model/JzAzBzTest.kt | 0 .../ajalt/colormath/model/JzCzHzTest.kt | 0 .../github/ajalt/colormath/model/LABTest.kt | 0 .../github/ajalt/colormath/model/LCHabTest.kt | 0 .../github/ajalt/colormath/model/LCHuvTest.kt | 0 .../github/ajalt/colormath/model/LUVTest.kt | 0 .../github/ajalt/colormath/model/OklabTest.kt | 0 .../github/ajalt/colormath/model/OklchTest.kt | 0 .../model/RGBColorSpacesConversionTest.kt | 0 .../RGBColorSpacesTransferFunctionsTest.kt | 0 .../ajalt/colormath/model/RGBIntTest.kt | 0 .../github/ajalt/colormath/model/RGBTest.kt | 0 .../github/ajalt/colormath/model/XYZTest.kt | 13 +++--- .../transform/EasingFunctionsTest.kt | 0 .../colormath/transform/HueAdjustmentsTest.kt | 0 .../colormath/transform/InterpolateTest.kt | 0 .../colormath/transform/TransformTest.kt | 0 42 files changed, 96 insertions(+), 31 deletions(-) create mode 100644 test/build.gradle.kts create mode 100644 test/gradle.properties rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/CssParseTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/CssRenderTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/HueColorTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/TestUtils.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/calculate/ContrastTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/calculate/DifferenceTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/calculate/GamutTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/Ansi16Test.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/Ansi256Test.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/CMYKTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/HPLuvTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/HSLTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/HSLuvTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/HSVTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/HWBTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/ICtCpTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/JzAzBzTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/JzCzHzTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/LABTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/LCHabTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/LCHuvTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/LUVTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/OklabTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/OklchTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBColorSpacesConversionTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBColorSpacesTransferFunctionsTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBIntTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/model/XYZTest.kt (86%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/transform/EasingFunctionsTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/transform/HueAdjustmentsTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/transform/InterpolateTest.kt (100%) rename {colormath => test}/src/commonTest/kotlin/com/github/ajalt/colormath/transform/TransformTest.kt (100%) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c6f5649b..d8d8c3fe 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,16 +16,17 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 20 + java-version: 21 - uses: gradle/gradle-build-action@v2 with: arguments: | - :colormath:jsNodeTest - :colormath:jvmTest - :colormath:linuxX64Test + :test:jsNodeTest + :test:jvmTest + :test:linuxX64Test :colormath:compileKotlinLinuxArm64 - :extensions:colormath-ext-jetpack-compose:check - :extensions:colormath-ext-android-colorint:check + :colormath:wasmJsTest + :extensions:colormath-ext-jetpack-compose:check + :extensions:colormath-ext-android-colorint:check :extensions:colormath-ext-android-color:check --stacktrace - name: Bundle the build report @@ -44,7 +45,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 20 + java-version: 21 - uses: gradle/gradle-build-action@v2 with: arguments: | @@ -63,7 +64,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 20 + java-version: 21 - uses: gradle/gradle-build-action@v2 with: arguments: mingwX64Test --stacktrace @@ -76,7 +77,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 20 + java-version: 21 - name: Fetch git tags run: git fetch origin +refs/tags/*:refs/tags/* - name: Deploy to sonatype diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c6f5e218..98f05b49 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,17 +14,19 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 20 + java-version: 21 - uses: gradle/gradle-build-action@v2 with: arguments: | - :colormath:jsNodeTest - :colormath:jvmTest - :colormath:linuxX64Test + :test:jsNodeTest + :test:jvmTest + :test:linuxX64Test :colormath:compileKotlinLinuxArm64 + :colormath:wasmJsTest :extensions:colormath-ext-jetpack-compose:check :extensions:colormath-ext-android-colorint:check - :extensions:colormath-ext-android-color:check --stacktrace + :extensions:colormath-ext-android-color:check + --stacktrace - name: Bundle the build report if: failure() run: find . -type d -name 'reports' | zip -@ -r build-reports.zip @@ -41,14 +43,17 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 20 + java-version: 21 - uses: gradle/gradle-build-action@v2 with: arguments: | macosX64Test :colormath:compileKotlinMacosArm64 - tvosX64Test iosX64Test + tvosX64Test + iosSimulatorArm64Test + tvosSimulatorArm64Test + watchosSimulatorArm64Test --stacktrace windows-tests: runs-on: windows-latest @@ -57,7 +62,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 20 + java-version: 21 - uses: gradle/gradle-build-action@v2 with: arguments: mingwX64Test --stacktrace diff --git a/README.md b/README.md index 1c7fb63f..6412d875 100644 --- a/README.md +++ b/README.md @@ -69,9 +69,11 @@ dependencies { #### Multiplatform -Colormath supports the following targets: `jvm`, `mingwX64`, `linuxX64`, `macosX64`, `ios`, -`watchos`, `tvos`, and `js` (for both NodeJS and Browsers). You'll need to use Gradle 6 or newer. -Artifacts for `macosArm64` and `linuxArm64` are also published, but not tested with CI. +Colormath publishes artifacts for all +[Tier 1 and Tier 2](https://kotlinlang.org/docs/native-target-support.html) +targets, as well as `mingwX64` and `wasm`. + +`wasm` and the `arm64` targets are not tested on CI. #### Snapshots diff --git a/colormath/build.gradle.kts b/colormath/build.gradle.kts index 0aa531f8..8d3f2060 100644 --- a/colormath/build.gradle.kts +++ b/colormath/build.gradle.kts @@ -13,6 +13,9 @@ kotlin { jvm() js { nodejs() } + @OptIn(ExperimentalWasmDsl::class) + wasmJs { nodejs() } + linuxX64() linuxArm64() mingwX64() @@ -32,7 +35,6 @@ kotlin { val commonTest by getting { dependencies { implementation(kotlin("test")) - implementation(libs.kotest) } } } diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/internal/MatrixTest.kt b/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/internal/MatrixTest.kt index ee937eba..d48aa20d 100644 --- a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/internal/MatrixTest.kt +++ b/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/internal/MatrixTest.kt @@ -1,8 +1,8 @@ package com.github.ajalt.colormath.internal -import io.kotest.matchers.shouldBe import kotlin.js.JsName import kotlin.test.Test +import kotlin.test.assertEquals class MatrixTest { @Test @@ -56,3 +56,8 @@ class MatrixTest { l.dot(10f, 20f, 30f).values shouldBe floatArrayOf(140f, 320f, 500f) } } + +// TODO(kotest): go back to kotest once is supports wasm +private infix fun Any?.shouldBe(other: Any?) { + assertEquals(other, this) +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 35054c40..51c236a6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,10 +1,10 @@ [versions] -kotlin = "1.9.20" -jbCompose = "1.5.10" +kotlin = "1.9.21" +jbCompose = "1.5.11" [libraries] # used in tests -kotest = "io.kotest:kotest-assertions-core:5.7.2" +kotest = "io.kotest:kotest-assertions-core:5.8.0" compose-ui-graphics = { module = "org.jetbrains.compose.ui:ui-graphics", version.ref = "jbCompose" } androidx-annotation = "androidx.annotation:annotation:1.7.0" junit = "junit:junit:4.13.2" diff --git a/settings.gradle.kts b/settings.gradle.kts index 75d793fe..b754b284 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,4 +1,5 @@ include("colormath") +include("test") include("extensions:colormath-ext-android-color") include("extensions:colormath-ext-android-colorint") include("extensions:colormath-ext-jetpack-compose") diff --git a/test/build.gradle.kts b/test/build.gradle.kts new file mode 100644 index 00000000..f34d94ed --- /dev/null +++ b/test/build.gradle.kts @@ -0,0 +1,46 @@ +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl + +plugins { + kotlin("multiplatform") + alias(libs.plugins.publish) +} + +repositories { + mavenCentral() +} + +kotlin { + jvm() + js { nodejs() } + + linuxX64() + linuxArm64() + mingwX64() + macosX64() + macosArm64() + iosX64() + iosArm64() + iosSimulatorArm64() + tvosX64() + tvosArm64() + tvosSimulatorArm64() + watchosX64() + watchosArm64() + watchosSimulatorArm64() + + sourceSets { + val commonTest by getting { + dependencies { + api(project(":colormath")) + implementation(libs.kotest) + implementation(kotlin("test")) + } + } + } +} + +tasks.withType().configureEach { + manifest { + attributes("Automatic-Module-Name" to "com.github.ajalt.colormath") + } +} diff --git a/test/gradle.properties b/test/gradle.properties new file mode 100644 index 00000000..d7a11582 --- /dev/null +++ b/test/gradle.properties @@ -0,0 +1,2 @@ +POM_ARTIFACT_ID=colormath +POM_NAME=Colormath diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/CssParseTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/CssParseTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/CssParseTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/CssParseTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/CssRenderTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/CssRenderTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/CssRenderTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/CssRenderTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/HueColorTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/HueColorTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/HueColorTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/HueColorTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/TestUtils.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/TestUtils.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/TestUtils.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/TestUtils.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/calculate/ContrastTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/calculate/ContrastTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/calculate/ContrastTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/calculate/ContrastTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/calculate/DifferenceTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/calculate/DifferenceTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/calculate/DifferenceTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/calculate/DifferenceTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/calculate/GamutTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/calculate/GamutTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/calculate/GamutTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/calculate/GamutTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/Ansi16Test.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/Ansi16Test.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/Ansi16Test.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/Ansi16Test.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/Ansi256Test.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/Ansi256Test.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/Ansi256Test.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/Ansi256Test.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/CMYKTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/CMYKTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/CMYKTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/CMYKTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/HPLuvTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/HPLuvTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/HPLuvTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/HPLuvTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/HSLTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/HSLTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/HSLTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/HSLTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/HSLuvTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/HSLuvTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/HSLuvTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/HSLuvTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/HSVTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/HSVTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/HSVTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/HSVTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/HWBTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/HWBTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/HWBTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/HWBTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/ICtCpTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/ICtCpTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/ICtCpTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/ICtCpTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/JzAzBzTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/JzAzBzTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/JzAzBzTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/JzAzBzTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/JzCzHzTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/JzCzHzTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/JzCzHzTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/JzCzHzTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/LABTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/LABTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/LABTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/LABTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/LCHabTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/LCHabTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/LCHabTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/LCHabTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/LCHuvTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/LCHuvTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/LCHuvTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/LCHuvTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/LUVTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/LUVTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/LUVTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/LUVTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/OklabTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/OklabTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/OklabTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/OklabTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/OklchTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/OklchTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/OklchTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/OklchTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBColorSpacesConversionTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBColorSpacesConversionTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBColorSpacesConversionTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBColorSpacesConversionTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBColorSpacesTransferFunctionsTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBColorSpacesTransferFunctionsTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBColorSpacesTransferFunctionsTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBColorSpacesTransferFunctionsTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBIntTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBIntTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBIntTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBIntTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/RGBTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/XYZTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/XYZTest.kt similarity index 86% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/XYZTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/model/XYZTest.kt index 590b9fa9..96ec9475 100644 --- a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/model/XYZTest.kt +++ b/test/src/commonTest/kotlin/com/github/ajalt/colormath/model/XYZTest.kt @@ -1,7 +1,5 @@ package com.github.ajalt.colormath.model -import com.github.ajalt.colormath.internal.CAT02_LMS_TO_XYZ -import com.github.ajalt.colormath.internal.CAT02_XYZ_TO_LMS import com.github.ajalt.colormath.model.LABColorSpaces.LAB50 import com.github.ajalt.colormath.model.LUVColorSpaces.LUV50 import com.github.ajalt.colormath.model.XYZColorSpaces.XYZ50 @@ -51,10 +49,13 @@ class XYZTest { XYZ(0.40, 0.50, 0.60) to Oklab(0.78539542, -0.06758384, -0.01449969), XYZ(1.00, 1.00, 1.00) to Oklab(1.00324405, 0.02673522, 0.0147436), XYZ(0.18, 0.18, 0.18).adaptTo(XYZ50) to Oklab(0.56645328, 0.01509528, 0.00832456), - XYZ(0.18, 0.18, 0.18).adaptTo(XYZ50, CAT02_XYZ_TO_LMS.rowMajor) to Oklab(0.56645328, 0.01509528, 0.00832456), - XYZ(0.18, 0.18, 0.18).adaptTo(XYZ50, CAT02_XYZ_TO_LMS.rowMajor, CAT02_LMS_TO_XYZ.rowMajor) to Oklab(0.56645328, - 0.01509528, - 0.00832456), + // TODO(kotest): reenable this when kotest supports wasm + // XYZ(0.18, 0.18, 0.18).adaptTo(XYZ50, CAT02_XYZ_TO_LMS) to Oklab( +// 0.56645328, 0.01509528, 0.00832456 +// ), +// XYZ(0.18, 0.18, 0.18).adaptTo(XYZ50, CAT02_XYZ_TO_LMS, CAT02_LMS_TO_XYZ.rowMajor) to Oklab( +// 0.56645328, 0.01509528, 0.00832456 +// ), ) @Test diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/transform/EasingFunctionsTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/transform/EasingFunctionsTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/transform/EasingFunctionsTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/transform/EasingFunctionsTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/transform/HueAdjustmentsTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/transform/HueAdjustmentsTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/transform/HueAdjustmentsTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/transform/HueAdjustmentsTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/transform/InterpolateTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/transform/InterpolateTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/transform/InterpolateTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/transform/InterpolateTest.kt diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/transform/TransformTest.kt b/test/src/commonTest/kotlin/com/github/ajalt/colormath/transform/TransformTest.kt similarity index 100% rename from colormath/src/commonTest/kotlin/com/github/ajalt/colormath/transform/TransformTest.kt rename to test/src/commonTest/kotlin/com/github/ajalt/colormath/transform/TransformTest.kt From 52e6044041d5893b6bc7798b5c8bdfe1a9e83637 Mon Sep 17 00:00:00 2001 From: AJ Date: Thu, 25 Jan 2024 12:44:36 -0800 Subject: [PATCH 2/3] Disable wasm tests since they fail --- .github/workflows/publish.yml | 2 +- .github/workflows/test.yml | 2 +- .../com/github/ajalt/colormath/internal/MatrixTest.kt | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d8d8c3fe..f94f6244 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -24,7 +24,7 @@ jobs: :test:jvmTest :test:linuxX64Test :colormath:compileKotlinLinuxArm64 - :colormath:wasmJsTest + :colormath:compileKotlinWasmJs :extensions:colormath-ext-jetpack-compose:check :extensions:colormath-ext-android-colorint:check :extensions:colormath-ext-android-color:check diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 98f05b49..07261bcc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ jobs: :test:jvmTest :test:linuxX64Test :colormath:compileKotlinLinuxArm64 - :colormath:wasmJsTest + :colormath:compileKotlinWasmJs :extensions:colormath-ext-jetpack-compose:check :extensions:colormath-ext-android-colorint:check :extensions:colormath-ext-android-color:check diff --git a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/internal/MatrixTest.kt b/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/internal/MatrixTest.kt index d48aa20d..ac42d792 100644 --- a/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/internal/MatrixTest.kt +++ b/colormath/src/commonTest/kotlin/com/github/ajalt/colormath/internal/MatrixTest.kt @@ -58,6 +58,8 @@ class MatrixTest { } // TODO(kotest): go back to kotest once is supports wasm -private infix fun Any?.shouldBe(other: Any?) { - assertEquals(other, this) +private infix fun FloatArray.shouldBe(other: FloatArray) { + for (i in indices) { + assertEquals(this[i], other[i], 0.00000001f, "index $i") + } } From 1d575d74879594efbc39527dbfe5ef9fc140d748 Mon Sep 17 00:00:00 2001 From: AJ Date: Thu, 25 Jan 2024 12:45:27 -0800 Subject: [PATCH 3/3] Remove deprecated annotation --- .../com/github/ajalt/colormath/internal/Constants.kt | 4 ---- .../kotlin/com/github/ajalt/colormath/model/ICtCp.kt | 9 --------- .../github/ajalt/colormath/model/RGBColorSpaces.kt | 11 ----------- .../ajalt/colormath/transform/ChromaticAdapter.kt | 3 --- .../github/ajalt/colormath/transform/Interpolate.kt | 2 -- 5 files changed, 29 deletions(-) diff --git a/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/internal/Constants.kt b/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/internal/Constants.kt index 9d259e6b..17a25c8b 100644 --- a/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/internal/Constants.kt +++ b/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/internal/Constants.kt @@ -1,7 +1,5 @@ package com.github.ajalt.colormath.internal -import kotlin.native.concurrent.SharedImmutable - // Constants used in LAB and LUV conversions. // http://www.brucelindbloom.com/index.html?LContinuity.html /** ϵ = (6/29)^3 */ @@ -15,12 +13,10 @@ internal const val CIE_E_times_K = 8.0 /** The CIECAM02 transform matrix for XYZ -> LMS */ // https://en.wikipedia.org/wiki/CIECAM02#CAT02 -@SharedImmutable internal val CAT02_XYZ_TO_LMS = Matrix( +0.7328f, +0.4296f, -0.1624f, -0.7036f, +1.6975f, +0.0061f, +0.0030f, +0.0136f, +0.9834f, ) -@SharedImmutable internal val CAT02_LMS_TO_XYZ = CAT02_XYZ_TO_LMS.inverse() diff --git a/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/model/ICtCp.kt b/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/model/ICtCp.kt index 7a13aa56..3428c0db 100644 --- a/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/model/ICtCp.kt +++ b/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/model/ICtCp.kt @@ -6,7 +6,6 @@ import com.github.ajalt.colormath.ColorSpace import com.github.ajalt.colormath.internal.* import com.github.ajalt.colormath.model.RGBColorSpaces.BT2020 import com.github.ajalt.colormath.model.XYZColorSpaces.XYZ65 -import kotlin.native.concurrent.SharedImmutable /** * The ICtCp color space, designed for high dynamic range and wide color gamut imagery. @@ -99,45 +98,37 @@ private object PqNonlinearity : RGBColorSpace.TransferFunctions { } } -@SharedImmutable private val ICTCP_RGB_TO_LMS = Matrix( 1688f, 2146f, 262f, 683f, 2951f, 462f, 99f, 309f, 3688f, ).scalarDiv(4096f, inPlace = true) -@SharedImmutable private val ICTCP_LMS_TO_ICTCP = Matrix( 2048f, 2048f, 0f, 6610f, -13613f, 7003f, 17933f, -17390f, -543f, ).scalarDiv(4096f, inPlace = true) -@SharedImmutable private val ICTCP_LMS_to_RGB = ICTCP_RGB_TO_LMS.inverse() -@SharedImmutable private val ICTCP_ICTCP_to_LMS = ICTCP_LMS_TO_ICTCP.inverse() // ICtCp defines the XYZ to LMS matrix by multiplying a crosstalk matrix with the old // Hunt-Pointer-Estevez transform. It's not clear why they use HPE rather than one of the newer // transforms. -@SharedImmutable private val ICTCP_CROSSTALK = Matrix( 0.92f, 0.04f, 0.04f, 0.04f, 0.92f, 0.04f, 0.04f, 0.04f, 0.92f, ) -@SharedImmutable private val HPE_XYZ_TO_LMS = Matrix( 0.4002f, 0.7076f, -0.0808f, -0.2263f, 1.1653f, 0.0457f, 0f, 0f, 0.9182f, ) -@SharedImmutable private val ICTCP_XYZ_TO_LMS = ICTCP_CROSSTALK.dot(HPE_XYZ_TO_LMS) -@SharedImmutable private val ICTCP_LMS_TO_XYZ = ICTCP_XYZ_TO_LMS.inverse() diff --git a/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/model/RGBColorSpaces.kt b/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/model/RGBColorSpaces.kt index f30db204..47d5bca1 100644 --- a/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/model/RGBColorSpaces.kt +++ b/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/model/RGBColorSpaces.kt @@ -7,7 +7,6 @@ import com.github.ajalt.colormath.WhitePoint import com.github.ajalt.colormath.internal.* import kotlin.math.log2 import kotlin.math.pow -import kotlin.native.concurrent.SharedImmutable object RGBColorSpaces { /** @@ -264,13 +263,10 @@ private data class RGBColorSpaceImpl( override operator fun invoke(r: Float, g: Float, b: Float, alpha: Float): RGB = RGB(r, g, b, alpha, this) } -@SharedImmutable private val SRGB_R = xyY(0.6400, 0.3300) -@SharedImmutable private val SRGB_G = xyY(0.3000, 0.6000) -@SharedImmutable private val SRGB_B = xyY(0.1500, 0.0600) private object SRGBTransferFunctions : RGBColorSpace.TransferFunctions { @@ -289,27 +285,20 @@ private object SRGBTransferFunctions : RGBColorSpace.TransferFunctions { } } -@SharedImmutable private val ACES_WHITE_POINT = WhitePoint("ACES", xyY(0.32168, 0.33767)) // values from [Academy TB-2014-004] -@SharedImmutable private val ACES_AP0_R = xyY(0.73470, 0.26530) -@SharedImmutable private val ACES_AP0_G = xyY(0.00000, 1.00000) -@SharedImmutable private val ACES_AP0_B = xyY(0.00010, -0.0770) // values from [Academy S-2014-004] -@SharedImmutable private val ACES_AP1_R = xyY(0.713, 0.293) -@SharedImmutable private val ACES_AP1_G = xyY(0.165, 0.830) -@SharedImmutable private val ACES_AP1_B = xyY(0.128, 0.044) // from [Academy S-2014-003] diff --git a/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/transform/ChromaticAdapter.kt b/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/transform/ChromaticAdapter.kt index 41d3d32a..31e67e9f 100644 --- a/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/transform/ChromaticAdapter.kt +++ b/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/transform/ChromaticAdapter.kt @@ -7,7 +7,6 @@ import com.github.ajalt.colormath.internal.dot import com.github.ajalt.colormath.model.* import com.github.ajalt.colormath.model.RGBColorSpaces.SRGB import com.github.ajalt.colormath.model.XYZColorSpaces.XYZ65 -import kotlin.native.concurrent.SharedImmutable /** * Create a chromatic adapter that will adapt colors from a given [sourceWhite] to this color space's @@ -69,8 +68,6 @@ private inline fun doAdapt(transform: Matrix, r: Float, g: Float, b: Float, } } -@SharedImmutable private val xyzToSrgb = Matrix(SRGB.matrixFromXyz) -@SharedImmutable private val srgbToXYZ = Matrix(SRGB.matrixToXyz) diff --git a/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/transform/Interpolate.kt b/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/transform/Interpolate.kt index 4779a08a..8f66db0b 100644 --- a/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/transform/Interpolate.kt +++ b/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/transform/Interpolate.kt @@ -5,7 +5,6 @@ import com.github.ajalt.colormath.ColorComponentInfo import com.github.ajalt.colormath.ColorSpace import com.github.ajalt.colormath.internal.scaleRange import com.github.ajalt.colormath.transform.InterpolationMethod.Point -import kotlin.native.concurrent.SharedImmutable /** * Interpolate linearly between this color and [other]. @@ -373,7 +372,6 @@ private fun requireComponentName(space: ColorSpace<*>, name: String): String { return name.lowercase() } -@SharedImmutable private val alphaAdjustment: ComponentAdjustment = { l -> when { l.all { it.isNaN() } -> l