Skip to content

Commit 66d494e

Browse files
Reorder params, fix other warnings.
1 parent 74a2ad9 commit 66d494e

File tree

4 files changed

+44
-50
lines changed

4 files changed

+44
-50
lines changed

src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
159159

160160
WriteBitmapFileHeader(stream, infoHeaderSize, colorPaletteSize, iccProfileSize, infoHeader, buffer);
161161
this.WriteBitmapInfoHeader(stream, infoHeader, buffer, infoHeaderSize);
162-
this.WriteImage(stream, image, configuration);
162+
this.WriteImage(configuration, stream, image);
163163
WriteColorProfile(stream, iccProfileData, buffer);
164164

165165
stream.Flush();
@@ -307,43 +307,43 @@ private void WriteBitmapInfoHeader(Stream stream, BmpInfoHeader infoHeader, Span
307307
/// Writes the pixel data to the binary stream.
308308
/// </summary>
309309
/// <typeparam name="TPixel">The pixel format.</typeparam>
310+
/// <param name="configuration">The global configuration.</param>
310311
/// <param name="stream">The <see cref="Stream"/> to write to.</param>
311312
/// <param name="image">
312313
/// The <see cref="ImageFrame{TPixel}"/> containing pixel data.
313314
/// </param>
314-
/// <param name="configuration">The global configuration.</param>
315-
private void WriteImage<TPixel>(Stream stream, Image<TPixel> image, Configuration configuration)
315+
private void WriteImage<TPixel>(Configuration configuration, Stream stream, Image<TPixel> image)
316316
where TPixel : unmanaged, IPixel<TPixel>
317317
{
318318
Buffer2D<TPixel> pixels = image.Frames.RootFrame.PixelBuffer;
319319
switch (this.bitsPerPixel)
320320
{
321321
case BmpBitsPerPixel.Pixel32:
322-
this.Write32BitPixelData(stream, pixels, configuration);
322+
this.Write32BitPixelData(configuration, stream, pixels);
323323
break;
324324

325325
case BmpBitsPerPixel.Pixel24:
326-
this.Write24BitPixelData(stream, pixels, configuration);
326+
this.Write24BitPixelData(configuration, stream, pixels);
327327
break;
328328

329329
case BmpBitsPerPixel.Pixel16:
330-
this.Write16BitPixelData(stream, pixels, configuration);
330+
this.Write16BitPixelData(configuration, stream, pixels);
331331
break;
332332

333333
case BmpBitsPerPixel.Pixel8:
334-
this.Write8BitPixelData(stream, image, configuration);
334+
this.Write8BitPixelData(configuration, stream, image);
335335
break;
336336

337337
case BmpBitsPerPixel.Pixel4:
338-
this.Write4BitPixelData(stream, image, configuration);
338+
this.Write4BitPixelData(configuration, stream, image);
339339
break;
340340

341341
case BmpBitsPerPixel.Pixel2:
342-
this.Write2BitPixelData(stream, image, configuration);
342+
this.Write2BitPixelData(configuration, stream, image);
343343
break;
344344

345345
case BmpBitsPerPixel.Pixel1:
346-
this.Write1BitPixelData(stream, image, configuration);
346+
this.Write1BitPixelData(configuration, stream, image);
347347
break;
348348
}
349349
}
@@ -355,10 +355,10 @@ private IMemoryOwner<byte> AllocateRow(int width, int bytesPerPixel)
355355
/// Writes 32-bit data with a color palette to the stream.
356356
/// </summary>
357357
/// <typeparam name="TPixel">The pixel format.</typeparam>
358+
/// <param name="configuration">The global configuration.</param>
358359
/// <param name="stream">The <see cref="Stream"/> to write to.</param>
359360
/// <param name="pixels">The <see cref="Buffer2D{TPixel}"/> containing pixel data.</param>
360-
/// <param name="configuration">The global configuration.</param>
361-
private void Write32BitPixelData<TPixel>(Stream stream, Buffer2D<TPixel> pixels, Configuration configuration)
361+
private void Write32BitPixelData<TPixel>(Configuration configuration, Stream stream, Buffer2D<TPixel> pixels)
362362
where TPixel : unmanaged, IPixel<TPixel>
363363
{
364364
using IMemoryOwner<byte> row = this.AllocateRow(pixels.Width, 4);
@@ -380,10 +380,10 @@ private void Write32BitPixelData<TPixel>(Stream stream, Buffer2D<TPixel> pixels,
380380
/// Writes 24-bit pixel data with a color palette to the stream.
381381
/// </summary>
382382
/// <typeparam name="TPixel">The pixel format.</typeparam>
383+
/// <param name="configuration">The global configuration.</param>
383384
/// <param name="stream">The <see cref="Stream"/> to write to.</param>
384385
/// <param name="pixels">The <see cref="Buffer2D{TPixel}"/> containing pixel data.</param>
385-
/// <param name="configuration">The global configuration.</param>
386-
private void Write24BitPixelData<TPixel>(Stream stream, Buffer2D<TPixel> pixels, Configuration configuration)
386+
private void Write24BitPixelData<TPixel>(Configuration configuration, Stream stream, Buffer2D<TPixel> pixels)
387387
where TPixel : unmanaged, IPixel<TPixel>
388388
{
389389
int width = pixels.Width;
@@ -407,11 +407,11 @@ private void Write24BitPixelData<TPixel>(Stream stream, Buffer2D<TPixel> pixels,
407407
/// Writes 16-bit pixel data with a color palette to the stream.
408408
/// </summary>
409409
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
410+
/// <param name="configuration">The global configuration.</param>
410411
/// <param name="stream">The <see cref="Stream"/> to write to.</param>
411412
/// <param name="pixels">The <see cref="Buffer2D{TPixel}"/> containing pixel data.</param>
412-
/// <param name="configuration">The global configuration.</param>
413-
private void Write16BitPixelData<TPixel>(Stream stream, Buffer2D<TPixel> pixels, Configuration configuration)
414-
where TPixel : unmanaged, IPixel<TPixel>
413+
private void Write16BitPixelData<TPixel>(Configuration configuration, Stream stream, Buffer2D<TPixel> pixels)
414+
where TPixel : unmanaged, IPixel<TPixel>
415415
{
416416
int width = pixels.Width;
417417
int rowBytesWithoutPadding = width * 2;
@@ -436,10 +436,10 @@ private void Write16BitPixelData<TPixel>(Stream stream, Buffer2D<TPixel> pixels,
436436
/// Writes 8 bit pixel data with a color palette. The color palette has 256 entry's with 4 bytes for each entry.
437437
/// </summary>
438438
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
439+
/// <param name="configuration">The global configuration.</param>
439440
/// <param name="stream">The <see cref="Stream"/> to write to.</param>
440441
/// <param name="image"> The <see cref="Image{TPixel}"/> containing pixel data.</param>
441-
/// <param name="configuration">The global configuration.</param>
442-
private void Write8BitPixelData<TPixel>(Stream stream, Image<TPixel> image, Configuration configuration)
442+
private void Write8BitPixelData<TPixel>(Configuration configuration, Stream stream, Image<TPixel> image)
443443
where TPixel : unmanaged, IPixel<TPixel>
444444
{
445445
bool isL8 = typeof(TPixel) == typeof(L8);
@@ -452,19 +452,19 @@ private void Write8BitPixelData<TPixel>(Stream stream, Image<TPixel> image, Conf
452452
}
453453
else
454454
{
455-
this.Write8BitColor(stream, image, colorPalette, configuration);
455+
this.Write8BitColor(configuration, stream, image, colorPalette);
456456
}
457457
}
458458

459459
/// <summary>
460460
/// Writes an 8 bit color image with a color palette. The color palette has 256 entry's with 4 bytes for each entry.
461461
/// </summary>
462462
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
463+
/// <param name="configuration">The global configuration.</param>
463464
/// <param name="stream">The <see cref="Stream"/> to write to.</param>
464465
/// <param name="image"> The <see cref="Image{TPixel}"/> containing pixel data.</param>
465466
/// <param name="colorPalette">A byte span of size 1024 for the color palette.</param>
466-
/// <param name="configuration">The global configuration</param>
467-
private void Write8BitColor<TPixel>(Stream stream, Image<TPixel> image, Span<byte> colorPalette, Configuration configuration)
467+
private void Write8BitColor<TPixel>(Configuration configuration, Stream stream, Image<TPixel> image, Span<byte> colorPalette)
468468
where TPixel : unmanaged, IPixel<TPixel>
469469
{
470470
using IQuantizer<TPixel> frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer<TPixel>(configuration);
@@ -473,7 +473,7 @@ private void Write8BitColor<TPixel>(Stream stream, Image<TPixel> image, Span<byt
473473
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds);
474474

475475
ReadOnlySpan<TPixel> quantizedColorPalette = quantized.Palette.Span;
476-
WriteColorPalette(stream, quantizedColorPalette, colorPalette, configuration);
476+
WriteColorPalette(configuration, stream, quantizedColorPalette, colorPalette);
477477

478478
for (int y = image.Height - 1; y >= 0; y--)
479479
{
@@ -529,10 +529,10 @@ private void Write8BitPixelData<TPixel>(Stream stream, Image<TPixel> image, Span
529529
/// Writes 4 bit pixel data with a color palette. The color palette has 16 entry's with 4 bytes for each entry.
530530
/// </summary>
531531
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
532+
/// <param name="configuration">The global configuration.</param>
532533
/// <param name="stream">The <see cref="Stream"/> to write to.</param>
533534
/// <param name="image"> The <see cref="ImageFrame{TPixel}"/> containing pixel data.</param>
534-
/// <param name="configuration">The global configuration.</param>
535-
private void Write4BitPixelData<TPixel>(Stream stream, Image<TPixel> image, Configuration configuration)
535+
private void Write4BitPixelData<TPixel>(Configuration configuration, Stream stream, Image<TPixel> image)
536536
where TPixel : unmanaged, IPixel<TPixel>
537537
{
538538
using IQuantizer<TPixel> frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer<TPixel>(configuration, new QuantizerOptions()
@@ -547,7 +547,7 @@ private void Write4BitPixelData<TPixel>(Stream stream, Image<TPixel> image, Conf
547547

548548
Span<byte> colorPalette = colorPaletteBuffer.GetSpan();
549549
ReadOnlySpan<TPixel> quantizedColorPalette = quantized.Palette.Span;
550-
WriteColorPalette(stream, quantizedColorPalette, colorPalette, configuration);
550+
WriteColorPalette(configuration, stream, quantizedColorPalette, colorPalette);
551551

552552
ReadOnlySpan<byte> pixelRowSpan = quantized.DangerousGetRowSpan(0);
553553
int rowPadding = pixelRowSpan.Length % 2 != 0 ? this.padding - 1 : this.padding;
@@ -577,10 +577,10 @@ private void Write4BitPixelData<TPixel>(Stream stream, Image<TPixel> image, Conf
577577
/// Writes 2 bit pixel data with a color palette. The color palette has 4 entry's with 4 bytes for each entry.
578578
/// </summary>
579579
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
580+
/// <param name="configuration">The global configuration.</param>
580581
/// <param name="stream">The <see cref="Stream"/> to write to.</param>
581582
/// <param name="image"> The <see cref="ImageFrame{TPixel}"/> containing pixel data.</param>
582-
/// <param name="configuration">The global configuration</param>
583-
private void Write2BitPixelData<TPixel>(Stream stream, Image<TPixel> image, Configuration configuration)
583+
private void Write2BitPixelData<TPixel>(Configuration configuration, Stream stream, Image<TPixel> image)
584584
where TPixel : unmanaged, IPixel<TPixel>
585585
{
586586
using IQuantizer<TPixel> frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer<TPixel>(configuration, new QuantizerOptions()
@@ -595,7 +595,7 @@ private void Write2BitPixelData<TPixel>(Stream stream, Image<TPixel> image, Conf
595595

596596
Span<byte> colorPalette = colorPaletteBuffer.GetSpan();
597597
ReadOnlySpan<TPixel> quantizedColorPalette = quantized.Palette.Span;
598-
WriteColorPalette(stream, quantizedColorPalette, colorPalette, configuration);
598+
WriteColorPalette(configuration, stream, quantizedColorPalette, colorPalette);
599599

600600
ReadOnlySpan<byte> pixelRowSpan = quantized.DangerousGetRowSpan(0);
601601
int rowPadding = pixelRowSpan.Length % 4 != 0 ? this.padding - 1 : this.padding;
@@ -634,10 +634,10 @@ private void Write2BitPixelData<TPixel>(Stream stream, Image<TPixel> image, Conf
634634
/// Writes 1 bit pixel data with a color palette. The color palette has 2 entry's with 4 bytes for each entry.
635635
/// </summary>
636636
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
637+
/// <param name="configuration">The global configuration.</param>
637638
/// <param name="stream">The <see cref="Stream"/> to write to.</param>
638639
/// <param name="image"> The <see cref="ImageFrame{TPixel}"/> containing pixel data.</param>
639-
/// <param name="configuration">The global configuration</param>
640-
private void Write1BitPixelData<TPixel>(Stream stream, Image<TPixel> image, Configuration configuration)
640+
private void Write1BitPixelData<TPixel>(Configuration configuration, Stream stream, Image<TPixel> image)
641641
where TPixel : unmanaged, IPixel<TPixel>
642642
{
643643
using IQuantizer<TPixel> frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer<TPixel>(configuration, new QuantizerOptions()
@@ -652,7 +652,7 @@ private void Write1BitPixelData<TPixel>(Stream stream, Image<TPixel> image, Conf
652652

653653
Span<byte> colorPalette = colorPaletteBuffer.GetSpan();
654654
ReadOnlySpan<TPixel> quantizedColorPalette = quantized.Palette.Span;
655-
WriteColorPalette(stream, quantizedColorPalette, colorPalette, configuration);
655+
WriteColorPalette(configuration, stream, quantizedColorPalette, colorPalette);
656656

657657
ReadOnlySpan<byte> quantizedPixelRow = quantized.DangerousGetRowSpan(0);
658658
int rowPadding = quantizedPixelRow.Length % 8 != 0 ? this.padding - 1 : this.padding;
@@ -684,11 +684,11 @@ private void Write1BitPixelData<TPixel>(Stream stream, Image<TPixel> image, Conf
684684
/// Writes the color palette to the stream. The color palette has 4 bytes for each entry.
685685
/// </summary>
686686
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
687+
/// <param name="configuration">The global configuration.</param>
687688
/// <param name="stream">The <see cref="Stream"/> to write to.</param>
688689
/// <param name="quantizedColorPalette">The color palette from the quantized image.</param>
689690
/// <param name="colorPalette">A temporary byte span to write the color palette to.</param>
690-
/// <param name="configuration">The global configuration</param>
691-
private static void WriteColorPalette<TPixel>(Stream stream, ReadOnlySpan<TPixel> quantizedColorPalette, Span<byte> colorPalette, Configuration configuration)
691+
private static void WriteColorPalette<TPixel>(Configuration configuration, Stream stream, ReadOnlySpan<TPixel> quantizedColorPalette, Span<byte> colorPalette)
692692
where TPixel : unmanaged, IPixel<TPixel>
693693
{
694694
int quantizedColorBytes = quantizedColorPalette.Length * 4;

src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel>
2626
private readonly int maxColors;
2727
private readonly int bitDepth;
2828
private readonly Octree octree;
29-
private IMemoryOwner<TPixel> paletteOwner;
29+
private readonly IMemoryOwner<TPixel> paletteOwner;
3030
private ReadOnlyMemory<TPixel> palette;
3131
private EuclideanPixelMap<TPixel>? pixelMap;
3232
private readonly bool isDithering;
@@ -38,11 +38,8 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel>
3838
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
3939
/// <param name="options">The quantizer options defining quantization rules.</param>
4040
[MethodImpl(InliningOptions.ShortMethod)]
41-
public OctreeQuantizer(Configuration? configuration, QuantizerOptions options)
41+
public OctreeQuantizer(Configuration configuration, QuantizerOptions options)
4242
{
43-
Guard.NotNull(configuration, nameof(configuration));
44-
Guard.NotNull(options, nameof(options));
45-
4643
this.Configuration = configuration;
4744
this.Options = options;
4845

src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization;
1717
"Design",
1818
"CA1001:Types that own disposable fields should be disposable",
1919
Justification = "https://github.com/dotnet/roslyn-analyzers/issues/6151")]
20-
internal struct PaletteQuantizer<TPixel> : IQuantizer<TPixel>
20+
internal readonly struct PaletteQuantizer<TPixel> : IQuantizer<TPixel>
2121
where TPixel : unmanaged, IPixel<TPixel>
2222
{
23-
private EuclideanPixelMap<TPixel> pixelMap;
23+
private readonly EuclideanPixelMap<TPixel> pixelMap;
2424

2525
/// <summary>
2626
/// Initializes a new instance of the <see cref="PaletteQuantizer{TPixel}"/> struct.
@@ -29,7 +29,7 @@ internal struct PaletteQuantizer<TPixel> : IQuantizer<TPixel>
2929
/// <param name="options">The quantizer options defining quantization rules.</param>
3030
/// <param name="palette">The palette to use.</param>
3131
[MethodImpl(InliningOptions.ShortMethod)]
32-
public PaletteQuantizer(Configuration? configuration, QuantizerOptions options, ReadOnlyMemory<TPixel> palette)
32+
public PaletteQuantizer(Configuration configuration, QuantizerOptions options, ReadOnlyMemory<TPixel> palette)
3333
{
3434
Guard.NotNull(configuration, nameof(configuration));
3535
Guard.NotNull(options, nameof(options));
@@ -65,8 +65,5 @@ public readonly byte GetQuantizedColor(TPixel color, out TPixel match)
6565
=> (byte)this.pixelMap.GetClosestColor(color, out match);
6666

6767
/// <inheritdoc/>
68-
public void Dispose()
69-
{
70-
this.pixelMap.Dispose();
71-
}
68+
public void Dispose() => this.pixelMap.Dispose();
7269
}

src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ internal struct WuQuantizer<TPixel> : IQuantizer<TPixel>
6969
/// </summary>
7070
private const int TableLength = IndexCount * IndexCount * IndexCount * IndexAlphaCount;
7171

72-
private IMemoryOwner<Moment> momentsOwner;
73-
private IMemoryOwner<byte> tagsOwner;
74-
private IMemoryOwner<TPixel> paletteOwner;
72+
private readonly IMemoryOwner<Moment> momentsOwner;
73+
private readonly IMemoryOwner<byte> tagsOwner;
74+
private readonly IMemoryOwner<TPixel> paletteOwner;
7575
private ReadOnlyMemory<TPixel> palette;
7676
private int maxColors;
7777
private readonly Box[] colorCube;
@@ -85,7 +85,7 @@ internal struct WuQuantizer<TPixel> : IQuantizer<TPixel>
8585
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
8686
/// <param name="options">The quantizer options defining quantization rules.</param>
8787
[MethodImpl(InliningOptions.ShortMethod)]
88-
public WuQuantizer(Configuration? configuration, QuantizerOptions options)
88+
public WuQuantizer(Configuration configuration, QuantizerOptions options)
8989
{
9090
Guard.NotNull(configuration, nameof(configuration));
9191
Guard.NotNull(options, nameof(options));

0 commit comments

Comments
 (0)