Skip to content

Commit

Permalink
added non-linear brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
MaWalla committed Feb 17, 2022
1 parent 8240061 commit c0ea074
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions devices/device.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import colorsys

import numpy as np
from math import sqrt

__all__ = [
'Device',
Expand Down Expand Up @@ -134,6 +133,7 @@ def __init__(self, device, name, *args, **kwargs):
self.enabled = device.get('enabled')

self.brightness = device.get('brightness', 1)
self.non_linear_brightness = device.get('non_linear_brightness', True)
self.flip = device.get('flip')
self.leds = device.get('leds', 1)
self.saturation = device.get('saturation', 1)
Expand All @@ -155,12 +155,16 @@ def get_color_temperature(self, value):

return self.color_temperature_map.get(key, default)

def apply_saturation(self, data):
def apply_enhancements(self, data):
"""
adjusts the saturation of input data
"""

new_values = np.array([colorsys.rgb_to_hsv(*value) for value in data]) * [1, self.saturation, 1]
if self.non_linear_brightness:
new_values = np.array([colorsys.rgb_to_hsv(*value) for value in data]) ** [1, 1, 2]
new_values = new_values * [1, self.saturation, 0.00390625]
else:
new_values = np.array([colorsys.rgb_to_hsv(*value) for value in data]) * [1, self.saturation, 1]

return np.array([colorsys.hsv_to_rgb(*value) for value in new_values]).clip(0, 255)

Expand Down
2 changes: 1 addition & 1 deletion fxmodes/PulseViz
Submodule PulseViz updated 1 files
+28 −44 intensity.py
2 changes: 1 addition & 1 deletion immersivefx.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def device_loop(self, device_name):

data = np.array(self.device_processing(device, device_instance))

data = (device_instance.apply_saturation(
data = (device_instance.apply_enhancements(
data * device_instance.brightness * device_instance.color_temperature
)).astype(int)

Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@
# the main thread must stay alive and should do as little as possible from this point on
# in the future we may put some control mechanisms for the FXMode here, but
# heavy lifting is done by the data thread and sending by device threads
sleep(5)
sleep(0.5)

0 comments on commit c0ea074

Please sign in to comment.