vendor/bliss: New bootanimation handling

Keep largest size bootanimation extracted and size bootanimation during compile
handle half res and size to exact device specs

Change-Id: Iee32f18440ff955d13ed85b273e97cbd540721fc
Signed-off-by: Jackeagle <jackeagle102@gmail.com>
diff --git a/bootanimation/Android.mk b/bootanimation/Android.mk
new file mode 100644
index 0000000..19c51c4
--- /dev/null
+++ b/bootanimation/Android.mk
@@ -0,0 +1,23 @@
+# Copyright (C) 2016 The SlimRom Project
+# Copyright (C) 2017 The BlissRoms 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.
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+LOCAL_MODULE := BlissBootAnimation
+
+BOOTANIMATION := $(shell $(ANDROID_BUILD_TOP)/vendor/bliss/bootanimation/generate-bootanimation.sh \
+    $(TARGET_SCREEN_WIDTH) \
+    $(TARGET_BOOTANIMATION_HALF_RES))
+
diff --git a/bootanimation/bootanimation.tar b/bootanimation/bootanimation.tar
new file mode 100644
index 0000000..2e43e04
--- /dev/null
+++ b/bootanimation/bootanimation.tar
Binary files differ
diff --git a/bootanimation/desc.txt b/bootanimation/desc.txt
new file mode 100644
index 0000000..4f578cff
--- /dev/null
+++ b/bootanimation/desc.txt
@@ -0,0 +1,4 @@
+1440 1440 30
+c 1 0 part0 #44C9F6
+c 0 0 part1 #44C9F6
+c 1 0 part2 #44C9F6
diff --git a/bootanimation/generate-bootanimation.sh b/bootanimation/generate-bootanimation.sh
new file mode 100755
index 0000000..6b7957f
--- /dev/null
+++ b/bootanimation/generate-bootanimation.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+CWD=`pwd`
+WIDTH=$1
+HEIGHT=$(echo "$WIDTH/1.6" | bc)
+RWIDTH=$WIDTH
+RHEIGHT=$HEIGHT
+HALF_RES=$2
+if [ "$HALF_RES" = "true" ]; then
+    WIDTH=`expr $WIDTH / 2`
+    HEIGHT=`expr $HEIGHT / 2`
+fi
+
+if [ -f "/usr/bin/convert" ]; then
+if [ -f "$ANDROID_PRODUCT_OUT/system/media/bootanimation.zip" ]; then
+    echo "$ANDROID_PRODUCT_OUT/system/media/bootanimation.zip"
+else
+RESOLUTION=""$WIDTH"x"$HEIGHT""
+
+mkdir -p $ANDROID_PRODUCT_OUT/obj/BOOTANIMATION/bootanimation/part{0..4}
+tar xvfp "$PWD/vendor/bliss/bootanimation/bootanimation.tar" --to-command="convert - -resize '$RESOLUTION' \"png8:$ANDROID_PRODUCT_OUT/obj/BOOTANIMATION/bootanimation/\$TAR_FILENAME\""
+# create desc.txt
+echo "$RWIDTH" "$RHEIGHT" 60 > "$ANDROID_PRODUCT_OUT/obj/BOOTANIMATION/bootanimation/desc.txt"
+cat "$PWD/vendor/bliss/bootanimation/desc.txt" >> "$ANDROID_PRODUCT_OUT/obj/BOOTANIMATION/bootanimation/desc.txt"
+
+# create bootanimation.zip
+cd "$ANDROID_PRODUCT_OUT/obj/BOOTANIMATION/bootanimation"
+
+if [ ! -d "$ANDROID_PRODUCT_OUT/system/media" ]; then
+mkdir -p "$ANDROID_PRODUCT_OUT/system/media"
+fi
+
+zip -r0 "$ANDROID_PRODUCT_OUT/system/media/bootanimation.zip" .
+echo "$ANDROID_PRODUCT_OUT/system/media/bootanimation.zip"
+
+fi
+fi
diff --git a/config/bliss_packages.mk b/config/bliss_packages.mk
index e6bc1e0..3d1d60f 100644
--- a/config/bliss_packages.mk
+++ b/config/bliss_packages.mk
@@ -44,6 +44,7 @@
 
 # Bliss Packages
 PRODUCT_PACKAGES += \
