View Single Post
Old 07-20-2024, 06:23 PM   #19
elinkser
Addict
elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.
 
Posts: 242
Karma: 146236
Join Date: Oct 2022
Device: Kobo Clara HD
YAFT - Yet Another Framebuffer Terminal - with SIXEL* image support

***

YAFT - Yet Another Framebuffer Terminal - with SIXEL* image support

*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.
https://saitoha.github.io/libsixel/

You need to have a terminal that supports SIXEL, e.g. xterm if invoked as:
$ xterm -ti vt340

$ img2sixel logo.gif
$ img2sixel tux.png
$ img2sixel tux.png -o tux.six
$ cat tux.six
$ w3m -sixel mywgets/index.html

***

uobikiemukot/yaft
https://github.com/uobikiemukot/yaft

$ wget https://github.com/uobikiemukot/yaft.../v0.2.9.tar.gz

$ mv v0.2.9.tar.gz yaft-v0.2.9.tar.gz

$ tar zxvf yaft-v0.2.9.tar.gz

$ cd yaft-0.2.9/


$ nano -l conf.h
Code:
...
 4 /* color: index number of color_palette[] (see color.h) */
 5 enum {
 6         DEFAULT_FG           = 0,
 7         DEFAULT_BG           = 255,
 8         ACTIVE_CURSOR_COLOR  = 2,
 9         PASSIVE_CURSOR_COLOR = 1,
10 };
...
41 /* shell: refer SHELL environment variable at first */
42 #if defined(__linux__) || defined(__MACH__)
43         const char *shell_cmd = "/bin/sh";
...

Use a bigger font than the default:

cambus/spleen
https://github.com/fcambus/spleen

$ wget https://github.com/fcambus/spleen/re...n-2.1.0.tar.gz

$ tar zxvf spleen-2.1.0.tar.gz

$ cp ../spleen-2.1.0/spleen-32x64.bdf fonts/
$ cp ../spleen-2.1.0/spleen-16x32.bdf fonts/
$ cp ../spleen-2.1.0/spleen-12x24.bdf fonts/


$ nano -l makefile
Code:
 1 CC1 ?= arm-kobo-linux-gnueabihf-gcc
 2 CC2 ?= gcc
...
25 mkfont_bdf: tools/mkfont_bdf.c tools/mkfont_bdf.h tools/bdf.h tools/util.h
26         $(CC2) -o $@ $< $(CFLAGS) $(LDFLAGS)
...
34         # ./mkfont_bdf table/alias fonts/milkjf_k16.bdf fonts/milkjf_8x16r.bdf fonts/milkjf_8x16.bdf > glyph.h
35         ./mkfont_bdf table/alias fonts/spleen-16x32.bdf > glyph.h
36
37 yaft: yaft.c $(HDR)
38         # If you want to change configuration, please modify conf.h before make (see conf.h for more detail)
39         $(CC1) -o $@ $< $(CFLAGS) $(LDFLAGS)
...
$ make mkfont_bdf
gcc -o mkfont_bdf tools/mkfont_bdf.c -std=c99 -pedantic -Wall -Wextra -O3 -s -pipe

$ rm glyph.h

$ make glyph.h

$ cd ..


***

Resize the bdf font:

ntwk/bdfresize
https://github.com/ntwk/bdfresize

$ wget http://openlab.ring.gr.jp/efont/dist...ize-1.5.tar.gz

$ tar zxvf bdfresize-1.5.tar.gz

$ cd bdfresize-1.5/

$ ./configure

$ nano -l charresize.c
Code:
...
 49   void  *malloc();
...
$ make

$ cp ../spleen-2.1.0/spleen-32x64.bdf .

$ ./bdfresize -f 17/32 spleen-32x64.bdf >spleen-17x34.bdf

$ cd ..

$ cd yaft-0.2.9/

Save copy of yaft made with smaller spleen-16x32.bdf font:
$ mv yaft yaftS

$ cp ../bdfresize-1.5/spleen-17x34.bdf fonts/

$ nano -l makefile
Code:
...
34         # ./mkfont_bdf table/alias fonts/milkjf_k16.bdf fonts/milkjf_8x16r.bdf fonts/milkjf_8x16.bdf > glyph.h
35         ./mkfont_bdf table/alias fonts/spleen-17x34.bdf > glyph.h
...

