Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

[RFC] RGB clamping/upscaling API #97

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ZipFile
Copy link
Contributor

@ZipFile ZipFile commented Aug 4, 2019

One PR to (re)fix em all: #49, #64, #66, #87.

API around clamping and upscaling seems confusing for everyone, so here's proposal to fix this issue. Idea is to keep rgb color objects to represent values in a unified way and provide additional helpers to work with out-of-range values and scaling.

Core changes:
sRGBColor(255, 123, 50, is_upscaled=True) becomes sRGBColor.new_from_upscaled(255, 123, 50)
and

color = sRGBColor(-1.0, 0.5, 1.77)
print(color.clamped_rgb_r, color.clamped_rgb_g, color.clamped_rgb_b)
# output: 0 0.5 1

becomes:

color = sRGBColor(-1.0, 0.5, 1.77)
print(color.rgb_r, color.rgb_g, color.rgb_b)
# output: -1.0 0.5 1.77
color = color.clamped()
print(color.rgb_r, color.rgb_g, color.rgb_b)
# output: 0 0.5 1

Things to discus:
colormath/color_conversions.py - In transformation chain math domain error occurs only for AdobeRGBColor and AppleRGBColor. Should it be documented? Seems like rgb clapping was added to fix #49, but as side effect we got contradiction with documentation and #87.

@KelSolaar
Copy link
Collaborator

I haven't looked yet at the PR but I think that the default behaviour should be to not clamp anything. Clamping values is really bad when doing gamut conversions. The math domain error on the power could be addressed elegantly by using a safe/symmetrical power such as the one we use in Colour.

@ZipFile
Copy link
Contributor Author

ZipFile commented Aug 13, 2019

Not really familiar with subject, but would safe/symmetrical power be correct? Avoiding stepping into complex numbers zone feels like there is some data loss possible, less drastic than clamping, though.

@KelSolaar
Copy link
Collaborator

but would safe/symmetrical power be correct?

Depends how you define correct. As you know, raising a negative number to a fractional power is undefined in R and it is problematic in many cases. The safe/symmetrical power will allow preserving the negative information which is important in a colour management chain, this is to say that anytime you clamp, you are destroying data.

@ZipFile
Copy link
Contributor Author

ZipFile commented Feb 3, 2020

Rebased with master.

I'm still not sure about safe/symmetrical power approach, though. Should I implement it for this PR?

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

Successfully merging this pull request may close these issues.

convert_color crash in 2.0.2
2 participants