Skip to content

Commit db1e37f

Browse files
committed
Added Enumerator to Image
1 parent ba5233b commit db1e37f

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

ScreenCapture.NET/Model/Image.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,50 @@ public TColor[] ToArray()
9494
return array;
9595
}
9696

97+
/// <inheritdoc cref="System.Collections.IEnumerable.GetEnumerator"/>
98+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
99+
public Enumerator GetEnumerator() => new(_pixels);
100+
97101
#endregion
98102

103+
public ref struct Enumerator
104+
{
105+
#region Properties & Fields
106+
107+
private readonly ReadOnlySpan<TColor> _pixels;
108+
private int _position;
109+
110+
/// <inheritdoc cref="System.Collections.Generic.IEnumerator{T}.Current"/>
111+
public TColor Current
112+
{
113+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
114+
get => _pixels[_position];
115+
}
116+
117+
#endregion
118+
119+
#region Constructors
120+
121+
122+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
123+
internal Enumerator(ReadOnlySpan<TColor> pixels)
124+
{
125+
this._pixels = pixels;
126+
127+
_position = -1;
128+
}
129+
130+
#endregion
131+
132+
#region Methods
133+
134+
/// <inheritdoc cref="System.Collections.IEnumerator.MoveNext"/>
135+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
136+
public bool MoveNext() => ++_position < _pixels.Length;
137+
138+
#endregion
139+
}
140+
99141
#region Indexer-Structs
100142

101143
public readonly ref struct ImageRows

0 commit comments

Comments
 (0)