Giflib.sourceforge.net has not been updated since June 25, 2019.

  • SourceForge Project Page source code entry. Source code is not very much, there are 12 files, you can directly copy into the project main/ CPP /giflib.
  • What is a Gif? It’s a GIF89a Specification. A W3C standard format. There is an introduction to a Gif file contains data, Gif file format, look is not too understand.
  • LZW ImageData, string table compression algorithm, means shorter code for longer string compression, kind of like Huffman algorithm. There are three main objects: CharStream codeStream StringTable Principle Extracts different characters from the original text file data, creates a compiled table based on these characters, and replaces the response characters of the original text file data with the index of the characters in the compiled table to reduce the size of the original data.

2 use GifLib to decode a GIF picture, and show the idea.

The first Java layer implementation uses the drawable scheduleSelf(Runnable,TimeUpdate) method to execute the Runnable run method at a specific time. The invalidateSelf() method is executed inside the run method and the draw() method is executed through the canvas. DrawBitmap (bitmap,srcRect,getBounds(),mPaint) to draw. In turn, scheduleSelf(Runnable,TimeUpdate) executes methods in the thread. Animatable inherits the Drawable package to control the execution of the method by calling the start stop isRunning method. TimeUpdate is the absolute time to execute a method in a thread, usually the current time plus the display time of the current frame

The second Java layer implementation uses jni to call C++ classes. The GifFrame class calls C++ methods by calling native methods. The main local variables are nativeHandler (the address of the pointer to the specific decoding image class in C++), with, height, count. Defines the nativeDecodeStreamJNI (AssetManager, Path), nativeGetFrame (nativeHandle, bitmap, frameIndex). These are the two main methods.

Treatment of the third Jni layer.

JNI will call the JNI_OnLoad method when loading the dynamic library. In this case, you can perform some initialization operations by registering env->findClass() to obtain the class, and env->RegisterNatives() to register the method. In this way can achieve the purpose of preloading, method method reuse, method mapping?? . JNINativeMethod is composed of (native method call string, all parameters passed + return parameter signature, Unregister env->UnregisterNatives(CL) in the JNI_OnUnload method.

NativeDecodeStreamJNI maps to the method decode_jni method. The GifFrame of C++ is initialized, and the GifFrame of C++ is converted to nativeHandler as a parameter to build a parameter of the Java layer GifFrame. GifFrame initialization in C++ mainly opens an Asset or an externally stored Gif image, encapsulates the image information and the time information of each image into GifType, and obtains subsequent basic information from GifType.

NativeGetFrame (nativeHandle, bitmap, frameIndex), parse each frame of data, and store data in the bitmap. The natvieHandler pointer can be strongly converted to C++ GifFrame. Call the C++ GifFrame method to process the data. This step is complicated. About the following

1 With AndroidBitmap luck a buffer pixel area piexes

2 SaveImage —-> GifImageDesc(record all pixels, width and height pixels) ColorMapObject stores all pixels to pixes, that is, indirectly update Bitmap.

3 remove the transparent value to reduce the memory occupied by the picture.