Skip to content

Commit

Permalink
Bump SixLabors.ImageSharp from 2.1.3 to 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stesee authored Mar 4, 2023
2 parents a052089 + 54fed93 commit 94a5f26
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 45 deletions.
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ updates:
interval: "daily"
ignore:
- dependency-name: "nunit"
- dependency-name: "coverlet.collector"
- dependency-name: "SonarAnalyzer.CSharp"
- dependency-name: "AngleSharp"
- dependency-name: "Microsoft.NET.Test.Sdk"
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/cla.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ jobs:
steps:
- name: "CLA Assistant"
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'
# Beta Release
uses: cla-assistant/github-action@v2.1.3-beta
uses: cla-assistant/github-action@v2.3.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# the below token should have repo scope and must be manually added by you in the repository's secret
PERSONAL_ACCESS_TOKEN : ${{ secrets.PERSONAL_ACCESS_TOKEN }}
with:
path-to-signatures: 'signatures/version1/cla.json'
path-to-document: 'https://github.com/Codeuctivity/ImageSharp.Compare/cla.md' # e.g. a CLA or a DCO document
path-to-document: 'https://github.com/Codeuctivity/ImageSharp.Compare/blob/main/cla.md' # e.g. a CLA or a DCO document
# branch should not be protected
branch: 'main'
allowlist: dependabot[bot]
branch: 'cla'
allowlist: dependabot[bot],stesee

#below are the optional inputs - If the optional inputs are not given, then default values will be taken
#remote-organization-name: enter the remote organization name where the signatures should be stored (Default is storing the signatures in the same repository)
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: .NET build and test
env:
CURRENT_VERSION: 2.0.${{ github.run_number }}
CURRENT_VERSION: 3.0.${{ github.run_number }}
LAST_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}

on:
Expand All @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
Expand All @@ -34,7 +34,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
pull-requests: write

steps:
- uses: actions/stale@v5
- uses: actions/stale@v7
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'Stale issue message'
Expand Down
3 changes: 3 additions & 0 deletions ImageSharpCompare.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A1B6F6C3-ECBE-471C-AE18-199DEF5982C3}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.github\workflows\cla.yml = .github\workflows\cla.yml
.github\dependabot.yml = .github\dependabot.yml
.github\workflows\dotnet.yml = .github\workflows\dotnet.yml
README.md = README.md
.github\workflows\stale.yml = .github\workflows\stale.yml
EndProjectSection
EndProject
Global
Expand Down
11 changes: 4 additions & 7 deletions ImageSharpCompare/ImageSharpCompare.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<RepositoryUrl>https://github.com/Codeuctivity/ImageSharp.Compare</RepositoryUrl>
Expand Down Expand Up @@ -34,10 +34,7 @@
<RootNamespace>Codeuctivity.ImageSharpCompare</RootNamespace>
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'">
<Optimize>True</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0|AnyCPU'">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<Optimize>True</Optimize>
</PropertyGroup>

Expand All @@ -46,9 +43,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.40.0.48530">
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.49.0.57237">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
80 changes: 59 additions & 21 deletions ImageSharpCompareTestNunit/ImageSharpCompareTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public void ShouldVerifyThatImagesSizeAreEqual(string pathActual, string pathExp
var absolutePathActual = Path.Combine(AppContext.BaseDirectory, pathActual);
var absolutePathExpected = Path.Combine(AppContext.BaseDirectory, pathExpected);

using var actual = SixLabors.ImageSharp.Image.Load(absolutePathActual);
using var expected = SixLabors.ImageSharp.Image.Load(absolutePathExpected);
using var actual = Image.Load(absolutePathActual);
using var expected = Image.Load(absolutePathExpected);

Assert.That(ImageSharpCompare.ImagesHaveEqualSize(absolutePathActual, absolutePathExpected), Is.EqualTo(expectedOutcome));
}
Expand Down Expand Up @@ -101,23 +101,8 @@ public void ShouldVerifyThatImageSharpImagesAreEqual(string pathActual, string p
using var expected = Image.Load(absolutePathExpected);

Assert.That(ImageSharpCompare.ImagesAreEqual(actual, expected), Is.True);

var isActualDiposed = (bool?)GetInstanceField(actual, "isDisposed");
var isExpectedDiposed = (bool?)GetInstanceField(expected, "isDisposed");
Assert.That(isActualDiposed, Is.False);
Assert.That(isExpectedDiposed, Is.False);
}

