Documentation
¶
Overview ¶
Package material computes Material You color schemes from an image, a port of Google's material-color-utilities (the TypeScript release 0.4.0, 2021 color spec): CAM16 and HCT, the Celebi quantizer (Wu, then WSMeans), the seed scorer, tonal palettes and the dynamic scheme roles of every variant, at any contrast level.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContrastRatio ¶
ContrastRatio is the WCAG contrast ratio between two colors, 1 to 21.
Types ¶
type ARGB ¶
type ARGB uint32
ARGB is an opaque sRGB color packed as 0xAARRGGBB.
const FallbackSeed ARGB = 0xff4285f4
FallbackSeed is the seed Score ranks when no color is suitable: a Google blue.
func Sample ¶
Sample reads img at a grid of at most side samples along its longer edge, keeping its aspect, one pixel at the center of each cell, and returns the opaque ones. Its work and its one allocation are bounded by the grid, whatever the image's resolution.
func Score ¶
func Score(colors []Population) []ARGB
Score ranks the quantized colors as theme seeds, best first: up to four colors of distinct hue, weighing chroma against how much of the image lies near each hue. It is never empty: FallbackSeed stands in when no color qualifies.
type HCT ¶
type HCT struct {
Hue, Chroma, Tone float64
// contains filtered or unexported fields
}
HCT is a color in Google's hue, chroma and tone space: CAM16 hue and chroma with L* tone.
type Population ¶
Population is one quantized color and the number of pixels it stands for.
func Quantize ¶
func Quantize(pixels []ARGB, maxColors int) []Population
Quantize reduces the opaque pixels to at most maxColors colors with the Celebi quantizer (Wu boxes refined by WSMeans), in the order the reference implementation reports them.
type Role ¶
type Role uint8
Role is a named color of a dynamic scheme.
const ( RolePrimaryPaletteKeyColor Role = iota RoleSecondaryPaletteKeyColor RoleTertiaryPaletteKeyColor RoleNeutralPaletteKeyColor RoleNeutralVariantPaletteKeyColor RoleErrorPaletteKeyColor RoleBackground RoleOnBackground RoleSurface RoleSurfaceDim RoleSurfaceBright RoleSurfaceContainerLowest RoleSurfaceContainerLow RoleSurfaceContainer RoleSurfaceContainerHigh RoleSurfaceContainerHighest RoleOnSurface RoleSurfaceVariant RoleOnSurfaceVariant RoleInverseSurface RoleInverseOnSurface RoleOutline RoleOutlineVariant RoleShadow RoleScrim RoleSurfaceTint RolePrimary RoleOnPrimary RolePrimaryContainer RoleOnPrimaryContainer RoleInversePrimary RoleSecondary RoleOnSecondary RoleSecondaryContainer RoleOnSecondaryContainer RoleTertiary RoleOnTertiary RoleTertiaryContainer RoleOnTertiaryContainer RoleError RoleOnError RoleErrorContainer RoleOnErrorContainer RolePrimaryFixed RolePrimaryFixedDim RoleOnPrimaryFixed RoleOnPrimaryFixedVariant RoleSecondaryFixed RoleSecondaryFixedDim RoleOnSecondaryFixed RoleOnSecondaryFixedVariant RoleTertiaryFixed RoleTertiaryFixedDim RoleOnTertiaryFixed RoleOnTertiaryFixedVariant // RoleCount is the number of roles. RoleCount )
The scheme roles, named as matugen's JSON names them.