Ads

Saturday 1 February 2014

Bake your own custom rom for android device PART 4

Welcome to part 4. 
In this class, we’re taking a slight detour to look at one of the more interesting parts of creating your own ROM and that’s adding your own custom bootup screen animation. While there are plenty of boot animations on the web you can mod yourself, nothings better than creating your own boot animation from scratch.
The boot animation is the video-like display you see when you first turn on your smartphone or tablet. They can be made as simple or as complicated as you like, but whether you make yours a single image or a video-quality animation like CyanogenMod, the process is still the same. And it’s reasonably simple to do. At the most basic level, all you need is an image editor (anything from Windows Paint to Photoshop will work), a text editor and some creativity.
How it works
An Android boot animation is a pretty simple affair: all it is is a ZIP file that contains a series of JPEG images in specific subfolders, which the device ROM loads and displays, as described by the text-based descriptor file.
While clever animations like the CyanogenMod splash may look like a video playing, they’re just a series of discrete images being played at a set resolution and frame rate. All of this information comes from the descriptor file.
Build a descriptor file
The descriptor file is the ‘desc.txt’ file in the root of the ‘bootanimation.zip’ file and its structure is fairly basic. The first line contains three numbers: the horizontal resolution in pixels, the vertical resolution in pixels and the image display frame rate in frames per second (fps). Let’s say you’re creating a boot animation for a smartphone. In that case, you’d set it up to display in portrait mode, in which case your first line would be something like this:
480 800 10
This means a 480 x 800-pixel frame size displayed at 10fps.
After that, the following lines describe the various animation sections and how they’re displayed in sequence. While the frame rate is fixed by this first line, you can split your animation into sections and display each one differently — you can choose the number of times each section is played or repeated before the next section begins, you can set the delay in seconds before repeating or moving onto a new section, and you can set the subfolder location for the pics of that section.
There doesn’t appear to be a limit on the number of animation sections you can have, although you don’t want it to go on for two hours either. For example, the code to display three sections of animation could look like this:
p 1 0 part0
p 2 3 part1
p 0 0 part2
Decoding those lines, the first says play (p) once (1) with zero delay afterwards (0) the images in subfolder (part0). The second line says play (p) twice (2) with a three-second (3) delay after the images in subfolder (part1). And finally, the third line says play (p) repeat infinitely (0) with zero delay afterwards (0) the images in subfolder (part2).
The images in those subfolders need to be numerically sequenced; for example, ‘image001.jpg’, ‘image002.jpg’, ‘image003.jpg’ and so on. Make sure you include those leading zeros, otherwise you’ll get strange things like ‘image10.png’ being played before ‘image2.png’. That’s because the system is designed to logically think ‘1’ comes before ‘2’, even if it’s meant to be ‘10’. The last thing is to make sure you leave an empty line at the end of the file.
How you create those images is entirely up to you. The simple, slow way is to create and save the images one by one. The alternative is to extract them from a video using a video-to-image extraction app. The command line audio/video transcoding app FFmpeg can do this.
While it won’t necessarily work for capturing frames from videos, one tip we do recommend if you’re creating animations from scratch is to follow the square frame size used by CyanogenMod. We like this option because you don’t need full-screen resolution for an animation to look good, and using a square frame will allow you to still achieve a high-resolution look without needing to update more screen pixels than necessary. That cuts down on the CPU time required, ensuring your device spends most of its time loading the ROM, which is really what you want anyway. The only other thing that we think helps is if you’re making an animation from scratch, start with a black background — it just looks better.

Playback speed
When creating your own boot animation, one of the first things to think about is how many images you’ll need. Remember, it’s just a splash display to give you something to look at while your phone is booting up, so you don’t really want 1080p images displaying at 30fps, otherwise the phone is spending more CPU time playing an HD-grade animation, slowing down the bootup process. Also, older phones have less reserves of CPU power available to play animation, so you need to consider these things when working out how complex to make your animation.
Since the frame rate in the first line sets the playback speed, it’s also the number of images you’ll need for each second of play. So clearly, creating a 10fps animation takes a lot less work than a 20fps one.
But how high a frame rate for a boot animation is too high? In the end, it’s not necessarily how high the frame rate is, but how many pixels your phone has to display each second, since that’s what the CPU is effectively doing; for example, a 1,080 x 1,920-pixel animation at 5fps equals the same number of pixels as a 480 x 800-pixel animation at 27fps. Obviously, your device has to have a screen size that can display the whole animation frame, but overall, you want to err on the side of simplicity. This is one case where it’s good to think less is more.
Compress the file
The last step to making a functioning animation file is to compress the ‘desc.txt’ file and image subfolders into a ZIP folder. You can use 7-Zip for this, but most importantly, remember to use the ‘store’ option only. You don’t actually want to compress anything, otherwise the ROM won’t be able to open and retrieve the files. When you’re done, load it into Boot Animation Factory to test that it works as you expect.
Add your animation to the ROM
Depending on your device, this can be complicated. Android Kitchen has an option for adding custom boot animations into your ROM. Go to the ‘Main Menu’ in the Kitchen, select ‘00’ for legacy options and then ‘27’ (add custom boot animation functionality). This will enable the ROM to look at the ‘\data\local’ subfolder. Next, copy the ‘bootanimation.zip’ file into that subfolder, which should be located in ‘WORKING_<date>_<day>’ folder and that’s it. The rest will be done when you build the ROM.
However, Samsung uses a proprietary animation system that works differently. If you’re working from a stock Samsung ROM (we’re using a Galaxy S3 ROM in this masterclass), here’s what you do.
  • Check the ‘\system\bin’ subfolder in your ‘WORKING’ ROM folder and look for the files ‘samsungani’ and ‘bootanimation’.
  • Download ‘bootanimation4u.zip’ from the bottom of the first post at tinyurl.com/ncjhcwl. Unzip it and inside the ‘\system\bin’ subfolder of that ZIP file, you’ll find replacement ‘samsungani’ and ‘bootanimation’ files. Back up the originals of these files from the ‘WORKING’ folder and copy these replacements over the top.
  • Grab your newly minted ‘bootanimation.zip’ and copy it into the ‘\system\media’ subfolder.
  • Build your ROM.
If you look in the ‘\system\media’ subfolder in your ‘WORKING’ folder, Samsung stock ROMs use a proprietary boot animation format for most things. The fix we’re using here allows Android-standard ‘bootanimation.zip’ files to also be used again.
We tested this technique with our Samsung Galaxy S3 phone, flashing a custom ROM built from a Samsung stock release with modded ‘bootanimation.zip’ support and it worked the first time. If you want to go back to the genuine boot animation, just replace the ‘samsungani’ and ‘bootanimation’ files you added with the originals you backed up in step 2 above.
to be continued...



No comments:

Post a Comment