1. color-rgb-to-hex rounding
Hi. I was investigating why a simple color space conversion from rgb to lab and back via just multiplying a component with 1.0 caused colors to change when being converted back. The issue is that even tiny changes to a component float in LAB space can bring the color value down by 0.00000x or something in RGB and when it's converted back to hex it gets a surprising value.
I think I propose this change making rounding optional so that it doesn't affect anyone who is depending on the current behaviour.
(defun solarized-color-rgb-to-hex (red green blue &optional digits-per-component round)
"Return hexadecimal #RGB notation for the color specified by RED GREEN BLUE.
RED, GREEN, and BLUE should be numbers between 0.0 and 1.0, inclusive.
Optional argument DIGITS-PER-COMPONENT can be either 4 (the default)
or 2; use the latter if you need a 24-bit specification of a color.
Optional argument ROUND rounds values which probably is what you usually want."
(or digits-per-component (setq digits-per-component 4))
(let* ((maxval (if (= digits-per-component 2) 255 65535))
(fmt (if (= digits-per-component 2) "#%02x%02x%02x" "#%04x%04x%04x")))
(if round
(format fmt (+ 0.5 (* red maxval)) (+ 0.5 (* green maxval)) (+ 0.5(* blue maxval)))
(format fmt (* red maxval) (* green maxval) (* blue maxval)))))
2. typos (?) in color-srgb-to-xyz typos
While looking at the issue and referencing the wikipedia sRGB page it seems like these values should be changed.. Doing this upset the tests a bit though so I didn't take it all the way because I started trying to understand how to actually produce test case data that is based on some verified numbers and not just the output of color.el's functions.
diff --git a/lisp/color.el b/lisp/color.el
index 258acbe405..cc478a7525 100644
--- a/lisp/color.el
+++ b/lisp/color.el
@@ -187,16 +187,16 @@ color-srgb-to-xyz
"Convert RED GREEN BLUE colors from the sRGB color space to CIE XYZ.
RED, GREEN and BLUE should be between 0.0 and 1.0, inclusive."
(let ((r (if (<= red 0.04045)
- (/ red 12.95)
+ (/ red 12.92)
(expt (/ (+ red 0.055) 1.055) 2.4)))
(g (if (<= green 0.04045)
- (/ green 12.95)
+ (/ green 12.92)
(expt (/ (+ green 0.055) 1.055) 2.4)))
(b (if (<= blue 0.04045)
- (/ blue 12.95)
+ (/ blue 12.92)
(expt (/ (+ blue 0.055) 1.055) 2.4))))
(list (+ (* 0.4124564 r) (* 0.3575761 g) (* 0.1804375 b))
- (+ (* 0.21266729 r) (* 0.7151522 g) (* 0.0721750 b))
+ (+ (* 0.2126729 r) (* 0.7151522 g) (* 0.0721750 b))
(+ (* 0.0193339 r) (* 0.1191920 g) (* 0.9503041 b)))))
(defun color-xyz-to-srgb (X Y Z)