View Single Post
Old 09-18-2023, 05:18 PM   #8
elinkser
Groupie
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: 185
Karma: 146236
Join Date: Oct 2022
Device: Kobo Clara HD
ADD A CHESS GAME FOR THE TERMINAL

***ADD A CHESS GAME FOR THE TERMINAL***

Here's a chess app to stress test your fbpadkb, and have a little fun at the same time!



The gnuchess game has only the following dependencies:

Depends (3)
libgcc**
libintl
musl*

* Already got it from the Elinks/Nano install above (POST #3 - also got the /korenv.sh script.)
** Do not install libgcc since it would crash OCP-KOReader-v2023.06 when opening pdf files.
Fortunately, gnuchess runs fine without it!


RUN THESE COMMANDS FROM LINUX DESKTOP:

$ cd myalpine/

DOWNLOAD THE REQUIRED PACKAGES:

$ wget https://dl-cdn.alpinelinux.org/alpin...s-6.2.9-r1.apk

$ wget https://dl-cdn.alpinelinux.org/alpin...-0.21.1-r1.apk

$ tar zxvf gnuchess-6.2.9-r1.apk

$ tar zxvf libintl-0.21.1-r1.apk

$ mv usr/bin/gnuchess scripts/

$ mv usr/lib/libintl.so.8.3.0 libs/libintl.so.8


NOW CONNECT YOUR KOBO TO YOUR PC:

Copy your gnuchess binary from the scripts/ folder on the PC to the /mnt/onboard/.adds/koreader/scripts/ folder on the kobo.

Copy new lib from the libs/ folder on the PC to the /mnt/onboard/.adds/koreader/libs/ folder on the kobo:
libintl.so.8

Copy the usr/share/gnuchess folder on the PC to the /usr/share/ folder on the kobo:


PLAY CHESS FROM fbpadkb TERMINAL:

# . /korenv.sh

# gnuchess -e
GNU Chess 6.2.9
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
White (1) :


ENTER YOUR MOVE, E.G.:
White (1) : e2e4

1. e2e4

black KQkq e3

r n b q k b n r
p p p p p p p p
. . . . . . . .
. . . . . . . .
. . . . P . . .
. . . . . . . .
P P P P . P P P
R N B Q K B N R

Thinking...

white KQkq d6

r n b q k b n r
p p p . p p p p
. . . . . . . .
. . . p . . . .
. . . . P . . .
. . . . . . . .
P P P P . P P P
R N B Q K B N R


My move is : d5
White (2) :


ENTER YOUR NEXT MOVE, E.G.:
White (2) : e4d5

2. e4d5

black KQkq

r n b q k b n r
p p p . p p p p
. . . . . . . .
. . . P . . . .
. . . . . . . .
. . . . . . . .
P P P P . P P P
R N B Q K B N R

Thinking...

white KQkq

r n b q k b . r
p p p . p p p p
. . . . . n . .
. . . P . . . .
. . . . . . . .
. . . . . . . .
P P P P . P P P
R N B Q K B N R


My move is : Nf6


SAVE YOUR GAME AND QUIT:
White (3) : pgnsave game1.pgn
White (3) : quit
#


PLAY AGAIN:
# gnuchess -e
GNU Chess 6.2.9
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
White (1) :


LOAD YOUR GAME AND QUIT:
White (1) : pgnload game1.pgn

white KQkq

r n b q k b . r
p p p . p p p p
. . . . . n . .
. . . P . . . .
. . . . . . . .
. . . . . . . .
P P P P . P P P
R N B Q K B N R

White (1) : quit
#



With a little command-line labor you can install a GUI chess app in a graphical chroot, thanks to NiMa et al:
https://www.mobileread.com/forums/sh...d.php?t=336210

*Of course there is also Vlasovsoft's app which includes a fine GUI chess program.


Updated setup instructions starting from:
https://www.mobileread.com/forums/sh...4&postcount=53

Then just:
# apk add xboard
# xboard

TIPS FOR GETTING STARTED WITH GRAPHICAL CHROOT:

1) Start with the simpler non-graphical version of the chroot:
https://www.mobileread.com/forums/sh...d.php?t=336175

(You may find a script like the one in section 6 of this comment helpful.):
https://www.mobileread.com/forums/sh...1&postcount=46


***
CAUTION: You know how Nickel does all that background work when you connect USB cable to desktop, click "connect", then later unmount?

Well, there may be a risk of data corruption if you had a loop mounted file, e.g. Alpine chroot.
https://www.mobileread.com/forums/sh...38&postcount=2

So better don't try this. But if you DO connect a USB cable, either exit the chroot and unmount the loop first, OR click "cancel" and use SSH/Telnet networking instead. (I have done this for months.)
***




