Mercurial > emacs
annotate lisp/gnus/color-lab.el @ 111702:087bcfbfa5ef
color-lab: Require 'cl when compiling.
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Wed, 24 Nov 2010 12:56:50 +0000 |
parents | 3fbe2d0ad0f8 |
children |
rev | line source |
---|---|
111695
62d2be8b2bd2
color-lab.el: Add coding cookie.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111693
diff
changeset
|
1 ;;; color-lab.el --- Color manipulation laboratory routines -*- coding: utf-8; -*- |
111678
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
2 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
3 ;; Copyright (C) 2010 Free Software Foundation, Inc. |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
4 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
5 ;; Author: Julien Danjou <julien@danjou.info> |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
6 ;; Keywords: html |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
7 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
9 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
11 ;; it under the terms of the GNU General Public License as published by |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
13 ;; (at your option) any later version. |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
14 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
15 ;; GNU Emacs is distributed in the hope that it will be useful, |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
18 ;; GNU General Public License for more details. |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
19 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
20 ;; You should have received a copy of the GNU General Public License |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
22 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
23 ;;; Commentary: |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
24 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
25 ;; This package provides color manipulation functions. |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
26 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
27 ;;; Code: |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
28 |
111702
087bcfbfa5ef
color-lab: Require 'cl when compiling.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111701
diff
changeset
|
29 (eval-when-compile |
087bcfbfa5ef
color-lab: Require 'cl when compiling.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111701
diff
changeset
|
30 (require 'cl)) |
087bcfbfa5ef
color-lab: Require 'cl when compiling.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111701
diff
changeset
|
31 |
111693
1cb16ad0d1bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111678
diff
changeset
|
32 ;; Emacs < 23.3 |
111695
62d2be8b2bd2
color-lab.el: Add coding cookie.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111693
diff
changeset
|
33 (eval-and-compile |
62d2be8b2bd2
color-lab.el: Add coding cookie.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111693
diff
changeset
|
34 (unless (boundp 'float-pi) |
62d2be8b2bd2
color-lab.el: Add coding cookie.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111693
diff
changeset
|
35 (defconst float-pi (* 4 (atan 1)) "The value of Pi (3.1415926...)."))) |
111693
1cb16ad0d1bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111678
diff
changeset
|
36 |
111678
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
37 (defun rgb->hsv (red green blue) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
38 "Convert RED GREEN BLUE values to HSV representation. |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
39 Hue is in radian. Saturation and values are between 0 and 1." |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
40 (let* ((r (float red)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
41 (g (float green)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
42 (b (float blue)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
43 (max (max r g b)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
44 (min (min r g b))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
45 (list |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
46 (/ (* 2 float-pi |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
47 (cond ((and (= r g) (= g b)) 0) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
48 ((and (= r max) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
49 (>= g b)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
50 (* 60 (/ (- g b) (- max min)))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
51 ((and (= r max) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
52 (< g b)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
53 (+ 360 (* 60 (/ (- g b) (- max min))))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
54 ((= max g) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
55 (+ 120 (* 60 (/ (- b r) (- max min))))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
56 ((= max b) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
57 (+ 240 (* 60 (/ (- r g) (- max min))))))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
58 360) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
59 (if (= max 0) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
60 0 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
61 (- 1 (/ min max))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
62 (/ max 255.0)))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
63 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
64 (defun rgb->hsl (red green blue) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
65 "Convert RED GREEN BLUE colors to their HSL representation. |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
66 RED, GREEN and BLUE must be between 0 and 255." |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
67 (let* ((r (/ red 255.0)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
68 (g (/ green 255.0)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
69 (b (/ blue 255.0)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
70 (max (max r g b)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
71 (min (min r g b)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
72 (delta (- max min)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
73 (l (/ (+ max min) 2.0))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
74 (list |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
75 (if (= max min) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
76 0 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
77 (* 2 float-pi |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
78 (/ (cond ((= max r) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
79 (+ (/ (- g b) delta) (if (< g b) 6 0))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
80 ((= max g) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
81 (+ (/ (- b r) delta) 2)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
82 (t |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
83 (+ (/ (- r g) delta) 4))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
84 6))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
85 (if (= max min) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
86 0 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
87 (if (> l 0.5) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
88 (/ delta (- 2 (+ max min))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
89 (/ delta (+ max min)))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
90 l))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
91 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
92 (defun rgb->xyz (red green blue) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
93 "Converts RED GREEN BLUE colors to CIE XYZ representation. |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
94 RED, BLUE and GREEN must be between 0 and 1." |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
95 (let ((r (if (<= red 0.04045) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
96 (/ red 12.95) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
97 (expt (/ (+ red 0.055) 1.055) 2.4))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
98 (g (if (<= green 0.04045) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
99 (/ green 12.95) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
100 (expt (/ (+ green 0.055) 1.055) 2.4))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
101 (b (if (<= blue 0.04045) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
102 (/ blue 12.95) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
103 (expt (/ (+ blue 0.055) 1.055) 2.4)))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
104 (list (+ (* 0.4124564 r) (* 0.3575761 g) (* 0.1804375 b)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
105 (+ (* 0.21266729 r) (* 0.7151522 g) (* 0.0721750 b)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
106 (+ (* 0.0193339 r) (* 0.1191920 g) (* 0.9503041 b))))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
107 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
108 (defun xyz->rgb (X Y Z) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
109 "Converts CIE XYZ colors to RGB." |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
110 (let ((r (+ (* 3.2404542 X) (* -1.5371385 Y) (* -0.4985314 Z))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
111 (g (+ (* -0.9692660 X) (* 1.8760108 Y) (* 0.0415560 Z))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
112 (b (+ (* 0.0556434 X) (* -0.2040259 Y) (* 1.0572252 Z)))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
113 (list (if (<= r 0.0031308) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
114 (* 12.92 r) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
115 (- (* 1.055 (expt r (/ 1 2.4))) 0.055)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
116 (if (<= g 0.0031308) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
117 (* 12.92 g) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
118 (- (* 1.055 (expt g (/ 1 2.4))) 0.055)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
119 (if (<= b 0.0031308) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
120 (* 12.92 b) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
121 (- (* 1.055 (expt b (/ 1 2.4))) 0.055))))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
122 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
123 (defconst color-lab-d65-xyz '(0.950455 1.0 1.088753) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
124 "D65 white point in CIE XYZ.") |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
125 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
126 (defconst color-lab-ε (/ 216 24389.0)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
127 (defconst color-lab-κ (/ 24389 27.0)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
128 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
129 (defun xyz->lab (X Y Z &optional white-point) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
130 "Converts CIE XYZ to CIE L*a*b*. |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
131 WHITE-POINT can be specified as (X Y Z) white point to use. If |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
132 none is set, `color-lab-d65-xyz' is used." |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
133 (destructuring-bind (Xr Yr Zr) (or white-point color-lab-d65-xyz) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
134 (let* ((xr (/ X Xr)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
135 (yr (/ Y Yr)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
136 (zr (/ Z Zr)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
137 (fx (if (> xr color-lab-ε) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
138 (expt xr (/ 1 3.0)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
139 (/ (+ (* color-lab-κ xr) 16) 116.0))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
140 (fy (if (> yr color-lab-ε) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
141 (expt yr (/ 1 3.0)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
142 (/ (+ (* color-lab-κ yr) 16) 116.0))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
143 (fz (if (> zr color-lab-ε) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
144 (expt zr (/ 1 3.0)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
145 (/ (+ (* color-lab-κ zr) 16) 116.0)))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
146 (list |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
147 (- (* 116 fy) 16) ; L |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
148 (* 500 (- fx fy)) ; a |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
149 (* 200 (- fy fz)))))) ; b |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
150 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
151 (defun lab->xyz (L a b &optional white-point) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
152 "Converts CIE L*a*b* to CIE XYZ. |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
153 WHITE-POINT can be specified as (X Y Z) white point to use. If |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
154 none is set, `color-lab-d65-xyz' is used." |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
155 (destructuring-bind (Xr Yr Zr) (or white-point color-lab-d65-xyz) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
156 (let* ((fy (/ (+ L 16) 116.0)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
157 (fz (- fy (/ b 200.0))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
158 (fx (+ (/ a 500.0) fy)) |
111701
3fbe2d0ad0f8
color-lab.el: Fix all expt calls to use float type.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111695
diff
changeset
|
159 (xr (if (> (expt fx 3.0) color-lab-ε) |
3fbe2d0ad0f8
color-lab.el: Fix all expt calls to use float type.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111695
diff
changeset
|
160 (expt fx 3.0) |
111678
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
161 (/ (- (* fx 116) 16) color-lab-κ))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
162 (yr (if (> L (* color-lab-κ color-lab-ε)) |
111701
3fbe2d0ad0f8
color-lab.el: Fix all expt calls to use float type.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111695
diff
changeset
|
163 (expt (/ (+ L 16) 116.0) 3.0) |
111678
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
164 (/ L color-lab-κ))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
165 (zr (if (> (expt fz 3) color-lab-ε) |
111701
3fbe2d0ad0f8
color-lab.el: Fix all expt calls to use float type.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111695
diff
changeset
|
166 (expt fz 3.0) |
111678
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
167 (/ (- (* 116 fz) 16) color-lab-κ)))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
168 (list (* xr Xr) ; X |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
169 (* yr Yr) ; Y |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
170 (* zr Zr))))) ; Z |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
171 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
172 (defun rgb->lab (red green blue) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
173 "Converts RGB to CIE L*a*b*." |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
174 (apply 'xyz->lab (rgb->xyz red green blue))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
175 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
176 (defun rgb->normalize (color) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
177 "Normalize a RGB color to values between [0,1]." |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
178 (mapcar (lambda (x) (/ x 65535.0)) (x-color-values color))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
179 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
180 (defun lab->rgb (L a b) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
181 "Converts CIE L*a*b* to RGB." |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
182 (apply 'xyz->rgb (lab->xyz L a b))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
183 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
184 (defun color-lab-ciede2000 (color1 color2 &optional kL kC kH) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
185 "Computes the CIEDE2000 color distance between COLOR1 and COLOR2. |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
186 Colors must be in CIE L*a*b* format." |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
187 (destructuring-bind (L₁ a₁ b₁) color1 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
188 (destructuring-bind (L₂ a₂ b₂) color2 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
189 (let* ((kL (or kL 1)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
190 (kC (or kC 1)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
191 (kH (or kH 1)) |
111701
3fbe2d0ad0f8
color-lab.el: Fix all expt calls to use float type.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111695
diff
changeset
|
192 (C₁ (sqrt (+ (expt a₁ 2.0) (expt b₁ 2.0)))) |
3fbe2d0ad0f8
color-lab.el: Fix all expt calls to use float type.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111695
diff
changeset
|
193 (C₂ (sqrt (+ (expt a₂ 2.0) (expt b₂ 2.0)))) |
111678
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
194 (C̄ (/ (+ C₁ C₂) 2.0)) |
111701
3fbe2d0ad0f8
color-lab.el: Fix all expt calls to use float type.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111695
diff
changeset
|
195 (G (* 0.5 (- 1 (sqrt (/ (expt C̄ 7.0) (+ (expt C̄ 7.0) (expt 25 7.0))))))) |
111678
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
196 (a′₁ (* (+ 1 G) a₁)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
197 (a′₂ (* (+ 1 G) a₂)) |
111701
3fbe2d0ad0f8
color-lab.el: Fix all expt calls to use float type.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111695
diff
changeset
|
198 (C′₁ (sqrt (+ (expt a′₁ 2.0) (expt b₁ 2.0)))) |
3fbe2d0ad0f8
color-lab.el: Fix all expt calls to use float type.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111695
diff
changeset
|
199 (C′₂ (sqrt (+ (expt a′₂ 2.0) (expt b₂ 2.0)))) |
111678
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
200 (h′₁ (if (and (= b₁ 0) (= a′₁ 0)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
201 0 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
202 (let ((v (atan b₁ a′₁))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
203 (if (< v 0) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
204 (+ v (* 2 float-pi)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
205 v)))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
206 (h′₂ (if (and (= b₂ 0) (= a′₂ 0)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
207 0 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
208 (let ((v (atan b₂ a′₂))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
209 (if (< v 0) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
210 (+ v (* 2 float-pi)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
211 v)))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
212 (ΔL′ (- L₂ L₁)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
213 (ΔC′ (- C′₂ C′₁)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
214 (Δh′ (cond ((= (* C′₁ C′₂) 0) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
215 0) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
216 ((<= (abs (- h′₂ h′₁)) float-pi) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
217 (- h′₂ h′₁)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
218 ((> (- h′₂ h′₁) float-pi) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
219 (- (- h′₂ h′₁) (* 2 float-pi))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
220 ((< (- h′₂ h′₁) (- float-pi)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
221 (+ (- h′₂ h′₁) (* 2 float-pi))))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
222 (ΔH′ (* 2 (sqrt (* C′₁ C′₂)) (sin (/ Δh′ 2.0)))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
223 (L̄′ (/ (+ L₁ L₂) 2.0)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
224 (C̄′ (/ (+ C′₁ C′₂) 2.0)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
225 (h̄′ (cond ((= (* C′₁ C′₂) 0) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
226 (+ h′₁ h′₂)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
227 ((<= (abs (- h′₁ h′₂)) float-pi) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
228 (/ (+ h′₁ h′₂) 2.0)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
229 ((< (+ h′₁ h′₂) (* 2 float-pi)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
230 (/ (+ h′₁ h′₂ (* 2 float-pi)) 2.0)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
231 ((>= (+ h′₁ h′₂) (* 2 float-pi)) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
232 (/ (+ h′₁ h′₂ (* -2 float-pi)) 2.0)))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
233 (T (+ 1 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
234 (- (* 0.17 (cos (- h̄′ (degrees-to-radians 30))))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
235 (* 0.24 (cos (* h̄′ 2))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
236 (* 0.32 (cos (+ (* h̄′ 3) (degrees-to-radians 6)))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
237 (- (* 0.20 (cos (- (* h̄′ 4) (degrees-to-radians 63))))))) |
111701
3fbe2d0ad0f8
color-lab.el: Fix all expt calls to use float type.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111695
diff
changeset
|
238 (Δθ (* (degrees-to-radians 30) (exp (- (expt (/ (- h̄′ (degrees-to-radians 275)) (degrees-to-radians 25)) 2.0))))) |
3fbe2d0ad0f8
color-lab.el: Fix all expt calls to use float type.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111695
diff
changeset
|
239 (Rc (* 2 (sqrt (/ (expt C̄′ 7.0) (+ (expt C̄′ 7.0) (expt 25.0 7.0)))))) |
3fbe2d0ad0f8
color-lab.el: Fix all expt calls to use float type.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111695
diff
changeset
|
240 (Sl (+ 1 (/ (* 0.015 (expt (- L̄′ 50) 2.0)) (sqrt (+ 20 (expt (- L̄′ 50) 2.0)))))) |
111678
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
241 (Sc (+ 1 (* C̄′ 0.045))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
242 (Sh (+ 1 (* 0.015 C̄′ T))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
243 (Rt (- (* (sin (* Δθ 2)) Rc)))) |
111701
3fbe2d0ad0f8
color-lab.el: Fix all expt calls to use float type.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111695
diff
changeset
|
244 (sqrt (+ (expt (/ ΔL′ (* Sl kL)) 2.0) |
3fbe2d0ad0f8
color-lab.el: Fix all expt calls to use float type.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111695
diff
changeset
|
245 (expt (/ ΔC′ (* Sc kC)) 2.0) |
3fbe2d0ad0f8
color-lab.el: Fix all expt calls to use float type.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111695
diff
changeset
|
246 (expt (/ ΔH′ (* Sh kH)) 2.0) |
111678
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
247 (* Rt (/ ΔC′ (* Sc kC)) (/ ΔH′ (* Sh kH))))))))) |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
248 |
3b6c0c4ef2bb
shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
249 (provide 'color-lab) |
111695
62d2be8b2bd2
color-lab.el: Add coding cookie.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111693
diff
changeset
|
250 |
62d2be8b2bd2
color-lab.el: Add coding cookie.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111693
diff
changeset
|
251 ;;; color-lab.el ends here |