From f1aa71a434bade3fc6ecb28c6816b0111d126e56 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 04:35:10 -0700 Subject: did some optimizations to make things a lot faster at the cost of making bbrll only work with 1/0 inputs, and if the buffer is exactly some multiple of 2x4 large --- bbrll | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) (limited to 'bbrll') diff --git a/bbrll b/bbrll index 661fd14..e94c1e8 100755 --- a/bbrll +++ b/bbrll @@ -43,6 +43,8 @@ function canvas() { #prints a single braille at $1=x $2=y function print_sin_braille() { +#NOTE, for optimization purposes, this only works if the buffer consits of 1s +#and 0s #bit to braille # #0 3 @@ -51,42 +53,31 @@ function print_sin_braille() { #6 7 #reverse #(1,3)(0,3)(1,2)(1,1)(1,0)(0,2)(0,1)(0,0) - #converts anything other than ., and empty string, or space into 1, else - #0 - prompt='s/[^\. ]/1/;s/^[^1]*$/0/' - b0=$( echo ${rawbuff[((0+4*$2))]:((0+2*$1)):1} | sed "$prompt" ) - b1=$( echo ${rawbuff[((1+4*$2))]:((0+2*$1)):1} | sed "$prompt" ) - b2=$( echo ${rawbuff[((2+4*$2))]:((0+2*$1)):1} | sed "$prompt" ) - b3=$( echo ${rawbuff[((0+4*$2))]:((1+2*$1)):1} | sed "$prompt" ) - b4=$( echo ${rawbuff[((1+4*$2))]:((1+2*$1)):1} | sed "$prompt" ) - b5=$( echo ${rawbuff[((2+4*$2))]:((1+2*$1)):1} | sed "$prompt" ) - b6=$( echo ${rawbuff[((3+4*$2))]:((0+2*$1)):1} | sed "$prompt" ) - b7=$( echo ${rawbuff[((3+4*$2))]:((1+2*$1)):1} | sed "$prompt" ) - #echo "2#$b7$b600$b5$b4$b3$b2$b1$b0" + 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} + + #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 | 0x$(echo -n ⠀ |xxd -p -u)))" |bc | xxd --reverse -ps + echo "obase=16;$(( 2#$b7${b6}00$b5$b4$b3$b2$b1$b0 | 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, 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 + #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)) i=0 j=0 while [ $i -lt $h ]; do -- cgit v1.1