mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Resharper cleanup layer modules
This commit is contained in:
parent
33094731aa
commit
188e1ddfe4
@ -9,34 +9,40 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator
|
||||
#region Methods
|
||||
|
||||
public byte[] GetAmbience(byte[] pixels, int sourceWidth, int sourceHeight,
|
||||
int targetWidth, int targetHeight,
|
||||
AmbientLightPropertiesModel settings)
|
||||
int targetWidth, int targetHeight,
|
||||
AmbientLightPropertiesModel settings)
|
||||
{
|
||||
AvgColor[] colors = new AvgColor[targetWidth];
|
||||
for (int i = 0; i < colors.Length; i++)
|
||||
var colors = new AvgColor[targetWidth];
|
||||
for (var i = 0; i < colors.Length; i++)
|
||||
colors[i] = new AvgColor();
|
||||
|
||||
int offsetLeft = settings.OffsetLeft + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Left)
|
||||
? pixels.DetectBlackBarLeft(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom)
|
||||
var offsetLeft = settings.OffsetLeft + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Left)
|
||||
? pixels.DetectBlackBarLeft(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight,
|
||||
settings.OffsetTop, settings.OffsetBottom)
|
||||
: 0);
|
||||
int offsetRight = settings.OffsetRight + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Right)
|
||||
? pixels.DetectBlackBarRight(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom)
|
||||
: 0);
|
||||
int offsetTop = settings.OffsetTop + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Top)
|
||||
? pixels.DetectBlackBarTop(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom)
|
||||
: 0);
|
||||
int offsetBottom = settings.OffsetBottom + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Bottom)
|
||||
? pixels.DetectBlackBarBottom(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom)
|
||||
var offsetRight = settings.OffsetRight +
|
||||
(settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Right)
|
||||
? pixels.DetectBlackBarRight(sourceWidth, sourceHeight, settings.OffsetLeft,
|
||||
settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom)
|
||||
: 0);
|
||||
var offsetTop = settings.OffsetTop + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Top)
|
||||
? pixels.DetectBlackBarTop(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight,
|
||||
settings.OffsetTop, settings.OffsetBottom)
|
||||
: 0);
|
||||
var offsetBottom = settings.OffsetBottom +
|
||||
(settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Bottom)
|
||||
? pixels.DetectBlackBarBottom(sourceWidth, sourceHeight, settings.OffsetLeft,
|
||||
settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom)
|
||||
: 0);
|
||||
|
||||
int effectiveSourceWidth = sourceWidth - offsetLeft - offsetRight;
|
||||
int effectiveSourceHeight = sourceHeight - offsetTop - offsetBottom;
|
||||
var effectiveSourceWidth = sourceWidth - offsetLeft - offsetRight;
|
||||
var effectiveSourceHeight = sourceHeight - offsetTop - offsetBottom;
|
||||
|
||||
int relevantSourceHeight = (int)Math.Round(effectiveSourceHeight * (settings.MirroredAmount / 100.0));
|
||||
int relevantOffsetTop = sourceHeight - offsetBottom - relevantSourceHeight;
|
||||
var relevantSourceHeight = (int) Math.Round(effectiveSourceHeight*(settings.MirroredAmount/100.0));
|
||||
var relevantOffsetTop = sourceHeight - offsetBottom - relevantSourceHeight;
|
||||
|
||||
double widthPixels = effectiveSourceWidth / (double)targetWidth;
|
||||
double heightPixels = relevantSourceHeight / (double)targetHeight;
|
||||
var widthPixels = effectiveSourceWidth/(double) targetWidth;
|
||||
var heightPixels = relevantSourceHeight/(double) targetHeight;
|
||||
|
||||
if (widthPixels <= 0 || heightPixels <= 0 || (relevantSourceHeight + relevantOffsetTop > sourceHeight) ||
|
||||
effectiveSourceWidth > sourceWidth)
|
||||
@ -45,13 +51,13 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator
|
||||
return colors.ToBGRArray();
|
||||
}
|
||||
|
||||
int increment = Math.Max(1, Math.Min(20, settings.Downsampling));
|
||||
for (int y = 0; y < relevantSourceHeight; y += increment)
|
||||
var increment = Math.Max(1, Math.Min(20, settings.Downsampling));
|
||||
for (var y = 0; y < relevantSourceHeight; y += increment)
|
||||
{
|
||||
int targetWidthIndex = 0;
|
||||
double widthCounter = widthPixels;
|
||||
var targetWidthIndex = 0;
|
||||
var widthCounter = widthPixels;
|
||||
|
||||
for (int x = 0; x < effectiveSourceWidth; x += increment)
|
||||
for (var x = 0; x < effectiveSourceWidth; x += increment)
|
||||
{
|
||||
if (x >= widthCounter)
|
||||
{
|
||||
@ -59,10 +65,10 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator
|
||||
targetWidthIndex++;
|
||||
}
|
||||
|
||||
int colorsOffset = targetWidthIndex;
|
||||
int sourceOffset = ((((relevantOffsetTop + y) * sourceWidth) + offsetLeft + x) * 4);
|
||||
var colorsOffset = targetWidthIndex;
|
||||
var sourceOffset = ((relevantOffsetTop + y)*sourceWidth + offsetLeft + x)*4;
|
||||
|
||||
AvgColor color = colors[colorsOffset];
|
||||
var color = colors[colorsOffset];
|
||||
color.AddB(pixels[sourceOffset]);
|
||||
color.AddG(pixels[sourceOffset + 1]);
|
||||
color.AddR(pixels[sourceOffset + 2]);
|
||||
@ -76,4 +82,4 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,43 +9,50 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator
|
||||
#region Methods
|
||||
|
||||
public byte[] GetAmbience(byte[] pixels, int sourceWidth, int sourceHeight,
|
||||
int targetWidth, int targetHeight,
|
||||
AmbientLightPropertiesModel settings)
|
||||
int targetWidth, int targetHeight,
|
||||
AmbientLightPropertiesModel settings)
|
||||
{
|
||||
AvgColor[] colors = new AvgColor[targetWidth * targetHeight];
|
||||
for (int i = 0; i < colors.Length; i++)
|
||||
var colors = new AvgColor[targetWidth*targetHeight];
|
||||
for (var i = 0; i < colors.Length; i++)
|
||||
colors[i] = new AvgColor();
|
||||
|
||||
int offsetLeft = settings.OffsetLeft + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Left)
|
||||
? pixels.DetectBlackBarLeft(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom)
|
||||
var offsetLeft = settings.OffsetLeft + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Left)
|
||||
? pixels.DetectBlackBarLeft(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight,
|
||||
settings.OffsetTop, settings.OffsetBottom)
|
||||
: 0);
|
||||
int offsetRight = settings.OffsetRight + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Right)
|
||||
? pixels.DetectBlackBarRight(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom)
|
||||
: 0);
|
||||
int offsetTop = settings.OffsetTop + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Top)
|
||||
? pixels.DetectBlackBarTop(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom)
|
||||
: 0);
|
||||
int offsetBottom = settings.OffsetBottom + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Bottom)
|
||||
? pixels.DetectBlackBarBottom(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom)
|
||||
var offsetRight = settings.OffsetRight +
|
||||
(settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Right)
|
||||
? pixels.DetectBlackBarRight(sourceWidth, sourceHeight, settings.OffsetLeft,
|
||||
settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom)
|
||||
: 0);
|
||||
var offsetTop = settings.OffsetTop + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Top)
|
||||
? pixels.DetectBlackBarTop(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight,
|
||||
settings.OffsetTop, settings.OffsetBottom)
|
||||
: 0);
|
||||
var offsetBottom = settings.OffsetBottom +
|
||||
(settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Bottom)
|
||||
? pixels.DetectBlackBarBottom(sourceWidth, sourceHeight, settings.OffsetLeft,
|
||||
settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom)
|
||||
: 0);
|
||||
|
||||
int effectiveSourceWidth = sourceWidth - offsetLeft - offsetRight;
|
||||
int effectiveSourceHeight = sourceHeight - offsetTop - offsetBottom;
|
||||
var effectiveSourceWidth = sourceWidth - offsetLeft - offsetRight;
|
||||
var effectiveSourceHeight = sourceHeight - offsetTop - offsetBottom;
|
||||
|
||||
int relevantSourceHeight = (int)Math.Round(effectiveSourceHeight * (settings.MirroredAmount / 100.0));
|
||||
int relevantOffsetTop = sourceHeight - offsetBottom - relevantSourceHeight;
|
||||
var relevantSourceHeight = (int) Math.Round(effectiveSourceHeight*(settings.MirroredAmount/100.0));
|
||||
var relevantOffsetTop = sourceHeight - offsetBottom - relevantSourceHeight;
|
||||
|
||||
double widthPixels = effectiveSourceWidth / (double)targetWidth;
|
||||
double heightPixels = relevantSourceHeight / (double)targetHeight;
|
||||
var widthPixels = effectiveSourceWidth/(double) targetWidth;
|
||||
var heightPixels = relevantSourceHeight/(double) targetHeight;
|
||||
|
||||
if (widthPixels <= 0 || heightPixels <= 0 || (relevantSourceHeight + relevantOffsetTop > sourceHeight) || effectiveSourceWidth > sourceWidth)
|
||||
if (widthPixels <= 0 || heightPixels <= 0 || (relevantSourceHeight + relevantOffsetTop > sourceHeight) ||
|
||||
effectiveSourceWidth > sourceWidth)
|
||||
return colors.ToBGRArray();
|
||||
|
||||
int targetHeightIndex = 0;
|
||||
double heightCounter = heightPixels;
|
||||
var targetHeightIndex = 0;
|
||||
var heightCounter = heightPixels;
|
||||
|
||||
int increment = Math.Max(1, Math.Min(20, settings.Downsampling));
|
||||
for (int y = 0; y < relevantSourceHeight; y += increment)
|
||||
var increment = Math.Max(1, Math.Min(20, settings.Downsampling));
|
||||
for (var y = 0; y < relevantSourceHeight; y += increment)
|
||||
{
|
||||
if (y >= heightCounter)
|
||||
{
|
||||
@ -53,10 +60,10 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator
|
||||
targetHeightIndex++;
|
||||
}
|
||||
|
||||
int targetWidthIndex = 0;
|
||||
double widthCounter = widthPixels;
|
||||
var targetWidthIndex = 0;
|
||||
var widthCounter = widthPixels;
|
||||
|
||||
for (int x = 0; x < effectiveSourceWidth; x += increment)
|
||||
for (var x = 0; x < effectiveSourceWidth; x += increment)
|
||||
{
|
||||
if (x >= widthCounter)
|
||||
{
|
||||
@ -64,10 +71,10 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator
|
||||
targetWidthIndex++;
|
||||
}
|
||||
|
||||
int colorsOffset = (targetHeightIndex * targetWidth) + targetWidthIndex;
|
||||
int sourceOffset = ((((relevantOffsetTop + y) * sourceWidth) + offsetLeft + x) * 4);
|
||||
var colorsOffset = targetHeightIndex*targetWidth + targetWidthIndex;
|
||||
var sourceOffset = ((relevantOffsetTop + y)*sourceWidth + offsetLeft + x)*4;
|
||||
|
||||
AvgColor color = colors[colorsOffset];
|
||||
var color = colors[colorsOffset];
|
||||
color.AddB(pixels[sourceOffset]);
|
||||
color.AddG(pixels[sourceOffset + 1]);
|
||||
color.AddR(pixels[sourceOffset + 2]);
|
||||
@ -80,4 +87,4 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,16 +4,16 @@
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private int _rCount = 0;
|
||||
private int _r = 0;
|
||||
private int _gCount = 0;
|
||||
private int _g = 0;
|
||||
private int _bCount = 0;
|
||||
private int _b = 0;
|
||||
private int _rCount;
|
||||
private int _r;
|
||||
private int _gCount;
|
||||
private int _g;
|
||||
private int _bCount;
|
||||
private int _b;
|
||||
|
||||
public byte R => (byte)(_rCount > 0 ? (_r / _rCount) : 0);
|
||||
public byte G => (byte)(_gCount > 0 ? (_g / _gCount) : 0);
|
||||
public byte B => (byte)(_bCount > 0 ? (_b / _bCount) : 0);
|
||||
public byte R => (byte) (_rCount > 0 ? _r/_rCount : 0);
|
||||
public byte G => (byte) (_gCount > 0 ? _g/_gCount : 0);
|
||||
public byte B => (byte) (_bCount > 0 ? _b/_bCount : 0);
|
||||
|
||||
#endregion
|
||||
|
||||
@ -39,4 +39,4 @@
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
{
|
||||
public interface IAmbienceCreator
|
||||
{
|
||||
byte[] GetAmbience(byte[] pixels, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, AmbientLightPropertiesModel settings);
|
||||
byte[] GetAmbience(byte[] pixels, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight,
|
||||
AmbientLightPropertiesModel settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7,6 +7,16 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight
|
||||
{
|
||||
public class AmbientLightPropertiesModel : LayerPropertiesModel
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
public AmbientLightPropertiesModel(LayerPropertiesModel properties)
|
||||
: base(properties)
|
||||
{
|
||||
Brush = new SolidColorBrush(Color.FromRgb(0, 0, 0));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
//HACK DarthAffe 30.10.2016: The 'normal' Brush-Property destoys the profile since Drawing-Brushes cannot be deserialized.
|
||||
@ -28,15 +38,5 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight
|
||||
public FlipMode FlipMode { get; set; } = FlipMode.Vertical;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public AmbientLightPropertiesModel(LayerPropertiesModel properties)
|
||||
: base(properties)
|
||||
{
|
||||
Brush = new SolidColorBrush(Color.FromRgb(0, 0, 0));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,14 +1,14 @@
|
||||
<UserControl x:Class="Artemis.Profiles.Layers.Types.AmbientLight.AmbientLightPropertiesView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:converters="clr-namespace:Artemis.Utilities.Converters"
|
||||
xmlns:system="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:model="clr-namespace:Artemis.Profiles.Layers.Types.AmbientLight.Model"
|
||||
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
|
||||
xmlns:helper="clr-namespace:Artemis.Profiles.Layers.Types.AmbientLight.Helper"
|
||||
mc:Ignorable="d"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="600" d:DesignWidth="500">
|
||||
|
||||
<UserControl.Resources>
|
||||
@ -51,7 +51,8 @@
|
||||
<!-- AmbienceCreatorType -->
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Margin="10,13,10,10" FontSize="13.333" Text="Ambilight-Mode:"
|
||||
VerticalAlignment="Top" Height="18" />
|
||||
<ComboBox Grid.Row="0" Grid.Column="1" ItemsSource="{Binding Source={StaticResource AmbienceCreatorTypeValues}}"
|
||||
<ComboBox Grid.Row="0" Grid.Column="1"
|
||||
ItemsSource="{Binding Source={StaticResource AmbienceCreatorTypeValues}}"
|
||||
Margin="10,10,10,0" SelectedItem="{Binding Path=LayerModel.Properties.AmbienceCreatorType}"
|
||||
VerticalAlignment="Top" Height="22">
|
||||
<ComboBox.ItemTemplate>
|
||||
@ -65,12 +66,14 @@
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Margin="10,13,10,10" FontSize="13.333" Text="Mirrored Amount (%):"
|
||||
Height="18" VerticalAlignment="Top" />
|
||||
<controls:NumericUpDown Grid.Row="1" Grid.Column="1" VerticalAlignment="Top" Minimum="0" Maximum="100"
|
||||
Value="{Binding Path=LayerModel.Properties.MirroredAmount, Mode=TwoWay}" Margin="10,12,10,2" Height="24" />
|
||||
|
||||
Value="{Binding Path=LayerModel.Properties.MirroredAmount, Mode=TwoWay}"
|
||||
Margin="10,12,10,2" Height="24" />
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="2" Margin="10,13,10,10" FontSize="13.333" Text="Downsampling:"
|
||||
Height="18" VerticalAlignment="Top" />
|
||||
<controls:NumericUpDown Grid.Row="1" Grid.Column="3" VerticalAlignment="Top" Minimum="1" Maximum="20"
|
||||
Value="{Binding Path=LayerModel.Properties.Downsampling, Mode=TwoWay}" Margin="10,12,10,2" Height="24" />
|
||||
Value="{Binding Path=LayerModel.Properties.Downsampling, Mode=TwoWay}"
|
||||
Margin="10,12,10,2" Height="24" />
|
||||
|
||||
<!-- SmoothMode -->
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Margin="10,13,10,10" FontSize="13.333" Text="Smoothing:"
|
||||
@ -105,23 +108,27 @@
|
||||
<TextBlock Grid.Row="5" Grid.Column="0" Margin="10,13,10,10" FontSize="13.333" Text="Left:"
|
||||
Height="18" VerticalAlignment="Top" />
|
||||
<controls:NumericUpDown Grid.Row="5" Grid.Column="1" VerticalAlignment="Top" Minimum="0"
|
||||
Value="{Binding Path=LayerModel.Properties.OffsetLeft, Mode=TwoWay}" Margin="10,12,10,2" Height="24" />
|
||||
Value="{Binding Path=LayerModel.Properties.OffsetLeft, Mode=TwoWay}"
|
||||
Margin="10,12,10,2" Height="24" />
|
||||
|
||||
<TextBlock Grid.Row="5" Grid.Column="2" Margin="10,13,10,10" FontSize="13.333" Text="Right:"
|
||||
Height="18" VerticalAlignment="Top" />
|
||||
<controls:NumericUpDown Grid.Row="5" Grid.Column="3" VerticalAlignment="Top" Minimum="0"
|
||||
Value="{Binding Path=LayerModel.Properties.OffsetRight, Mode=TwoWay}" Margin="10,12,10,2" Height="24" />
|
||||
Value="{Binding Path=LayerModel.Properties.OffsetRight, Mode=TwoWay}"
|
||||
Margin="10,12,10,2" Height="24" />
|
||||
|
||||
<!-- Vertical offsets -->
|
||||
<TextBlock Grid.Row="6" Grid.Column="0" Margin="10,13,10,10" FontSize="13.333" Text="Top:"
|
||||
Height="18" VerticalAlignment="Top" />
|
||||
<controls:NumericUpDown Grid.Row="6" Grid.Column="1" VerticalAlignment="Top" Minimum="0"
|
||||
Value="{Binding Path=LayerModel.Properties.OffsetTop, Mode=TwoWay}" Margin="10,12,10,2" Height="24" />
|
||||
Value="{Binding Path=LayerModel.Properties.OffsetTop, Mode=TwoWay}" Margin="10,12,10,2"
|
||||
Height="24" />
|
||||
|
||||
<TextBlock Grid.Row="6" Grid.Column="2" Margin="10,13,10,10" FontSize="13.333" Text="Bottom:"
|
||||
Height="18" VerticalAlignment="Top" />
|
||||
<controls:NumericUpDown Grid.Row="6" Grid.Column="3" VerticalAlignment="Top" Minimum="0"
|
||||
Value="{Binding Path=LayerModel.Properties.OffsetBottom, Mode=TwoWay}" Margin="10,12,10,2" Height="24" />
|
||||
Value="{Binding Path=LayerModel.Properties.OffsetBottom, Mode=TwoWay}"
|
||||
Margin="10,12,10,2" Height="24" />
|
||||
|
||||
<!-- Horizontal BlackBar-detection -->
|
||||
<TextBlock Grid.Row="7" Grid.Column="0" Margin="10,20,10,3" FontSize="13.333" Text="Black-Bar detection"
|
||||
@ -153,4 +160,4 @@
|
||||
helper:CheckboxEnumFlagHelper.Flags="{Binding Path=LayerModel.Properties.BlackBarDetectionMode}" />
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
</UserControl>
|
||||
@ -9,4 +9,4 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,15 +9,17 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight
|
||||
|
||||
public AmbientLightPropertiesViewModel(LayerEditorViewModel editorVm)
|
||||
: base(editorVm)
|
||||
{ }
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public override void ApplyProperties()
|
||||
{ }
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -26,13 +26,11 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight
|
||||
public bool ShowInEdtor => true;
|
||||
public DrawType DrawType => DrawType.Keyboard;
|
||||
|
||||
[JsonIgnore]
|
||||
private AmbienceCreatorType? _lastAmbienceCreatorType = null;
|
||||
[JsonIgnore]
|
||||
private IAmbienceCreator _lastAmbienceCreator;
|
||||
[JsonIgnore] private AmbienceCreatorType? _lastAmbienceCreatorType;
|
||||
|
||||
[JsonIgnore]
|
||||
private byte[] _lastData;
|
||||
[JsonIgnore] private IAmbienceCreator _lastAmbienceCreator;
|
||||
|
||||
[JsonIgnore] private byte[] _lastData;
|
||||
|
||||
#endregion
|
||||
|
||||
@ -56,36 +54,39 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight
|
||||
|
||||
public void Update(LayerModel layerModel, IDataModel dataModel, bool isPreview = false)
|
||||
{
|
||||
AmbientLightPropertiesModel properties = layerModel?.Properties as AmbientLightPropertiesModel;
|
||||
var properties = layerModel?.Properties as AmbientLightPropertiesModel;
|
||||
if (properties == null) return;
|
||||
|
||||
int width = (int)Math.Round(properties.Width);
|
||||
int height = (int)Math.Round(properties.Height);
|
||||
var width = (int) Math.Round(properties.Width);
|
||||
var height = (int) Math.Round(properties.Height);
|
||||
|
||||
byte[] data = ScreenCaptureManager.GetLastScreenCapture();
|
||||
byte[] newData = GetAmbienceCreator(properties).GetAmbience(data, ScreenCaptureManager.LastCaptureWidth, ScreenCaptureManager.LastCaptureHeight, width, height, properties);
|
||||
var data = ScreenCaptureManager.GetLastScreenCapture();
|
||||
var newData = GetAmbienceCreator(properties)
|
||||
.GetAmbience(data, ScreenCaptureManager.LastCaptureWidth, ScreenCaptureManager.LastCaptureHeight, width,
|
||||
height, properties);
|
||||
|
||||
_lastData = _lastData?.Blend(newData, properties.SmoothMode) ?? newData;
|
||||
int stride = (width * ScreenCaptureManager.LastCapturePixelFormat.BitsPerPixel + 7) / 8;
|
||||
var stride = (width*ScreenCaptureManager.LastCapturePixelFormat.BitsPerPixel + 7)/8;
|
||||
properties.AmbientLightBrush = new DrawingBrush(new ImageDrawing
|
||||
(BitmapSource.Create(width, height, 96, 96, ScreenCaptureManager.LastCapturePixelFormat, null, _lastData, stride), new Rect(0, 0, width, height)));
|
||||
(BitmapSource.Create(width, height, 96, 96, ScreenCaptureManager.LastCapturePixelFormat, null, _lastData,
|
||||
stride), new Rect(0, 0, width, height)));
|
||||
}
|
||||
|
||||
public void Draw(LayerModel layerModel, DrawingContext c)
|
||||
{
|
||||
Rect rect = new Rect(layerModel.Properties.X * 4,
|
||||
layerModel.Properties.Y * 4,
|
||||
layerModel.Properties.Width * 4,
|
||||
layerModel.Properties.Height * 4);
|
||||
var rect = new Rect(layerModel.Properties.X*4,
|
||||
layerModel.Properties.Y*4,
|
||||
layerModel.Properties.Width*4,
|
||||
layerModel.Properties.Height*4);
|
||||
|
||||
c.DrawRectangle(((AmbientLightPropertiesModel)layerModel.Properties).AmbientLightBrush, null, rect);
|
||||
c.DrawRectangle(((AmbientLightPropertiesModel) layerModel.Properties).AmbientLightBrush, null, rect);
|
||||
}
|
||||
|
||||
public ImageSource DrawThumbnail(LayerModel layer)
|
||||
{
|
||||
Rect thumbnailRect = new Rect(0, 0, 18, 18);
|
||||
DrawingVisual visual = new DrawingVisual();
|
||||
using (DrawingContext c = visual.RenderOpen())
|
||||
var thumbnailRect = new Rect(0, 0, 18, 18);
|
||||
var visual = new DrawingVisual();
|
||||
using (var c = visual.RenderOpen())
|
||||
c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.ambilight), thumbnailRect);
|
||||
|
||||
return new DrawingImage(visual.Drawing);
|
||||
@ -99,12 +100,15 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight
|
||||
_lastAmbienceCreatorType = properties.AmbienceCreatorType;
|
||||
switch (properties.AmbienceCreatorType)
|
||||
{
|
||||
case AmbienceCreatorType.Mirror: return _lastAmbienceCreator = new AmbienceCreatorMirror();
|
||||
case AmbienceCreatorType.Extend: return _lastAmbienceCreator = new AmbienceCreatorExtend();
|
||||
default: throw new InvalidEnumArgumentException();
|
||||
case AmbienceCreatorType.Mirror:
|
||||
return _lastAmbienceCreator = new AmbienceCreatorMirror();
|
||||
case AmbienceCreatorType.Extend:
|
||||
return _lastAmbienceCreator = new AmbienceCreatorExtend();
|
||||
default:
|
||||
throw new InvalidEnumArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,10 +8,13 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Helper
|
||||
public class CheckboxEnumFlagHelper
|
||||
{
|
||||
#region DependencyProperties
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
public static readonly DependencyProperty FlagsProperty = DependencyProperty.RegisterAttached(
|
||||
"Flags", typeof(Enum), typeof(CheckboxEnumFlagHelper), new FrameworkPropertyMetadata(default(Enum), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, FlagsChanged));
|
||||
"Flags", typeof(Enum), typeof(CheckboxEnumFlagHelper),
|
||||
new FrameworkPropertyMetadata(default(Enum), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
||||
FlagsChanged));
|
||||
|
||||
public static void SetFlags(DependencyObject element, Enum value)
|
||||
{
|
||||
@ -20,7 +23,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Helper
|
||||
|
||||
public static Enum GetFlags(DependencyObject element)
|
||||
{
|
||||
return (Enum)element.GetValue(FlagsProperty);
|
||||
return (Enum) element.GetValue(FlagsProperty);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ValueProperty = DependencyProperty.RegisterAttached(
|
||||
@ -33,10 +36,11 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Helper
|
||||
|
||||
public static Enum GetValue(DependencyObject element)
|
||||
{
|
||||
return (Enum)element.GetValue(ValueProperty);
|
||||
return (Enum) element.GetValue(ValueProperty);
|
||||
}
|
||||
|
||||
// ReSharper restore InconsistentNaming
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
@ -50,7 +54,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Helper
|
||||
private static void ValueChanged(DependencyObject dependencyObject,
|
||||
DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
|
||||
{
|
||||
CheckBox checkbox = dependencyObject as CheckBox;
|
||||
var checkbox = dependencyObject as CheckBox;
|
||||
if (checkbox == null) return;
|
||||
|
||||
checkbox.Checked -= UpdateSource;
|
||||
@ -69,17 +73,17 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Helper
|
||||
{
|
||||
if (checkbox == null) return;
|
||||
|
||||
Enum value = GetValue(checkbox);
|
||||
var value = GetValue(checkbox);
|
||||
checkbox.IsChecked = value != null && (flags?.HasFlag(value) ?? false);
|
||||
}
|
||||
|
||||
private static void UpdateSource(object sender, RoutedEventArgs routedEventArgs)
|
||||
{
|
||||
CheckBox checkbox = sender as CheckBox;
|
||||
var checkbox = sender as CheckBox;
|
||||
if (checkbox == null) return;
|
||||
|
||||
Enum flags = GetFlags(checkbox);
|
||||
Enum value = GetValue(checkbox);
|
||||
var flags = GetFlags(checkbox);
|
||||
var value = GetValue(checkbox);
|
||||
if (value == null) return;
|
||||
|
||||
if (checkbox.IsChecked ?? false)
|
||||
@ -90,4 +94,4 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Helper
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,10 +4,8 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model
|
||||
{
|
||||
public enum AmbienceCreatorType
|
||||
{
|
||||
[Description("Mirror")]
|
||||
Mirror,
|
||||
[Description("Mirror")] Mirror,
|
||||
|
||||
[Description("Extend")]
|
||||
Extend
|
||||
[Description("Extend")] Extend
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,6 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model
|
||||
Left = 1 << 0,
|
||||
Right = 1 << 1,
|
||||
Top = 1 << 2,
|
||||
Bottom = 1 << 3,
|
||||
Bottom = 1 << 3
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -23,10 +23,10 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
|
||||
|
||||
public static AvgColor[] ExtendHeight(this AvgColor[] colors, int height)
|
||||
{
|
||||
AvgColor[] extended = new AvgColor[colors.Length * height];
|
||||
var extended = new AvgColor[colors.Length*height];
|
||||
|
||||
for (int i = 0; i < height; i++)
|
||||
Array.Copy(colors, 0, extended, i * colors.Length, colors.Length);
|
||||
for (var i = 0; i < height; i++)
|
||||
Array.Copy(colors, 0, extended, i*colors.Length, colors.Length);
|
||||
|
||||
return extended;
|
||||
}
|
||||
@ -35,9 +35,9 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
|
||||
{
|
||||
if (colors == null || width <= 0) return colors;
|
||||
|
||||
AvgColor[] flipped = new AvgColor[colors.Length];
|
||||
var flipped = new AvgColor[colors.Length];
|
||||
for (int i = 0, j = colors.Length - width; i < colors.Length; i += width, j -= width)
|
||||
for (int k = 0; k < width; ++k)
|
||||
for (var k = 0; k < width; ++k)
|
||||
flipped[i + k] = colors[j + k];
|
||||
|
||||
return flipped;
|
||||
@ -47,8 +47,8 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
|
||||
{
|
||||
if (colors == null || width <= 0) return colors;
|
||||
|
||||
AvgColor[] flipped = new AvgColor[colors.Length];
|
||||
for (int i = 0; i < colors.Length; i += width)
|
||||
var flipped = new AvgColor[colors.Length];
|
||||
for (var i = 0; i < colors.Length; i += width)
|
||||
for (int j = 0, k = width - 1; j < width; ++j, --k)
|
||||
flipped[i + j] = colors[i + k];
|
||||
|
||||
@ -57,9 +57,9 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
|
||||
|
||||
public static byte[] ToBGRArray(this AvgColor[] colors)
|
||||
{
|
||||
byte[] newData = new byte[colors.Length * 3];
|
||||
int counter = 0;
|
||||
foreach (AvgColor color in colors)
|
||||
var newData = new byte[colors.Length*3];
|
||||
var counter = 0;
|
||||
foreach (var color in colors)
|
||||
{
|
||||
newData[counter++] = color.B;
|
||||
newData[counter++] = color.G;
|
||||
@ -71,4 +71,4 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,17 +10,17 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
|
||||
{
|
||||
if (e == null || value == null || t == null) return e;
|
||||
|
||||
int eValue = Convert.ToInt32(e);
|
||||
int valueValue = Convert.ToInt32(value);
|
||||
var eValue = Convert.ToInt32(e);
|
||||
var valueValue = Convert.ToInt32(value);
|
||||
|
||||
if (set)
|
||||
eValue |= valueValue;
|
||||
else
|
||||
eValue &= ~valueValue;
|
||||
|
||||
return (Enum)Enum.ToObject(t, eValue);
|
||||
return (Enum) Enum.ToObject(t, eValue);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,17 +6,18 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
|
||||
{
|
||||
#region Methods
|
||||
|
||||
public static int DetectBlackBarLeft(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight, int offsetTop, int offsetBottom)
|
||||
public static int DetectBlackBarLeft(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight,
|
||||
int offsetTop, int offsetBottom)
|
||||
{
|
||||
int bottomBorder = height - offsetBottom;
|
||||
int rightBorder = width - offsetRight;
|
||||
var bottomBorder = height - offsetBottom;
|
||||
var rightBorder = width - offsetRight;
|
||||
|
||||
int blackBarWidth = 0;
|
||||
for (int x = rightBorder - 1; x >= offsetLeft; x--)
|
||||
var blackBarWidth = 0;
|
||||
for (var x = rightBorder - 1; x >= offsetLeft; x--)
|
||||
{
|
||||
for (int y = offsetTop; y < bottomBorder; y++)
|
||||
for (var y = offsetTop; y < bottomBorder; y++)
|
||||
{
|
||||
int offset = ((y * width) + x) * 4;
|
||||
var offset = (y*width + x)*4;
|
||||
if (pixels[offset] > 15 || pixels[offset + 1] > 15 || pixels[offset + 2] > 15)
|
||||
return blackBarWidth;
|
||||
}
|
||||
@ -26,17 +27,18 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
|
||||
return width;
|
||||
}
|
||||
|
||||
public static int DetectBlackBarRight(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight, int offsetTop, int offsetBottom)
|
||||
public static int DetectBlackBarRight(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight,
|
||||
int offsetTop, int offsetBottom)
|
||||
{
|
||||
int bottomBorder = height - offsetBottom;
|
||||
int rightBorder = width - offsetRight;
|
||||
var bottomBorder = height - offsetBottom;
|
||||
var rightBorder = width - offsetRight;
|
||||
|
||||
int blackBarWidth = 0;
|
||||
for (int x = offsetLeft; x < rightBorder; x++)
|
||||
var blackBarWidth = 0;
|
||||
for (var x = offsetLeft; x < rightBorder; x++)
|
||||
{
|
||||
for (int y = offsetTop; y < bottomBorder; y++)
|
||||
for (var y = offsetTop; y < bottomBorder; y++)
|
||||
{
|
||||
int offset = ((y * width) + x) * 4;
|
||||
var offset = (y*width + x)*4;
|
||||
if (pixels[offset] > 15 || pixels[offset + 1] > 15 || pixels[offset + 2] > 15)
|
||||
return blackBarWidth;
|
||||
}
|
||||
@ -46,17 +48,18 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
|
||||
return width;
|
||||
}
|
||||
|
||||
public static int DetectBlackBarTop(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight, int offsetTop, int offsetBottom)
|
||||
public static int DetectBlackBarTop(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight,
|
||||
int offsetTop, int offsetBottom)
|
||||
{
|
||||
int bottomBorder = height - offsetBottom;
|
||||
int rightBorder = width - offsetRight;
|
||||
var bottomBorder = height - offsetBottom;
|
||||
var rightBorder = width - offsetRight;
|
||||
|
||||
int blackBarHeight = 0;
|
||||
for (int y = offsetTop; y < bottomBorder; y++)
|
||||
var blackBarHeight = 0;
|
||||
for (var y = offsetTop; y < bottomBorder; y++)
|
||||
{
|
||||
for (int x = offsetLeft; x < rightBorder; x++)
|
||||
for (var x = offsetLeft; x < rightBorder; x++)
|
||||
{
|
||||
int offset = ((y * width) + x) * 4;
|
||||
var offset = (y*width + x)*4;
|
||||
if (pixels[offset] > 15 || pixels[offset + 1] > 15 || pixels[offset + 2] > 15)
|
||||
return blackBarHeight;
|
||||
}
|
||||
@ -66,17 +69,18 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
|
||||
return height;
|
||||
}
|
||||
|
||||
public static int DetectBlackBarBottom(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight, int offsetTop, int offsetBottom)
|
||||
public static int DetectBlackBarBottom(this byte[] pixels, int width, int height, int offsetLeft,
|
||||
int offsetRight, int offsetTop, int offsetBottom)
|
||||
{
|
||||
int bottomBorder = height - offsetBottom;
|
||||
int rightBorder = width - offsetRight;
|
||||
var bottomBorder = height - offsetBottom;
|
||||
var rightBorder = width - offsetRight;
|
||||
|
||||
int blackBarHeight = 0;
|
||||
for (int y = bottomBorder - 1; y >= offsetTop; y--)
|
||||
var blackBarHeight = 0;
|
||||
for (var y = bottomBorder - 1; y >= offsetTop; y--)
|
||||
{
|
||||
for (int x = offsetLeft; x < rightBorder; x++)
|
||||
for (var x = offsetLeft; x < rightBorder; x++)
|
||||
{
|
||||
int offset = ((y * width) + x) * 4;
|
||||
var offset = (y*width + x)*4;
|
||||
if (pixels[offset] > 15 || pixels[offset + 1] > 15 || pixels[offset + 2] > 15)
|
||||
return blackBarHeight;
|
||||
}
|
||||
@ -89,23 +93,25 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
|
||||
public static byte[] Blend(this byte[] pixels, byte[] blendPixels, SmoothMode smoothMode)
|
||||
{
|
||||
if (smoothMode == SmoothMode.None || pixels.Length != blendPixels.Length) return blendPixels;
|
||||
|
||||
double percentage = smoothMode == SmoothMode.Low? 0.25: (smoothMode == SmoothMode.Medium ? 0.075 : 0.025 /*high*/);
|
||||
|
||||
byte[] blended = new byte[pixels.Length];
|
||||
var percentage = smoothMode == SmoothMode.Low
|
||||
? 0.25
|
||||
: (smoothMode == SmoothMode.Medium ? 0.075 : 0.025 /*high*/);
|
||||
|
||||
for (int i = 0; i < blended.Length; i++)
|
||||
blended[i] = GetIntColor((blendPixels[i] / 255.0) * percentage + (pixels[i] / 255.0) * (1 - percentage));
|
||||
var blended = new byte[pixels.Length];
|
||||
|
||||
for (var i = 0; i < blended.Length; i++)
|
||||
blended[i] = GetIntColor(blendPixels[i]/255.0*percentage + pixels[i]/255.0*(1 - percentage));
|
||||
|
||||
return blended;
|
||||
}
|
||||
|
||||
private static byte GetIntColor(double d)
|
||||
{
|
||||
double calcF = Math.Max(0, Math.Min(1, d));
|
||||
return (byte)(calcF.Equals(1) ? 255 : calcF * 256);
|
||||
var calcF = Math.Max(0, Math.Min(1, d));
|
||||
return (byte) (calcF.Equals(1) ? 255 : calcF*256);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,4 +9,4 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model
|
||||
Vertical = 1 << 0,
|
||||
Horizontal = 1 << 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,6 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model
|
||||
{
|
||||
public enum ScreenCaptureMode
|
||||
{
|
||||
[Description("DirectX 9")]
|
||||
DirectX9
|
||||
[Description("DirectX 9")] DirectX9
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,16 +4,12 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model
|
||||
{
|
||||
public enum SmoothMode
|
||||
{
|
||||
[Description("None")]
|
||||
None,
|
||||
[Description("None")] None,
|
||||
|
||||
[Description("Low")]
|
||||
Low,
|
||||
[Description("Low")] Low,
|
||||
|
||||
[Description("Medium")]
|
||||
Medium,
|
||||
[Description("Medium")] Medium,
|
||||
|
||||
[Description("High")]
|
||||
High
|
||||
[Description("High")] High
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,25 +2,12 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Media;
|
||||
using SharpDX;
|
||||
using SharpDX.Direct3D9;
|
||||
|
||||
namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
|
||||
{
|
||||
public class DX9ScreenCapture : IScreenCapture
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private Device _device;
|
||||
private Surface _surface;
|
||||
private byte[] _buffer;
|
||||
|
||||
public int Width { get; }
|
||||
public int Height { get; }
|
||||
public PixelFormat PixelFormat => PixelFormats.Bgr24;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public DX9ScreenCapture()
|
||||
@ -28,26 +15,39 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
|
||||
Width = Screen.PrimaryScreen.Bounds.Width;
|
||||
Height = Screen.PrimaryScreen.Bounds.Height;
|
||||
|
||||
PresentParameters presentParams = new PresentParameters(Width, Height)
|
||||
var presentParams = new PresentParameters(Width, Height)
|
||||
{
|
||||
Windowed = true,
|
||||
SwapEffect = SwapEffect.Discard
|
||||
};
|
||||
|
||||
_device = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, presentParams);
|
||||
_device = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero,
|
||||
CreateFlags.SoftwareVertexProcessing, presentParams);
|
||||
_surface = Surface.CreateOffscreenPlain(_device, Width, Height, Format.A8R8G8B8, Pool.Scratch);
|
||||
_buffer = new byte[Width * Height * 4];
|
||||
_buffer = new byte[Width*Height*4];
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly Device _device;
|
||||
private readonly Surface _surface;
|
||||
private readonly byte[] _buffer;
|
||||
|
||||
public int Width { get; }
|
||||
public int Height { get; }
|
||||
public PixelFormat PixelFormat => PixelFormats.Bgr24;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public byte[] CaptureScreen()
|
||||
{
|
||||
_device.GetFrontBufferData(0, _surface);
|
||||
|
||||
DataRectangle dr = _surface.LockRectangle(LockFlags.None);
|
||||
var dr = _surface.LockRectangle(LockFlags.None);
|
||||
Marshal.Copy(dr.DataPointer, _buffer, 0, _buffer.Length);
|
||||
_surface.UnlockRectangle();
|
||||
|
||||
@ -62,4 +62,4 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,9 +10,9 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
|
||||
PixelFormat PixelFormat { get; }
|
||||
|
||||
/// <summary>
|
||||
/// As Pixel-Data BGRA
|
||||
/// As Pixel-Data BGRA
|
||||
/// </summary>
|
||||
/// <returns>The Pixel-Data</returns>
|
||||
byte[] CaptureScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -14,13 +14,14 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
|
||||
private static Thread _worker;
|
||||
private static DateTime _lastCaptureAccess;
|
||||
private static volatile byte[] _lastScreenCapture;
|
||||
private static volatile bool _isRunning = false;
|
||||
private static volatile bool _isRunning;
|
||||
|
||||
private static ScreenCaptureMode? _lastScreenCaptureMode = null;
|
||||
private static ScreenCaptureMode? _lastScreenCaptureMode;
|
||||
private static IScreenCapture _screenCapture;
|
||||
|
||||
public static double StandByTime { get; set; } = 3;
|
||||
public static double UpdateRate { get; set; } = 1.0 / 20.0; // DarthAffe 29.10.2016: I think 20 FPS should be enough as default
|
||||
public static double UpdateRate { get; set; } = 1.0/20.0;
|
||||
// DarthAffe 29.10.2016: I think 20 FPS should be enough as default
|
||||
public static ScreenCaptureMode ScreenCaptureMode { get; set; } = ScreenCaptureMode.DirectX9;
|
||||
|
||||
public static int LastCaptureWidth { get; private set; }
|
||||
@ -41,8 +42,10 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
|
||||
_lastScreenCaptureMode = ScreenCaptureMode;
|
||||
switch (ScreenCaptureMode)
|
||||
{
|
||||
case ScreenCaptureMode.DirectX9: return _screenCapture = new DX9ScreenCapture();
|
||||
default: throw new InvalidEnumArgumentException();
|
||||
case ScreenCaptureMode.DirectX9:
|
||||
return _screenCapture = new DX9ScreenCapture();
|
||||
default:
|
||||
throw new InvalidEnumArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +62,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
|
||||
{
|
||||
while ((DateTime.Now - _lastCaptureAccess).TotalSeconds < StandByTime)
|
||||
{
|
||||
DateTime lastCapture = DateTime.Now;
|
||||
var lastCapture = DateTime.Now;
|
||||
try
|
||||
{
|
||||
CaptureScreen();
|
||||
@ -69,7 +72,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
|
||||
Debug.WriteLine("[CaptureLoop]: " + ex.Message);
|
||||
}
|
||||
|
||||
int sleep = (int)((UpdateRate - (DateTime.Now - lastCapture).TotalSeconds) * 1000);
|
||||
var sleep = (int) ((UpdateRate - (DateTime.Now - lastCapture).TotalSeconds)*1000);
|
||||
if (sleep > 0)
|
||||
Thread.Sleep(sleep);
|
||||
}
|
||||
@ -83,7 +86,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
|
||||
|
||||
private static void CaptureScreen()
|
||||
{
|
||||
IScreenCapture screenCapture = GetScreenCapture();
|
||||
var screenCapture = GetScreenCapture();
|
||||
|
||||
_lastScreenCapture = screenCapture.CaptureScreen();
|
||||
LastCaptureWidth = screenCapture.Width;
|
||||
@ -113,4 +116,4 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -21,11 +21,11 @@ namespace Artemis.Profiles.Layers.Types.Audio
|
||||
{
|
||||
internal class AudioType : ILayerType
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly List<LayerModel> _audioLayers = new List<LayerModel>();
|
||||
private readonly MMDevice _device;
|
||||
private readonly SampleAggregator _sampleAggregator = new SampleAggregator(1024);
|
||||
private readonly WasapiLoopbackCapture _waveIn;
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private int _lines;
|
||||
private AudioPropertiesModel _previousSettings;
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Models.Interfaces;
|
||||
using Artemis.Profiles.Layers.Abstract;
|
||||
@ -13,7 +12,7 @@ namespace Artemis.Profiles.Layers.Types.Folder
|
||||
{
|
||||
public class FolderType : ILayerType
|
||||
{
|
||||
public string Name { get; } = "Folder";
|
||||
public string Name => "Folder";
|
||||
public bool ShowInEdtor { get; } = false;
|
||||
// FolderType pretents to be a keyboard so it's children get drawn
|
||||
public DrawType DrawType { get; } = DrawType.Keyboard;
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
<UserControl
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:ncore="http://schemas.ncore.com/wpf/xaml/colorbox"
|
||||
xmlns:ObjectModel="clr-namespace:System.Collections.ObjectModel;assembly=System" x:Class="Artemis.Profiles.Layers.Types.Generic.GenericPropertiesView"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="600" d:DesignWidth="500">
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:ncore="http://schemas.ncore.com/wpf/xaml/colorbox"
|
||||
xmlns:ObjectModel="clr-namespace:System.Collections.ObjectModel;assembly=System"
|
||||
x:Class="Artemis.Profiles.Layers.Types.Generic.GenericPropertiesView"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="600" d:DesignWidth="500">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
@ -24,10 +25,10 @@
|
||||
</Grid.RowDefinitions>
|
||||
<!-- Animation -->
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Margin="10" FontSize="13.333" Text="Animation:"
|
||||
VerticalAlignment="Center"
|
||||
Height="18" />
|
||||
VerticalAlignment="Center"
|
||||
Height="18" />
|
||||
<ComboBox Grid.Row="0" Grid.Column="1" Margin="10,10,10,0" x:Name="LayerAnimations" VerticalAlignment="Top"
|
||||
Height="22">
|
||||
Height="22">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name, Mode=OneWay}" />
|
||||
@ -37,33 +38,41 @@
|
||||
|
||||
<!-- Animation Speed -->
|
||||
<TextBlock Grid.Row="0" Grid.Column="2" Margin="10" FontSize="13.333" Text="Animation speed:"
|
||||
VerticalAlignment="Center" Height="18" />
|
||||
VerticalAlignment="Center" Height="18" />
|
||||
<Slider x:Name="RotationSpeed" Grid.Row="0" Grid.Column="3" VerticalAlignment="Center"
|
||||
TickPlacement="None" TickFrequency="0.05"
|
||||
Value="{Binding LayerModel.Properties.AnimationSpeed, Mode=TwoWay}" Minimum="0.05" Maximum="3"
|
||||
SmallChange="0" IsSnapToTickEnabled="True" Margin="10,12,10,2" Height="24" />
|
||||
TickPlacement="None" TickFrequency="0.05"
|
||||
Value="{Binding LayerModel.Properties.AnimationSpeed, Mode=TwoWay}" Minimum="0.05" Maximum="3"
|
||||
SmallChange="0" IsSnapToTickEnabled="True" Margin="10,12,10,2" Height="24" />
|
||||
|
||||
<!-- Colors -->
|
||||
<StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" x:Name="ShowBrush">
|
||||
<TextBlock Margin="10,13,10,0" FontSize="13.333" Text="Color(s):"
|
||||
VerticalAlignment="Top" Height="18" Width="130" />
|
||||
VerticalAlignment="Top" Height="18" Width="130" />
|
||||
<Border Margin="10" BorderBrush="{StaticResource ControlBorderBrush}"
|
||||
BorderThickness="1" SnapsToDevicePixels="True" ToolTip="Click to edit">
|
||||
<ncore:ColorBox Brush="{Binding Brush, Mode=TwoWay}" Height="24" Width="134"/>
|
||||
BorderThickness="1" SnapsToDevicePixels="True" ToolTip="Click to edit">
|
||||
<ncore:ColorBox Brush="{Binding Brush, Mode=TwoWay}" Height="24" Width="134" />
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Dynamic -->
|
||||
<Label Grid.Row="3" Grid.Column="0" FontSize="20" HorizontalAlignment="Left"
|
||||
Content="Dynamic" Width="97" VerticalAlignment="Bottom" />
|
||||
Content="Dynamic" Width="97" VerticalAlignment="Bottom" />
|
||||
|
||||
<!-- Dynamic property views -->
|
||||
<ContentControl Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="4" x:Name="OpacityProperties" />
|
||||
|
||||
<!-- Note -->
|
||||
<TextBlock Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="4" Margin="10,2,10,10" FontSize="13.333"
|
||||
Foreground="{DynamicResource HighlightBrush}"
|
||||
VerticalAlignment="Top" Height="Auto" TextWrapping="Wrap"><Run Text="Note: Generic devices are devices over which Artemis has limited control." /><LineBreak /><Run /><LineBreak /><Run Text="You can use this layer type to assign a color to all generic devices at once." /><LineBreak /><Run
|
||||
Text="Should your generic device have multiple LEDs, Artemis will try to take the colors from the Brush and spread them over the LEDs." /><LineBreak /><Run /><LineBreak /><Run Text="Examples of supported generic devices:" /><LineBreak /><Run Text="- Logitech mice and headsets" /><LineBreak /><Run Text="- Logitech G19" /><LineBreak /><Run Text="- Logitech G510" /><LineBreak /><Run /></TextBlock>
|
||||
Foreground="{DynamicResource HighlightBrush}"
|
||||
VerticalAlignment="Top" Height="Auto" TextWrapping="Wrap">
|
||||
<Run Text="Note: Generic devices are devices over which Artemis has limited control." /><LineBreak />
|
||||
<Run /><LineBreak />
|
||||
<Run Text="You can use this layer type to assign a color to all generic devices at once." /><LineBreak />
|
||||
<Run
|
||||
Text="Should your generic device have multiple LEDs, Artemis will try to take the colors from the Brush and spread them over the LEDs." />
|
||||
<LineBreak /><Run /><LineBreak /><Run Text="Examples of supported generic devices:" /><LineBreak />
|
||||
<Run Text="- Logitech mice and headsets" /><LineBreak /><Run Text="- Logitech G19" /><LineBreak />
|
||||
<Run Text="- Logitech G510" /><LineBreak /><Run />
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Models.Interfaces;
|
||||
@ -15,7 +14,7 @@ namespace Artemis.Profiles.Layers.Types.Generic
|
||||
{
|
||||
public class GenericType : ILayerType
|
||||
{
|
||||
public string Name { get; } = "Generic (Logitech)";
|
||||
public string Name => "Generic (Logitech)";
|
||||
public bool ShowInEdtor { get; } = false;
|
||||
public DrawType DrawType { get; } = DrawType.Generic;
|
||||
|
||||
@ -43,7 +42,7 @@ namespace Artemis.Profiles.Layers.Types.Generic
|
||||
|
||||
// Otherwise draw the rectangle with its applied dimensions and brush
|
||||
var rect = layerModel.LayerRect();
|
||||
|
||||
|
||||
// Can't meddle with the original brush because it's frozen.
|
||||
var brush = layerModel.Brush.Clone();
|
||||
brush.Opacity = layerModel.Opacity;
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Models.Interfaces;
|
||||
@ -15,7 +14,7 @@ namespace Artemis.Profiles.Layers.Types.Headset
|
||||
{
|
||||
public class HeadsetType : ILayerType
|
||||
{
|
||||
public string Name { get; } = "Headset";
|
||||
public string Name => "Headset";
|
||||
public bool ShowInEdtor { get; } = false;
|
||||
public DrawType DrawType { get; } = DrawType.Headset;
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ namespace Artemis.Profiles.Layers.Types.KeyPress
|
||||
public RadialGradientBrush TempBrush { get; set; }
|
||||
|
||||
|
||||
public string Name { get; } = "Keyboard - Key press";
|
||||
public string Name => "Keyboard - Key press";
|
||||
public bool ShowInEdtor { get; } = false;
|
||||
public DrawType DrawType { get; } = DrawType.Keyboard;
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@
|
||||
VerticalAlignment="Top" Height="18" Width="130" />
|
||||
<Border Margin="10" BorderBrush="{StaticResource ControlBorderBrush}"
|
||||
BorderThickness="1" SnapsToDevicePixels="True" ToolTip="Click to edit">
|
||||
<ncore:ColorBox Brush="{Binding Path=Brush, Mode=TwoWay}" Height="24" Width="134"/>
|
||||
<ncore:ColorBox Brush="{Binding Path=Brush, Mode=TwoWay}" Height="24" Width="134" />
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ namespace Artemis.Profiles.Layers.Types.Keyboard
|
||||
{
|
||||
public class KeyboardType : ILayerType
|
||||
{
|
||||
public string Name { get; } = "Keyboard";
|
||||
public string Name => "Keyboard";
|
||||
public bool ShowInEdtor { get; } = true;
|
||||
public DrawType DrawType { get; } = DrawType.Keyboard;
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ namespace Artemis.Profiles.Layers.Types.KeyboardGif
|
||||
{
|
||||
internal class KeyboardGifType : ILayerType
|
||||
{
|
||||
public string Name { get; } = "Keyboard - GIF";
|
||||
public string Name => "Keyboard - GIF";
|
||||
public bool ShowInEdtor { get; } = true;
|
||||
public DrawType DrawType { get; } = DrawType.Keyboard;
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Models.Interfaces;
|
||||
@ -15,7 +14,7 @@ namespace Artemis.Profiles.Layers.Types.Mouse
|
||||
{
|
||||
public class MouseType : ILayerType
|
||||
{
|
||||
public string Name { get; } = "Mouse";
|
||||
public string Name => "Mouse";
|
||||
public bool ShowInEdtor { get; } = false;
|
||||
public DrawType DrawType { get; } = DrawType.Mouse;
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ namespace Artemis.Profiles.Layers.Types.Mousemat
|
||||
{
|
||||
public class MousematType : ILayerType
|
||||
{
|
||||
public string Name { get; } = "Mousemat";
|
||||
public string Name => "Mousemat";
|
||||
public bool ShowInEdtor { get; } = false;
|
||||
public DrawType DrawType { get; } = DrawType.Mousemat;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user