sixel

package
v0.11.7 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 14 Imported by: 2

Documentation

Overview

Package sixel provides sixel graphics format functionality.

Index

Constants

View Source
const (
	LineBreak        byte = '-'
	CarriageReturn   byte = '$'
	RepeatIntroducer byte = '!'
	ColorIntroducer  byte = '#'
	RasterAttribute  byte = '"'
)

Sixel control functions.

View Source
const (
	// MaxColors is the maximum number of colors a sixelPalette can contain.
	MaxColors int = 256
)

Variables

View Source
var ErrInvalidColor = fmt.Errorf("invalid color")

ErrInvalidColor is returned when a Sixel color is invalid.

View Source
var ErrInvalidRaster = fmt.Errorf("invalid raster attributes")

ErrInvalidRaster is returned when Raster Attributes are invalid.

View Source
var ErrInvalidRepeat = fmt.Errorf("invalid repeat")

ErrInvalidRepeat is returned when a Repeat is invalid.

Functions

func ConvertChannel

func ConvertChannel(c uint32) uint32

ConvertChannel converts a color channel from color.Color 0xffff to 0-100 Sixel RGB format.

func DefaultPalette

func DefaultPalette() color.Palette

DefaultPalette is the default palette used when decoding a Sixel image. It contains the 256 colors defined by the xterm 256-color palette.

func WriteColor

func WriteColor(w io.Writer, pc, pu, px, py, pz int) (int, error)

WriteColor writes a Sixel color to a writer. If pu is 0, the rest of the parameters are ignored.

func WriteRaster

func WriteRaster(w io.Writer, pan, pad, ph, pv int) (n int, err error)

WriteRaster writes Raster attributes to a writer. If ph and pv are 0, they are omitted.

func WriteRepeat

func WriteRepeat(w io.Writer, count int, char byte) (int, error)

WriteRepeat writes a Repeat to a writer. A repeat character is in the range of '?' (0x3F) to '~' (0x7E).

Types

type Color

type Color struct {
	// Pc is the color number (0-255).
	Pc int
	// Pu is an optional color system
	//  - 0: default color map
	//  - 1: HLS
	//  - 2: RGB
	Pu int
	// Color components range from 0-100 for RGB values. For HLS format, the Px
	// (Hue) component ranges from 0-360 degrees while L (Lightness) and S
	// (Saturation) are 0-100.
	Px, Py, Pz int
}

Color represents a Sixel color.

func DecodeColor

func DecodeColor(data []byte) (c Color, n int)

DecodeColor decodes a Sixel color from a byte slice. It returns the Color and the number of bytes read.

func FromColor

func FromColor(c color.Color) Color

FromColor returns a Sixel color from a color.Color. It converts the color channels to the 0-100 range.

func (Color) RGBA

func (c Color) RGBA() (r, g, b, a uint32)

RGBA implements the color.Color interface.

type Decoder

type Decoder struct{}

Decoder is a Sixel image decoder. It reads Sixel image data from an io.Reader and decodes it into an image.Image.

func (*Decoder) Decode

func (d *Decoder) Decode(r io.Reader) (image.Image, error)

Decode will parse sixel image data into an image or return an error. Because the sixel image format does not have a predictable size, the end of the sixel image data can only be identified when ST, ESC, or BEL has been read from a reader. In order to avoid reading bytes from a reader one at a time to avoid missing the end, this method simply accepts a byte slice instead of a reader. Callers should read the entire escape sequence and pass the Ps..Ps portion of the sequence to this method.

type Encoder

type Encoder struct{}

Encoder is a Sixel encoder. It encodes an image to Sixel data format.

func (*Encoder) Encode

func (e *Encoder) Encode(w io.Writer, img image.Image) error

Encode will accept an Image and write sixel data to a Writer. The sixel data will be everything after the 'q' that ends the DCS parameters and before the ST that ends the sequence. That means it includes the pixel metrics and color palette.

type Raster

type Raster struct {
	Pan, Pad, Ph, Pv int
}

Raster represents Sixel raster attributes.

func DecodeRaster

func DecodeRaster(data []byte) (r Raster, n int)

DecodeRaster decodes a Raster from a byte slice. It returns the Raster and the number of bytes read.

func (Raster) String

func (r Raster) String() string

String returns the Raster as a string.

func (Raster) WriteTo

func (r Raster) WriteTo(w io.Writer) (int64, error)

WriteTo writes Raster attributes to a writer.

type Repeat

type Repeat struct {
	Count int
	Char  byte
}

Repeat represents a Sixel repeat introducer.

func DecodeRepeat

func DecodeRepeat(data []byte) (r Repeat, n int)

DecodeRepeat decodes a Repeat from a byte slice. It returns the Repeat and the number of bytes read.

func (Repeat) String

func (r Repeat) String() string

String returns the Repeat as a string.

func (Repeat) WriteTo

func (r Repeat) WriteTo(w io.Writer) (int64, error)

WriteTo writes a Repeat to a writer.

Jump to

Keyboard shortcuts

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