The decoding process contains multiple aforementioned steps. Butthere are more factors to consider. Initially, we require some kind of a tickeror clock that is responsible for advancing the time means that switching tosubsequent frames.
Such a ticker needs to be aware of the UI lifecycle. Especially itneeds to be disposed of when UI is no longer alive for instance user pressedthe back button or simply navigate to another app development. Handling the Android UIlifecycle properly is a significant challenge for flutter developers tobuild it. In Android app development, a lotof bugs and crashes are caused by leaks which are effects of improper lifecyclehandling. Especially the Movie class used recently for GIF decoding also usedto leak. After 60 days another one was exposed.
Encoding vs decoding
GIF encoding process is much more complicated than decoding. Thereare two main reasons. Image data in the GIF file is separated into multipleframes. But, they are not always the same as physical film frames. Let’s take alook at the below animation:
1. The most effective way of encoding is to store only differencesof subsequent frames:
2. Of course, nothing prohibits from saving the full-sized second software developers frame like this:
3. However, doing so will cause the complete GIF file size will bemuch.
Note, that GIF files used in real-time usually contain dozens offrames, larger than one in this simple example. Extracting differences betweensubsequent frames is not a small problem. The computer and mobile app development displays, image formats GIF,JPG, PNG, etc, use 24-bit color depth. That means about 16 million colors.
Even a single GIF frame may only consist of up to 256 differentcolors. As you can remember from the previous paragraphs. So, let’s look topack 16 million possibilities into 256 places. Well, it is pretty hard to dothat effectively, but many techniques have been created, they are collectivelycalled dithering. Encoding is a complicated app development process, and it needs to workon Android devices with reasonable performance.
Sign in to leave a comment.