$ rm glyph.h

$ make glyph.h

$ cd ..



***

Prepare build system as was done in Post #4 above:

$ source ~/koxtoolchain/refs/x-compile.sh kobo env bare

***

Make shared version of FBInk as in Post #4 above:

NiLuJe/FBInk
https://github.com/NiLuJe/FBInk/releases

$ wget https://github.com/NiLuJe/FBInk/rele...v1.25.0.tar.xz

$ tar xJf FBInk-v1.25.0.tar.xz

$ cd FBInk-v1.25.0/

$ make static stripped

$ cd ..

***


$ cd yaft-0.2.9/

$ mkdir fb/FBInk

$ cp -r ../FBInk-v1.25.0/Release fb/FBInk/

$ cp ../FBInk-v1.25.0/fbink.h fb/FBInk/


$ nano -l fb/common.h
Code:
...
 41
 42 #include "FBInk/fbink.h"
 43
 44 FBInkConfig fbink_cfg = {0};
 45
 46 FBInkConfig* cfg(){
 47         return &fbink_cfg;
 48 }
 49
...
303         /* open framebuffer device: check FRAMEBUFFER env at first */
304         path = ((env = getenv("FRAMEBUFFER")) == NULL) ? fb_path: env;
305 /*      if ((fb->fd = eopen(path, O_RDWR)) < 0) */
306         fb->fd = fbink_open();
307         if (fb->fd < 0)
308                 return false;
...
488         fbink_refresh( fb->fd,
489                 0,
490                 0,
491                 fb->info.width,
492                 fb->info.height,
493                 cfg() );
494 }
...

$ nano -l terminal.h
Code:
...
340         term->cols  = term->width / CELL_WIDTH;
341         term->lines = term->height / CELL_HEIGHT;
342         int percentDisplay;     /* percent of display used */
343         if (getenv("YAFT_PERCENT") != NULL) {
344                 printf("YAFT_PERCENT = %s\n", getenv("YAFT_PERCENT"));
345                 percentDisplay = atoi(getenv("YAFT_PERCENT"));
346                 if (percentDisplay < 1 || percentDisplay > 99) {
347                         percentDisplay = 100;
348                 }
349         } else {
350                 percentDisplay = 100;
351         }
352         term->lines = term->lines * percentDisplay / 100;
...

$ rm yaft

$ LDFLAGS=" -Lfb/FBInk/Release/ -lfbink " make yaft


$ cd ..


***


Now, copy the yaft and yaftS binaries to the /mnt/onboard/.adds/kordir/scripts/ folder on the Kobo.

From an SSH session to the Kobo:
# . /korenv.sh
# YAFT_PERCENT=58 yaft
YAFT_PERCENT = 58
>>WARN<< ioctl: VT_SETMODE failed (maybe here is not console)
>>WARN<< ioctl: KDSETMODE failed (maybe here is not console)

# lsof | grep yaft

# . /korenv.sh

# OSK_TTY=/dev/pts/0 oskansi2 &

# pkill yaft


