Skip to content

Commit b2bd68d

Browse files
authored
Merge pull request #1122 from SixLabors/sp/refactoring-and-tweaks-2
Refactoring and tweaks (2)
2 parents 71e3ac1 + 687d13a commit b2bd68d

File tree

290 files changed

+1115
-1111
lines changed

Some content is hidden

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

290 files changed

+1115
-1111
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/Formats/Bmp/BmpDecoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public sealed class BmpDecoder : IImageDecoder, IBmpDecoderOptions, IImageInfoDe
2929

3030
/// <inheritdoc/>
3131
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream)
32-
where TPixel : struct, IPixel<TPixel>
32+
where TPixel : unmanaged, IPixel<TPixel>
3333
{
3434
Guard.NotNull(stream, nameof(stream));
3535

src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public BmpDecoderCore(Configuration configuration, IBmpDecoderOptions options)
131131
/// </exception>
132132
/// <returns>The decoded image.</returns>
133133
public Image<TPixel> Decode<TPixel>(Stream stream)
134-
where TPixel : struct, IPixel<TPixel>
134+
where TPixel : unmanaged, IPixel<TPixel>
135135
{
136136
try
137137
{
@@ -256,7 +256,7 @@ private static int CalculatePadding(int width, int componentCount)
256256
/// <param name="pixels">The output pixel buffer containing the decoded image.</param>
257257
/// <param name="inverted">Whether the bitmap is inverted.</param>
258258
private void ReadBitFields<TPixel>(Buffer2D<TPixel> pixels, bool inverted)
259-
where TPixel : struct, IPixel<TPixel>
259+
where TPixel : unmanaged, IPixel<TPixel>
260260
{
261261
if (this.infoHeader.BitsPerPixel == 16)
262262
{
@@ -296,7 +296,7 @@ private void ReadBitFields<TPixel>(Buffer2D<TPixel> pixels, bool inverted)
296296
/// <param name="height">The height of the bitmap.</param>
297297
/// <param name="inverted">Whether the bitmap is inverted.</param>
298298
private void ReadRle<TPixel>(BmpCompression compression, Buffer2D<TPixel> pixels, byte[] colors, int width, int height, bool inverted)
299-
where TPixel : struct, IPixel<TPixel>
299+
where TPixel : unmanaged, IPixel<TPixel>
300300
{
301301
TPixel color = default;
302302
using (IMemoryOwner<byte> buffer = this.memoryAllocator.Allocate<byte>(width * height, AllocationOptions.Clean))
@@ -376,7 +376,7 @@ private void ReadRle<TPixel>(BmpCompression compression, Buffer2D<TPixel> pixels
376376
/// <param name="height">The height of the bitmap.</param>
377377
/// <param name="inverted">Whether the bitmap is inverted.</param>
378378
private void ReadRle24<TPixel>(Buffer2D<TPixel> pixels, int width, int height, bool inverted)
379-
where TPixel : struct, IPixel<TPixel>
379+
where TPixel : unmanaged, IPixel<TPixel>
380380
{
381381
TPixel color = default;
382382
using (IMemoryOwner<byte> buffer = this.memoryAllocator.Allocate<byte>(width * height * 3, AllocationOptions.Clean))
@@ -814,7 +814,7 @@ private static int RleSkipDelta(
814814
/// the bytes per color palette entry's can be 3 bytes instead of 4.</param>
815815
/// <param name="inverted">Whether the bitmap is inverted.</param>
816816
private void ReadRgbPalette<TPixel>(Buffer2D<TPixel> pixels, byte[] colors, int width, int height, int bitsPerPixel, int bytesPerColorMapEntry, bool inverted)
817-
where TPixel : struct, IPixel<TPixel>
817+
where TPixel : unmanaged, IPixel<TPixel>
818818
{
819819
// Pixels per byte (bits per pixel).
820820
int ppb = 8 / bitsPerPixel;
@@ -872,7 +872,7 @@ private void ReadRgbPalette<TPixel>(Buffer2D<TPixel> pixels, byte[] colors, int
872872
/// <param name="greenMask">The bitmask for the green channel.</param>
873873
/// <param name="blueMask">The bitmask for the blue channel.</param>
874874
private void ReadRgb16<TPixel>(Buffer2D<TPixel> pixels, int width, int height, bool inverted, int redMask = DefaultRgb16RMask, int greenMask = DefaultRgb16GMask, int blueMask = DefaultRgb16BMask)
875-
where TPixel : struct, IPixel<TPixel>
875+
where TPixel : unmanaged, IPixel<TPixel>
876876
{
877877
int padding = CalculatePadding(width, 2);
878878
int stride = (width * 2) + padding;
@@ -939,7 +939,7 @@ private void ReadRgb16<TPixel>(Buffer2D<TPixel> pixels, int width, int height, b
939939
/// <param name="height">The height of the bitmap.</param>
940940
/// <param name="inverted">Whether the bitmap is inverted.</param>
941941
private void ReadRgb24<TPixel>(Buffer2D<TPixel> pixels, int width, int height, bool inverted)
942-
where TPixel : struct, IPixel<TPixel>
942+
where TPixel : unmanaged, IPixel<TPixel>
943943
{
944944
int padding = CalculatePadding(width, 3);
945945

@@ -968,7 +968,7 @@ private void ReadRgb24<TPixel>(Buffer2D<TPixel> pixels, int width, int height, b
968968
/// <param name="height">The height of the bitmap.</param>
969969
/// <param name="inverted">Whether the bitmap is inverted.</param>
970970
private void ReadRgb32Fast<TPixel>(Buffer2D<TPixel> pixels, int width, int height, bool inverted)
971-
where TPixel : struct, IPixel<TPixel>
971+
where TPixel : unmanaged, IPixel<TPixel>
972972
{
973973
int padding = CalculatePadding(width, 4);
974974

@@ -998,7 +998,7 @@ private void ReadRgb32Fast<TPixel>(Buffer2D<TPixel> pixels, int width, int heigh
998998
/// <param name="height">The height of the bitmap.</param>
999999
/// <param name="inverted">Whether the bitmap is inverted.</param>
10001000
private void ReadRgb32Slow<TPixel>(Buffer2D<TPixel> pixels, int width, int height, bool inverted)
1001-
where TPixel : struct, IPixel<TPixel>
1001+
where TPixel : unmanaged, IPixel<TPixel>
10021002
{
10031003
int padding = CalculatePadding(width, 4);
10041004

@@ -1099,7 +1099,7 @@ private void ReadRgb32Slow<TPixel>(Buffer2D<TPixel> pixels, int width, int heigh
10991099
/// <param name="blueMask">The bitmask for the blue channel.</param>
11001100
/// <param name="alphaMask">The bitmask for the alpha channel.</param>
11011101
private void ReadRgb32BitFields<TPixel>(Buffer2D<TPixel> pixels, int width, int height, bool inverted, int redMask, int greenMask, int blueMask, int alphaMask)
1102-
where TPixel : struct, IPixel<TPixel>
1102+
where TPixel : unmanaged, IPixel<TPixel>
11031103
{
11041104
TPixel color = default;
11051105
int padding = CalculatePadding(width, 4);

0 commit comments

Comments
 (0)