vendor: omni: use specific resolution for bootanimation

the original idea came from this patch
https://github.com/CyanogenMod/android_vendor_cm/commit/367e64830fde67dc689d56e733c85dfbb30b8ae1

PS2:
-added hdmi and qhd

PS3:
-use correct geometry to match landscape

PS4:
-use resolution as geometry

PS5|6:
-fix code style

PS7:
-add 720x480
     840x560
     960x640

PS8:
-add 2560x1440

PS9:
-use TARGET_BOOTANIMATION_SIZE instead of TARGET_BOOTANIMATION_NAME

Signed-off-by: Humberto Borba <humberos@gmail.com>
Change-Id: I36ca35dbdb638cc29f29cf2a2c619c3cbd3c1034
diff --git a/config/common.mk b/config/common.mk
index 15d526c..aa00a95 100644
--- a/config/common.mk
+++ b/config/common.mk
@@ -1,12 +1,12 @@
 PRODUCT_BRAND ?= omni
 
-# bootanimation (Some devices cant go over 100fps for a bootani)
-ifneq ($(USE_LOWFPS_BOOTANI),true)
+# use specific resolution for bootanimation
+ifneq ($(TARGET_BOOTANIMATION_SIZE),)
 PRODUCT_COPY_FILES += \
-    vendor/omni/prebuilt/bootanimation/bootanimation.zip:system/media/bootanimation.zip
+    vendor/omni/prebuilt/bootanimation/res/$(TARGET_BOOTANIMATION_SIZE).zip:system/media/bootanimation.zip
 else
 PRODUCT_COPY_FILES += \
-    vendor/omni/prebuilt/bootanimation/lowfps-bootanimation.zip:system/media/bootanimation.zip
+    vendor/omni/prebuilt/bootanimation/bootanimation.zip:system/media/bootanimation.zip
 endif
 
 ifeq ($(PRODUCT_GMS_CLIENTID_BASE),)
diff --git a/prebuilt/bootanimation/lowfps-bootanimation.zip b/prebuilt/bootanimation/lowfps-bootanimation.zip
deleted file mode 100644
index 5c1d0b9..0000000
--- a/prebuilt/bootanimation/lowfps-bootanimation.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/bootanimation/res/1080x720.zip b/prebuilt/bootanimation/res/1080x720.zip
new file mode 100644
index 0000000..cc12117
--- /dev/null
+++ b/prebuilt/bootanimation/res/1080x720.zip
Binary files differ
diff --git a/prebuilt/bootanimation/res/1440x960.zip b/prebuilt/bootanimation/res/1440x960.zip
new file mode 100644
index 0000000..d3dc477
--- /dev/null
+++ b/prebuilt/bootanimation/res/1440x960.zip
Binary files differ
diff --git a/prebuilt/bootanimation/res/2560x1440.zip b/prebuilt/bootanimation/res/2560x1440.zip
new file mode 100644
index 0000000..8f16834
--- /dev/null
+++ b/prebuilt/bootanimation/res/2560x1440.zip
Binary files differ
diff --git a/prebuilt/bootanimation/res/360x240.zip b/prebuilt/bootanimation/res/360x240.zip
new file mode 100644
index 0000000..c21086f
--- /dev/null
+++ b/prebuilt/bootanimation/res/360x240.zip
Binary files differ
diff --git a/prebuilt/bootanimation/res/420x280.zip b/prebuilt/bootanimation/res/420x280.zip
new file mode 100644
index 0000000..09848a0
--- /dev/null
+++ b/prebuilt/bootanimation/res/420x280.zip
Binary files differ
diff --git a/prebuilt/bootanimation/res/480x320.zip b/prebuilt/bootanimation/res/480x320.zip
new file mode 100644
index 0000000..856e777
--- /dev/null
+++ b/prebuilt/bootanimation/res/480x320.zip
Binary files differ
diff --git a/prebuilt/bootanimation/res/720x480.zip b/prebuilt/bootanimation/res/720x480.zip
new file mode 100644
index 0000000..ed33459
--- /dev/null
+++ b/prebuilt/bootanimation/res/720x480.zip
Binary files differ
diff --git a/prebuilt/bootanimation/res/840x560.zip b/prebuilt/bootanimation/res/840x560.zip
new file mode 100644
index 0000000..2290646
--- /dev/null
+++ b/prebuilt/bootanimation/res/840x560.zip
Binary files differ
diff --git a/prebuilt/bootanimation/res/960x640.zip b/prebuilt/bootanimation/res/960x640.zip
new file mode 100644
index 0000000..3110565
--- /dev/null
+++ b/prebuilt/bootanimation/res/960x640.zip
Binary files differ
diff --git a/prebuilt/bootanimation/res/generate-packages.sh b/prebuilt/bootanimation/res/generate-packages.sh
new file mode 100755
index 0000000..8448105
--- /dev/null
+++ b/prebuilt/bootanimation/res/generate-packages.sh
@@ -0,0 +1,99 @@
+#!/bin/sh
+#
+# Copyright (C) 2015 OmniROM Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# cleanup screen
+clear;
+
+# resolutions
+# based on stock 600x400px Omni bootanimation (30fps)
+RESOLUTIONS="\
+    360x240 \
+    420x280 \
+    480x320 \
+    720x480 \
+    840x560 \
+    960x640 \
+    1080x720 \
+    1440x960 \
+    2560x1440 \
+    ";
+
+# resize image and set quality
+convert_image() {
+    convert "${1}" -resize "${2}" -quality ${3} tmp.jpg;
+    mv tmp.jpg "${1}";
+}
+
+# rewrite desc.txt
+rewrite_desc() {
+res=$(echo "${1}" | sed s/x/\ /)
+cat > desc.txt << EOF
+${res} 30
+p 1 0 Part0
+p 0 0 Part1
+EOF
+}
+
+# reading images
+for i in ${RESOLUTIONS}; do
+
+#   cleanup environment
+    rm -rf "${i}";
+    rm -rf "${i}.zip";
+
+#   create a temporary folder
+    mkdir -p "${i}";
+    cd ${i};
+
+    echo "============================================================";
+    echo "Resolution: ${i}"
+    echo "============================================================";
+    echo "Uncompressing bootanimation...";
+    unzip ../../bootanimation.zip > /dev/zero;
+
+    echo "Rewriting desc.txt...";
+    rewrite_desc "${i}"
+
+#   set image quality
+#   add an aggressive value for low resolutions
+    case "${i}" in
+        "360x240"|"420x280"|"480x320")
+            quality=80;
+        ;;
+        *)
+            quality=90;
+        ;;
+    esac
+
+    echo "Resizing images...";
+    for j in Part*/*.jpg; do
+        convert_image "${j}" "${i}" $quality;
+        echo -ne " ==> please wait...\r";
+    done
+
+    echo "";
+    echo "Compressing bootanimation...";
+    echo "";
+    zip -r0 ../${i}.zip . > /dev/zero;
+
+    sleep 1;
+    echo "Done";
+
+#   remove temporary folder
+    cd ..
+    rm -rf ${i}
+done