diff options
| author | Haoran S. Diao (刁浩然) <0@hairydiode.xyz> | 2023-07-02 04:35:10 -0700 | 
|---|---|---|
| committer | Haoran S. Diao (刁浩然) <0@hairydiode.xyz> | 2023-07-02 04:35:10 -0700 | 
| commit | f1aa71a434bade3fc6ecb28c6816b0111d126e56 (patch) | |
| tree | 4d19054a2ce78a4273ac1166a67931060dcb4435 /bbrll | |
| parent | d41ea136c0380ef7f77256b292171906eabc0f07 (diff) | |
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
Diffstat (limited to 'bbrll')
| -rwxr-xr-x | bbrll | 45 | 
1 files changed, 18 insertions, 27 deletions
@@ -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  | 
