瀏覽代碼

Fix warnings and tidup code

tznind 9 月之前
父節點
當前提交
5a6aae694a

+ 0 - 1
Terminal.Gui/ConsoleDrivers/NetDriver.cs

@@ -1339,7 +1339,6 @@ internal class NetDriver : ConsoleDriver
     }
     }
 
 
     private CursorVisibility? _cachedCursorVisibility;
     private CursorVisibility? _cachedCursorVisibility;
-    private static bool _supportsSixel;
 
 
     public override void UpdateCursor ()
     public override void UpdateCursor ()
     {
     {

+ 5 - 0
Terminal.Gui/Drawing/Quant/ColorQuantizer.cs

@@ -32,6 +32,11 @@ public class ColorQuantizer
 
 
     private readonly ConcurrentDictionary<Color, int> _nearestColorCache = new ();
     private readonly ConcurrentDictionary<Color, int> _nearestColorCache = new ();
 
 
+    /// <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"/>.
+    /// </summary>
+    /// <param name="pixels"></param>
     public void BuildPalette (Color [,] pixels)
     public void BuildPalette (Color [,] pixels)
     {
     {
         List<Color> allColors = new List<Color> ();
         List<Color> allColors = new List<Color> ();

+ 6 - 0
Terminal.Gui/Drawing/Quant/PopularityPaletteWithThreshold.cs

@@ -12,6 +12,11 @@ public class PopularityPaletteWithThreshold : IPaletteBuilder
     private readonly IColorDistance _colorDistance;
     private readonly IColorDistance _colorDistance;
     private readonly double _mergeThreshold;
     private readonly double _mergeThreshold;
 
 
+    /// <summary>
+    /// Creates a new instance with the given color grouping parameters.
+    /// </summary>
+    /// <param name="colorDistance">Determines which different colors can be considered the same.</param>
+    /// <param name="mergeThreshold">Threshold for merging two colors together.</param>
     public PopularityPaletteWithThreshold (IColorDistance colorDistance, double mergeThreshold)
     public PopularityPaletteWithThreshold (IColorDistance colorDistance, double mergeThreshold)
     {
     {
         _colorDistance = colorDistance;
         _colorDistance = colorDistance;
@@ -62,6 +67,7 @@ public class PopularityPaletteWithThreshold : IPaletteBuilder
     /// 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>
     /// <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)
     {
     {

+ 15 - 29
Terminal.Gui/Drawing/SixelEncoder.cs

@@ -114,7 +114,6 @@ public class SixelEncoder
         for (int x = 0; x < width; ++x)
         for (int x = 0; x < width; ++x)
         {
         {
             Array.Clear (code, 0, usedColorIdx.Count);
             Array.Clear (code, 0, usedColorIdx.Count);
-            bool anyNonTransparentPixel = false;  // Track if any non-transparent pixels are found in this column
 
 
             // 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 (int row = 0; row < bandHeight; ++row)
@@ -127,10 +126,6 @@ public class SixelEncoder
                 {
                 {
                     continue;
                     continue;
                 }
                 }
-                else
-                {
-                    anyNonTransparentPixel = true;
-                }
 
 
                 if (slots [colorIndex] == -1)
                 if (slots [colorIndex] == -1)
                 {
                 {
@@ -147,27 +142,6 @@ public class SixelEncoder
                 code [slots [colorIndex]] |= (byte)(1 << row); // Accumulate SIXEL data
                 code [slots [colorIndex]] |= (byte)(1 << row); // Accumulate SIXEL data
             }
             }
 
 
-            /*
-            // If no non-transparent pixels are found in the entire column, it's fully transparent
-            if (!anyNonTransparentPixel)
-            {
-                // Emit fully transparent pixel data: #0!<width>?$
-                result.Append ($"#0!{width}?");
-
-                // Add the line terminator: use "$-" if it's not the last line, "$" if it's the last line
-                if (x < width - 1)
-                {
-                    result.Append ("$-");
-                }
-                else
-                {
-                    result.Append ("$");
-                }
-
-                // Skip to the next column as we have already handled transparency
-                continue;
-            }*/
-
             // Handle transitions between columns
             // Handle transitions between columns
             for (int j = 0; j < usedColorIdx.Count; ++j)
             for (int j = 0; j < usedColorIdx.Count; ++j)
             {
             {
@@ -209,9 +183,21 @@ public class SixelEncoder
     private static string CodeToSixel (int code, int repeat)
     private static string CodeToSixel (int code, int repeat)
     {
     {
         char c = (char)(code + 63);
         char c = (char)(code + 63);
-        if (repeat > 3) return "!" + repeat + c;
-        if (repeat == 3) return c.ToString () + c + c;
-        if (repeat == 2) return c.ToString () + c;
+        if (repeat > 3)
+        {
+            return "!" + repeat + c;
+        }
+
+        if (repeat == 3)
+        {
+            return c.ToString () + c + c;
+        }
+
+        if (repeat == 2)
+        {
+            return c.ToString () + c;
+        }
+
         return c.ToString ();
         return c.ToString ();
     }
     }
 
 

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

@@ -2,7 +2,7 @@
 
 
 /// <summary>
 /// <summary>
 /// Describes the discovered state of sixel support and ancillary information
 /// Describes the discovered state of sixel support and ancillary information
-/// e.g. <see cref="Resolution"/>. You can use <see cref="SixelSupportDetector"/>
+/// e.g. <see cref="Resolution"/>. You can use any <see cref="ISixelSupportDetector"/>
 /// to discover this information.
 /// to discover this information.
 /// </summary>
 /// </summary>
 public class SixelSupportResult
 public class SixelSupportResult