Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative clause in linearize-srgb and delinearize-srgb #10

Open
wasserwerk opened this issue Apr 24, 2018 · 4 comments
Open

Negative clause in linearize-srgb and delinearize-srgb #10

wasserwerk opened this issue Apr 24, 2018 · 4 comments

Comments

@wasserwerk
Copy link

The cond in linearize-srgb have a negative clause for x < -0.040449936d0 (exactly: (* -0.0031308d0 12.92d0)). You make similar computation in delinearize-srgb. Why? I've never seen such a formula (negative term). Neither in wikipedia, nor Bruce Lindbloom, nor other sources (e.g. https://www.w3.org/Graphics/Color/srgb.pdf).

@privet-kitty
Copy link
Owner

Hi. As in docstring written, it is actually the same formula as bg-sRGB, that extends the range of sRGB ([-0.53, 1.68] instead of [0, 1]).
http://www.color.org/chardata/rgb/bgsrgb.xalter

@wasserwerk
Copy link
Author

wasserwerk commented Apr 24, 2018

All right! Understood. I read the comment, but didn't know, what bg-sRGB means. And I didn't google for it. Sorry.

As you wrote earlier, you prefer multiple values over lists for better performance. But here you do one comparision more that necessary (for sRGB) - for each color once, which gives millions for a real color image. Would not it be better to have one pair of linearizer/delinearizer for sRGB and another for bg-SRGB. Although the code is largely identical.

@privet-kitty
Copy link
Owner

privet-kitty commented Apr 24, 2018

You might mean

(defun linearize-srgb-faster (x)
  (declare (optimize (speed 3) (safety 1))
	   (double-float x))
  (if(> x #.(* 0.0031308d0 12.92d0))
     (expt (* (+ 0.055d0 x) #.(/ 1.055d0)) 2.4d0)
     (* x #.(/ 12.92d0))))

Though in reality it makes little difference in speed when doing

> (dufy::time-after-gc (dotimes (i 50000000)
                          (dufy:rgb-to-lrgb (random 1d0) (random 1d0) (random 1d0)))) ;; mistake edited

or something alike. (Of course, it's because almost all values here are processed in the first case.)
One more cond matters little. (A much larger overhead in dufy is dynamic call of (de)linearizer.)

@privet-kitty
Copy link
Owner

Additional remark:
I adopted the (bg-sRGB-type) extension in every normal (i.e. the nominal range = [0, 1]) RGB space, since it's consistent with the extensions already in use (bg-sRGB, scRGB-nl, etc.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants