From 2d3fe4e940deb0078bef80f0f56ea38852c991e7 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 6 Jul 2021 21:35:22 -0700 Subject: . --- 505colors.mu | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to '505colors.mu') diff --git a/505colors.mu b/505colors.mu index 3d8d28f1..719c1af9 100644 --- a/505colors.mu +++ b/505colors.mu @@ -225,7 +225,7 @@ fn nearest-color-euclidean-hsl h: int, s: int, l: int -> _/eax: int { a, b, c <- color-rgb color a, b, c <- hsl a, b, c { - var curr-distance/eax: int <- euclidean-distance-squared a, b, c, h, s, l + var curr-distance/eax: int <- euclidean-hsl-squared a, b, c, h, s, l compare curr-distance, max-distance break-if->= $nearest-color-euclidean-hsl:body max-distance <- copy curr-distance @@ -238,18 +238,28 @@ fn nearest-color-euclidean-hsl h: int, s: int, l: int -> _/eax: int { return result } -fn euclidean-distance-squared x1: int, y1: int, z1: int, x2: int, y2: int, z2: int -> _/eax: int { +fn euclidean-hsl-squared h1: int, s1: int, l1: int, h2: int, s2: int, l2: int -> _/eax: int { var result/edi: int <- copy 0 - var tmp/eax: int <- copy x1 - tmp <- subtract x2 + # hue + var tmp/eax: int <- copy h1 + tmp <- subtract h2 tmp <- multiply tmp + # hue is a cylindrical space; distance can't be greater than 0x80 + { + compare tmp, 0x4000 # 0x80*0x80 + break-if-<= + tmp <- subtract 0x4000 + tmp <- negate + } result <- add tmp - tmp <- copy y1 - tmp <- subtract y2 + # saturation + tmp <- copy s1 + tmp <- subtract s2 tmp <- multiply tmp result <- add tmp - tmp <- copy z1 - tmp <- subtract z2 + # luminance + tmp <- copy l1 + tmp <- subtract l2 tmp <- multiply tmp result <- add tmp return result -- cgit 1.4.1-2-gfad0