codec

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockSize2 = 2
	BlockSize4 = 4
	BlockSize8 = 8
)

Variables

This section is empty.

Functions

func ClampToByte

func ClampToByte(v float64) int

ClampToByte rounds and clamps a float into 0..255.

func GrayFromRGB

func GrayFromRGB(r, g, b uint8) uint8

GrayFromRGB converts RGB to an 8-bit grayscale value.

func Luminance

func Luminance(r, g, b uint8) float64

Luminance computes perceived brightness for RGB values.

Types

type BlockHandler

type BlockHandler interface {
	BeginBlock(col, row int)
	AddSample(sample BlockSample)
	Result() (glyph rune, fg, bg *Color)
}

BlockHandler consumes samples for each block to produce a glyph and optional colors.

type BlockSample

type BlockSample struct {
	Gray uint8
	R    uint8
	G    uint8
	B    uint8
	X    int // relative column inside the block (0..blockW-1)
	Y    int // relative row inside the block (0..blockH-1)
}

BlockSample represents a single pixel sampled within a block.

type Cell

type Cell struct {
	Glyph rune
	FG    PaletteIndex
	BG    PaletteIndex
}

Cell хранит глиф и ссылки на цвета палитры.

type Color

type Color struct {
	R uint8
	G uint8
	B uint8
}

Color описывает RGB-тройку.

func (Color) RGBA

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

RGBA allows Color to satisfy the image/color.Color interface.

type Frame

type Frame struct {
	Cols  int
	Rows  int
	Cells []Cell
	// contains filtered or unexported fields
}

Frame — двумерная сетка терминальных ячеек с общей палитрой.

func EncodeFull

func EncodeFull(img *PreparedImage, cols, rows int) *Frame

EncodeFull renders full 4×8 monochrome blocks using the extended glyph palette.

func EncodeFullColor

func EncodeFullColor(img *PreparedImage, cols, rows int) *Frame

EncodeFullColor renders the image using ANSI colors and the extended glyph set for 4x8 blocks.

func EncodeFullGray

func EncodeFullGray(img *PreparedImage, cols, rows int) *Frame

EncodeFullGray renders the image using ANSI colors and a glyph set defined for 4x8 blocks.

func EncodeHalf

func EncodeHalf(img *PreparedImage, cols, rows int) *Frame

EncodeHalf renders monochrome output using upper/lower half block glyphs.

func EncodeHalfColor

func EncodeHalfColor(img *PreparedImage, cols, rows int) *Frame

EncodeHalfColor renders the image using ANSI tinted spaces/▀ to represent two stacked color pixels.

func EncodeHalfGray

func EncodeHalfGray(img *PreparedImage, cols, rows int) *Frame

EncodeHalfGray renders the image using ANSI tinted spaces/▀ to represent two stacked grayscale pixels.

func EncodeOne

func EncodeOne(img *PreparedImage, cols, rows int) *Frame

EncodeOne renders two stacked monochrome pixels using solid/blank glyphs.

func EncodeOneColor

func EncodeOneColor(img *PreparedImage, cols, rows int) *Frame

EncodeOneColor renders the image as ANSI tinted spaces representing the original pixel colors.

func EncodeOneGray

func EncodeOneGray(img *PreparedImage, cols, rows int) *Frame

EncodeOneGray renders the image as ANSI tinted spaces representing grayscale pixels.

func EncodeQuarter

func EncodeQuarter(img *PreparedImage, cols, rows int) *Frame

EncodeQuarter renders monochrome quarter blocks (2×2 pixels per terminal cell).

func EncodeQuarterColor

func EncodeQuarterColor(img *PreparedImage, cols, rows int) *Frame

EncodeQuarterColor renders the image using ANSI colors and a limited quarter-block glyph set.

func EncodeQuarterGray

func EncodeQuarterGray(img *PreparedImage, cols, rows int) *Frame

EncodeQuarterGray renders the image using ANSI colors and a limited quarter-block glyph set.

func NewFrame

func NewFrame(cols, rows int) *Frame

NewFrame выделяет кадр указанных размеров.

func (*Frame) Palette

func (f *Frame) Palette() []Color

Palette возвращает текущую палитру кадра.

func (*Frame) PaletteColor

func (f *Frame) PaletteColor(idx PaletteIndex) (Color, bool)

PaletteColor ищет цвет по индексу палитры.

func (*Frame) Reset

func (f *Frame) Reset(cols, rows int)

Reset переиспользует уже выделенный кадр.

func (*Frame) SetCell

func (f *Frame) SetCell(row, col int, glyph rune, fg, bg *Color)

SetCell записывает глиф и цветовые ссылки.

func (*Frame) SetGlyph

func (f *Frame) SetGlyph(row, col int, glyph rune)

SetGlyph меняет только глиф.

type GrayBuffer

type GrayBuffer struct {
	Pix    []uint8
	Width  int
	Height int
	// contains filtered or unexported fields
}

GrayBuffer contains a grayscale copy of an image for quick random access.

func (*GrayBuffer) Index

func (g *GrayBuffer) Index(x, y int) uint8

Index returns the grayscale value at absolute coordinates with bounds checking.

func (*GrayBuffer) Release

func (g *GrayBuffer) Release()

Release returns the underlying memory to the pool.

type PaletteIndex

type PaletteIndex uint16

PaletteIndex identifies цвет в палитре кадра.

const (
	// PaletteIndexNone означает отсутствие цвета (фон/передний план).
	PaletteIndexNone PaletteIndex = 0
)

type PreparedImage

type PreparedImage struct {
	Pix    []uint8
	Stride int
	Width  int
	Height int
}

PreparedImage хранит изображение в формате 4 байта на пиксель (NRGBA или RGBA).

func PrepareImage

func PrepareImage(img image.Image, cols, rows int, mode string) *PreparedImage

PrepareImage масштабирует и приводит входное изображение к нужному режиму.

Jump to

Keyboard shortcuts

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