summaryrefslogtreecommitdiff
path: root/test/uncompress-6level.sh.in
blob: f4bd9e91a6a475e3367888c01b86693e05b8aa0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!@SHELL@

# compression of 5-level inks (irrespective of bits per level)
# 3-level, 5 pixels = 1024 combinations: 10 bits long
# but since not all levels used: unique are 242, or 1 byte
# 4-level, 4 pixels = 65536 combinations: 16 bits long
# but since only 2 bits per pixel used there are 256 combinations, or 1 byte
# 5-level, 3 pixels: 15 bits long
# but since only 3 bits per pixel used there are 125 unique combinations, or 1 byte


# m: max number of levels used
m=6
maxl=$(( $m-1 )) # the max level numerical value
# z: max number allowed by bits (numerical value)
z=15
# a: iteration of valid array subscript (1-based)
a=1
# iteration of pixels
#i=0
j=0
k=0
l=0

echo "static const unsigned short Table6Level[] ="
echo "{"

#for (( i=0; i<=$z; i++ ))
#do
    for (( j=0; j<=$z; j++ ))
    do
	for (( k=0; k<=$z; k++ ))
	do
	    for (( l=0; l<=$z; l++ ))
	    do
		if test $j -le ${maxl} -a $k -le ${maxl} -a $l -le ${maxl}
		then
		    bj=$(echo "ibase=16;obase=2; $j" | bc | awk '{if ($0<10){print "000"$0} else if ($0<100){print "00"$0} else if ($0<1000){print "0"$0} else {print $0} }')
		    bk=$(echo "ibase=16;obase=2; $k" | bc | awk '{if ($0<10){print "000"$0} else if ($0<100){print "00"$0} else if ($0<1000){print "0"$0} else {print $0} }')
		    bl=$(echo "ibase=16;obase=2; $l" | bc | awk '{if ($0<10){print "000"$0} else if ($0<100){print "00"$0} else if ($0<1000){print "0"$0} else {print $0} }')
		    binput="${bj}${bk}${bl}"
		    #echo "test:" ${bj} ${bk} ${bl} ":" ${binput} ":" $(echo "ibase=2;obase=10000; ${binput}" | bc)
		    array[$a]=$(echo "ibase=2;obase=10000; ${binput}" | bc)
		    remainder=$(( $a % 16 ))
		    a=$(( $a+1 ))
		    #echo "test:" ${remainder}
		    # print line of output
		    if test ${remainder} -eq 0
		    then
			printf "  "
			pstart=$(( $a-16 ))
			pfinal=$(( $a-1 ))
			#echo "array subscript: $a, pstart: $pstart, pfinal: $pfinal, iterators: $j $k $l"
			for (( p=$pstart; p<=$pfinal; p++ ))
			do
			    printf "0x%x," 0x${array[$p]}
			done
			printf "\n"
		    fi
		fi
	    done
	done
    done
#done

# need to print out the last set of combinations
dividend=$(( $a-1 ))
divisor=${dividend}/16 # the number of completed rows already printed
printf "  "
pstart=$(( ${divisor}*16+1 ))
pfinal=${dividend}
#echo "array subscript: $a, pstart: $pstart, pfinal: $pfinal, iterators: $j $k $l"
for (( p=$pstart; p<=$pfinal; p++ ))
do
    printf "0x%x," 0x${array[$p]}
done
printf "\n"



echo "};"
echo "max number of valid combinations: $(( a-1 ))"