helper

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClampRGB

func ClampRGB(r, g, b float64) (_, _, _ float64)

func ColorToNLRGBA

func ColorToNLRGBA(c color.Color) (_, _, _, _ float64)

func ColorToNOkLabA

func ColorToNOkLabA(c color.Color) (lightness, chromaA, chromaB, a float64)

func Delinearize

func Delinearize(l float64) uint32

Delinearize converts a linearRGB component in the range [0, 1] to an sRGB component in the range [0, 0xffff].

func DelinearizeF added in v0.2.0

func DelinearizeF(l float64) float64

Delinearize converts a linearRGB component in the range [0, 1] to an sRGB component in the range [0, 1].

func Enum

func Enum(color, alpha, slow bool) iter.Seq[_color.RGBA64]

Enum iterates over a sparse sample of the RGBA colour space.

If color is true, the colours will have distinct RGB components. otherwise, the colours will have identical RGB components.

If alpha is true, the colours will include transparency, otherwise the returned colours will be fully opaque.

If slow is false, an even smaller number of samples will be returned making this suitable for use in a nested loop.

color=true alpha=true slow=true: 87481 samples. color=true alpha=false slow=true: 140608 samples. color=true alpha=true slow=false: 649 samples. color=true alpha=false slow=false: 216 samples.

func EnumColor

func EnumColor[C _color.Color](color, alpha, slow bool, m _color.Model) iter.Seq[C]

EnumColor is identical to Enum, but invokes a color.Model to return a concrete colour type.

func EqFloat64Fuzzy

func EqFloat64Fuzzy(a, b float64) bool

EqFloat64Fuzzy returns true if two floats aren't meaningfully distinct from each other.

NaNs aren't considered distinct (meaning this function will return true if both inputs are NaN).

func EqFloat64SliceFuzzy

func EqFloat64SliceFuzzy(a, b []float64) bool

EqFloat64SliceFuzzy returns true if two lists of floats aren't meaningfully distinct from each other.

Returns false if the lists are of different lengths, EqFloat64Fuzzy returns false for any pair of floats.

func LMStoLRGB

func LMStoLRGB(l, m, s float64) (_, _, _ float64)

func LMStoOkLab

func LMStoOkLab(l, m, s float64) (_, _, _ float64)

func LMStoXYZ

func LMStoXYZ(l, m, s float64) (_, _, _ float64)

func LRGBtoLMS

func LRGBtoLMS(r, g, b float64) (_, _, _ float64)

func LRGBtoRGB

func LRGBtoRGB(r, g, b float64) (_, _, _ uint32)

func LRGBtoXYZ

func LRGBtoXYZ(r, g, b float64) (_, _, _ float64)

func Linearize

func Linearize(c uint32) float64

Linearize converts an sRGB component in the range [0, 0xffff] to a linearRGB component in the range [0, 1].

func LinearizeF added in v0.2.0

func LinearizeF(l float64) float64

LinearizeF converts an sRGB component in the range [0, 1] to a linearRGB component in the range [0, 1].

func Model

func Model[C _color.Color](fromColor func(_color.Color) C) _color.Model

func NLRGBAtoNRGBA

func NLRGBAtoNRGBA(r, g, b, a float64) (_, _, _, _ uint32)

func NLRGBAtoRGBA

func NLRGBAtoRGBA(r, g, b, a float64) (_, _, _, _ uint32)

func NRGBAtoNLRGBA

func NRGBAtoNLRGBA(r, g, b, a uint32) (_, _, _, _ float64)

func OkLabToLMS

func OkLabToLMS(l, a, b float64) (_, _, _ float64)

func RGBAtoNLRGBA

func RGBAtoNLRGBA(r, g, b, a uint32) (_, _, _, _ float64)

func RGBtoLRGB

func RGBtoLRGB(r, g, b uint32) (_, _, _ float64)

func TestDistance

func TestDistance[T tester[T], C color.Color](t T, color, alpha bool, midpoint func(c0, c1 C) C, f func(c0, c1 C) float64, m color.Model)

func TestModel

func TestModel[T tester[T], C Color](t T, color, alpha bool, m _color.Model, eq func(c0, c1 C) bool, extra []ConvertTest[C])

func XYZtoLMS

func XYZtoLMS(x, y, z float64) (_, _, _ float64)

func XYZtoLRGB

func XYZtoLRGB(x, y, z float64) (_, _, _ float64)

Types

type Color

type Color interface {
	comparable
	_color.Color
	NRGBA() (r, g, b, a uint32)
	NLRGBA() (r, g, b, a float64)
	NXYZA() (x, y, z, a float64)
	NOkLabA() (lightness, chromaA, chromaB, a float64)
}

Interface that the colours used in this package are expected to implement.

type ConvertTest

type ConvertTest[C Color] struct {
	Name string
	In   _color.Color
	Out  C
}

Jump to

Keyboard shortcuts

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