* color-rgb-to-hex rounding / color-srgb-to-xyz typos
@ 2021-01-12 11:23 Thomas Frössman
2021-01-19 3:37 ` Lars Ingebrigtsen
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Frössman @ 2021-01-12 11:23 UTC (permalink / raw)
To: emacs-devel
[-- 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 --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: color-rgb-to-hex rounding / color-srgb-to-xyz typos
2021-01-12 11:23 color-rgb-to-hex rounding / color-srgb-to-xyz typos Thomas Frössman
@ 2021-01-19 3:37 ` Lars Ingebrigtsen
2021-01-20 15:17 ` Thomas Frössman
0 siblings, 1 reply; 3+ messages in thread
From: Lars Ingebrigtsen @ 2021-01-19 3:37 UTC (permalink / raw)
To: Thomas Frössman; +Cc: emacs-devel
Thomas Frössman <thomasf@jossystem.se> writes:
> 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)
Was this meant to be added to the solarized package, or to the in-tree
`color-rgb-to-hex' function?
> 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.
I don't know, either. Is this related to bug#41544, perhaps?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: color-rgb-to-hex rounding / color-srgb-to-xyz typos
2021-01-19 3:37 ` Lars Ingebrigtsen
@ 2021-01-20 15:17 ` Thomas Frössman
0 siblings, 0 replies; 3+ messages in thread
From: Thomas Frössman @ 2021-01-20 15:17 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 2615 bytes --]
On Tue, Jan 19, 2021 at 4:37 AM Lars Ingebrigtsen <larsi@gnus.org> wrote:
> Thomas Frössman <thomasf@jossystem.se> writes:
>
> > 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)
>
> Was this meant to be added to the solarized package, or to the in-tree
> `color-rgb-to-hex' function?
>
Yes the in tree one, I added the change locally to that theme to avoid
getting the rounding issues but I forgot to remove the prefix when posting
to the e-mail list.
I am really not sure if rounding should just always be applied or if it
should be optional, I can't see many situations when you would not want to
round but at the same time it will change colors in existing code ever so
slightly.
>
> > 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.
>
> I don't know, either. Is this related to bug#41544, perhaps?
>
I don't think color-distance has anything to do with color.el at all.
Fixing these small value changes doesn't practically change much as far as
I could see except that color-tests.el maybe shouldn't assume that it's own
internal functions are correct when testing.
I mostly want good test data for the ciede2000 function, there is probably
good test data available here but it's unlikely to be usable in emacs due
to licensing. http://www2.ece.rochester.edu/~gsharma/ciede2000/ I might
resume work on finding better test data a little later and then create a
patch of it all.
>
> --
> (domestic pets only, the antidote for overdose, milk.)
> bloggy blog: http://lars.ingebrigtsen.no
>
--
Thomas Frössman
http://t.jossystem.se
[-- Attachment #2: Type: text/html, Size: 3836 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-20 15:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-12 11:23 color-rgb-to-hex rounding / color-srgb-to-xyz typos Thomas Frössman
2021-01-19 3:37 ` Lars Ingebrigtsen
2021-01-20 15:17 ` Thomas Frössman
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).