Skip to content

Latest commit

History

1,448 Commits

Folders and files

NameName
Last commit message
Last commit date

libsixel

Build StatusCoverage Status

What is this?

This package provides encoder/decoder implementation for DEC SIXEL graphics, and some converter programs.

img2sixel

SIXEL is one of image formats for printer and terminal imaging introduced by Digital Equipment Corp. (DEC). Its data scheme is represented as a terminal-friendly escape sequence. So if you want to view a SIXEL image file, all you have to do is "cat" it to your terminal.

SIXEL Animation

img2sixel(1) can decode GIF animation.

Animation

Related projects

Video streaming

Now Youtube video streaming is available over SIXEL protocol by FFmpeg-SIXEL project.

FFmpeg-SIXEL

SDL integration: Gaming, Virtualization, ...etc.

SDL1.2-SIXEL project makes enable you to operate various GUI applications on the terminal.

You can play "The Battle for Wesnoth" over SIXEL protocol.

SDL1.2-SIXEL WESNOTH

You can run QEMU on SIXEL terminals.

SDL1.2-SIXEL QEMU

SDL1.2-SIXEL can collaborate with XSDL-SIXEL.

SDL1.2-SIXEL XSDL

X11 on SIXEL terminals

XSIXEL is a kdrive server implementation for SIXEL terminals.

XSIXEL

W3M integration

img2sixel(1) can be integrated with Arakiken's w3m fork(remoteimg branch).

w3m-sixel

@uobikiemukot's sdump project selected another approach. He wrote a w3mimgdisplay compatible program yaimg-sixel. It also works with ranger.

w3m-yaimg-sixel

GNU Screen integration

Arakiken's GNU Screen fork(sixel branch) works with SIXEL-supported applications including above products. This project is now in progress. GUI flavored SIXEL applications will integrated with existing terminal applications on it.

w3m-sixel-screen

sixel-screen

xsixel-screen

See also on youtube.

Twitter client integration

Some NetBSD/OpenBSD users are doing amazing challenges.

Now mikutter + mikutterm works with libsixel inline-image extension.

SIXEL works with old powerless machines such as

NetBSD/luna68k (here is OMRON LUNA-II):

mikutterm-netbsd-luna68k

NetBSD/hp300 (here is HP9000/425e):

mikutterm-netbsd-hp9000

arakiken's tw(tw-sixel) works with libsixel inline-image extension.

SIXEL works with old powerless machines such as OpenBSD/luna88k (here is OMRON LUNA-88K2 MC88100@33MHz):

mikutterm-netbsd-hp9000

sayaka-chan works with libsixel inline-image extension.

SIXEL works with old powerless machines such as NetBSD/x68k (here is SHARP X68030 with 060turbo):

sayaka-chan

SIXEL works even in-kernel console. @isaki68k wrote a patch for ite(4).

ite(4)

Highlighted features

Improved compression

Former sixel encoders(such as ppmtosixel) are mainly designed for dot-matrix printers. They minimize the amount of printer-head movement distance. But nowadays this method did not represent the best performance for displaying sixel data on terminal emulators. SIXEL data for terminals were found in 80's Usenet, but the technology of how to create them seems to be lost. kmiya's sixel introduces the encoding method which is re-designed for terminal emulators to optimize the overhead of transporting SIXEL with keeping compatibility with former SIXEL terminal. Now libsixel and ImageMagick's sixel coder follow it.

High quality quantization

img2sixel(1) supports color image quantization. It works well even if few number of colors are allowed.

  • ppmtosixel (netpbm)

    $ jpegtopnm images/snake.jpg | pnmquant 16 | ppmtosixel

    ppmtosixel

  • ppmtosixel with Floyd–Steinberg dithering (netpbm)

    $ jpegtopnm images/snake.jpg | pnmquant 16 -floyd | ppmtosixel

    ppmtosixel

  • kmiya's sixel

    $ sixel -p16 images/snake.jpg

    kmiya's sixel

  • PySixel (sixelconv command)

    $ sixelconv -n16 images/snake.jpg

    PySixel

  • libsixel (img2sixel command)

    $ img2sixel -p16 images/snake.jpg

    PySixel

Terminal requirements

If you want to view a SIXEL image, you have to get a terminal which support sixel graphics.

Now SIXEL feature is supported by the following terminals.

Packages

Build and install

Linux, OSX, cygwin

