diff --git a/build.gradle.kts b/build.gradle.kts index 6923dc9..897bc97 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ repositories { } dependencies { - implementation("com.github.ajalt.colormath:colormath:3.6.0") + api("com.github.ajalt.colormath:colormath:3.6.0") } tasks.test { diff --git a/src/main/kotlin/me/aroze/colornames/ColorNames.kt b/src/main/kotlin/me/aroze/colornames/ColorNames.kt index d091507..7f0dc5c 100644 --- a/src/main/kotlin/me/aroze/colornames/ColorNames.kt +++ b/src/main/kotlin/me/aroze/colornames/ColorNames.kt @@ -17,6 +17,28 @@ class ColorNames( kdTree = buildKDTree(colorNames.map { Triple(it.lightness, it.aComponent, it.bComponent) to it }.toList(), 0) } + /** + * Get the name of the closest color to the given hex color + */ + fun getName(hex: String): String { + return findClosestColor(hex).name + } + + /** + * Get the name of the closest color to the given RGB color + */ + fun getName(r: Int, g: Int, b: Int): String { + return findClosestColor(r, g, b).name + } + + /** + * Get the name of the closest color to the given [LAB] color + */ + fun getName(lab: LAB): String { + return findClosestColor(lab).name + } + + /** * Find the closest color to the given hex color *