source: subversion/applications/rendering/gosmore/mkicons.sh @ 15979

Last change on this file since 15979 was 12108, checked in by daviddean, 11 years ago

AddWayOrNode? can now just add a note for things that aren't in the presets
(goes in as gosmore_note=yes at the moment + name and note fields)
These probably shouldn't be saved to openstreetmaps though

  • Property svn:executable set to *
File size: 3.8 KB
Line 
1#!/bin/bash -u
2
3## poplargestfit function
4# grabs the largest image that fits in a specified region and removes
5# it from the filelist
6# NOTE: assumes that allicons list is sorted from tallest to shortest
7function poplargestfit {
8    # params: height width
9    height=$1; width=$2
10
11    # get row
12    row=$(awk -F':' '$3 <= '$height' && $4 <= '$width' { print $0; exit }' \
13        $allicons)
14    if [ ! -z "$row" ]; then
15        # remove row from filelist (if one found)
16        id=$(echo $row | cut -d':' -f1)
17        sed -i "/^$id/d" $allicons
18        # echo row to stdout
19    fi
20    echo $row
21}
22
23## fillregion function
24# recursively fills a specified region with images
25function fillregion {
26    # params: top left height width
27    local top=$1; local left=$2; local height=$3; local width=$4
28
29    # add the largest icon that will fit in the space in the top left
30    local image=$(poplargestfit $height $width)
31    local imfile=$(echo $image | cut -d':' -f2)
32    local imheight=$(echo $image | cut -d':' -f3)
33    local imwidth=$(echo $image | cut -d':' -f4)
34   
35    if [ ! -z "$imfile" ]; then
36        echo ${imfile}:${left}:${top}:${imwidth}:${imheight}
37       
38        # fillregion the rest of the row (row height is imheight)
39        fillregion $top $(($left+$imwidth)) $imheight $(($width-$imwidth))
40
41        # fillregion the rest of the region (i.e. minus first row)
42        fillregion $(($top+$imheight)) $left $(($height-$imheight)) $width
43    fi
44
45}
46
47#collect the icons from here
48ICONDIR="map-icons"
49
50tmpdir=$(mktemp -d)
51allicons=$tmpdir/all
52sizeicons=$tmpdir/size
53montagelist=$tmpdir/montages
54
55name=icons
56
57# list all icons we want, sorting them by height then width
58find $ICONDIR -iname '*.png' \
59    -not -iwholename '*people*' \
60    -not -iwholename '*waypoint*' \
61    -not -iwholename '*wlan*' \
62    -not -iwholename '*rendering*' \
63    -not -iwholename '*svg*' \
64    | xargs identify -format '%i:%h:%w\n' \
65    | awk '{printf("%05d:%s\n",NR,$0)}' \
66    | sort -r -t':' -k3 -n -k4 -n > $allicons
67
68echo "Calculating icon distribution"
69
70fillregion 0 0 1024 1024 > $name.csv
71
72echo "Icon distribution list is in $name.csv ($(cat $allicons | wc -l) not included)"
73
74echo "Creating $name.png"
75
76convert -size 0x0 xc:black $name.png
77for line in $(cat $name.csv); do
78    convert $name.png \
79        -page +$(echo $line | cut -d':' -f2)+$(echo $line | cut -d':' -f3) \
80        "$(echo $line | cut -d':' -f1)" \
81        -background None -mosaic $name.png
82done
83
84echo "Flattening image (see $name-flatten.png)"
85# convert to binary transparency through thresholding of alpha channel
86convert $name.png -channel matte -separate +channel -negate \
87    -threshold 25% -alpha off $tmpdir/mask.png
88# add mask back to original image
89composite -compose CopyOpacity $tmpdir/mask.png $name.png $tmpdir/binalpha.png
90# set background for transparent regions and reduce colors
91convert $tmpdir/binalpha.png -background black \
92    -flatten -colors 256 -type palette \
93    $name-flatten.png
94
95echo "Converting to bmp and xpm formats"
96# imagemagick's bmp conversion doesn't seem to work well for
97# windows mobile resource files, so we will use netpbm here instead
98# convert $name-flatten.png -type palette $name.bmp
99pngtopnm $name-flatten.png | ppmtobmp > $name.bmp
100pngtopnm $tmpdir/mask.png | pnminvert | ppmtobmp > $name-mask.bmp
101# imagemagick works ok for xpm though
102convert $tmpdir/binalpha.png $name.xpm
103
104echo "Making icons.csv compatable with old version"
105# this would probably be better done in gosmore.cpp, but I'll do
106# it here to maintain compatability for now
107sed -i -e 's|^map-icons/||' -e 's|/|_|g' $name.csv
108
109# Suppress the icons Ulf is using to highlight errors
110echo 'classic.big_misc_deprecated.png:0:0:1:1
111square.big_misc_deprecated.png:0:0:1:1
112classic.small_misc_deprecated.png:0:0:1:1
113square.small_misc_deprecated.png:0:0:1:1
114classic.big_misc_no_icon.png:0:0:1:1
115square.big_misc_no_icon.png:0:0:1:1
116classic.small_misc_no_icon.png:0:0:1:1
117square.small_misc_no_icon.png:0:0:1:1' >> $name.csv
118
119rm -r $tmpdir
120
121
Note: See TracBrowser for help on using the repository browser.