$ ./configure
$ make
# make install

Cross compile with MinGW

$ CC=i686-w64-mingw32-gcc cross_compile=yes ./configure --host=i686-w64-mingw32
$ make

Configure options

Build with optional packages

--with-libcurl build with libcurl (default: auto)
--with-gd build with libgd (default: no)
--with-gdk-pixbuf2 build with gdk-pixbuf2 (default: no)
--with-jpeg build with libjpeg (default: auto)
--with-png build with libpng (default: auto)
--with-pkgconfigdir specify pkgconfig dir (default is libdir/pkgconfig)
--with-bashcompletiondir specify bashcompletion.d
--with-zshcompletiondir specify zshcompletion.d

Usage of command line tools

img2sixel

Usage: img2sixel [Options] imagefiles
img2sixel [Options] < imagefile
Options:
-7, --7bit-mode generate a sixel image for 7bit
terminals or printers (default)
-8, --8bit-mode generate a sixel image for 8bit
terminals or printers
-p COLORS, --colors=COLORS specify number of colors to reduce
the image to (default=256)
-m FILE, --mapfile=FILE transform image colors to match this
set of colorsspecify map
-e, --monochrome output monochrome sixel image
this option assumes the terminal
background color is black
-i, --invert assume the terminal background color
is white, make sense only when -e
option is given
-u, --use-macro use DECDMAC and DEVINVM sequences to
optimize GIF animation rendering
-n, --macro-number specify an number argument for
DECDMAC and make terminal memorize
SIXEL image. No image is shown if this
option is specified
-C COMPLEXIONSCORE, --complexion-score=COMPLEXIONSCORE
specify an number argument for the
score of complexion correction.
COMPLEXIONSCORE must be 1 or more.
-g, --ignore-delay render GIF animation without delay
-S, --static render animated GIF as a static image
-d DIFFUSIONTYPE, --diffusion=DIFFUSIONTYPE
choose diffusion method which used
with -p option (color reduction)
DIFFUSIONTYPE is one of them:
auto -> choose diffusion type
automatically (default)
none -> do not diffuse
fs -> Floyd-Steinberg method
atkinson -> Bill Atkinson's method
jajuni -> Jarvis, Judice & Ninke
stucki -> Stucki's method
burkes -> Burkes' method
-f FINDTYPE, --find-largest=FINDTYPE
choose method for finding the largest
dimension of median cut boxes for
splitting, make sense only when -p
option (color reduction) is
specified
FINDTYPE is one of them:
auto -> choose finding method
automatically (default)
norm -> simply comparing the
range in RGB space
lum -> transforming into
luminosities before the
comparison
-s SELECTTYPE, --select-color=SELECTTYPE
choose the method for selecting
representative color from each
median-cut box, make sense only
when -p option (color reduction) is
specified
SELECTTYPE is one of them:
auto -> choose selecting
method automatically
(default)
center -> choose the center of
the box
average -> calculate the color
average into the box
histogram -> similar with average
but considers color
histogram
-c REGION, --crop=REGION crop source image to fit the
specified geometry. REGION should
be formatted as '%dx%d+%d+%d'
-w WIDTH, --width=WIDTH resize image to specified width
WIDTH is represented by the
following syntax
auto -> preserving aspect
ratio (default)
<number>% -> scale width with
given percentage
<number> -> scale width with
pixel counts
<number>px -> scale width with
pixel counts
-h HEIGHT, --height=HEIGHT resize image to specified height
HEIGHT is represented by the
following syntax
auto -> preserving aspect
ratio (default)
<number>% -> scale height with
given percentage
<number> -> scale height with
pixel counts
<number>px -> scale height with
pixel counts
-r RESAMPLINGTYPE, --resampling=RESAMPLINGTYPE
choose resampling filter used
with -w or -h option (scaling)
RESAMPLINGTYPE is one of them:
nearest -> Nearest-Neighbor
method
gaussian -> Gaussian filter
hanning -> Hanning filter
hamming -> Hamming filter
bilinear -> Bilinear filter
(default)
welsh -> Welsh filter
bicubic -> Bicubic filter
lanczos2 -> Lanczos-2 filter
lanczos3 -> Lanczos-3 filter
lanczos4 -> Lanczos-4 filter
-q QUALITYMODE, --quality=QUALITYMODE
select quality of color
quanlization.
auto -> decide quality mode
automatically (default)
high -> high quality and low
speed mode
low -> low quality and high
speed mode
-l LOOPMODE, --loop-control=LOOPMODE
select loop control mode for GIF
animation.
auto -> honor the setting of
GIF header (default)
force -> always enable loop
disable -> always disable loop
-t PALETTETYPE, --palette-type=PALETTETYPE
select palette color space type
auto -> choose palette type
automatically (default)
hls -> use HLS color space
rgb -> use RGB color space
-P --penetrate penetrate GNU Screen using DCS
pass-through sequence
-v, --verbose show debugging info
-V, --version show version and license info
-H, --help show this help

