Portable Network Graphic Format I. Introduction PNG is an image file storage format developed in the middle of 1990s. It aims to replace GIF and TIFF file formats and add features not available in GIF file formats. The Portable Network Graphic Format (PNG) name is derived from the unofficial "PNG's Not GIF". It is a bitmap file storage Format, read as "ping ". When PNG is used to store a grayscale image, the depth of the grayscale image can be up to 16 bits. When the color image is stored, the depth of the color image can be up to 48 bits, it can also store up to 16-bit alpha channel data. PNG uses the lossless data compression algorithm derived from LZ77. The PNG file format retains the following features of the GIF file format:
- You can use a color search table or a color palette to support color images of 256 colors.
- Stream read/write performance (streamability): The image file format allows continuous reading and writing of image data, which is suitable for generating and displaying images during communication.
- Progressive display: This feature enables you to display images on the terminal while transmitting image files on the communication link. After the entire outline is displayed, the image details are gradually displayed, that is, first display the image with low resolution, and then gradually improve its resolution.
- Transparency: This performance prevents certain parts of the image from being displayed and is used to create distinctive images.
- Ancillary information: this feature can be used to store text comments in image files.
- Independent from the computer software and hardware environment.
- Use lossless compression.
Add the following features not available in the GIF file format:
- Each pixel is a 48-bit real-color image.
- Each pixel is a 16-bit grayscale image.
- You can add Alpha channels for Grayscale and true color graphs.
- Add the Gamma information of the image.
- Use the cyclic escape code (CYclicREdundancyCOde, CRC.
- Accelerate the display method of the image display.
- Standard read/write toolkit.
- Multiple images can be stored in one file.
Ii. File structure A png Image Format file (or data stream) consists of an 8-byte PNG file signature domain and more than three chunks organized according to a specific structure. PNG defines two types of data blocks. One is critical chunk, which is a standard data block, and the other is ancillary chunks ), this is an optional data block. Key data blocks define four standard data blocks. Each PNG file must contain them. PNG read/write software must also support these data blocks. Although the PNG file specification does not require the PNG encoding/Decoding of optional data blocks, the specification advocates the support of optional data blocks.
(1) PNG file signature domain The 8-byte PNG file signature field is used to identify whether the file is a PNG file. The value of this field is:
Decimal number |
137 |
80 |
78 |
71 |
13 |
10 |
26 |
10 |
Hexadecimal number |
89 |
50 |
4e |
47 |
0d |
0a |
1a |
0a |
(2) structure of data blocks Each data block consists of four fields shown in Table 6-07. Table 6-07 structure of PNG file data blocks
Name
|
Bytes
|
Description
|
Length) |
4 bytes |
The length of the data field in the specified data block. The length cannot exceed (231-1) bytes |
Chunk Type Code (data block Type Code) |
4 bytes |
The data block type code consists of ASCII letters (A-Z and a-z) |
Chunk Data (Data block Data) |
Variable Length |
Store data specified by Chunk Type Code |
CRC (Cyclic Redundancy detection) |
4 bytes |
The storage is used to check whether there are error cyclic verification codes. |
In table 6-7, CRC (CYclicREdundancyCThe value in the Chunk Type Code field and the Data in the Chunk Data field are calculated. The specific CRC algorithm is defined in ISO 3309 and ITU-T V.42, and its value is calculated according to the following CRC code generation polynomial: X32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 Iii. Data Block Structure 1. Key data blocks The four standard data blocks in key data blocks are: (1) header data block IHDR (header chunk): it contains the basic information of the image data stored in the PNG file and needs to appear as the first data block in the PNG data stream, in addition, a PNG data stream can only contain one file header data block. The file header data block consists of 13 bytes. Its format is shown in Table 6-08. Table 6-08 structure of the PNG file header key data block
Domain Name |
Bytes |
Description |
Width |
4 bytes |
Image Width, in pixels |
Height |
4 bytes |
Image Height, in pixels |
Bit depth |
1 byte |
Image depth: Indexed color images: 1, 2, 4, or 8 Grayscale Images: 1, 2, 4, 8, or 16 True Color Image: 8 or 16 |
ColorType |
1 byte |
Color type: 0: grayscale image, 1, 2, 4, 8, or 16 2: true color image, 8 or 16 3: indexing color images, 1, 2, 4, or 8 4: grayscale image with alpha channel data, 8 or 16 6: true color image with alpha channel data, 8 or 16 |
Compression method |
1 byte |
Compression Method (LZ77 derived algorithm) |
Filter method |
1 byte |
Filter Method |
Interencryption method |
1 byte |
How to scan through multiple rows: 0: Non-interlace Scan 1: Adam7 (7 developed by Adam M. Costello How to scan through multiple rows) |
(2) palette data block PLTE (palette chunk): it contains color transformation data related to the indexed color image (indexed-color image, it is only related to indexed color images and should be placed before the image data chunk. A real-color PNG data stream can also contain color palette data blocks, which are used by a non-real-color display program to quantify image data and display the image. The structure of the palette data block is shown in Table 6-9. Table 6-09 data block structure of the color palette
Domain Name |
Bytes |
Description |
Red |
1 byte |
0 = Black, 255 = red |
Green |
"> 0 = Black, 255 = green |
Blue |
1 byte |
0 = Black, 255 = blue |
The color palette is actually a color index to find a table. The number of table items can be 1 ~ Each table item has three bytes. Therefore, the maximum number of bytes contained in the palette data block is 256. (3) image data block IDAT (image data chunk): It stores actual data and can contain multiple consecutive sequential image data blocks in the data stream. (4) image trailer chunk: it is used to mark the PNG file or the data stream has ended and must be placed at the end of the file. Except that the IHDR that indicates the start of the data block must be placed at the beginning, the IEND data block that indicates the end of the PNG file is placed at the end, there is no limit on the storage sequence of other data blocks.
2. Auxiliary Data blocks The 10 auxiliary data blocks in PNG file format are: (1) background color data block bKGD (background color ). (2) base color and white data block cHRM (primary chromaticities and white point ). The white degree refers to the white degree produced on the display when R = G = B = the maximum value. (3) image gamma data block gAMA (image gamma ). (4) image histogram (hIST ). (5) physical pixel size data block pHYs (physical pixel dimensions ). (6) Sample effective BIT data block sBIT (significant bits ). (7) tEXt information data block tEXt (textual data ). (8) The last modification tIME (image last-modification time) of the image ). (9) transparent data block tRNS (transparency ). (10) compressed text data block zTXt (compressed textual data ).
3. Data Block Summary Key data blocks, secondary data blocks, and specialized public data blocks (special-purpose public chunks) are integrated in Table 6-10. Table 6-10 data blocks in PNG file format
Data Block symbol
|
Data Block name
|
Multiple Data blocks
|
Optional
|
Location restrictions
|
IHDR |
File header data block |
No |
No |
First |
CHRM |
Base color and white point data block |
No |
Yes |
Before PLTE and IDAT |
GAMA |
Image gamma data block |
No |
Yes |
Before PLTE and IDAT |
SBIT |
Sample valid BIT data block |
No |
Yes |
Before PLTE and IDAT |
PLTE |
Color Palette data block |
No |
Yes |
Before IDAT |
BKGD |
Background color data block |
No |
Yes |
Before IDAT after PLTE |
HIST |
Image histogram data block |
No |
Yes |
Before IDAT after PLTE |
TRNS |
Transparent data block |
No |
Yes |
Before IDAT after PLTE |
OFFs |
(Private Public Data blocks) |
No |
Yes |
Before IDAT |
PHYs |
Physical pixel size data block |
No |
Yes |
Before IDAT |
SCAL |
(Private Public Data blocks) |
No |
Yes |
Before IDAT |
IDAT |
Image Data Block |
Yes |
No |
Continuous with other IDAT |
TIME |
Last modification time data block of the image |
No |
Yes |
Unlimited |
TEXt |
Text Information Data Block |
Yes |
Yes |
Unlimited |
ZTXt |
Compressing text data blocks |
Yes |
Yes |
Unlimited |
FRAc |
(Private Public Data blocks) |
Yes |
Yes |
Unlimited |
GIFg |
(Private Public Data blocks) |
Yes |
Yes |
Unlimited |
GIFt |
(Private Public Data blocks) |
Yes |
Yes |
Unlimited |
GIFx |
(Private Public Data blocks) |
Yes |
Yes |
Unlimited |
IEND |
Image end data |
No |
No |
Last data block |
TEXt And standard keywords in zTXt data blocks:
Title |
Image name or title |
Author |
Image author name |
Description |
Image Description |
Copyright |
Copyright Notice |
CreationTime |
Original Image Creation Time |
Software |
Software used to create images |
Disclause |
Abstaining |
Warning |
Image Content warning |
Source |
Devices used to create images |
Comment |
Various annotations |
|