Package org.aesh.terminal.image
Class SixelImage
java.lang.Object
org.aesh.terminal.image.SixelImage
- All Implemented Interfaces:
TerminalImage
Sixel graphics protocol implementation.
Sixel is a bitmap graphics format using DCS escape sequences. Each "sixel" represents 6 vertical pixels encoded as a single character.
Protocol format:
DCS P1;P2;P3 q [sixel data] STWhere:
- DCS = ESC P (or 0x90)
- P1 = pixel aspect ratio (0=2:1, 1=5:1, 2=3:1, etc.)
- P2 = background mode (0=device default, 1=no change, 2=set to 0)
- P3 = horizontal grid size (ignored by most terminals)
- q = sixel mode identifier
- ST = ESC \ (string terminator)
Sixel data includes:
- Color definitions: #Pc;Pu;Px;Py;Pz (register, mode, R/H, G/L, B/S)
- Color selection: #Pc
- Sixel characters: ? (0x3F) to ~ (0x7E), value = char - 63
- RLE compression: !Pn[char] (repeat char Pn times)
- Carriage return: $
- New line: - (move to next sixel band)
Supported by: xterm, mlterm, foot, Windows Terminal, mintty, contour, etc.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionencode()Encode the image as an escape sequence string ready to be written to the terminal.static SixelImagefromBytes(byte[] data) Create a Sixel image from raw bytes.static SixelImageCreate a Sixel image from a file.intGet the display height in terminal cells.Get the protocol used by this image.intGet the display width in terminal cells.maxColors(int colors) Set maximum number of colors in palette (2-256).maxHeight(int pixels) Set maximum height in pixels.maxWidth(int pixels) Set maximum width in pixels.useRle(boolean useRle) Enable or disable run-length encoding compression.
-
Constructor Details
-
SixelImage
public SixelImage(byte[] imageData) Create a Sixel image from raw image data.- Parameters:
imageData- the image data (PNG, JPEG, GIF, etc.)
-
-
Method Details
-
fromFile
Create a Sixel image from a file.- Parameters:
path- path to the image file- Returns:
- the terminal image
- Throws:
IOException- if the file cannot be read
-
fromBytes
Create a Sixel image from raw bytes.- Parameters:
data- the image data- Returns:
- the terminal image
-
maxWidth
Set maximum width in pixels. Image will be scaled if larger.- Parameters:
pixels- maximum width- Returns:
- this image for chaining
-
maxHeight
Set maximum height in pixels. Image will be scaled if larger.- Parameters:
pixels- maximum height- Returns:
- this image for chaining
-
maxColors
Set maximum number of colors in palette (2-256). Lower values produce smaller output but less accurate colors.- Parameters:
colors- maximum colors (default 256)- Returns:
- this image for chaining
-
useRle
Enable or disable run-length encoding compression.- Parameters:
useRle- true to use RLE (default true)- Returns:
- this image for chaining
-
encode
Description copied from interface:TerminalImageEncode the image as an escape sequence string ready to be written to the terminal.- Specified by:
encodein interfaceTerminalImage- Returns:
- the escape sequence that will display the image
-
getProtocol
Description copied from interface:TerminalImageGet the protocol used by this image.- Specified by:
getProtocolin interfaceTerminalImage- Returns:
- the image protocol
-
getWidthCells
public int getWidthCells()Description copied from interface:TerminalImageGet the display width in terminal cells. Returns -1 if width is auto-detected or not specified.- Specified by:
getWidthCellsin interfaceTerminalImage- Returns:
- width in cells, or -1 for auto
-
getHeightCells
public int getHeightCells()Description copied from interface:TerminalImageGet the display height in terminal cells. Returns -1 if height is auto-detected or not specified.- Specified by:
getHeightCellsin interfaceTerminalImage- Returns:
- height in cells, or -1 for auto
-