Skip to content

Repository files navigation

csolfarve

NuGet version

Øl farve ("beer color") renders SRM and EBC beer color values as sRGB colors, following the spectral model described by A. J. de Lange, "Color," in Brewing Materials and Processes, Elsevier, 2016, pp. 199-249.

Given a color value and an optical path length (the width of the glass the beer is viewed through), the sample's spectral transmittance is derived from its absorption coefficient at 430 nm via the Beer-Lambert law, integrated against the CIE 1931 color matching functions of the 2 degree standard colorimetric observer under illuminant D65, and the resulting XYZ tristimulus values are transformed to sRGB.

Installation

dotnet add package Olfarve

Usage

using Olfarve;
using System.Drawing;

BeerColor.SrmToSrgb(10).ToHex();
BeerColor.EbcToSrgb(20).ToHex();

// The default path length is 5 cm, the width of a typical sample glass
BeerColor.SrmToSrgb(10, pathLengthCm: 1.0).ToHex();

// Results are SRGBColor records of gamma encoded components in [0, 1]
SRGBColor color = BeerColor.SrmToSrgb(10);
var (r, g, b) = color;
color.ToRgb8();
Color drawingColor = color.ToColor();

// Or start from an absorbance measured at 430 nm
BeerColor.AbsorptionToSrgb(0.7874);

Development

Requires the .NET 8 and .NET 10 SDKs (both, to build and test every target framework).

dotnet build
dotnet test
dotnet format --verify-no-changes

About

sRGB rendering of SRM/EBC beer color values for C#

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages