From 4e4ed8bc96ee2947c77d778ce04f449fc54c963d Mon Sep 17 00:00:00 2001 From: Hung-Te Lin Date: Tue, 7 Aug 2012 18:34:36 +0800 Subject: [PATCH] Generates x86 and arm firmware bitmap blocks. X86 (coreboot) uses 800x600 resolution while ARM systems (uboot) initialze LCD as its maximum size, so we must refine the bmpblk build scripts to generate output with different scaling parameters. BUG=chrome-os-partner:11078 TEST=make # got ARM bmpblock and verified to work on daisy. Change-Id: Ib9e9a0dc3b6695cef451772391f207a5b57977df Reviewed-on: https://gerrit.chromium.org/gerrit/29606 Reviewed-by: Dave Parker Reviewed-by: Bill Richardson Commit-Ready: Hung-Te Lin Tested-by: Hung-Te Lin Reviewed-by: Tom Wai-Hong Tam --- .gitignore | 4 + scripts/newbitmaps/Makefile | 23 +++--- scripts/newbitmaps/fonts/make_ascii_bmps.py | 1 + scripts/newbitmaps/images/Makefile | 75 ++--------------- scripts/newbitmaps/images/build_images | 90 +++++++++++++++++++++ scripts/newbitmaps/images/make_default_yaml | 6 +- 6 files changed, 115 insertions(+), 84 deletions(-) create mode 100755 scripts/newbitmaps/images/build_images diff --git a/.gitignore b/.gitignore index 089802ed9e..b2f7a2eabc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ /build-au /build-main ID +scripts/newbitmaps/lib/*.pyc +scripts/newbitmaps/strings/localized_text/*/*.png +scripts/newbitmaps/fonts/outdir +scripts/newbitmaps/images/out_* diff --git a/scripts/newbitmaps/Makefile b/scripts/newbitmaps/Makefile index 70435fc574..90c4a56011 100644 --- a/scripts/newbitmaps/Makefile +++ b/scripts/newbitmaps/Makefile @@ -13,7 +13,7 @@ ALL_LOCALES=en es_419 pt_BR en_GB fr es pt_PT ca it de \ # Here are the launch locales for Stumpy/Lumpy (issue 6595), same ordering. DEFAULT_LOCALES=en es_419 pt_BR en_GB fr es it de nl da no sv ko ja -default: outside_chroot fonts x86 arm clean +default: outside_chroot fonts strings x86 arm clean outside_chroot: @if [ -e /etc/debian_chroot ]; then \ @@ -25,25 +25,24 @@ outside_chroot: fonts: + # TODO(hungte) Move fonts generation to its own Makefile. cd fonts && ./make_ascii_bmps.py bmpblk_font --outfile images/hwid_fonts.bin fonts/outdir/* +strings: + $(MAKE) -C strings/localized_text + x86: - $(MAKE) -C strings/localized_text PT=15 - cd strings/localized_text && tar cf temp.tar */*.bmp - mkdir -p images/out_$@/localized_images - cd images/out_$@/localized_images && \ - tar xf ../../../strings/localized_text/temp.tar $(MAKE) -C images $@ DEFAULT_LOCALES="$(DEFAULT_LOCALES)" cp -f images/out_$@/bmpblock.bin bmpblock_$@.bin arm: - @echo "FIXME: ARM bitmaps are not yet autogenerated" + $(MAKE) -C images $@ DEFAULT_LOCALES="$(DEFAULT_LOCALES)" + cp -f images/out_$@/bmpblock.bin bmpblock_$@.bin clean: - rm -rf fonts/outdir strings/localized_text/*/*.bmp \ - strings/localized_text/temp.tar \ - images/localized_images \ - images/out_x86 images/out_arm + rm -rf fonts/outdir + $(MAKE) -C strings/localized_text clean + $(MAKE) -C images clean -.PHONY: outside_chroot fonts x86 arm +.PHONY: outside_chroot fonts strings x86 arm diff --git a/scripts/newbitmaps/fonts/make_ascii_bmps.py b/scripts/newbitmaps/fonts/make_ascii_bmps.py index 27b50110d8..8d58849da5 100755 --- a/scripts/newbitmaps/fonts/make_ascii_bmps.py +++ b/scripts/newbitmaps/fonts/make_ascii_bmps.py @@ -61,6 +61,7 @@ def main(): for ascii in chars: outfile = os.path.join(options.outdir, "idx%03d_%x.bmp" % (count,ord(ascii))) + # TODO(hungte) Support assigning size & scaling for character images. print outfile cmd = ('convert', '-font', options.font, diff --git a/scripts/newbitmaps/images/Makefile b/scripts/newbitmaps/images/Makefile index b22608d4d4..b36b8c0bcd 100644 --- a/scripts/newbitmaps/images/Makefile +++ b/scripts/newbitmaps/images/Makefile @@ -18,18 +18,13 @@ DEFAULT_LOCALES=en es_419 pt_BR en_GB fr es pt_PT ca it de \ el nl da no sv fi et lv lt ru pl cs sk hu sl sr hr bg ro \ uk tr iw ar fa hi th vi id fil zh_CN zh_TW ko ja -BACKGROUND_IMAGE=Background_white.bmp -GRAYSCALE_IMAGES=arrow_left.bmp arrow_right.bmp divider_top.bmp divider_btm.bmp -OTHER_IMAGES=Devmode_graphic.bmp Insert_graphic.bmp Remove_graphic.bmp \ - Yuck_graphic.bmp Url.bmp hwid_unknown.bmp chrome_logo.bmp - -FONTS=hwid_fonts.bin - default: outside_chroot @echo "Specify a target to build for:" @echo " ${TARGETS}" outside_chroot: + # TODO(hungte) It's now not easy to have bmpblk_utility outside + # chroot... We need some better way to do this. @if [ -e /etc/debian_chroot ]; then \ echo "ImageMagick is too complex to build inside the chroot."; \ echo "You must be outside the chroot to do this"; \ @@ -39,76 +34,18 @@ outside_chroot: ${TARGETS}:: outside_chroot - -# The image size with UEFI BIOS is always 800x600, which is stretched to fill -# the entire screen. With previous devices the physical screen size was either -# 1280x800 (16:10) or 1366x768 (16:9). There's not a lot of difference between -# those, so let's just assume 16:9 for future platforms to make things simpler. -_x86_max=800x600! -_x86_scale=59%x78% -_x86_opts=-colors 256 -compress none -alpha off -_arm_max=800x600! -_arm_scale=59%x78% - x86:: - # create output directories - mkdir -p "out_$@" - # copy stuff we need - cp "${FONTS}" "out_$@" - # Scale and preserve the 256 color index of background image - echo " out_$@/${BACKGROUND_IMAGE}" && \ - convert ${BACKGROUND_IMAGE} -scale '${_x86_max}' ${_x86_opts} \ - -remap gradient.png "BMP3:out_$@/${BACKGROUND_IMAGE}" || \ - exit 1; - # Preserve the 256 color index of grayscale images - @for i in ${GRAYSCALE_IMAGES}; do \ - echo " out_$@/$$i" && \ - convert $$i -scale '${_x86_scale}' ${_x86_opts} \ - -remap gradient.png "BMP3:out_$@/$$i" || \ - exit 1; \ - done - @for i in ${OTHER_IMAGES}; do \ - echo " out_$@/$$i" && \ - convert $$i -scale '${_x86_scale}' ${_x86_opts} \ - "BMP3:out_$@/$$i" || \ - exit 1; \ - done - # produce the new yaml + ./build_images "$@" cd "out_$@" && ../make_default_yaml ${DEFAULT_LOCALES} cd "out_$@" && bmpblk_utility -c DEFAULT.yaml bmpblock.bin ls -l "out_$@"/bmpblock.bin arm:: - # create output directories - mkdir -p "out_$@" - for i in localized_images/*; do \ - mkdir -p "out_$@/$$i"; \ - done - # copy stuff we need - cp "${FONTS}" "out_$@" - convert ${BACKGROUND_IMAGE} -append \ - -colors 256 -unique-colors "out_$@/base_cmap.png" - convert localized_images/*/*.bmp -append \ - -colors 256 -unique-colors "out_$@/loc_cmap.png" - # scale the background exactly... - echo " out_$@/${BACKGROUND_IMAGE}"; \ - convert ${BACKGROUND_IMAGE} -scale "${_arm_max}" \ - -remap "out_$@/base_cmap.png" "out_$@/${BACKGROUND_IMAGE}"; \ - done - # scale the localized string images using percentages... - @for i in ${GRAYSCALE_IMAGES} ${OTHER_IMAGES} localized_images/*/*.bmp; do \ - echo " out_$@/$$i"; \ - convert $$i -scale "${_arm_scale}" \ - -remap "out_$@/loc_cmap.png" "out_$@/$$i"; \ - done - # produce the new yaml + ./build_images "$@" cd "out_$@" && ../make_default_yaml ${DEFAULT_LOCALES} - perl -i -p -e 's/^compression:.*/compression: 2/;' "out_$@/DEFAULT.yaml" - # Note: manually use bmpblk_utility to create the binary from out_$@ - - - + cd "out_$@" && bmpblk_utility -c DEFAULT.yaml bmpblock.bin + ls -l "out_$@"/bmpblock.bin clean: rm -rf out_* diff --git a/scripts/newbitmaps/images/build_images b/scripts/newbitmaps/images/build_images new file mode 100755 index 0000000000..9245d0f092 --- /dev/null +++ b/scripts/newbitmaps/images/build_images @@ -0,0 +1,90 @@ +#!/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.bmp + +die() { + echo "$*" >&2 + exit 1 +} + +convert_to_bmp3() { + local input="$1" + local folder="$2" + local param="$3" + local output="$(basename "$input")" + + # Always output as .bmp + output="${output%.*}.bmp" + mkdir -p "$folder" + + # TODO(hungte) Add -flatten to support converting images with transparency. + # Syntax: -background "$BACKGROUND_COLOR" -flatten + # (Currently conflicts with -colors that will create 1 bit /pixel images) + echo "$input -> $folder/$output" + convert "$input" \ + -compress none -alpha off -colors 256 \ + $param "BMP3:$folder/$output" +} + +main() { + local profile="$1" + local output="out_$1" + local scale_param="" background_scale_param="" + local base locale X + + # Currently we use image resources originally designed for 1366x768, and + # re-scale to different aspects on demand. + case "$profile" in + x86 ) + # The image size with x86 UEFI BIOS (also applies to coreboot) is always + # 800x600, which is stretched to fill the entire screen. With previous + # devices the physical screen size was either 1280x800 (16:10) or 1366x768 + # (16:9). There's not a lot of difference between those, so let's just + # assume 16:9 for future platforms to make things simpler. + scale_param="-scale 59%x78%" + background_scale_param="-scale 800x600!" + ;; + arm ) + # On ARM platforms, we need to provide a bitmap with full size. + # TODO(hungte) Support more profiles, ex 1280x800. + true + ;; + * ) + die "Sorry, unknown profile $profile." + esac + + # Prepare output folder + mkdir -p "$output" + cp hwid_fonts.bin "$output" + + # Prepare images in current folder + # TODO(hungte) Deprecate arrow*.bmp by markup ◀ and ▶, and + # Url.bmp by http://. + for X in *.bmp *.png; do + if [ "$X" = "$BACKGROUND_IMAGE" ]; then + convert_to_bmp3 "$X" "$output" "$background_scale_param" + else + convert_to_bmp3 "$X" "$output" "$convert_param" + fi + done + + # Prepares localized images + base="../strings/localized_text" + for X in $base/*/*.png; do + locale="$(basename $(dirname $X))" + convert_to_bmp3 "$X" "$output/locale/$locale" "$scale_param" + done +} + +set -e +main "$@" + diff --git a/scripts/newbitmaps/images/make_default_yaml b/scripts/newbitmaps/images/make_default_yaml index 529aa8bad9..44a6750b9c 100755 --- a/scripts/newbitmaps/images/make_default_yaml +++ b/scripts/newbitmaps/images/make_default_yaml @@ -10,7 +10,7 @@ yaml_file="DEFAULT.yaml" # I'm sorting the locales in more-or-less geographical order. Right should move # east, left should move west. Of course we'll start in the US. :-) locales="en es_419 pt_BR en_GB fr es pt_PT ca it de el nl da no sv fi et lv lt ru pl cs sk hu sl sr hr bg ro uk tr iw ar fa hi th vi id fil zh_CN zh_TW ko ja" -localedir="./localized_images" +localedir="./locale" # These render right-to-left rtol="ar fa iw" @@ -69,7 +69,7 @@ set_centered_y_percent() { # Return width of a .bmp file specified by a variable. get_width() { local filename="$(eval "echo \$$1")" - file ${filename} | awk '{print $7}' | sed -e 's/[^0-9]//g' + identify -format "%[fx:w]" "$filename" } # Return the width of a list of images. @@ -84,7 +84,7 @@ total_width() { # Return height of a .bmp file specified by a variable. get_height() { local filename="$(eval "echo \$${1}")" - file ${filename} | awk '{print $9}' | sed -e 's/[^0-9]//g' + identify -format "%[fx:h]" "$filename" } # Returns the max height of a list of images.