From 9c67e49293459fd3c09bc4ad9b0886e6f734ff83 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 6 Jul 2024 19:50:47 +0200 Subject: [PATCH] Fixed some code issues --- HPPH.Generators/ColorFormatSourceGenerator.cs | 2 +- HPPH.Generators/ColorSortSourceGenerator.cs | 2 +- HPPH.Reference/HPPHExtensions.cs | 14 -------------- HPPH/Images/RefImage.cs | 10 ++++++---- HPPH/PixelHelper.Sort.cs | 1 + HPPH/Quantization/ColorCube.cs | 2 +- 6 files changed, 10 insertions(+), 21 deletions(-) delete mode 100644 HPPH.Reference/HPPHExtensions.cs diff --git a/HPPH.Generators/ColorFormatSourceGenerator.cs b/HPPH.Generators/ColorFormatSourceGenerator.cs index fcd7af6..4f631f1 100644 --- a/HPPH.Generators/ColorFormatSourceGenerator.cs +++ b/HPPH.Generators/ColorFormatSourceGenerator.cs @@ -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> classes = context.SyntaxProvider - .ForAttributeWithMetadataName("HPPH.ColorGeneratorAttribute", static (_, __) => true, Transform) + .ForAttributeWithMetadataName("HPPH.ColorGeneratorAttribute", static (_, _) => true, Transform) .Where(type => type.HasValue) .Select((data, _) => data!.Value) .Collect(); diff --git a/HPPH.Generators/ColorSortSourceGenerator.cs b/HPPH.Generators/ColorSortSourceGenerator.cs index c05c75d..40384b1 100644 --- a/HPPH.Generators/ColorSortSourceGenerator.cs +++ b/HPPH.Generators/ColorSortSourceGenerator.cs @@ -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> classes = context.SyntaxProvider - .ForAttributeWithMetadataName("HPPH.ColorSortGeneratorAttribute", static (_, __) => true, Transform) + .ForAttributeWithMetadataName("HPPH.ColorSortGeneratorAttribute", static (_, _) => true, Transform) .Where(type => type.HasValue) .Select((data, _) => data!.Value) .Collect(); diff --git a/HPPH.Reference/HPPHExtensions.cs b/HPPH.Reference/HPPHExtensions.cs deleted file mode 100644 index 8212d6d..0000000 --- a/HPPH.Reference/HPPHExtensions.cs +++ /dev/null @@ -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); -} \ No newline at end of file diff --git a/HPPH/Images/RefImage.cs b/HPPH/Images/RefImage.cs index 8e7a725..1ed2a7b 100644 --- a/HPPH/Images/RefImage.cs +++ b/HPPH/Images/RefImage.cs @@ -145,7 +145,7 @@ public readonly ref struct RefImage private int _position; /// - public TColor Current + public readonly TColor Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _pixels[_position]; @@ -194,7 +194,7 @@ public readonly ref struct RefImage #region Indexer - public readonly ReadOnlyRefEnumerable this[int row] + public ReadOnlyRefEnumerable this[int row] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get @@ -212,6 +212,7 @@ public readonly ref struct RefImage #region Constructors + // ReSharper disable once ConvertToPrimaryConstructor - Not possible with ref types public ImageRows(ReadOnlySpan pixels, int x, int y, int width, int height, int stride) { this._pixels = pixels; @@ -240,7 +241,7 @@ public readonly ref struct RefImage private int _position; /// - public ReadOnlyRefEnumerable Current + public readonly ReadOnlyRefEnumerable Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _rows[_position]; @@ -306,6 +307,7 @@ public readonly ref struct RefImage #region Constructors + // ReSharper disable once ConvertToPrimaryConstructor - Not possible with ref types public ImageColumns(ReadOnlySpan pixels, int x, int y, int width, int height, int stride) { this._pixels = pixels; @@ -334,7 +336,7 @@ public readonly ref struct RefImage private int _position; /// - public ReadOnlyRefEnumerable Current + public readonly ReadOnlyRefEnumerable Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _columns[_position]; diff --git a/HPPH/PixelHelper.Sort.cs b/HPPH/PixelHelper.Sort.cs index 8706653..a62a015 100644 --- a/HPPH/PixelHelper.Sort.cs +++ b/HPPH/PixelHelper.Sort.cs @@ -1,5 +1,6 @@ namespace HPPH; +// ReSharper disable once RedundantUnsafeContext public static unsafe partial class PixelHelper { #region Methods diff --git a/HPPH/Quantization/ColorCube.cs b/HPPH/Quantization/ColorCube.cs index e0ee60b..184fd03 100644 --- a/HPPH/Quantization/ColorCube.cs +++ b/HPPH/Quantization/ColorCube.cs @@ -28,7 +28,7 @@ internal struct ColorCube #region Methods [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal Span Slice(Span fullColorList) => fullColorList.Slice(_offset, _length); + internal readonly Span Slice(Span fullColorList) => fullColorList.Slice(_offset, _length); internal void Split(Span fullColorList, out ColorCube a, out ColorCube b) {