Hsluv 2.0.0

dotnet add package Hsluv --version 2.0.0
                    
NuGet\Install-Package Hsluv -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hsluv" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hsluv" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Hsluv" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Hsluv --version 2.0.0
                    
#r "nuget: Hsluv, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Hsluv@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Hsluv&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Hsluv&version=2.0.0
                    
Install as a Cake Tool

Build Status Package Version

Explanation, demo, ports etc.

API

This library implements revision 4 of the HSLuv color math, ported from the Haxe reference implementation.

The API is designed to avoid heap allocation. The Hsluv.HsluvConverter class defines the following public fields:

  • RGB: hex, rgb_r [0;1], rgb_g [0;1], rgb_b [0;1]
  • CIE XYZ: xyz_x, xyz_y, xyz_z
  • CIE LUV: luv_l, luv_u, luv_v
  • CIE LUV LCh: lch_l, lch_c, lch_h
  • HSLuv: hsluv_h [0;360], hsluv_s [0;100], hsluv_l [0;100]
  • HPLuv: hpluv_h [0;360], hpluv_p [0;100], hpluv_l [0;100]

To convert between color spaces, simply set the fields of the source color space, run the conversion methods, then read the fields of the target color space.

Use the following methods to convert to and from RGB:

  • HSLuv: HsluvToRgb(), HsluvToHex(), RgbToHsluv(), HexToHsluv()
  • HPLuv: HpluvToRgb(), HpluvToHex(), RgbToHpluv(), HexToHpluv()

Use the following methods to do step-by-step conversion:

  • Forward: HsluvToLch() (or HpluvToLch()), LchToLuv(), LuvToXyz(), XyzToRgb(), RgbToHex()
  • Backward: HexToRgb(), RgbToXyz(), XyzToLuv(), LuvToLch(), LchToHsluv() (or LchToHpluv())

For advanced usage, we also export the bounding lines in slope-intercept format, two for each RGB channel representing the limit of the gamut. They are populated by CalculateBoundingLines(l).

  • R < 0: r0s, r0i
  • R > 1: r1s, r1i
  • G < 0: g0s, g0i
  • G > 1: g1s, g1i
  • B < 0: b0s, b0i
  • B > 1: b1s, b1i

Example:

var conv = new Hsluv.HsluvConverter();
conv.hsluv_h = 10;
conv.hsluv_s = 75;
conv.hsluv_l = 65;
conv.HsluvToHex();
Console.WriteLine(conv.hex); // Will print "#ec7d82"

Supported platforms

The NuGet package ships two builds of the library:

  • netstandard2.0: .NET Core 2.0+, .NET 5+, .NET Framework 4.6.1+, Mono 5.4+, Unity, Xamarin
  • net40: .NET Framework 4.0+

The library is plain C# 7.3 with no dependencies, so Hsluv/Hsluv.cs can also be copied into any project directly.

Building and testing

Requires the .NET SDK (8.0 and 10.0 to run all test targets).

dotnet build -c Release
dotnet run -c Release --project HsluvTest -f net8.0
dotnet run -c Release --project HsluvTest -f net10.0
dotnet run -c Release --project HsluvTest -f net48   # Windows, or Mono elsewhere

CI also compiles the sources with Mono's mcs, see .github/workflows/test.yml.

Packaging

To build the package locally:

dotnet pack Hsluv -c Release -o dist

Releasing

Releases are published to NuGet by the release.yml workflow, triggered by a v* tag. It uses NuGet trusted publishing, so no long-lived API key is stored in GitHub.

One-time setup:

  1. On nuget.org, sign in as an owner of the Hsluv package, open Trusted Publishing and add a policy:

    • Package Owner: your account (it must be an owner of Hsluv, see Manage → Owners on the package page)
    • Repository Owner: hsluv (the GitHub organization)
    • Repository: hsluv-csharp
    • Workflow File: release.yml
    • Environment: release
    • Scopes: select the Hsluv package (or use glob pattern Hsluv)
  2. Store the nuget.org username (profile name, not email) of the policy owner as a repo secret:

    gh secret set NUGET_USER --repo hsluv/hsluv-csharp --body "<nuget.org username>"
    

Then bump <Version> in Hsluv/Hsluv.csproj and create a release:

gh release create v2.0.0 --generate-notes

Authors

Mark Wonnacott, Alexei Boronine

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net40 is compatible.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.0

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 105 11/26/2026
1.0.2 4,313 1/1/2017