Current location - Health Preservation Learning Network - Healthy weight loss - A detailed description of several image formats such as PNG, JPEG, BMP (IV)-GIF.
A detailed description of several image formats such as PNG, JPEG, BMP (IV)-GIF.
The following parts are from Baidu Encyclopedia, and some are my own opinions. The purpose of writing this article is to let you know what you have learned on Baidu, but you don't have to go to Baidu again. I also have a deep understanding of this picture format. After reading this article, including me, I will feel that even a small knowledge point will be profound in the future. The underlying and deep principles are my favorite, which is also the original intention of my blog.

GIF (Graphic Interchange Format) originally means "Image Interchange Format", which is an image file format developed by CompuServe Company in 1987. The data of GIF file is a continuous tone lossless compression format based on LZW algorithm. Its compression ratio is generally around 50%, which does not belong to any application. GIF format can store images of multiple colors. If the data of multiple images stored in one file are read out one by one and displayed on the screen, the simplest animation can be formed.

GIF pictures are based on a color list (the stored data is the index value of the color list corresponding to the color of the point), and only 8 bits (256 colors) are supported at most. GIF file is divided into many storage blocks, which are used to store multiple images or control blocks that determine the performance behavior of images, thus realizing animation and interactive applications. GIF files also compress image data through LZW compression algorithm to reduce the image size.

GIF format was introduced by CompuServe Company in 1987. Because of its small size and relatively clear imaging, it is especially suitable for the early slow network speed and is very popular.

In the early days, the LZW compression algorithm used in GIF was a free algorithm developed by Compuserv. However, to the surprise of many software developers, the compression algorithm used in GIF files suddenly became the patent of Unisys.

According to Unisys, they have registered the W part of the LZW algorithm. If you want to develop a program to generate (or display) GIF files, you need to pay royalties to the company. Therefore, people began to seek a new technology to reduce the development cost. PNG (Portable Network Graphics) standard came into being under this background. On the one hand, it meets the market demand for less legal restrictions, on the other hand, it also brings less technical restrictions, such as the number of colors.

On June 20, 2003, the patent right of LZW algorithm in the United States expired. Patents in Europe, Japan and Canada also expired on June 18, June 20 and July 7, 2004 respectively. However, with its technical advantages, PNG file format has become the third most widely used format on the network. GIF related patents expired on August 1 1, 2006.

For a long time, iOS has been spit out and cannot use GIF. The main reasons for this situation are:

GIFs can be divided into static GIFs and animated GIFs, and the extension is. GIF。 GIF is a compressed bitmap format, which supports transparent background images and is suitable for various operating systems. GIF is very small, and many small animations on the Internet are in GIF format. Gif is actually to save multiple pictures as a picture file, thus forming an animation. The most common is a funny GIF picture with frame-by-frame animation, so GIF is still a picture file format after all.

But GIF can only display 256 colors. Like jpg format, this is a very popular graphic file format on the Internet.

GIF is mainly divided into two versions, namely GIF 89a and GIF 87a.

The syntax given here is used to explain the block sequence that forms the gif data stream, which is represented by some rule lists. The symbol definitions used for gif syntax are listed below.

Symbol definition of gif syntax:: = head <; Data > * tail record

The data blocks in gif data stream can be divided into three groups: control block, imaging block and special block.

Color table -gif format uses a color table to display raster-based images. Color tables are divided into global color tables and local color tables. The global color table is suitable for images without a local color table. The scope of the global color table is the whole data stream. The local color table is suitable for the next single image. Both color tables are optional.

The global color table is something we are interested in. Kind of like a palette defined in png format. If you want to modify the color of gif pictures, haha, you can modify this global color table. If there is a global color table block, it must start with a gif stream of 14 bytes (the first 6+7 logical video description blocks).

The following is a description of each data block. If it is marked as version 89a, it means that the data block will not appear in the protocol of version 87a.

The packaging field explains:

GIF files are divided into blocks, including control blocks and data sub-blocks. The control block controls the behavior of the data block and contains some different control parameters according to different control blocks. The data block only contains some 8-bit character streams, and its function is determined by the previous control block. The size of each data block ranges from 0 to 255 bytes. The first byte of a data block indicates the size (number of bytes) of the data block, which is not included when calculating the size of the data block, so an empty data block has one byte, that is, the size of the data block 0x00. The following table shows the structure of data blocks:

The structure of GIF file can be divided into three parts: file header, GIF data stream and file trailer. The file header contains the GIF file signature and version); Number; GIF data stream consists of control identifiers, image blocks and other extension blocks. The file terminator has only one character (""); ) indicates the end of the file. The following table shows the structure of the GIF file:

Used to identify GIF signature and version number.

GIF signature is used to confirm whether the file is in GIF format. This part consists of three characters: "gif"; The file version number also consists of three bytes, which can be "87a" or "89a". Specific as shown in the figure below.

It contains many parts.

(1) Logical screen descriptor: This part consists of 7 bytes, which defines the size (logical screen width & height), color bit, Blackground ColorIndex whether there is a global color list and the IndexCount of the color list, as shown in the following figure.

You can also refer to the picture below.

(2) Global color table:

The global color list must be followed by the logical screen identifier, and each color list index entry consists of three bytes, arranged in the order of R, G and B. ..

(3) Image Descriptor: A GIF file can contain multiple images, and one image is followed by an image identifier. The image identifier starts with the character 0x2C ('',''), and defines the attributes of the image that follows it, including the offset of the image from the boundary of the logical screen, the image size, the existence of the local color list and the size of the color list (10 bytes).

You can also refer to the picture below.

(4) Local color list: If the above-mentioned local color list flag is set, you need to define a local color list for the image behind it here (immediately after the image identifier). Note that the original color list should be saved online before use, and the original saved global color list should be restored after use. If the GIF file does not provide a global color list or a local color list, you can create your own color list or use the system color list. The local color list is arranged in the same way as the global color list: RGBRGB. ......

(5) Table-based image data: It consists of two parts: LZW minimum code length and image data.

A schematic diagram of the overall storage structure is given below.

Adobe ImageReady and fireworks are the main softwares produced on PC.

Gif online production and editing gif5.net on the web page, supporting pictures, videos and FLASH to GIF.

I usually use LICEcap to make gif pictures.

1. Baidu encyclopedia

2. The file storage structure and animation principle of 2.GIF pictures.

3. The principle and storage structure of GIF images are deeply analyzed.