Convert a jpeg image file into a sixel file

$ img2sixel < images/egret.jpg > egret.sixel

Reduce colors to 16:

$ img2sixel -p 16 < images/egret.jpg > egret.sixel

Reduce colors with fixed palette:

$ img2sixel -m images/map16.png < images/egret.jpg > egret.sixel

sixel2png

Usage: sixel2png -i input.sixel -o output.png
sixel2png < input.sixel > output.png
Options:
-i, --input specify input file
-o, --output specify output file
-V, --version show version and license information
-H, --help show this help

Convert a sixel file into a png image file

$ sixel2png < egret.sixel > egret.png

Usage of conversion API 1.0

The Whole API is described here.

Example

If you use OSX, a tiny example is available here.

opengl example

Bitmap to SIXEL

sixel_encode function converts bitmap array into SIXEL format.

/* converter API *//* convert pixels into sixel format and write it to output context */intsixel_encode(unsigned char/* in */*pixels, /* pixel bytes */int/* in */width, /* image width */int/* in */height, /* image height */int/* in */depth, /* pixel depth: now only 3 is supported */sixel_dither_t/* in */*dither, /* dither context */sixel_output_t/* in */*context); /* output context */

To use this function, you have to initialize two objects,

  • sixel_dither_t (dithering context object)
  • sixel_output_t (output context object)

Dithering context

Here is a part of APIs for dithering context manipulation.

/* create dither context object: reference counter is set to 1 */sixel_dither_t*sixel_dither_create(int/* in */ncolors); /* number of colors *//* increment reference count of dither context object (thread-unsafe) */voidsixel_dither_ref(sixel_dither_t*dither); /* dither context object *//* decrement reference count of dither context object (thread-unsafe) */voidsixel_dither_unref(sixel_dither_t*dither); /* dither context object *//* initialize internal palette from specified pixel buffer */intsixel_dither_initialize(
sixel_dither_t*dither, /* dither context object */unsigned char/* in */*data, /* sample image */int/* in */width, /* image width */int/* in */height, /* image height */int/* in */depth, /* pixel depth, now only '3' is supported */int/* in */method_for_largest, /* set 0 or method for finding the largest dimension */int/* in */method_for_rep, /* set 0 or method for choosing a color from the box */int/* in */quality_mode/* set 0 or quality of histogram processing */
);

Output context

Here is a part of APIs for output context manipulation.

