Skip to content

Commit eb8d089

Browse files
committed
Update to coloraide 5.1 and allow setting gamut map parameters in config
1 parent 0da18c3 commit eb8d089

File tree

137 files changed

+6861
-2976
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+6861
-2976
lines changed

ch_mixin.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def setup_gamut_style(self):
2323
ch_settings = sublime.load_settings('color_helper.sublime-settings')
2424
self.show_out_of_gamut_preview = ch_settings.get('show_out_of_gamut_preview', True)
2525
self.gamut_space = ch_settings.get('gamut_space', 'srgb')
26-
self.gamut_map = ch_settings.get('gamut_map', 'lch-chroma')
26+
gmap = ch_settings.get('gamut_map', {'method': 'minde-chroma', 'pspace': 'lch-d65'})
27+
if isinstance(gmap, str):
28+
gmap = {'method': gmap}
29+
self.gamut_map = gmap
2730
if self.gamut_space not in GAMUT_SPACES:
2831
self.gamut_space = 'srgb'
2932

@@ -35,7 +38,7 @@ def setup_image_border(self):
3538
if border_color is not None:
3639
try:
3740
border_color = self.base(border_color)
38-
border_color.fit(self.gamut_space, method=self.gamut_map)
41+
border_color.fit(self.gamut_space, **self.gamut_map)
3942
except Exception:
4043
border_color = None
4144

@@ -188,15 +191,15 @@ def get_preview(self, color):
188191
if not color.in_gamut(check_space):
189192
message = 'preview out of gamut'
190193
if self.show_out_of_gamut_preview:
191-
pcolor = color.convert(self.gamut_space, fit=self.gamut_map)
194+
pcolor = color.convert(self.gamut_space).fit(**gamut_map)
192195
preview1 = pcolor.clone().set('alpha', 1)
193196
preview2 = pcolor
194197
else:
195198
preview1 = self.out_of_gamut
196199
preview2 = self.out_of_gamut
197200
preview_border = self.out_of_gamut_border
198201
else:
199-
pcolor = color.convert(self.gamut_space, fit=self.gamut_map)
202+
pcolor = color.convert(self.gamut_space).fit(**self.gamut_map)
200203
preview1 = pcolor.clone().set('alpha', 1)
201204
preview2 = pcolor
202205

ch_panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def color_picker(self, color):
245245

