summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaoran S. Diao (刁浩然) <0@hairydiode.xyz>2023-07-02 06:22:00 -0700
committerHaoran S. Diao (刁浩然) <0@hairydiode.xyz>2023-07-02 06:22:00 -0700
commit9aee1bd8d90cb9ee252aa27dcc106e5991bc8cb3 (patch)
treef8c49b24831ffcd757d0232799c785cd035c2e3f
parentfb63015770e5958ba8091e61461dcf39d447f67b (diff)
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
-rw-r--r--README2
-rwxr-xr-xbbrll59
2 files changed, 44 insertions, 17 deletions
diff --git a/README b/README
index 36f7bb4..3ac97dc 100644
--- a/README
+++ b/README
@@ -22,7 +22,7 @@ begin:
PRINT_RAW or
#prints the raw image buffer
PRINT_BRAILLE or
- #NOTE: THIS ONLY WORKS IF THE CANVAS Consits of only 0s and 1s
+ #NOTE: THIS ONLY PRINTS '1' as a filled in dot
#prints the output in braille, this uses only the width of the
#first row so make sure to call CANVAS or something before hand
END
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