oklch

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

nbrain-oklch-wcag-go

Zero-dependency Go 1.22+ perceptual color science engine (sRGB ↔ OKLab ↔ OKLCH) and WCAG 2.1 contrast auditor.

Documentation

Overview

Package oklch provides zero-dependency Go 1.22+ perceptual color space conversions (sRGB <-> Linear RGB <-> OKLab <-> OKLCH) and WCAG 2.1 contrast auditing by NBrain (https://nbra.in).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChannelToLinear

func ChannelToLinear(c float64) float64

ChannelToLinear converts a normalized sRGB channel to linear light intensity.

func RelativeLuminance

func RelativeLuminance(c SRGB) float64

RelativeLuminance returns WCAG 2.1 relative luminance Y in [0,1].

func WCAGContrastRatio

func WCAGContrastRatio(a, b SRGB) float64

WCAGContrastRatio computes the WCAG 2.1 contrast ratio in [1,21].

Types

type OKLCH

type OKLCH struct{ L, C, H float64 }

OKLCH represents perceptual Lightness L, Chroma C, and Hue H in degrees [0,360).

func SRGBToOKLCH

func SRGBToOKLCH(c SRGB) OKLCH

SRGBToOKLCH converts sRGB directly to cylindrical OKLCH.

type OKLab

type OKLab struct{ L, A, B float64 }

OKLab represents perceptual lightness L and chromatic axes a, b.

func SRGBToOKLab

func SRGBToOKLab(c SRGB) OKLab

SRGBToOKLab implements Björn Ottosson's exact D65 sRGB -> OKLab transform.

type SRGB

type SRGB struct{ R, G, B float64 }

SRGB represents normalized [0,1] sRGB channels.

func HexToSRGB

func HexToSRGB(hex string) (SRGB, error)

HexToSRGB parses a #RRGGBB hex string into normalized [0,1] sRGB channels.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL