f32color

package
v0.0.0-...-ec39e06 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2024 License: Unlicense Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// All legible text should have at least this contrast ratio.
	MinimumContrastRatio = 4.5 / 1.0
	// With the exception of large text, which can have lower contrast ratio.
	LargeTextMinimumContrastRatio = 3.0 / 1.0

	// Enhanced Contrast mode has stricter values.
	EnhancedMinimumContrastRatio          = 7 / 1.0
	EnhancedLargeTextMinimumContrastRatio = 4.5 / 1.0

	// DefaultBlend is good argument for Emphasis, Lighten and Darken.
	DefaultBlend = 0.15
)

Constants defined by https://www.w3.org/TR/WCAG20/#visual-audio-contrast-contrast

Variables

This section is empty.

Functions

func ContrastRatio

func ContrastRatio(a, b RGBA) float32

ContrastRatio calculates contrast ratio between two values. Returns a value between 0 and 21.

See https://www.w3.org/TR/WCAG20/#contrast-ratiodef for more details.

func MulAlpha

func MulAlpha(c color.NRGBA, alpha uint8) color.NRGBA

MulAlpha scales all color components by alpha/255.

Types

type HSLA

type HSLA struct{ H, S, L, A float32 }

HSLA is a 32 bit floating point HSL space color, all from 0 to 1.

func (HSLA) Darken

func (col HSLA) Darken(p float32) HSLA

Darken returns linear color blend with black in HSL colorspace with the specified percentage.

func (HSLA) Emphasize

func (col HSLA) Emphasize(ratio float32) HSLA

Emphasize darkens light colors and lightens dark colors.

func (HSLA) IsBright

func (col HSLA) IsBright() bool

IsBright estimates whether the color is considered as bright or not based on CIELab perceived lightness.

func (HSLA) Lighten

func (col HSLA) Lighten(p float32) HSLA

Lighten returns linear color blend with white in HSL colorspace with the specified percentage.

func (HSLA) RGBA

func (col HSLA) RGBA() RGBA

HSLA converts color to RGBA.

type RGBA

type RGBA struct {
	R, G, B, A float32
}

RGBA is a 32 bit floating point linear space color.

func LinearFromSRGB

func LinearFromSRGB(col color.NRGBA) RGBA

LinearFromSRGB converts from SRGBA to RGBA.

func (RGBA) Array

func (rgba RGBA) Array() [4]float32

Array returns rgba values in a [4]float32 array.

func (RGBA) Darken

func (col RGBA) Darken(p float32) RGBA

DarkenRGB returns linear color blend with black in RGB colorspace with the specified percentage. Returns `(r,g,b) * (1 - p) + (0, 0, 0) * p`.

func (RGBA) Emphasize

func (col RGBA) Emphasize(p float32) RGBA

Emphasize darkens light colors and lightens dark colors.

func (RGBA) Float32

func (col RGBA) Float32() (r, g, b, a float32)

Float32 returns r, g, b, a values.

func (RGBA) HSLA

func (col RGBA) HSLA() HSLA

HSLA converts color to HSLA.

func (RGBA) IsBright

func (col RGBA) IsBright() bool

IsBright estimates whether the color is considered as bright or not based on CIELab perceived lightness.

func (RGBA) IsBrightAlt

func (col RGBA) IsBrightAlt() bool

IsBrightAlt determines whether color is bright based on whether contrast ratio to white or black is higher.

func (RGBA) Lighten

func (col RGBA) Lighten(p float32) RGBA

LightenRGB returns linear color blend with white in RGB colorspace with the specified percentage. Returns `(r,g,b) * (1 - p) + (1, 1, 1) * p`.

func (RGBA) Luminance

func (col RGBA) Luminance() float32

Luminance calculates the relative luminance of a linear RGBA color. Normalized to 0 for black and 1 for white.

See https://www.w3.org/TR/WCAG20/#relativeluminancedef for more details.

func (RGBA) Opaque

func (col RGBA) Opaque() RGBA

Opaque returns the color without alpha component.

func (RGBA) PerceivedLightness

func (col RGBA) PerceivedLightness() float32

PerceivedLightness calculates the perceived lightness from 0 black to 100 white. 50 is the middle gray.

This corresponds to the L value in CIELab color space. It does not take into account some psychophyscal attributes like Helmholtz-Kohlrausch effect.

Based on https://stackoverflow.com/a/56678483/192220.

func (RGBA) SRGB

func (col RGBA) SRGB() color.NRGBA

SRGBA converts from linear to sRGB color space.

Jump to

Keyboard shortcuts

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