ref: 8d492b83859ade0e039dbed166d002c4e1e957e3
dir: /unspr/
#!/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