+    BlissBootAnimation \
     Launcher3 \
     MusicFX \
     SnapdragonGallery \
diff --git a/config/common.mk b/config/common.mk
index 491c5e5..e5dc5a5 100644
--- a/config/common.mk
+++ b/config/common.mk
@@ -25,44 +25,6 @@
     vendor/bliss/prebuilt/common/bin/whitelist:system/addon.d/whitelist \
     vendor/bliss/prebuilt/bin/blacklist:system/addon.d/blacklist
 
- # Bootanimation support
-ifneq ($(TARGET_SCREEN_WIDTH) $(TARGET_SCREEN_HEIGHT),$(space))
-# determine the smaller dimension
-TARGET_BOOTANIMATION_SIZE := $(shell \
-  if [ $(TARGET_SCREEN_WIDTH) -lt $(TARGET_SCREEN_HEIGHT) ]; then \
-    echo $(TARGET_SCREEN_WIDTH); \
-  else \
-    echo $(TARGET_SCREEN_HEIGHT); \
-  fi )
-
-# get a sorted list of the sizes
-bootanimation_sizes := $(subst .zip,, $(shell ls vendor/bliss/prebuilt/common/bootanimation))
-bootanimation_sizes := $(shell echo -e $(subst $(space),'\n',$(bootanimation_sizes)) | sort -rn)
-
-# find the appropriate size and set
-define check_and_set_bootanimation
-$(eval TARGET_BOOTANIMATION_NAME := $(shell \
-  if [ -z "$(TARGET_BOOTANIMATION_NAME)" ]; then
-    if [ $(1) -le $(TARGET_BOOTANIMATION_SIZE) ]; then \
-      echo $(1); \
-      exit 0; \
-    fi;
-  fi;
-  echo $(TARGET_BOOTANIMATION_NAME); ))
-endef
-
-$(foreach size,$(bootanimation_sizes), $(call check_and_set_bootanimation,$(size)))
-
-ifeq ($(TARGET_BOOTANIMATION_HALF_RES),true)
-PRODUCT_BOOTANIMATION := vendor/bliss/prebuilt/common/bootanimation/halfres/$(TARGET_BOOTANIMATION_NAME).zip
-else
-PRODUCT_BOOTANIMATION := vendor/bliss/prebuilt/common/bootanimation/$(TARGET_BOOTANIMATION_NAME).zip
-endif
-
-PRODUCT_COPY_FILES += \
-    $(PRODUCT_BOOTANIMATION):system/media/bootanimation.zip
-endif
-
 # init.d support
 PRODUCT_COPY_FILES += \
     vendor/bliss/prebuilt/common/bin/sysinit:system/bin/sysinit \
