| OLD | NEW |
| 1 #!/bin/bash -e | 1 #!/bin/bash -e |
| 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 # | 5 # |
| 6 # This adds text to our non-labeled recovery images. | 6 # This adds text to our non-labeled recovery images. |
| 7 # | 7 # |
| 8 # The source images should be 1366x800, with the expectation they'll be cropped | 8 # The source images should be 1366x800, with the expectation they'll be cropped |
| 9 # to 1366x768 or 1280x800, have 2 lines of text overlayed at the bottom, and | 9 # to 1366x768 or 1280x800, have 2 lines of text overlayed at the bottom, and |
| 10 # then be resized to 800x600 so that the BIOS can then display them stretched | 10 # then be resized to 800x600 so that the BIOS can then display them stretched |
| 11 # to the full screen size. | 11 # to the full screen size. |
| 12 # | 12 # |
| 13 | 13 |
| 14 | 14 |
| 15 | 15 |
| 16 | 16 |
| 17 # Require one arg | 17 # Require one arg |
| 18 if [ $# -ne "1" ]; then | 18 if [ $# -ne "2" ]; then |
| 19 echo "Usage: $(basename $0) MODEL" 1>&2 | 19 echo "Usage: $(basename $0) <MODEL> <screen geometry>" 1>&2 |
| 20 exit 1 | 20 exit 1 |
| 21 fi | 21 fi |
| 22 MODEL=$1 | 22 MODEL=$1 |
| 23 geom_crop=$2 |
| 24 |
| 25 nicename=${MODEL// /_} |
| 23 | 26 |
| 24 # Default URL | 27 # Default URL |
| 25 URL='http://google.com/chromeos/recovery' | 28 URL='http://google.com/chromeos/recovery' |
| 26 | 29 |
| 27 | |
| 28 # Image parameters | 30 # Image parameters |
| 29 geom_orig='1366x800' | 31 geom_orig='1366x800' |
| 30 geom_crop_a='1366x768' | |
| 31 geom_crop_b='1280x800' | |
| 32 geom_final='800x600!' | 32 geom_final='800x600!' |
| 33 bluecolor='#9ccaec' | 33 bluecolor='#9ccaec' |
| 34 bluefont="Helvetica-Narrow" | 34 bluefont="Helvetica-Narrow" |
| 35 bluepointsize=30 | 35 bluepointsize=30 |
| 36 whitefont="Helvetica-Narrow" | 36 whitefont="Helvetica-Narrow" |
| 37 whitepointsize=48 | 37 whitepointsize=48 |
| 38 | 38 |
| 39 | 39 |
| 40 # Temporary files | 40 # Temporary files |
| 41 tmpdir=$(mktemp -d /tmp/tmp.XXXXXXXXX) | 41 tmpdir=$(mktemp -d /tmp/tmp.bmp.XXXXXX) |
| 42 trap "rm -rf $tmpdir" EXIT | 42 trap "rm -rf $tmpdir" EXIT |
| 43 img_orig="${tmpdir}/img_orig.bmp" | 43 img_orig="${tmpdir}/img_orig.bmp" |
| 44 img_crop_a="${tmpdir}/img_crop_a.bmp" | 44 img_crop="${tmpdir}/img_crop.bmp" |
| 45 img_crop_b="${tmpdir}/img_crop_b.bmp" | 45 img_txt="${tmpdir}/img_txt.bmp" |
| 46 img_txt_a="${tmpdir}/img_txt_a.bmp" | |
| 47 img_txt_b="${tmpdir}/img_txt_b.bmp" | |
| 48 label_file="${tmpdir}/label.txt" | 46 label_file="${tmpdir}/label.txt" |
| 49 label_img="${tmpdir}/label.bmp" | 47 label_img="${tmpdir}/label.bmp" |
| 50 | 48 |
| 51 # Output directories | 49 # Output directories |
| 52 thisdir=$(readlink -e $(dirname $0)) | 50 thisdir=$(readlink -e $(dirname $0)) |
| 53 outdir_a=${thisdir}/out_${geom_crop_a} | 51 outdir="${thisdir}/out_${nicename}" |
| 54 [ -d "$outdir_a" ] || mkdir -p "$outdir_a" | 52 [ -d "$outdir" ] || mkdir -p "$outdir" |
| 55 outdir_b=${thisdir}/out_${geom_crop_b} | |
| 56 [ -d "$outdir_b" ] || mkdir -p "$outdir_b" | |
| 57 | |
| 58 | 53 |
| 59 function find_background_color { | 54 function find_background_color { |
| 60 src_img=$1 | 55 src_img=$1 |
| 61 convert "$src_img" -crop '1x1+10+10!' txt:- | \ | 56 convert "$src_img" -crop '1x1+10+10!' txt:- | \ |
| 62 perl -n -e 'print "$1" if m/(#[0-9a-f]+)/i;' | 57 perl -n -e 'print "$1" if m/(#[0-9a-f]+)/i;' |
| 63 } | 58 } |
| 64 | 59 |
| 65 function process_one_file { | 60 function process_one_file { |
| 66 src_img=$1 | 61 src_img=$1 |
| 67 | 62 |
| 68 # Figure out the filenames to use | 63 # Figure out the filenames to use |
| 69 txt_file=${src_img%*.gif}.txt | 64 txt_file=${src_img%*.gif}.txt |
| 70 root=$(basename "$src_img") | 65 root=$(basename "$src_img") |
| 71 root=${root%*.*} | 66 root=${root%*.*} |
| 72 # one more layer of heirarchy to match BIOS source tree | 67 # one more layer of heirarchy to match BIOS source tree |
| 73 dst_dir_a="${outdir_a}/${root}" | 68 dst_dir="${outdir}/${root}" |
| 74 [ -d "$dst_dir_a" ] || mkdir -p "$dst_dir_a" | 69 [ -d "$dst_dir" ] || mkdir -p "$dst_dir" |
| 75 dst_dir_b="${outdir_b}/${root}" | 70 dst_img="${dst_dir}/${root}.bmp" |
| 76 [ -d "$dst_dir_b" ] || mkdir -p "$dst_dir_b" | |
| 77 dst_img_a="${dst_dir_a}/${root}.bmp" | |
| 78 dst_img_b="${dst_dir_b}/${root}.bmp" | |
| 79 echo "processing $root ..." | 71 echo "processing $root ..." |
| 80 | 72 |
| 81 # First, make sure we start with the right-size original | 73 # First, make sure we start with the right-size original |
| 82 bg=$(find_background_color "$src_img") | 74 bg=$(find_background_color "$src_img") |
| 83 convert "$src_img" -background "$bg" \ | 75 convert "$src_img" -background "$bg" \ |
| 84 -gravity center -extent $geom_orig "$img_orig" | 76 -gravity center -extent $geom_orig "$img_orig" |
| 85 | 77 |
| 86 # Now crop that to the two target sizes | 78 # Now crop that to the two target sizes |
| 87 convert "$img_orig" -gravity Center \ | 79 convert "$img_orig" -gravity Center \ |
| 88 -crop "$geom_crop_a"+0+0 +repage "$img_crop_a" | 80 -crop "$geom_crop"+0+0 +repage "$img_crop" |
| 89 convert "$img_orig" -gravity Center \ | |
| 90 -crop "$geom_crop_b"+0+0 +repage "$img_crop_b" | |
| 91 | 81 |
| 92 # Add the labels in | 82 # Add the labels in |
| 93 if [ -r "$txt_file" ]; then | 83 if [ -r "$txt_file" ]; then |
| 94 # The only way to change font and color in multiline text is to split each | 84 # The only way to change font and color in multiline text is to split each |
| 95 # line into a separate image and then composite them together. Ugh. | 85 # line into a separate image and then composite them together. Ugh. |
| 96 # First, split each input line into a separate file. | 86 # First, split each input line into a separate file. |
| 97 "${thisdir}/makelines" -u "$URL" -m "$MODEL" -d "$tmpdir" "$txt_file" | 87 "${thisdir}/makelines" -u "$URL" -m "$MODEL" -d "$tmpdir" "$txt_file" |
| 98 # Convert each line file into an image file. | 88 # Convert each line file into an image file. |
| 99 for txtfile in ${tmpdir}/linetxt_*; do | 89 for txtfile in ${tmpdir}/linetxt_*; do |
| 100 case "$txtfile" in | 90 case "$txtfile" in |
| (...skipping 10 matching lines...) Expand all Loading... |
| 111 -font "$whitefont" -pointsize "$whitepointsize" \ | 101 -font "$whitefont" -pointsize "$whitepointsize" \ |
| 112 -bordercolor "$bg" -border 0x10 \ | 102 -bordercolor "$bg" -border 0x10 \ |
| 113 label:'@'"$txtfile" "${txtfile%.*}".bmp | 103 label:'@'"$txtfile" "${txtfile%.*}".bmp |
| 114 ;; | 104 ;; |
| 115 esac | 105 esac |
| 116 done | 106 done |
| 117 # Now bash them all together to make one image. | 107 # Now bash them all together to make one image. |
| 118 convert -background "$bg" -gravity center ${tmpdir}/linetxt_*.bmp \ | 108 convert -background "$bg" -gravity center ${tmpdir}/linetxt_*.bmp \ |
| 119 label:'\n\n\n\n' -append "$label_img" | 109 label:'\n\n\n\n' -append "$label_img" |
| 120 # Finally, layer the label image on top of the original. | 110 # Finally, layer the label image on top of the original. |
| 121 composite "$label_img" -gravity south "$img_crop_a" "$img_txt_a" | 111 composite "$label_img" -gravity south "$img_crop" "$img_txt" |
| 122 composite "$label_img" -gravity south "$img_crop_b" "$img_txt_b" | |
| 123 else | 112 else |
| 124 mv "$img_crop_a" "$img_txt_a" | 113 mv "$img_crop" "$img_txt" |
| 125 mv "$img_crop_b" "$img_txt_b" | |
| 126 fi | 114 fi |
| 127 | 115 |
| 128 # Now scale the result to the final size | 116 # Now scale the result to the final size |
| 129 convert "$img_txt_a" -scale "$geom_final" -alpha off "$dst_img_a" | 117 convert "$img_txt" -scale "$geom_final" -alpha off "$dst_img" |
| 130 convert "$img_txt_b" -scale "$geom_final" -alpha off "$dst_img_b" | |
| 131 } | 118 } |
| 132 | 119 |
| 133 | 120 |
| 134 # Do it. | 121 # Do it. |
| 135 for file in originals/*.gif; do | 122 for file in originals/*.gif; do |
| 136 process_one_file "$file" | 123 process_one_file "$file" |
| 137 done | 124 done |
| 138 | 125 |
| 139 # Zip up the bitmaps | 126 # Zip up the bitmaps |
| 140 nicename=${MODEL// /_} | 127 (cd "$outdir" && zip -qr "${geom_crop}.zip" *) |
| 141 (cd "$outdir_a" && zip -qr "${thisdir}/out_${nicename}__${geom_crop_a}.zip" *) | |
| 142 (cd "$outdir_b" && zip -qr "${thisdir}/out_${nicename}__${geom_crop_b}.zip" *) | |
| OLD | NEW |