[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#54514: incorrect arithmetic in color-lighten-hsl?
From: |
Noah Friedman |
Subject: |
bug#54514: incorrect arithmetic in color-lighten-hsl? |
Date: |
Mon, 21 Mar 2022 16:31:01 -0700 (PDT) |
(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.
- bug#54514: incorrect arithmetic in color-lighten-hsl?,
Noah Friedman <=