From: "Thomas Frössman" <thomasf@jossystem.se>
To: emacs-devel@gnu.org
Subject: color-rgb-to-hex rounding / color-srgb-to-xyz typos
Date: Tue, 12 Jan 2021 12:23:53 +0100 [thread overview]
Message-ID: <CANDWisAspK_C7vojOgNiWW88MZTbP8ZHdCH+z6nJqK0kKexFSQ@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2873 bytes --]
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)
--
Thomas Frössman
http://t.jossystem.se
[-- Attachment #2: Type: text/html, Size: 5300 bytes --]
next reply other threads:[~2021-01-12 11:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-12 11:23 Thomas Frössman [this message]
2021-01-19 3:37 ` color-rgb-to-hex rounding / color-srgb-to-xyz typos Lars Ingebrigtsen
2021-01-20 15:17 ` Thomas Frössman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CANDWisAspK_C7vojOgNiWW88MZTbP8ZHdCH+z6nJqK0kKexFSQ@mail.gmail.com \
--to=thomasf@jossystem.se \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).