]> de.git.xonotic.org Git - xonotic/mediasource.git/blob - gfx/crosshairs/luma/render-crosshairs.sh
Merge branch 'sev/luma-filters' into 'master'
[xonotic/mediasource.git] / gfx / crosshairs / luma / render-crosshairs.sh
1 #!/bin/sh -e
2 # TASK
3 #   Render crosshairs from gfx/crosshair*.svg to DATADIR/gfx/crosshair*.tga,
4 #   if they are newer than their target tga file.
5 #
6 # NOTES
7 #   To compensate for filter rendering errors and to reduce rbg noise,
8 #   the svg files are rendered at a large size and then scaled down.
9 #
10 # DEPENDENCIES
11 #   rsvg-convert (librsvg)
12 #   convert (imagemagick)
13 #
14 # USAGE
15 #   ./render-svg.sh DATADIR
16 #
17 # USAGE EXAMPLE
18 #   ./render-crosshairs.sh ~/.xonotic/data
19
20
21 # Check for argument
22 if [ -z "$1" ]; then
23         echo "Usage: $0 DATADIR"
24         exit 1
25 fi
26
27
28 data="$1"; shift
29 maxScale=8
30 maxPixels=100000000
31
32
33 for svg in gfx/*.svg; do
34         ext="${svg##*.}"
35         dir="$data/${svg%/*}"
36         tga="$data/${svg%.*}.tga"
37
38         if [ "$ext" = "svg" ] && [ -f "$svg" ] && [ "$svg" -nt "$tga" ]; then
39                 echo "Rendering $tga"
40
41                 w=$(identify -format "%w" "$svg")
42                 h=$(identify -format "%h" "$svg")
43                 scale=$(echo "s=sqrt($maxPixels/$w/$h);if(s>$maxScale)s=$maxScale;s" | bc)
44
45                 mkdir -p "$dir"
46                 rsvg-convert -z "$scale" "$svg" | convert - -scale "$w" "$tga"
47         fi
48 done