aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/spectral.py19
-rw-r--r--autoload/spectral.vim21
2 files changed, 39 insertions, 1 deletions
diff --git a/autoload/spectral.py b/autoload/spectral.py
index f7903aa..9afcf6b 100644
--- a/autoload/spectral.py
+++ b/autoload/spectral.py
@@ -3,7 +3,7 @@ import os
import vim
import colormath
import colormath.color_diff
-from colormath.color_objects import LabColor, sRGBColor
+from colormath.color_objects import LabColor, sRGBColor, HSVColor
from colormath.color_conversions import convert_color
import sys
import math
@@ -423,6 +423,23 @@ def spectral_start(outfile):
spectral_ctx = Vivid(outfile)
spectral_ctx.start()
+def set_saturation(color, amnt):
+ if isinstance(color, str):
+ color = sRGBColor.new_from_rgb_hex(color)
+
+ print("Color " + str(color) + " " + get_rgb_hex(color))
+ color_hsv = convert_color(color, HSVColor)
+ (h, s, v) = color_hsv.get_value_tuple()
+
+ print("HSVPre " + str(color_hsv))
+ color_hsv = HSVColor(h, amnt, v)
+ print("HSVPost " + str(color_hsv))
+ return convert_color(color_hsv, sRGBColor)
+
+def spectral_set_saturation(color, amnt):
+ c = set_saturation(color, amnt)
+ vim.command('let g:return="%s"' % get_rgb_hex(c))
+
def lighter(color, amt):
if isinstance(color, str):
diff --git a/autoload/spectral.vim b/autoload/spectral.vim
index e2b6376..fe70131 100644
--- a/autoload/spectral.vim
+++ b/autoload/spectral.vim
@@ -50,6 +50,27 @@ function! spectral#desaturate(color, amount)
return spectral#toColor(nr, ng, nb)
endfunction
+function! spectral#set_saturation(color, amount)
+ let saved = 0
+ if exists('g:return')
+ let old_return = g:return
+ let saved = 1
+ endif
+
+ call s:loadPythonScript()
+ exec printf('python3 spectral_set_saturation("%s", %s)', a:color, a:amount)
+
+ let ret = g:return
+
+ if saved
+ let g:return = old_return
+ else
+ unlet g:return
+ endif
+
+ return ret
+endfunction
+
function! spectral#parseColor(color) abort
if type(a:color) == v:t_list