1
0
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:
SpoinkyNL 2016-11-30 14:47:16 +01:00
parent 33094731aa
commit 188e1ddfe4
32 changed files with 312 additions and 274 deletions

View File

@ -9,34 +9,40 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator
#region Methods #region Methods
public byte[] GetAmbience(byte[] pixels, int sourceWidth, int sourceHeight, public byte[] GetAmbience(byte[] pixels, int sourceWidth, int sourceHeight,
int targetWidth, int targetHeight, int targetWidth, int targetHeight,
AmbientLightPropertiesModel settings) AmbientLightPropertiesModel settings)
{ {
AvgColor[] colors = new AvgColor[targetWidth]; var colors = new AvgColor[targetWidth];
for (int i = 0; i < colors.Length; i++) for (var i = 0; i < colors.Length; i++)
colors[i] = new AvgColor(); colors[i] = new AvgColor();
int offsetLeft = settings.OffsetLeft + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Left) var offsetLeft = settings.OffsetLeft + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Left)
? pixels.DetectBlackBarLeft(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) ? pixels.DetectBlackBarLeft(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight,
settings.OffsetTop, settings.OffsetBottom)
: 0); : 0);
int offsetRight = settings.OffsetRight + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Right) var offsetRight = settings.OffsetRight +
? pixels.DetectBlackBarRight(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Right)
: 0); ? pixels.DetectBlackBarRight(sourceWidth, sourceHeight, settings.OffsetLeft,
int offsetTop = settings.OffsetTop + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Top) settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom)
? pixels.DetectBlackBarTop(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) : 0);
: 0); var offsetTop = settings.OffsetTop + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Top)
int offsetBottom = settings.OffsetBottom + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Bottom) ? pixels.DetectBlackBarTop(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight,
? pixels.DetectBlackBarBottom(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) settings.OffsetTop, settings.OffsetBottom)
: 0); : 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; var effectiveSourceWidth = sourceWidth - offsetLeft - offsetRight;
int effectiveSourceHeight = sourceHeight - offsetTop - offsetBottom; var effectiveSourceHeight = sourceHeight - offsetTop - offsetBottom;
int relevantSourceHeight = (int)Math.Round(effectiveSourceHeight * (settings.MirroredAmount / 100.0)); var relevantSourceHeight = (int) Math.Round(effectiveSourceHeight*(settings.MirroredAmount/100.0));
int relevantOffsetTop = sourceHeight - offsetBottom - relevantSourceHeight; var relevantOffsetTop = sourceHeight - offsetBottom - relevantSourceHeight;
double widthPixels = effectiveSourceWidth / (double)targetWidth; var widthPixels = effectiveSourceWidth/(double) targetWidth;
double heightPixels = relevantSourceHeight / (double)targetHeight; var heightPixels = relevantSourceHeight/(double) targetHeight;
if (widthPixels <= 0 || heightPixels <= 0 || (relevantSourceHeight + relevantOffsetTop > sourceHeight) || if (widthPixels <= 0 || heightPixels <= 0 || (relevantSourceHeight + relevantOffsetTop > sourceHeight) ||
effectiveSourceWidth > sourceWidth) effectiveSourceWidth > sourceWidth)
@ -45,13 +51,13 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator
return colors.ToBGRArray(); return colors.ToBGRArray();
} }
int increment = Math.Max(1, Math.Min(20, settings.Downsampling)); var increment = Math.Max(1, Math.Min(20, settings.Downsampling));
for (int y = 0; y < relevantSourceHeight; y += increment) for (var y = 0; y < relevantSourceHeight; y += increment)
{ {
int targetWidthIndex = 0; var targetWidthIndex = 0;
double widthCounter = widthPixels; var widthCounter = widthPixels;
for (int x = 0; x < effectiveSourceWidth; x += increment) for (var x = 0; x < effectiveSourceWidth; x += increment)
{ {
if (x >= widthCounter) if (x >= widthCounter)
{ {
@ -59,10 +65,10 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator
targetWidthIndex++; targetWidthIndex++;
} }
int colorsOffset = targetWidthIndex; var colorsOffset = targetWidthIndex;
int sourceOffset = ((((relevantOffsetTop + y) * sourceWidth) + offsetLeft + x) * 4); var sourceOffset = ((relevantOffsetTop + y)*sourceWidth + offsetLeft + x)*4;
AvgColor color = colors[colorsOffset]; var color = colors[colorsOffset];
color.AddB(pixels[sourceOffset]); color.AddB(pixels[sourceOffset]);
color.AddG(pixels[sourceOffset + 1]); color.AddG(pixels[sourceOffset + 1]);
color.AddR(pixels[sourceOffset + 2]); color.AddR(pixels[sourceOffset + 2]);

View File

@ -9,43 +9,50 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator
#region Methods #region Methods
public byte[] GetAmbience(byte[] pixels, int sourceWidth, int sourceHeight, public byte[] GetAmbience(byte[] pixels, int sourceWidth, int sourceHeight,
int targetWidth, int targetHeight, int targetWidth, int targetHeight,
AmbientLightPropertiesModel settings) AmbientLightPropertiesModel settings)
{ {
AvgColor[] colors = new AvgColor[targetWidth * targetHeight]; var colors = new AvgColor[targetWidth*targetHeight];
for (int i = 0; i < colors.Length; i++) for (var i = 0; i < colors.Length; i++)
colors[i] = new AvgColor(); colors[i] = new AvgColor();
int offsetLeft = settings.OffsetLeft + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Left) var offsetLeft = settings.OffsetLeft + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Left)
? pixels.DetectBlackBarLeft(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) ? pixels.DetectBlackBarLeft(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight,
settings.OffsetTop, settings.OffsetBottom)
: 0); : 0);
int offsetRight = settings.OffsetRight + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Right) var offsetRight = settings.OffsetRight +
? pixels.DetectBlackBarRight(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Right)
: 0); ? pixels.DetectBlackBarRight(sourceWidth, sourceHeight, settings.OffsetLeft,
int offsetTop = settings.OffsetTop + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Top) settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom)
? pixels.DetectBlackBarTop(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) : 0);
: 0); var offsetTop = settings.OffsetTop + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Top)
int offsetBottom = settings.OffsetBottom + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Bottom) ? pixels.DetectBlackBarTop(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight,
? pixels.DetectBlackBarBottom(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) settings.OffsetTop, settings.OffsetBottom)
: 0); : 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; var effectiveSourceWidth = sourceWidth - offsetLeft - offsetRight;
int effectiveSourceHeight = sourceHeight - offsetTop - offsetBottom; var effectiveSourceHeight = sourceHeight - offsetTop - offsetBottom;
int relevantSourceHeight = (int)Math.Round(effectiveSourceHeight * (settings.MirroredAmount / 100.0)); var relevantSourceHeight = (int) Math.Round(effectiveSourceHeight*(settings.MirroredAmount/100.0));
int relevantOffsetTop = sourceHeight - offsetBottom - relevantSourceHeight; var relevantOffsetTop = sourceHeight - offsetBottom - relevantSourceHeight;
double widthPixels = effectiveSourceWidth / (double)targetWidth; var widthPixels = effectiveSourceWidth/(double) targetWidth;
double heightPixels = relevantSourceHeight / (double)targetHeight; 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(); return colors.ToBGRArray();
int targetHeightIndex = 0; var targetHeightIndex = 0;
double heightCounter = heightPixels; var heightCounter = heightPixels;
int increment = Math.Max(1, Math.Min(20, settings.Downsampling)); var increment = Math.Max(1, Math.Min(20, settings.Downsampling));
for (int y = 0; y < relevantSourceHeight; y += increment) for (var y = 0; y < relevantSourceHeight; y += increment)
{ {
if (y >= heightCounter) if (y >= heightCounter)
{ {
@ -53,10 +60,10 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator
targetHeightIndex++; targetHeightIndex++;
} }
int targetWidthIndex = 0; var targetWidthIndex = 0;
double widthCounter = widthPixels; var widthCounter = widthPixels;
for (int x = 0; x < effectiveSourceWidth; x += increment) for (var x = 0; x < effectiveSourceWidth; x += increment)
{ {
if (x >= widthCounter) if (x >= widthCounter)
{ {
@ -64,10 +71,10 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator
targetWidthIndex++; targetWidthIndex++;
} }
int colorsOffset = (targetHeightIndex * targetWidth) + targetWidthIndex; var colorsOffset = targetHeightIndex*targetWidth + targetWidthIndex;
int sourceOffset = ((((relevantOffsetTop + y) * sourceWidth) + offsetLeft + x) * 4); var sourceOffset = ((relevantOffsetTop + y)*sourceWidth + offsetLeft + x)*4;
AvgColor color = colors[colorsOffset]; var color = colors[colorsOffset];
color.AddB(pixels[sourceOffset]); color.AddB(pixels[sourceOffset]);
color.AddG(pixels[sourceOffset + 1]); color.AddG(pixels[sourceOffset + 1]);
color.AddR(pixels[sourceOffset + 2]); color.AddR(pixels[sourceOffset + 2]);

View File

@ -4,16 +4,16 @@
{ {
#region Properties & Fields #region Properties & Fields
private int _rCount = 0; private int _rCount;
private int _r = 0; private int _r;
private int _gCount = 0; private int _gCount;
private int _g = 0; private int _g;
private int _bCount = 0; private int _bCount;
private int _b = 0; private int _b;
public byte R => (byte)(_rCount > 0 ? (_r / _rCount) : 0); public byte R => (byte) (_rCount > 0 ? _r/_rCount : 0);
public byte G => (byte)(_gCount > 0 ? (_g / _gCount) : 0); public byte G => (byte) (_gCount > 0 ? _g/_gCount : 0);
public byte B => (byte)(_bCount > 0 ? (_b / _bCount) : 0); public byte B => (byte) (_bCount > 0 ? _b/_bCount : 0);
#endregion #endregion

View File

@ -2,6 +2,7 @@
{ {
public interface IAmbienceCreator 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);
} }
} }

View File

@ -7,6 +7,16 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight
{ {
public class AmbientLightPropertiesModel : LayerPropertiesModel public class AmbientLightPropertiesModel : LayerPropertiesModel
{ {
#region Constructors
public AmbientLightPropertiesModel(LayerPropertiesModel properties)
: base(properties)
{
Brush = new SolidColorBrush(Color.FromRgb(0, 0, 0));
}
#endregion
#region Properties & Fields #region Properties & Fields
//HACK DarthAffe 30.10.2016: The 'normal' Brush-Property destoys the profile since Drawing-Brushes cannot be deserialized. //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; public FlipMode FlipMode { get; set; } = FlipMode.Vertical;
#endregion #endregion
#region Constructors
public AmbientLightPropertiesModel(LayerPropertiesModel properties)
: base(properties)
{
Brush = new SolidColorBrush(Color.FromRgb(0, 0, 0));
}
#endregion
} }
} }

View File

@ -51,7 +51,8 @@
<!-- AmbienceCreatorType --> <!-- AmbienceCreatorType -->
<TextBlock Grid.Row="0" Grid.Column="0" Margin="10,13,10,10" FontSize="13.333" Text="Ambilight-Mode:" <TextBlock Grid.Row="0" Grid.Column="0" Margin="10,13,10,10" FontSize="13.333" Text="Ambilight-Mode:"
VerticalAlignment="Top" Height="18" /> 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}" Margin="10,10,10,0" SelectedItem="{Binding Path=LayerModel.Properties.AmbienceCreatorType}"
VerticalAlignment="Top" Height="22"> VerticalAlignment="Top" Height="22">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
@ -65,12 +66,14 @@
<TextBlock Grid.Row="1" Grid.Column="0" Margin="10,13,10,10" FontSize="13.333" Text="Mirrored Amount (%):" <TextBlock Grid.Row="1" Grid.Column="0" Margin="10,13,10,10" FontSize="13.333" Text="Mirrored Amount (%):"
Height="18" VerticalAlignment="Top" /> Height="18" VerticalAlignment="Top" />
<controls:NumericUpDown Grid.Row="1" Grid.Column="1" VerticalAlignment="Top" Minimum="0" Maximum="100" <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:" <TextBlock Grid.Row="1" Grid.Column="2" Margin="10,13,10,10" FontSize="13.333" Text="Downsampling:"
Height="18" VerticalAlignment="Top" /> Height="18" VerticalAlignment="Top" />
<controls:NumericUpDown Grid.Row="1" Grid.Column="3" VerticalAlignment="Top" Minimum="1" Maximum="20" <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 --> <!-- SmoothMode -->
<TextBlock Grid.Row="2" Grid.Column="0" Margin="10,13,10,10" FontSize="13.333" Text="Smoothing:" <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:" <TextBlock Grid.Row="5" Grid.Column="0" Margin="10,13,10,10" FontSize="13.333" Text="Left:"
Height="18" VerticalAlignment="Top" /> Height="18" VerticalAlignment="Top" />
<controls:NumericUpDown Grid.Row="5" Grid.Column="1" VerticalAlignment="Top" Minimum="0" <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:" <TextBlock Grid.Row="5" Grid.Column="2" Margin="10,13,10,10" FontSize="13.333" Text="Right:"
Height="18" VerticalAlignment="Top" /> Height="18" VerticalAlignment="Top" />
<controls:NumericUpDown Grid.Row="5" Grid.Column="3" VerticalAlignment="Top" Minimum="0" <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 --> <!-- Vertical offsets -->
<TextBlock Grid.Row="6" Grid.Column="0" Margin="10,13,10,10" FontSize="13.333" Text="Top:" <TextBlock Grid.Row="6" Grid.Column="0" Margin="10,13,10,10" FontSize="13.333" Text="Top:"
Height="18" VerticalAlignment="Top" /> Height="18" VerticalAlignment="Top" />
<controls:NumericUpDown Grid.Row="6" Grid.Column="1" VerticalAlignment="Top" Minimum="0" <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:" <TextBlock Grid.Row="6" Grid.Column="2" Margin="10,13,10,10" FontSize="13.333" Text="Bottom:"
Height="18" VerticalAlignment="Top" /> Height="18" VerticalAlignment="Top" />
<controls:NumericUpDown Grid.Row="6" Grid.Column="3" VerticalAlignment="Top" Minimum="0" <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 --> <!-- Horizontal BlackBar-detection -->
<TextBlock Grid.Row="7" Grid.Column="0" Margin="10,20,10,3" FontSize="13.333" Text="Black-Bar detection" <TextBlock Grid.Row="7" Grid.Column="0" Margin="10,20,10,3" FontSize="13.333" Text="Black-Bar detection"

View File

@ -9,14 +9,16 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight
public AmbientLightPropertiesViewModel(LayerEditorViewModel editorVm) public AmbientLightPropertiesViewModel(LayerEditorViewModel editorVm)
: base(editorVm) : base(editorVm)
{ } {
}
#endregion #endregion
#region Methods #region Methods
public override void ApplyProperties() public override void ApplyProperties()
{ } {
}
#endregion #endregion
} }