2) Try this site to get the tldr description of a Linux command e.g. the chroot command:
https://html.duckduckgo.com/html/?q=tldr+chroot

(You can change the "chroot" to some other command, e.g. "pkill"):
https://html.duckduckgo.com/html/?q=tldr+pkill






***ADD NETPBM IMAGE CONVERTER***

Netpbm's pnmscale and pnmtopng help with converting our phone camera images to rmkit's Harmony drawing app png layers.
Then you can draw with the photo as a background layer.
https://rmkit.dev/apps/harmony

You can also run the following script as a GUI app, using rmkit's Simple App Script interpreter:
https://www.mobileread.com/forums/sh...59&postcount=9

The netpbm package has the following dependencies:

Depends (6)
libjpeg-turbo**
libpng
libx11***
musl*
tiff***
zlib**

* Already got it from the Elinks/Nano install above (POST #3 - also got the /korenv.sh script.)
** Already have equivalents from base KOReader install.
*** Don't need tiff or libx11 for our commands


RUN THESE COMMANDS FROM LINUX DESKTOP:

$ cd myalpine/

DOWNLOAD THE REQUIRED PACKAGES:

$ wget https://dl-cdn.alpinelinux.org/alpin...0.73.41-r1.apk

$ wget https://dl-cdn.alpinelinux.org/alpin...-1.6.39-r0.apk

$ tar zxvf netpbm-10.73.41-r1.apk

$ mv usr/bin/pamscale scripts/pnmscale

$ mv usr/bin/pnmtopng scripts/

$ mv usr/lib/libnetpbm.so.11.73 libs/libnetpbm.so.11

$ tar zxvf libpng-1.6.39-r0.apk

$ mv usr/lib/libpng16.so.16.39.0 libs/


NOW CONNECT YOUR KOBO TO YOUR PC:

Copy the following binaries from the scripts/ folder on the PC to the /mnt/onboard/.adds/koreader/scripts/ folder on the kobo.
pnmscale
pnmtopng

***
* Backup your old libpng16.so.16 from the /mnt/onboard/.adds/koreader/libs/ folder on the kobo.
Then delete it from /mnt/onboard/.adds/koreader/libs/
***

Copy libs from the libs/ folder on the PC to the /mnt/onboard/.adds/koreader/libs/ folder on the kobo:
libnetpbm.so.11
libpng16.so.16.39.0

***
* Now doublecheck that KOReader can read png files with this new libpng16.so.16.39.0
***

Copy camera image s.jpg from your phone to the /mnt/onboard/.adds/rmkit/data/harmony/ folder on the kobo.


TRANSFORM PHOTO S.JPG FROM fbpadkb OR KOReader TERMINAL:

From kobo terminal(or SSH session):
# . /korenv.sh
# cd /mnt/onboard/.adds/rmkit/data/harmony

Convert image to grayscale, rotating if necessary:
# jpegtran -rotate 90 -grayscale s.jpg > s90.jpg

Convert jpg image to pnm:
# djpeg -pnm s90.jpg > sg.pnm

Scale image to your display(1088x1488 for Clara HD):
# pnmscale -width 1088 -height 1488 sg.pnm > bg.pnm

Convert pnm image to png:
# pnmtopng bg.pnm > bg.png

Note: you could have dimmed the image by using itself as an alpha mask:
# pnmtopng -alpha bg.pnm bg.pnm > bgs.png

Or for a less ghostly effect, use a 50% grayscale mask:
# pnmtopng -alpha a50.pgm bg.pnm > bga.png

Run harmony from rmkit, and import the bg.png as a layer.

Tip: You can wirelessly copy the photo from phone to Kobo, e.g. with KOReader's GUI ftp client:
https://www.mobileread.com/forums/sh...25&postcount=6


***


USING SCRIPT AND 50% ALPHA CHANNEL (REQUIRES ATTACHED a50.pgm FILE):

Create script jtop.sh (and jtopr.sh for when image needs to be rotated), to convert a jpg image to png while applying 50% alpha transparency.

$ nano jtop.sh
Code:
jpegtran -grayscale $1 | djpeg -pnm | pnmscale -width 1088 -height 1488 | pnmtopng -alpha a50.pgm > $2
Copy this script to /mnt/onboard/.adds/koreader/scripts/ on your kobo.
Unzip the attached a50.zip file and copy a50.pgm and your phone photo s.jpg to /mnt/onboard/.adds/rmkit/data/harmony.
Tip: you can use KOReader's GUI ftp client to download the photo from your phone to your kobo.
https://www.mobileread.com/forums/sh...25&postcount=6


Run the script with input parameters s.jpg (the photo image from your phone) and bg.png (the name you chose for the output png file).

# jtop.sh s.jpg bg.png

You can then input this png image as a layer to harmony.

Similarly for landscape photos that you need to rotate to portrait:

$ nano jtopr.sh
Code:
jpegtran -rotate 90 -grayscale $1 | djpeg -pnm | pnmscale -width 1088 -height 1488 | pnmtopng -alpha a50.pgm > $2
# jtopr.sh s.jpg bgr.png


* NOTE : you have to kill agetty again upon returning to Nickel after exiting KOReader.


***


*UPDATE: Add GIF support

From netpbm package above, add also:

$ mv usr/bin/pngtopnm scripts/

$ mv usr/bin/pamtogif scripts/

$ mv usr/bin/ppmtogif scripts/

$ mv usr/bin/giftopnm scripts/


Also add gifsicle package:

Gifsicle assembles gif images into gif animations.
http://www.lcdf.org/gifsicle/

The gifsicle package has the following dependencies:

Depends (2)
libx11**
musl*

* Already got it from the Elinks/Nano install above
** Don't need libx11 for our command


RUN THESE COMMANDS FROM LINUX DESKTOP:

$ cd myalpine/

DOWNLOAD THE REQUIRED PACKAGES:

$ wget https://dl-cdn.alpinelinux.org/alpin...le-1.93-r1.apk

$ tar zxvf gifsicle-1.93-r1.apk

$ mv usr/bin/gifsicle scripts/


NOW CONNECT YOUR KOBO TO YOUR PC:

Copy the following binaries from the scripts/ folder on the PC to the /mnt/onboard/.adds/koreader/scripts/ folder on the kobo.
pngtopnm
pamtogif
ppmtogif
giftopnm
gifsicle


FROM SSH SHELL OR ON KOBO:

# . /korenv.sh

# cd /mnt/onboard/.adds/rmkit/data/harmony

Convert png images to gif:

# pngtopnm lines.png | ppmtogif > 1.gif

# pngtopnm mtn.png | ppmtogif > 2.gif


Making a GIF animation with gifsicle:

# gifsicle --delay=123 --loop 1.gif 2.gif > anim.gif

# gifsicle -I anim.gif
* anim.gif 2 images
logical screen 1408x1920
global color table [2]
background 0
loop forever
+ image #0 1088x1448
delay 1.23s
+ image #1 1408x1920
delay 1.23s


View animated gif on desktop browser (or luakit browser if you had installed a graphical chroot on your Kobo) via html file:

# vi anim.html
Code:
<html>
<img SRC="anim.gif" ALT="anim">
</html>
# cp anim.* /mnt/onboard/shared/

# ls /mnt/onboard/shared/anim.*
/mnt/onboard/shared/anim.gif /mnt/onboard/shared/anim.html


View animated gif on Kobo via playgif.sh script (requires fbink binary and gifsicle from above):

# vi /mnt/onboard/.adds/kordir/scripts/playgif.sh
Code:
#!/bin/sh
# playgif.sh - play animated gifs using gifsicle and fbink

export LD_LIBRARY_PATH="/mnt/onboard/.adds/kordir/libs:$LD_LIBRARY_PATH"
nframes=`/mnt/onboard/.adds/kordir/scripts/gifsicle -I $1 | sed -n 's/ images//p' | sed 's/\* .*\.gif // '`
echo "nframes = $nframes"
nframes=$(expr "$nframes" - 1)
delays=`/mnt/onboard/.adds/kordir/scripts/gifsicle -I $1 | sed -n 's/.*delay //p' | sed  's/s//'`
for i in $(seq 0 1 "$nframes");do
 /mnt/onboard/.adds/kordir/scripts/gifsicle "$1" "#$i" > /tmp/tmp.gif;
 /mnt/onboard/.adds/kordir/scripts/fbink -G -g file=/tmp/tmp.gif;
 j=$(expr "$i" \+ 1)
 delayfraction=`echo "$delays" | sed -n "$j"' s/.*[0-9][0-9]*\.//p'`
 delaywhole=`echo "$delays" | sed -n "$j"' s/\.[0-9][0-9]//p'`
 delay=`echo $(expr "$delayfraction" \* 10000 \+ "$delaywhole" \* 1000000)`
echo "delay = $delay"
 usleep "$delay";
done
# playgif.sh anim.gif
nframes = 2
delay = 1230000
delay = 1230000

(can comment out : echo "delay = $delay")

***
Attached Files
File Type: zip a50.zip (1.8 KB, 140 views)

Last edited by elinkser; 03-27-2024 at 04:15 PM. Reason: ADD NETPBM + GIFSICLE + IMPROVED PLAYGIF+REPO
elinkser is offline   Reply With Quote