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

Colour values with different range #5

Open
emlyn opened this issue Feb 15, 2017 · 2 comments
Open

Colour values with different range #5

emlyn opened this issue Feb 15, 2017 · 2 comments

Comments

@emlyn
Copy link

emlyn commented Feb 15, 2017

What is the recommended way to get e.g. RGB values from a colour with a 0-255 range? Do I have to do something like [int(i * 255) for i in col.rgb]? It seems like a shortcut for this very common case would be useful.

@emlyn
Copy link
Author

emlyn commented Feb 15, 2017

Actually, I guess it should use rgb_clamped instead of rgb to ensure the resulting values are within range. But even that is not quite right because only values exactly equal to 1.0 will map to 255, whereas it should really be values in the range 255/256 to 1.
So would this be more correct: [min(255, int(i * 256)) for i in col.rgb_clamped]?

@emlyn
Copy link
Author

emlyn commented Feb 16, 2017

After a bit more looking around, I found another way: col.to('rgb').color_object.get_upscaled_value_tuple(), but it doesn't clamp the values to the valid range:

In [1]: col = spectra.lab(80, -250, 80)
In [2]: col.to('rgb').color_object.get_upscaled_value_tuple()
Out[2]: (0, 261, 0)

I think a simple, documented, and correct way of doing this would be very useful.

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

1 participant