Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions ch_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def setup_gamut_style(self):
ch_settings = sublime.load_settings('color_helper.sublime-settings')
self.show_out_of_gamut_preview = ch_settings.get('show_out_of_gamut_preview', True)
self.gamut_space = ch_settings.get('gamut_space', 'srgb')
self.gamut_map = ch_settings.get('gamut_map', 'lch-chroma')
gmap = ch_settings.get('gamut_map', {'method': 'minde-chroma', 'pspace': 'lch-d65'})
if isinstance(gmap, str):
gmap = {'method': gmap}
self.gamut_map = gmap
if self.gamut_space not in GAMUT_SPACES:
self.gamut_space = 'srgb'

Expand All @@ -35,7 +38,7 @@ def setup_image_border(self):
if border_color is not None:
try:
border_color = self.base(border_color)
border_color.fit(self.gamut_space, method=self.gamut_map)
border_color.fit(self.gamut_space, **self.gamut_map)
except Exception:
border_color = None

Expand Down Expand Up @@ -188,15 +191,15 @@ def get_preview(self, color):
if not color.in_gamut(check_space):
message = 'preview out of gamut'
if self.show_out_of_gamut_preview:
pcolor = color.convert(self.gamut_space, fit=self.gamut_map)
pcolor = color.convert(self.gamut_space).fit(**self.gamut_map)
preview1 = pcolor.clone().set('alpha', 1)
preview2 = pcolor
else:
preview1 = self.out_of_gamut
preview2 = self.out_of_gamut
preview_border = self.out_of_gamut_border
else:
pcolor = color.convert(self.gamut_space, fit=self.gamut_map)
pcolor = color.convert(self.gamut_space).fit(**self.gamut_map)
preview1 = pcolor.clone().set('alpha', 1)
preview2 = pcolor

Expand Down
2 changes: 1 addition & 1 deletion ch_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def color_picker(self, color):

