palette

package
v0.0.0-...-0be9921 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package palette provides tools to extract color palettes from images.

Index

Constants

This section is empty.

Variables

View Source
var Lab = lab{}

Lab represents the CIE L*a*b* color space, which provides a more accurate representation of what humans see.

View Source
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.

func (Cdf) Rand

func (cdf Cdf) Rand(random Rand) int

Rand returns a random value from the cdf, chosen based on the weight of the values.

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

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

type ColorPalette []color.Color

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.

func (Extractor) FromImage

func (p Extractor) FromImage(img image.Image, n int) (ColorPalette, error)

FromImage returns the palette of n colors for the given image.

type Histogram

type Histogram []bin

Histogram is simple histogram implementation.

func UnMarshalBinaryHistogram

func UnMarshalBinaryHistogram(data []byte) (Histogram, error)

func (Histogram) Cdf

func (h Histogram) Cdf() (Cdf, error)

Cdf returns the cumulative distribution function (CDF) for this histogram.

func (Histogram) Combine

func (h Histogram) Combine(hist Histogram) Histogram

Combine combines two histograms together. The resulting histogram is not normalised.

func (Histogram) MarshalBinary

func (h Histogram) MarshalBinary() (data []byte, err error)

MarshalBinary encodes the receiver into a binary form and returns the result.

func (Histogram) Normalise

func (h Histogram) Normalise() Histogram

Normalise ensures the area under the histogram equals one.

func (Histogram) String

func (h Histogram) String() string

func (Histogram) Total

func (h Histogram) Total() float64

Total returns the area under the histogram.

type RGBA

type RGBA color.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) Hex

func (c RGBA) Hex() string

Hex returns the HTML hex form, e.g "#001122".

func (RGBA) Int

func (c RGBA) Int() int

Int returns the 32 bit value of this color.

func (RGBA) MarshalText

func (c RGBA) MarshalText() ([]byte, error)

MarshalText marshals the color into its HTML hex form, e.g "#001122".

func (RGBA) RGBA

func (c RGBA) RGBA() (uint32, uint32, uint32, uint32)

RGBA returns the alpha-premultiplied red, green, blue and alpha values for the color.

func (*RGBA) UnmarshalText

func (c *RGBA) UnmarshalText(hex []byte) error

UnmarshalText unmarshal from HTML hex form to a color.Color.

type Rand

type Rand interface {
	// Float64 returns, as a float64, a pseudo-random number in [0.0,1.0)
	Float64() float64
}

Rand is a source of random float64s, compatible with *rand.Rand.

Jump to

Keyboard shortcuts

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