Documentation ¶
Overview ¶
Package palette provides tools to extract color palettes from images.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Lab = lab{}
Lab represents the CIE L*a*b* color space, which provides a more accurate representation of what humans see.
var RGB = rgb{}
RGB represents the RGB color space.
Functions ¶
This section is empty.
Types ¶
type BinaryEncoder ¶
type BinaryEncoder struct {
// contains filtered or unexported fields
}
func (*BinaryEncoder) Bytes ¶
func (e *BinaryEncoder) Bytes() []byte
Bytes returns the []byte with the encoding data
func (*BinaryEncoder) Float64 ¶
func (e *BinaryEncoder) Float64(x float64) error
Float64 writes a float64 in IEEE 754 binary representation.
func (*BinaryEncoder) Uvarint ¶
func (e *BinaryEncoder) Uvarint(x uint64) error
Uvarint writes a uint64 in varint encoding.
func (*BinaryEncoder) Varint ¶
func (e *BinaryEncoder) Varint(x int64) error
Varint writes a int64 in varint encoding.
type Cdf ¶
type Cdf []bin
Cdf is a cumulative distribution function (CDF) of colors in a image. The value field is the less than or equal to the probability of this color.
type ColorHistogram ¶
type ColorHistogram Histogram
ColorHistogram is the histogram of colors in a image.
func NewColorHistogram ¶
func NewColorHistogram(img image.Image) ColorHistogram
NewColorHistogram returns the ColorHistogram for the given image where the histogram keys are encoded RGB values.
func (ColorHistogram) Cdf ¶
func (h ColorHistogram) Cdf() (Cdf, error)
Cdf returns the cumulative distribution function (CDF) for this histogram.
func (ColorHistogram) Combine ¶
func (h ColorHistogram) Combine(hist ColorHistogram) ColorHistogram
Combine combines two histograms together. The resulting histogram is not normalised.
func (ColorHistogram) Normalise ¶
func (h ColorHistogram) Normalise() ColorHistogram
Normalise ensures the area under the histogram equals one.
func (ColorHistogram) String ¶
func (h ColorHistogram) String() string
type ColorPalette ¶
ColorPalette is a slice of color.Color.
func FromRGBA ¶
func FromRGBA(pal []RGBA) ColorPalette
FromRGBA creates a ColorPalette from the given slice of RGBA colors.
func (ColorPalette) Draw ¶
func (p ColorPalette) Draw(out io.Writer) error
Draw outputs a png file representing the color palette.
func (ColorPalette) String ¶
func (p ColorPalette) String() string
func (ColorPalette) ToRGBA ¶
func (p ColorPalette) ToRGBA() []RGBA
ToRGBA returns this ColorPalette represented by RGBA colors.
type Extractor ¶
type Extractor struct { ColorSpace colorSpace // Color Space to use, either palette.RGB or palette.Lab Samples int // Number of pixels to sample. 0 means all pixels. // contains filtered or unexported fields }
Extractor extracts a Color Palette from a image.
func (Extractor) FromHistogram ¶
func (p Extractor) FromHistogram(hist ColorHistogram, n int) (ColorPalette, error)
FromHistogram returns the palette of n colors for the given ColorHistogram.
type Histogram ¶
type Histogram []bin
Histogram is simple histogram implementation.
func (Histogram) Combine ¶
Combine combines two histograms together. The resulting histogram is not normalised.
func (Histogram) MarshalBinary ¶
MarshalBinary encodes the receiver into a binary form and returns the result.
type RGBA ¶
RGBA is a color.RGBA but implements the encoding.TextMarshaler and encoding.TextUnmarshaler interfaces to turn the color into HTML hex form, e.g "#001122".
func (RGBA) MarshalText ¶
MarshalText marshals the color into its HTML hex form, e.g "#001122".
func (RGBA) RGBA ¶
RGBA returns the alpha-premultiplied red, green, blue and alpha values for the color.
func (*RGBA) UnmarshalText ¶
UnmarshalText unmarshal from HTML hex form to a color.Color.