Fit/Gamut Mapping
Description
Fit plugins (or gamut mapping plugins) allow for mapping an out of gamut color to be within the current color space's gamut. All default gamut mapping methods provided by ColorAide are provided via plugins.
Plugin Class
Plugins are created by subclassing coloraide.gamut.Fit
.
class Fit(Plugin, metaclass=ABCMeta):
"""Fit plugin class."""
NAME = ''
@abstractmethod
def fit(self, color: 'Color', space: str, **kwargs) -> None:
"""Get coordinates of the new gamut mapped color."""
Once registered, the plugin can then be used via fit
(and in some places like convert
) by passing its NAME
via the method
parameter along with any additional key word arguments to override default behavior. The current color
will be gamut mapped accordingly.
color.fit(method=NAME, **kwargs)
If you'd like the user to be able to set specific defaults, you can define an __init__
method and manage defaults accordingly. Defaults can be passed in when instantiating a new plugin.
Color.register(Plugin(**kwargs))
Reserved Name
clip
is a special, reserved name and the associated plugin cannot be overridden. Another clip plugin can be written, but it cannot override the original.