View File

@ -26,13 +26,11 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight
public bool ShowInEdtor => true; public bool ShowInEdtor => true;
public DrawType DrawType => DrawType.Keyboard; public DrawType DrawType => DrawType.Keyboard;
[JsonIgnore] [JsonIgnore] private AmbienceCreatorType? _lastAmbienceCreatorType;
private AmbienceCreatorType? _lastAmbienceCreatorType = null;
[JsonIgnore]
private IAmbienceCreator _lastAmbienceCreator;
[JsonIgnore] [JsonIgnore] private IAmbienceCreator _lastAmbienceCreator;
private byte[] _lastData;
[JsonIgnore] private byte[] _lastData;
#endregion #endregion
@ -56,36 +54,39 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight
public void Update(LayerModel layerModel, IDataModel dataModel, bool isPreview = false) 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; if (properties == null) return;
int width = (int)Math.Round(properties.Width); var width = (int) Math.Round(properties.Width);
int height = (int)Math.Round(properties.Height); var height = (int) Math.Round(properties.Height);
byte[] data = ScreenCaptureManager.GetLastScreenCapture(); var data = ScreenCaptureManager.GetLastScreenCapture();
byte[] newData = GetAmbienceCreator(properties).GetAmbience(data, ScreenCaptureManager.LastCaptureWidth, ScreenCaptureManager.LastCaptureHeight, width, height, properties); var newData = GetAmbienceCreator(properties)
.GetAmbience(data, ScreenCaptureManager.LastCaptureWidth, ScreenCaptureManager.LastCaptureHeight, width,
height, properties);
_lastData = _lastData?.Blend(newData, properties.SmoothMode) ?? newData; _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 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) public void Draw(LayerModel layerModel, DrawingContext c)
{ {
Rect rect = new Rect(layerModel.Properties.X * 4, var rect = new Rect(layerModel.Properties.X*4,
layerModel.Properties.Y * 4, layerModel.Properties.Y*4,
layerModel.Properties.Width * 4, layerModel.Properties.Width*4,
layerModel.Properties.Height * 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) public ImageSource DrawThumbnail(LayerModel layer)
{ {
Rect thumbnailRect = new Rect(0, 0, 18, 18); var thumbnailRect = new Rect(0, 0, 18, 18);
DrawingVisual visual = new DrawingVisual(); var visual = new DrawingVisual();
using (DrawingContext c = visual.RenderOpen()) using (var c = visual.RenderOpen())
c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.ambilight), thumbnailRect); c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.ambilight), thumbnailRect);
return new DrawingImage(visual.Drawing); return new DrawingImage(visual.Drawing);
@ -99,9 +100,12 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight
_lastAmbienceCreatorType = properties.AmbienceCreatorType; _lastAmbienceCreatorType = properties.AmbienceCreatorType;
switch (properties.AmbienceCreatorType) switch (properties.AmbienceCreatorType)
{ {
case AmbienceCreatorType.Mirror: return _lastAmbienceCreator = new AmbienceCreatorMirror(); case AmbienceCreatorType.Mirror:
case AmbienceCreatorType.Extend: return _lastAmbienceCreator = new AmbienceCreatorExtend(); return _lastAmbienceCreator = new AmbienceCreatorMirror();
default: throw new InvalidEnumArgumentException(); case AmbienceCreatorType.Extend:
return _lastAmbienceCreator = new AmbienceCreatorExtend();
default:
throw new InvalidEnumArgumentException();
} }
} }

