summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncan Laurie <dlaurie@chromium.org>2012-08-14 10:39:13 -0700
committerDuncan Laurie <dlaurie@chromium.org>2012-08-14 10:51:00 -0700
commit5a78b41378f983720536f38fe3ea6ec73722ef30 (patch)
tree0fedc1532f20457d6bcb476060c9d11944f6999c
parent1646b2d0acd935e6e63492e65ab1822a1ff3aa71 (diff)
downloadvboot-5a78b41378f983720536f38fe3ea6ec73722ef30.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. Old-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> (cherry picked from commit 69742668297ac9e5e82f0dbb704a3714bd0cba62) Change-Id: Ia0527b665ca032e08b2d11e6699e2f1f738ba9b4 Signed-off-by: Duncan Laurie <dlaurie@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/30245
-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
}