Added Bgra32 type

このコミットが含まれているのは:
Sergio Pedri committed 2021-01-04 23:39:11 +01:00
1 親 2dd0549eec
コミット 050182367f
3ファイル変更
+136

検索条件に一致するファイルはありません

+1
ファイルの表示
@@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
</ItemGroup>
</Project>
+119
ファイルの表示
@@ -0,0 +1,119 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.__Internals;
#pragma warning disable CS0618
namespace ComputeSharp
{
/// <summary>
/// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
/// The color components are stored in blue, green, red, and alpha order (least significant to most significant byte).
/// The format is binary compatible with System.Drawing.Imaging.PixelFormat.Format32bppArgb.
/// <para>
/// Ranges from [0, 0, 0, 0] to [1, 1, 1, 1] in vector form.
/// </para>
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct Bgra32 : IEquatable<Bgra32>, IUnorm<Vector4>, IUnorm<Float4>, IUnorm<Double4>
{
/// <summary>
/// The blue component.
/// </summary>
public byte B;
/// <summary>
/// The green component.
/// </summary>
public byte G;
/// <summary>
/// The red component.
/// </summary>
public byte R;
/// <summary>
/// The alpha component.
/// </summary>
public byte A;
/// <summary>
/// Initializes a new instance of the <see cref="Bgra32"/> struct.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Bgra32(byte r, byte g, byte b)
{
R = r;
G = g;
B = b;
A = byte.MaxValue;
}
/// <summary>
/// Initializes a new instance of the <see cref="Bgra32"/> struct.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Bgra32(byte r, byte g, byte b, byte a)
{
R = r;
G = g;
B = b;
A = a;
}
/// <summary>
/// Gets or sets the packed representation of the <see cref="Bgra32"/> struct.
/// </summary>
public uint PackedValue
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => Unsafe.As<Bgra32, uint>(ref Unsafe.AsRef(this));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set => Unsafe.As<Bgra32, uint>(ref this) = value;
}
/// <summary>
/// Compares two <see cref="Bgra32"/> objects for equality.
/// </summary>
/// <param name="left">The <see cref="Bgra32"/> on the left side of the operand.</param>
/// <param name="right">The <see cref="Bgra32"/> on the right side of the operand.</param>
/// <returns>
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Bgra32 left, Bgra32 right) => left.Equals(right);
/// <summary>
/// Compares two <see cref="Bgra32"/> objects for equality.
/// </summary>
/// <param name="left">The <see cref="Bgra32"/> on the left side of the operand.</param>
/// <param name="right">The <see cref="Bgra32"/> on the right side of the operand.</param>
/// <returns>
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Bgra32 left, Bgra32 right) => !left.Equals(right);
/// <inheritdoc/>
public override readonly bool Equals(object? obj) => obj is Bgra32 other && Equals(other);
/// <inheritdoc/>
public readonly bool Equals(Bgra32 other) => PackedValue.Equals(other.PackedValue);
/// <inheritdoc/>
public override readonly int GetHashCode() => PackedValue.GetHashCode();
/// <inheritdoc />
public override readonly string ToString() => $"{nameof(Bgra32)}({this.B}, {this.G}, {this.R}, {this.A})";
}
}
+16
ファイルの表示
@@ -0,0 +1,16 @@
using System;
using System.ComponentModel;
namespace ComputeSharp.__Internals
{
/// <summary>
/// Indicates the supported HLSL pixel types to represent a given normalized pixel type.
/// </summary>
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This interface is not intended to be used directly by user code")]
public interface IUnorm<TPixel>
where TPixel : unmanaged
{
}
}