Documentation ¶
Index ¶
- Constants
- Variables
- func BrownDitherForBlocks(img gocv.Mat, edges gocv.Mat) [][]BlockRune
- func CompressANSI(ansiImage string) string
- func ComputeDistinctColors()
- func ImageToANSI(imagePath string) string
- func LoadPalette(path string) (*ComputedTables, *ComputedTables, error)
- func LoadPaletteAsCompactTables(path string) (CompactComputedTables, CompactComputedTables, error)
- func LoadPaletteJSON(path string) (*ComputedTables, *ComputedTables, error)
- func PaletteSame(fgData AnsiData, bgData AnsiData) bool
- func ReadAnsiDataFromJSON(filename string) (AnsiData, AnsiData, error)
- type AnsiData
- type AnsiEntry
- type ApproximateCache
- type BlockRune
- type ByAnsiCode
- type ColorDistance
- type ColorDistanceMethod
- type ColorMethodCompactTables
- type ColorNode
- type ColorTableEntry
- type CompactComputedTables
- type CompactTablePair
- type ComputedTables
- type LAB
- type Match
- type OrderedMap
- type PriorityQueue
- type Quadrants
- type RGB
- type Uint128
- type Uint256
Constants ¶
const (
ESC = "\u001b"
)
Variables ¶
var ( TargetWidth = 100 ScaleFactor = 3.0 MaxChars = 1048576 Quantization = 1 KdSearch = 0 CacheThreshold = 50.0 LookupHits int LookupMisses int BeginInitTime time.Time BestBlockTime time.Duration DistinctColors int )
var ColorDistanceMethods = []string{
"RGB",
"LAB",
"Redmean",
}
var CurrentColorDistanceMethod = MethodRGB
Global variable to set the color distance method
Functions ¶
func BrownDitherForBlocks ¶
BrownDitherForBlocks applies a modified Floyd-Steinberg dithering algorithm to an image operating on 2x2 blocks rather than pixels. The function takes an input image and a binary image with edges detected. It returns a BlockRune representation with the dithering algorithm applied, with colors quantized to the nearest ANSI color.
func CompressANSI ¶
CompressANSI compresses an ANSI image by combining adjacent blocks with the same foreground and background colors. The function takes an ANSI image as a string and returns the more efficient ANSI image as a string.
func ComputeDistinctColors ¶
func ComputeDistinctColors()
func ImageToANSI ¶
ImageToANSI converts an image to ANSI art. The function takes the path to an image file as a string and returns the image as an ANSI string.
func LoadPalette ¶
func LoadPalette(path string) (*ComputedTables, *ComputedTables, error)
func LoadPaletteAsCompactTables ¶
func LoadPaletteAsCompactTables(path string) (CompactComputedTables, CompactComputedTables, error)
func LoadPaletteJSON ¶
func LoadPaletteJSON(path string) (*ComputedTables, *ComputedTables, error)
func PaletteSame ¶
func ReadAnsiDataFromJSON ¶
ReadAnsiDataFromJSON reads ANSI color data from a JSON file and returns the foreground and background ANSI color data as AnsiData slices. The function takes a filename as a string and returns the foreground and background AnsiData slices, or an error if the file cannot be read or the data cannot be unmarshalled.
Types ¶
type AnsiData ¶
type AnsiData []AnsiEntry
func (AnsiData) ToOrderedMap ¶
func (ansiData AnsiData) ToOrderedMap() *OrderedMap
ToOrderedMap converts an AnsiData slice to an OrderedMap with the values as keys and the keys as values.
type ApproximateCache ¶
type ApproximateCache map[Uint256]lookupEntry
ApproximateCache is a map of Uint256 to lookupEntry that is used to store approximate matches for a given block of 4 RGB values. Approximate matches are performed by comparing the error of a given match to a threshold Value.
The Key of the map is a Uint256, which is a 256-bit unsigned integer that is used to represent the foreground and background colors of a block of 4 RGB values.
There may be multiple matches for a given Key, so the Value of the map is a lookupEntry, which is a struct that contains a slice of Match structs.
type BlockRune ¶
BlockRune represents a 2x2 block of runes with foreground and background colors mapped in the ANSI color space. The struct contains a rune representing the block character, and two RGB colors representing the foreground and background colors of the block.
type ByAnsiCode ¶
type ByAnsiCode AnsiData
ByAnsiCode implements sort.Interface for AnsiData based on the numeric value of the ANSI code
func (ByAnsiCode) Len ¶
func (a ByAnsiCode) Len() int
func (ByAnsiCode) Less ¶
func (a ByAnsiCode) Less(i, j int) bool
func (ByAnsiCode) Swap ¶
func (a ByAnsiCode) Swap(i, j int)
type ColorDistance ¶
type ColorDistance struct {
// contains filtered or unexported fields
}
ColorDistance is a helper struct to keep track of colors and their distances
type ColorDistanceMethod ¶
type ColorDistanceMethod int
ColorDistanceMethod is an enum type for different color distance calculation methods
const ( MethodRGB ColorDistanceMethod = iota MethodLAB MethodRedmean )
type ColorMethodCompactTables ¶
type ColorMethodCompactTables map[ColorDistanceMethod]CompactTablePair
type ColorNode ¶
ColorNode represents a node in a KD-tree that stores RGB colors. Each node contains a color, a left child, a right child, and the axis along which the colors are split.
func DeserializeKDTree ¶
type ColorTableEntry ¶
type CompactComputedTables ¶
type CompactComputedTables struct { ColorArr []RGB AnsiData AnsiData ClosestColorIdx []byte // Use 1 byte per color instead of full RGB ColorTable []ColorTableEntry KDTreeData []byte // Serialized KD-tree data }
func CompactComputeTables ¶
func CompactComputeTables(colorData AnsiData) CompactComputedTables
func (CompactComputedTables) Restore ¶
func (cct CompactComputedTables) Restore() ComputedTables
type CompactTablePair ¶
type CompactTablePair struct { Fg CompactComputedTables Bg CompactComputedTables }
type ComputedTables ¶
type ComputedTables struct { AnsiData AnsiData ColorArr *[]RGB ClosestColorArr *[]RGB ColorTable *map[RGB]uint32 KdTree *ColorNode }
func ComputeTables ¶
func ComputeTables(colorData AnsiData) ComputedTables
ComputeTables computes the color tables and KD-tree for a given color map. The function takes an OrderedMap of color codes and RGB colors as input, and returns a ComputedTables struct containing the color array, closest color array, color table, and KD-tree.
func LoadPaletteBinary ¶
func LoadPaletteBinary(path string) (fg, bg *ComputedTables, err error)
type Match ¶
Match is a struct that contains the rune, foreground color, background color, and error of a match. The error is a float64 Value that represents the difference between the actual block of 4 RGB values and the pair of foreground and background colors encoded in the Key as an Uint256.
type OrderedMap ¶
type OrderedMap struct {
// contains filtered or unexported fields
}
OrderedMap represents an ordered map data structure
func (*OrderedMap) Delete ¶
func (om *OrderedMap) Delete(key interface{})
Delete removes a Key-Value pair from the map
func (*OrderedMap) Get ¶
func (om *OrderedMap) Get(key interface{}) (interface{}, bool)
Get retrieves a Value from the map by Key
func (*OrderedMap) Iterate ¶
func (om *OrderedMap) Iterate(f func(key, value interface{}))
Iterate calls the provided function for each Key-Value pair in order
func (*OrderedMap) Keys ¶
func (om *OrderedMap) Keys() []interface{}
Keys returns a slice of keys in the order they were inserted
func (*OrderedMap) Len ¶
func (om *OrderedMap) Len() int
Len returns the number of elements in the map
func (*OrderedMap) Set ¶
func (om *OrderedMap) Set(key, value interface{})
Set adds a Key-Value pair to the map
type PriorityQueue ¶
type PriorityQueue []ColorDistance
PriorityQueue implements heap.Interface and holds ColorDistance items
func (PriorityQueue) Len ¶
func (pq PriorityQueue) Len() int
func (PriorityQueue) Less ¶
func (pq PriorityQueue) Less(i, j int) bool
func (*PriorityQueue) Pop ¶
func (pq *PriorityQueue) Pop() interface{}
func (*PriorityQueue) Push ¶
func (pq *PriorityQueue) Push(x interface{})
func (PriorityQueue) Swap ¶
func (pq PriorityQueue) Swap(i, j int)
type Quadrants ¶
Quadrants represents the four quadrants of a 2x2 block of a rune that can be colored independently. Each quadrant is represented by a boolean Value, where true indicates that the quadrant should be colored with the foreground color, and false indicates that the quadrant should be colored with the background color.