xcolor

package
v0.0.0-...-b509ac4 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NRGBAToRGBAImage

func NRGBAToRGBAImage(img *image.NRGBA) *image.RGBA

NRGBAToRGBAImage converts an *image.NRGBA to an *image.RGBA. It does not perform alpha-premultiplication.

Types

type AveragingFunc

type AveragingFunc func([]AveragingPoint) RGB

AveragingFunc is a function that averages a slice of colors into a single color.

func NewNearestAveraging

func NewNearestAveraging() AveragingFunc

NewNearestAveraging creates a new AveragingFunc that averages a slice of colors into a single color. It simply returns the first color in the slice.

func NewSimpleAveraging

func NewSimpleAveraging() AveragingFunc

NewSimpleAveraging creates a new AveragingFunc that averages a slice of colors into a single color. It simply averages the red, green, and blue values of the colors.

This function can handle about 2.8 million colors before overflowing.

func NewSquaredAveraging

func NewSquaredAveraging() AveragingFunc

NewSquaredAveraging creates a new AveragingFunc that averages a slice of colors into a single color. It squares the red, green, and blue values of the colors before averaging them to give more weight to brighter colors.

This function can handle about 33 thousand colors before overflowing.

For more information, see: https://sighack.com/post/averaging-rgb-colors-the-right-way

type AveragingPoint

type AveragingPoint struct {
	Color     RGB
	Intensity float32
}

AveragingPoint is a point that is used to average a slice of colors into a single color.

type AveragingType

type AveragingType uint8
const (
	SimpleAveragingType AveragingType
	SquaredAveragingType
	NearestNeighborAveragingType
)

type RGB

type RGB struct {
	R, G, B uint8
}

RGB is a color in the RGB color space. It is represented as 3 8-bit values for red, green, and blue.

func RGBFromColor

func RGBFromColor(c color.Color) RGB

RGBFromColor converts any color.Color to RGB.

func RGBFromRGBA

func RGBFromRGBA(c color.RGBA) RGB

RGBFromRGBA converts a color.RGBA to RGB.

func RGBFromString

func RGBFromString(s string) (RGB, error)

RGBFromString converts a string to RGB.

func RGBFromUint

func RGBFromUint(u uint32) RGB

RGBFromUint converts an integer to RGB.

func (RGB) MarshalJSON

func (c RGB) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. It marshals RGB as an integer.

func (RGB) RGBA

func (c RGB) RGBA() (r, g, b, a uint32)

RGBA implements the color.Color interface.

func (RGB) String

func (c RGB) String() string

String implements the fmt.Stringer interface. It returns the color in hexadecimal notation.

func (RGB) ToUint

func (c RGB) ToUint() uint32

ToUint converts the RGB color to an integer.

func (*RGB) UnmarshalJSON

func (c *RGB) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. It unmarshals an integer as RGB.

Jump to

Keyboard shortcuts

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