2
0
Эх сурвалжийг харах

Run TidyCode on all new classes

tznind 10 сар өмнө
parent
commit
bcdb11e2f6

+ 5 - 5
Terminal.Gui/Drawing/AssumeSupportDetector.cs

@@ -1,19 +1,19 @@
 namespace Terminal.Gui;
 namespace Terminal.Gui;
 
 
 /// <summary>
 /// <summary>
-/// Implementation of <see cref="ISixelSupportDetector"/> that assumes best
-/// case scenario (full support including transparency with 10x20 resolution).
+///     Implementation of <see cref="ISixelSupportDetector"/> that assumes best
+///     case scenario (full support including transparency with 10x20 resolution).
 /// </summary>
 /// </summary>
 public class AssumeSupportDetector : ISixelSupportDetector
 public class AssumeSupportDetector : ISixelSupportDetector
 {
 {
-    /// <inheritdoc />
+    /// <inheritdoc/>
     public SixelSupportResult Detect ()
     public SixelSupportResult Detect ()
     {
     {
-        return new SixelSupportResult
+        return new()
         {
         {
             IsSupported = true,
             IsSupported = true,
             MaxPaletteColors = 256,
             MaxPaletteColors = 256,
-            Resolution = new Size (10, 20),
+            Resolution = new (10, 20),
             SupportsTransparency = true
             SupportsTransparency = true
         };
         };
     }
     }

+ 4 - 4
Terminal.Gui/Drawing/ISixelSupportDetector.cs

@@ -1,14 +1,14 @@
 namespace Terminal.Gui;
 namespace Terminal.Gui;
 
 
 /// <summary>
 /// <summary>
-/// Interface for detecting sixel support. Either through
-/// ansi requests to terminal or config file etc.
+///     Interface for detecting sixel support. Either through
+///     ansi requests to terminal or config file etc.
 /// </summary>
 /// </summary>
 public interface ISixelSupportDetector
 public interface ISixelSupportDetector
 {
 {
     /// <summary>
     /// <summary>
-    /// Gets the supported sixel state e.g. by sending Ansi escape sequences
-    /// or from a config file etc.
+    ///     Gets the supported sixel state e.g. by sending Ansi escape sequences
+    ///     or from a config file etc.
     /// </summary>
     /// </summary>
     /// <returns>Description of sixel support.</returns>
     /// <returns>Description of sixel support.</returns>
     public SixelSupportResult Detect ();
     public SixelSupportResult Detect ();

+ 19 - 18
Terminal.Gui/Drawing/Quant/ColorQuantizer.cs

@@ -3,49 +3,49 @@
 namespace Terminal.Gui;
 namespace Terminal.Gui;
 
 
 /// <summary>
 /// <summary>
-/// Translates colors in an image into a Palette of up to <see cref="MaxColors"/> colors (typically 256).
+///     Translates colors in an image into a Palette of up to <see cref="MaxColors"/> colors (typically 256).
 /// </summary>
 /// </summary>
 public class ColorQuantizer
 public class ColorQuantizer
 {
 {
     /// <summary>
     /// <summary>
-    /// Gets the current colors in the palette based on the last call to
-    /// <see cref="BuildPalette"/>.
+    ///     Gets the current colors in the palette based on the last call to
+    ///     <see cref="BuildPalette"/>.
     /// </summary>
     /// </summary>
     public IReadOnlyCollection<Color> Palette { get; private set; } = new List<Color> ();
     public IReadOnlyCollection<Color> Palette { get; private set; } = new List<Color> ();
 
 
     /// <summary>
     /// <summary>
-    /// Gets or sets the maximum number of colors to put into the <see cref="Palette"/>.
-    /// Defaults to 256 (the maximum for sixel images).
+    ///     Gets or sets the maximum number of colors to put into the <see cref="Palette"/>.
+    ///     Defaults to 256 (the maximum for sixel images).
     /// </summary>
     /// </summary>
     public int MaxColors { get; set; } = 256;
     public int MaxColors { get; set; } = 256;
 
 
     /// <summary>
     /// <summary>
-    /// Gets or sets the algorithm used to map novel colors into existing
-    /// palette colors (closest match). Defaults to <see cref="EuclideanColorDistance"/>
+    ///     Gets or sets the algorithm used to map novel colors into existing
+    ///     palette colors (closest match). Defaults to <see cref="EuclideanColorDistance"/>
     /// </summary>
     /// </summary>
     public IColorDistance DistanceAlgorithm { get; set; } = new EuclideanColorDistance ();
     public IColorDistance DistanceAlgorithm { get; set; } = new EuclideanColorDistance ();
 
 
     /// <summary>
     /// <summary>
-    /// Gets or sets the algorithm used to build the <see cref="Palette"/>.
+    ///     Gets or sets the algorithm used to build the <see cref="Palette"/>.
     /// </summary>
     /// </summary>
-    public IPaletteBuilder PaletteBuildingAlgorithm { get; set; } = new PopularityPaletteWithThreshold (new EuclideanColorDistance (),8) ;
+    public IPaletteBuilder PaletteBuildingAlgorithm { get; set; } = new PopularityPaletteWithThreshold (new EuclideanColorDistance (), 8);
 
 
     private readonly ConcurrentDictionary<Color, int> _nearestColorCache = new ();
     private readonly ConcurrentDictionary<Color, int> _nearestColorCache = new ();
 
 
     /// <summary>
     /// <summary>
-    /// Builds a <see cref="Palette"/> of colors that most represent the colors used in <paramref name="pixels"/> image.
-    /// This is based on the currently configured <see cref="PaletteBuildingAlgorithm"/>.
+    ///     Builds a <see cref="Palette"/> of colors that most represent the colors used in <paramref name="pixels"/> image.
+    ///     This is based on the currently configured <see cref="PaletteBuildingAlgorithm"/>.
     /// </summary>
     /// </summary>
     /// <param name="pixels"></param>
     /// <param name="pixels"></param>
     public void BuildPalette (Color [,] pixels)
     public void BuildPalette (Color [,] pixels)
     {
     {
-        List<Color> allColors = new List<Color> ();
+        List<Color> allColors = new ();
         int width = pixels.GetLength (0);
         int width = pixels.GetLength (0);
         int height = pixels.GetLength (1);
         int height = pixels.GetLength (1);
 
 
-        for (int x = 0; x < width; x++)
+        for (var x = 0; x < width; x++)
         {
         {
-            for (int y = 0; y < height; y++)
+            for (var y = 0; y < height; y++)
             {
             {
                 allColors.Add (pixels [x, y]);
                 allColors.Add (pixels [x, y]);
             }
             }
@@ -57,14 +57,14 @@ public class ColorQuantizer
 
 
     public int GetNearestColor (Color toTranslate)
     public int GetNearestColor (Color toTranslate)
     {
     {
-        if (_nearestColorCache.TryGetValue (toTranslate, out var cachedAnswer))
+        if (_nearestColorCache.TryGetValue (toTranslate, out int cachedAnswer))
         {
         {
             return cachedAnswer;
             return cachedAnswer;
         }
         }
 
 
         // Simple nearest color matching based on DistanceAlgorithm
         // Simple nearest color matching based on DistanceAlgorithm
-        double minDistance = double.MaxValue;
-        int nearestIndex = 0;
+        var minDistance = double.MaxValue;
+        var nearestIndex = 0;
 
 
         for (var index = 0; index < Palette.Count; index++)
         for (var index = 0; index < Palette.Count; index++)
         {
         {
@@ -79,6 +79,7 @@ public class ColorQuantizer
         }
         }
 
 
         _nearestColorCache.TryAdd (toTranslate, nearestIndex);
         _nearestColorCache.TryAdd (toTranslate, nearestIndex);
+
         return nearestIndex;
         return nearestIndex;
     }
     }
-}
+}

+ 16 - 14
Terminal.Gui/Drawing/Quant/EuclideanColorDistance.cs

@@ -1,20 +1,21 @@
 namespace Terminal.Gui;
 namespace Terminal.Gui;
 
 
 /// <summary>
 /// <summary>
-/// <para>
-/// Calculates the distance between two colors using Euclidean distance in 3D RGB space.
-/// This measures the straight-line distance between the two points representing the colors.
-///</para>
-/// <para>
-/// Euclidean distance in RGB space is calculated as:
-/// </para>
-/// <code>
-///     √((R2 - R1)² + (G2 - G1)² + (B2 - B1)²)
-/// </code>
-/// <remarks>Values vary from 0 to ~441.67 linearly</remarks>
-/// 
-/// <remarks>This distance metric is commonly used for comparing colors in RGB space, though
-/// it doesn't account for perceptual differences in color.</remarks>
+///     <para>
+///         Calculates the distance between two colors using Euclidean distance in 3D RGB space.
+///         This measures the straight-line distance between the two points representing the colors.
+///     </para>
+///     <para>
+///         Euclidean distance in RGB space is calculated as:
+///     </para>
+///     <code>
+///      √((R2 - R1)² + (G2 - G1)² + (B2 - B1)²)
+///  </code>
+///     <remarks>Values vary from 0 to ~441.67 linearly</remarks>
+///     <remarks>
+///         This distance metric is commonly used for comparing colors in RGB space, though
+///         it doesn't account for perceptual differences in color.
+///     </remarks>
 /// </summary>
 /// </summary>
 public class EuclideanColorDistance : IColorDistance
 public class EuclideanColorDistance : IColorDistance
 {
 {
@@ -24,6 +25,7 @@ public class EuclideanColorDistance : IColorDistance
         int rDiff = c1.R - c2.R;
         int rDiff = c1.R - c2.R;
         int gDiff = c1.G - c2.G;
         int gDiff = c1.G - c2.G;
         int bDiff = c1.B - c2.B;
         int bDiff = c1.B - c2.B;
+
         return Math.Sqrt (rDiff * rDiff + gDiff * gDiff + bDiff * bDiff);
         return Math.Sqrt (rDiff * rDiff + gDiff * gDiff + bDiff * bDiff);
     }
     }
 }
 }

+ 5 - 5
Terminal.Gui/Drawing/Quant/IColorDistance.cs

@@ -1,15 +1,15 @@
 namespace Terminal.Gui;
 namespace Terminal.Gui;
 
 
 /// <summary>
 /// <summary>
-/// Interface for algorithms that compute the relative distance between pairs of colors.
-/// This is used for color matching to a limited palette, such as in Sixel rendering.
+///     Interface for algorithms that compute the relative distance between pairs of colors.
+///     This is used for color matching to a limited palette, such as in Sixel rendering.
 /// </summary>
 /// </summary>
 public interface IColorDistance
 public interface IColorDistance
 {
 {
     /// <summary>
     /// <summary>
-    /// Computes a similarity metric between two <see cref="Color"/> instances.
-    /// A larger value indicates more dissimilar colors, while a smaller value indicates more similar colors.
-    /// The metric is internally consistent for the given algorithm.
+    ///     Computes a similarity metric between two <see cref="Color"/> instances.
+    ///     A larger value indicates more dissimilar colors, while a smaller value indicates more similar colors.
+    ///     The metric is internally consistent for the given algorithm.
     /// </summary>
     /// </summary>
     /// <param name="c1">The first color.</param>
     /// <param name="c1">The first color.</param>
     /// <param name="c2">The second color.</param>
     /// <param name="c2">The second color.</param>

+ 7 - 5
Terminal.Gui/Drawing/Quant/IPaletteBuilder.cs

@@ -1,16 +1,18 @@
 namespace Terminal.Gui;
 namespace Terminal.Gui;
 
 
 /// <summary>
 /// <summary>
-/// Builds a palette of a given size for a given set of input colors.
+///     Builds a palette of a given size for a given set of input colors.
 /// </summary>
 /// </summary>
 public interface IPaletteBuilder
 public interface IPaletteBuilder
 {
 {
     /// <summary>
     /// <summary>
-    /// Reduce the number of <paramref name="colors"/> to <paramref name="maxColors"/> (or less)
-    /// using an appropriate selection algorithm.
+    ///     Reduce the number of <paramref name="colors"/> to <paramref name="maxColors"/> (or less)
+    ///     using an appropriate selection algorithm.
     /// </summary>
     /// </summary>
-    /// <param name="colors">Color of every pixel in the image. Contains duplication in order
-    /// to support algorithms that weigh how common a color is.</param>
+    /// <param name="colors">
+    ///     Color of every pixel in the image. Contains duplication in order
+    ///     to support algorithms that weigh how common a color is.
+    /// </param>
     /// <param name="maxColors">The maximum number of colours that should be represented.</param>
     /// <param name="maxColors">The maximum number of colours that should be represented.</param>
     /// <returns></returns>
     /// <returns></returns>
     List<Color> BuildPalette (List<Color> colors, int maxColors);
     List<Color> BuildPalette (List<Color> colors, int maxColors);

+ 8 - 8
Terminal.Gui/Drawing/Quant/PopularityPaletteWithThreshold.cs

@@ -2,10 +2,10 @@
 using Color = Terminal.Gui.Color;
 using Color = Terminal.Gui.Color;
 
 
 /// <summary>
 /// <summary>
-/// Simple fast palette building algorithm which uses the frequency that a color is seen
-/// to determine whether it will appear in the final palette. Includes a threshold where
-/// by colors will be considered 'the same'. This reduces the chance of under represented
-/// colors being missed completely.
+///     Simple fast palette building algorithm which uses the frequency that a color is seen
+///     to determine whether it will appear in the final palette. Includes a threshold where
+///     by colors will be considered 'the same'. This reduces the chance of under represented
+///     colors being missed completely.
 /// </summary>
 /// </summary>
 public class PopularityPaletteWithThreshold : IPaletteBuilder
 public class PopularityPaletteWithThreshold : IPaletteBuilder
 {
 {
@@ -13,7 +13,7 @@ public class PopularityPaletteWithThreshold : IPaletteBuilder
     private readonly double _mergeThreshold;
     private readonly double _mergeThreshold;
 
 
     /// <summary>
     /// <summary>
-    /// Creates a new instance with the given color grouping parameters.
+    ///     Creates a new instance with the given color grouping parameters.
     /// </summary>
     /// </summary>
     /// <param name="colorDistance">Determines which different colors can be considered the same.</param>
     /// <param name="colorDistance">Determines which different colors can be considered the same.</param>
     /// <param name="mergeThreshold">Threshold for merging two colors together.</param>
     /// <param name="mergeThreshold">Threshold for merging two colors together.</param>
@@ -31,7 +31,7 @@ public class PopularityPaletteWithThreshold : IPaletteBuilder
         }
         }
 
 
         // Step 1: Build the histogram of colors (count occurrences)
         // Step 1: Build the histogram of colors (count occurrences)
-        Dictionary<Color, int> colorHistogram = new Dictionary<Color, int> ();
+        Dictionary<Color, int> colorHistogram = new ();
 
 
         foreach (Color color in colors)
         foreach (Color color in colors)
         {
         {
@@ -64,14 +64,14 @@ public class PopularityPaletteWithThreshold : IPaletteBuilder
     }
     }
 
 
     /// <summary>
     /// <summary>
-    /// Merge colors in the histogram if they are within the threshold distance
+    ///     Merge colors in the histogram if they are within the threshold distance
     /// </summary>
     /// </summary>
     /// <param name="colorHistogram"></param>
     /// <param name="colorHistogram"></param>
     /// <param name="maxColors"></param>
     /// <param name="maxColors"></param>
     /// <returns></returns>
     /// <returns></returns>
     private Dictionary<Color, int> MergeSimilarColors (Dictionary<Color, int> colorHistogram, int maxColors)
     private Dictionary<Color, int> MergeSimilarColors (Dictionary<Color, int> colorHistogram, int maxColors)
     {
     {
-        Dictionary<Color, int> mergedHistogram = new Dictionary<Color, int> ();
+        Dictionary<Color, int> mergedHistogram = new ();
 
 
         foreach (KeyValuePair<Color, int> entry in colorHistogram)
         foreach (KeyValuePair<Color, int> entry in colorHistogram)
         {
         {

+ 39 - 36
Terminal.Gui/Drawing/SixelEncoder.cs

@@ -4,12 +4,10 @@
 // libsixel (C/C++) - https://github.com/saitoha/libsixel
 // libsixel (C/C++) - https://github.com/saitoha/libsixel
 // Copyright (c) 2014-2016 Hayaki Saito @license MIT
 // Copyright (c) 2014-2016 Hayaki Saito @license MIT
 
 
-using Terminal.Gui;
-
 namespace Terminal.Gui;
 namespace Terminal.Gui;
 
 
 /// <summary>
 /// <summary>
-/// Encodes a images into the sixel console image output format.
+///     Encodes a images into the sixel console image output format.
 /// </summary>
 /// </summary>
 public class SixelEncoder
 public class SixelEncoder
 {
 {
@@ -35,32 +33,29 @@ public class SixelEncoder
 
 
    */
    */
 
 
-
     /// <summary>
     /// <summary>
-    /// Gets or sets the quantizer responsible for building a representative
-    /// limited color palette for images and for mapping novel colors in
-    /// images to their closest palette color
+    ///     Gets or sets the quantizer responsible for building a representative
+    ///     limited color palette for images and for mapping novel colors in
+    ///     images to their closest palette color
     /// </summary>
     /// </summary>
     public ColorQuantizer Quantizer { get; set; } = new ();
     public ColorQuantizer Quantizer { get; set; } = new ();
 
 
     /// <summary>
     /// <summary>
-    /// Encode the given bitmap into sixel encoding
+    ///     Encode the given bitmap into sixel encoding
     /// </summary>
     /// </summary>
     /// <param name="pixels"></param>
     /// <param name="pixels"></param>
     /// <returns></returns>
     /// <returns></returns>
     public string EncodeSixel (Color [,] pixels)
     public string EncodeSixel (Color [,] pixels)
     {
     {
-
         const string start = "\u001bP"; // Start sixel sequence
         const string start = "\u001bP"; // Start sixel sequence
 
 
-
-            string defaultRatios = this.AnyHasAlphaOfZero(pixels) ? "0;1;0": "0;0;0"; // Defaults for aspect ratio and grid size
+        string defaultRatios = AnyHasAlphaOfZero (pixels) ? "0;1;0" : "0;0;0"; // Defaults for aspect ratio and grid size
         const string completeStartSequence = "q"; // Signals beginning of sixel image data
         const string completeStartSequence = "q"; // Signals beginning of sixel image data
         const string noScaling = "\"1;1;"; // no scaling factors (1x1);
         const string noScaling = "\"1;1;"; // no scaling factors (1x1);
 
 
         string fillArea = GetFillArea (pixels);
         string fillArea = GetFillArea (pixels);
 
 
-        string pallette = GetColorPalette (pixels );
+        string pallette = GetColorPalette (pixels);
 
 
         string pixelData = WriteSixel (pixels);
         string pixelData = WriteSixel (pixels);
 
 
@@ -71,15 +66,14 @@ public class SixelEncoder
 
 
     private string WriteSixel (Color [,] pixels)
     private string WriteSixel (Color [,] pixels)
     {
     {
-
-        StringBuilder sb = new StringBuilder ();
+        var sb = new StringBuilder ();
         int height = pixels.GetLength (1);
         int height = pixels.GetLength (1);
         int width = pixels.GetLength (0);
         int width = pixels.GetLength (0);
 
 
         // Iterate over each 'row' of the image. Because each sixel write operation
         // Iterate over each 'row' of the image. Because each sixel write operation
         // outputs a screen area 6 pixels high (and 1+ across) we must process the image
         // outputs a screen area 6 pixels high (and 1+ across) we must process the image
         // 6 'y' units at once (1 band)
         // 6 'y' units at once (1 band)
-        for (int y = 0; y < height; y += 6)
+        for (var y = 0; y < height; y += 6)
         {
         {
             sb.Append (ProcessBand (pixels, y, Math.Min (6, height - y), width));
             sb.Append (ProcessBand (pixels, y, Math.Min (6, height - y), width));
 
 
@@ -107,18 +101,18 @@ public class SixelEncoder
         Array.Fill (accu, (ushort)1);
         Array.Fill (accu, (ushort)1);
         Array.Fill (slots, (short)-1);
         Array.Fill (slots, (short)-1);
 
 
-        var usedColorIdx = new List<int> ();
-        var targets = new List<List<string>> ();
+        List<int> usedColorIdx = new List<int> ();
+        List<List<string>> targets = new List<List<string>> ();
 
 
         // Process columns within the band
         // Process columns within the band
-        for (int x = 0; x < width; ++x)
+        for (var x = 0; x < width; ++x)
         {
         {
             Array.Clear (code, 0, usedColorIdx.Count);
             Array.Clear (code, 0, usedColorIdx.Count);
 
 
             // Process each row in the 6-pixel high band
             // Process each row in the 6-pixel high band
-            for (int row = 0; row < bandHeight; ++row)
+            for (var row = 0; row < bandHeight; ++row)
             {
             {
-                var color = pixels [x, startY + row];
+                Color color = pixels [x, startY + row];
 
 
                 int colorIndex = Quantizer.GetNearestColor (color);
                 int colorIndex = Quantizer.GetNearestColor (color);
 
 
@@ -129,12 +123,14 @@ public class SixelEncoder
 
 
                 if (slots [colorIndex] == -1)
                 if (slots [colorIndex] == -1)
                 {
                 {
-                    targets.Add (new List<string> ());
+                    targets.Add (new ());
+
                     if (x > 0)
                     if (x > 0)
                     {
                     {
                         last [usedColorIdx.Count] = 0;
                         last [usedColorIdx.Count] = 0;
                         accu [usedColorIdx.Count] = (ushort)x;
                         accu [usedColorIdx.Count] = (ushort)x;
                     }
                     }
+
                     slots [colorIndex] = (short)usedColorIdx.Count;
                     slots [colorIndex] = (short)usedColorIdx.Count;
                     usedColorIdx.Add (colorIndex);
                     usedColorIdx.Add (colorIndex);
                 }
                 }
@@ -143,7 +139,7 @@ public class SixelEncoder
             }
             }
 
 
             // Handle transitions between columns
             // Handle transitions between columns
-            for (int j = 0; j < usedColorIdx.Count; ++j)
+            for (var j = 0; j < usedColorIdx.Count; ++j)
             {
             {
                 if (code [j] == last [j])
                 if (code [j] == last [j])
                 {
                 {
@@ -155,6 +151,7 @@ public class SixelEncoder
                     {
                     {
                         targets [j].Add (CodeToSixel (last [j], accu [j]));
                         targets [j].Add (CodeToSixel (last [j], accu [j]));
                     }
                     }
+
                     last [j] = (sbyte)code [j];
                     last [j] = (sbyte)code [j];
                     accu [j] = 1;
                     accu [j] = 1;
                 }
                 }
@@ -162,7 +159,7 @@ public class SixelEncoder
         }
         }
 
 
         // Process remaining data for this band
         // Process remaining data for this band
-        for (int j = 0; j < usedColorIdx.Count; ++j)
+        for (var j = 0; j < usedColorIdx.Count; ++j)
         {
         {
             if (last [j] != 0)
             if (last [j] != 0)
             {
             {
@@ -172,7 +169,8 @@ public class SixelEncoder
 
 
         // Build the final output for this band
         // Build the final output for this band
         var result = new StringBuilder ();
         var result = new StringBuilder ();
-        for (int j = 0; j < usedColorIdx.Count; ++j)
+
+        for (var j = 0; j < usedColorIdx.Count; ++j)
         {
         {
             result.Append ($"#{usedColorIdx [j]}{string.Join ("", targets [j])}$");
             result.Append ($"#{usedColorIdx [j]}{string.Join ("", targets [j])}$");
         }
         }
@@ -182,7 +180,8 @@ public class SixelEncoder
 
 
     private static string CodeToSixel (int code, int repeat)
     private static string CodeToSixel (int code, int repeat)
     {
     {
-        char c = (char)(code + 63);
+        var c = (char)(code + 63);
+
         if (repeat > 3)
         if (repeat > 3)
         {
         {
             return "!" + repeat + c;
             return "!" + repeat + c;
@@ -205,16 +204,18 @@ public class SixelEncoder
     {
     {
         Quantizer.BuildPalette (pixels);
         Quantizer.BuildPalette (pixels);
 
 
-        StringBuilder paletteSb = new StringBuilder ();
+        var paletteSb = new StringBuilder ();
 
 
-        for (int i = 0; i < Quantizer.Palette.Count; i++)
+        for (var i = 0; i < Quantizer.Palette.Count; i++)
         {
         {
-            var color = Quantizer.Palette.ElementAt (i);
-            paletteSb.AppendFormat ("#{0};2;{1};{2};{3}",
-                i,
-                color.R * 100 / 255,
-                color.G * 100 / 255,
-                color.B * 100 / 255);
+            Color color = Quantizer.Palette.ElementAt (i);
+
+            paletteSb.AppendFormat (
+                                    "#{0};2;{1};{2};{3}",
+                                    i,
+                                    color.R * 100 / 255,
+                                    color.G * 100 / 255,
+                                    color.B * 100 / 255);
         }
         }
 
 
         return paletteSb.ToString ();
         return paletteSb.ToString ();
@@ -227,15 +228,16 @@ public class SixelEncoder
 
 
         return $"{widthInChars};{heightInChars}";
         return $"{widthInChars};{heightInChars}";
     }
     }
+
     private bool AnyHasAlphaOfZero (Color [,] pixels)
     private bool AnyHasAlphaOfZero (Color [,] pixels)
     {
     {
         int width = pixels.GetLength (0);
         int width = pixels.GetLength (0);
         int height = pixels.GetLength (1);
         int height = pixels.GetLength (1);
 
 
         // Loop through each pixel in the 2D array
         // Loop through each pixel in the 2D array
-        for (int x = 0; x < width; x++)
+        for (var x = 0; x < width; x++)
         {
         {
-            for (int y = 0; y < height; y++)
+            for (var y = 0; y < height; y++)
             {
             {
                 // Check if the alpha component (A) is 0
                 // Check if the alpha component (A) is 0
                 if (pixels [x, y].A == 0)
                 if (pixels [x, y].A == 0)
@@ -244,6 +246,7 @@ public class SixelEncoder
                 }
                 }
             }
             }
         }
         }
+
         return false; // No pixel with A of 0 was found
         return false; // No pixel with A of 0 was found
     }
     }
-}
+}

+ 3 - 3
Terminal.Gui/Drawing/SixelSupportResult.cs

@@ -1,9 +1,9 @@
 namespace Terminal.Gui;
 namespace Terminal.Gui;
 
 
 /// <summary>
 /// <summary>
-/// Describes the discovered state of sixel support and ancillary information
-/// e.g. <see cref="Resolution"/>. You can use any <see cref="ISixelSupportDetector"/>
-/// to discover this information.
+///     Describes the discovered state of sixel support and ancillary information
+///     e.g. <see cref="Resolution"/>. You can use any <see cref="ISixelSupportDetector"/>
+///     to discover this information.
 /// </summary>
 /// </summary>
 public class SixelSupportResult
 public class SixelSupportResult
 {
 {

+ 5 - 5
Terminal.Gui/Drawing/SixelToRender.cs

@@ -1,19 +1,19 @@
 namespace Terminal.Gui;
 namespace Terminal.Gui;
 
 
 /// <summary>
 /// <summary>
-/// Describes a request to render a given <see cref="SixelData"/> at a given <see cref="ScreenPosition"/>.
-/// Requires that the terminal and <see cref="ConsoleDriver"/> both support sixel.
+///     Describes a request to render a given <see cref="SixelData"/> at a given <see cref="ScreenPosition"/>.
+///     Requires that the terminal and <see cref="ConsoleDriver"/> both support sixel.
 /// </summary>
 /// </summary>
 public class SixelToRender
 public class SixelToRender
 {
 {
     /// <summary>
     /// <summary>
-    /// gets or sets the encoded sixel data. Use <see cref="SixelEncoder"/> to convert bitmaps
-    /// into encoded sixel data.
+    ///     gets or sets the encoded sixel data. Use <see cref="SixelEncoder"/> to convert bitmaps
+    ///     into encoded sixel data.
     /// </summary>
     /// </summary>
     public string SixelData { get; set; }
     public string SixelData { get; set; }
 
 
     /// <summary>
     /// <summary>
-    /// gets or sets where to move the cursor to before outputting the <see cref="SixelData"/>.
+    ///     gets or sets where to move the cursor to before outputting the <see cref="SixelData"/>.
     /// </summary>
     /// </summary>
     public Point ScreenPosition { get; set; }
     public Point ScreenPosition { get; set; }
 }
 }

+ 29 - 32
UICatalog/Scenarios/Images.cs

@@ -1,7 +1,6 @@
 using System;
 using System;
 using System.Collections.Concurrent;
 using System.Collections.Concurrent;
 using System.Collections.Generic;
 using System.Collections.Generic;
-using System.ComponentModel;
 using System.IO;
 using System.IO;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
@@ -70,7 +69,7 @@ public class Images : Scenario
         _sixelSupportResult = sixelSupportDetector.Detect ();
         _sixelSupportResult = sixelSupportDetector.Detect ();
 
 
         Application.Init ();
         Application.Init ();
-        _win = new() { Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}" };
+        _win = new () { Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}" };
 
 
         bool canTrueColor = Application.Driver?.SupportsTrueColor ?? false;
         bool canTrueColor = Application.Driver?.SupportsTrueColor ?? false;
 
 
@@ -79,7 +78,7 @@ public class Images : Scenario
             DisplayText = "Basic"
             DisplayText = "Basic"
         };
         };
 
 
-        _tabSixel = new()
+        _tabSixel = new ()
         {
         {
             DisplayText = "Sixel"
             DisplayText = "Sixel"
         };
         };
@@ -129,7 +128,7 @@ public class Images : Scenario
         var btnOpenImage = new Button { X = Pos.Right (cbUseTrueColor) + 2, Y = 0, Text = "Open Image" };
         var btnOpenImage = new Button { X = Pos.Right (cbUseTrueColor) + 2, Y = 0, Text = "Open Image" };
         _win.Add (btnOpenImage);
         _win.Add (btnOpenImage);
 
 
-        _tabView = new()
+        _tabView = new ()
         {
         {
             Y = Pos.Bottom (btnOpenImage), Width = Dim.Fill (), Height = Dim.Fill ()
             Y = Pos.Bottom (btnOpenImage), Width = Dim.Fill (), Height = Dim.Fill ()
         };
         };
@@ -166,19 +165,18 @@ public class Images : Scenario
         if (!_sixelSupportResult.SupportsTransparency)
         if (!_sixelSupportResult.SupportsTransparency)
         {
         {
             if (MessageBox.Query (
             if (MessageBox.Query (
-                                     "Transparency Not Supported",
-                                     "It looks like your terminal does not support transparent sixel backgrounds. Do you want to try anyway?",
-                                     "Yes",
-                                     "No")
+                                  "Transparency Not Supported",
+                                  "It looks like your terminal does not support transparent sixel backgrounds. Do you want to try anyway?",
+                                  "Yes",
+                                  "No")
                 != 0)
                 != 0)
             {
             {
                 return;
                 return;
             }
             }
         }
         }
 
 
-
-        _fire = new DoomFire (_win.Frame.Width * _pxX.Value, _win.Frame.Height * _pxY.Value);
-        _fireEncoder = new SixelEncoder ();
+        _fire = new (_win.Frame.Width * _pxX.Value, _win.Frame.Height * _pxY.Value);
+        _fireEncoder = new ();
         _fireEncoder.Quantizer.MaxColors = Math.Min (_fireEncoder.Quantizer.MaxColors, _sixelSupportResult.MaxPaletteColors);
         _fireEncoder.Quantizer.MaxColors = Math.Min (_fireEncoder.Quantizer.MaxColors, _sixelSupportResult.MaxPaletteColors);
         _fireEncoder.Quantizer.PaletteBuildingAlgorithm = new ConstPalette (_fire.Palette);
         _fireEncoder.Quantizer.PaletteBuildingAlgorithm = new ConstPalette (_fire.Palette);
 
 
@@ -294,14 +292,14 @@ public class Images : Scenario
 
 
     private void BuildSixelTab ()
     private void BuildSixelTab ()
     {
     {
-        _sixelSupported = new()
+        _sixelSupported = new ()
         {
         {
             Width = Dim.Fill (),
             Width = Dim.Fill (),
             Height = Dim.Fill (),
             Height = Dim.Fill (),
             CanFocus = true
             CanFocus = true
         };
         };
 
 
-        _sixelNotSupported = new()
+        _sixelNotSupported = new ()
         {
         {
             Width = Dim.Fill (),
             Width = Dim.Fill (),
             Height = Dim.Fill (),
             Height = Dim.Fill (),
@@ -318,7 +316,7 @@ public class Images : Scenario
                                     VerticalTextAlignment = Alignment.Center
                                     VerticalTextAlignment = Alignment.Center
                                 });
                                 });
 
 
-        _sixelView = new()
+        _sixelView = new ()
         {
         {
             Width = Dim.Percent (50),
             Width = Dim.Percent (50),
             Height = Dim.Fill (),
             Height = Dim.Fill (),
@@ -345,7 +343,6 @@ public class Images : Scenario
         btnStartFire.Accepting += BtnStartFireOnAccept;
         btnStartFire.Accepting += BtnStartFireOnAccept;
         _sixelSupported.Add (btnStartFire);
         _sixelSupported.Add (btnStartFire);
 
 
-
         var lblPxX = new Label
         var lblPxX = new Label
         {
         {
             X = Pos.Right (_sixelView),
             X = Pos.Right (_sixelView),
@@ -353,7 +350,7 @@ public class Images : Scenario
             Text = "Pixels per Col:"
             Text = "Pixels per Col:"
         };
         };
 
 
-        _pxX = new()
+        _pxX = new ()
         {
         {
             X = Pos.Right (lblPxX),
             X = Pos.Right (lblPxX),
             Y = Pos.Bottom (btnStartFire) + 1,
             Y = Pos.Bottom (btnStartFire) + 1,
@@ -367,27 +364,27 @@ public class Images : Scenario
             Text = "Pixels per Row:"
             Text = "Pixels per Row:"
         };
         };
 
 
-        _pxY = new()
+        _pxY = new ()
         {
         {
             X = Pos.Right (lblPxY),
             X = Pos.Right (lblPxY),
             Y = Pos.Bottom (_pxX),
             Y = Pos.Bottom (_pxX),
             Value = _sixelSupportResult.Resolution.Height
             Value = _sixelSupportResult.Resolution.Height
         };
         };
 
 
-        var l1 = new Label ()
+        var l1 = new Label
         {
         {
             Text = "Palette Building Algorithm",
             Text = "Palette Building Algorithm",
             Width = Dim.Auto (),
             Width = Dim.Auto (),
             X = Pos.Right (_sixelView),
             X = Pos.Right (_sixelView),
-            Y = Pos.Bottom (_pxY) + 1,
+            Y = Pos.Bottom (_pxY) + 1
         };
         };
 
 
-        _rgPaletteBuilder = new RadioGroup
+        _rgPaletteBuilder = new()
         {
         {
             RadioLabels = new []
             RadioLabels = new []
             {
             {
                 "Popularity",
                 "Popularity",
-                "Median Cut",
+                "Median Cut"
             },
             },
             X = Pos.Right (_sixelView) + 2,
             X = Pos.Right (_sixelView) + 2,
             Y = Pos.Bottom (l1),
             Y = Pos.Bottom (l1),
@@ -401,21 +398,22 @@ public class Images : Scenario
             Value = 8
             Value = 8
         };
         };
 
 
-        var lblPopThreshold = new Label ()
+        var lblPopThreshold = new Label
         {
         {
             Text = "(threshold)",
             Text = "(threshold)",
             X = Pos.Right (_popularityThreshold),
             X = Pos.Right (_popularityThreshold),
-            Y = Pos.Top (_popularityThreshold),
+            Y = Pos.Top (_popularityThreshold)
         };
         };
 
 
-        var l2 = new Label ()
+        var l2 = new Label
         {
         {
             Text = "Color Distance Algorithm",
             Text = "Color Distance Algorithm",
             Width = Dim.Auto (),
             Width = Dim.Auto (),
             X = Pos.Right (_sixelView),
             X = Pos.Right (_sixelView),
-            Y = Pos.Bottom (_rgPaletteBuilder) + 1,
+            Y = Pos.Bottom (_rgPaletteBuilder) + 1
         };
         };
-        _rgDistanceAlgorithm = new RadioGroup ()
+
+        _rgDistanceAlgorithm = new()
         {
         {
             RadioLabels = new []
             RadioLabels = new []
             {
             {
@@ -423,7 +421,7 @@ public class Images : Scenario
                 "CIE76"
                 "CIE76"
             },
             },
             X = Pos.Right (_sixelView) + 2,
             X = Pos.Right (_sixelView) + 2,
-            Y = Pos.Bottom (l2),
+            Y = Pos.Bottom (l2)
         };
         };
 
 
         _sixelSupported.Add (lblPxX);
         _sixelSupported.Add (lblPxX);
@@ -441,7 +439,7 @@ public class Images : Scenario
         _sixelView.DrawContent += SixelViewOnDrawContent;
         _sixelView.DrawContent += SixelViewOnDrawContent;
     }
     }
 
 
-    IPaletteBuilder GetPaletteBuilder ()
+    private IPaletteBuilder GetPaletteBuilder ()
     {
     {
         switch (_rgPaletteBuilder.SelectedItem)
         switch (_rgPaletteBuilder.SelectedItem)
         {
         {
@@ -451,7 +449,7 @@ public class Images : Scenario
         }
         }
     }
     }
 
 
-    IColorDistance GetDistanceAlgorithm ()
+    private IColorDistance GetDistanceAlgorithm ()
     {
     {
         switch (_rgDistanceAlgorithm.SelectedItem)
         switch (_rgDistanceAlgorithm.SelectedItem)
         {
         {
@@ -466,6 +464,7 @@ public class Images : Scenario
         if (_imageView.FullResImage == null)
         if (_imageView.FullResImage == null)
         {
         {
             MessageBox.Query ("No Image Loaded", "You must first open an image.  Use the 'Open Image' button above.", "Ok");
             MessageBox.Query ("No Image Loaded", "You must first open an image.  Use the 'Open Image' button above.", "Ok");
+
             return;
             return;
         }
         }
 
 
@@ -493,9 +492,7 @@ public class Images : Scenario
             _sixelImage.SixelData = _encodedSixelData;
             _sixelImage.SixelData = _encodedSixelData;
         }
         }
 
 
-        _sixelView.SetNeedsDisplay();
-
-
+        _sixelView.SetNeedsDisplay ();
     }
     }
 
 
     private void SixelViewOnDrawContent (object sender, DrawEventArgs e)
     private void SixelViewOnDrawContent (object sender, DrawEventArgs e)

+ 5 - 5
UnitTests/Drawing/PopularityPaletteWithThresholdTests.cs

@@ -25,7 +25,7 @@ public class PopularityPaletteWithThresholdTests
     {
     {
         // Arrange
         // Arrange
         var paletteBuilder = new PopularityPaletteWithThreshold (_colorDistance, 50);
         var paletteBuilder = new PopularityPaletteWithThreshold (_colorDistance, 50);
-        List<Color> colors = new() { new (255, 0), new (0, 255) };
+        List<Color> colors = new () { new (255, 0), new (0, 255) };
 
 
         // Act
         // Act
         List<Color> result = paletteBuilder.BuildPalette (colors, 0);
         List<Color> result = paletteBuilder.BuildPalette (colors, 0);
@@ -39,7 +39,7 @@ public class PopularityPaletteWithThresholdTests
     {
     {
         // Arrange
         // Arrange
         var paletteBuilder = new PopularityPaletteWithThreshold (_colorDistance, 50);
         var paletteBuilder = new PopularityPaletteWithThreshold (_colorDistance, 50);
-        List<Color> colors = new() { new (255, 0), new (255, 0) };
+        List<Color> colors = new () { new (255, 0), new (255, 0) };
 
 
         // Act
         // Act
         List<Color> result = paletteBuilder.BuildPalette (colors, 256);
         List<Color> result = paletteBuilder.BuildPalette (colors, 256);
@@ -55,7 +55,7 @@ public class PopularityPaletteWithThresholdTests
         // Arrange
         // Arrange
         var paletteBuilder = new PopularityPaletteWithThreshold (_colorDistance, 50); // Set merge threshold to 50
         var paletteBuilder = new PopularityPaletteWithThreshold (_colorDistance, 50); // Set merge threshold to 50
 
 
-        List<Color> colors = new List<Color>
+        List<Color> colors = new()
         {
         {
             new (255, 0), // Red
             new (255, 0), // Red
             new (250, 0), // Very close to Red
             new (250, 0), // Very close to Red
@@ -78,7 +78,7 @@ public class PopularityPaletteWithThresholdTests
         // Arrange
         // Arrange
         var paletteBuilder = new PopularityPaletteWithThreshold (_colorDistance, 50);
         var paletteBuilder = new PopularityPaletteWithThreshold (_colorDistance, 50);
 
 
-        List<Color> colors = new()
+        List<Color> colors = new ()
         {
         {
             new (255, 0), // Red
             new (255, 0), // Red
             new (0, 255) // Green
             new (0, 255) // Green
@@ -99,7 +99,7 @@ public class PopularityPaletteWithThresholdTests
         // Arrange
         // Arrange
         var paletteBuilder = new PopularityPaletteWithThreshold (_colorDistance, 50);
         var paletteBuilder = new PopularityPaletteWithThreshold (_colorDistance, 50);
 
 
-        List<Color> colors = new List<Color>
+        List<Color> colors = new()
         {
         {
             new (255, 0), // Red
             new (255, 0), // Red
             new (254, 0), // Close to Red
             new (254, 0), // Close to Red