Class SixelImage

java.lang.Object
org.aesh.terminal.image.SixelImage
All Implemented Interfaces:
TerminalImage

public class SixelImage extends Object implements 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] ST
 
Where:
  • 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 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

      public static SixelImage fromFile(Path path) throws IOException
      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

      public static SixelImage fromBytes(byte[] data)
      Create a Sixel image from raw bytes.
      Parameters:
      data - the image data
      Returns:
      the terminal image
    • maxWidth

      public SixelImage maxWidth(int pixels)
      Set maximum width in pixels. Image will be scaled if larger.
      Parameters:
      pixels - maximum width
      Returns:
      this image for chaining
    • maxHeight

      public SixelImage maxHeight(int pixels)
      Set maximum height in pixels. Image will be scaled if larger.
      Parameters:
      pixels - maximum height
      Returns:
      this image for chaining
    • maxColors

      public SixelImage maxColors(int colors)
      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

      public SixelImage useRle(boolean useRle)
      Enable or disable run-length encoding compression.
      Parameters:
      useRle - true to use RLE (default true)
      Returns:
      this image for chaining
    • encode

      public String encode()
      Description copied from interface: TerminalImage
      Encode the image as an escape sequence string ready to be written to the terminal.
      Specified by:
      encode in interface TerminalImage
      Returns:
      the escape sequence that will display the image
    • getProtocol

      public ImageProtocol getProtocol()
      Description copied from interface: TerminalImage
      Get the protocol used by this image.
      Specified by:
      getProtocol in interface TerminalImage
      Returns:
      the image protocol
    • getWidthCells

      public int getWidthCells()
      Description copied from interface: TerminalImage
      Get the display width in terminal cells. Returns -1 if width is auto-detected or not specified.
      Specified by:
      getWidthCells in interface TerminalImage
      Returns:
      width in cells, or -1 for auto
    • getHeightCells

      public int getHeightCells()
      Description copied from interface: TerminalImage
      Get the display height in terminal cells. Returns -1 if height is auto-detected or not specified.
      Specified by:
      getHeightCells in interface TerminalImage
      Returns:
      height in cells, or -1 for auto