private static object? GetInstanceField<T>(T instance, string fieldName)
{
var bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
var field = typeof(T).GetField(fieldName, bindFlags);
if (field == null)
{
throw new ArgumentNullException(fieldName);
}

return field.GetValue(instance);
AssertDisposeBehavior(actual);
AssertDisposeBehavior(expected);
}

[Test]
Expand Down Expand Up @@ -164,7 +149,7 @@ public void ShouldVerifyThatImageStreamsAreSemiEqual(string pathPic1, string pat
}

[TestCase(png0Rgba32, png1Rgba32, 0, 0, 0, 0)]
public void Diffmask(string pathPic1, string pathPic2, int expectedMeanError, int expectedAbsoluteError, int expectedPixelErrorCount, double expectedPixelErrorPercentage)
public void ShoulCalcDiffmask(string pathPic1, string pathPic2, int expectedMeanError, int expectedAbsoluteError, int expectedPixelErrorCount, double expectedPixelErrorPercentage)
{
var absolutePathPic1 = Path.Combine(AppContext.BaseDirectory, pathPic1);
var absolutePathPic2 = Path.Combine(AppContext.BaseDirectory, pathPic2);
Expand All @@ -173,7 +158,7 @@ public void Diffmask(string pathPic1, string pathPic2, int expectedMeanError, in
using (var fileStreamDifferenceMask = File.Create(differenceMask))
using (var maskImage = ImageSharpCompare.CalcDiffMaskImage(absolutePathPic1, absolutePathPic2))
{
SixLabors.ImageSharp.ImageExtensions.SaveAsPng(maskImage, fileStreamDifferenceMask);
ImageExtensions.SaveAsPng(maskImage, fileStreamDifferenceMask);
}

var maskedDiff = ImageSharpCompare.CalcDiff(absolutePathPic1, absolutePathPic2, differenceMask);
Expand All @@ -185,6 +170,59 @@ public void Diffmask(string pathPic1, string pathPic2, int expectedMeanError, in
Assert.That(maskedDiff.PixelErrorPercentage, Is.EqualTo(expectedPixelErrorPercentage), "PixelErrorPercentage");
}

[TestCase(png0Rgba32, png1Rgba32, 0, 0, 0, 0)]
[TestCase(jpg0Rgb24, jpg1Rgb24, 0, 0, 0, 0)]
public void ShoulCalcDiffmaskImageSharp(string pathPic1, string pathPic2, int expectedMeanError, int expectedAbsoluteError, int expectedPixelErrorCount, double expectedPixelErrorPercentage)
{
var absolutePathPic1 = Path.Combine(AppContext.BaseDirectory, pathPic1);
var absolutePathPic2 = Path.Combine(AppContext.BaseDirectory, pathPic2);
var differenceMaskPicPath = Path.GetTempFileName() + "differenceMask.png";

using var absolutePic1 = Image.Load(absolutePathPic1);
using var absolutePic2 = Image.Load(absolutePathPic2);

using (var fileStreamDifferenceMask = File.Create(differenceMaskPicPath))
using (var maskImage = ImageSharpCompare.CalcDiffMaskImage(absolutePic1, absolutePic2))
{
ImageExtensions.SaveAsPng(maskImage, fileStreamDifferenceMask);
}

using var differenceMaskPic = Image.Load(differenceMaskPicPath);
var maskedDiff = ImageSharpCompare.CalcDiff(absolutePic1, absolutePic2, differenceMaskPic);
File.Delete(differenceMaskPicPath);

Assert.That(maskedDiff.AbsoluteError, Is.EqualTo(expectedAbsoluteError), "AbsoluteError");
Assert.That(maskedDiff.MeanError, Is.EqualTo(expectedMeanError), "MeanError");
Assert.That(maskedDiff.PixelErrorCount, Is.EqualTo(expectedPixelErrorCount), "PixelErrorCount");
Assert.That(maskedDiff.PixelErrorPercentage, Is.EqualTo(expectedPixelErrorPercentage), "PixelErrorPercentage");

AssertDisposeBehavior(absolutePic1);
AssertDisposeBehavior(absolutePic2);
AssertDisposeBehavior(differenceMaskPic);
}

private void AssertDisposeBehavior(Image image)
{
const string imageSharpPrivateFieldNameIsDisposed = "isDisposed";
var isDisposed = (bool?)GetInstanceField(image, imageSharpPrivateFieldNameIsDisposed);
Assert.That(isDisposed, Is.False);
image.Dispose();
isDisposed = (bool?)GetInstanceField(image, imageSharpPrivateFieldNameIsDisposed);
Assert.That(isDisposed, Is.True);
}

private static object? GetInstanceField<T>(T instance, string fieldName)
{
var bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
var field = typeof(T).GetField(fieldName, bindFlags);
if (field == null)
{
throw new ArgumentNullException(fieldName);
}

return field.GetValue(instance);
}

[TestCase(png0Rgba32, png1Rgba32, 0, 0, 0, 0)]
public void DiffmaskSteams(string pathPic1, string pathPic2, int expectedMeanError, int expectedAbsoluteError, int expectedPixelErrorCount, double expectedPixelErrorPercentage)
{
Expand Down
11 changes: 5 additions & 6 deletions ImageSharpCompareTestNunit/ImageSharpCompareTestNunit.csproj
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT' ">net472;net6.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT' ">net6.0</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.40.0.48530">
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.49.0.57237">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1">
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

Compares images

[![.github/workflows/dotnet.yml](https://github.com/Codeuctivity/ImageSharp.Compare/actions/workflows/dotnet.yml/badge.svg)](https://github.com/Codeuctivity/ImageSharp.Compare/actions/workflows/dotnet.yml) [![Nuget](https://img.shields.io/nuget/v/Codeuctivity.ImageSharpCompare.svg)](https://www.nuget.org/packages/Codeuctivity.ImageSharpCompare/) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/2fb2807a16f84021b088769e56e1515a)](https://www.codacy.com/gh/Codeuctivity/ImageSharp.Compare/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Codeuctivity/ImageSharp.Compare&utm_campaign=Badge_Grade) [![Donate](https://img.shields.io/static/v1?label=Paypal&message=Donate&color=informational)](https://www.paypal.com/donate?hosted_button_id=7M7UFMMRTS7UE)
[![.github/workflows/dotnet.yml](https://github.com/Codeuctivity/ImageSharp.Compare/actions/workflows/dotnet.yml/badge.svg)](https://github.com/Codeuctivity/ImageSharp.Compare/actions/workflows/dotnet.yml) [![Nuget](https://img.shields.io/nuget/v/Codeuctivity.ImageSharpCompare.svg)](https://www.nuget.org/packages/Codeuctivity.ImageSharpCompare/) [![Donate](https://img.shields.io/static/v1?label=Paypal&message=Donate&color=informational)](https://www.paypal.com/donate?hosted_button_id=7M7UFMMRTS7UE)

Inspired by the image compare feature "Visual verification API" of [TestApi](https://blogs.msdn.microsoft.com/ivo_manolov/2009/04/20/introduction-to-testapi-part-3-visual-verification-apis/) this code supports comparing images by using a tolerance mask image. That tolerance mask image is a valid image by itself and can be manipulated.

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

**NOTE**: for now the comparer will only work with **RGB** components and totally ignores **A**lpha-channell.

## Example simple show cases

```csharp
Expand Down
8 changes: 8 additions & 0 deletions signatures/version1/cla.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
"created_at": "2022-06-22T21:12:05Z",
"repoId": 216339629,
"pullRequestNo": 36
},
{
"name": "snechaev",
"id": 6499856,
"comment_id": 1190056766,
"created_at": "2022-07-20T09:39:43Z",
"repoId": 216339629,
"pullRequestNo": 39
}
]
}

0 comments on commit 94a5f26

Please sign in to comment.