quant

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2018 License: MIT Imports: 4 Imported by: 3

README

Quant

Experiments with color quantizers

Implemented here are two rather simple quantizers and an (also simple) ditherer. The quantizers satisfy the draw.Quantizer interface of the standard library. The ditherer satisfies the draw.Drawer interface of the standard library.

Documentation

Overview

Quant provides an interface for image color quantizers.

Index

Constants

View Source
const (
	TLeaf = iota
	TSplitR
	TSplitG
	TSplitB
)

Variables

This section is empty.

Functions

func Paletted

func Paletted(p Palette, img image.Image) *image.Paletted

Types

type LinearPalette

type LinearPalette struct {
	color.Palette
}

LinearPalette implements the Palette interface with color.Palette and has no optimizations.

func (LinearPalette) ColorNear

func (p LinearPalette) ColorNear(c color.Color) color.Color

Color near returns the nearest palette color.

It simply wraps color.Palette.Convert.

func (LinearPalette) ColorPalette

func (p LinearPalette) ColorPalette() color.Palette

ColorPalette satisfies interface Palette.

It simply returns the internal color.Palette.

func (LinearPalette) IndexNear

func (p LinearPalette) IndexNear(c color.Color) int

IndexNear returns the palette index of the nearest palette color.

It simply wraps color.Palette.Index.

func (LinearPalette) Len

func (p LinearPalette) Len() int

type Node

type Node struct {
	Type int
	// for TLeaf
	Index int
	Color color.RGBA64
	// for TSplit
	Split     uint32
	Low, High *Node
}

Node is a TreePalette node. It is exported for access by quantizer packages and otherwise can be ignored for typical use of this package.

type Palette

type Palette interface {
	Len() int
	IndexNear(color.Color) int
	ColorNear(color.Color) color.Color
	ColorPalette() color.Palette
}

Palette is a palette of color.Colors, much like color.Palette of the standard library.

It is defined as an interface here to allow more general implementations, presumably ones that maintain some data structure to achieve performance advantages over linear search.

type Quantizer

type Quantizer interface {
	// Paletted quantizes an image and returns a paletted image.
	Paletted(image.Image) *image.Paletted
	// Palette quantizes an image and returns a Palette.  Note the return
	// type is the Palette interface of this package and not image.Palette.
	Palette(image.Image) Palette
}

Quantizer defines a color quantizer for images.

type Sierra24A

type Sierra24A struct{}

Sierra24A satisfies draw.Drawer

func (Sierra24A) Draw

func (d Sierra24A) Draw(dst draw.Image, r image.Rectangle, src image.Image, sp image.Point)

Draw performs error diffusion dithering.

This method satisfies the draw.Drawer interface, implementing a dithering filter attributed to Frankie Sierra. It uses the kernel

  X 2
1 1

type TreePalette

type TreePalette struct {
	Leaves int
	Root   *Node
}

TreePalette implements the Palette interface with a binary tree.

XNear methods run in O(log n) time for palette size.

Fields are exported for access by quantizer packages. Typical use of TreePalette should be through methods.

func (TreePalette) ColorNear

func (t TreePalette) ColorNear(c color.Color) (p color.Color)

ColorNear returns the nearest palette color.

func (TreePalette) ColorPalette

func (t TreePalette) ColorPalette() color.Palette

ColorPalette returns a color.Palette corresponding to the TreePalette.

func (TreePalette) IndexNear

func (t TreePalette) IndexNear(c color.Color) (i int)

IndexNear returns the index of the nearest palette color.

func (TreePalette) Len

func (p TreePalette) Len() int

func (TreePalette) Search

func (t TreePalette) Search(c color.Color, f func(leaf *Node))

Search searches for the given color and calls f for the node representing the nearest color.

func (TreePalette) Walk

func (t TreePalette) Walk(f func(leaf *Node, i int))

Walk walks the TreePalette calling f for each color.

Directories

Path Synopsis
Mean is a simple color quantizer.
Mean is a simple color quantizer.
Median implements basic median cut color quantization.
Median implements basic median cut color quantization.

Jump to

Keyboard shortcuts

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