Skip to content

Commit

Permalink
Bump SixLabors.ImageSharp from 1.0.4 to 2.0.0 (#78)
Browse files Browse the repository at this point in the history
* Bump SixLabors.ImageSharp from 1.0.4 to 2.0.0

Bumps [SixLabors.ImageSharp](https://github.com/SixLabors/ImageSharp) from 1.0.4 to 2.0.0.
- [Release notes](https://github.com/SixLabors/ImageSharp/releases)
- [Commits](SixLabors/ImageSharp@v1.0.4...v2.0.0)

---
updated-dependencies:
- dependency-name: SixLabors.ImageSharp
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* Fixed breaking changes, Removed support for netstandard1.3

* Cleanup

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Coen van den Munckhof <[email protected]>
  • Loading branch information
dependabot[bot] and coenm authored Feb 11, 2022
1 parent 4079cad commit 40a5099
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 72 deletions.
8 changes: 1 addition & 7 deletions .azuredevops/Pipelines/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ stages:
- script: git submodule update --init --recursive
displayName: Update git submodules

- task: UseDotNet@2
displayName: "Use dotnet sdk 2.1.x"
inputs:
version: 2.1.x
includePreviewVersions: false

- task: UseDotNet@2
displayName: "Use dotnet sdk 3.1.x"
inputs:
Expand All @@ -67,7 +61,7 @@ stages:
displayName: "Use dotnet sdk 6.0.x"
inputs:
version: 6.0.x
includePreviewVersions: true
includePreviewVersions: false

- script: dotnet --info
displayName: Show dotnet SDK info
Expand Down
8 changes: 1 addition & 7 deletions .azuredevops/Pipelines/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ stages:
value: 39ce9363-a308-4580-8610-ee11f4953539/01001223-8651-4b73-a7ca-ba27c3e10a3c

steps:
- task: UseDotNet@2
displayName: "Use dotnet sdk 2.1.x"
inputs:
version: 2.1.x
includePreviewVersions: false

- task: UseDotNet@2
displayName: "Use dotnet sdk 3.1.x"
inputs:
Expand All @@ -52,7 +46,7 @@ stages:
displayName: "Use dotnet sdk 6.0.x"
inputs:
version: 6.0.x
includePreviewVersions: true
includePreviewVersions: false

- script: dotnet --info
displayName: Show dotnet SDK info
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/on-push-do-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ jobs:
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.1.x

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
Expand All @@ -39,7 +34,7 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
include-prerelease: true
include-prerelease: false

- name: Remove demo project from solution
run: dotnet sln ImageHash.sln remove demo/Demo.csproj
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

<!-- Set the CheckEolTargetFramework property to false. This will remove the following warning:
The target framework 'netcoreapp2.1' is out of support and will not receive security updates in the future. -->
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<!-- <CheckEolTargetFramework>false</CheckEolTargetFramework> -->
</PropertyGroup>
</Project>
1 change: 0 additions & 1 deletion ImageHash.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
GitVersion.yml = GitVersion.yml
build\Packages.targets = build\Packages.targets
README.md = README.md
version.json = version.json
Expand Down
4 changes: 2 additions & 2 deletions build/Packages.targets
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<ItemGroup>

<!--Dependencies production code (and maybe also in test code)-->
<PackageReference Update="SixLabors.ImageSharp" Version="1.0.4" />
<PackageReference Update="SixLabors.ImageSharp" Version="2.0.0" />

<!-- Packages and tools for releasing (sourcelink)-->
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />

Expand Down
57 changes: 30 additions & 27 deletions src/ImageHash/HashAlgorithms/AverageHash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,43 @@ public ulong Hash(Image<Rgba32> image)
.Grayscale(GrayscaleMode.Bt601)
.AutoOrient());

uint averageValue = 0;
var hash = 0UL;

for (var y = 0; y < HEIGHT; y++)
{
Span<Rgba32> row = image.GetPixelRowSpan(y);
for (var x = 0; x < WIDTH; x++)
image.ProcessPixelRows((imageAccessor) =>
{
// We know 4 bytes (RGBA) are used to describe one pixel
// Also, it is already grayscaled, so R=G=B. Therefore, we can take one of these
// values for average calculation. We take the R (the first of each 4 bytes).
averageValue += row[x].R;
}
}
uint averageValue = 0;
for (var y = 0; y < HEIGHT; y++)
{
Span<Rgba32> row = imageAccessor.GetRowSpan(y);
for (var x = 0; x < WIDTH; x++)
{
// We know 4 bytes (RGBA) are used to describe one pixel
// Also, it is already grayscaled, so R=G=B. Therefore, we can take one of these
// values for average calculation. We take the R (the first of each 4 bytes).
averageValue += row[x].R;
}
}

averageValue /= NR_PIXELS;
averageValue /= NR_PIXELS;

// Compute the hash: each bit is a pixel
// 1 = higher than average, 0 = lower than average
var hash = 0UL;
var mask = MOST_SIGNIFICANT_BIT_MASK;
// Compute the hash: each bit is a pixel
// 1 = higher than average, 0 = lower than average
var mask = MOST_SIGNIFICANT_BIT_MASK;

for (var y = 0; y < HEIGHT; y++)
{
Span<Rgba32> row = image.GetPixelRowSpan(y);
for (var x = 0; x < WIDTH; x++)
{
if (row[x].R >= averageValue)
for (var y = 0; y < HEIGHT; y++)
{
hash |= mask;
}
Span<Rgba32> row = imageAccessor.GetRowSpan(y);
for (var x = 0; x < WIDTH; x++)
{
if (row[x].R >= averageValue)
{
hash |= mask;
}

mask >>= 1;
}
}
mask >>= 1;
}
}
});

