Skip to content

Commit

Permalink
Merge pull request #110 from facelessuser/enhance/interp-fit
Browse files Browse the repository at this point in the history
Don't fit spaces when interpolating unless they cannot be represented
  • Loading branch information
facelessuser authored Feb 17, 2022
2 parents 3f9919a + 55d165d commit a389ca0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
5 changes: 3 additions & 2 deletions coloraide/interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,9 @@ def color_lerp(
"""Color interpolation."""

# Convert to the color space and ensure the color fits inside
color1 = color1.convert(space, fit=True)
color2 = color1._handle_color_input(color2).convert(space, fit=True)
fit = not color1.CS_MAP[space].EXTENDED_RANGE
color1 = color1.convert(space, fit=fit)
color2 = color1._handle_color_input(color2).convert(space, fit=fit)

# Adjust hues if we have two valid hues
if isinstance(color1._space, Cylindrical):
Expand Down
6 changes: 6 additions & 0 deletions coloraide/spaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ class Space(
# gamut, when evaluated with a threshold, may appear to be in gamut enough, but when checking the original color
# space, the values can be greatly out of specification (looking at you HSL).
GAMUT_CHECK = None # type: Optional[str]
# When set to `True`, this denotes that the color space has the ability to represent out of gamut in colors in an
# extended range. When interpolation is done, if colors are interpolated in a smaller gamut than the colors being
# interpolated, the colors will usually be gamut mapped, but if the interpolation space happens to support extended
# ranges, then the colors will not be gamut mapped even if their gamut is larger than the target interpolation
# space.
EXTENDED_RANGE = False
# Bounds of channels. Range could be suggested or absolute as not all spaces have definitive ranges.
BOUNDS = tuple() # type: Tuple[Bounds, ...]
# White point
Expand Down
1 change: 1 addition & 0 deletions coloraide/spaces/srgb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class SRGB(Space):
}
WHITE = "D65"

EXTENDED_RANGE = True
BOUNDS = (
GamutBound(0.0, 1.0, FLG_OPT_PERCENT),
GamutBound(0.0, 1.0, FLG_OPT_PERCENT),
Expand Down
9 changes: 8 additions & 1 deletion docs/src/markdown/about/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

## 0.9.0

!!! warning "Breaking Change"
Custom gamut mapping plugins no longer return coordinates and require the method to update the passed in color.

- **NEW**: Improved, faster gamut mapping algorithm.
- **NEW**: FIT plugins (gamut mapping) no longer return coordinates but should modify the color passed in.
- **NEW**: FIT plugins (gamut mapping) no longer return coordinates but should modify the color passed in.
- **NEW**: Expose default interpolation space as a class variable that can be controlled when creating a custom class
via class inheritance.
- **NEW**: Colors can now directly specify the ∆E method that is used when interpolating color steps and using
`max_delta_e` via the new `delta_e` argument. If the `delta_e` parameter is omitted, the color object's default ∆E
method will be used.
- **NEW**: Oklab is now the default interpolation color space.
- **NEW**: Interpolation will now avoid fitting colors that are out of gamut unless the color space cannot represent
out of gamut colors. Currently, all of the RGB colors (`srgb`, `display-p3`, etc.) all support extended ranges, but
the HSL, HWB, and HSV color models for `srgb` (including spaces such as `okhsl` and `okhsv`) do not support extended
ranges and will still be gamut mapped.
- **FIX**: Remove some incorrect code from the gamut mapping algorithm that would shortcut the mapping to reduce chroma
to zero.

Expand Down
6 changes: 6 additions & 0 deletions docs/src/markdown/plugins/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ class XYZD65(Space):
# gamut, when evaluated with a threshold, may appear to be in gamut enough, but when checking the original color
# space, the values can be greatly out of specification (looking at you HSL).
GAMUT_CHECK = None
# When set to `True`, this denotes that the color space has the ability to represent out of gamut in colors in an
# extended range. When interpolation is done, if colors are interpolated in a smaller gamut than the colors being
# interpolated, the colors will usually be gamut mapped, but if the interpolation space happens to support extended
# ranges, then the colors will not be gamut mapped even if their gamut is larger than the target interpolation
# space.
EXTENDED_RANGE = False

############################
# Getters and setters for non-alpha properties
Expand Down

0 comments on commit a389ca0

Please sign in to comment.