View File

@ -8,10 +8,13 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Helper
public class CheckboxEnumFlagHelper public class CheckboxEnumFlagHelper
{ {
#region DependencyProperties #region DependencyProperties
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
public static readonly DependencyProperty FlagsProperty = DependencyProperty.RegisterAttached( 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) 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) public static Enum GetFlags(DependencyObject element)
{ {
return (Enum)element.GetValue(FlagsProperty); return (Enum) element.GetValue(FlagsProperty);
} }
public static readonly DependencyProperty ValueProperty = DependencyProperty.RegisterAttached( public static readonly DependencyProperty ValueProperty = DependencyProperty.RegisterAttached(
@ -33,10 +36,11 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Helper
public static Enum GetValue(DependencyObject element) public static Enum GetValue(DependencyObject element)
{ {
return (Enum)element.GetValue(ValueProperty); return (Enum) element.GetValue(ValueProperty);
} }
// ReSharper restore InconsistentNaming // ReSharper restore InconsistentNaming
#endregion #endregion
#region Methods #region Methods
@ -50,7 +54,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Helper
private static void ValueChanged(DependencyObject dependencyObject, private static void ValueChanged(DependencyObject dependencyObject,
DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{ {
CheckBox checkbox = dependencyObject as CheckBox; var checkbox = dependencyObject as CheckBox;
if (checkbox == null) return; if (checkbox == null) return;
checkbox.Checked -= UpdateSource; checkbox.Checked -= UpdateSource;
@ -69,17 +73,17 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Helper
{ {
if (checkbox == null) return; if (checkbox == null) return;
Enum value = GetValue(checkbox); var value = GetValue(checkbox);
checkbox.IsChecked = value != null && (flags?.HasFlag(value) ?? false); checkbox.IsChecked = value != null && (flags?.HasFlag(value) ?? false);
} }
private static void UpdateSource(object sender, RoutedEventArgs routedEventArgs) private static void UpdateSource(object sender, RoutedEventArgs routedEventArgs)
{ {
CheckBox checkbox = sender as CheckBox; var checkbox = sender as CheckBox;
if (checkbox == null) return; if (checkbox == null) return;
Enum flags = GetFlags(checkbox); var flags = GetFlags(checkbox);
Enum value = GetValue(checkbox); var value = GetValue(checkbox);
if (value == null) return; if (value == null) return;
if (checkbox.IsChecked ?? false) if (checkbox.IsChecked ?? false)

View File

@ -4,10 +4,8 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model
{ {
public enum AmbienceCreatorType public enum AmbienceCreatorType
{ {
[Description("Mirror")] [Description("Mirror")] Mirror,
Mirror,
[Description("Extend")] [Description("Extend")] Extend
Extend
} }
} }

View File

@ -9,6 +9,6 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model
Left = 1 << 0, Left = 1 << 0,
Right = 1 << 1, Right = 1 << 1,
Top = 1 << 2, Top = 1 << 2,
Bottom = 1 << 3, Bottom = 1 << 3
} }
} }

View File

@ -23,10 +23,10 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
public static AvgColor[] ExtendHeight(this AvgColor[] colors, int height) 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++) for (var i = 0; i < height; i++)
Array.Copy(colors, 0, extended, i * colors.Length, colors.Length); Array.Copy(colors, 0, extended, i*colors.Length, colors.Length);
return extended; return extended;
} }
@ -35,9 +35,9 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
{ {
if (colors == null || width <= 0) return colors; 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 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]; flipped[i + k] = colors[j + k];
return flipped; return flipped;
@ -47,8 +47,8 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
{ {
if (colors == null || width <= 0) return colors; if (colors == null || width <= 0) return colors;
AvgColor[] flipped = new AvgColor[colors.Length]; var flipped = new AvgColor[colors.Length];
for (int i = 0; i < colors.Length; i += width) for (var i = 0; i < colors.Length; i += width)
for (int j = 0, k = width - 1; j < width; ++j, --k) for (int j = 0, k = width - 1; j < width; ++j, --k)
flipped[i + j] = colors[i + 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) public static byte[] ToBGRArray(this AvgColor[] colors)
{ {
byte[] newData = new byte[colors.Length * 3]; var newData = new byte[colors.Length*3];
int counter = 0; var counter = 0;
foreach (AvgColor color in colors) foreach (var color in colors)
{ {
newData[counter++] = color.B; newData[counter++] = color.B;
newData[counter++] = color.G; newData[counter++] = color.G;

View File

@ -10,15 +10,15 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
{ {
if (e == null || value == null || t == null) return e; if (e == null || value == null || t == null) return e;
int eValue = Convert.ToInt32(e); var eValue = Convert.ToInt32(e);
int valueValue = Convert.ToInt32(value); var valueValue = Convert.ToInt32(value);
if (set) if (set)
eValue |= valueValue; eValue |= valueValue;
else else
eValue &= ~valueValue; eValue &= ~valueValue;
return (Enum)Enum.ToObject(t, eValue); return (Enum) Enum.ToObject(t, eValue);
} }
#endregion #endregion

View File

@ -6,17 +6,18 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
{ {
#region Methods #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; var bottomBorder = height - offsetBottom;
int rightBorder = width - offsetRight; var rightBorder = width - offsetRight;
int blackBarWidth = 0; var blackBarWidth = 0;
for (int x = rightBorder - 1; x >= offsetLeft; x--) 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) if (pixels[offset] > 15 || pixels[offset + 1] > 15 || pixels[offset + 2] > 15)
return blackBarWidth; return blackBarWidth;
} }
@ -26,17 +27,18 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
return width; 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; var bottomBorder = height - offsetBottom;
int rightBorder = width - offsetRight; var rightBorder = width - offsetRight;
int blackBarWidth = 0; var blackBarWidth = 0;
for (int x = offsetLeft; x < rightBorder; x++) 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) if (pixels[offset] > 15 || pixels[offset + 1] > 15 || pixels[offset + 2] > 15)
return blackBarWidth; return blackBarWidth;
} }
@ -46,17 +48,18 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
return width; 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; var bottomBorder = height - offsetBottom;
int rightBorder = width - offsetRight; var rightBorder = width - offsetRight;
int blackBarHeight = 0; var blackBarHeight = 0;
for (int y = offsetTop; y < bottomBorder; y++) 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) if (pixels[offset] > 15 || pixels[offset + 1] > 15 || pixels[offset + 2] > 15)
return blackBarHeight; return blackBarHeight;
} }
@ -66,17 +69,18 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
return height; 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; var bottomBorder = height - offsetBottom;
int rightBorder = width - offsetRight; var rightBorder = width - offsetRight;
int blackBarHeight = 0; var blackBarHeight = 0;
for (int y = bottomBorder - 1; y >= offsetTop; y--) 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) if (pixels[offset] > 15 || pixels[offset + 1] > 15 || pixels[offset + 2] > 15)
return blackBarHeight; return blackBarHeight;
} }
@ -90,20 +94,22 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions
{ {
if (smoothMode == SmoothMode.None || pixels.Length != blendPixels.Length) return blendPixels; 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*/); var percentage = smoothMode == SmoothMode.Low
? 0.25
: (smoothMode == SmoothMode.Medium ? 0.075 : 0.025 /*high*/);
byte[] blended = new byte[pixels.Length]; var blended = new byte[pixels.Length];
for (int i = 0; i < blended.Length; i++) for (var i = 0; i < blended.Length; i++)
blended[i] = GetIntColor((blendPixels[i] / 255.0) * percentage + (pixels[i] / 255.0) * (1 - percentage)); blended[i] = GetIntColor(blendPixels[i]/255.0*percentage + pixels[i]/255.0*(1 - percentage));
return blended; return blended;
} }
private static byte GetIntColor(double d) private static byte GetIntColor(double d)
{ {
double calcF = Math.Max(0, Math.Min(1, d)); var calcF = Math.Max(0, Math.Min(1, d));
return (byte)(calcF.Equals(1) ? 255 : calcF * 256); return (byte) (calcF.Equals(1) ? 255 : calcF*256);
} }
#endregion #endregion

