Function: hfy-triplet

hfy-triplet is a byte-compiled function defined in htmlfontify.el.gz.

Signature

(hfy-triplet COLOR)

Documentation

Takes a COLOR name (string) and return a CSS rgb(R, G, B) triplet string.

Uses the definition of "white" to map the numbers to the 0-255 range, so if you've redefined white, (esp. if you've redefined it to have a triplet member lower than that of the color you are processing) strange things may happen.

Source Code

;; Defined in /usr/src/emacs/lisp/htmlfontify.el.gz
;; utility functions - cast emacs style specification values into their
;; css2 equivalents:
(defun hfy-triplet (color)
  "Takes a COLOR name (string) and return a CSS rgb(R, G, B) triplet string.
Uses the definition of \"white\" to map the numbers to the 0-255 range, so
if you've redefined white, (esp. if you've redefined it to have a triplet
member lower than that of the color you are processing) strange things
may happen."
  ;;(message "hfy-color-vals");;DBUG
  ;; TODO?  Can we do somehow do better than this?
  (cond
   ((equal color "unspecified-fg") (setq color "black"))
   ((equal color "unspecified-bg") (setq color "white")))
  (let ((white (mapcar (lambda (I) (float (1+ I))) (hfy-color-vals "white")))
        (rgb16 (mapcar (lambda (I) (float (1+ I))) (hfy-color-vals  color))))
    (if rgb16
        ;;(apply #'format "rgb(%d, %d, %d)"
        ;; Use #rrggbb instead, it is smaller
        (apply #'format "#%02x%02x%02x"
               (mapcar (lambda (X)
                         (* (/ (nth X rgb16)
                               (nth X white))
                            255))
                       '(0 1 2))))))