Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c981cee
Update nuget componentes test project
fernandezja Jul 3, 2020
73b7a8c
Add test coverage with nuget component coverlet.msbuild
fernandezja Jul 3, 2020
a37ba4d
Create a color with custom Hue option (hex, hsl)
fernandezja Nov 29, 2020
8ece822
Update dotnet version in CI yaml to 3.1.404
fernandezja Nov 29, 2020
29d25c1
Update readme with branches CI status
fernandezja Nov 29, 2020
5615e47
Change name CI pipeline in github actions to CI-NETCore
fernandezja Nov 29, 2020
175596d
Benchmark NET6/NET7
fernandezja Dec 10, 2022
673cc8c
Test default .editorConfig
fernandezja Dec 10, 2022
c9be2a5
Update nugets (BenchmarkDotNet, Microsoft.NET.Test.Sdk)
fernandezja May 15, 2023
83df5d1
Added Links.md for resources related to ColorHashSharp
Jun 20, 2025
1b0c7e6
Enhanced ColorHashSharp project to support multiple target frameworks…
Jun 20, 2025
545d722
Update README.md with NuGet downloads badge
Jun 20, 2025
3bbbef0
Add CI workflow for .NET projects using GitHub Actions using a matrix…
Jun 20, 2025
9149b2a
Fix error on Github Action "No usable version of libssl was found" wi…
Jun 20, 2025
e9e9af7
Update CI workflow for .NET on Windows and simplify the strategy matrix.
Jun 20, 2025
a49a24b
Update CI workflow for .NET on Windows and simplify the strategy matrix.
Jun 20, 2025
4a940dc
Update Links.md with new commands (pack a project and to push a packa…
Jun 22, 2025
24170cc
Remove yml file
Jun 22, 2025
322a660
Update .yml file, test framework and .NET version in CI config. Incl…
Jun 22, 2025
dbdd9dc
Update README.md badges for CI visibility
Jun 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
name: .NET Core
name: CI

on:
push:
branches: [ master ]
branches: [ master, develop ]
pull_request:
branches: [ master ]
branches: [ master, develop ]

jobs:
build:

runs-on: ubuntu-latest

build-and-test:
runs-on: windows-latest
strategy:
matrix:
test-framework: ['net9.0']
#test-framework: [ 'net8.0', 'net9.0', 'net48', 'net481' ]
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101
- name: Install dependencies
working-directory: src
run: dotnet restore
- name: Build
working-directory: src
run: dotnet build --configuration Release --no-restore
- name: Test
working-directory: src
run: dotnet test --no-restore --verbosity normal
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version:
9.0.x
- name: Install dependencies
working-directory: src
run: dotnet restore
- name: Build
working-directory: src
run: dotnet build --configuration Release --no-restore
- name: Test
working-directory: src
run: dotnet test --no-restore --verbosity normal --framework ${{ matrix.test-framework }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,4 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/
/src/ColorHashSharp.Tests/coverage.json
20 changes: 20 additions & 0 deletions Benchmark.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# ColorHashSharp Benchmark

### Benchmark NET6 & NET7

BenchmarkDotNet=v0.13.2, OS=Windows 11 (10.0.22000.1281/21H2)
Intel Core i7-8550U CPU 1.80GHz (Kaby Lake R), 1 CPU, 8 logical and 4 physical cores
.NET SDK=7.0.100
[Host] : .NET 6.0.11 (6.0.1122.52304), X64 RyuJIT AVX2 [AttachedDebugger]
.NET 6.0 : .NET 6.0.11 (6.0.1122.52304), X64 RyuJIT AVX2
.NET 7.0 : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2


| Method | Job | Runtime | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio |
|------- |--------- |--------- |---------:|----------:|----------:|---------:|------:|--------:|-------:|----------:|------------:|
| Hsl | .NET 6.0 | .NET 6.0 | 1.289 us | 0.0292 us | 0.0789 us | 1.263 us | 1.00 | 0.00 | 0.5360 | 2.2 KB | 1.00 |
| Rgb | .NET 6.0 | .NET 6.0 | 1.296 us | 0.0256 us | 0.0639 us | 1.280 us | 1.00 | 0.08 | 0.5360 | 2.2 KB | 1.00 |
| Hex | .NET 6.0 | .NET 6.0 | 1.435 us | 0.0284 us | 0.0433 us | 1.432 us | 1.09 | 0.07 | 0.5741 | 2.35 KB | 1.07 |
| Hsl | .NET 7.0 | .NET 7.0 | 1.432 us | 0.0674 us | 0.1911 us | 1.372 us | 1.12 | 0.17 | 0.5360 | 2.2 KB | 1.00 |
| Rgb | .NET 7.0 | .NET 7.0 | 1.497 us | 0.0678 us | 0.1890 us | 1.448 us | 1.15 | 0.15 | 0.5360 | 2.2 KB | 1.00 |
| Hex | .NET 7.0 | .NET 7.0 | 1.358 us | 0.0272 us | 0.0381 us | 1.350 us | 1.03 | 0.07 | 0.5741 | 2.35 KB | 1.07 |
17 changes: 17 additions & 0 deletions Links.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ColorHashSharp resources links

#### Links
- [Packaging Icon within the nupkg](https://github.com/NuGet/Home/wiki/Packaging-Icon-within-the-nupkg)
- [Supporting Multiple Target Frameworks](https://learn.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks)
- [NuGet Package Explorer](https://apps.microsoft.com/detail/9WZDNCRDMDM3?hl=en-us&gl=AR&ocid=pdpshare)
- [NuGet Package Explorer GitHub](https://github.com/NuGetPackageExplorer/NuGetPackageExplorer)

#### Command to push a package to NuGet
```bash
dotnet nuget push file.nupkg -k {YOUR_API_KEY_HERE} -s https://api.nuget.org/v3/index.json
```

#### Command to pack a project
```bash
dotnet pack --configuration Release
```
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# ColorHashSharp
Generate color based on the given string. C# port of [ColorHash Javascript Library](https://github.com/zenozeng/color-hash).

[![NuGet version (ColorHashSharp)](https://img.shields.io/nuget/v/ColorHashSharp.svg?style=flat-square)](https://www.nuget.org/packages/ColorHashSharp/)
![.NET Core](https://github.com/fernandezja/ColorHashSharp/workflows/.NET%20Core/badge.svg?branch=master)
[![Build status](https://fernandezja.visualstudio.com/ColorHashSharp/_apis/build/status/ColorHashSharp-CI)](https://fernandezja.visualstudio.com/ColorHashSharp/_build/latest?definitionId=4)
[![NuGet version (ColorHashSharp)](https://img.shields.io/nuget/v/ColorHashSharp.svg?style=flat-square)](https://www.nuget.org/packages/ColorHashSharp/)   [![NuGet Downloads](https://img.shields.io/nuget/dt/ColorHashSharp.svg)](https://www.nuget.org/packages/Serilog/)

[![CI](https://github.com/fernandezja/ColorHashSharp/actions/workflows/dotnet-core.yml/badge.svg)](https://github.com/fernandezja/ColorHashSharp/actions/workflows/dotnet-core.yml)  [![Build status](https://fernandezja.visualstudio.com/ColorHashSharp/_apis/build/status/ColorHashSharp-CI)](https://fernandezja.visualstudio.com/ColorHashSharp/_build/latest?definitionId=4)

#### Status


|Actions |master |develop |
|--- |--- |--- |
|CI |[![CI](https://github.com/fernandezja/ColorHashSharp/actions/workflows/dotnet-core.yml/badge.svg?branch=master)](https://github.com/fernandezja/ColorHashSharp/actions/workflows/dotnet-core.yml) |[![CI](https://github.com/fernandezja/ColorHashSharp/actions/workflows/dotnet-core.yml/badge.svg?branch=develop)](https://github.com/fernandezja/ColorHashSharp/actions/workflows/dotnet-core.yml) |


#### Basic

Expand Down
Binary file modified assets/icon/ColorHashSharp-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/ColorHashSharp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/ColorHashSharp.Benchmarks/ColorHashSharp.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.15.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ColorHashSharp\ColorHashSharp.csproj" />
</ItemGroup>

</Project>
44 changes: 44 additions & 0 deletions src/ColorHashSharp.Benchmarks/ColorHashSharpBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using Fernandezja.ColorHashSharp;
using Fernandezja.ColorHashSharp.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ColorHashSharp.Benchmarks
{
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net48)]
[SimpleJob(RuntimeMoniker.Net481)]
[SimpleJob(RuntimeMoniker.Net80, baseline: true)]
[SimpleJob(RuntimeMoniker.Net90)]
[SimpleJob(RuntimeMoniker.Net10_0)]
public class ColorHashSharpBenchmarks
{
private const string STRING_TO_HASH = "The Force will be with you always";

private ColorHash _colorHash = new();


[Benchmark(Baseline = true)]
public void Hsl()
{
_ = _colorHash.Hsl(STRING_TO_HASH);
}

[Benchmark]
public void Rgb()
{
_ = _colorHash.Rgb(STRING_TO_HASH);
}

[Benchmark]
public void Hex()
{
_ = _colorHash.Hex(STRING_TO_HASH);
}
}
}
8 changes: 8 additions & 0 deletions src/ColorHashSharp.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using BenchmarkDotNet.Running;
using ColorHashSharp.Benchmarks;

Console.WriteLine("ColorHashSharp benchmarks!");

_ = BenchmarkRunner.Run<ColorHashSharpBenchmarks>();

Console.ReadKey();
13 changes: 8 additions & 5 deletions src/ColorHashSharp.Tests/ColorHashSharp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>

<TargetFramework>net9.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
48 changes: 48 additions & 0 deletions src/ColorHashSharp.Tests/ColorHashTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
Expand Down Expand Up @@ -42,6 +43,53 @@ public void BuildToHsl_ShouldCreateAColorInHSL(
Assert.Equal(lExpected, result.L);
}


[Theory(DisplayName = "BuildToHsl_ShouldCreateAColorInHSLWithCustomHueOption")]
[InlineData("yoda", 90, 90, 0.35, 0.35)]
[InlineData("yoda", 270, 270, 0.35, 0.35)]
public void BuildToHsl_ShouldCreateAColorInHSLWithCustomHueOption(
string phrase, int hue,
int hExpected, double sExpected, double lExpected)
{
var options = new Options();
options.SetHue(hue);

var colorHash = new Fernandezja.ColorHashSharp.ColorHash(options);

var result = colorHash.BuildToHsl(phrase);

Assert.NotNull(result);
Assert.Equal(hExpected, result.H);
Assert.Equal(sExpected, result.S);
Assert.Equal(lExpected, result.L);


}



[Theory(DisplayName = "BuildToHsl_ShouldCreateAColorInHexWithCustomHueOption")]
[InlineData("yoda", 90, "59783A")]
[InlineData("yoda", 210, "3A5978")]
[InlineData("yoda", 270, "593A78")]
[InlineData("yoda", 360, "783A3A")]
public void BuildToHsl_ShouldCreateAColorInHexWithCustomHueOption(
string phrase, int hue, string hexExpected)
{
var options = new Options();
options.SetHue(hue);

var colorHash = new Fernandezja.ColorHashSharp.ColorHash(options);

var result = colorHash.BuildToHex(phrase);

Assert.NotNull(result);

Assert.Equal(hexExpected, result);


}

[Theory(DisplayName = "BuildToHex_ShouldCreateAColorInHex")]
[InlineData("yoda", "68783A")]
[InlineData("Yoda", "D279BE")]
Expand Down
56 changes: 56 additions & 0 deletions src/ColorHashSharp.Tests/OptionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,61 @@ public void GetLS_ArrayValues()
}


[Theory(DisplayName = "SetHue_SimpleValue")]
[InlineData(90)]
[InlineData(0.35)]
public void SetHue_SimpleValue(int value)
{
var options = new Fernandezja.ColorHashSharp.Options();
options.SetHue(value);

Assert.NotNull(options.HueRanges);
Assert.Single(options.HueRanges);
Assert.Equal(value, options.HueRanges[0].Min);
Assert.Equal(value, options.HueRanges[0].Max);
}


[Fact(DisplayName = "SetHue_ListValues")]
public void SetHue_ListValues()
{
var options = new Fernandezja.ColorHashSharp.Options();

var hueValues = new List<(int Min, int Max)>();
hueValues.Add((90, 270));

options.SetHue(hueValues);

Assert.NotNull(options.HueRanges);
Assert.Single(options.HueRanges);
Assert.Equal(90, options.HueRanges[0].Min);
Assert.Equal(270, options.HueRanges[0].Max);
}

[Fact(DisplayName = "SetHue_ListValues2")]
public void SetHue_ListValues2()
{
var options = new Fernandezja.ColorHashSharp.Options();

var hueValues = new List<(int Min, int Max)>();
hueValues.Add((30, 90));
hueValues.Add((180, 210));
hueValues.Add((270, 285));

options.SetHue(hueValues);

Assert.NotNull(options.HueRanges);
Assert.Equal(3, options.HueRanges.Count);

Assert.Equal(30, options.HueRanges[0].Min);
Assert.Equal(90, options.HueRanges[0].Max);

Assert.Equal(180, options.HueRanges[1].Min);
Assert.Equal(210, options.HueRanges[1].Max);

Assert.Equal(270, options.HueRanges[2].Min);
Assert.Equal(285, options.HueRanges[2].Max);
}

}
}
10 changes: 8 additions & 2 deletions src/ColorHashSharp.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.168
# Visual Studio Version 17
VisualStudioVersion = 17.5.33103.201
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ColorHashSharp", "ColorHashSharp\ColorHashSharp.csproj", "{68766358-4CA1-4A57-94B9-0E1CF0F809BF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ColorHashSharp.Tests", "ColorHashSharp.Tests\ColorHashSharp.Tests.csproj", "{2170724A-3466-4604-B243-D3B0936B44A3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColorHashSharp.Benchmarks", "ColorHashSharp.Benchmarks\ColorHashSharp.Benchmarks.csproj", "{2CC808B2-AF1F-4556-B601-C755129CCEB0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{2170724A-3466-4604-B243-D3B0936B44A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2170724A-3466-4604-B243-D3B0936B44A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2170724A-3466-4604-B243-D3B0936B44A3}.Release|Any CPU.Build.0 = Release|Any CPU
{2CC808B2-AF1F-4556-B601-C755129CCEB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2CC808B2-AF1F-4556-B601-C755129CCEB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CC808B2-AF1F-4556-B601-C755129CCEB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CC808B2-AF1F-4556-B601-C755129CCEB0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading