diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
index a988e22b2f..0273f02f56 100644
--- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
+++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
@@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Advanced
/// therefore it's not recommended to mutate the image while holding a reference to it's .
///
public static IMemoryGroup GetPixelMemoryGroup(this ImageFrame source)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
=> source?.PixelBuffer.FastMemoryGroup.View ?? throw new ArgumentNullException(nameof(source));
///
@@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Advanced
/// therefore it's not recommended to mutate the image while holding a reference to it's .
///
public static IMemoryGroup GetPixelMemoryGroup(this Image source)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
=> source?.Frames.RootFrame.GetPixelMemoryGroup() ?? throw new ArgumentNullException(nameof(source));
///
@@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.Advanced
[Obsolete(
@"GetPixelSpan might fail, because the backing buffer could be discontiguous for large images. Use GetPixelMemoryGroup or GetPixelRowSpan instead!")]
public static Span GetPixelSpan(this ImageFrame source)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
Guard.NotNull(source, nameof(source));
@@ -113,7 +113,7 @@ namespace SixLabors.ImageSharp.Advanced
[Obsolete(
@"GetPixelSpan might fail, because the backing buffer could be discontiguous for large images. Use GetPixelMemoryGroup or GetPixelRowSpan instead!")]
public static Span GetPixelSpan(this Image source)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
Guard.NotNull(source, nameof(source));
@@ -129,7 +129,7 @@ namespace SixLabors.ImageSharp.Advanced
/// The row.
/// The
public static Span GetPixelRowSpan(this ImageFrame source, int rowIndex)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
Guard.NotNull(source, nameof(source));
Guard.MustBeGreaterThanOrEqualTo(rowIndex, 0, nameof(rowIndex));
@@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Advanced
/// The row.
/// The
public static Span GetPixelRowSpan(this Image source, int rowIndex)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
Guard.NotNull(source, nameof(source));
Guard.MustBeGreaterThanOrEqualTo(rowIndex, 0, nameof(rowIndex));
@@ -165,7 +165,7 @@ namespace SixLabors.ImageSharp.Advanced
/// The row.
/// The
public static Memory GetPixelRowMemory(this ImageFrame source, int rowIndex)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
Guard.NotNull(source, nameof(source));
Guard.MustBeGreaterThanOrEqualTo(rowIndex, 0, nameof(rowIndex));
@@ -183,7 +183,7 @@ namespace SixLabors.ImageSharp.Advanced
/// The row.
/// The
public static Memory GetPixelRowMemory(this Image source, int rowIndex)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
Guard.NotNull(source, nameof(source));
Guard.MustBeGreaterThanOrEqualTo(rowIndex, 0, nameof(rowIndex));
diff --git a/src/ImageSharp/Advanced/AotCompilerTools.cs b/src/ImageSharp/Advanced/AotCompilerTools.cs
index c8c8568e4d..23ae62c7a1 100644
--- a/src/ImageSharp/Advanced/AotCompilerTools.cs
+++ b/src/ImageSharp/Advanced/AotCompilerTools.cs
@@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.Advanced
///
/// The pixel format.
private static void Seed()
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
// This is we actually call all the individual methods you need to seed.
AotCompileOctreeQuantizer();
@@ -110,7 +110,7 @@ namespace SixLabors.ImageSharp.Advanced
///
/// The pixel format.
private static void AotCompileOctreeQuantizer()
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
using (var test = new OctreeFrameQuantizer(Configuration.Default, new OctreeQuantizer().Options))
{
@@ -124,7 +124,7 @@ namespace SixLabors.ImageSharp.Advanced
///
/// The pixel format.
private static void AotCompileWuQuantizer()
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
using (var test = new WuFrameQuantizer(Configuration.Default, new WuQuantizer().Options))
{
@@ -138,7 +138,7 @@ namespace SixLabors.ImageSharp.Advanced
///
/// The pixel format.
private static void AotCompilePaletteQuantizer()
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
using (var test = (PaletteFrameQuantizer)new PaletteQuantizer(Array.Empty()).CreateFrameQuantizer(Configuration.Default))
{
@@ -152,7 +152,7 @@ namespace SixLabors.ImageSharp.Advanced
///
/// The pixel format.
private static void AotCompileDithering()
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
ErrorDither errorDither = ErrorDither.FloydSteinberg;
OrderedDither orderedDither = OrderedDither.Bayer2x2;
@@ -171,7 +171,7 @@ namespace SixLabors.ImageSharp.Advanced
/// The image encoder to seed.
/// The pixel format.
private static void AotCodec(IImageDecoder decoder, IImageEncoder encoder)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
try
{
@@ -195,7 +195,7 @@ namespace SixLabors.ImageSharp.Advanced
///
/// The pixel format.
private static void AotCompilePixelOperations()
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
var pixelOp = new PixelOperations();
pixelOp.GetPixelBlender(PixelColorBlendingMode.Normal, PixelAlphaCompositionMode.Clear);
diff --git a/src/ImageSharp/Advanced/IImageVisitor.cs b/src/ImageSharp/Advanced/IImageVisitor.cs
index ba8b13e2e8..079db42c07 100644
--- a/src/ImageSharp/Advanced/IImageVisitor.cs
+++ b/src/ImageSharp/Advanced/IImageVisitor.cs
@@ -17,6 +17,6 @@ namespace SixLabors.ImageSharp.Advanced
/// The image.
/// The pixel type.
void Visit(Image image)
- where TPixel : struct, IPixel;
+ where TPixel : unmanaged, IPixel;
}
}
diff --git a/src/ImageSharp/Advanced/IPixelSource.cs b/src/ImageSharp/Advanced/IPixelSource.cs
index a321e877ba..d7162bc61f 100644
--- a/src/ImageSharp/Advanced/IPixelSource.cs
+++ b/src/ImageSharp/Advanced/IPixelSource.cs
@@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Advanced
///
/// The type of the pixel.
internal interface IPixelSource
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
///
/// Gets the pixel buffer.
diff --git a/src/ImageSharp/Color/Color.cs b/src/ImageSharp/Color/Color.cs
index fcf091638e..e0f9d1e8d1 100644
--- a/src/ImageSharp/Color/Color.cs
+++ b/src/ImageSharp/Color/Color.cs
@@ -220,7 +220,7 @@ namespace SixLabors.ImageSharp
/// The pixel value.
[MethodImpl(InliningOptions.ShortMethod)]
public TPixel ToPixel()
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
TPixel pixel = default;
pixel.FromRgba64(this.data);
@@ -239,7 +239,7 @@ namespace SixLabors.ImageSharp
Configuration configuration,
ReadOnlySpan source,
Span destination)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
ReadOnlySpan rgba64Span = MemoryMarshal.Cast(source);
PixelOperations.Instance.FromRgba64(configuration, rgba64Span, destination);
diff --git a/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs b/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs
index f827746015..312ab388d7 100644
--- a/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs
+++ b/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs
@@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp
int maxRow,
int minColumn,
int maxColumn)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
ComplexVector4 vector = default;
int kernelLength = kernel.Length;
diff --git a/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs b/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs
index ff6e3a4ec6..bd25a7b440 100644
--- a/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs
+++ b/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs
@@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp
int maxRow,
int minColumn,
int maxColumn)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
Convolve2DImpl(
in matrixY,
@@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp
int maxRow,
int minColumn,
int maxColumn)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
Convolve2DImpl(
in matrixY,
@@ -121,7 +121,7 @@ namespace SixLabors.ImageSharp
int minColumn,
int maxColumn,
out Vector4 vector)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
Vector4 vectorY = default;
Vector4 vectorX = default;
@@ -175,7 +175,7 @@ namespace SixLabors.ImageSharp
int maxRow,
int minColumn,
int maxColumn)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
Vector4 vector = default;
@@ -222,7 +222,7 @@ namespace SixLabors.ImageSharp
int maxRow,
int minColumn,
int maxColumn)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
Vector4 vector = default;
@@ -253,7 +253,7 @@ namespace SixLabors.ImageSharp
int minColumn,
int maxColumn,
ref Vector4 vector)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
int matrixHeight = matrix.Rows;
int matrixWidth = matrix.Columns;
diff --git a/src/ImageSharp/Common/Helpers/ImageMaths.cs b/src/ImageSharp/Common/Helpers/ImageMaths.cs
index a0ce30212f..92430c915d 100644
--- a/src/ImageSharp/Common/Helpers/ImageMaths.cs
+++ b/src/ImageSharp/Common/Helpers/ImageMaths.cs
@@ -269,7 +269,7 @@ namespace SixLabors.ImageSharp
/// The .
///
public static Rectangle GetFilteredBoundingRectangle(ImageFrame bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
int width = bitmap.Width;
int height = bitmap.Height;
diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs b/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs
index bc07fbf317..690bf83095 100644
--- a/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs
+++ b/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs
@@ -94,17 +94,17 @@ namespace SixLabors.ImageSharp
var magicInt = new Vector(1191182336); // reinterpreted value of 32768.0f
var mask = new Vector(255);
- ref Octet.OfByte sourceBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source));
- ref Octet.OfUInt32 destBaseAsWideOctet = ref Unsafe.As(ref MemoryMarshal.GetReference(dest));
+ ref Octet sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source));
+ ref Octet destBaseAsWideOctet = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest));
- ref Vector destBaseAsFloat = ref Unsafe.As>(ref destBaseAsWideOctet);
+ ref Vector destBaseAsFloat = ref Unsafe.As, Vector>(ref destBaseAsWideOctet);
int n = dest.Length / 8;
for (int i = 0; i < n; i++)
{
- ref Octet.OfByte s = ref Unsafe.Add(ref sourceBase, i);
- ref Octet.OfUInt32 d = ref Unsafe.Add(ref destBaseAsWideOctet, i);
+ ref Octet s = ref Unsafe.Add(ref sourceBase, i);
+ ref Octet d = ref Unsafe.Add(ref destBaseAsWideOctet, i);
d.LoadFrom(ref s);
}
@@ -137,17 +137,17 @@ namespace SixLabors.ImageSharp
}
ref Vector srcBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source));
- ref Octet.OfByte destBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest));
+ ref Octet destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest));
int n = source.Length / 8;
var magick = new Vector(32768.0f);
var scale = new Vector(255f) / new Vector(256f);
// need to copy to a temporary struct, because
- // SimdUtils.Octet.OfUInt32 temp = Unsafe.As, SimdUtils.Octet.OfUInt32>(ref x)
+ // SimdUtils.Octet temp = Unsafe.As, SimdUtils.Octet>(ref x)
// does not work. TODO: This might be a CoreClr bug, need to ask/report
- var temp = default(Octet.OfUInt32);
- ref Vector tempRef = ref Unsafe.As>(ref temp);
+ var temp = default(Octet);
+ ref Vector tempRef = ref Unsafe.As, Vector>(ref temp);
for (int i = 0; i < n; i++)
{
@@ -161,7 +161,7 @@ namespace SixLabors.ImageSharp
x = (x * scale) + magick;
tempRef = x;
- ref Octet.OfByte d = ref Unsafe.Add(ref destBase, i);
+ ref Octet d = ref Unsafe.Add(ref destBase, i);
d.LoadFrom(ref temp);
}
}
@@ -186,17 +186,17 @@ namespace SixLabors.ImageSharp
}
ref Vector srcBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source));
- ref Octet.OfByte destBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest));
+ ref Octet destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest));
int n = source.Length / 8;
var magick = new Vector(32768.0f);
var scale = new Vector(255f) / new Vector(256f);
// need to copy to a temporary struct, because
- // SimdUtils.Octet.OfUInt32 temp = Unsafe.As, SimdUtils.Octet.OfUInt32>(ref x)
+ // SimdUtils.Octet temp = Unsafe.As, SimdUtils.Octet>(ref x)
// does not work. TODO: This might be a CoreClr bug, need to ask/report
- var temp = default(Octet.OfUInt32);
- ref Vector tempRef = ref Unsafe.As>(ref temp);
+ var temp = default(Octet);
+ ref Vector tempRef = ref Unsafe.As, Vector>(ref temp);
for (int i = 0; i < n; i++)
{
@@ -207,7 +207,7 @@ namespace SixLabors.ImageSharp
x = (x * scale) + magick;
tempRef = x;
- ref Octet.OfByte d = ref Unsafe.Add(ref destBase, i);
+ ref Octet d = ref Unsafe.Add(ref destBase, i);
d.LoadFrom(ref temp);
}
}
diff --git a/src/ImageSharp/Common/Tuples/Octet.cs b/src/ImageSharp/Common/Tuples/Octet.cs
deleted file mode 100644
index 7ece2ed562..0000000000
--- a/src/ImageSharp/Common/Tuples/Octet.cs
+++ /dev/null
@@ -1,112 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace SixLabors.ImageSharp.Tuples
-{
- ///
- /// Contains 8 element value tuples of various types.
- ///
- internal static class Octet
- {
- ///
- /// Value tuple of -s.
- ///
- [StructLayout(LayoutKind.Explicit, Size = 8 * sizeof(uint))]
- public struct OfUInt32
- {
- [FieldOffset(0 * sizeof(uint))]
- public uint V0;
-
- [FieldOffset(1 * sizeof(uint))]
- public uint V1;
-
- [FieldOffset(2 * sizeof(uint))]
- public uint V2;
-
- [FieldOffset(3 * sizeof(uint))]
- public uint V3;
-
- [FieldOffset(4 * sizeof(uint))]
- public uint V4;
-
- [FieldOffset(5 * sizeof(uint))]
- public uint V5;
-
- [FieldOffset(6 * sizeof(uint))]
- public uint V6;
-
- [FieldOffset(7 * sizeof(uint))]
- public uint V7;
-
- public override string ToString()
- {
- return $"{nameof(Octet)}.{nameof(OfUInt32)}({this.V0},{this.V1},{this.V2},{this.V3},{this.V4},{this.V5},{this.V6},{this.V7})";
- }
-
- [MethodImpl(InliningOptions.ShortMethod)]
- public void LoadFrom(ref OfByte src)
- {
- this.V0 = src.V0;
- this.V1 = src.V1;
- this.V2 = src.V2;
- this.V3 = src.V3;
- this.V4 = src.V4;
- this.V5 = src.V5;
- this.V6 = src.V6;
- this.V7 = src.V7;
- }
- }
-
- ///
- /// Value tuple of -s
- ///
- [StructLayout(LayoutKind.Explicit, Size = 8)]
- public struct OfByte
- {
- [FieldOffset(0)]
- public byte V0;
-
- [FieldOffset(1)]
- public byte V1;
-
- [FieldOffset(2)]
- public byte V2;
-
- [FieldOffset(3)]
- public byte V3;
-
- [FieldOffset(4)]
- public byte V4;
-
- [FieldOffset(5)]
- public byte V5;
-
- [FieldOffset(6)]
- public byte V6;
-
- [FieldOffset(7)]
- public byte V7;
-
- public override string ToString()
- {
- return $"{nameof(Octet)}.{nameof(OfByte)}({this.V0},{this.V1},{this.V2},{this.V3},{this.V4},{this.V5},{this.V6},{this.V7})";
- }
-
- [MethodImpl(InliningOptions.ShortMethod)]
- public void LoadFrom(ref OfUInt32 src)
- {
- this.V0 = (byte)src.V0;
- this.V1 = (byte)src.V1;
- this.V2 = (byte)src.V2;
- this.V3 = (byte)src.V3;
- this.V4 = (byte)src.V4;
- this.V5 = (byte)src.V5;
- this.V6 = (byte)src.V6;
- this.V7 = (byte)src.V7;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp/Common/Tuples/Octet{T}.cs b/src/ImageSharp/Common/Tuples/Octet{T}.cs
new file mode 100644
index 0000000000..71e7da801e
--- /dev/null
+++ b/src/ImageSharp/Common/Tuples/Octet{T}.cs
@@ -0,0 +1,73 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the Apache License, Version 2.0.
+
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+namespace SixLabors.ImageSharp.Tuples
+{
+ ///
+ /// Contains 8 element value tuples of various types.
+ ///
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct Octet
+ where T : unmanaged
+ {
+ public T V0;
+ public T V1;
+ public T V2;
+ public T V3;
+ public T V4;
+ public T V5;
+ public T V6;
+ public T V7;
+
+ ///
+ public override readonly string ToString()
+ {
+ return $"Octet<{typeof(T)}>({this.V0},{this.V1},{this.V2},{this.V3},{this.V4},{this.V5},{this.V6},{this.V7})";
+ }
+ }
+
+ ///
+ /// Extension methods for the type.
+ ///
+ internal static class OctetExtensions
+ {
+ ///
+ /// Loads the fields in a target of from one of type.
+ ///
+ /// The target of instance.
+ /// The source of instance.
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static void LoadFrom(ref this Octet destination, ref Octet source)
+ {
+ destination.V0 = source.V0;
+ destination.V1 = source.V1;
+ destination.V2 = source.V2;
+ destination.V3 = source.V3;
+ destination.V4 = source.V4;
+ destination.V5 = source.V5;
+ destination.V6 = source.V6;
+ destination.V7 = source.V7;
+ }
+
+ ///
+ /// Loads the fields in a target of from one of type.
+ ///
+ /// The target of instance.
+ /// The source of instance.
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static void LoadFrom(ref this Octet destination, ref Octet source)
+ {
+ destination.V0 = (byte)source.V0;
+ destination.V1 = (byte)source.V1;
+ destination.V2 = (byte)source.V2;
+ destination.V3 = (byte)source.V3;
+ destination.V4 = (byte)source.V4;
+ destination.V5 = (byte)source.V5;
+ destination.V6 = (byte)source.V6;
+ destination.V7 = (byte)source.V7;
+ }
+ }
+}
diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
index e5546b3613..a956f19c72 100644
--- a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
@@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
///
public Image Decode(Configuration configuration, Stream stream)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
Guard.NotNull(stream, nameof(stream));
diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
index 80b20c0255..dfdbb22fa5 100644
--- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
@@ -131,7 +131,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
///
/// The decoded image.
public Image Decode(Stream stream)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
try
{
@@ -256,7 +256,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The output pixel buffer containing the decoded image.
/// Whether the bitmap is inverted.
private void ReadBitFields(Buffer2D pixels, bool inverted)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
if (this.infoHeader.BitsPerPixel == 16)
{
@@ -296,7 +296,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The height of the bitmap.
/// Whether the bitmap is inverted.
private void ReadRle(BmpCompression compression, Buffer2D pixels, byte[] colors, int width, int height, bool inverted)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
TPixel color = default;
using (IMemoryOwner buffer = this.memoryAllocator.Allocate(width * height, AllocationOptions.Clean))
@@ -376,7 +376,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The height of the bitmap.
/// Whether the bitmap is inverted.
private void ReadRle24(Buffer2D pixels, int width, int height, bool inverted)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
TPixel color = default;
using (IMemoryOwner buffer = this.memoryAllocator.Allocate(width * height * 3, AllocationOptions.Clean))
@@ -814,7 +814,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// the bytes per color palette entry's can be 3 bytes instead of 4.
/// Whether the bitmap is inverted.
private void ReadRgbPalette(Buffer2D pixels, byte[] colors, int width, int height, int bitsPerPixel, int bytesPerColorMapEntry, bool inverted)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
// Pixels per byte (bits per pixel).
int ppb = 8 / bitsPerPixel;
@@ -872,7 +872,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The bitmask for the green channel.
/// The bitmask for the blue channel.
private void ReadRgb16(Buffer2D pixels, int width, int height, bool inverted, int redMask = DefaultRgb16RMask, int greenMask = DefaultRgb16GMask, int blueMask = DefaultRgb16BMask)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
int padding = CalculatePadding(width, 2);
int stride = (width * 2) + padding;
@@ -939,7 +939,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The height of the bitmap.
/// Whether the bitmap is inverted.
private void ReadRgb24(Buffer2D pixels, int width, int height, bool inverted)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
int padding = CalculatePadding(width, 3);
@@ -968,7 +968,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The height of the bitmap.
/// Whether the bitmap is inverted.
private void ReadRgb32Fast(Buffer2D pixels, int width, int height, bool inverted)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
int padding = CalculatePadding(width, 4);
@@ -998,7 +998,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The height of the bitmap.
/// Whether the bitmap is inverted.
private void ReadRgb32Slow(Buffer2D pixels, int width, int height, bool inverted)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
int padding = CalculatePadding(width, 4);
@@ -1099,7 +1099,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The bitmask for the blue channel.
/// The bitmask for the alpha channel.
private void ReadRgb32BitFields(Buffer2D pixels, int width, int height, bool inverted, int redMask, int greenMask, int blueMask, int alphaMask)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
TPixel color = default;
int padding = CalculatePadding(width, 4);
diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs
index 612675c33c..9c05ae2d50 100644
--- a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs
@@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
///
public void Encode(Image image, Stream stream)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
var encoder = new BmpEncoderCore(this, image.GetMemoryAllocator());
encoder.Encode(image, stream);
diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
index 1b3e0228a8..66a60d5330 100644
--- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
@@ -98,7 +98,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The to encode from.
/// The to encode the image data to.
public void Encode(Image image, Stream stream)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
Guard.NotNull(image, nameof(image));
Guard.NotNull(stream, nameof(stream));
@@ -203,7 +203,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The containing pixel data.
///
private void WriteImage(Stream stream, ImageFrame image)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
Buffer2D pixels = image.PixelBuffer;
switch (this.bitsPerPixel)
@@ -235,7 +235,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The to write to.
/// The containing pixel data.
private void Write32Bit(Stream stream, Buffer2D pixels)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
using (IManagedByteBuffer row = this.AllocateRow(pixels.Width, 4))
{
@@ -259,7 +259,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The to write to.
/// The containing pixel data.
private void Write24Bit(Stream stream, Buffer2D pixels)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
using (IManagedByteBuffer row = this.AllocateRow(pixels.Width, 3))
{
@@ -283,7 +283,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The to write to.
/// The containing pixel data.
private void Write16Bit(Stream stream, Buffer2D pixels)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
using (IManagedByteBuffer row = this.AllocateRow(pixels.Width, 2))
{
@@ -309,7 +309,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The to write to.
/// The containing pixel data.
private void Write8Bit(Stream stream, ImageFrame image)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
bool isL8 = typeof(TPixel) == typeof(L8);
using (IMemoryOwner colorPaletteBuffer = this.memoryAllocator.AllocateManagedByteBuffer(ColorPaletteSize8Bit, AllocationOptions.Clean))
@@ -334,7 +334,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The containing pixel data.
/// A byte span of size 1024 for the color palette.
private void Write8BitColor(Stream stream, ImageFrame image, Span colorPalette)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
using IFrameQuantizer quantizer = this.quantizer.CreateFrameQuantizer(this.configuration);
using QuantizedFrame quantized = quantizer.QuantizeFrame(image, image.Bounds());
@@ -378,7 +378,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The containing pixel data.
/// A byte span of size 1024 for the color palette.
private void Write8BitGray(Stream stream, ImageFrame image, Span colorPalette)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
// Create a color palette with 256 different gray values.
for (int i = 0; i <= 255; i++)
diff --git a/src/ImageSharp/Formats/Gif/GifDecoder.cs b/src/ImageSharp/Formats/Gif/GifDecoder.cs
index 24e3d88261..caa076553d 100644
--- a/src/ImageSharp/Formats/Gif/GifDecoder.cs
+++ b/src/ImageSharp/Formats/Gif/GifDecoder.cs
@@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
public Image Decode(Configuration configuration, Stream stream)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
var decoder = new GifDecoderCore(configuration, this);
diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
index bc508cba74..02267de1ac 100644
--- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
+++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
@@ -104,7 +104,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// The stream containing image data.
/// The decoded image
public Image Decode(Stream stream)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
Image image = null;
ImageFrame previousFrame = null;
@@ -348,7 +348,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// The image to decode the information to.
/// The previous frame.
private void ReadFrame(ref Image image, ref ImageFrame previousFrame)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
this.ReadImageDescriptor();
@@ -405,7 +405,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// The color table containing the available colors.
/// The
private void ReadFrameColors(ref Image image, ref ImageFrame previousFrame, Span indices, ReadOnlySpan colorTable, in GifImageDescriptor descriptor)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
ref byte indicesRef = ref MemoryMarshal.GetReference(indices);
int imageWidth = this.logicalScreenDescriptor.Width;
@@ -535,7 +535,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// The pixel format.
/// The frame.
private void RestoreToBackground(ImageFrame frame)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
if (this.restoreArea is null)
{
diff --git a/src/ImageSharp/Formats/Gif/GifEncoder.cs b/src/ImageSharp/Formats/Gif/GifEncoder.cs
index 248915cb70..978609d7fb 100644
--- a/src/ImageSharp/Formats/Gif/GifEncoder.cs
+++ b/src/ImageSharp/Formats/Gif/GifEncoder.cs
@@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
public void Encode(Image image, Stream stream)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
var encoder = new GifEncoderCore(image.GetConfiguration(), this);
encoder.Encode(image, stream);
diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
index 3a0fa5169d..e32910d37b 100644
--- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
+++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
@@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// The to encode from.
/// The to encode the image data to.
public void Encode(Image image, Stream stream)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
Guard.NotNull(image, nameof(image));
Guard.NotNull(stream, nameof(stream));
@@ -126,7 +126,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
}
private void EncodeGlobal(Image image, QuantizedFrame quantized, int transparencyIndex, Stream stream)
- where TPixel : struct, IPixel
+ where TPixel : unmanaged, IPixel
{
for (int i = 0; i < image.Frames.Count; i++)
{
@@ -152,7 +152,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
}
private void EncodeLocal(Image