diff --git a/px6_convert.sh b/px6_convert.sh index 8a914ea..a49e6d4 100755 --- a/px6_convert.sh +++ b/px6_convert.sh @@ -1,4 +1,5 @@ -#! /bin/bash +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p bash imagemagick INPUT="$1" OUTPUT="$2" @@ -10,18 +11,19 @@ if [ "$OH" == "" ]; then OH=0; fi OPTIONS="-resize $W -set depth 8 -set colorspace RGB" #initial conversion -convert-im6 $OPTIONS "$INPUT" txt:- | awk -v ow="$OW" -v oh="$OH" 'match($0, /^([0-9]*),([0-9]*):.*#([0-9A-Fa-f]{6,8}) +r/, arr ){ print "PX " arr[1]+ow " " arr[2]+oh " " arr[3] }' > "$OUTPUT" +convert $OPTIONS "$INPUT" txt:- | awk -v ow="$OW" -v oh="$OH" 'match($0, /^([0-9]*),([0-9]*):.*#([0-9A-Fa-f]{6,8}) +r/, arr ){ print "PX " arr[1]+ow " " arr[2]+oh " " arr[3] }' > "${OUTPUT}.tmp" echo optimizing >&2 # edge detection -convert-im6 $OPTIONS "$INPUT" -negate -edge 4 -negate txt:- | awk -v ow="$OW" -v oh="$OH" 'match($0, /^([0-9]*),([0-9]*):.*#000000/, arr ){ print "PX " arr[1]+ow " " arr[2]+oh " " }' > /tmp/px6_optimize -grep -Ff /tmp/px6_optimize "$OUTPUT" > "${OUTPUT}.tmp" -grep -Ff /tmp/px6_optimize "$OUTPUT" >> "${OUTPUT}.tmp" -grep -Ff /tmp/px6_optimize "$OUTPUT" >> "${OUTPUT}.tmp" -grep -Ff /tmp/px6_optimize "$OUTPUT" >> "${OUTPUT}.tmp" -cat "${OUTPUT}.tmp" >> "$OUTPUT" -cat "$OUTPUT" | grep -ve " [a-fA-F0-9]\{6\}00" | shuf > "${OUTPUT}.tmp" -mv "${OUTPUT}.tmp" "$OUTPUT" -rm /tmp/px6_optimize +convert $OPTIONS "$INPUT" -canny 0x1+10%+30% txt:- | awk -v ow="$OW" -v oh="$OH" 'match($0, /^([0-9]*),([0-9]*):.*#000000/, arr ){ print "PX " arr[1]+ow " " arr[2]+oh " " }' > /tmp/px6_optimize +grep -Ff /tmp/px6_optimize "${OUTPUT}.tmp" >> "${OUTPUT}.tmp2" +cat "${OUTPUT}.tmp" > "${OUTPUT}.tmp3" +cat "${OUTPUT}.tmp2" >> "${OUTPUT}.tmp3" +cat "${OUTPUT}.tmp2" >> "${OUTPUT}.tmp3" +cat "${OUTPUT}.tmp2" >> "${OUTPUT}.tmp3" +cat "${OUTPUT}.tmp2" >> "${OUTPUT}.tmp3" +cat "${OUTPUT}.tmp3" | grep -ve " [a-fA-F0-9]\{6\}00" | shuf > /tmp/px6_optimize +mv /tmp/px6_optimize "$OUTPUT" +rm "${OUTPUT}.tmp" "${OUTPUT}.tmp2" "${OUTPUT}.tmp3" diff --git a/px6_send.sh b/px6_send.sh index eee52cc..086e13a 100755 --- a/px6_send.sh +++ b/px6_send.sh @@ -1,4 +1,5 @@ -#! /bin/bash +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p bash bc IP="$1" PORT="$2" PROCS="$3" @@ -13,7 +14,7 @@ do_exit() { } trap do_exit SIGINT SIGTERM -for i in $(seq 0 $(($PROCS-1))); do +for i in $(seq 1 $PROCS); do ( THISPID=$BASHPID # ( while kill -0 $MAINPID; do sleep 1; done; do_exit ) & @@ -21,11 +22,11 @@ for i in $(seq 0 $(($PROCS-1))); do ( THISPID2=$BASHPID ( sleep $PROCMAXTIME; kill -9 $THISPID2 >/dev/null 2>&1 ) & - echo "starting $(($i+1)) / $PROCS" - ( while kill -0 $THISPID2; do cat "$FILE"; done ) | nc "$IP" "$PORT" >/dev/null 2>&1 + echo "starting $i / $PROCS" + ( while kill -0 $THISPID2; do cat "$FILE"; done ) > /dev/tcp/$IP/$PORT 2>&1 ) >/dev/null 2>&1 done ) & - sleep $(echo "scale=2; ($PROCMAXTIME/$PROCS) + 1" | bc) + # sleep $(echo "scale=2; ($PROCMAXTIME/$PROCS) + 1" | bc) done while true; do sleep 9999999; done