if self.os_color_picker:
self.view.hide_popup()
new_color = native_picker(self.base(color).convert("srgb", fit=self.gamut_map))
new_color = native_picker(self.base(color).convert("srgb").fit(**self.gamut_map))
if new_color is not None:
sublime.set_timeout(
lambda c=new_color.to_string(**util.COLOR_FULL_PREC): self.view.run_command(
Expand Down
2 changes: 1 addition & 1 deletion ch_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def setup(self, color, mode, controls, on_done, on_cancel):
self.setup_controls(controls)
color.convert(self.mode, in_place=True)
if not color.in_gamut():
color.fit(method=self.gamut_map)
color.fit(**self.gamut_map)
else:
color.clip()
# Ensure hue is between 0 - 360.
Expand Down
12 changes: 7 additions & 5 deletions ch_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ def setup_gamut_options(self):

self.show_out_of_gamut_preview = ch_settings.get('show_out_of_gamut_preview', True)
self.gamut_space = ch_settings.get('gamut_space', 'srgb')
self.gamut_map = ch_settings.get('gamut_map', 'lch-chroma')
gmap = ch_settings.get('gamut_map', {'method': 'minde-chroma', 'pspace': 'lch-d65'})
if isinstance(gmap, str):
gmap = {'method': gmap}
self.gamut_map = gmap
if self.gamut_space not in util.GAMUT_SPACES:
self.gamut_space = 'srgb'
self.out_of_gamut = self.base("transparent").convert(self.gamut_space)
Expand Down Expand Up @@ -437,7 +440,7 @@ def do_search(self, force=False):
mdpopups.scope2style(self.view, self.view.scope_name(pt))['background']
).convert("hsl")
hsl['lightness'] = hsl['lightness'] + (0.3 if hsl.luminance() < 0.5 else -0.3)
preview_border = hsl.convert(self.gamut_space, fit=self.gamut_map).set('alpha', 1)
preview_border = hsl.convert(self.gamut_space).fit(**self.gamut_map).set('alpha', 1)

color = self.base(obj.color)
title = ''
Expand All @@ -448,15 +451,15 @@ def do_search(self, force=False):
if not color.in_gamut(check_space):
title = ' title="Preview out of gamut"'
if self.show_out_of_gamut_preview:
pcolor = color.convert(self.gamut_space, fit=self.gamut_map)
pcolor = color.convert(self.gamut_space).fit(**self.gamut_map)
preview1 = pcolor.clone().set('alpha', 1)
preview2 = pcolor
else:
preview1 = self.out_of_gamut
preview2 = self.out_of_gamut
preview_border = self.out_of_gamut_border
else:
pcolor = color.convert(self.gamut_space, fit=self.gamut_map)
pcolor = color.convert(self.gamut_space).fit(**self.gamut_map)
preview1 = pcolor.clone().set('alpha', 1)
preview2 = pcolor

Expand Down Expand Up @@ -884,7 +887,6 @@ def plugin_loaded():
"""Setup plugin."""

global ch_settings
global ch_last_updated

# Setup settings
ch_settings = sublime.load_settings('color_helper.sublime-settings')
Expand Down
4 changes: 2 additions & 2 deletions ch_tool_blend.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ def preview(self, text):
else:
check_space = self.gamut_space
if not pcolor.in_gamut(check_space):
pcolor.fit(self.gamut_space, method=self.gamut_map)
pcolor.fit(self.gamut_space, **self.gamut_map)
message = '<br><em style="font-size: 0.9em;">* preview out of gamut</em>'
color_string = "<strong>Gamut Mapped</strong>: {}<br>".format(pcolor.to_string())
pcolor.convert(self.gamut_space, fit=self.gamut_map, in_place=True)
pcolor.convert(self.gamut_space, in_place=True).fit(**self.gamut_map)
color_string += "<strong>Color</strong>: {}".format(color.to_string(**util.DEFAULT))
preview = pcolor.clone().set('alpha', 1)
preview_alpha = pcolor
Expand Down
2 changes: 1 addition & 1 deletion ch_tool_colormod.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def preview(self, text):
check_space = self.gamut_space
if not pcolor.in_gamut(check_space):
message = '<br><em style="font-size: 0.9em;">* preview out of gamut</em>'
pcolor.convert(self.gamut_space, fit=self.gamut_map, in_place=True)
pcolor.convert(self.gamut_space, in_place=True).fit(**self.gamut_map)
preview = pcolor.clone().set('alpha', 1)
preview_alpha = pcolor
preview_border = self.default_border
Expand Down
4 changes: 2 additions & 2 deletions ch_tool_contrast.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ def evaluate(base, string, gamut_map):

# Package up the color, or the two reference colors along with the mixed.
if first:
colors.append(first.fit('srgb', method=gamut_map))
colors.append(first.fit('srgb', **gamut_map))
if second:
if second[-1] < 1.0:
second[-1] = 1.0
colors.append(second.fit('srgb', method=gamut_map))
colors.append(second.fit('srgb', **gamut_map))
if ratio:
if first[-1] < 1.0:
first = first.compose(second, space="srgb", out_space=first.space())
Expand Down
4 changes: 2 additions & 2 deletions ch_tool_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ def preview(self, text):
else:
check_space = self.gamut_space
if not orig.in_gamut(check_space):
orig.fit(self.gamut_space, method=self.gamut_map)
orig.fit(self.gamut_space, **self.gamut_map)
message = '<br><em style="font-size: 0.9em;">* preview out of gamut</em>'
color_string = "<strong>Gamut Mapped</strong>: {}<br>".format(orig.to_string())
orig.convert(self.gamut_space, fit=self.gamut_map, in_place=True)
orig.convert(self.gamut_space, in_place=True).fit(**self.gamut_map)
color_string += "<strong>Color</strong>: {}".format(color.to_string(**util.DEFAULT))
preview = orig.clone().set('alpha', 1)
preview_alpha = orig
Expand Down
4 changes: 2 additions & 2 deletions ch_tool_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ def preview(self, text):
else:
check_space = self.gamut_space
if not pcolor.in_gamut(check_space):
pcolor.fit(self.gamut_space, method=self.gamut_map)
pcolor.fit(self.gamut_space, **self.gamut_map)
message = '<br><em style="font-size: 0.9em;">* preview out of gamut</em>'
color_string = "<strong>Gamut Mapped</strong>: {}<br>".format(pcolor.to_string())
pcolor.convert(self.gamut_space, fit=self.gamut_map, in_place=True)
pcolor.convert(self.gamut_space, in_place=True).fit(**self.gamut_map)
color_string += "<strong>Color</strong>: {}".format(color.to_string(**util.DEFAULT))
preview = pcolor.clone().set('alpha', 1)
preview_alpha = pcolor
Expand Down
27 changes: 20 additions & 7 deletions color_helper.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@
"gamut_space": "srgb",

// Gamut mapping approach
// Supported methods are: `lch-chroma`, `oklch-chroma`, `oklch-raytrace`, and `clip` (default).
// Supported methods are: `lch-chroma`, `oklch-chroma`, `raytrace`, and `clip` (default).
// `lch-chroma` was the original default before this was configurable.
// If you need to set options within the gamut mapping, you can use a dictionary:
// `{"method": "raytrace", "pspace": "oklch"}`
"gamut_map": "clip",

//////////////////
Expand All @@ -135,22 +137,29 @@
// "ColorHelper.lib.coloraide.spaces.acescc.ACEScc",
// "ColorHelper.lib.coloraide.spaces.acescg.ACEScg",
// "ColorHelper.lib.coloraide.spaces.acescct.ACEScct",
// "ColorHelper.lib.coloraide.spaces.cam16_jmh.CAM16JMh",
// "ColorHelper.lib.coloraide.spaces.cam16.CAM16JMh",
// "ColorHelper.lib.coloraide.spaces.cam16_ucs.CAM16UCS",
// "ColorHelper.lib.coloraide.spaces.cam16_ucs.CAM16SCD",
// "ColorHelper.lib.coloraide.spaces.cam16_ucs.CAM16LCD",
// "ColorHelper.lib.coloraide.spaces.cam02.CAM02JMh",
// "ColorHelper.lib.coloraide.spaces.cam02_ucs.CAM02UCS",
// "ColorHelper.lib.coloraide.spaces.cam02_ucs.CAM02SCD",
// "ColorHelper.lib.coloraide.spaces.cam02_ucs.CAM02LCD",
// "ColorHelper.lib.coloraide.spaces.zcam.ZCAMJMh",
// "ColorHelper.lib.coloraide.spaces.hellwig.HellwigJMh",
// "ColorHelper.lib.coloraide.spaces.hellwig.HellwigHKJMh",
// "ColorHelper.lib.coloraide.spaces.cmy.CMY",
// "ColorHelper.lib.coloraide.spaces.cmyk.CMYK",
// "ColorHelper.lib.coloraide.spaces.din99o.DIN99o",
// "ColorHelper.lib.coloraide.spaces.hct.HCT",
// "ColorHelper.lib.coloraide.spaces.hpluv.HPLuv",
// "ColorHelper.lib.coloraide.spaces.hsi.HSI",
// "ColorHelper.lib.coloraide.spaces.hunter_lab.HunterLab",
// "ColorHelper.lib.coloraide.spaces.ictcp.ICtCp",
// "ColorHelper.lib.coloraide.spaces.ictcp.css.ICtCp",
// "ColorHelper.lib.coloraide.spaces.igtgpg.IgTgPg",
// "ColorHelper.lib.coloraide.spaces.ipt.IPT",
// "ColorHelper.lib.coloraide.spaces.jzazbz.Jzazbz",
// "ColorHelper.lib.coloraide.spaces.jzczhz.JzCzhz",
// "ColorHelper.lib.coloraide.spaces.jzazbz.css.Jzazbz",
// "ColorHelper.lib.coloraide.spaces.jzczhz.css.JzCzhz",
// "ColorHelper.lib.coloraide.spaces.lch99o.LCh99o",
// "ColorHelper.lib.coloraide.spaces.orgb.oRGB",
// "ColorHelper.lib.coloraide.spaces.prismatic.Prismatic",
Expand All @@ -160,6 +169,8 @@
// "ColorHelper.lib.coloraide.spaces.ryb.RYB",
// "ColorHelper.lib.coloraide.spaces.xyb.XYB",
// "ColorHelper.lib.coloraide.spaces.xyy.xyY",
// "ColorHelper.lib.coloraide.spaces.oklrab.Oklrab",
// "ColorHelper.lib.coloraide.spaces.oklrch.OkLrCh",
"ColorHelper.lib.coloraide.spaces.hsluv.HSLuv",
"ColorHelper.lib.coloraide.spaces.lchuv.LChuv",
"ColorHelper.lib.coloraide.spaces.luv.Luv",
Expand Down Expand Up @@ -220,7 +231,7 @@
"color_classes": {
"css-level-4": {
"filters": [
"srgb", "hsl", "hwb", "lch", "lab", "display-p3", "rec2020",
"srgb", "hsl", "hwb", "lch", "lab", "display-p3", "display-p3-linear", "rec2020",
"prophoto-rgb", "a98-rgb", "xyz-d65", "xyz-d50", "srgb-linear",
"oklab", "oklch"
],
Expand All @@ -231,6 +242,7 @@
{"space": "hwb", "format": {"comma": false}},
{"space": "a98-rgb", "format": {}},
{"space": "display-p3", "format": {}},
{"space": "display-p3-linear", "format": {}},
{"space": "prophoto-rgb", "format": {}},
{"space": "rec2020", "format": {}},
{"space": "srgb-linear", "format": {}},
Expand Down Expand Up @@ -422,7 +434,8 @@
"color_class": "css-level-4",
"scanning": [
"source.sass meta.property-value.css -comment -string -variable.declaration.sass",
"source.scss meta.property-value.css -comment -string -variable.declaration.sass"
"source.scss meta.property-value.css -comment -string -variable.declaration.sass",
"source.scss meta.declaration.value.scss constant.other.color.rgb-value.css"
]
},
{
Expand Down
4 changes: 3 additions & 1 deletion docs/src/markdown/settings/previews.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ else in the code.

```js
// Gamut mapping approach
// Supported methods are: `lch-chroma`, `oklch-chroma`, `oklch-raytrace`, and `clip` (default).
// Supported methods are: `lch-chroma`, `oklch-chroma`, `raytrace`, and `clip` (default).
// `lch-chroma` was the original default before this was configurable.
// If you need to set options within the gamut mapping, you can use a dictionary:
// `{"method": "raytrace", "pspace": "oklch"}`
"gamut_map": "clip",
```

Expand Down
16 changes: 8 additions & 8 deletions lib/coloraide/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __new__(
raise ValueError("All version parts except 'release' should be integers.")

if release not in REL_MAP:
raise ValueError("'{}' is not a valid release type.".format(release))
raise ValueError(f"'{release}' is not a valid release type.")

# Ensure valid pre-release (we do not allow implicit pre-releases).
if ".dev-candidate" < release < "final":
Expand Down Expand Up @@ -145,15 +145,15 @@ def _get_canonical(self) -> str:

# Assemble major, minor, micro version and append `pre`, `post`, or `dev` if needed..
if self.micro == 0 and self.major != 0:
ver = "{}.{}".format(self.major, self.minor)
ver = f"{self.major}.{self.minor}"
else:
ver = "{}.{}.{}".format(self.major, self.minor, self.micro)
ver = f"{self.major}.{self.minor}.{self.micro}"
if self._is_pre():
ver += '{}{}'.format(REL_MAP[self.release], self.pre)
ver += f'{REL_MAP[self.release]}{self.pre}'
if self._is_post():
ver += ".post{}".format(self.post)
ver += f".post{self.post}"
if self._is_dev():
ver += ".dev{}".format(self.dev)
ver += f".dev{self.dev}"

return ver

Expand All @@ -164,7 +164,7 @@ def parse_version(ver: str) -> Version:
m = RE_VER.match(ver)

if m is None:
raise ValueError("'{}' is not a valid version".format(ver))
raise ValueError(f"'{ver}' is not a valid version")

# Handle major, minor, micro
major = int(m.group('major'))
Expand Down Expand Up @@ -193,5 +193,5 @@ def parse_version(ver: str) -> Version:
return Version(major, minor, micro, release, pre, post, dev)


__version_info__ = Version(3, 3, 1, "final")
__version_info__ = Version(5, 1, 0, "final")
__version__ = __version_info__._get_canonical()
Loading