aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGnus developers2010-11-25 14:51:51 +0000
committerKatsumi Yamaoka2010-11-25 14:51:51 +0000
commitfd042993b7e4017c9fd26fe0cfac3a50a9dcdaa0 (patch)
tree558d5f0afdaf2de43600414524551c28d89bbe30
parentd50717f03009b20bedfeb1c652fc63fae38ae325 (diff)
downloademacs-fd042993b7e4017c9fd26fe0cfac3a50a9dcdaa0.tar.gz
emacs-fd042993b7e4017c9fd26fe0cfac3a50a9dcdaa0.zip
shr.el (shr-insert): Fix the way to fold lines.
shr-color.el (shr-color->hexadecimal): Use color-rgb->hex color.el: Rename from color-lab.el (color-rgb->hex): Add. (color-complement): Add. (color-complement-hex): Add.
-rw-r--r--lisp/gnus/ChangeLog11
-rw-r--r--lisp/gnus/color.el (renamed from lisp/gnus/color-lab.el)97
-rw-r--r--lisp/gnus/shr-color.el18
-rw-r--r--lisp/gnus/shr.el2
4 files changed, 78 insertions, 50 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog
index ba5c53aca0e..4bc94f9008a 100644
--- a/lisp/gnus/ChangeLog
+++ b/lisp/gnus/ChangeLog
@@ -1,5 +1,16 @@
12010-11-25 Katsumi Yamaoka <yamaoka@jpl.org>
2
3 * shr.el (shr-insert): Fix the way to fold lines.
4
12010-11-25 Julien Danjou <julien@danjou.info> 52010-11-25 Julien Danjou <julien@danjou.info>
2 6
7 * shr-color.el (shr-color->hexadecimal): Use color-rgb->hex
8
9 * color.el: Rename from color-lab.el
10 (color-rgb->hex): Add.
11 (color-complement): Add.
12 (color-complement-hex): Add.
13
3 * gnus-sum.el (gnus-summary-widget-forward): Add, and bind to [tab]. 14 * gnus-sum.el (gnus-summary-widget-forward): Add, and bind to [tab].
4 15
52010-11-25 Lars Magne Ingebrigtsen <larsi@gnus.org> 162010-11-25 Lars Magne Ingebrigtsen <larsi@gnus.org>
diff --git a/lisp/gnus/color-lab.el b/lisp/gnus/color.el
index c3663ebc712..67ee9e79f10 100644
--- a/lisp/gnus/color-lab.el
+++ b/lisp/gnus/color.el
@@ -1,4 +1,4 @@
1;;; color-lab.el --- Color manipulation laboratory routines -*- coding: utf-8; -*- 1;;; color.el --- Color manipulation laboratory routines -*- coding: utf-8; -*-
2 2
3;; Copyright (C) 2010 Free Software Foundation, Inc. 3;; Copyright (C) 2010 Free Software Foundation, Inc.
4 4
@@ -34,7 +34,24 @@
34 (unless (boundp 'float-pi) 34 (unless (boundp 'float-pi)
35 (defconst float-pi (* 4 (atan 1)) "The value of Pi (3.1415926...)."))) 35 (defconst float-pi (* 4 (atan 1)) "The value of Pi (3.1415926...).")))
36 36
37(defun rgb->hsv (red green blue) 37(defun color-rgb->hex (red green blue)
38 "Return hexadecimal notation for RED GREEN BLUE color.
39RED GREEN BLUE must be values between [0,1]."
40 (format "#%02x%02x%02x"
41 (* red 255) (* green 255) (* blue 255)))
42
43(defun color-complement (color)
44 "Return the color that is the complement of COLOR."
45 (let ((color (color-rgb->normalize color)))
46 (list (- 1.0 (car color))
47 (- 1.0 (cadr color))
48 (- 1.0 (caddr color)))))
49
50(defun color-complement-hex (color)
51 "Return the color that is the complement of COLOR, in hexadecimal format."
52 (apply 'color-rgb->hex (color-complement color)))
53
54(defun color-rgb->hsv (red green blue)
38 "Convert RED GREEN BLUE values to HSV representation. 55 "Convert RED GREEN BLUE values to HSV representation.
39Hue is in radian. Saturation and values are between 0 and 1." 56Hue is in radian. Saturation and values are between 0 and 1."
40 (let* ((r (float red)) 57 (let* ((r (float red))
@@ -61,12 +78,12 @@ Hue is in radian. Saturation and values are between 0 and 1."
61 (- 1 (/ min max))) 78 (- 1 (/ min max)))
62 (/ max 255.0)))) 79 (/ max 255.0))))
63 80
64(defun rgb->hsl (red green blue) 81(defun color-rgb->hsl (red green blue)
65 "Convert RED GREEN BLUE colors to their HSL representation. 82 "Convert RED GREEN BLUE colors to their HSL representation.
66RED, GREEN and BLUE must be between 0 and 255." 83RED, GREEN and BLUE must be between [0,1]."
67 (let* ((r (/ red 255.0)) 84 (let* ((r red)
68 (g (/ green 255.0)) 85 (g green)
69 (b (/ blue 255.0)) 86 (b blue)
70 (max (max r g b)) 87 (max (max r g b))
71 (min (min r g b)) 88 (min (min r g b))
72 (delta (- max min)) 89 (delta (- max min))
@@ -89,9 +106,9 @@ RED, GREEN and BLUE must be between 0 and 255."
89 (/ delta (+ max min)))) 106 (/ delta (+ max min))))
90 l))) 107 l)))
91 108
92(defun rgb->xyz (red green blue) 109(defun color-rgb->xyz (red green blue)
93 "Converts RED GREEN BLUE colors to CIE XYZ representation. 110 "Converts RED GREEN BLUE colors to CIE XYZ representation.
94RED, BLUE and GREEN must be between 0 and 1." 111RED, BLUE and GREEN must be between [0,1]."
95 (let ((r (if (<= red 0.04045) 112 (let ((r (if (<= red 0.04045)
96 (/ red 12.95) 113 (/ red 12.95)
97 (expt (/ (+ red 0.055) 1.055) 2.4))) 114 (expt (/ (+ red 0.055) 1.055) 2.4)))
@@ -105,8 +122,8 @@ RED, BLUE and GREEN must be between 0 and 1."
105 (+ (* 0.21266729 r) (* 0.7151522 g) (* 0.0721750 b)) 122 (+ (* 0.21266729 r) (* 0.7151522 g) (* 0.0721750 b))
106 (+ (* 0.0193339 r) (* 0.1191920 g) (* 0.9503041 b))))) 123 (+ (* 0.0193339 r) (* 0.1191920 g) (* 0.9503041 b)))))
107 124
108(defun xyz->rgb (X Y Z) 125(defun color-xyz->rgb (X Y Z)
109 "Converts CIE XYZ colors to RGB." 126 "Converts CIE X Y Z colors to RGB."
110 (let ((r (+ (* 3.2404542 X) (* -1.5371385 Y) (* -0.4985314 Z))) 127 (let ((r (+ (* 3.2404542 X) (* -1.5371385 Y) (* -0.4985314 Z)))
111 (g (+ (* -0.9692660 X) (* 1.8760108 Y) (* 0.0415560 Z))) 128 (g (+ (* -0.9692660 X) (* 1.8760108 Y) (* 0.0415560 Z)))
112 (b (+ (* 0.0556434 X) (* -0.2040259 Y) (* 1.0572252 Z)))) 129 (b (+ (* 0.0556434 X) (* -0.2040259 Y) (* 1.0572252 Z))))
@@ -120,68 +137,68 @@ RED, BLUE and GREEN must be between 0 and 1."
120 (* 12.92 b) 137 (* 12.92 b)
121 (- (* 1.055 (expt b (/ 1 2.4))) 0.055))))) 138 (- (* 1.055 (expt b (/ 1 2.4))) 0.055)))))
122 139
123(defconst color-lab-d65-xyz '(0.950455 1.0 1.088753) 140(defconst color-d65-xyz '(0.950455 1.0 1.088753)
124 "D65 white point in CIE XYZ.") 141 "D65 white point in CIE XYZ.")
125 142
126(defconst color-lab-ε (/ 216 24389.0)) 143(defconst color-cie-ε (/ 216 24389.0))
127(defconst color-lab-κ (/ 24389 27.0)) 144(defconst color-cie-κ (/ 24389 27.0))
128 145
129(defun xyz->lab (X Y Z &optional white-point) 146(defun color-xyz->lab (X Y Z &optional white-point)
130 "Converts CIE XYZ to CIE L*a*b*. 147 "Converts CIE XYZ to CIE L*a*b*.
131WHITE-POINT can be specified as (X Y Z) white point to use. If 148WHITE-POINT can be specified as (X Y Z) white point to use. If
132none is set, `color-lab-d65-xyz' is used." 149none is set, `color-d65-xyz' is used."
133 (destructuring-bind (Xr Yr Zr) (or white-point color-lab-d65-xyz) 150 (destructuring-bind (Xr Yr Zr) (or white-point color-d65-xyz)
134 (let* ((xr (/ X Xr)) 151 (let* ((xr (/ X Xr))
135 (yr (/ Y Yr)) 152 (yr (/ Y Yr))
136 (zr (/ Z Zr)) 153 (zr (/ Z Zr))
137 (fx (if (> xr color-lab-ε) 154 (fx (if (> xr color-cie-ε)
138 (expt xr (/ 1 3.0)) 155 (expt xr (/ 1 3.0))
139 (/ (+ (* color-lab-κ xr) 16) 116.0))) 156 (/ (+ (* color-cie-κ xr) 16) 116.0)))
140 (fy (if (> yr color-lab-ε) 157 (fy (if (> yr color-cie-ε)
141 (expt yr (/ 1 3.0)) 158 (expt yr (/ 1 3.0))
142 (/ (+ (* color-lab-κ yr) 16) 116.0))) 159 (/ (+ (* color-cie-κ yr) 16) 116.0)))
143 (fz (if (> zr color-lab-ε) 160 (fz (if (> zr color-cie-ε)
144 (expt zr (/ 1 3.0)) 161 (expt zr (/ 1 3.0))
145 (/ (+ (* color-lab-κ zr) 16) 116.0)))) 162 (/ (+ (* color-cie-κ zr) 16) 116.0))))
146 (list 163 (list
147 (- (* 116 fy) 16) ; L 164 (- (* 116 fy) 16) ; L
148 (* 500 (- fx fy)) ; a 165 (* 500 (- fx fy)) ; a
149 (* 200 (- fy fz)))))) ; b 166 (* 200 (- fy fz)))))) ; b
150 167
151(defun lab->xyz (L a b &optional white-point) 168(defun color-lab->xyz (L a b &optional white-point)
152 "Converts CIE L*a*b* to CIE XYZ. 169 "Converts CIE L*a*b* to CIE XYZ.
153WHITE-POINT can be specified as (X Y Z) white point to use. If 170WHITE-POINT can be specified as (X Y Z) white point to use. If
154none is set, `color-lab-d65-xyz' is used." 171none is set, `color-d65-xyz' is used."
155 (destructuring-bind (Xr Yr Zr) (or white-point color-lab-d65-xyz) 172 (destructuring-bind (Xr Yr Zr) (or white-point color-d65-xyz)
156 (let* ((fy (/ (+ L 16) 116.0)) 173 (let* ((fy (/ (+ L 16) 116.0))
157 (fz (- fy (/ b 200.0))) 174 (fz (- fy (/ b 200.0)))
158 (fx (+ (/ a 500.0) fy)) 175 (fx (+ (/ a 500.0) fy))
159 (xr (if (> (expt fx 3.0) color-lab-ε) 176 (xr (if (> (expt fx 3.0) color-cie-ε)
160 (expt fx 3.0) 177 (expt fx 3.0)
161 (/ (- (* fx 116) 16) color-lab-κ))) 178 (/ (- (* fx 116) 16) color-cie-κ)))
162 (yr (if (> L (* color-lab-κ color-lab-ε)) 179 (yr (if (> L (* color-cie-κ color-cie-ε))
163 (expt (/ (+ L 16) 116.0) 3.0) 180 (expt (/ (+ L 16) 116.0) 3.0)
164 (/ L color-lab-κ))) 181 (/ L color-cie-κ)))
165 (zr (if (> (expt fz 3) color-lab-ε) 182 (zr (if (> (expt fz 3) color-cie-ε)
166 (expt fz 3.0) 183 (expt fz 3.0)
167 (/ (- (* 116 fz) 16) color-lab-κ)))) 184 (/ (- (* 116 fz) 16) color-cie-κ))))
168 (list (* xr Xr) ; X 185 (list (* xr Xr) ; X
169 (* yr Yr) ; Y 186 (* yr Yr) ; Y
170 (* zr Zr))))) ; Z 187 (* zr Zr))))) ; Z
171 188
172(defun rgb->lab (red green blue) 189(defun color-rgb->lab (red green blue)
173 "Converts RGB to CIE L*a*b*." 190 "Converts RGB to CIE L*a*b*."
174 (apply 'xyz->lab (rgb->xyz red green blue))) 191 (apply 'color-xyz->lab (color-rgb->xyz red green blue)))
175 192
176(defun rgb->normalize (color) 193(defun color-rgb->normalize (color)
177 "Normalize a RGB color to values between [0,1]." 194 "Normalize a RGB color to values between [0,1]."
178 (mapcar (lambda (x) (/ x 65535.0)) (x-color-values color))) 195 (mapcar (lambda (x) (/ x 65535.0)) (x-color-values color)))
179 196
180(defun lab->rgb (L a b) 197(defun color-lab->rgb (L a b)
181 "Converts CIE L*a*b* to RGB." 198 "Converts CIE L*a*b* to RGB."
182 (apply 'xyz->rgb (lab->xyz L a b))) 199 (apply 'color-xyz->rgb (color-lab->xyz L a b)))
183 200
184(defun color-lab-ciede2000 (color1 color2 &optional kL kC kH) 201(defun color-cie-de2000 (color1 color2 &optional kL kC kH)
185 "Computes the CIEDE2000 color distance between COLOR1 and COLOR2. 202 "Computes the CIEDE2000 color distance between COLOR1 and COLOR2.
186Colors must be in CIE L*a*b* format." 203Colors must be in CIE L*a*b* format."
187 (destructuring-bind (L₁ a₁ b₁) color1 204 (destructuring-bind (L₁ a₁ b₁) color1
@@ -246,6 +263,6 @@ Colors must be in CIE L*a*b* format."
246 (expt (/ ΔH′ (* Sh kH)) 2.0) 263 (expt (/ ΔH′ (* Sh kH)) 2.0)
247 (* Rt (/ ΔC′ (* Sc kC)) (/ ΔH′ (* Sh kH))))))))) 264 (* Rt (/ ΔC′ (* Sc kC)) (/ ΔH′ (* Sh kH)))))))))
248 265
249(provide 'color-lab) 266(provide 'color)
250 267
251;;; color-lab.el ends here 268;;; color.el ends here
diff --git a/lisp/gnus/shr-color.el b/lisp/gnus/shr-color.el
index c5ee8c721c8..3346b43d964 100644
--- a/lisp/gnus/shr-color.el
+++ b/lisp/gnus/shr-color.el
@@ -26,7 +26,7 @@
26 26
27;;; Code: 27;;; Code:
28 28
29(require 'color-lab) 29(require 'color)
30 30
31(defgroup shr-color nil 31(defgroup shr-color nil
32 "Simple HTML Renderer colors" 32 "Simple HTML Renderer colors"
@@ -258,7 +258,7 @@ Like rgb() or hsl()."
258 (l (/ (string-to-number (match-string-no-properties 3 color)) 100.0))) 258 (l (/ (string-to-number (match-string-no-properties 3 color)) 100.0)))
259 (destructuring-bind (r g b) 259 (destructuring-bind (r g b)
260 (shr-color-hsl-to-rgb-fractions h s l) 260 (shr-color-hsl-to-rgb-fractions h s l)
261 (format "#%02X%02X%02X" (* r 255) (* g 255) (* b 255))))) 261 (color-rgb->hex r g b))))
262 ;; Color names 262 ;; Color names
263 ((cdr (assoc-string color shr-color-html-colors-alist t))) 263 ((cdr (assoc-string color shr-color-html-colors-alist t)))
264 ;; Unrecognized color :( 264 ;; Unrecognized color :(
@@ -324,15 +324,15 @@ If FIXED-BACKGROUND is set, and if the color are not visible, a
324new background color will not be computed. Only the foreground 324new background color will not be computed. Only the foreground
325color will be adapted to be visible on BG." 325color will be adapted to be visible on BG."
326 ;; Convert fg and bg to CIE Lab 326 ;; Convert fg and bg to CIE Lab
327 (let ((fg-norm (rgb->normalize fg)) 327 (let ((fg-norm (color-rgb->normalize fg))
328 (bg-norm (rgb->normalize bg))) 328 (bg-norm (color-rgb->normalize bg)))
329 (if (or (null fg-norm) 329 (if (or (null fg-norm)
330 (null bg-norm)) 330 (null bg-norm))
331 (list bg fg) 331 (list bg fg)
332 (let* ((fg-lab (apply 'rgb->lab fg-norm)) 332 (let* ((fg-lab (apply 'color-rgb->lab fg-norm))
333 (bg-lab (apply 'rgb->lab bg-norm)) 333 (bg-lab (apply 'color-rgb->lab bg-norm))
334 ;; Compute color distance using CIE DE 2000 334 ;; Compute color distance using CIE DE 2000
335 (fg-bg-distance (color-lab-ciede2000 fg-lab bg-lab)) 335 (fg-bg-distance (color-cie-de2000 fg-lab bg-lab))
336 ;; Compute luminance distance (substract L component) 336 ;; Compute luminance distance (substract L component)
337 (luminance-distance (abs (- (car fg-lab) (car bg-lab))))) 337 (luminance-distance (abs (- (car fg-lab) (car bg-lab)))))
338 (if (and (>= fg-bg-distance shr-color-visible-distance-min) 338 (if (and (>= fg-bg-distance shr-color-visible-distance-min)
@@ -350,10 +350,10 @@ color will be adapted to be visible on BG."
350 bg 350 bg
351 (apply 'format "#%02x%02x%02x" 351 (apply 'format "#%02x%02x%02x"
352 (mapcar (lambda (x) (* (max (min 1 x) 0) 255)) 352 (mapcar (lambda (x) (* (max (min 1 x) 0) 255))
353 (apply 'lab->rgb bg-lab)))) 353 (apply 'color-lab->rgb bg-lab))))
354 (apply 'format "#%02x%02x%02x" 354 (apply 'format "#%02x%02x%02x"
355 (mapcar (lambda (x) (* (max (min 1 x) 0) 255)) 355 (mapcar (lambda (x) (* (max (min 1 x) 0) 255))
356 (apply 'lab->rgb fg-lab)))))))))) 356 (apply 'color-lab->rgb fg-lab))))))))))
357 357
358(provide 'shr-color) 358(provide 'shr-color)
359 359
diff --git a/lisp/gnus/shr.el b/lisp/gnus/shr.el
index 9078e524031..1746c9aee4b 100644
--- a/lisp/gnus/shr.el
+++ b/lisp/gnus/shr.el
@@ -254,7 +254,7 @@ redirects somewhere else."
254 (while (and (> (current-column) shr-width) 254 (while (and (> (current-column) shr-width)
255 (progn 255 (progn
256 (setq found (shr-find-fill-point)) 256 (setq found (shr-find-fill-point))
257 (not (eolp)))) 257 (not (or (bolp) (eolp)))))
258 (when (eq (preceding-char) ? ) 258 (when (eq (preceding-char) ? )
259 (delete-char -1)) 259 (delete-char -1))
260 (insert "\n") 260 (insert "\n")