Or, update our NickelMenu and fbmenu scripts (from POST #14 above):


# nano /mnt/onboard/.adds/nm/config.txt
Code:
...
menu_item :main    :YAFT_PERCENT=58    :cmd_spawn          :quiet :export HOME="/mnt/onboard/.adds/kordir/" && cd "$HOME" && export PATH="$PATH:/mnt/onboard/.adds/kordir/scripts" && export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/mnt/onboard/.adds/kordir/libs" && export YAFT_PERCENT=58 && yaft 0</dev/tty1
    chain_success                      :dbg_toast          :Started yaft
    chain_failure                      :dbg_toast          :Error starting yaft
...

# nano -l /mnt/onboard/.adds/kordir/scripts/fbmenu.sh
Code:
...
 18 if [ "$num" == "1" ]; then
 19                 qndb -m mwcToast 500 "You selected 1-Stop agetty+fbpad+yaft"
 20                 fbcmd="/usr/bin/pkill agetty"
 21                 qndb -m mwcToast 200 "$fbcmd"
 22                 fberr=$($fbcmd 2>&1)
 23                 fbcmd="/usr/bin/pkill fbpad"
 24                 qndb -m mwcToast 200 "$fbcmd"
 25                 fberr=$($fbcmd 2>&1)
 26                 fbcmd="/usr/bin/pkill fbkeyboard"
 27                 qndb -m mwcToast 200 "$fbcmd"
 28                 fberr=$($fbcmd 2>&1)
 29                 fbcmd="/usr/bin/pkill oskansi"
 30                 qndb -m mwcToast 200 "$fbcmd"
 31                 fberr=$($fbcmd 2>&1)
 32                 fbcmd="/usr/bin/pkill yaft"
 33                 qndb -m mwcToast 200 "$fbcmd"
 34                 fberr=$($fbcmd 2>&1)
 35 elif [ "$num" == "2" ]; then
 36                 qndb -m mwcToast 1000 "You selected 2-yaft"
 37                 export HOME="/mnt/onboard/.adds/kordir/"
 38                 cd "$HOME"
 39                 export LD_LIBRARY_PATH="/mnt/onboard/.adds/kordir/libs/:$LD_LIBRARY_PATH"
 40                 fbcmd="/mnt/onboard/.adds/kordir/scripts/fbkeyboard2"
 41                 qndb -m mwcToast 1000 "$fbcmd"
 42                 fberr=$($fbcmd 2>&1) &
 43                 fbcmd="eval YAFT_PERCENT=58 /mnt/onboard/.adds/kordir/scripts/yaft 0</dev/tty1"
 44                 qndb -m mwcToast 1000 "$fbcmd"
 45                 fberr=$($fbcmd 2>&1)
...


***
UNFORTUNATELY, YOU MAY NEED TO KILL AGETTY (E.G VIA FBMENU) TO GET YAFT TO WORK WITH FBKEYBOARD/OSKANSI KEYBOARDS, AT LEAST ON MY CLARA HD.
*** EDIT - and maybe even USB networking/dropbox too, to get YAFT to start!
ALSO, AS WITH FBPAD, YOU MAY NEED WIFI ON, THOUGH NO ACCESS POINT CONNECTION NEEDED.)
***




***

YAFT supports sixel images:


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

$ wget https://github.com/saitoha/libsixel/.../v1.8.6.tar.gz

$ mv v1.8.6.tar.gz libsixel-v1.8.6.tar.gz

$ tar zxvf libsixel-v1.8.6.tar.gz

$ cd libsixel-1.8.6/

$ ./configure --help

$ ./configure --host=arm-kobo-linux-gnueabihf --disable-python

$ make


$ cp converters/.libs/img2sixel .

$ cp converters/.libs/sixel2png .

$ cp src/.libs/libsixel.so.1.0.6 libsixel.so.1


***

Copy the img2sixel and sixel2png binaries to the /mnt/onboard/.adds/kordir/scripts/ folder of your kobo.


Copy the libsixel.so.1 lib to the /mnt/onboard/.adds/kordir/libs/ folder of your kobo.


Displaying images in YAFT with sixel:

# . /korenv.sh

# img2sixel tux.png


Unfortunately, the img2sixel gives error with Alpine Linux w3m binary:

w3m -sixel -o display_image=1 mywgets/index.html


We will attempt to mod the w3m source to fix sixel support.

***


Building w3m in chroot* partition to fix sixel image support:

*See POST #8 for chroot reference.


On kobo, switch to chroot:

# chalpine.sh

On kobo chroot:

(as root)
***
# apk add gc-dev
(1/2) Installing libgc++ (8.2.2-r2)
(2/2) Installing gc-dev (8.2.2-r2)
OK: 1029 MiB in 528 packages

# apk add ncurses-dev
(1/4) Installing libformw (6.4_p20230506-r0)
(2/4) Installing libmenuw (6.4_p20230506-r0)
(3/4) Installing libncurses++ (6.4_p20230506-r0)
(4/4) Installing ncurses-dev (6.4_p20230506-r0)
Executing busybox-1.36.0-r9.trigger
OK: 1030 MiB in 536 packages

# apk add libpng-dev
OK: 1030 MiB in 532 packages

# apk add libjpeg-turbo-dev
(1/1) Installing libjpeg-turbo-dev (2.1.5.1-r3)
OK: 1030 MiB in 533 packages

# apk add giflib-dev
(1/2) Upgrading giflib (5.2.1-r4 -> 5.2.2-r0)
(2/2) Installing giflib-dev (5.2.2-r0)
OK: 1030 MiB in 534 packages

