summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2012-08-10 16:37:38 +0800
committerGerrit <chrome-bot@google.com>2012-08-10 11:18:52 -0700
commit69742668297ac9e5e82f0dbb704a3714bd0cba62 (patch)
tree5cf6839e324fa48a7fb1bb7c2df7eb0d7c30422f
parent1eb883dce6eb96be984a1155e5a6011e637979b9 (diff)
downloadvboot-69742668297ac9e5e82f0dbb704a3714bd0cba62.tar.gz
newbitmaps: Always generate bitmaps in 8bpp mode.
ImageMagick may produce 1bpp mode for background if the image is modified (ex, x86 output). We need to ensure the output to be 8bpp mode for firmware to render images correctly. BUG=chrome-os-partner:11078 TEST=make x86 # all images are in 8bpp mode. Change-Id: Ia6e4fbc5e7580ebbb51e1067bcf554ee06f1fbc5 Reviewed-on: https://gerrit.chromium.org/gerrit/29868 Tested-by: Hung-Te Lin <hungte@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Ready: Hung-Te Lin <hungte@chromium.org>
-rwxr-xr-xscripts/newbitmaps/images/build_images36
1 files changed, 29 insertions, 7 deletions
diff --git a/scripts/newbitmaps/images/build_images b/scripts/newbitmaps/images/build_images
index 9245d0f0..7ce4db59 100755
--- a/scripts/newbitmaps/images/build_images
+++ b/scripts/newbitmaps/images/build_images
@@ -26,13 +26,34 @@ convert_to_bmp3() {
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" \
+ # When input has Alpha channel, we need to fill the background properly
+ # otherwise ImageMagick will fill it with black. The operation (-flatten) is
+ # so slow so we only want to do that if the input source really has
+ # transparency.
+ if [ "$#" -gt 3 ]; then
+ flatten="$4"
+ else
+ # Auto-detect
+ if [ "$(identify -format "%A" "$input")" = "True" ]; then
+ flatten="-background $BACKGROUND_COLOR -flatten"
+ else
+ flatten=""
+ fi
+ fi
+
+ echo "$input -> $folder/$output $flatten"
+ convert "$input" $flatten \
-compress none -alpha off -colors 256 \
$param "BMP3:$folder/$output"
+
+ # ImageMagic quantization may choose arbitrary color depth, even if we assign
+ # -depth or -colors; so a single-color background may become 1 bit per pixel
+ # after convertion. To workaround that, we use Python Image Library which
+ # always generates 8bpp BMP file.
+ # TODO(hungte) Find a better way to decide if PIL is required. Unfortunately,
+ # ImageMagic identify "%z" is not always what we're looking for...
+ local fn="$folder/$output"
+ python -c "import Image; Image.open('$fn').convert('P').save('$fn')"
}
main() {
@@ -77,11 +98,12 @@ main() {
fi
done
- # Prepares localized images
+ # Prepares localized images. All these images were rendered by pango-view and
+ # should not have transparency, so we specify flatten="" to speed up.
base="../strings/localized_text"
for X in $base/*/*.png; do
locale="$(basename $(dirname $X))"
- convert_to_bmp3 "$X" "$output/locale/$locale" "$scale_param"
+ convert_to_bmp3 "$X" "$output/locale/$locale" "$scale_param" ""
done
}