View File

@ -4,7 +4,6 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model
{ {
public enum ScreenCaptureMode public enum ScreenCaptureMode
{ {
[Description("DirectX 9")] [Description("DirectX 9")] DirectX9
DirectX9
} }
} }

View File

@ -4,16 +4,12 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model
{ {
public enum SmoothMode public enum SmoothMode
{ {
[Description("None")] [Description("None")] None,
None,
[Description("Low")] [Description("Low")] Low,
Low,
[Description("Medium")] [Description("Medium")] Medium,
Medium,
[Description("High")] [Description("High")] High
High
} }
} }

View File

@ -2,25 +2,12 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Media; using System.Windows.Media;
using SharpDX;
using SharpDX.Direct3D9; using SharpDX.Direct3D9;
namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
{ {
public class DX9ScreenCapture : IScreenCapture 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 #region Constructors
public DX9ScreenCapture() public DX9ScreenCapture()
@ -28,26 +15,39 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
Width = Screen.PrimaryScreen.Bounds.Width; Width = Screen.PrimaryScreen.Bounds.Width;
Height = Screen.PrimaryScreen.Bounds.Height; Height = Screen.PrimaryScreen.Bounds.Height;
PresentParameters presentParams = new PresentParameters(Width, Height) var presentParams = new PresentParameters(Width, Height)
{ {
Windowed = true, Windowed = true,
SwapEffect = SwapEffect.Discard 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); _surface = Surface.CreateOffscreenPlain(_device, Width, Height, Format.A8R8G8B8, Pool.Scratch);
_buffer = new byte[Width * Height * 4]; _buffer = new byte[Width*Height*4];
} }
#endregion #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 #region Methods
public byte[] CaptureScreen() public byte[] CaptureScreen()
{ {
_device.GetFrontBufferData(0, _surface); _device.GetFrontBufferData(0, _surface);
DataRectangle dr = _surface.LockRectangle(LockFlags.None); var dr = _surface.LockRectangle(LockFlags.None);
Marshal.Copy(dr.DataPointer, _buffer, 0, _buffer.Length); Marshal.Copy(dr.DataPointer, _buffer, 0, _buffer.Length);
_surface.UnlockRectangle(); _surface.UnlockRectangle();

View File

@ -10,7 +10,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
PixelFormat PixelFormat { get; } PixelFormat PixelFormat { get; }
/// <summary> /// <summary>
/// As Pixel-Data BGRA /// As Pixel-Data BGRA
/// </summary> /// </summary>
/// <returns>The Pixel-Data</returns> /// <returns>The Pixel-Data</returns>
byte[] CaptureScreen(); byte[] CaptureScreen();

View File

@ -14,13 +14,14 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
private static Thread _worker; private static Thread _worker;
private static DateTime _lastCaptureAccess; private static DateTime _lastCaptureAccess;
private static volatile byte[] _lastScreenCapture; 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; private static IScreenCapture _screenCapture;
public static double StandByTime { get; set; } = 3; 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 ScreenCaptureMode ScreenCaptureMode { get; set; } = ScreenCaptureMode.DirectX9;
public static int LastCaptureWidth { get; private set; } public static int LastCaptureWidth { get; private set; }
@ -41,8 +42,10 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
_lastScreenCaptureMode = ScreenCaptureMode; _lastScreenCaptureMode = ScreenCaptureMode;
switch (ScreenCaptureMode) switch (ScreenCaptureMode)
{ {
case ScreenCaptureMode.DirectX9: return _screenCapture = new DX9ScreenCapture(); case ScreenCaptureMode.DirectX9:
default: throw new InvalidEnumArgumentException(); 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) while ((DateTime.Now - _lastCaptureAccess).TotalSeconds < StandByTime)
{ {
DateTime lastCapture = DateTime.Now; var lastCapture = DateTime.Now;
try try
{ {
CaptureScreen(); CaptureScreen();
@ -69,7 +72,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
Debug.WriteLine("[CaptureLoop]: " + ex.Message); 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) if (sleep > 0)
Thread.Sleep(sleep); Thread.Sleep(sleep);
} }
@ -83,7 +86,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
private static void CaptureScreen() private static void CaptureScreen()
{ {
IScreenCapture screenCapture = GetScreenCapture(); var screenCapture = GetScreenCapture();
_lastScreenCapture = screenCapture.CaptureScreen(); _lastScreenCapture = screenCapture.CaptureScreen();
LastCaptureWidth = screenCapture.Width; LastCaptureWidth = screenCapture.Width;

View File

@ -21,11 +21,11 @@ namespace Artemis.Profiles.Layers.Types.Audio
{ {
internal class AudioType : ILayerType internal class AudioType : ILayerType
{ {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly List<LayerModel> _audioLayers = new List<LayerModel>(); private readonly List<LayerModel> _audioLayers = new List<LayerModel>();
private readonly MMDevice _device; private readonly MMDevice _device;
private readonly SampleAggregator _sampleAggregator = new SampleAggregator(1024); private readonly SampleAggregator _sampleAggregator = new SampleAggregator(1024);
private readonly WasapiLoopbackCapture _waveIn; private readonly WasapiLoopbackCapture _waveIn;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private int _lines; private int _lines;
private AudioPropertiesModel _previousSettings; private AudioPropertiesModel _previousSettings;

View File

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Windows;
using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using Artemis.Models.Interfaces; using Artemis.Models.Interfaces;
using Artemis.Profiles.Layers.Abstract; using Artemis.Profiles.Layers.Abstract;
@ -13,7 +12,7 @@ namespace Artemis.Profiles.Layers.Types.Folder
{ {
public class FolderType : ILayerType public class FolderType : ILayerType
{ {
public string Name { get; } = "Folder"; public string Name => "Folder";
public bool ShowInEdtor { get; } = false; public bool ShowInEdtor { get; } = false;
// FolderType pretents to be a keyboard so it's children get drawn // FolderType pretents to be a keyboard so it's children get drawn
public DrawType DrawType { get; } = DrawType.Keyboard; public DrawType DrawType { get; } = DrawType.Keyboard;

View File

@ -1,12 +1,13 @@
<UserControl <UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 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:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ncore="http://schemas.ncore.com/wpf/xaml/colorbox" 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" xmlns:ObjectModel="clr-namespace:System.Collections.ObjectModel;assembly=System"
mc:Ignorable="d" x:Class="Artemis.Profiles.Layers.Types.Generic.GenericPropertiesView"
d:DesignHeight="600" d:DesignWidth="500"> mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="500">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition /> <ColumnDefinition />
@ -24,10 +25,10 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<!-- Animation --> <!-- Animation -->
<TextBlock Grid.Row="0" Grid.Column="0" Margin="10" FontSize="13.333" Text="Animation:" <TextBlock Grid.Row="0" Grid.Column="0" Margin="10" FontSize="13.333" Text="Animation:"
VerticalAlignment="Center" VerticalAlignment="Center"
Height="18" /> Height="18" />
<ComboBox Grid.Row="0" Grid.Column="1" Margin="10,10,10,0" x:Name="LayerAnimations" VerticalAlignment="Top" <ComboBox Grid.Row="0" Grid.Column="1" Margin="10,10,10,0" x:Name="LayerAnimations" VerticalAlignment="Top"
Height="22"> Height="22">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding Name, Mode=OneWay}" /> <TextBlock Text="{Binding Name, Mode=OneWay}" />
@ -37,33 +38,41 @@
<!-- Animation Speed --> <!-- Animation Speed -->
<TextBlock Grid.Row="0" Grid.Column="2" Margin="10" FontSize="13.333" Text="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" <Slider x:Name="RotationSpeed" Grid.Row="0" Grid.Column="3" VerticalAlignment="Center"
TickPlacement="None" TickFrequency="0.05" TickPlacement="None" TickFrequency="0.05"
Value="{Binding LayerModel.Properties.AnimationSpeed, Mode=TwoWay}" Minimum="0.05" Maximum="3" Value="{Binding LayerModel.Properties.AnimationSpeed, Mode=TwoWay}" Minimum="0.05" Maximum="3"
SmallChange="0" IsSnapToTickEnabled="True" Margin="10,12,10,2" Height="24" /> SmallChange="0" IsSnapToTickEnabled="True" Margin="10,12,10,2" Height="24" />
<!-- Colors --> <!-- Colors -->
<StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" x:Name="ShowBrush"> <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):" <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}" <Border Margin="10" BorderBrush="{StaticResource ControlBorderBrush}"
BorderThickness="1" SnapsToDevicePixels="True" ToolTip="Click to edit"> BorderThickness="1" SnapsToDevicePixels="True" ToolTip="Click to edit">
<ncore:ColorBox Brush="{Binding Brush, Mode=TwoWay}" Height="24" Width="134"/> <ncore:ColorBox Brush="{Binding Brush, Mode=TwoWay}" Height="24" Width="134" />
</Border> </Border>
</StackPanel> </StackPanel>
<!-- Dynamic --> <!-- Dynamic -->
<Label Grid.Row="3" Grid.Column="0" FontSize="20" HorizontalAlignment="Left" <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 --> <!-- Dynamic property views -->
<ContentControl Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="4" x:Name="OpacityProperties" /> <ContentControl Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="4" x:Name="OpacityProperties" />
<!-- Note --> <!-- Note -->
<TextBlock Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="4" Margin="10,2,10,10" FontSize="13.333" <TextBlock Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="4" Margin="10,2,10,10" FontSize="13.333"
Foreground="{DynamicResource HighlightBrush}" 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 VerticalAlignment="Top" Height="Auto" TextWrapping="Wrap">
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> <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> </Grid>
</UserControl> </UserControl>

View File

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Linq;
using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using Artemis.Models.Interfaces; using Artemis.Models.Interfaces;
@ -15,7 +14,7 @@ namespace Artemis.Profiles.Layers.Types.Generic
{ {
public class GenericType : ILayerType public class GenericType : ILayerType
{ {
public string Name { get; } = "Generic (Logitech)"; public string Name => "Generic (Logitech)";
public bool ShowInEdtor { get; } = false; public bool ShowInEdtor { get; } = false;
public DrawType DrawType { get; } = DrawType.Generic; public DrawType DrawType { get; } = DrawType.Generic;

View File

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Linq;
using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using Artemis.Models.Interfaces; using Artemis.Models.Interfaces;
@ -15,7 +14,7 @@ namespace Artemis.Profiles.Layers.Types.Headset
{ {
public class HeadsetType : ILayerType public class HeadsetType : ILayerType
{ {
public string Name { get; } = "Headset"; public string Name => "Headset";
public bool ShowInEdtor { get; } = false; public bool ShowInEdtor { get; } = false;
public DrawType DrawType { get; } = DrawType.Headset; public DrawType DrawType { get; } = DrawType.Headset;

View File

@ -32,7 +32,7 @@ namespace Artemis.Profiles.Layers.Types.KeyPress
public RadialGradientBrush TempBrush { get; set; } public RadialGradientBrush TempBrush { get; set; }
public string Name { get; } = "Keyboard - Key press"; public string Name => "Keyboard - Key press";
public bool ShowInEdtor { get; } = false; public bool ShowInEdtor { get; } = false;
public DrawType DrawType { get; } = DrawType.Keyboard; public DrawType DrawType { get; } = DrawType.Keyboard;

View File

@ -60,7 +60,7 @@
VerticalAlignment="Top" Height="18" Width="130" /> VerticalAlignment="Top" Height="18" Width="130" />
<Border Margin="10" BorderBrush="{StaticResource ControlBorderBrush}" <Border Margin="10" BorderBrush="{StaticResource ControlBorderBrush}"
BorderThickness="1" SnapsToDevicePixels="True" ToolTip="Click to edit"> 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> </Border>
</StackPanel> </StackPanel>

View File

@ -11,7 +11,7 @@ namespace Artemis.Profiles.Layers.Types.Keyboard
{ {
public class KeyboardType : ILayerType public class KeyboardType : ILayerType
{ {
public string Name { get; } = "Keyboard"; public string Name => "Keyboard";
public bool ShowInEdtor { get; } = true; public bool ShowInEdtor { get; } = true;
public DrawType DrawType { get; } = DrawType.Keyboard; public DrawType DrawType { get; } = DrawType.Keyboard;

View File

@ -15,7 +15,7 @@ namespace Artemis.Profiles.Layers.Types.KeyboardGif
{ {
internal class KeyboardGifType : ILayerType internal class KeyboardGifType : ILayerType
{ {
public string Name { get; } = "Keyboard - GIF"; public string Name => "Keyboard - GIF";
public bool ShowInEdtor { get; } = true; public bool ShowInEdtor { get; } = true;
public DrawType DrawType { get; } = DrawType.Keyboard; public DrawType DrawType { get; } = DrawType.Keyboard;

View File

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Linq;
using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using Artemis.Models.Interfaces; using Artemis.Models.Interfaces;
@ -15,7 +14,7 @@ namespace Artemis.Profiles.Layers.Types.Mouse
{ {
public class MouseType : ILayerType public class MouseType : ILayerType
{ {
public string Name { get; } = "Mouse"; public string Name => "Mouse";
public bool ShowInEdtor { get; } = false; public bool ShowInEdtor { get; } = false;
public DrawType DrawType { get; } = DrawType.Mouse; public DrawType DrawType { get; } = DrawType.Mouse;

View File

@ -14,7 +14,7 @@ namespace Artemis.Profiles.Layers.Types.Mousemat
{ {
public class MousematType : ILayerType public class MousematType : ILayerType
{ {
public string Name { get; } = "Mousemat"; public string Name => "Mousemat";
public bool ShowInEdtor { get; } = false; public bool ShowInEdtor { get; } = false;
public DrawType DrawType { get; } = DrawType.Mousemat; public DrawType DrawType { get; } = DrawType.Mousemat;