Skip to content

Commit b721746

Browse files
authored
Merge branch 'main' into releaseImageSharp2.1.3
2 parents 0bef844 + 9144afd commit b721746

File tree

10 files changed

+87
-40
lines changed

10 files changed

+87
-40
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ updates:
2929
interval: "daily"
3030
ignore:
3131
- dependency-name: "nunit"
32+
- dependency-name: "coverlet.collector"
3233
- dependency-name: "SonarAnalyzer.CSharp"
3334
- dependency-name: "AngleSharp"
3435
- dependency-name: "Microsoft.NET.Test.Sdk"

.github/workflows/cla.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@ jobs:
1111
steps:
1212
- name: "CLA Assistant"
1313
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target'
14-
# Beta Release
15-
uses: cla-assistant/[email protected]
14+
uses: cla-assistant/[email protected]
1615
env:
1716
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1817
# the below token should have repo scope and must be manually added by you in the repository's secret
1918
PERSONAL_ACCESS_TOKEN : ${{ secrets.PERSONAL_ACCESS_TOKEN }}
2019
with:
2120
path-to-signatures: 'signatures/version1/cla.json'
22-
path-to-document: 'https://github.com/Codeuctivity/ImageSharp.Compare/cla.md' # e.g. a CLA or a DCO document
21+
path-to-document: 'https://github.com/Codeuctivity/ImageSharp.Compare/blob/main/cla.md' # e.g. a CLA or a DCO document
2322
# branch should not be protected
24-
branch: 'main'
25-
allowlist: dependabot[bot]
23+
branch: 'cla'
24+
allowlist: dependabot[bot],stesee
2625

2726
#below are the optional inputs - If the optional inputs are not given, then default values will be taken
2827
#remote-organization-name: enter the remote organization name where the signatures should be stored (Default is storing the signatures in the same repository)

.github/workflows/dotnet.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: .NET build and test
22
env:
3-
CURRENT_VERSION: 2.0.${{ github.run_number }}
3+
CURRENT_VERSION: 3.0.${{ github.run_number }}
44
LAST_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
55

66
on:
@@ -16,7 +16,7 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v3
1818
- name: Setup .NET
19-
uses: actions/setup-dotnet@v2
19+
uses: actions/setup-dotnet@v3
2020
with:
2121
dotnet-version: |
2222
6.0.x
@@ -34,7 +34,7 @@ jobs:
3434
steps:
3535
- uses: actions/checkout@v3
3636
- name: Setup .NET
37-
uses: actions/setup-dotnet@v2
37+
uses: actions/setup-dotnet@v3
3838
with:
3939
dotnet-version: |
4040
6.0.x
@@ -65,7 +65,7 @@ jobs:
6565
steps:
6666
- uses: actions/checkout@v3
6767
- name: Setup .NET
68-
uses: actions/setup-dotnet@v2
68+
uses: actions/setup-dotnet@v3
6969
with:
7070
dotnet-version: |
7171
6.0.x

.github/workflows/stale.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
pull-requests: write
1919

2020
steps:
21-
- uses: actions/stale@v5
21+
- uses: actions/stale@v7
2222
with:
2323
repo-token: ${{ secrets.GITHUB_TOKEN }}
2424
stale-issue-message: 'Stale issue message'

ImageSharpCompare.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A1B6F6C3-ECBE-471C-AE18-199DEF5982C3}"
1111
ProjectSection(SolutionItems) = preProject
1212
.editorconfig = .editorconfig
13+
.github\workflows\cla.yml = .github\workflows\cla.yml
14+
.github\dependabot.yml = .github\dependabot.yml
1315
.github\workflows\dotnet.yml = .github\workflows\dotnet.yml
1416
README.md = README.md
17+
.github\workflows\stale.yml = .github\workflows\stale.yml
1518
EndProjectSection
1619
EndProject
1720
Global

