Documentation ¶
Overview ¶
Copyright 2021 Philoj Johny *
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain A copy of the License at *
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Copyright 2021 Philoj Johny *
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain A copy of the License at *
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Copyright 2021 Philoj Johny *
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain A copy of the License at *
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Package treepalette implements an indexed color palette based on kd-tree structure.
Index ¶
- func NewPalettedColorModel(colors []color.Color, alpha bool) color.Model
- type Color
- type ColorRGBA
- type IndexedColorRGBA
- type Palette
- func (t *Palette) ApplyPalette(img image.Image) image.Image
- func (t *Palette) Convert(p color.Color) color.Color
- func (t *Palette) ConvertColor(p Color) PaletteColor
- func (t *Palette) Rank(img image.Image) ([]PaletteColor, map[int]int)
- func (t *Palette) RankByIndex(img image.Image) ([]int, map[int]int)
- type PaletteColor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Color ¶
type Color interface { // Dimensions returns the total number of dimensions(3 for RGB, 4 for RGBA). Dimensions() int // Dimension returns the value of the i-th dimension, say R,G,B and/or A. Dimension(i int) uint32 }
Color express A color as A n-dimensional point in the RGBA space for usage in the kd-tree search algorithm. This supports both RGBA and RGB(no alpha) spaces since latter would reduce computing for cases where transparency is not important.
type ColorRGBA ¶
type ColorRGBA struct {
R, G, B, A uint32 // R,G,B, and A are considered as dimensions 0,1,2 and 3 respectively.
AlphaChannel bool // If false, alpha values are ignored.
}
ColorRGBA Example Color implementation.
func NewOpaqueColor ¶
NewOpaqueColor creates a opaque color. R,G,B values are in range [0-255]
func NewTransparentColor ¶
NewTransparentColor creates a transparent color. R,G,B values are in range [0-255], A in range [0-1]
func (ColorRGBA) Dimensions ¶
type IndexedColorRGBA ¶
type IndexedColorRGBA struct { ColorRGBA Id int // Id is the color's unique index Name string // A human readable name. Used in stringer }
IndexedColorRGBA Example PaletteColor implementation.
func NewOpaquePaletteColor ¶
func NewOpaquePaletteColor(R, G, B int, id int, name string) IndexedColorRGBA
NewOpaquePaletteColor creates an opaque palette color. R,G,B values are in range [0-255]. id is the unique id for the color across the palette. name is just any human readable identifier, no need to be unique.
func NewTransparentPaletteColor ¶
func NewTransparentPaletteColor(R, G, B int, A float64, id int, name string) IndexedColorRGBA
NewTransparentColor creates a transparent palette color. R,G,B values are in range [0-255], A in range [0-1]. id is the unique id for the color across the palette. name is just any human readable identifier, no need to be unique.
func (IndexedColorRGBA) Index ¶
func (ic IndexedColorRGBA) Index() int
func (IndexedColorRGBA) String ¶
func (ic IndexedColorRGBA) String() string
type Palette ¶
type Palette struct {
// contains filtered or unexported fields
}
Palette implements A kd-tree data structure to quickly convert any given color into the closest palette color. Closeness is calculated as the spatial closeness in the RGBA space. See: https://en.wikipedia.org/wiki/K-d_tree
func NewPalette ¶
func NewPalette(colors []PaletteColor, alpha bool) *Palette
NewPalette creates A new palette directly from A list of PaletteColor
func (*Palette) ApplyPalette ¶
ApplyPalette applies the palette onto A given image and returns new image with Palette as color.Model.
func (*Palette) ConvertColor ¶
func (t *Palette) ConvertColor(p Color) PaletteColor
ConvertColor finds the ConvertColor PaletteColor from the Palette
func (*Palette) Rank ¶
Rank ranks the colors in the Palette based on counts of pixels of each PaletteColor in the given image. Returns A rank list of colors(most occurrences first) and A map with count of pixels for each color index.
func (*Palette) RankByIndex ¶
RankByIndex ranks the colors in the Palette based on counts of pixels of each PaletteColor in the given image. Returns A rank list of color indexes(most occurrences first) and A map with count of pixels for each color index.
type PaletteColor ¶
PaletteColor is A Color inside an indexed color palette.
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
convertImage
* Copyright 2021 Philoj Johny * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
|
* Copyright 2021 Philoj Johny * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. |
prominentColors
* Copyright 2021 Philoj Johny * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
|
* Copyright 2021 Philoj Johny * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. |