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

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

Script for making all 58 bboxes from the planet file

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