Skip to content

Commit 5063c97

Browse files
sync
1 parent 7f31230 commit 5063c97

26 files changed

Lines changed: 176 additions & 112 deletions

CommonControls.Converter/BooleanToVisibilityConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
5757
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
5858
=> value is Visibility.Visible;
5959
}
60-
}
60+
}

CommonControls.Converter/ColorToNameConverter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
4141

4242
return colorProperty?.Name ?? color.ToString();
4343
}
44+
4445
return string.Empty;
4546
}
4647

@@ -64,7 +65,8 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
6465
}
6566
catch { return Colors.Transparent; }
6667
}
68+
6769
return Colors.Transparent;
6870
}
6971
}
70-
}
72+
}

CommonControls.Converter/EnumToBooleanConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
5353
return Binding.DoNothing;
5454
}
5555
}
56-
}
56+
}

CommonControls.Converter/NotNullToBooleanConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
4444
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
4545
=> Binding.DoNothing;
4646
}
47-
}
47+
}

CommonControls.Converter/NullToVisibilityConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
5353
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
5454
=> Binding.DoNothing;
5555
}
56-
}
56+
}

CommonControls.Images/ColorPicker.xaml.cs

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
using System.Windows.Media.Imaging;
1717
using Imaging;
1818

19+
// ReSharper disable MemberCanBeInternal
20+
1921
namespace CommonControls.Images
2022
{
2123
/// <inheritdoc cref="INotifyPropertyChanged" />
@@ -27,7 +29,7 @@ namespace CommonControls.Images
2729
/// <seealso cref="T:System.Windows.Markup.IComponentConnector" />
2830
public sealed partial class ColorPicker : INotifyPropertyChanged
2931
{
30-
private WriteableBitmap _bitmap;
32+
private WriteableBitmap? _bitmap;
3133
private bool _isDragging;
3234

3335
// Internal state
@@ -54,7 +56,7 @@ public sealed partial class ColorPicker : INotifyPropertyChanged
5456
/// <summary>
5557
/// Occurs when [color changed].
5658
/// </summary>
57-
public event DelegateColor ColorChanged;
59+
public event DelegateColor? ColorChanged;
5860

5961
/// <inheritdoc />
6062
/// <summary>
@@ -81,13 +83,15 @@ public ColorPicker()
8183
Alpha = alpha;
8284

8385
// This is the trigger that will finally make it draw
84-
this.SizeChanged += (s, e) =>
86+
SizeChanged += (s, e) =>
8587
{
86-
if (e.NewSize.Width > 0 && e.NewSize.Height > 0)
88+
if (!(e.NewSize.Width > 0) || !(e.NewSize.Height > 0))
8789
{
88-
RedrawAsync();
89-
UpdateCursors();
90+
return;
9091
}
92+
93+
RedrawAsync();
94+
UpdateCursors();
9195
};
9296
}
9397

@@ -96,7 +100,7 @@ public ColorPicker()
96100
/// When overridden in a derived class, participates in rendering operations that are directed by the layout system. The rendering instructions for this element are not used directly when this method is invoked, and are instead preserved for later asynchronous use by layout and drawing.
97101
/// </summary>
98102
/// <param name="drawingContext">The drawing instructions for a specific element. This context is provided to the layout system.</param>
99-
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
103+
protected override void OnRender(DrawingContext drawingContext)
100104
{
101105
base.OnRender(drawingContext);
102106
// If the bitmap hasn't been created yet, try to draw now
@@ -123,6 +127,12 @@ public bool ShowTextBoxes
123127

124128
// --- PROPERTIES with Change Logic ---
125129

130+
/// <summary>
131+
/// Gets or sets the hue.
132+
/// </summary>
133+
/// <value>
134+
/// The hue.
135+
/// </value>
126136
public double Hue
127137
{
128138
get => _h;
@@ -135,6 +145,12 @@ public double Hue
135145
}
136146
}
137147

148+
/// <summary>
149+
/// Gets or sets the sat.
150+
/// </summary>
151+
/// <value>
152+
/// The sat.
153+
/// </value>
138154
public double Sat
139155
{
140156
get => _s;
@@ -147,6 +163,12 @@ public double Sat
147163
}
148164
}
149165