ImageSharpCompare/ImageSharpCompare.csproj

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
3+
<TargetFramework>net6.0</TargetFramework>
44
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
66
<RepositoryUrl>https://github.com/Codeuctivity/ImageSharp.Compare</RepositoryUrl>
@@ -34,10 +34,7 @@
3434
<RootNamespace>Codeuctivity.ImageSharpCompare</RootNamespace>
3535
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
3636
</PropertyGroup>
37-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'">
38-
<Optimize>True</Optimize>
39-
</PropertyGroup>
40-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0|AnyCPU'">
37+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
4138
<Optimize>True</Optimize>
4239
</PropertyGroup>
4340

@@ -46,9 +43,9 @@
4643
</ItemGroup>
4744

4845
<ItemGroup>
49-
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
46+
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.0" />
5047
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
51-
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.40.0.48530">
48+
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.49.0.57237">
5249
<PrivateAssets>all</PrivateAssets>
5350
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
5451
</PackageReference>

ImageSharpCompareTestNunit/ImageSharpCompareTest.cs

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,8 @@ public void ShouldVerifyThatImageSharpImagesAreEqual(string pathActual, string p
114114
using var expected = Image.Load(absolutePathExpected);
115115

116116
Assert.That(ImageSharpCompare.ImagesAreEqual(actual, expected), Is.True);
117-
118-
var isActualDiposed = (bool?)GetInstanceField(actual, "isDisposed");
119-
var isExpectedDiposed = (bool?)GetInstanceField(expected, "isDisposed");
120-
Assert.That(isActualDiposed, Is.False);
121-
Assert.That(isExpectedDiposed, Is.False);
122-
}
123-
124-
private static object? GetInstanceField<T>(T instance, string fieldName)
125-
{
126-
var bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
127-
var field = typeof(T).GetField(fieldName, bindFlags);
128-
if (field == null)
129-
{
130-
throw new ArgumentNullException(fieldName);
131-
}
132-
133-
return field.GetValue(instance);
117+
AssertDisposeBehavior(actual);
118+
AssertDisposeBehavior(expected);
134119
}
135120

136121
[Test]
@@ -228,6 +213,59 @@ public void Diffmask(string pathPic1, string pathPic2, int expectedMeanError, in
228213
Assert.That(maskedDiff.PixelErrorPercentage, Is.EqualTo(expectedPixelErrorPercentage), "PixelErrorPercentage");
229214
}
230215