246246
if self.os_color_picker:
247247
self.view.hide_popup()
248-
new_color = native_picker(self.base(color).convert("srgb", fit=self.gamut_map))
248+
new_color = native_picker(self.base(color).convert("srgb").fit(**self.gamut_map))
249249
if new_color is not None:
250250
sublime.set_timeout(
251251
lambda c=new_color.to_string(**util.COLOR_FULL_PREC): self.view.run_command(

ch_picker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def setup(self, color, mode, controls, on_done, on_cancel):
6969
self.setup_controls(controls)
7070
color.convert(self.mode, in_place=True)
7171
if not color.in_gamut():
72-
color.fit(method=self.gamut_map)
72+
color.fit(**self.gamut_map)
7373
else:
7474
color.clip()
7575
# Ensure hue is between 0 - 360.

ch_preview.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ def setup_gamut_options(self):
271271

272272
self.show_out_of_gamut_preview = ch_settings.get('show_out_of_gamut_preview', True)
273273
self.gamut_space = ch_settings.get('gamut_space', 'srgb')
274-
self.gamut_map = ch_settings.get('gamut_map', 'lch-chroma')
274+
gmap = ch_settings.get('gamut_map', {'method': 'minde-chroma', 'pspace': 'lch-d65'})
275+
if isinstance(gmap, str):
276+
gmap = {'method': gmap}
277+
self.gamut_map = gmap
275278
if self.gamut_space not in util.GAMUT_SPACES:
276279
self.gamut_space = 'srgb'
277280
self.out_of_gamut = self.base("transparent").convert(self.gamut_space)
@@ -437,7 +440,7 @@ def do_search(self, force=False):
437440
mdpopups.scope2style(self.view, self.view.scope_name(pt))['background']
438441
).convert("hsl")
439442
hsl['lightness'] = hsl['lightness'] + (0.3 if hsl.luminance() < 0.5 else -0.3)
440-
preview_border = hsl.convert(self.gamut_space, fit=self.gamut_map).set('alpha', 1)
443+
preview_border = hsl.convert(self.gamut_space).fit(**self.gamut_map).set('alpha', 1)
441444

442445
color = self.base(obj.color)
443446
title = ''
@@ -448,15 +451,15 @@ def do_search(self, force=False):
448451
if not color.in_gamut(check_space):
449452
title = ' title="Preview out of gamut"'
450453
if self.show_out_of_gamut_preview:
451-
pcolor = color.convert(self.gamut_space, fit=self.gamut_map)
454+
pcolor = color.convert(self.gamut_space).fit(**self.gamut_map)
452455
preview1 = pcolor.clone().set('alpha', 1)
453456
preview2 = pcolor
454457
else:
455458
preview1 = self.out_of_gamut
456459
preview2 = self.out_of_gamut
457460
preview_border = self.out_of_gamut_border
458461
else:
459-
pcolor = color.convert(self.gamut_space, fit=self.gamut_map)
462+
pcolor = color.convert(self.gamut_space).fit(**self.gamut_map)
460463
preview1 = pcolor.clone().set('alpha', 1)
461464
preview2 = pcolor
462465

ch_tool_blend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ def preview(self, text):
185185
else:
186186
check_space = self.gamut_space
187187
if not pcolor.in_gamut(check_space):
188-
pcolor.fit(self.gamut_space, method=self.gamut_map)
188+
pcolor.fit(self.gamut_space, **self.gamut_map)
189189
message = '<br><em style="font-size: 0.9em;">* preview out of gamut</em>'
190190
color_string = "<strong>Gamut Mapped</strong>: {}<br>".format(pcolor.to_string())
191-
pcolor.convert(self.gamut_space, fit=self.gamut_map, in_place=True)
191+
pcolor.convert(self.gamut_space, in_place=True).fit(**self.gamut_map)
192192
color_string += "<strong>Color</strong>: {}".format(color.to_string(**util.DEFAULT))
193193
preview = pcolor.clone().set('alpha', 1)
194194
preview_alpha = pcolor

ch_tool_colormod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def preview(self, text):
106106
check_space = self.gamut_space
107107
if not pcolor.in_gamut(check_space):
108108
message = '<br><em style="font-size: 0.9em;">* preview out of gamut</em>'
109-
pcolor.convert(self.gamut_space, fit=self.gamut_map, in_place=True)
109+
pcolor.convert(self.gamut_space, in_place=True).fit(**self.gamut_map)
110110
preview = pcolor.clone().set('alpha', 1)
111111
preview_alpha = pcolor
112112
preview_border = self.default_border

ch_tool_contrast.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ def evaluate(base, string, gamut_map):
114114

115115
# Package up the color, or the two reference colors along with the mixed.
116116
if first:
117-
colors.append(first.fit('srgb', method=gamut_map))
117+
colors.append(first.fit('srgb', **gamut_map))
118118
if second:
119119
if second[-1] < 1.0:
120120
second[-1] = 1.0
121-
colors.append(second.fit('srgb', method=gamut_map))
121+
colors.append(second.fit('srgb', **gamut_map))
122122
if ratio:
123123
if first[-1] < 1.0:
124124
first = first.compose(second, space="srgb", out_space=first.space())

ch_tool_diff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ def preview(self, text):
186186
else:
187187
check_space = self.gamut_space
188188
if not orig.in_gamut(check_space):
189-
orig.fit(self.gamut_space, method=self.gamut_map)
189+
orig.fit(self.gamut_space, **self.gamut_map)
190190
message = '<br><em style="font-size: 0.9em;">* preview out of gamut</em>'
191191
color_string = "<strong>Gamut Mapped</strong>: {}<br>".format(orig.to_string())
192-
orig.convert(self.gamut_space, fit=self.gamut_map, in_place=True)
192+
orig.convert(self.gamut_space, in_place=True).fit(**self.gamut_map)
193193
color_string += "<strong>Color</strong>: {}".format(color.to_string(**util.DEFAULT))
194194
preview = orig.clone().set('alpha', 1)
195195
preview_alpha = orig

ch_tool_edit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ def preview(self, text):
222222
else:
223223
check_space = self.gamut_space
224224
if not pcolor.in_gamut(check_space):
225-
pcolor.fit(self.gamut_space, method=self.gamut_map)
225+
pcolor.fit(self.gamut_space, **self.gamut_map)
226226
message = '<br><em style="font-size: 0.9em;">* preview out of gamut</em>'
227227
color_string = "<strong>Gamut Mapped</strong>: {}<br>".format(pcolor.to_string())
228-
pcolor.convert(self.gamut_space, fit=self.gamut_map, in_place=True)
228+
pcolor.convert(self.gamut_space, in_place=True).fit(**self.gamut_map)
229229
color_string += "<strong>Color</strong>: {}".format(color.to_string(**util.DEFAULT))
230230
preview = pcolor.clone().set('alpha', 1)
231231
preview_alpha = pcolor

color_helper.sublime-settings

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@
117117
"gamut_space": "srgb",
118118

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

124126
//////////////////
@@ -135,22 +137,29 @@
135137
// "ColorHelper.lib.coloraide.spaces.acescc.ACEScc",
136138
// "ColorHelper.lib.coloraide.spaces.acescg.ACEScg",
137139
// "ColorHelper.lib.coloraide.spaces.acescct.ACEScct",
138-
// "ColorHelper.lib.coloraide.spaces.cam16_jmh.CAM16JMh",
140+
// "ColorHelper.lib.coloraide.spaces.cam16.CAM16JMh",
139141
// "ColorHelper.lib.coloraide.spaces.cam16_ucs.CAM16UCS",
140142
// "ColorHelper.lib.coloraide.spaces.cam16_ucs.CAM16SCD",
141143
// "ColorHelper.lib.coloraide.spaces.cam16_ucs.CAM16LCD",
144+
// "ColorHelper.lib.coloraide.spaces.cam02.CAM02JMh",
145+
// "ColorHelper.lib.coloraide.spaces.cam02_ucs.CAM02UCS",
146+
// "ColorHelper.lib.coloraide.spaces.cam02_ucs.CAM02SCD",
147+
// "ColorHelper.lib.coloraide.spaces.cam02_ucs.CAM02LCD",
148+
// "ColorHelper.lib.coloraide.spaces.zcam.ZCAMJMh",
149+
// "ColorHelper.lib.coloraide.spaces.hellwig.HellwigJMh",
150+
// "ColorHelper.lib.coloraide.spaces.hellwig.HellwigHKJMh",
142151
// "ColorHelper.lib.coloraide.spaces.cmy.CMY",
143152
// "ColorHelper.lib.coloraide.spaces.cmyk.CMYK",
144153
// "ColorHelper.lib.coloraide.spaces.din99o.DIN99o",
145154
// "ColorHelper.lib.coloraide.spaces.hct.HCT",
146155
// "ColorHelper.lib.coloraide.spaces.hpluv.HPLuv",
147156
// "ColorHelper.lib.coloraide.spaces.hsi.HSI",
148157
// "ColorHelper.lib.coloraide.spaces.hunter_lab.HunterLab",
149-
// "ColorHelper.lib.coloraide.spaces.ictcp.ICtCp",
158+
// "ColorHelper.lib.coloraide.spaces.ictcp.css.ICtCp",
150159
// "ColorHelper.lib.coloraide.spaces.igtgpg.IgTgPg",
151160
// "ColorHelper.lib.coloraide.spaces.ipt.IPT",
152-
// "ColorHelper.lib.coloraide.spaces.jzazbz.Jzazbz",
153-
// "ColorHelper.lib.coloraide.spaces.jzczhz.JzCzhz",
161+
// "ColorHelper.lib.coloraide.spaces.jzazbz.css.Jzazbz",
162+
// "ColorHelper.lib.coloraide.spaces.jzczhz.css.JzCzhz",
154163
// "ColorHelper.lib.coloraide.spaces.lch99o.LCh99o",
155164
// "ColorHelper.lib.coloraide.spaces.orgb.oRGB",
156165
// "ColorHelper.lib.coloraide.spaces.prismatic.Prismatic",
@@ -160,6 +169,8 @@
160169
// "ColorHelper.lib.coloraide.spaces.ryb.RYB",
161170
// "ColorHelper.lib.coloraide.spaces.xyb.XYB",
162171
// "ColorHelper.lib.coloraide.spaces.xyy.xyY",
172+
// "ColorHelper.lib.coloraide.spaces.oklrab.Oklrab",
173+
// "ColorHelper.lib.coloraide.spaces.oklrch.OkLrCh",
163174
"ColorHelper.lib.coloraide.spaces.hsluv.HSLuv",
164175
"ColorHelper.lib.coloraide.spaces.lchuv.LChuv",
165176
"ColorHelper.lib.coloraide.spaces.luv.Luv",
@@ -220,7 +231,7 @@
220231
"color_classes": {
221232
"css-level-4": {
222233
"filters": [
223-
"srgb", "hsl", "hwb", "lch", "lab", "display-p3", "rec2020",
234+
"srgb", "hsl", "hwb", "lch", "lab", "display-p3", "display-p3-linear", "rec2020",
224235
"prophoto-rgb", "a98-rgb", "xyz-d65", "xyz-d50", "srgb-linear",
225236
"oklab", "oklch"
226237
],
@@ -231,6 +242,7 @@
231242
{"space": "hwb", "format": {"comma": false}},
232243
{"space": "a98-rgb", "format": {}},
233244
{"space": "display-p3", "format": {}},
245+
{"space": "display-p3-linear", "format": {}},
234246
{"space": "prophoto-rgb", "format": {}},
235247
{"space": "rec2020", "format": {}},
236248
{"space": "srgb-linear", "format": {}},
@@ -422,7 +434,8 @@
422434
"color_class": "css-level-4",
423435
"scanning": [
424436
"source.sass meta.property-value.css -comment -string -variable.declaration.sass",
425-
"source.scss meta.property-value.css -comment -string -variable.declaration.sass"
437+
"source.scss meta.property-value.css -comment -string -variable.declaration.sass",
438+
"source.scss meta.declaration.value.scss constant.other.color.rgb-value.css"
426439
]
427440
},
428441
{

0 commit comments

Comments
 (0)