typedefint (*sixel_write_function)(char*data, intsize, void*priv);
/* create output context object */sixel_output_t*constsixel_output_create(
sixel_write_function/* in */fn_write, /* callback function for output sixel */void/* in */*priv/* private data given as); 3rd argument of fn_write *//* increment reference count of output context object (thread-unsafe) */voidsixel_output_ref(sixel_output_t/* in */*output); /* output context *//* decrement reference count of output context object (thread-unsafe) */voidsixel_output_unref(sixel_output_t/* in */*output); /* output context */

SIXEL to indexed bitmap

sixel_decode function converts SIXEL into indexed bitmap bytes with its palette.

/* malloc(3) compatible function */
typedef void * (* sixel_allocator_function)(size_t size);
/* convert sixel data into indexed pixel bytes and palette data */
int
sixel_decode(unsigned char /* in */ *sixels, /* sixel bytes */
int /* in */ size, /* size of sixel bytes */
unsigned char /* out */ **pixels, /* decoded pixels */
int /* out */ *pwidth, /* image width */
int /* out */ *pheight, /* image height */
unsigned char /* out */ **palette, /* RGBA palette */
int /* out */ *ncolors, /* palette size (<= 256) */
sixel_allocator_function /* out */ allocator); /* malloc function */

Support

This software is provided "as is" without express or implied warranty. The main support channel for this software is the github issue tracker:

https://github.com/saitoha/libsixel/issues

Please post your issue if you have any problems, questions or suggestions.

License

The MIT License (MIT)

Copyright (c) 2014 Hayaki Saito

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contributers and Reviewers

  • @arakiken
  • @elfring
  • @isaki68k
  • @knok
  • @mattn
  • @tsutsui
  • @ttdoda
  • @uobikiemukot
  • @waywardmonkeys
  • @yoshikaw

Acknowledgment

This software derives from the following implementations.

sixel 2014-3-2

src/tosixel.c, src/fromsixel.c, and some part of converters/loader.c are derived from kmiya's "sixel" original version (2014-3-2)

Package: http://nanno.dip.jp/softlib/man/rlogin/sixel.tar.gz

Unofficial repo: https://github.com/saitoha/sixel

This work is written by kmiya@ culti. He distributes it under very permissive license.

The original license text(in Japanese only) is:

このプログラム及びソースコードの使用について個人・商用を問わず
ご自由に使用していただいで結構です。
また、配布・転載・紹介もご連絡の必要もありません。
ソースの改変による配布も自由ですが、どのバージョンの改変かを
明記されることを希望します。
バージョン情報が無い場合は、配布物の年月日を明記されることを
希望します。
2014/10/05 kmiya

The unofficial translation:

Anyone is free to use this program for any purpose,
commercial or non-commercial, without any restriction.
Anyone is free to distribute, copy, publish, or
advertise this software, without any contact.
Anyone is free to distribute with modification of the
source code, but I "hope" that its based version or
date will be written clearly.
2014/10/05 kmiya

kmiya also said this is compatible with MIT/BSD/GPL.

stbi-1.41

This software includes stbi-1.41 (stb_image.h), public domain JPEG/PNG reader.

https://github.com/nothings/stb

stbiw-0.92

This software includes stbiw-0.94 (stb_image_write.h), public domain PNG/BMP/TGA writer.

https://github.com/nothings/stb

pnmquant.c (netpbm library)

The implementation of median cut algorithm for color quantization in quant.c is imported from pnmcolormap included in netpbm library.

http://netpbm.sourceforge.net/

pnmcolormap was derived from ppmquant, originally written by Jef Poskanzer.

Copyright (C) 1989, 1991 by Jef Poskanzer. Copyright (C) 2001 by Bryan Henderson.

Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. This software is provided "as is" without express or implied warranty.

loader.h (@uobikiemukot's sdump)

Some parts of converters/loader.c are imported from @uobikiemukot's sdump project

The MIT License (MIT)

Copyright (c) 2014 haru

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ax_gcc_var_attribute / ax_gcc_func_attribute

These are useful m4 macros for detecting some GCC attributes.

http://www.gnu.org/software/autoconf-archive/ax_gcc_var_attribute.htmlhttp://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html

Copyright (c) 2013 Gabriele Svelto gabriele.svelto@gmail.com

Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty.

graphics.c (from Xterm pl#310)

The helper function hls2rgb in src/fromsixel.c is imported from graphics.c in Xterm pl#310, originally written by Ross Combs.

Copyright 2013,2014 by Ross Combs

 All Rights Reserved

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name(s) of the above copyright holders shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization.

test images

The following test images in "image/" directory came from PUBLIC-DOMAIN-PHOTOS.com.

These are in the public domain.

vimperator3.png (mascot of vimperator)

images/vimperator3.png is in the public domain.

author: @k_wizard
url: http://quadrantem.com/~k_wizard/vimprtan/

References

ImageMagick

We are greatly inspired by the quality of ImageMagick and added some resampling filters to img2sixel in reference to the line-up of filters of MagickCore's resize.c.

http://www.imagemagick.org/api/MagickCore/resize_8c_source.html

Similar software

  • netpbm

    You can get SIXEL graphics using ppmtosixel or pbmtoln03.

  • kmiya's sixel

    libgd based SIXEL converter

  • PySixel

    Python implementation of SIXEL converter

  • ImageMagick

    Now SIXEL coder is available in svn trunk and V6 branch.

  • monosixel in arakiken's tw

    A monochrome SIXEL converter

  • xpr(x11-apps)

    xpr(1) can convert a xwd(X window dump) format image into a sixel image with '-device ln03' or '-device la100' option. But now it is not maintained. It looks broken.

Other software supporting SIXEL

About

A lightweight, fast implementation of DEC SIXEL graphics codec

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages