Skip to content

Commit

Permalink
Merge pull request #2055 from diogotr7/feature/ambilight-average-sliders
Browse files Browse the repository at this point in the history
made color adjust sliders apply to the average color
  • Loading branch information
diogotr7 authored May 31, 2020
2 parents 2dcaf76 + 26f3fb2 commit 0de4418
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,18 @@ public override EffectLayer Render(IGameState gamestate)
break;

case AmbilightType.AverageColor:
ambilight_layer.Set(Properties.Sequence, BitmapUtils.GetAverageColor(screen));
var average = BitmapUtils.GetAverageColor(screen);

if (Properties.BrightenImage)
average = ColorUtils.ChangeBrightness(average, Properties.BrightnessChange);

if (Properties.SaturateImage)
average = ColorUtils.ChangeSaturation(average, Properties.SaturationChange);

if (Properties.HueShiftImage)
average = ColorUtils.ChangeHue(average, Properties.HueShiftAngle);

ambilight_layer.Set(Properties.Sequence, average);
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@
<RowDefinition/>
</Grid.RowDefinitions>
<CheckBox IsChecked="{Binding Properties._BrightenImage}" x:Name="EnableBrightnessMod" Content="Brightness:" Grid.Row="0" Grid.Column="0"/>
<Slider Value="{Binding Properties._BrightnessChange}" x:Name="BrightnessSlider" IsEnabled="{Binding ElementName=EnableBrightnessMod, Path=IsChecked}" Minimum="-0.5" Maximum="0.5" TickFrequency="0.1" Grid.Row="0" Grid.Column="1"/>
<Slider Value="{Binding Properties._BrightnessChange}" x:Name="BrightnessSlider" IsEnabled="{Binding ElementName=EnableBrightnessMod, Path=IsChecked}" Minimum="0" Maximum="3" TickFrequency="0.1" Grid.Row="0" Grid.Column="1"/>
<Label Content="{Binding ElementName=BrightnessSlider, Path=Value}" ContentStringFormat="N1" Grid.Row="0" Grid.Column="2" />

<CheckBox IsChecked="{Binding Properties._SaturateImage}" x:Name="EnableSaturationMod" Content="Saturation:" Grid.Row="1" Grid.Column="0"/>
<Slider Value="{Binding Properties._SaturationChange}" x:Name="SaturationSlider" IsEnabled="{Binding ElementName=EnableSaturationMod, Path=IsChecked}" Minimum="0" Maximum="4" TickFrequency="0.1" Grid.Row="1" Grid.Column="1"/>
<Slider Value="{Binding Properties._SaturationChange}" x:Name="SaturationSlider" IsEnabled="{Binding ElementName=EnableSaturationMod, Path=IsChecked}" Minimum="0" Maximum="3" TickFrequency="0.1" Grid.Row="1" Grid.Column="1"/>
<Label Content="{Binding ElementName=SaturationSlider, Path=Value}" ContentStringFormat="N1" Grid.Row="1" Grid.Column="2"/>

<CheckBox IsChecked="{Binding Properties._HueShiftImage}" x:Name="EnableHueMod" Content="Hue:" Grid.Row="2" Grid.Column="0"/>
Expand Down
9 changes: 8 additions & 1 deletion Project-Aurora/Project-Aurora/Settings/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,14 @@ public void ProcessManager(object manager)
{
foreach (var plugin in this.Plugins)
{
plugin.Value.ProcessManager(manager);
try
{
plugin.Value.ProcessManager(manager);
}
catch(Exception e)
{
Global.logger.Error($"Failed to load plugin {plugin.Key}: {e.Message}");
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions Project-Aurora/Project-Aurora/Utils/BitmapUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,21 @@ public static Color GetAverageColor(Image screenshot)
/// Returns a color matrix that when applied to an image alters its brightness.
/// Taken from https://docs.rainmeter.net/tips/colormatrix-guide/
/// </summary>
/// <param name="b">Brightness (-1..1)</param>
/// <param name="b">Brightness (0..4)</param>
/// <returns></returns>
public static float[][] GetBrightnessColorMatrix(float b) => new float[][] {
new float[] {1, 0, 0, 0, 0},//red
new float[] {0, 1, 0, 0, 0},//green
new float[] {0, 0, 1, 0, 0},//blue
new float[] {b, 0, 0, 0, 0},//red
new float[] {0, b, 0, 0, 0},//green
new float[] {0, 0, b, 0, 0},//blue
new float[] {0, 0, 0, 1, 0},//alpha
new float[] {b, b, b, 0, 1}
new float[] {0, 0, 0, 0, 1}
};

/// <summary>
/// Returns a color matrix that when applied to an image alters its saturation.
/// Taken from https://docs.rainmeter.net/tips/colormatrix-guide/
/// </summary>
/// <param name="s">Saturation (0..~5)</param>
/// <param name="s">Saturation (0..4)</param>
/// <returns></returns>
public static float[][] GetSaturationColorMatrix(float s)
{
Expand Down

0 comments on commit 0de4418

Please sign in to comment.