diff --git a/prebuilt/common/bootanimation/1080.zip b/prebuilt/common/bootanimation/1080.zip
deleted file mode 100644
index 27c2e8c..0000000
--- a/prebuilt/common/bootanimation/1080.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/1200.zip b/prebuilt/common/bootanimation/1200.zip
deleted file mode 100644
index 9224099..0000000
--- a/prebuilt/common/bootanimation/1200.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/1280.zip b/prebuilt/common/bootanimation/1280.zip
deleted file mode 100644
index bd8d57d..0000000
--- a/prebuilt/common/bootanimation/1280.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/1440.zip b/prebuilt/common/bootanimation/1440.zip
deleted file mode 100644
index d0484b1..0000000
--- a/prebuilt/common/bootanimation/1440.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/1600.zip b/prebuilt/common/bootanimation/1600.zip
deleted file mode 100644
index 1cb51d7..0000000
--- a/prebuilt/common/bootanimation/1600.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/1920.zip b/prebuilt/common/bootanimation/1920.zip
deleted file mode 100644
index 4a50649..0000000
--- a/prebuilt/common/bootanimation/1920.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/2160.zip b/prebuilt/common/bootanimation/2160.zip
deleted file mode 100644
index f5824ef..0000000
--- a/prebuilt/common/bootanimation/2160.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/480.zip b/prebuilt/common/bootanimation/480.zip
deleted file mode 100644
index 5eb2fb7..0000000
--- a/prebuilt/common/bootanimation/480.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/600.zip b/prebuilt/common/bootanimation/600.zip
deleted file mode 100644
index d75cba1..0000000
--- a/prebuilt/common/bootanimation/600.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/720.zip b/prebuilt/common/bootanimation/720.zip
deleted file mode 100644
index e5d9ed4..0000000
--- a/prebuilt/common/bootanimation/720.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/800.zip b/prebuilt/common/bootanimation/800.zip
deleted file mode 100644
index 9357a65..0000000
--- a/prebuilt/common/bootanimation/800.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/halfres/1080.zip b/prebuilt/common/bootanimation/halfres/1080.zip
deleted file mode 100644
index 4662ae7..0000000
--- a/prebuilt/common/bootanimation/halfres/1080.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/halfres/1200.zip b/prebuilt/common/bootanimation/halfres/1200.zip
deleted file mode 100644
index c40e657..0000000
--- a/prebuilt/common/bootanimation/halfres/1200.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/halfres/1280.zip b/prebuilt/common/bootanimation/halfres/1280.zip
deleted file mode 100644
index 247c0cb..0000000
--- a/prebuilt/common/bootanimation/halfres/1280.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/halfres/1440.zip b/prebuilt/common/bootanimation/halfres/1440.zip
deleted file mode 100644
index 180eefa..0000000
--- a/prebuilt/common/bootanimation/halfres/1440.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/halfres/1600.zip b/prebuilt/common/bootanimation/halfres/1600.zip
deleted file mode 100644
index c8f3f3c..0000000
--- a/prebuilt/common/bootanimation/halfres/1600.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/halfres/1920.zip b/prebuilt/common/bootanimation/halfres/1920.zip
deleted file mode 100644
index d08dfca..0000000
--- a/prebuilt/common/bootanimation/halfres/1920.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/halfres/2160.zip b/prebuilt/common/bootanimation/halfres/2160.zip
deleted file mode 100644
index e35cd99..0000000
--- a/prebuilt/common/bootanimation/halfres/2160.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/halfres/480.zip b/prebuilt/common/bootanimation/halfres/480.zip
deleted file mode 100644
index 2a4174f..0000000
--- a/prebuilt/common/bootanimation/halfres/480.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/halfres/600.zip b/prebuilt/common/bootanimation/halfres/600.zip
deleted file mode 100644
index 5c3fe25..0000000
--- a/prebuilt/common/bootanimation/halfres/600.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/halfres/720.zip b/prebuilt/common/bootanimation/halfres/720.zip
deleted file mode 100644
index c134479..0000000
--- a/prebuilt/common/bootanimation/halfres/720.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/halfres/800.zip b/prebuilt/common/bootanimation/halfres/800.zip
deleted file mode 100644
index 1d59379..0000000
--- a/prebuilt/common/bootanimation/halfres/800.zip
+++ /dev/null
Binary files differ
diff --git a/prebuilt/common/bootanimation/halfres/generate-half-res-anims.sh b/prebuilt/common/bootanimation/halfres/generate-half-res-anims.sh
deleted file mode 100755
index 409432e..0000000
--- a/prebuilt/common/bootanimation/halfres/generate-half-res-anims.sh
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/sh
-
-HALF_RES_RESOLUTIONS="480 600 720 800 1080 1200 1280 1440 1600 1920 2160"
-
-for i in $HALF_RES_RESOLUTIONS; do
-	rm -f $i.zip
-	mkdir $i
-	cd $i
-	if [ -f ../../$(($i/2)).zip ]; then
-		# use the existing scaled images
-		echo "Using existing half-scale images instead of scaling from $i px"
-		unzip ../../$(($i/2)).zip
-		rm -f desc.txt
-		unzip ../../$i.zip desc.txt
-	else
-		unzip ../../$i.zip
-		for j in */*.[pP][nN][gG]; do
-			convert $j -resize 50% tmp.png
-			mv tmp.png $j
-		done
-	fi
-	zip -r0 ../$i.zip .
-	cd ..
-	rm -rf $i
-done