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

Last change on this file since 27126 was 19581, checked in by nic, 10 years ago

WinCE: Fix AddWayOrNode?. Fix compiling errors.
Improve distiction between dragging and clicking.
Fix bug 2454: SEGV when HOME not set

  • Property svn:executable set to *
File size: 4.1 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# Add PD Icons from openclipart.org
58cp -a [^i0]*.png iconset.png $ICONDIR/classic.big
59for n in [^i0]*.png iconset.png
60do convert $n -resize 32x32\> $ICONDIR/classic.small/$n
61done
62
63# list all icons we want, sorting them by height then width
64find $ICONDIR -iname '*.png' \
65    -not -iwholename '*people*' \
66    -not -iwholename '*wlan*' \
67    -not -iwholename '*rendering*' \
68    -not -iwholename '*svg*' \
69    | xargs identify -format '%i:%h:%w\n' \
70    | awk '{printf("%05d:%s\n",NR,$0)}' \
71    | sort -r -t':' -k3 -n -k4 -n > $allicons
72
73echo "Calculating icon distribution"
74
75fillregion 0 0 1024 1024 > $name.csv
76
77echo "Icon distribution list is in $name.csv ($(cat $allicons | wc -l) not included)"
78
79echo "Creating $name.png"
80
81convert -quality 0 -size 0x0 xc:black $name.png
82for line in $(cat $name.csv); do
83    convert $name.png \
84        -page +$(echo $line | cut -d':' -f2)+$(echo $line | cut -d':' -f3) \
85        "$(echo $line | cut -d':' -f1)" \
86        -background None -mosaic -quality 0 $name.png
87done
88# The for loop can also be replaced with these 3 lines, which is slower for
89# some reason:
90#convert $name.png `
91#  sed -e 's/\(.*\):\(.*\):\(.*\):.*:.*/ -page +\2+\3 \1/' <$name.csv` \
92#  -background None -mosaic -quality 0 $name.png
93
94echo "Flattening image (see $name-flatten.png)"
95# convert to binary transparency through thresholding of alpha channel
96convert $name.png -channel matte -separate +channel -negate \
97    -threshold 25% -alpha off $tmpdir/mask.png
98# add mask back to original image
99composite -compose CopyOpacity $tmpdir/mask.png $name.png $tmpdir/binalpha.png
100# set background for transparent regions and reduce colors
101convert $tmpdir/binalpha.png -background black \
102    -flatten -colors 256 -type palette \
103    $name-flatten.png
104
105echo "Converting to bmp and xpm formats"
106# imagemagick's bmp conversion doesn't seem to work well for
107# windows mobile resource files, so we will use netpbm here instead
108# convert $name-flatten.png -type palette $name.bmp
109pngtopnm $name-flatten.png | ppmtobmp > $name.bmp
110pngtopnm $tmpdir/mask.png | pnminvert | ppmtobmp > $name-mask.bmp
111# imagemagick works ok for xpm though
112convert $tmpdir/binalpha.png $name.xpm
113
114# Suppress the icons Ulf is using to highlight errors
115echo 'map-icons/classic.big/misc/deprecated.png:0:0:1:1
116map-icons/square.big/misc/deprecated.png:0:0:1:1
117map-icons/classic.small/misc/deprecated.png:0:0:1:1
118map-icons/square.small/misc/deprecated.png:0:0:1:1
119map-icons/classic.big/misc/no_icon.png:0:0:1:1
120map-icons/square.big/misc/no_icon.png:0:0:1:1
121map-icons/classic.small/misc/no_icon.png:0:0:1:1
122map-icons/square.small/misc/no_icon.png:0:0:1:1' >> $name.csv
123
124rm -r $tmpdir
125
126
Note: See TracBrowser for help on using the repository browser.