Skip to content

Commit 517ec1a

Browse files
committed
Fix more style warnings
1 parent d52ee77 commit 517ec1a

File tree

268 files changed

+18830
-19322
lines changed

Some content is hidden

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

268 files changed

+18830
-19322
lines changed

src/ImageSharp.Textures.Astc/AstcDecoder.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static class AstcDecoder
3030
/// <exception cref="InvalidOperationException">If decompression fails for any block</exception>
3131
public static Span<byte> DecompressImage(ReadOnlySpan<byte> astcData, int width, int height, Footprint footprint)
3232
{
33-
var imageBuffer = new byte[width * height * BytesPerPixelUnorm8];
33+
byte[] imageBuffer = new byte[width * height * BytesPerPixelUnorm8];
3434

3535
return DecompressImage(astcData, width, height, footprint, imageBuffer)
3636
? imageBuffer
@@ -54,13 +54,13 @@ public static bool DecompressImage(ReadOnlySpan<byte> astcData, int width, int h
5454
return false;
5555
}
5656

57-
var decodedBlock = Array.Empty<byte>();
57+
byte[] decodedBlock = [];
5858

5959
try
6060
{
6161
// Create a buffer once for fallback blocks; fast path writes directly to image
6262
decodedBlock = ArrayPool.Rent(footprint.Width * footprint.Height * BytesPerPixelUnorm8);
63-
var decodedPixels = decodedBlock.AsSpan();
63+
Span<byte> decodedPixels = decodedBlock.AsSpan();
6464
int blockIndex = 0;
6565
int footprintWidth = footprint.Width;
6666
int footprintHeight = footprint.Height;
@@ -75,16 +75,16 @@ public static bool DecompressImage(ReadOnlySpan<byte> astcData, int width, int h
7575
continue;
7676
}
7777

78-
ulong low = BinaryPrimitives.ReadUInt64LittleEndian(astcData.Slice(blockDataOffset));
79-
ulong high = BinaryPrimitives.ReadUInt64LittleEndian(astcData.Slice(blockDataOffset + 8));
80-
var blockBits = new UInt128(high, low);
78+
ulong low = BinaryPrimitives.ReadUInt64LittleEndian(astcData[blockDataOffset..]);
79+
ulong high = BinaryPrimitives.ReadUInt64LittleEndian(astcData[(blockDataOffset + 8)..]);
80+
UInt128 blockBits = new(high, low);
8181

8282
int dstBaseX = blockX * footprintWidth;
8383
int dstBaseY = blockY * footprintHeight;
8484
int copyWidth = Math.Min(footprintWidth, width - dstBaseX);
8585
int copyHeight = Math.Min(footprintHeight, height - dstBaseY);
8686

87-
var info = BlockInfo.Decode(blockBits);
87+
BlockInfo info = BlockInfo.Decode(blockBits);
8888
if (!info.IsValid)
8989
{
9090
continue;
@@ -114,7 +114,7 @@ public static bool DecompressImage(ReadOnlySpan<byte> astcData, int width, int h
114114
}
115115
else
116116
{
117-
var logicalBlock = LogicalBlock.UnpackLogicalBlock(footprint, blockBits, in info);
117+
LogicalBlock? logicalBlock = LogicalBlock.UnpackLogicalBlock(footprint, blockBits, in info);
118118
if (logicalBlock is null)
119119
{
120120
continue;
@@ -150,11 +150,11 @@ public static bool DecompressImage(ReadOnlySpan<byte> astcData, int width, int h
150150
/// <returns>The decoded block of pixels as RGBA values</returns>
151151
public static Span<byte> DecompressBlock(ReadOnlySpan<byte> blockData, Footprint footprint)
152152
{
153-
var decodedPixels = Array.Empty<byte>();
153+
byte[] decodedPixels = [];
154154
try
155155
{
156156
decodedPixels = ArrayPool.Rent(footprint.Width * footprint.Height * BytesPerPixelUnorm8);
157-
var decodedPixelBuffer = decodedPixels.AsSpan();
157+
Span<byte> decodedPixelBuffer = decodedPixels.AsSpan();
158158

159159
DecompressBlock(blockData, footprint, decodedPixelBuffer);
160160
}
@@ -176,10 +176,10 @@ public static void DecompressBlock(ReadOnlySpan<byte> blockData, Footprint footp
176176
{
177177
// Read the 16 bytes that make up the ASTC block as a 128-bit value
178178
ulong low = BinaryPrimitives.ReadUInt64LittleEndian(blockData);
179-
ulong high = BinaryPrimitives.ReadUInt64LittleEndian(blockData.Slice(8));
180-
var blockBits = new UInt128(high, low);
179+
ulong high = BinaryPrimitives.ReadUInt64LittleEndian(blockData[8..]);
180+
UInt128 blockBits = new(high, low);
181181

182-
var info = BlockInfo.Decode(blockBits);
182+
BlockInfo info = BlockInfo.Decode(blockBits);
183183
if (!info.IsValid)
184184
{
185185
return;
@@ -194,7 +194,7 @@ public static void DecompressBlock(ReadOnlySpan<byte> blockData, Footprint footp
194194
}
195195

196196
// Fallback for void extent, multi-partition, dual plane, HDR
197-
var logicalBlock = LogicalBlock.UnpackLogicalBlock(footprint, blockBits, in info);
197+
LogicalBlock? logicalBlock = LogicalBlock.UnpackLogicalBlock(footprint, blockBits, in info);
198198
if (logicalBlock is null)
199199
{
200200
return;
@@ -216,7 +216,7 @@ public static void DecompressBlock(ReadOnlySpan<byte> blockData, Footprint footp
216216
public static Span<float> DecompressHdrImage(ReadOnlySpan<byte> astcData, int width, int height, Footprint footprint)
217217
{
218218
const int channelsPerPixel = 4;
219-
var imageBuffer = new float[width * height * channelsPerPixel];
219+
float[] imageBuffer = new float[width * height * channelsPerPixel];
220220
if (!DecompressHdrImage(astcData, width, height, footprint, imageBuffer))
221221
{
222222
return [];
@@ -243,13 +243,13 @@ public static bool DecompressHdrImage(ReadOnlySpan<byte> astcData, int width, in
243243
}
244244

245245
const int channelsPerPixel = 4;
246-
var decodedBlock = Array.Empty<float>();
246+
float[] decodedBlock = [];
247247

248248
try
249249
{
250250
// Create a buffer once for fallback blocks; fast path writes directly to image
251251
decodedBlock = ArrayPool<float>.Shared.Rent(footprint.Width * footprint.Height * channelsPerPixel);
252-
var decodedPixels = decodedBlock.AsSpan();
252+
Span<float> decodedPixels = decodedBlock.AsSpan();
253253
int blockIndex = 0;
254254
int footprintWidth = footprint.Width;
255255
int footprintHeight = footprint.Height;
@@ -264,16 +264,16 @@ public static bool DecompressHdrImage(ReadOnlySpan<byte> astcData, int width, in
264264
continue;
265265
}
266266

267-
ulong low = BinaryPrimitives.ReadUInt64LittleEndian(astcData.Slice(blockDataOffset));
268-
ulong high = BinaryPrimitives.ReadUInt64LittleEndian(astcData.Slice(blockDataOffset + 8));
269-
var blockBits = new UInt128(high, low);
267+
ulong low = BinaryPrimitives.ReadUInt64LittleEndian(astcData[blockDataOffset..]);
268+
ulong high = BinaryPrimitives.ReadUInt64LittleEndian(astcData[(blockDataOffset + 8)..]);
269+
UInt128 blockBits = new(high, low);
270270

271271
int dstBaseX = blockX * footprintWidth;
272272
int dstBaseY = blockY * footprintHeight;
273273
int copyWidth = Math.Min(footprintWidth, width - dstBaseX);
274274
int copyHeight = Math.Min(footprintHeight, height - dstBaseY);
275275

276-
var info = BlockInfo.Decode(blockBits);
276+
BlockInfo info = BlockInfo.Decode(blockBits);
277277
if (!info.IsValid)
278278
{
279279
continue;
@@ -302,7 +302,7 @@ public static bool DecompressHdrImage(ReadOnlySpan<byte> astcData, int width, in
302302
else
303303
{
304304
// Fallback: LogicalBlock path for void extent, multi-partition, dual plane
305-
var logicalBlock = LogicalBlock.UnpackLogicalBlock(footprint, blockBits, in info);
305+
LogicalBlock? logicalBlock = LogicalBlock.UnpackLogicalBlock(footprint, blockBits, in info);
306306
if (logicalBlock is null)
307307
{
308308
continue;
@@ -312,7 +312,7 @@ public static bool DecompressHdrImage(ReadOnlySpan<byte> astcData, int width, in
312312
{
313313
for (int column = 0; column < footprintWidth; ++column)
314314
{
315-
var pixelOffset = (footprintWidth * row * channelsPerPixel) + (column * channelsPerPixel);
315+
int pixelOffset = (footprintWidth * row * channelsPerPixel) + (column * channelsPerPixel);
316316
logicalBlock.WriteHdrPixel(column, row, decodedPixels.Slice(pixelOffset, channelsPerPixel));
317317
}
318318
}
@@ -349,7 +349,7 @@ public static bool DecompressHdrImage(ReadOnlySpan<byte> astcData, int width, in
349349
/// </returns>
350350
public static Span<float> DecompressHdrImage(ReadOnlySpan<byte> astcData, int width, int height, FootprintType footprint)
351351
{
352-
var footPrint = Footprint.FromFootprintType(footprint);
352+
Footprint footPrint = Footprint.FromFootprintType(footprint);
353353
return DecompressHdrImage(astcData, width, height, footPrint);
354354
}
355355

@@ -363,10 +363,10 @@ public static void DecompressHdrBlock(ReadOnlySpan<byte> blockData, Footprint fo
363363
{
364364
// Read the 16 bytes that make up the ASTC block as a 128-bit value
365365
ulong low = BinaryPrimitives.ReadUInt64LittleEndian(blockData);
366-
ulong high = BinaryPrimitives.ReadUInt64LittleEndian(blockData.Slice(8));
367-
var blockBits = new UInt128(high, low);
366+
ulong high = BinaryPrimitives.ReadUInt64LittleEndian(blockData[8..]);
367+
UInt128 blockBits = new(high, low);
368368

369-
var info = BlockInfo.Decode(blockBits);
369+
BlockInfo info = BlockInfo.Decode(blockBits);
370370
if (!info.IsValid)
371371
{
372372
return;
@@ -380,7 +380,7 @@ public static void DecompressHdrBlock(ReadOnlySpan<byte> blockData, Footprint fo
380380
}
381381

382382
// Fallback for void extent, multi-partition, dual plane
383-
var logicalBlock = LogicalBlock.UnpackLogicalBlock(footprint, blockBits, in info);
383+
LogicalBlock? logicalBlock = LogicalBlock.UnpackLogicalBlock(footprint, blockBits, in info);
384384
if (logicalBlock is null)
385385
{
386386
return;
@@ -391,7 +391,7 @@ public static void DecompressHdrBlock(ReadOnlySpan<byte> blockData, Footprint fo
391391
{
392392
for (int column = 0; column < footprint.Width; ++column)
393393
{
394-
var pixelOffset = (footprint.Width * row * channelsPerPixel) + (column * channelsPerPixel);
394+
int pixelOffset = (footprint.Width * row * channelsPerPixel) + (column * channelsPerPixel);
395395
logicalBlock.WriteHdrPixel(column, row, buffer.Slice(pixelOffset, channelsPerPixel));
396396
}
397397
}
@@ -406,7 +406,7 @@ internal static Span<byte> DecompressImage(AstcFile file)
406406

407407
internal static Span<byte> DecompressImage(ReadOnlySpan<byte> astcData, int width, int height, FootprintType footprint)
408408
{
409-
var footPrint = Footprint.FromFootprintType(footprint);
409+
Footprint footPrint = Footprint.FromFootprintType(footprint);
410410

411411
return DecompressImage(astcData, width, height, footPrint);
412412
}

src/ImageSharp.Textures.Astc/BiseEncoding/BoundedIntegerSequenceCodec.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ internal partial class BoundedIntegerSequenceCodec
116116

117117
private static readonly (BiseEncodingMode Mode, int BitCount)[] PackingModeCache = InitPackingModeCache();
118118

119-
private BiseEncodingMode encoding;
120-
private int bitCount;
121-
122119
/// <summary>
123120
/// Initializes a new instance of the <see cref="BoundedIntegerSequenceCodec"/> class.
124121
/// operate on sequences of integers and produce bit patterns that pack the
@@ -143,14 +140,14 @@ internal partial class BoundedIntegerSequenceCodec
143140
/// <param name="range">Creates a decoder that decodes values within [0, <paramref name="range"/>] (inclusive).</param>
144141
protected BoundedIntegerSequenceCodec(int range)
145142
{
146-
var (encodingMode, bitCount) = GetPackingModeBitCount(range);
147-
this.encoding = encodingMode;
148-
this.bitCount = bitCount;
143+
(BiseEncodingMode encodingMode, int bitCount) = GetPackingModeBitCount(range);
144+
this.Encoding = encodingMode;
145+
this.BitCount = bitCount;
149146
}
150147

151-
protected BiseEncodingMode Encoding => this.encoding;
148+
protected BiseEncodingMode Encoding { get; }
152149

153-
protected int BitCount => this.bitCount;
150+
protected int BitCount { get; }
154151

155152
/// <summary>
156153
/// The number of bits needed to encode the given number of values with respect to the
@@ -169,14 +166,14 @@ public static (BiseEncodingMode Mode, int BitCount) GetPackingModeBitCount(int r
169166
/// </summary>
170167
public static int GetBitCount(BiseEncodingMode encodingMode, int valuesCount, int bitCount)
171168
{
172-
var encodingBitCount = encodingMode switch
169+
int encodingBitCount = encodingMode switch
173170
{
174171
BiseEncodingMode.TritEncoding => ((valuesCount * 8) + 4) / 5,
175172
BiseEncodingMode.QuintEncoding => ((valuesCount * 7) + 2) / 3,
176173
BiseEncodingMode.BitEncoding => 0,
177174
_ => throw new ArgumentOutOfRangeException(nameof(encodingMode), "Invalid encoding mode"),
178175
};
179-
var baseBitCount = valuesCount * bitCount;
176+
int baseBitCount = valuesCount * bitCount;
180177

181178
return encodingBitCount + baseBitCount;
182179
}
@@ -186,7 +183,7 @@ public static int GetBitCount(BiseEncodingMode encodingMode, int valuesCount, in
186183
/// </summary>
187184
public static int GetBitCountForRange(int valuesCount, int range)
188185
{
189-
var (mode, bitCount) = GetPackingModeBitCount(range);
186+
(BiseEncodingMode mode, int bitCount) = GetPackingModeBitCount(range);
190187

191188
return GetBitCount(mode, valuesCount, bitCount);
192189
}
@@ -196,20 +193,20 @@ public static int GetBitCountForRange(int valuesCount, int range)
196193
/// </summary>
197194
protected int GetEncodedBlockSize()
198195
{
199-
var (blockSize, extraBlockSize) = this.encoding switch
196+
(int blockSize, int extraBlockSize) = this.Encoding switch
200197
{
201198
BiseEncodingMode.TritEncoding => (5, 8),
202199
BiseEncodingMode.QuintEncoding => (3, 7),
203200
BiseEncodingMode.BitEncoding => (1, 0),
204201
_ => (0, 0),
205202
};
206203

207-
return extraBlockSize + (blockSize * this.bitCount);
204+
return extraBlockSize + (blockSize * this.BitCount);
208205
}
209206

210207
private static int[] FlattenEncodings(int[][] jagged, int stride)
211208
{
212-
var flat = new int[jagged.Length * stride];
209+
int[] flat = new int[jagged.Length * stride];
213210
for (int i = 0; i < jagged.Length; i++)
214211
{
215212
for (int j = 0; j < stride; j++)
@@ -223,7 +220,7 @@ private static int[] FlattenEncodings(int[][] jagged, int stride)
223220

224221
private static (BiseEncodingMode, int)[] InitPackingModeCache()
225222
{
226-
var cache = new (BiseEncodingMode, int)[1 << Log2MaxRangeForBits];
223+
(BiseEncodingMode, int)[] cache = new (BiseEncodingMode, int)[1 << Log2MaxRangeForBits];
227224

228225
// Precompute for all valid ranges [1, 255]
229226
for (int range = 1; range < cache.Length; range++)
@@ -239,13 +236,13 @@ private static (BiseEncodingMode, int)[] InitPackingModeCache()
239236
}
240237

241238
int maxValue = index < 0
242-
? MaxRanges[MaxRanges.Length - 1] + 1
239+
? MaxRanges[^1] + 1
243240
: MaxRanges[index] + 1;
244241

245242
// Check QuintEncoding (5), TritEncoding (3), BitEncoding (1) in descending order
246243
BiseEncodingMode encodingMode = BiseEncodingMode.Unknown;
247244
ReadOnlySpan<BiseEncodingMode> modes = [BiseEncodingMode.QuintEncoding, BiseEncodingMode.TritEncoding, BiseEncodingMode.BitEncoding];
248-
foreach (var em in modes)
245+
foreach (BiseEncodingMode em in modes)
249246
{
250247
if (maxValue % (int)em == 0 && int.IsPow2(maxValue / (int)em))
251248
{

src/ImageSharp.Textures.Astc/BiseEncoding/BoundedIntegerSequenceDecoder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public BoundedIntegerSequenceDecoder(int range)
1616

1717
public static BoundedIntegerSequenceDecoder GetCached(int range)
1818
{
19-
var decoder = Cache[range];
19+
BoundedIntegerSequenceDecoder? decoder = Cache[range];
2020
if (decoder is null)
2121
{
2222
decoder = new BoundedIntegerSequenceDecoder(range);
@@ -89,7 +89,7 @@ public void Decode(int valuesCount, ref BitStream bitSource, Span<int> result)
8989
/// <exception cref="InvalidOperationException">Thrown when there are not enough bits to decode.</exception>
9090
public int[] Decode(int valuesCount, ref BitStream bitSource)
9191
{
92-
var result = new int[valuesCount];
92+
int[] result = new int[valuesCount];
9393
this.Decode(valuesCount, ref bitSource, result);
9494
return result;
9595
}

src/ImageSharp.Textures.Astc/BiseEncoding/BoundedIntegerSequenceEncoder.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void Encode(ref BitStream bitSink)
3333
switch (this.Encoding)
3434
{
3535
case BiseEncodingMode.TritEncoding:
36-
var trits = new List<int>();
36+
List<int> trits = [];
3737
for (int i = 0; i < 5; ++i)
3838
{
3939
if (index < this.values.Count)
@@ -49,10 +49,10 @@ public void Encode(ref BitStream bitSink)
4949
EncodeISEBlock<int>(trits, this.BitCount, ref bitSink, ref bitsWrittenCount, totalBitCount);
5050
break;
5151
case BiseEncodingMode.QuintEncoding:
52-
var quints = new List<int>();
52+
List<int> quints = [];
5353
for (int i = 0; i < 3; ++i)
5454
{
55-
var value = index < this.values.Count
55+
int value = index < this.values.Count
5656
? this.values[index++]
5757
: 0;
5858
quints.Add(value);
@@ -82,8 +82,8 @@ private static void EncodeISEBlock<T>(List<int> values, int bitsPerValue, ref Bi
8282
? InterleavedQuintBits
8383
: InterleavedTritBits;
8484

85-
var nonBitComponents = new int[valueCount];
86-
var bitComponents = new int[valueCount];
85+
int[] nonBitComponents = new int[valueCount];
86+
int[] bitComponents = new int[valueCount];
8787
for (int i = 0; i < valueCount; ++i)
8888
{
8989
bitComponents[i] = values[i] & ((1 << bitsPerValue) - 1);

0 commit comments

Comments
 (0)