HLS-based color correction
This commit is contained in:
parent
15708ceb9b
commit
d0bad861ae
18
wibe.py
18
wibe.py
@ -7,6 +7,7 @@ import json
|
|||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
import colorsys
|
||||||
|
|
||||||
wledPalettes = {'colorsOnly': 5, 'colorGradient': 4, '2Colors': 3}
|
wledPalettes = {'colorsOnly': 5, 'colorGradient': 4, '2Colors': 3}
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ def main(token, ip='192.168.3.42', bri=51):
|
|||||||
#pprint(palette)
|
#pprint(palette)
|
||||||
speed = min(int((feat['tempo']/30*feat['energy'])**2.0)*10,255)
|
speed = min(int((feat['tempo']/30*feat['energy'])**2.0)*10,255)
|
||||||
power = min(8 + int(((feat['energy']*10)**2.0)*0.5),255)
|
power = min(8 + int(((feat['energy']*10)**2.0)*0.5),255)
|
||||||
pprint(requests.post(url, json={"seg": [{"col": palette, "pal": wledPalettes['colorsOnly'], 'sx': speed, 'ix': power}]}).json())
|
pprint(requests.post(url, json={"seg": [{"col": palette, "pal": wledPalettes['colorGradient'], 'sx': speed, 'ix': power}]}).json())
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
@ -39,14 +40,25 @@ def getPalette(curTrack,numColors):
|
|||||||
imgStream = requests.get(curTrack["album"]["images"][-1]["url"]).content #Get the lowest res cover
|
imgStream = requests.get(curTrack["album"]["images"][-1]["url"]).content #Get the lowest res cover
|
||||||
imgFile = io.BytesIO(imgStream)
|
imgFile = io.BytesIO(imgStream)
|
||||||
print("[i] Generating palette")
|
print("[i] Generating palette")
|
||||||
palette = [normalizeColor([col.rgb[c] for c in range(3)]+[0]) for col in sorted(colorgram.extract(imgFile, numColors), key=lambda c: c.proportion + 0*c.hsl.h)]
|
palette = [normalizeColor([col.rgb[c] for c in range(3)]+[0]) for col in sorted(colorgram.extract(imgFile, numColors), key=lambda c: c.proportion*0 + c.hsl.h)]
|
||||||
return palette
|
return palette
|
||||||
|
|
||||||
def normalizeColor(rgbw):
|
def normalizeColorByLength(rgbw):
|
||||||
s = max(max(rgbw),1)
|
s = max(max(rgbw),1)
|
||||||
fac = (1 + 255/s)/2
|
fac = (1 + 255/s)/2
|
||||||
return [min(int(c*fac),255) for c in rgbw]
|
return [min(int(c*fac),255) for c in rgbw]
|
||||||
|
|
||||||
|
def normalizeColorByHue(rgbw, strength=1.0):
|
||||||
|
x = strength
|
||||||
|
y = 1-x
|
||||||
|
r, g, b, w = rgbw
|
||||||
|
h, l, s = colorsys.rgb_to_hls(r/255, g/255, b/255)
|
||||||
|
r, g, b = colorsys.hls_to_rgb(h, 0.5*x+l*y, 1*x+s*y)
|
||||||
|
return [r*255, g*255, b*255]
|
||||||
|
|
||||||
|
def normalizeColor(rgbw):
|
||||||
|
return normalizeColorByHue(rgbw, strength=0.5)
|
||||||
|
|
||||||
def genSpoToken(username, client_id, client_secret):
|
def genSpoToken(username, client_id, client_secret):
|
||||||
return spoUtil.prompt_for_user_token(username,"user-read-currently-playing",client_id=client_id,client_secret=client_secret,redirect_uri='http://localhost/')
|
return spoUtil.prompt_for_user_token(username,"user-read-currently-playing",client_id=client_id,client_secret=client_secret,redirect_uri='http://localhost/')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user