Package jexer.backend

Class HQSixelEncoder

  • All Implemented Interfaces:
    SixelEncoder

    public class HQSixelEncoder
    extends java.lang.Object
    implements SixelEncoder
    HQSixelEncoder turns a BufferedImage into String of sixel image data, using several strategies to produce a reasonably high quality image within sixel's ~19.97 bit (101^3) color depth.

    Portions of this encoder were inspired / influenced by Hans Petter Jansson's chafa project: https://hpjansson.org/chafa/ . Please refer to chafa's high-performance sixel encoder for far more advanced implementations of principal component analysis color mapping, and sixel row encoding.

    • Constructor Summary

      Constructors 
      Constructor Description
      HQSixelEncoder()
      Public constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearPalette()
      Clear the sixel palette.
      void emitPalette​(java.lang.StringBuilder sb)
      If the palette is shared for the entire terminal, emit it to a StringBuilder.
      int getPaletteSize()
      Get the number of colors in the sixel palette.
      boolean hasSharedPalette()
      Get the sixel shared palette option.
      static void main​(java.lang.String[] args)
      Convert all filenames to sixel.
      void reloadOptions()
      Reload options from System properties.
      void setPaletteSize​(int paletteSize)
      Set the number of colors in the sixel palette.
      void setSharedPalette​(boolean sharedPalette)
      Set the sixel shared palette option.
      java.lang.String toSixel​(java.awt.image.BufferedImage bitmap)
      Create a sixel string representing a bitmap.
      java.lang.String toSixel​(java.awt.image.BufferedImage bitmap, boolean allowTransparent)
      Create a sixel string representing a bitmap.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HQSixelEncoder

        public HQSixelEncoder()
        Public constructor.
    • Method Detail

      • reloadOptions

        public void reloadOptions()
        Reload options from System properties.
        Specified by:
        reloadOptions in interface SixelEncoder
      • toSixel

        public java.lang.String toSixel​(java.awt.image.BufferedImage bitmap)
        Create a sixel string representing a bitmap. The returned string does NOT include the DCS start or ST end sequences.
        Specified by:
        toSixel in interface SixelEncoder
        Parameters:
        bitmap - the bitmap data
        Returns:
        the string to emit to an ANSI / ECMA-style terminal
      • toSixel

        public java.lang.String toSixel​(java.awt.image.BufferedImage bitmap,
                                        boolean allowTransparent)
        Create a sixel string representing a bitmap. The returned string does NOT include the DCS start or ST end sequences.
        Parameters:
        bitmap - the bitmap data
        allowTransparent - if true, allow transparent pixels to be specified
        Returns:
        the string to emit to an ANSI / ECMA-style terminal
      • emitPalette

        public void emitPalette​(java.lang.StringBuilder sb)
        If the palette is shared for the entire terminal, emit it to a StringBuilder.
        Specified by:
        emitPalette in interface SixelEncoder
        Parameters:
        sb - the StringBuilder to write the shared palette to
      • hasSharedPalette

        public boolean hasSharedPalette()
        Get the sixel shared palette option.
        Specified by:
        hasSharedPalette in interface SixelEncoder
        Returns:
        true if all sixel output is using the same palette that is set in one DCS sequence and used in later sequences
      • setSharedPalette

        public void setSharedPalette​(boolean sharedPalette)
        Set the sixel shared palette option.
        Specified by:
        setSharedPalette in interface SixelEncoder
        Parameters:
        sharedPalette - if true, then all sixel output will use the same palette that is set in one DCS sequence and used in later sequences
      • getPaletteSize

        public int getPaletteSize()
        Get the number of colors in the sixel palette.
        Specified by:
        getPaletteSize in interface SixelEncoder
        Returns:
        the palette size
      • setPaletteSize

        public void setPaletteSize​(int paletteSize)
        Set the number of colors in the sixel palette.
        Specified by:
        setPaletteSize in interface SixelEncoder
        Parameters:
        paletteSize - the new palette size
      • clearPalette

        public void clearPalette()
        Clear the sixel palette. It will be regenerated on the next image encode.
        Specified by:
        clearPalette in interface SixelEncoder
      • main

        public static void main​(java.lang.String[] args)
        Convert all filenames to sixel.
        Parameters:
        args - [] the filenames to read