# apk add imlib2-dev
(1/4) Installing libice-dev (1.1.1-r2)
(2/4) Installing util-linux-dev (2.38.1-r8)
(3/4) Installing libsm-dev (1.2.4-r1)
(4/4) Installing imlib2-dev (1.11.1-r0)
OK: 1033 MiB in 538 packages

# apk add gdb
(1/1) Installing gdb (13.1-r9)
OK: 1043 MiB in 541 packages


# su myuser

$ cd

$ mv master.zip w3m-master.zip

$ unzip w3m-master.zip

$ cd w3m-master/


$ ./configure CFLAGS=" -g " --enable-image=fb --disable-mouse --with-imagelib=imlib2


* While we are messing with w3m source code to support sixel, we may as well remove symlink requirement to allow images even in vfat /mnt/onboard (user) partition, but of course it is not as secure to run as root.


$ nano -l config.h
Code:
...
139 #undef HAVE_SYMLINK
...

Fix execvp quirk that interfered with img2sixel argument parsing (* updated to use snprintf and restore integer length to 11 as in original w3m code *):

$ nano -l terms.c
Code:
...
 789     if ((pid = fork()) == 0) {
 790         char *env;
 791         int n = 0;
 792         char *argv[20];
 793 /*      char digit[2][11+1]; */
 794         char clip1[15+7+1], clip2[3+11+1], clip3[3+11+1], clip4[3+3+44+1], clip5[12+1];
 795         Str str_url;
 796
 797         close(STDERR_FILENO);   /* Don't output error message. */
...
 821         else {
 822                 argv[n++] = "/mnt/onboard/.adds/kordir/scripts/img2sixel";
 823         }
 824 /*      argv[n++] = "-l";
 825         argv[n++] = do_anim ? "auto" : "disable";
 826         argv[n++] = "-w";
 827         sprintf(digit[0], "%d", w);
 828         argv[n++] = digit[0];
 829         argv[n++] = "-h";
 830         sprintf(digit[1], "%d", h);
 831         argv[n++] = digit[1];
 832         argv[n++] = "-c"; */
 833         snprintf(clip1, sizeof(clip1) - 1, "--loop-control=auto");
 834         argv[n++] = clip1;
 835         snprintf(clip2, sizeof(clip2) - 1, "-w %d", w);
 836         argv[n++] = clip2;
 837         snprintf(clip3, sizeof(clip3) - 1, "-h %d", h);
 838         argv[n++] = clip3;
 839         snprintf(clip4, sizeof(clip4) - 1, "-c %dx%d+%d+%d", sw, sh, sx, sy);
 840         argv[n++] = clip4;
 841         argv[n++] = url;
 842         if (getenv("TERM") && strcmp(getenv("TERM"), "screen") == 0 &&
 843             (!getenv("SCREEN_VARIANT") || strcmp(getenv("SCREEN_VARIANT"), "sixel") != 0)) {
 844 /*          argv[n++] = "-P"; */
 845                 snprintf(clip5, sizeof(clip5) - 1, "--penetrate");
 846                 argv[n++] = clip5;
 847         }
 848         argv[n++] = NULL;
 849         execvp(argv[0],argv);
 850         exit(0);
 851     }
...

$ HAVE_SYMLINK="" make

$ mv w3m w3msxl

Copy the w3msxl binary to the /mnt/onboard/.adds/kordir/scripts/ folder of your kobo.



# YAFT_PERCENT=58 yaft

# . /korenv.sh

# TERM=linux w3msxl -sixel -o display_image=1 mywgets/index.html

... and we have sixel image support in w3m in the /mnt/onboard partition (but pls recall security notice in POST #1).

(note that "w3msxl mywgets/index.html" would still work but default to w3imgfbink framebuffer viewer if you had set that up previously, except now can run as root in /mnt/onboard.)


*TO ACTIVATE BOOKMARKS:

# cd /usr/local/libexec/

# ln -s /mnt/onboard/.adds/kordir/usr/lib/w3m w3m


***
***
***
Attached Files
File Type: zip w3msixel.zip (1.63 MB, 408 views)

Last edited by elinkser; 10-28-2024 at 06:57 PM. Reason: cleaned up terms.c&w3msxl,need USB netorking for YAFT?
elinkser is offline   Reply With Quote