return hash;
}
Expand Down
34 changes: 19 additions & 15 deletions src/ImageHash/HashAlgorithms/DifferenceHash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,30 @@ public ulong Hash(Image<Rgba32> image)
.Resize(WIDTH, HEIGHT)
.Grayscale(GrayscaleMode.Bt601));

var mask = 1UL << ((HEIGHT * (WIDTH - 1)) - 1);
var hash = 0UL;

for (var y = 0; y < HEIGHT; y++)
{
Span<Rgba32> row = image.GetPixelRowSpan(y);
Rgba32 leftPixel = row[0];

for (var index = 1; index < WIDTH; index++)
image.ProcessPixelRows((imageAccessor) =>
{
Rgba32 rightPixel = row[index];
if (leftPixel.R < rightPixel.R)
var mask = 1UL << ((HEIGHT * (WIDTH - 1)) - 1);

for (var y = 0; y < HEIGHT; y++)
{
hash |= mask;
}
Span<Rgba32> row = imageAccessor.GetRowSpan(y);
Rgba32 leftPixel = row[0];

leftPixel = rightPixel;
mask >>= 1;
}
}
for (var index = 1; index < WIDTH; index++)
{
Rgba32 rightPixel = row[index];
if (leftPixel.R < rightPixel.R)
{
hash |= mask;
}

leftPixel = rightPixel;
mask >>= 1;
}
}
});

return hash;
}
Expand Down
8 changes: 4 additions & 4 deletions src/ImageHash/HashAlgorithms/PerceptualHash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static double CalculateMedian64Values(IReadOnlyCollection<double> values

private static List<Vector<double>>[] GenerateDctCoeffsSimd()
{
List<Vector<double>>[] results = new List<Vector<double>>[SIZE];
var results = new List<Vector<double>>[SIZE];
for (var coef = 0; coef < SIZE; coef++)
{
var singleResultRaw = new double[SIZE];
Expand All @@ -110,7 +110,7 @@ private static List<Vector<double>>[] GenerateDctCoeffsSimd()
var singleResultList = new List<Vector<double>>();
var stride = Vector<double>.Count;
Debug.Assert(SIZE % stride == 0, "Size must be a multiple of SIMD stride");
for (int i = 0; i < SIZE; i += stride)
for (var i = 0; i < SIZE; i += stride)
{
var v = new Vector<double>(singleResultRaw, i);
singleResultList.Add(v);
Expand All @@ -136,14 +136,14 @@ private static void Dct1D_SIMD(double[] valuesRaw, double[,] coefficients, int c

var valuesList = new List<Vector<double>>();
var stride = Vector<double>.Count;
for (int i = 0; i < valuesRaw.Length; i += stride)
for (var i = 0; i < valuesRaw.Length; i += stride)
{
valuesList.Add(new Vector<double>(valuesRaw, i));
}

for (var coef = 0; coef < limit; coef++)
{
for (int i = 0; i < valuesList.Count; i++)
for (var i = 0; i < valuesList.Count; i++)
{
coefficients[ci, coef] += Vector.Dot(valuesList[i], _dctCoeffsSimd[coef][i]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ImageHash/ImageHash.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard1.3;netstandard2.0;netcoreapp2.1;netcoreapp3.1;net5;net6</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netcoreapp2.1;netcoreapp3.1;net5;net6</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Unix'">$(TargetFrameworks);net461;net472</TargetFrameworks>
<Description>Perceptual image hashing in netstandard using the ImageSharp library. Includes three hashing algorithms (AverageHash, DifferenceHash, and PerceptualHash).</Description>
<RootNamespace>CoenM.ImageHash</RootNamespace>
Expand Down
2 changes: 1 addition & 1 deletion tests/ImageHash.Test/ImageHash.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5;net6</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5;net6</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Unix'">$(TargetFrameworks);net461;net472</TargetFrameworks>
<IsPackable>false</IsPackable>
<AssemblyName>CoenM.ImageSharp.ImageHash.Test</AssemblyName>
Expand Down

0 comments on commit 40a5099

Please sign in to comment.