166+
/// <summary>
167+
/// Gets or sets the value.
168+
/// </summary>
169+
/// <value>
170+
/// The value.
171+
/// </value>
150172
public double Val
151173
{
152174
get => _v;
@@ -159,6 +181,12 @@ public double Val
159181
}
160182
}
161183

184+
/// <summary>
185+
/// Gets or sets the alpha.
186+
/// </summary>
187+
/// <value>
188+
/// The alpha.
189+
/// </value>
162190
public int Alpha
163191
{
164192
get => _alpha;
@@ -365,13 +393,21 @@ private void UpdateCursors()
365393

366394
// --- RENDERING & CURSORS ---
367395

396+
/// <summary>
397+
/// Called when [size changed].
398+
/// </summary>
399+
/// <param name="sender">The sender.</param>
400+
/// <param name="e">The <see cref="SizeChangedEventArgs"/> instance containing the event data.</param>
368401
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
369402
{
370403
RedrawAsync();
371404
UpdateCursors();
372405
}
373406

374-
// This is the "Magic" pixel drawer (Same as before)
407+
/// <summary>
408+
/// This is the "Magic" pixel drawer
409+
/// Redraws the color picker asynchronous.
410+
/// </summary>
375411
private void RedrawAsync()
376412
{
377413
if (!CheckAccess())
@@ -396,7 +432,7 @@ private void RedrawAsync()
396432
PickerContainer.Height = size;
397433

398434
// 4. Create/Draw Bitmap (Standard)
399-
if (_bitmap == null || _bitmap.PixelWidth != size || _bitmap.PixelHeight != size)
435+
if (_bitmap?.PixelWidth != size || _bitmap.PixelHeight != size)
400436
{
401437
_bitmap = new WriteableBitmap(size, size, 96, 96, PixelFormats.Bgra32, null);
402438
PickerImage.Source = _bitmap;
@@ -485,6 +521,14 @@ private Point GetPointFromSv(double h, double s, double v, double r)
485521
w1 * pColor.Y + w2 * pWhite.Y + w3 * pBlack.Y);
486522
}
487523

524+
/// <summary>
525+
/// HSVs to int.
526+
/// </summary>
527+
/// <param name="h">The h.</param>
528+
/// <param name="s">The s.</param>
529+
/// <param name="v">The v.</param>
530+
/// <param name="alpha">The alpha.</param>
531+
/// <returns></returns>
488532
private static int HsvToInt(double h, double s, double v, int alpha)
489533
{
490534
double c = v * s;
@@ -593,8 +637,15 @@ private void GetSvFromPointClamped(double x, double y, double r, double hue, out
593637
v = Math.Max(0, Math.Min(1, v));
594638
}
595639

596-
597-
private bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
640+
/// <summary>
641+
/// Sets the field.
642+
/// </summary>
643+
/// <typeparam name="T"></typeparam>
644+
/// <param name="field">The field.</param>
645+
/// <param name="value">The value.</param>
646+
/// <param name="propertyName">Name of the property.</param>
647+
/// <returns>Field name</returns>
648+
private bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
598649
{
599650
if (System.Collections.Generic.EqualityComparer<T>.Default.Equals(field, value)) return false;
600651

@@ -603,7 +654,11 @@ private bool SetField<T>(ref T field, T value, [CallerMemberName] string propert
603654
return true;
604655
}
605656

606-
private void OnPropertyChanged(string propertyName) =>
657+
/// <summary>
658+
/// Called when [property changed].
659+
/// </summary>
660+
/// <param name="propertyName">Name of the property.</param>
661+
private void OnPropertyChanged(string? propertyName) =>
607662
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
608663
}
609664
}

CoreViewer/AnalyzerViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private void ApplyFilter()
240240
openFile: _ => HandleOpen(d.Name),
241241
ignore: _ => HandleIgnore(d.Name),
242242
fix: FixableAnalyzers.Contains(d.Name)
243-
? _ => global::CoreViewer.AnalyzerViewModel.HandleFix(d.Name)
243+
? _ => HandleFix(d.Name)
244244
: null));
245245
}
246246
}

Imaging/DirectBitmap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public DirectBitmap(string filePath)
130130
}
131131

132132
/// <inheritdoc />
133-
public Pixel32[] Bits { get; private set; }
133+
public Pixel32[]? Bits { get; private set; }
134134

135135
/// <summary>
136136
/// Gets the bitmap.

Imaging/DirectBitmapCore.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* PROGRAMER: Peter Geinitz (Wayfarer)
77
*/
88

