unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#54514: incorrect arithmetic in color-lighten-hsl?
@ 2022-03-21 23:31 Noah Friedman
  2022-03-22 14:28 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Noah Friedman @ 2022-03-21 23:31 UTC (permalink / raw)
  To: 54514

(Any branch or release; this function in color.el looks to be unchanged 
since it was originally introduced)

I might be mistaken, but I think color-lighten-hsl is wrong.  It's
increasing luminance by an absolute percent of 1, not the present
luminance.


Suppose you want to lighten the color "red":

	(color-name-to-rgb "red")
	=> (1.0 0.0 0.0)

	(color-rgb-to-hsl 1.0 0.0 0.0)
	=> (0.0 1.0 0.5)

If you try to lighten this by, say, 50%, currently the result is

	(color-lighten-hsl 0.0 1.0 0.5  50)
	=> (0.0 1.0 1.0)

Which is clearly wrong.  50% lighter red is not white!
The result I would have expected to see is 

	=> (0.0 1.0 0.75)


Currently, the function reads:

	(defun color-lighten-hsl (H S L percent)
	  ...
	  (list H S (color-clamp (+ L (/ percent 100.0)))))

I think it should be:

	(defun color-lighten-hsl (H S L percent)
	  ...
	  (list H S (color-clamp (+ L (* L (/ percent 100.0))))))


Could someone sanity check me?  My color theory background is pretty weak.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-22 14:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-21 23:31 bug#54514: incorrect arithmetic in color-lighten-hsl? Noah Friedman
2022-03-22 14:28 ` Lars Ingebrigtsen

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).