Fixed some code issues

This commit is contained in:
Darth Affe 2024-07-06 19:50:47 +02:00
parent 3ccb62538d
commit 9c67e49293
6 changed files with 10 additions and 21 deletions

View File

@ -44,7 +44,7 @@ public class ColorSourceGenerator : IIncrementalGenerator
context.RegisterPostInitializationOutput(ctx => ctx.AddSource("ColorGeneratorAttribute.g.cs", SourceText.From(COLOR_GENERATOR_ATTRIBUTE_SOURCE, Encoding.UTF8)));
IncrementalValueProvider<ImmutableArray<ColorFormatData>> classes = context.SyntaxProvider
.ForAttributeWithMetadataName("HPPH.ColorGeneratorAttribute", static (_, __) => true, Transform)
.ForAttributeWithMetadataName("HPPH.ColorGeneratorAttribute", static (_, _) => true, Transform)
.Where(type => type.HasValue)
.Select((data, _) => data!.Value)
.Collect();

View File

@ -37,7 +37,7 @@ public class ColorSortSourceGenerator : IIncrementalGenerator
context.RegisterPostInitializationOutput(ctx => ctx.AddSource("ColorSortGeneratorAttribute.g.cs", SourceText.From(SORT_GENERATOR_ATTRIBUTE_SOURCE, Encoding.UTF8)));
IncrementalValueProvider<ImmutableArray<ColorSortData>> classes = context.SyntaxProvider
.ForAttributeWithMetadataName("HPPH.ColorSortGeneratorAttribute", static (_, __) => true, Transform)
.ForAttributeWithMetadataName("HPPH.ColorSortGeneratorAttribute", static (_, _) => true, Transform)
.Where(type => type.HasValue)
.Select((data, _) => data!.Value)
.Collect();

View File

@ -1,14 +0,0 @@
namespace HPPH.Reference;
internal static class HPPHExtensions
{
public static byte GetByteValueFromPercentage(this float percentage)
{
if (float.IsNaN(percentage) || (percentage < 0)) return 0;
return (byte)(percentage >= 1.0f ? 255 : percentage * 256.0f);
}
public static float GetPercentageFromByteValue(this byte value)
=> value == 255 ? 1.0f : (value / 256.0f);
}

View File

@ -145,7 +145,7 @@ public readonly ref struct RefImage<TColor>
private int _position;
/// <inheritdoc cref="System.Collections.Generic.IEnumerator{T}.Current"/>
public TColor Current
public readonly TColor Current
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _pixels[_position];
@ -194,7 +194,7 @@ public readonly ref struct RefImage<TColor>
#region Indexer
public readonly ReadOnlyRefEnumerable<TColor> this[int row]
public ReadOnlyRefEnumerable<TColor> this[int row]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
@ -212,6 +212,7 @@ public readonly ref struct RefImage<TColor>
#region Constructors
// ReSharper disable once ConvertToPrimaryConstructor - Not possible with ref types
public ImageRows(ReadOnlySpan<TColor> pixels, int x, int y, int width, int height, int stride)
{
this._pixels = pixels;
@ -240,7 +241,7 @@ public readonly ref struct RefImage<TColor>
private int _position;
/// <inheritdoc cref="System.Collections.Generic.IEnumerator{T}.Current"/>
public ReadOnlyRefEnumerable<TColor> Current
public readonly ReadOnlyRefEnumerable<TColor> Current
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _rows[_position];
@ -306,6 +307,7 @@ public readonly ref struct RefImage<TColor>
#region Constructors
// ReSharper disable once ConvertToPrimaryConstructor - Not possible with ref types
public ImageColumns(ReadOnlySpan<TColor> pixels, int x, int y, int width, int height, int stride)
{
this._pixels = pixels;
@ -334,7 +336,7 @@ public readonly ref struct RefImage<TColor>
private int _position;
/// <inheritdoc cref="System.Collections.Generic.IEnumerator{T}.Current"/>
public ReadOnlyRefEnumerable<TColor> Current
public readonly ReadOnlyRefEnumerable<TColor> Current
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _columns[_position];

View File

@ -1,5 +1,6 @@
namespace HPPH;
// ReSharper disable once RedundantUnsafeContext
public static unsafe partial class PixelHelper
{
#region Methods

View File

@ -28,7 +28,7 @@ internal struct ColorCube<T>
#region Methods
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal Span<T> Slice(Span<T> fullColorList) => fullColorList.Slice(_offset, _length);
internal readonly Span<T> Slice(Span<T> fullColorList) => fullColorList.Slice(_offset, _length);
internal void Split(Span<T> fullColorList, out ColorCube<T> a, out ColorCube<T> b)
{