Skip to content

Commit 38a2e73

Browse files
committed
Merge branch 'master' of https://github.com/SixLabors/ImageSharp
2 parents e1e2290 + b2bd68d commit 38a2e73

File tree

294 files changed

+1210
-1245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

294 files changed

+1210
-1245
lines changed

src/ImageSharp/Advanced/AdvancedImageExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private static Configuration GetConfiguration(IConfigurationProvider source)
6060
/// therefore it's not recommended to mutate the image while holding a reference to it's <see cref="IMemoryGroup{T}"/>.
6161
/// </remarks>
6262
public static IMemoryGroup<TPixel> GetPixelMemoryGroup<TPixel>(this ImageFrame<TPixel> source)
63-
where TPixel : struct, IPixel<TPixel>
63+
where TPixel : unmanaged, IPixel<TPixel>
6464
=> source?.PixelBuffer.FastMemoryGroup.View ?? throw new ArgumentNullException(nameof(source));
6565

6666
/// <summary>
@@ -75,7 +75,7 @@ public static IMemoryGroup<TPixel> GetPixelMemoryGroup<TPixel>(this ImageFrame<T
7575
/// therefore it's not recommended to mutate the image while holding a reference to it's <see cref="IMemoryGroup{T}"/>.
7676
/// </remarks>
7777
public static IMemoryGroup<TPixel> GetPixelMemoryGroup<TPixel>(this Image<TPixel> source)
78-
where TPixel : struct, IPixel<TPixel>
78+
where TPixel : unmanaged, IPixel<TPixel>
7979
=> source?.Frames.RootFrame.GetPixelMemoryGroup() ?? throw new ArgumentNullException(nameof(source));
8080

8181
/// <summary>
@@ -89,7 +89,7 @@ public static IMemoryGroup<TPixel> GetPixelMemoryGroup<TPixel>(this Image<TPixel
8989
[Obsolete(
9090
@"GetPixelSpan might fail, because the backing buffer could be discontiguous for large images. Use GetPixelMemoryGroup or GetPixelRowSpan instead!")]
9191
public static Span<TPixel> GetPixelSpan<TPixel>(this ImageFrame<TPixel> source)
92-
where TPixel : struct, IPixel<TPixel>
92+
where TPixel : unmanaged, IPixel<TPixel>
9393
{
9494
Guard.NotNull(source, nameof(source));
9595

@@ -113,7 +113,7 @@ public static Span<TPixel> GetPixelSpan<TPixel>(this ImageFrame<TPixel> source)
113113
[Obsolete(
114114
@"GetPixelSpan might fail, because the backing buffer could be discontiguous for large images. Use GetPixelMemoryGroup or GetPixelRowSpan instead!")]
115115
public static Span<TPixel> GetPixelSpan<TPixel>(this Image<TPixel> source)
116-
where TPixel : struct, IPixel<TPixel>
116+
where TPixel : unmanaged, IPixel<TPixel>
117117
{
118118
Guard.NotNull(source, nameof(source));
119119

@@ -129,7 +129,7 @@ public static Span<TPixel> GetPixelSpan<TPixel>(this Image<TPixel> source)
129129
/// <param name="rowIndex">The row.</param>
130130
/// <returns>The <see cref="Span{TPixel}"/></returns>
131131
public static Span<TPixel> GetPixelRowSpan<TPixel>(this ImageFrame<TPixel> source, int rowIndex)
132-
where TPixel : struct, IPixel<TPixel>
132+
where TPixel : unmanaged, IPixel<TPixel>
133133
{
134134
Guard.NotNull(source, nameof(source));
135135
Guard.MustBeGreaterThanOrEqualTo(rowIndex, 0, nameof(rowIndex));
@@ -147,7 +147,7 @@ public static Span<TPixel> GetPixelRowSpan<TPixel>(this ImageFrame<TPixel> sourc
147147
/// <param name="rowIndex">The row.</param>
148148
/// <returns>The <see cref="Span{TPixel}"/></returns>
149149
public static Span<TPixel> GetPixelRowSpan<TPixel>(this Image<TPixel> source, int rowIndex)
150-
where TPixel : struct, IPixel<TPixel>
150+
where TPixel : unmanaged, IPixel<TPixel>
151151
{
152152
Guard.NotNull(source, nameof(source));
153153
Guard.MustBeGreaterThanOrEqualTo(rowIndex, 0, nameof(rowIndex));
@@ -165,7 +165,7 @@ public static Span<TPixel> GetPixelRowSpan<TPixel>(this Image<TPixel> source, in
165165
/// <param name="rowIndex">The row.</param>
166166
/// <returns>The <see cref="Span{TPixel}"/></returns>
167167
public static Memory<TPixel> GetPixelRowMemory<TPixel>(this ImageFrame<TPixel> source, int rowIndex)
168-
where TPixel : struct, IPixel<TPixel>
168+
where TPixel : unmanaged, IPixel<TPixel>
169169
{
170170
Guard.NotNull(source, nameof(source));
171171
Guard.MustBeGreaterThanOrEqualTo(rowIndex, 0, nameof(rowIndex));
@@ -183,7 +183,7 @@ public static Memory<TPixel> GetPixelRowMemory<TPixel>(this ImageFrame<TPixel> s
183183
/// <param name="rowIndex">The row.</param>
184184
/// <returns>The <see cref="Span{TPixel}"/></returns>
185185
public static Memory<TPixel> GetPixelRowMemory<TPixel>(this Image<TPixel> source, int rowIndex)
186-
where TPixel : struct, IPixel<TPixel>
186+
where TPixel : unmanaged, IPixel<TPixel>
187187
{
188188
Guard.NotNull(source, nameof(source));
189189
Guard.MustBeGreaterThanOrEqualTo(rowIndex, 0, nameof(rowIndex));

src/ImageSharp/Advanced/AotCompilerTools.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private static void SeedEverything()
7979
/// </summary>
8080
/// <typeparam name="TPixel">The pixel format.</typeparam>
8181
private static void Seed<TPixel>()
82-
where TPixel : struct, IPixel<TPixel>
82+
where TPixel : unmanaged, IPixel<TPixel>
8383
{
8484
// This is we actually call all the individual methods you need to seed.
8585
AotCompileOctreeQuantizer<TPixel>();
@@ -110,7 +110,7 @@ private static void Seed<TPixel>()
110110
/// </summary>
111111
/// <typeparam name="TPixel">The pixel format.</typeparam>
112112
private static void AotCompileOctreeQuantizer<TPixel>()
113-
where TPixel : struct, IPixel<TPixel>
113+
where TPixel : unmanaged, IPixel<TPixel>
114114
{
115115
using (var test = new OctreeFrameQuantizer<TPixel>(Configuration.Default, new OctreeQuantizer().Options))
116116
{
@@ -124,7 +124,7 @@ private static void AotCompileOctreeQuantizer<TPixel>()
124124
/// </summary>
125125
/// <typeparam name="TPixel">The pixel format.</typeparam>
126126
private static void AotCompileWuQuantizer<TPixel>()
127-
where TPixel : struct, IPixel<TPixel>
127+
where TPixel : unmanaged, IPixel<TPixel>
128128
{
129129
using (var test = new WuFrameQuantizer<TPixel>(Configuration.Default, new WuQuantizer().Options))
130130
{
@@ -138,7 +138,7 @@ private static void AotCompileWuQuantizer<TPixel>()
138138
/// </summary>
139139
/// <typeparam name="TPixel">The pixel format.</typeparam>
140140
private static void AotCompilePaletteQuantizer<TPixel>()
141-
where TPixel : struct, IPixel<TPixel>
141+
where TPixel : unmanaged, IPixel<TPixel>
142142
{
143143
using (var test = (PaletteFrameQuantizer<TPixel>)new PaletteQuantizer(Array.Empty<Color>()).CreateFrameQuantizer<TPixel>(Configuration.Default))
144144
{
@@ -152,7 +152,7 @@ private static void AotCompilePaletteQuantizer<TPixel>()
152152
/// </summary>
153153
/// <typeparam name="TPixel">The pixel format.</typeparam>
154154
private static void AotCompileDithering<TPixel>()
155-
where TPixel : struct, IPixel<TPixel>
155+
where TPixel : unmanaged, IPixel<TPixel>
156156
{
157157
ErrorDither errorDither = ErrorDither.FloydSteinberg;
158158
OrderedDither orderedDither = OrderedDither.Bayer2x2;
@@ -171,7 +171,7 @@ private static void AotCompileDithering<TPixel>()
171171
/// <param name="encoder">The image encoder to seed.</param>
172172
/// <typeparam name="TPixel">The pixel format.</typeparam>
173173
private static void AotCodec<TPixel>(IImageDecoder decoder, IImageEncoder encoder)
174-
where TPixel : struct, IPixel<TPixel>
174+
where TPixel : unmanaged, IPixel<TPixel>
175175
{
176176
try
177177
{
@@ -195,7 +195,7 @@ private static void AotCodec<TPixel>(IImageDecoder decoder, IImageEncoder encode
195195
/// </summary>
196196
/// <typeparam name="TPixel">The pixel format.</typeparam>
197197
private static void AotCompilePixelOperations<TPixel>()
198-
where TPixel : struct, IPixel<TPixel>
198+
where TPixel : unmanaged, IPixel<TPixel>
199199
{
200200
var pixelOp = new PixelOperations<TPixel>();
201201
pixelOp.GetPixelBlender(PixelColorBlendingMode.Normal, PixelAlphaCompositionMode.Clear);

src/ImageSharp/Advanced/IImageVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public interface IImageVisitor
1717
/// <param name="image">The image.</param>
1818
/// <typeparam name="TPixel">The pixel type.</typeparam>
1919
void Visit<TPixel>(Image<TPixel> image)
20-
where TPixel : struct, IPixel<TPixel>;
20+
where TPixel : unmanaged, IPixel<TPixel>;
2121
}
2222
}

src/ImageSharp/Advanced/IPixelSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Advanced
1111
/// </summary>
1212
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
1313
internal interface IPixelSource<TPixel>
14-
where TPixel : struct, IPixel<TPixel>
14+
where TPixel : unmanaged, IPixel<TPixel>
1515
{
1616
/// <summary>
1717
/// Gets the pixel buffer.

src/ImageSharp/Color/Color.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public Color WithAlpha(float alpha)
220220
/// <returns>The pixel value.</returns>
221221
[MethodImpl(InliningOptions.ShortMethod)]
222222
public TPixel ToPixel<TPixel>()
223-
where TPixel : struct, IPixel<TPixel>
223+
where TPixel : unmanaged, IPixel<TPixel>
224224
{
225225
TPixel pixel = default;
226226
pixel.FromRgba64(this.data);
@@ -239,7 +239,7 @@ public static void ToPixel<TPixel>(
239239
Configuration configuration,
240240
ReadOnlySpan<Color> source,
241241
Span<TPixel> destination)
242-
where TPixel : struct, IPixel<TPixel>
242+
where TPixel : unmanaged, IPixel<TPixel>
243243
{
244244
ReadOnlySpan<Rgba64> rgba64Span = MemoryMarshal.Cast<Color, Rgba64>(source);
245245
PixelOperations<TPixel>.Instance.FromRgba64(configuration, rgba64Span, destination);

src/ImageSharp/Common/Helpers/Buffer2DUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void Convolve4<TPixel>(
4040
int maxRow,
4141
int minColumn,
4242
int maxColumn)
43-
where TPixel : struct, IPixel<TPixel>
43+
where TPixel : unmanaged, IPixel<TPixel>
4444
{
4545
ComplexVector4 vector = default;
4646
int kernelLength = kernel.Length;

src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static void Convolve2D3<TPixel>(
4242
int maxRow,
4343
int minColumn,
4444
int maxColumn)
45-
where TPixel : struct, IPixel<TPixel>
45+
where TPixel : unmanaged, IPixel<TPixel>
4646
{
4747
Convolve2DImpl(
4848
in matrixY,
@@ -90,7 +90,7 @@ public static void Convolve2D4<TPixel>(
9090
int maxRow,
9191
int minColumn,
9292
int maxColumn)
93-
where TPixel : struct, IPixel<TPixel>
93+
where TPixel : unmanaged, IPixel<TPixel>
9494
{
9595
Convolve2DImpl(
9696
in matrixY,
@@ -121,7 +121,7 @@ public static void Convolve2DImpl<TPixel>(
121121
int minColumn,
122122
int maxColumn,
123123
out Vector4 vector)
124-
where TPixel : struct, IPixel<TPixel>
124+
where TPixel : unmanaged, IPixel<TPixel>
125125
{
126126
Vector4 vectorY = default;
127127
Vector4 vectorX = default;
@@ -175,7 +175,7 @@ public static void Convolve3<TPixel>(
175175
int maxRow,
176176
int minColumn,
177177
int maxColumn)
178-
where TPixel : struct, IPixel<TPixel>
178+
where TPixel : unmanaged, IPixel<TPixel>
179179
{
180180
Vector4 vector = default;
181181

@@ -222,7 +222,7 @@ public static void Convolve4<TPixel>(
222222
int maxRow,
223223
int minColumn,
224224
int maxColumn)
225-
where TPixel : struct, IPixel<TPixel>
225+
where TPixel : unmanaged, IPixel<TPixel>
226226
{
227227
Vector4 vector = default;
228228

@@ -253,7 +253,7 @@ private static void ConvolveImpl<TPixel>(
253253
int minColumn,
254254
int maxColumn,
255255
ref Vector4 vector)
256-
where TPixel : struct, IPixel<TPixel>
256+
where TPixel : unmanaged, IPixel<TPixel>
257257
{
258258
int matrixHeight = matrix.Rows;
259259
int matrixWidth = matrix.Columns;

src/ImageSharp/Common/Helpers/ImageMaths.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public static float SinC(float f)
269269
/// The <see cref="Rectangle"/>.
270270
/// </returns>
271271
public static Rectangle GetFilteredBoundingRectangle<TPixel>(ImageFrame<TPixel> bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B)
272-
where TPixel : struct, IPixel<TPixel>
272+
where TPixel : unmanaged, IPixel<TPixel>
273273
{
274274
int width = bitmap.Width;
275275
int height = bitmap.Height;

src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,17 @@ internal static void BulkConvertByteToNormalizedFloat(ReadOnlySpan<byte> source,
9494
var magicInt = new Vector<uint>(1191182336); // reinterpreted value of 32768.0f
9595
var mask = new Vector<uint>(255);
9696

97-
ref Octet.OfByte sourceBase = ref Unsafe.As<byte, Octet.OfByte>(ref MemoryMarshal.GetReference(source));
98-
ref Octet.OfUInt32 destBaseAsWideOctet = ref Unsafe.As<float, Octet.OfUInt32>(ref MemoryMarshal.GetReference(dest));
97+
ref Octet<byte> sourceBase = ref Unsafe.As<byte, Octet<byte>>(ref MemoryMarshal.GetReference(source));
98+
ref Octet<uint> destBaseAsWideOctet = ref Unsafe.As<float, Octet<uint>>(ref MemoryMarshal.GetReference(dest));
9999

100-
ref Vector<float> destBaseAsFloat = ref Unsafe.As<Octet.OfUInt32, Vector<float>>(ref destBaseAsWideOctet);
100+
ref Vector<float> destBaseAsFloat = ref Unsafe.As<Octet<uint>, Vector<float>>(ref destBaseAsWideOctet);
101101

102102
int n = dest.Length / 8;
103103

104104
for (int i = 0; i < n; i++)
105105
{
106-
ref Octet.OfByte s = ref Unsafe.Add(ref sourceBase, i);
107-
ref Octet.OfUInt32 d = ref Unsafe.Add(ref destBaseAsWideOctet, i);
106+
ref Octet<byte> s = ref Unsafe.Add(ref sourceBase, i);
107+
ref Octet<uint> d = ref Unsafe.Add(ref destBaseAsWideOctet, i);
108108
d.LoadFrom(ref s);
109109
}
110110

@@ -137,17 +137,17 @@ internal static void BulkConvertNormalizedFloatToByteClampOverflows(ReadOnlySpan
137137
}
138138

139139
ref Vector<float> srcBase = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(source));
140-
ref Octet.OfByte destBase = ref Unsafe.As<byte, Octet.OfByte>(ref MemoryMarshal.GetReference(dest));
140+
ref Octet<byte> destBase = ref Unsafe.As<byte, Octet<byte>>(ref MemoryMarshal.GetReference(dest));
141141
int n = source.Length / 8;
142142

143143
var magick = new Vector<float>(32768.0f);
144144
var scale = new Vector<float>(255f) / new Vector<float>(256f);
145145

146146
// need to copy to a temporary struct, because
147-
// SimdUtils.Octet.OfUInt32 temp = Unsafe.As<Vector<float>, SimdUtils.Octet.OfUInt32>(ref x)
147+
// SimdUtils.Octet<uint> temp = Unsafe.As<Vector<float>, SimdUtils.Octet<uint>>(ref x)
148148
// does not work. TODO: This might be a CoreClr bug, need to ask/report
149-
var temp = default(Octet.OfUInt32);
150-
ref Vector<float> tempRef = ref Unsafe.As<Octet.OfUInt32, Vector<float>>(ref temp);
149+
var temp = default(Octet<uint>);
150+
ref Vector<float> tempRef = ref Unsafe.As<Octet<uint>, Vector<float>>(ref temp);
151151

152152
for (int i = 0; i < n; i++)
153153
{
@@ -161,7 +161,7 @@ internal static void BulkConvertNormalizedFloatToByteClampOverflows(ReadOnlySpan
161161
x = (x * scale) + magick;
162162
tempRef = x;
163163

164-
ref Octet.OfByte d = ref Unsafe.Add(ref destBase, i);
164+
ref Octet<byte> d = ref Unsafe.Add(ref destBase, i);
165165
d.LoadFrom(ref temp);
166166
}
167167
}
@@ -186,17 +186,17 @@ internal static void BulkConvertNormalizedFloatToByte(ReadOnlySpan<float> source
186186
}
187187

188188
ref Vector<float> srcBase = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(source));
189-
ref Octet.OfByte destBase = ref Unsafe.As<byte, Octet.OfByte>(ref MemoryMarshal.GetReference(dest));
189+
ref Octet<byte> destBase = ref Unsafe.As<byte, Octet<byte>>(ref MemoryMarshal.GetReference(dest));
190190
int n = source.Length / 8;
191191

192192
var magick = new Vector<float>(32768.0f);
193193
var scale = new Vector<float>(255f) / new Vector<float>(256f);
194194

195195
// need to copy to a temporary struct, because
196-
// SimdUtils.Octet.OfUInt32 temp = Unsafe.As<Vector<float>, SimdUtils.Octet.OfUInt32>(ref x)
196+
// SimdUtils.Octet<uint> temp = Unsafe.As<Vector<float>, SimdUtils.Octet<uint>>(ref x)
197197
// does not work. TODO: This might be a CoreClr bug, need to ask/report
198-
var temp = default(Octet.OfUInt32);
199-
ref Vector<float> tempRef = ref Unsafe.As<Octet.OfUInt32, Vector<float>>(ref temp);
198+
var temp = default(Octet<uint>);
199+
ref Vector<float> tempRef = ref Unsafe.As<Octet<uint>, Vector<float>>(ref temp);
200200

201201
for (int i = 0; i < n; i++)
202202
{
@@ -207,7 +207,7 @@ internal static void BulkConvertNormalizedFloatToByte(ReadOnlySpan<float> source
207207
x = (x * scale) + magick;
208208
tempRef = x;
209209

210-
ref Octet.OfByte d = ref Unsafe.Add(ref destBase, i);
210+
ref Octet<byte> d = ref Unsafe.Add(ref destBase, i);
211211
d.LoadFrom(ref temp);
212212
}
213213
}

0 commit comments

Comments
 (0)