+# illuminant C
+WHITEx = 0.3101
+WHITEy = 0.3162
+
munsell-data.el: all.dat
awk 'NR != 1 {printf("(\"%s%s/%s\" . \"CIExyY:%s/%s/%s\")\n", $$1, $$2, $$3, $$4, $$5, $$6 / 100)}' all.dat > _generated
+ awk 'NR != 1 {printf("(\"N%s\" . \"CIExyY:%s/%s/%s\")\n", $$2, $(WHITEx), $(WHITEy), $$6 / 100)}' all.dat|uniq >> _generated
m4 munsell-data.template > munsell-data.el
all.dat:
(value-var (nth 1 vars))
(chroma-var (nth 2 vars)))
`(let ((,color-var ,color-expr))
- (if (string-match "^\\(N\\|\\([0-9]+\\(\\.[0-9]*\\)?\\)\\(B\\|BG\\|G\\|GY\\|Y\\|YR\\|R\\|RP\\|P\\|PB\\)\\)\\([0-9]+\\(\\.[0-9]*\\)?\\)/\\([0-9]+\\(\\.[0-9]*\\)?\\)$" ,color-var)
+ (if (string-match "^N\\([0-9]+\\(\\.[0-9]*\\)?\\)\\|\\([0-9]+\\(\\.[0-9]*\\)?\\)\\(B\\|BG\\|G\\|GY\\|Y\\|YR\\|R\\|RP\\|P\\|PB\\)\\([0-9]+\\(\\.[0-9]*\\)?\\)/\\([0-9]+\\(\\.[0-9]*\\)?\\)$" ,color-var)
(let ((,hue-var
- (if (match-beginning 2)
- (cons (string-to-number (match-string 2 ,color-var))
- (match-string 4 ,color-var))
- (cons 0 (match-string 1 ,color-var))))
- (,value-var (string-to-number (match-string 5 ,color-var)))
- (,chroma-var (string-to-number (match-string 7 ,color-var))))
+ (if (match-beginning 1)
+ '(0 . "N")
+ (cons (string-to-number (match-string 3 ,color-var))
+ (match-string 5 ,color-var))))
+ (,value-var
+ (string-to-number
+ (match-string (if (match-beginning 1) 1 6) ,color-var)))
+ (,chroma-var
+ (if (match-beginning 1)
+ 0
+ (string-to-number (match-string 8 ,color-var)))))
,body)
,(or
invalid-action
`(error "invalid munsell color: %s" ,color-var))))))
(defun munsell-round (h v c hue-round value-round chroma-round)
- (concat
- (let ((h2 (* 5 (apply hue-round (car h) '(2.5)))))
- (if (= (logand h2 1) 0)
- (int-to-string (ash h2 -1))
- (concat (int-to-string (ash h2 -1)) ".5")))
- (cdr h)
- (if (< v 0.9)
- (concat "0." (int-to-string (* 2 (apply value-round v '(0.2)))))
- (int-to-string (apply value-round v '(1))))
- "/"
- (int-to-string (* 2 (apply chroma-round c '(2))))))
+ (let ((c-rounded (* 2 (apply chroma-round c '(2)))))
+ (concat
+ (if (= c-rounded 0)
+ "N"
+ (let ((h2 (* 5 (apply hue-round (car h) '(2.5)))))
+ (concat
+ (int-to-string (ash h2 -1))
+ (unless (= (logand h2 1) 0) ".5")
+ (cdr h))))
+ (if (< v 0.9)
+ (concat "0." (int-to-string (* 2 (apply value-round v '(0.2)))))
+ (int-to-string (apply value-round v '(1))))
+ (if (= c-rounded 0)
+ ""
+ (concat "/" (int-to-string c-rounded))))))
(defun munsell-convert (color)
(munsell-split color (h v c)
("10PB3.5/10" "\e$B5K9<\e(B" "\e$B$-$-$g$&\e(B")
("7.5P5.0/8.0" "\e$BF#\e(B" "\e$B$U$8\e(B")
("5.0RP4.5/14" "\e$B24C0\e(B" "\e$B$\$?$s\e(B")
-;; ("N1.5/0" "\e$BKO\e(B" "\e$B$9$_\e(B")
-;; ("5.0YR3.0/0.5" "\e$BKOFK\e(B" "\e$B$/$m$D$k$P$_\e(B")
-;; ("2.5YR3.0/0.5" "\e$Bb%\e(B" "\e$B$/$j\e(B")
-;; ("7.5R4.0/0.5" "\e$BF_\e(B" "\e$B$K$S\e(B")
-;; ("5.0B4.0/0.5" "\e$B@DF_\e(B" "\e$B$"$*$K$S\e(B")
-;; ("5.0G4.5/0.5" "\e$BMx5WAM\e(B" "\e$B$j$-$e$&$M$:$_\e(B")
-;; ("5.0GY5.0/0.5" "\e$B3%\e(B" "\e$B$O$$\e(B")
+ ("N1.5" "\e$BKO\e(B" "\e$B$9$_\e(B")
+ ("5.0YR3.0/0.5" "\e$BKOFK\e(B" "\e$B$/$m$D$k$P$_\e(B")
+ ("2.5YR3.0/0.5" "\e$Bb%\e(B" "\e$B$/$j\e(B")
+ ("7.5R4.0/0.5" "\e$BF_\e(B" "\e$B$K$S\e(B")
+ ("5.0B4.0/0.5" "\e$B@DF_\e(B" "\e$B$"$*$K$S\e(B")
+ ("5.0G4.5/0.5" "\e$BMx5WAM\e(B" "\e$B$j$-$e$&$M$:$_\e(B")
+ ("5.0GY5.0/0.5" "\e$B3%\e(B" "\e$B$O$$\e(B")
)
"Munsell color names")