-
Notifications
You must be signed in to change notification settings - Fork 2
/
deepzoom_v1.sh
executable file
·171 lines (152 loc) · 5.76 KB
/
deepzoom_v1.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
. functions.inc.sh
trap "kill 0" SIGINT SIGTERM EXIT # kill all subshells on exit
trap "kill -STOP 0" SIGSTOP
trap "kill -CONT 0" SIGCONT
export MAGICK_TEMPORARY_PATH=.
tileSize=512
startLevel=19
level=${startLevel}
THREADS=1
echo "Level: ${level}"
echo -n "Cropping ..."
if [ -d map_files/${level} ] ; then
echo " map_files/${level} exists ... skipping ..."
else
for THREAD in $( seq 0 $((${THREADS}-1)) ) ; do (
export MAGICK_MEMORY_LIMIT=6GB
numPic=0
for pic in current-*-*.png ; do
numPic=$((${numPic}+1))
[ $(( ${numPic} % ${THREADS} )) -eq ${THREAD} ] || continue
x=${pic#current-}
x=${x%-*}
y=${pic%.png}
y=${y##*-}
x=$((${x}/${tileSize}))
y=$((${y}/${tileSize}))
mkdir -p map_files/${level}
SECONDS=0
convert ${pic} -crop ${tileSize}x${tileSize} -set filename:tile "%[fx:page.x/${tileSize}+${x}]_%[fx:page.y/${tileSize}+${y}]" map_files/${level}/%[filename:tile].jpg
echo -n " T:${THREAD} ${pic}(${SECONDS}s)"
done ) &
done
wait
echo " ... done"
fi
rm -f work.png
src="current" # set to "work" after first iteration
for level in $( seq $(( ${startLevel}-1 )) -1 0 ) ; do
echo "Level: ${level}"
read w h < <( identify -format "%w %h" ${src}-0-0.png )
if [ ${w} -le 12800 ] ; then
if [ ! -f work.png ] ; then
echo -n "Resizing ..."
for THREAD in $( seq 0 $((${THREADS}-1)) ) ; do (
export MAGICK_MEMORY_LIMIT=6GB
numPic=0
for pic in ${src}-*-*.png ; do
numPic=$((${numPic}+1))
[ $(( ${numPic} % ${THREADS} )) -eq ${THREAD} ] || continue
SECONDS=0
convert ${pic} -resize 50% "work-${pic#${src}-}" ;
echo -n " T:${THREAD} ${pic}(${SECONDS}s)"
done ) &
done
wait
echo " ... done"
read w h < <( identify -format "%w %h" ${src}-0-0.png )
echo -n "Montaging ..."
SECONDS=0
export MAGICK_MEMORY_LIMIT=4GB
montage \
work-0-0.png work-25600-0.png work-51200-0.png work-76800-0.png work-102400-0.png work-128000-0.png work-153600-0.png work-179200-0.png work-204800-0.png work-230400-0.png work-256000-0.png \
work-0-25600.png work-25600-25600.png work-51200-25600.png work-76800-25600.png work-102400-25600.png work-128000-25600.png work-153600-25600.png work-179200-25600.png work-204800-25600.png work-230400-25600.png work-256000-25600.png \
work-0-51200.png work-25600-51200.png work-51200-51200.png work-76800-51200.png work-102400-51200.png work-128000-51200.png work-153600-51200.png work-179200-51200.png work-204800-51200.png work-230400-51200.png work-256000-51200.png \
work-0-76800.png work-25600-76800.png work-51200-76800.png work-76800-76800.png work-102400-76800.png work-128000-76800.png work-153600-76800.png work-179200-76800.png work-204800-76800.png work-230400-76800.png work-256000-76800.png \
work-0-102400.png work-25600-102400.png work-51200-102400.png work-76800-102400.png work-102400-102400.png work-128000-102400.png work-153600-102400.png work-179200-102400.png work-204800-102400.png work-230400-102400.png work-256000-102400.png \
work-0-128000.png work-25600-128000.png work-51200-128000.png work-76800-128000.png work-102400-128000.png work-128000-128000.png work-153600-128000.png work-179200-128000.png work-204800-128000.png work-230400-128000.png work-256000-128000.png \
-geometry ${w}x${h}+0+0 \
-tile 11x6 \
work.png
cp -v work.png offlinemap.png
echo " done in ${SECONDS}s"
else # work.png exists from previous iteration
echo -n "Resizing ..."
SECONDS=0
export MAGICK_MEMORY_LIMIT=6GB
convert work.png -resize 50% work.png
echo " done in ${SECONDS}s"
fi
echo -n "Cropping ..."
[ -d map_files/${level} ] && echo -e "\tmap_files/${level} exists ... skipping ..." && continue
mkdir -p map_files/${level}
SECONDS=0
export MAGICK_MEMORY_LIMIT=6GB
convert work.png -crop ${tileSize}x${tileSize} -set filename:tile "%[fx:page.x/${tileSize}]_%[fx:page.y/${tileSize}]" map_files/${level}/%[filename:tile].jpg
echo " done in ${SECONDS}s"
else # ${w} > 12800
echo -n "Resizing ..."
for THREAD in $( seq 0 $((${THREADS}-1)) ) ; do (
numPic=0
for pic in ${src}-*-*.png ; do
numPic=$((${numPic}+1))
[ $(( ${numPic} % ${THREADS} )) -eq ${THREAD} ] || continue
SECONDS=0
convert ${pic} -resize 50% "work-${pic#${src}-}" ;
echo -n " T:${THREAD} ${pic}"
echo -n "(${SECONDS}s)"
done ) &
done
wait
echo " ... done"
src="work"
[ -d map_files/${level} ] && echo -e "\tmap_files/${level} exists ... skipping ..." && continue
mkdir -p map_files/${level}
echo -n "Cropping ..."
read w h < <( identify -format "%w %h" work-0-0.png )
w=$((${w}/${tileSize}))
h=$((${h}/${tileSize}))
for THREAD in $( seq 0 $((${THREADS}-1)) ) ; do (
numPic=0
for pic in work-*-*.png ; do
numPic=$((${numPic}+1))
[ $(( ${numPic} % ${THREADS} )) -eq ${THREAD} ] || continue
x=${pic#work-}
x=${x%-*}
x=$(((${x}/25600)*${w}))
y=${pic%.png}
y=${y##*-}
y=$(((${y}/25600)*${h}))
SECONDS=0
convert ${pic} -crop ${tileSize}x${tileSize} -set filename:tile "%[fx:page.x/${tileSize}+${x}]_%[fx:page.y/${tileSize}+${y}]" map_files/${level}/%[filename:tile].jpg
echo -n " T:${THREAD} ${pic}+${x}+${y}(${SECONDS}s)"
done ) &
done
wait
echo " ... done"
fi
done
read w h < <( identify -format "%w %h" current-0-0.png )
maxx=0
maxy=0
for pic in current-*-*.png ; do
x=${pic#current-}
x=${x%-*}
y=${pic%.png}
y=${y##*-}
[ ${x} -gt ${maxx} ] && maxx=${x}
[ ${y} -gt ${maxy} ] && maxy=${y}
done
maxx=$((${maxx}+${w}))
maxy=$((${maxy}+${h}))
cat > map.xml <<EOF
<?xml version='1.0' encoding='UTF-8'?>
<Image TileSize='${tileSize}'
Overlap='0'
Format='jpg'
xmlns='http://schemas.microsoft.com/deepzoom/2008'>
<Size Width='${maxx}' Height='${maxy}'/>
</Image>
EOF
createOverlaysJSON