216+
[TestCase(png0Rgba32, png1Rgba32, 0, 0, 0, 0)]
217+
[TestCase(jpg0Rgb24, jpg1Rgb24, 0, 0, 0, 0)]
218+
public void ShoulCalcDiffmaskImageSharp(string pathPic1, string pathPic2, int expectedMeanError, int expectedAbsoluteError, int expectedPixelErrorCount, double expectedPixelErrorPercentage)
219+
{
220+
var absolutePathPic1 = Path.Combine(AppContext.BaseDirectory, pathPic1);
221+
var absolutePathPic2 = Path.Combine(AppContext.BaseDirectory, pathPic2);
222+
var differenceMaskPicPath = Path.GetTempFileName() + "differenceMask.png";
223+
224+
using var absolutePic1 = Image.Load(absolutePathPic1);
225+
using var absolutePic2 = Image.Load(absolutePathPic2);
226+
227+
using (var fileStreamDifferenceMask = File.Create(differenceMaskPicPath))
228+
using (var maskImage = ImageSharpCompare.CalcDiffMaskImage(absolutePic1, absolutePic2))
229+
{
230+
ImageExtensions.SaveAsPng(maskImage, fileStreamDifferenceMask);
231+
}
232+
233+
using var differenceMaskPic = Image.Load(differenceMaskPicPath);
234+
var maskedDiff = ImageSharpCompare.CalcDiff(absolutePic1, absolutePic2, differenceMaskPic);
235+
File.Delete(differenceMaskPicPath);
236+
237+
Assert.That(maskedDiff.AbsoluteError, Is.EqualTo(expectedAbsoluteError), "AbsoluteError");
238+
Assert.That(maskedDiff.MeanError, Is.EqualTo(expectedMeanError), "MeanError");
239+
Assert.That(maskedDiff.PixelErrorCount, Is.EqualTo(expectedPixelErrorCount), "PixelErrorCount");
240+
Assert.That(maskedDiff.PixelErrorPercentage, Is.EqualTo(expectedPixelErrorPercentage), "PixelErrorPercentage");
241+
242+
AssertDisposeBehavior(absolutePic1);
243+
AssertDisposeBehavior(absolutePic2);
244+
AssertDisposeBehavior(differenceMaskPic);
245+
}
246+
247+
private void AssertDisposeBehavior(Image image)
248+
{
249+
const string imageSharpPrivateFieldNameIsDisposed = "isDisposed";
250+
var isDisposed = (bool?)GetInstanceField(image, imageSharpPrivateFieldNameIsDisposed);
251+
Assert.That(isDisposed, Is.False);
252+
image.Dispose();
253+
isDisposed = (bool?)GetInstanceField(image, imageSharpPrivateFieldNameIsDisposed);
254+
Assert.That(isDisposed, Is.True);
255+
}
256+
257+
private static object? GetInstanceField<T>(T instance, string fieldName)
258+
{
259+
var bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
260+
var field = typeof(T).GetField(fieldName, bindFlags);
261+
if (field == null)
262+
{
263+
throw new ArgumentNullException(fieldName);
264+
}
265+
266+
return field.GetValue(instance);
267+
}
268+
231269
[TestCase(png0Rgba32, png1Rgba32, 0, 0, 0, 0)]
232270
public void DiffmaskSteams(string pathPic1, string pathPic2, int expectedMeanError, int expectedAbsoluteError, int expectedPixelErrorCount, double expectedPixelErrorPercentage)
233271
{

ImageSharpCompareTestNunit/ImageSharpCompareTestNunit.csproj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT' ">net472;net6.0</TargetFrameworks>
5-
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT' ">net6.0</TargetFrameworks>
4+
<TargetFramework>net6.0</TargetFramework>
65
<IsPackable>false</IsPackable>
76
<LangVersion>8.0</LangVersion>
87
<Nullable>enable</Nullable>
98
<EnableNETAnalyzers>true</EnableNETAnalyzers>
109
</PropertyGroup>
1110

1211
<ItemGroup>
13-
<PackageReference Include="coverlet.collector" Version="3.1.2">
12+
<PackageReference Include="coverlet.collector" Version="3.2.0">
1413
<PrivateAssets>all</PrivateAssets>
1514
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1615
</PackageReference>
1716
<PackageReference Include="nunit" Version="3.13.3" />
18-
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.40.0.48530">
17+
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.49.0.57237">
1918
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2019
<PrivateAssets>all</PrivateAssets>
2120
</PackageReference>
22-
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1">
21+
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1">
2322
<PrivateAssets>all</PrivateAssets>
2423
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2524
</PackageReference>
26-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
25+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
2726
</ItemGroup>
2827

2928
<ItemGroup>

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Inspired by the image compare feature "Visual verification API" of [TestApi](htt
88

99
ImageSharpCompare focus on os agnostic support and therefore depends on [SixLabors.ImageSharp](https://github.com/SixLabors/ImageSharp).
1010

11+
**NOTE**: for now the comparer will only work with **RGB** components and totally ignores **A**lpha-channell.
12+
1113
## Example simple show cases
1214

1315
### Compares each RGB value of each pixel to determine the equality

signatures/version1/cla.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
"created_at": "2022-06-22T21:12:05Z",
1616
"repoId": 216339629,
1717
"pullRequestNo": 36
18+
},
19+
{
20+
"name": "snechaev",
21+
"id": 6499856,
22+
"comment_id": 1190056766,
23+
"created_at": "2022-07-20T09:39:43Z",
24+
"repoId": 216339629,
25+
"pullRequestNo": 39
1826
}
1927
]
2028
}

0 commit comments

Comments
 (0)