mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Added support for HPPH-images in presets
This commit is contained in:
parent
4c3875e561
commit
b1cf26b1e6
27
RGB.NET.Presets/Extensions/HPPHExtensions.cs
Normal file
27
RGB.NET.Presets/Extensions/HPPHExtensions.cs
Normal file
@ -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"/>.
|
||||
/// </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"/>.
|
||||
/// </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);
|
||||
}
|
||||
@ -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>
|
||||
|
||||
76
RGB.NET.Presets/Textures/ImageTexture.cs
Normal file
76
RGB.NET.Presets/Textures/ImageTexture.cs
Normal file
@ -0,0 +1,76 @@
|
||||
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 readonly IImage _image;
|
||||
|
||||
/// <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>
|
||||
public ImageTexture(IImage image)
|
||||
{
|
||||
this._image = image;
|
||||
|
||||
Size = new Size(image.Width, image.Height);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -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>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user