Skip to content

Commit ec57728

Browse files
committed
Added Tests for Images; Small improvements
1 parent adacf41 commit ec57728

File tree

13 files changed

+559
-2
lines changed

13 files changed

+559
-2
lines changed

ScreenCapture.NET.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScreenCapture.NET", "Screen
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScreenCapture.NET.DX11", "ScreenCapture.NET.DX11\ScreenCapture.NET.DX11.csproj", "{58A09AD8-D66F-492E-8BC7-62BDB85E57EC}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{CF7A1475-3A44-4870-A80F-5988DA25418B}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScreenCapture.NET.Tests", "Tests\ScreenCapture.NET.Tests\ScreenCapture.NET.Tests.csproj", "{AA1829BB-EFA7-4BB8-8041-76374659A42B}"
13+
EndProject
1014
Global
1115
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1216
Debug|Any CPU = Debug|Any CPU
@@ -21,10 +25,17 @@ Global
2125
{58A09AD8-D66F-492E-8BC7-62BDB85E57EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
2226
{58A09AD8-D66F-492E-8BC7-62BDB85E57EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
2327
{58A09AD8-D66F-492E-8BC7-62BDB85E57EC}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{AA1829BB-EFA7-4BB8-8041-76374659A42B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{AA1829BB-EFA7-4BB8-8041-76374659A42B}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{AA1829BB-EFA7-4BB8-8041-76374659A42B}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{AA1829BB-EFA7-4BB8-8041-76374659A42B}.Release|Any CPU.Build.0 = Release|Any CPU
2432
EndGlobalSection
2533
GlobalSection(SolutionProperties) = preSolution
2634
HideSolutionNode = FALSE
2735
EndGlobalSection
36+
GlobalSection(NestedProjects) = preSolution
37+
{AA1829BB-EFA7-4BB8-8041-76374659A42B} = {CF7A1475-3A44-4870-A80F-5988DA25418B}
38+
EndGlobalSection
2839
GlobalSection(ExtensibilityGlobals) = postSolution
2940
SolutionGuid = {B5111031-6E65-4331-9E6E-A07165289860}
3041
EndGlobalSection

ScreenCapture.NET.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BGR/@EntryIndexedValue">BGR</s:String>
23
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BGRA/@EntryIndexedValue">BGRA</s:String>
34
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DPI/@EntryIndexedValue">DPI</s:String>
45
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DX/@EntryIndexedValue">DX</s:String></wpf:ResourceDictionary>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// ReSharper disable ConvertToAutoProperty
2+
3+
using System.Diagnostics;
4+
using System.Runtime.InteropServices;
5+
6+
namespace ScreenCapture.NET;
7+
8+
[DebuggerDisplay("[A: {A}, R: {R}, G: {G}, B: {B}]")]
9+
[StructLayout(LayoutKind.Sequential)]
10+
public readonly struct ColorARGB : IColor
11+
{
12+
#region Properties & Fields
13+
14+
public static ColorFormat ColorFormat => ColorFormat.ARGB;
15+
16+
private readonly byte _a;
17+
private readonly byte _r;
18+
private readonly byte _g;
19+
private readonly byte _b;
20+
21+
// ReSharper disable ConvertToAutoPropertyWhenPossible
22+
public byte A => _a;
23+
public byte R => _r;
24+
public byte G => _g;
25+
public byte B => _b;
26+
// ReSharper restore ConvertToAutoPropertyWhenPossible
27+
28+
#endregion
29+
30+
#region Constructors
31+
32+
public ColorARGB(byte a, byte r, byte g, byte b)
33+
{
34+
this._a = a;
35+
this._r = r;
36+
this._g = g;
37+
this._b = b;
38+
}
39+
40+
#endregion
41+
42+
#region Methods
43+
44+
public override string ToString() => $"[A: {_a}, R: {_r}, G: {_g}, B: {_b}]";
45+
46+
#endregion
47+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// ReSharper disable ConvertToAutoProperty
2+
3+
using System.Diagnostics;
4+
using System.Runtime.InteropServices;
5+
6+
namespace ScreenCapture.NET;
7+
8+
[DebuggerDisplay("[A: {A}, R: {R}, G: {G}, B: {B}]")]
9+
[StructLayout(LayoutKind.Sequential)]
10+
public readonly struct ColorBGR : IColor
11+
{
12+
#region Properties & Fields
13+
14+
public static ColorFormat ColorFormat => ColorFormat.BGR;
15+
16+
private readonly byte _b;
17+
private readonly byte _g;
18+
private readonly byte _r;
19+
20+
// ReSharper disable ConvertToAutoPropertyWhenPossible
21+
public byte A => byte.MaxValue;
22+
public byte B => _b;
23+
public byte G => _g;
24+
public byte R => _r;
25+
// ReSharper restore ConvertToAutoPropertyWhenPossible
26+
27+
#endregion
28+
29+
#region Constructors
30+
31+
public ColorBGR(byte b, byte g, byte r)
32+
{
33+
this._b = b;
34+
this._g = g;
35+
this._r = r;
36+
}
37+
38+
#endregion
39+
40+
#region Methods
41+
42+
public override string ToString() => $"[A: {A}, R: {_r}, G: {_g}, B: {_b}]";
43+
44+
#endregion
45+
}

ScreenCapture.NET/Model/Colors/ColorFormat.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ public readonly struct ColorFormat
55
#region Instances
66

77
public static readonly ColorFormat BGRA = new(1, 4);
8+
public static readonly ColorFormat ARGB = new(2, 4);
9+
public static readonly ColorFormat RGB = new(3, 3);
10+
public static readonly ColorFormat BGR = new(4, 3);
811

912
#endregion
1013

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// ReSharper disable ConvertToAutoProperty
2+
3+
using System.Diagnostics;
4+
using System.Runtime.InteropServices;
5+
6+
namespace ScreenCapture.NET;
7+
8+
[DebuggerDisplay("[A: {A}, R: {R}, G: {G}, B: {B}]")]
9+
[StructLayout(LayoutKind.Sequential)]
10+
public readonly struct ColorRGB : IColor
11+
{
12+
#region Properties & Fields
13+
14+
public static ColorFormat ColorFormat => ColorFormat.RGB;
15+
16+
private readonly byte _r;
17+
private readonly byte _g;
18+
private readonly byte _b;
19+
20+
// ReSharper disable ConvertToAutoPropertyWhenPossible
21+
public byte A => byte.MaxValue;
22+
public byte R => _r;
23+
public byte G => _g;
24+
public byte B => _b;
25+
// ReSharper restore ConvertToAutoPropertyWhenPossible
26+
27+
#endregion
28+
29+
#region Constructors
30+
31+
public ColorRGB(byte r, byte g, byte b)
32+
{
33+
this._r = r;
34+
this._g = g;
35+
this._b = b;
36+
}
37+
38+
#endregion
39+
40+
#region Methods
41+
42+
public override string ToString() => $"[A: {A}, R: {_r}, G: {_g}, B: {_b}]";
43+
44+
#endregion
45+
}

ScreenCapture.NET/Model/IImage.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,25 @@ public interface IImage : IEnumerable<IColor>
1515

1616
public interface IImageRows : IEnumerable<IImageRow>
1717
{
18+
int Count { get; }
1819
IImageRow this[int column] { get; }
1920
}
2021

2122
public interface IImageColumns : IEnumerable<IImageColumn>
2223
{
24+
int Count { get; }
2325
IImageColumn this[int column] { get; }
2426
}
2527

2628
public interface IImageRow : IEnumerable<IColor>
2729
{
30+
int Length { get; }
2831
IColor this[int x] { get; }
2932
}
3033

3134
public interface IImageColumn : IEnumerable<IColor>
3235
{
36+
int Length { get; }
3337
IColor this[int y] { get; }
3438
}
3539
}

ScreenCapture.NET/Model/Image.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public sealed class Image<TColor> : IImage
4040
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4141
get
4242
{
43-
if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0) || ((x + width) >= Width) || ((y + height) >= Height)) throw new IndexOutOfRangeException();
43+
if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0) || ((x + width) > Width) || ((y + height) > Height)) throw new IndexOutOfRangeException();
4444

4545
return new Image<TColor>(_buffer, _x + x, _y + y, width, height, _stride);
4646
}
@@ -100,6 +100,8 @@ private sealed class ImageRows : IImage.IImageRows
100100
private readonly int _height;
101101
private readonly int _stride;
102102

103+
public int Count => _height;
104+
103105
#endregion
104106

105107
#region Indexer
@@ -151,6 +153,8 @@ private sealed class ImageRow : IImage.IImageRow
151153
private readonly int _start;
152154
private readonly int _length;
153155

156+
public int Length => _length;
157+
154158
#endregion
155159

156160
#region Indexer
@@ -203,6 +207,8 @@ private sealed class ImageColumns : IImage.IImageColumns
203207
private readonly int _height;
204208
private readonly int _stride;
205209

210+
public int Count => _width;
211+
206212
#endregion
207213

208214
#region Indexer
@@ -255,6 +261,8 @@ private sealed class ImageColumn : IImage.IImageColumn
255261
private readonly int _length;
256262
private readonly int _step;
257263

264+
public int Length => _length;
265+
258266
#endregion
259267

260268
#region Indexer

ScreenCapture.NET/Model/RefImage.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public readonly ref struct RefImage<TColor>
3838
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3939
get
4040
{
41-
if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0) || ((x + width) >= Width) || ((y + height) >= Height)) throw new IndexOutOfRangeException();
41+
if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0) || ((x + width) > Width) || ((y + height) > Height)) throw new IndexOutOfRangeException();
4242

4343
return new RefImage<TColor>(_pixels, _x + x, _y + y, width, height, _stride);
4444
}
@@ -151,6 +151,8 @@ public readonly ref struct ImageRows
151151
private readonly int _height;
152152
private readonly int _stride;
153153

154+
public int Count => _height;
155+
154156
#endregion
155157

156158
#region Indexer
@@ -243,6 +245,8 @@ public readonly ref struct ImageColumns
243245
private readonly int _height;
244246
private readonly int _stride;
245247

248+
public int Count => _width;
249+
246250
#endregion
247251

248252
#region Indexer

0 commit comments

Comments
 (0)