jart / hiptext

Turn images into text better than caca/aalib
Apache License 2.0
763 stars 44 forks source link

Issue #16 Sixel support #17

Closed saitoha closed 10 years ago

saitoha commented 10 years ago

This PR is a quick implementation of SIXEL graphics(Issue #16).

It introduces the following new options.

-sixel2 : emit monochrome sixel
-sixel16 : emit 16-color sixel
-sixel256 : emit 256-color sixel

Note that we can get more beautiful picture using palette re-definition sequence If this software can do dynamic-palette quantization method(such as median-cut), but I didn't know how to do it.

DEMO

I tested this patch on above 4 terminals.

rrthomas commented 10 years ago

When I try to build this with g++ 4.8.1, I get:

sixelprinter.cc:67:26: error: expected primary-expression before ‘<<’ token
   if (sixel_offset_ != ! << 5) {
                      ^
make: *** [sixelprinter.o] Error 1
make: *** Waiting for unfinished jobs....

I guess that should be 1 << 5 not ! << 5

With that change, it sort of works: when I install mlterm 3.2.0 in Ubuntu, I get it black-on-white by default, and the colors are all wrong (with -sixel256 it's all black, with -sixel16, it's somewhat colored, but not correctly). If I use -bg white -fg black to mlterm, I get the same result.

With xterm 297, from Ubuntu trusty, the program simply hangs: it's not taking any CPU time, but it produces no output. (Yes, I remembered the command-line option and the extra printf command!)

saitoha commented 10 years ago

@rrthomas Thanks for your review, and sorry for bothering you with that typo.

Above DEMO is played on mlterm 3.3.1 and xterm patch level 301.

Did you play it on GNU Screen or tmux? It may hangs on terminal multiplexers. Otherwise, xterm on Ubuntu may be not compiled with --enable-sixel option. At least It's enabled on xterm package (301-1) on my Debian(jessie).

Now I reproduced the mlterm color problem on 3.2.0 and 3.3.3. I have reported this problem to mlterm maintainer and try to avoid it.

rrthomas commented 10 years ago

I'm quite happy with the feature, but it's a good idea to give minimum versions of each terminal emulator on which it's known to work (though it seems that at least mlterm managed to break it between 3.2.0 and 3.3.3). Sixel support is enabled in my xterm 297, I checked the configure command line supplied by the Ubuntu package. I don't know why it didn't seem to work, maybe there are bugs fixed or features added by the time of version 301. I wasn't using Screen or tmux.

By the way, it's not me who will accept the pull request, it's @jart; I've alerted her to it, but it may take a little while.

saitoha commented 10 years ago

@rrthomas Thanks for your advice. I'll check the minimum supported version of each terminals. Then mlterm developer arakiken pointed out palette operation bugs. I fixed it.

I have set up an Ubuntu Trusty environment and tested it on xterm 297. I got the following screenshot. 2014-02-26 20 36 09

On mlterm, now -sixel256 (with -bgprint option) option works well but -sixel16 is not well. Because hiptext does fixed palette based color approximation. We can improve this in future. 2014-02-26 22 29 39

jart commented 10 years ago

Thank you for writing this! Sorry for the slow merge.