From 9aee1bd8d90cb9ee252aa27dcc106e5991bc8cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haoran=20S=2E=20Diao=20=28=E5=88=81=E6=B5=A9=E7=84=B6=29?= <0@hairydiode.xyz> Date: Sun, 2 Jul 2023 06:22:00 -0700 Subject: Optimized braille conversion in bbrll to not need any sed or string ops, it's just a big list of ifs for all 8 bytes --- bbrll | 59 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 16 deletions(-) (limited to 'bbrll') diff --git a/bbrll b/bbrll index e94c1e8..5f3324f 100755 --- a/bbrll +++ b/bbrll @@ -53,31 +53,58 @@ function print_sin_braille() { #6 7 #reverse #(1,3)(0,3)(1,2)(1,1)(1,0)(0,2)(0,1)(0,0) - - b0=${rawbuff[((0+4*$2))]:((0+2*$1)):1} - b1=${rawbuff[((1+4*$2))]:((0+2*$1)):1} - b2=${rawbuff[((2+4*$2))]:((0+2*$1)):1} - b3=${rawbuff[((0+4*$2))]:((1+2*$1)):1} - b4=${rawbuff[((1+4*$2))]:((1+2*$1)):1} - b5=${rawbuff[((2+4*$2))]:((1+2*$1)):1} - b6=${rawbuff[((3+4*$2))]:((0+2*$1)):1} - b7=${rawbuff[((3+4*$2))]:((1+2*$1)):1} - + num=0 + if [ "${rawbuff[((0+4*$2))]:((0+2*$1)):1}" == "1" ]; then + num=$(($num + 1)) + fi + if [ "${rawbuff[((1+4*$2))]:((0+2*$1)):1}" == "1" ];then + num=$(($num + 2)) + fi + if [ "${rawbuff[((2+4*$2))]:((0+2*$1)):1}" == "1" ];then + num=$(($num + 4)) + fi + if [ "${rawbuff[((0+4*$2))]:((1+2*$1)):1}" == "1" ];then + num=$(($num + 8)) + fi + if [ "${rawbuff[((1+4*$2))]:((1+2*$1)):1}" == "1" ];then + num=$(($num + 16)) + fi + if [ "${rawbuff[((2+4*$2))]:((1+2*$1)):1}" == "1" ];then + num=$(($num + 32)) + fi + if [ "${rawbuff[((3+4*$2))]:((0+2*$1)):1}" == "1" ];then + num=$(($num + 256)) + fi + if [ "${rawbuff[((3+4*$2))]:((1+2*$1)):1}" == "1" ];then + num=$(($num + 512)) + fi #ors it with the utf-8 hex value of the empty braille character #the two spaces assume aht the encoding is utf-8, convoluted bitwise OR #and coversion between character and number stuff - echo "obase=16;$(( 2#$b7${b6}00$b5$b4$b3$b2$b1$b0 | 0xE2A080 ))"|bc | xxd --reverse -ps + #echo "obase=16;$(( 2#$b7${b6}00$b5$b4$b3$b2$b1$b0 | 0xE2A080 ))"|bc | xxd --reverse -ps + echo "obase=16;$(( $num | 0xE2A080 ))"|bc | xxd --reverse -ps } function print_braille() { #I do the lazy thing and just test the first line w=${#rawbuff[0]} h=${#rawbuff[@]} - #conver to braille coords, we do not want to try to print incomplete - #characters because they will break with our optimization, so rounding - #down is good - w=$((w/2)) - h=$((h/4)) + + #conver to braille coords, since bash rounds down, account for when + #there a braille character that will not be completely filled(it can + #handle this fine because of how the sed pattern was constructed in + #print_sin_braille) + if [ $((w % 2)) -gt 0 ]; then + w=$((w/2+1)) + else + w=$((w/2)) + fi + if [ $((h % 4)) -gt 0 ]; then + h=$((h/4+1)) + else + h=$((h/4)) + fi + i=0 j=0 while [ $i -lt $h ]; do -- cgit v1.1