summaryrefslogtreecommitdiff
path: root/scripts/newbitmaps/images/build_images
blob: 35f2c813b82dc8c8f8bb0c868d1466db3dc4bcc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/sh
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Prepares image resources into output folder.

# Composition settings
BACKGROUND_COLOR=white

# The only file that uses different scaling parameter.
BACKGROUND_IMAGE=Background_white.png

# Output file name.
BMPBLK_OUTPUT="bmpblock.bin"

SCRIPT_BASE="$(dirname $(readlink -f "$0"))"

die() {
  echo "ERROR: $*" >&2
  exit 1
}

convert_to_bmp3() {
  local folder="$1"
  local param="$2"
  shift
  shift

  # convert_to_bmp3.py takes '--scale' while ImageMagic takes '-scale'.
  [ -n "$param" ] && param="-$param"

  $SCRIPT_BASE/convert_to_bmp3.py $param --outdir "$folder" "$@"
}

main() {
  local profile="$1"
  local output="out_$1"
  local scale_param="" background_scale_param="" replace_files=""
  local base locale X

  # TODO(hungte) Derive and calculate profile params automatically.

  # Currently we use image resources originally designed for 1366x768, and
  # re-scale to different aspects on demand.
  case "$profile" in
    std )
      # Standard: profile with all default values.
      true
      ;;

    # Native profiles

    n1366 )
      # "Native 1366x768" resolution.
      background_scale_param="-scale 1366x768!"
      ;;

    n1366usb )
      # Similar to n1366, and can only boot recovery by USB.
      background_scale_param="-scale 1366x768!"
      replace_files="insert=insert_usb BadSD=dummy RemoveDevices=RemoveUSB"
      ;;

    n1366sdusb2 )
      # Similar to n1366, and can only boot recovery by SD card or USB2.
      background_scale_param="-scale 1366x768!"
      replace_files="insert=insert_sd_usb2"
      ;;

    # Stretched profiles

    s800 )
      # "Streched 800x600". Designed for x86 UEFI BIOS (and coreboot), which
      # always puts display into VESA 800x600 16-bit mode (0x0114), and is
      # stretched to fill the entire screen.
      scale_param="-scale 59%x78%"
      background_scale_param="-scale 800x600!"
      ;;

    s1024 )
      # Similar to s800, using VESA graphics mode 1024x768 (0x0117).
      scale_param="-scale 75%x100%"
      background_scale_param="-scale 1024x768!"
      ;;

    s1024usb )
      # Similar to s1024, and can only boot recovery by USB2. (No card reader,
      # not not able to recover from card reader.)
      scale_param="-scale 75%x100%"
      background_scale_param="-scale 1024x768!"
      replace_files="insert=insert_usb BadSD=dummy RemoveDevices=RemoveUSB"
      ;;

    s1024usb2 )
      # Similar to s1024, and can only boot recovery by USB2.
      scale_param="-scale 75%x100%"
      background_scale_param="-scale 1024x768!"
      replace_files="insert=insert_usb2 BadSD=dummy RemoveDevices=RemoveUSB"
      ;;

    s1024sdusb2 )
      # Similar to s1024, and can only boot recovery by SD card or USB2.
      scale_param="-scale 75%x100%"
      background_scale_param="-scale 1024x768!"
      replace_files="insert=insert_sd_usb2"
      ;;

    s1280a8x5 )
      # Similar to s1024, using VESA graphics mode 1280x1024 (0x011A), and
      # adjusted for aspect ratio 8x5 panels.
      background_scale_param="-scale 1280x1024!"
      scale_param="-scale 94%x119%"  # 119% = 133% * (1.6 / 1.78)
      ;;

    s1280x850a8x5 )
      # Similar to s1280a8x5, using graphics mode 1280x850.
      background_scale_param="-scale 1280x850!"
      scale_param="-scale 94%x99%" # 99% = 110% * (1.6 / 1.78)
      ;;

    * )
      die "Sorry, unknown profile $profile."
  esac

  # Prepare output folder
  rm -rf "$output"
  mkdir -p "$output"

  # Prepare images in current folder
  # TODO(hungte) Deprecate arrow*.bmp by markup ◀ and ▶, and
  # Url.bmp by <span foreground="blue">http://</span>.
  for X in *.png assets/*.png; do
    if [ "$X" = "$BACKGROUND_IMAGE" ]; then
      convert_to_bmp3 "$output" "$background_scale_param" "$X"
    else
      convert_to_bmp3 "$output" "$scale_param" "$X"
    fi
  done

  # Prepares strings and localized images. All these images were rendered by
  # pango-view and should not have transparency, so we specify flatten="" to
  # speed up.
  echo "Preparing common strings..."
  base="../strings"
  convert_to_bmp3 "$output" "$scale_param" $base/*.png

  echo "Preparing localized messages... $LOCALES"
  base="../strings/localized_text"
  if [ -z "$LOCALES" ]; then
    # Collect all locales
    for X in $(cd $base; ls); do
      if [ -d "$base/$X" ]; then
        LOCALES="${LOCALES}${X} "
      fi
    done
    echo "Found locales: $LOCALES"
  fi
  for locale in $LOCALES; do
    # Prepare all locales.
    convert_to_bmp3 "$output/locale/$locale" "$scale_param" $base/$locale/*.png
  done

  if [ -n "$replace_files" ]; then
    echo "Replacing files..."
    echo "$replace_files" | tr ' ' '\n' | while read X; do
      local Xdest="${X%%=*}" Xsrc="${X##*=}" Xfile=""
      echo " $Xsrc => $Xdest"
      for Xfile in $(find "$output" -name "$Xsrc.bmp"); do
        echo "  * $Xfile"
        mv "$Xfile" "$(dirname "$Xfile")/$Xdest.bmp"
      done
    done
  fi

  echo "Preparing fonts..."
  base="../strings/font"
  convert_to_bmp3 "$output/font" "$scale_param" $base/*.png
  bmpblk_font --outfile "$output/hwid_fonts.bin" "$output"/font/*.bmp

  # Create YAML file.
  (cd "$output" && ../make_default_yaml $LOCALES)

  # Compile bitmap block file.
  (cd "$output" && bmpblk_utility -c DEFAULT.yaml $BMPBLK_OUTPUT)
  ls -l "$output/$BMPBLK_OUTPUT"
}

set -e
main "$@"