diff options
-rw-r--r-- | 505colors.mu | 44 | ||||
-rw-r--r-- | colors.mu | 44 |
2 files changed, 44 insertions, 44 deletions
diff --git a/505colors.mu b/505colors.mu index 3185f9f7..3d8d28f1 100644 --- a/505colors.mu +++ b/505colors.mu @@ -211,6 +211,50 @@ fn test-hsl-cyan { check-ints-equal l, 0x7f, "F - test-hsl-cyan/luminance" # TODO: should round up } +fn nearest-color-euclidean-hsl h: int, s: int, l: int -> _/eax: int { + var result/edi: int <- copy 0x100/invalid + var max-distance/esi: int <- copy 0x30000/max # 3 * 0x100*0x100 + var a/ecx: int <- copy 0 + var b/edx: int <- copy 0 + var c/ebx: int <- copy 0 + var color/eax: int <- copy 0 + { + compare color, 0x100 + break-if->= + $nearest-color-euclidean-hsl:body: { + 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 + compare curr-distance, max-distance + break-if->= $nearest-color-euclidean-hsl:body + max-distance <- copy curr-distance + } + result <- copy color + } + color <- increment + loop + } + return result +} + +fn euclidean-distance-squared x1: int, y1: int, z1: int, x2: int, y2: int, z2: int -> _/eax: int { + var result/edi: int <- copy 0 + var tmp/eax: int <- copy x1 + tmp <- subtract x2 + tmp <- multiply tmp + result <- add tmp + tmp <- copy y1 + tmp <- subtract y2 + tmp <- multiply tmp + result <- add tmp + tmp <- copy z1 + tmp <- subtract z2 + tmp <- multiply tmp + result <- add tmp + return result +} + ### fn maximum a: int, b: int -> _/eax: int { diff --git a/colors.mu b/colors.mu index 43094153..90f33454 100644 --- a/colors.mu +++ b/colors.mu @@ -240,47 +240,3 @@ fn print-nearby-colors screen: (addr screen), h: int, s: int, l: int { loop } } - -fn nearest-color-euclidean-hsl h: int, s: int, l: int -> _/eax: int { - var result/edi: int <- copy 0x100/invalid - var max-distance/esi: int <- copy 0x30000/max # 3 * 0x100*0x100 - var a/ecx: int <- copy 0 - var b/edx: int <- copy 0 - var c/ebx: int <- copy 0 - var color/eax: int <- copy 0 - { - compare color, 0x100 - break-if->= - $nearest-color-euclidean-hsl:body: { - 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 - compare curr-distance, max-distance - break-if->= $nearest-color-euclidean-hsl:body - max-distance <- copy curr-distance - } - result <- copy color - } - color <- increment - loop - } - return result -} - -fn euclidean-distance-squared x1: int, y1: int, z1: int, x2: int, y2: int, z2: int -> _/eax: int { - var result/edi: int <- copy 0 - var tmp/eax: int <- copy x1 - tmp <- subtract x2 - tmp <- multiply tmp - result <- add tmp - tmp <- copy y1 - tmp <- subtract y2 - tmp <- multiply tmp - result <- add tmp - tmp <- copy z1 - tmp <- subtract z2 - tmp <- multiply tmp - result <- add tmp - return result -} |