shithub: rc

Download patch

ref: 54f9bc11d6900ebb24697d70db213ace24f3578e
parent: 3878ac8749bfcc81188d33c01b52909e18561b2f
author: qwx <qwx@sciops.net>
date: Thu Jan 9 09:20:07 EST 2020

add gfx: auxiliary scripts for using plan9 images with spred(1)

diff: cannot open b/gfx//null: file does not exist: 'b/gfx//null'
--- /dev/null
+++ b/gfx/dpal
@@ -1,0 +1,16 @@
+#!/bin/rc
+# convert selected playpal palette to spred(1) format
+# FIXME: includes garbage past the end
+pn=0
+while(~ $1 -n){
+	pn=$2
+	shift 2
+}
+echo pal 256
+dd -bs 768 -skip $pn -count 1 <$1 >[2]/dev/null \
+	| xd -1x \
+	| ssam '
+,s/^....... +//g
+s/\n/ /g
+s/(..) (..) (..) /0x\1\2\3\n/g
+'
--- /dev/null
+++ b/gfx/tospr
@@ -1,0 +1,51 @@
+#!/bin/rc -e
+# FIXME: includes garbage past the end
+fn cleanup{
+	if(! ~ $#tf 0)
+		rm -f $tf
+	tf=()
+}
+fn sigint{
+	cleanup
+	exit
+}
+fn sigexit{
+	cleanup
+}
+
+if(! ~ $#* 2){
+	echo usage: $0 pal image
+	exit usage
+}
+tf=/tmp/tospr.$pid
+iconv -uc r8g8b8 $2 > $tf
+r=`{awk '{ print $4-$2, $5-$3; exit }' $tf}
+awk '
+NR == 1{
+	npal = $2
+}
+FNR == NR && NR != 1{
+	pal[$1] = NR-2
+}
+FNR == 1 && NR != 1{
+	print "sprite", '^$r(1)^,^$r(2)^',"'^$1^'"
+}
+FNR != NR{
+	if($1 in pal)
+		printf "%d ", pal[$1]
+	else{
+		print "value " $1 " not in palette!"
+		exit
+	}
+	if(++px == '^$r(1)^'){
+		printf "\n"
+		px = 0
+	}
+}
+' $1 <{dd -bs 5x12 -skip 1 <$tf >[2]/dev/null \
+	| xd -1x \
+	| ssam '
+,s/^....... +//g
+s/\n/ /g
+s/(..) (..) (..) /0x\3\2\1\n/g
+'}
--- /dev/null
+++ b/gfx/unspr
@@ -1,0 +1,44 @@
+#!/bin/rc
+if(! ~ $#* 2){
+	echo usage: $0 pal spr
+	exit usage
+}
+awk '
+function hex(s, v){
+	if(s ~ /^0x/)
+		s = substr(s, 3)
+	for(n=1; n<=length(s); n++)
+		v = v * 16 + h[substr(s, n, 1)]
+	return v
+}
+BEGIN{
+	for(n=0; n<16; n++){
+		h[sprintf("%x", n)] = n
+		h[sprintf("%X", n)] = n
+	}
+}
+FNR == 1{
+	x = $2
+	y = $3
+}
+FNR == NR{
+	sub(/0x/, "")
+	gsub(/../, "0x& ")
+	split($0, a)
+	c[i,3] = hex(a[1])
+	c[i,2] = hex(a[2])
+	c[i,1] = hex(a[3])
+	i++
+	next
+}
+{
+	if(FNR == 1){
+		printf "     r8g8b8           0           0%12d%12d ", x, y
+		next
+	}
+	for(i=1; i<=NF; i++){
+		n = $i + 1
+		printf "%c%c%c", c[n,1], c[n,2], c[n,3]
+	}
+}
+' $1 $2