Skip to content

Commit

Permalink
Merge pull request #396 from DarthAffe/HPPH
Browse files Browse the repository at this point in the history
Added HPPH Image texture in presets; Removed old .NET versions
  • Loading branch information
DarthAffe authored Jul 21, 2024
2 parents 0d41314 + cfbbdc6 commit 681adcb
Show file tree
Hide file tree
Showing 24 changed files with 144 additions and 21 deletions.
2 changes: 1 addition & 1 deletion RGB.NET.Core/Devices/AbstractRGBDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public virtual void Update(bool flushLeds = false)
/// Applies all <see cref="ColorCorrections"/>.
/// if no <see cref="Led.CustomData"/> ist specified the <see cref="Led.Id"/> is used.
/// </remarks>
/// <param name="leds">The enumerable of leds to convert.</param>
/// <param name="led">The of led to convert.</param>
/// <returns>The enumerable of custom data and color tuples for the specified leds.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected (object key, Color color) GetUpdateData(Led led)
Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Core/RGB.NET.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.WLED/RGB.NET.Devices.WLED.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.HID/RGB.NET.HID.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion RGB.NET.Layout/RGB.NET.Layout.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down
27 changes: 27 additions & 0 deletions RGB.NET.Presets/Extensions/HPPHExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using HPPH;
using RGB.NET.Core;

namespace RGB.NET.Presets.Extensions;

/// <summary>
/// Offers some extensions related to HPPH.
/// </summary>
public static class HPPHExtensions
{
/// <summary>
/// Converts the given HPPH <see cref="IColor"/> to a RGB.NET <see cref="Color"/>.

Check warning on line 12 in RGB.NET.Presets/Extensions/HPPHExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Ambiguous reference in cref attribute: 'Color'. Assuming 'Color', but could have also matched other overloads including 'Color'.

Check warning on line 12 in RGB.NET.Presets/Extensions/HPPHExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Ambiguous reference in cref attribute: 'Color'. Assuming 'Color', but could have also matched other overloads including 'Color'.
/// </summary>
/// <param name="color">The color to convert.</param>
/// <returns>The converted color.</returns>
public static Color ToColor(this IColor color) => new(color.A, color.R, color.G, color.B);

/// <summary>
/// Converts the given HPPH <see cref="IColor"/> to a RGB.NET <see cref="Color"/>.

Check warning on line 19 in RGB.NET.Presets/Extensions/HPPHExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Ambiguous reference in cref attribute: 'Color'. Assuming 'Color', but could have also matched other overloads including 'Color'.

Check warning on line 19 in RGB.NET.Presets/Extensions/HPPHExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Ambiguous reference in cref attribute: 'Color'. Assuming 'Color', but could have also matched other overloads including 'Color'.
/// </summary>
/// <param name="color">The color to convert.</param>
/// <typeparam name="T">The color-type of the HPPH color.</typeparam>
/// <returns>The converted color.</returns>
public static Color ToColor<T>(this T color)
where T : struct, IColor
=> new(color.A, color.R, color.G, color.B);
}
6 changes: 5 additions & 1 deletion RGB.NET.Presets/RGB.NET.Presets.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

Expand Down Expand Up @@ -57,6 +57,10 @@
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="HPPH" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RGB.NET.Core\RGB.NET.Core.csproj" />
</ItemGroup>
Expand Down
91 changes: 91 additions & 0 deletions RGB.NET.Presets/Textures/ImageTexture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using HPPH;
using RGB.NET.Core;
using RGB.NET.Presets.Extensions;

namespace RGB.NET.Presets.Textures;

/// <inheritdoc />
/// <summary>
/// Represents a texture drawing an <see cref="IImage"/>.
/// </summary>
public sealed class ImageTexture : ITexture
{
#region Properties & Fields

private IImage _image;

/// <summary>
/// The image drawn by this texture.
/// </summary>
public IImage Image
{
get => _image;
set
{
ArgumentNullException.ThrowIfNull(value);
_image = value;
}
}

/// <inheritdoc />
public Size Size { get; }

/// <inheritdoc />
public Color this[Point point]
{
get
{
int x = (int)MathF.Round((Size.Width - 1) * point.X.Clamp(0, 1));
int y = (int)MathF.Round((Size.Height - 1) * point.Y.Clamp(0, 1));

return Image[x, y].ToColor();
}
}

/// <inheritdoc />
public Color this[Rectangle rectangle]
{
get
{
int x = (int)MathF.Round((Size.Width - 1) * rectangle.Location.X.Clamp(0, 1));
int y = (int)MathF.Round((Size.Height - 1) * rectangle.Location.Y.Clamp(0, 1));
int width = (int)MathF.Round(Size.Width * rectangle.Size.Width.Clamp(0, 1));
int height = (int)MathF.Round(Size.Height * rectangle.Size.Height.Clamp(0, 1));

if ((width == 0) && (rectangle.Size.Width > 0)) width = 1;
if ((height == 0) && (rectangle.Size.Height > 0)) height = 1;

return this[x, y, width, height];
}
}

/// <summary>
/// Gets the sampled color inside the specified region.
/// </summary>
/// <param name="x">The x-location of the region.</param>
/// <param name="y">The y-location of the region.</param>
/// <param name="width">The with of the region.</param>
/// <param name="height">The height of the region.</param>
/// <returns>The sampled color.</returns>
public Color this[int x, int y, int width, int height] => Image[x, y, width, height].Average().ToColor();

#endregion

#region Constructors

/// <summary>
/// Initializes a new instance of the <see cref="ImageTexture" /> class.
/// </summary>
/// <param name="image">The image represented by the texture.</param>
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public ImageTexture(IImage image)
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
{
this.Image = image;

Size = new Size(image.Width, image.Height);
}

#endregion
}
1 change: 1 addition & 0 deletions RGB.NET.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GEZ/@EntryIndexedValue">GEZ</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GSDK/@EntryIndexedValue">GSDK</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HID/@EntryIndexedValue">HID</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HPPH/@EntryIndexedValue">HPPH</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HS/@EntryIndexedValue">HS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HSV/@EntryIndexedValue">HSV</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IBAN/@EntryIndexedValue">IBAN</s:String>
Expand Down

0 comments on commit 681adcb

Please sign in to comment.