-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppm2rdf.sh
executable file
·53 lines (53 loc) · 898 Bytes
/
ppm2rdf.sh
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
#!/bin/bash
a=$(cat <<SETA
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with ppm2rdf.sh (https://github.com/millercl/xslt-rdf-mr) -->
<!DOCTYPE rdf:RDF [
<!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
]>
<RDF xmlns="&rdf;" xml:lang="hexrgb" >
SETA
)
l=1
m=0
w=0
r=0
g=0
b=0
x=1
y=1
while read line
do
[[ $l -eq 1 && $line != "P3" ]] && exit
if [[ $l -eq 3 ]]
then
w=`echo $line | cut -d ' ' -f 1`
fi
if [ $l -eq 4 ]
then
[[ $line != "255" ]] && exit
echo "$a"
fi
if [ $l -gt 4 ]
then
case $m in
0 ) r=`printf '%02x' $line` ;;
1 ) g=`printf '%02x' $line` ;;
2 ) b=`printf '%02x' $line` ;;
esac
if [ $m -eq 2 ]
then
echo " <Description about=\"&rdf;_$x\" > <_$y >#$r$g$b</_$y> </Description>"
if [ $(($x+1)) -gt $w ]
then
((y++))
fi
x=$(( ( x % w ) + 1 ))
fi
m=$(( ( m + 1 ) % 3 ))
fi
((l++))
done
cat <<SETC
</RDF>
SETC