9+
// ReSharper disable MemberCanBePrivate.Global
10+
911
using System;
1012
using System.Collections.Generic;
1113
using System.Linq;
@@ -67,8 +69,6 @@ internal static unsafe void SetPixelsAdaptive(
6769
IEnumerable<PixelData> pixels,
6870
int threshold)
6971
{
70-
if (pixels == null) return;
71-
7272
IEnumerable<PixelData> pixelCollection = pixels;
7373

7474
int count;
@@ -116,9 +116,9 @@ internal static unsafe void SetPixelsAdaptive(
116116
/// <param name="height">The height of the image.</param>
117117
/// <param name="pixels">Enumerable of (x, y, Pixel32) tuples to set.</param>
118118
internal static void SetPixelsSimd(Pixel32[] bits, int width, int height,
119-
IEnumerable<(int x, int y, Pixel32 color)> pixels)
119+
IEnumerable<(int x, int y, Pixel32 color)>? pixels)
120120
{
121-
if (bits == null || pixels == null) return;
121+
if (pixels == null) return;
122122

123123
// Group pixels by row and color to make contiguous writes cache-friendly
124124
var grouped = pixels
@@ -168,11 +168,11 @@ internal static unsafe void SetPixelsUnsafe(
168168
Pixel32[] bits,
169169
int width,
170170
int height,
171-
IEnumerable<PixelData> pixels,
171+
IEnumerable<PixelData>? pixels,
172172
byte* backBuffer = null,
173173
int stride = 0)
174174
{
175-
if (bits == null || pixels == null) return;
175+
if (pixels == null) return;
176176

177177
if (backBuffer != null && stride <= 0)
178178
throw new ArgumentException("Stride must be positive when backBuffer is provided.");
@@ -199,6 +199,8 @@ internal static unsafe void SetPixelsUnsafe(
199199

200200
/// <summary>
201201
/// Sets the pixels unsafe span.
202+
/// Could be private but is internal for testing purposes.
203+
/// Uses unsafe code to set pixels from a ReadOnlySpan of PixelData, which can be stackalloc'd for small batches to avoid heap allocations.
202204
/// </summary>
203205
/// <param name="bits">The bits.</param>
204206
/// <param name="width">The width.</param>
@@ -211,8 +213,6 @@ internal static unsafe void SetPixelsUnsafeSpan(
211213
int height,
212214
ReadOnlySpan<PixelData> pixels)
213215
{
214-
if (bits == null) return;
215-
216216
fixed (Pixel32* pBits = bits)
217217
{
218218
for (int i = 0; i < pixels.Length; i++)

Imaging/DirectBitmapImage.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public DirectBitmapImage(int width, int height)
8787
/// </summary>
8888
/// <param name="bits">The pixel array (BGRA32).</param>
8989
/// <param name="width">The width of the image.</param>
90-
public DirectBitmapImage(Pixel32[] bits, int width)
90+
public DirectBitmapImage(Pixel32[]? bits, int width)
9191
{
9292
if (bits == null) throw new ArgumentNullException(nameof(bits));
9393
if (width <= 0) throw new ArgumentOutOfRangeException(nameof(width));
@@ -115,7 +115,7 @@ public DirectBitmapImage(Pixel32[] bits, int width)
115115
/// <summary>
116116
/// Gets the raw pixel buffer.
117117
/// </summary>
118-
public Pixel32[] Bits { get; }
118+
public Pixel32[]? Bits { get; }
119119

120120
/// <summary>
121121
/// Gets the cached converted BitmapImage.
@@ -219,6 +219,7 @@ public void ApplyColorMatrix(float[][] matrix)
219219
/// Sets pixels from PixelData collection efficiently.
220220
/// </summary>
221221
/// <param name="pixels">Collection of PixelData (x, y, RGBA).</param>
222+
/// <param name="threshold">The threshold.</param>
222223
public void SetPixels(IEnumerable<PixelData> pixels, int threshold = 64)
223224
{
224225
lock (_syncLock)
@@ -331,7 +332,6 @@ private void Dispose(bool disposing)
331332
if (disposing && _bitsHandle.IsAllocated)
332333
{
333334
_cachedImage = null;
334-
335335
}
336336

337337
if (_bitsHandle.IsAllocated)

0 commit comments

Comments
 (0)