summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2012-08-10 16:37:38 +0800
committerDave Parker <dparker@chromium.org>2012-08-16 19:02:10 -0700
commit26a00c5ab7207fea7265bb8f082adc5182018221 (patch)
treec42b78f9f3adeb1f86a649d5b2cbea9d838a66e6
parent23c178e67146a6148be22665545b554d41dc9989 (diff)
downloadvboot-26a00c5ab7207fea7265bb8f082adc5182018221.tar.gz
Cherry-Pick: 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: I8e91c684e7029337c85b1e2b94dffaf8cbb6eff5 Original-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> Reviewed-on: https://gerrit.chromium.org/gerrit/30626 Reviewed-by: Hung-Te Lin <hungte@chromium.org> Tested-by: Dave Parker <dparker@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 7cf256b1..9f038680 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
}