There are two kinds of PNG in view of the data block storage method of the picture
1. Indexed color mode storage. Png8 's indexed color transparency is taken this way. This is in the optional module palette where the color exists in PNG, and the color storage format for the palette is RGB (1byte each). The pixels in the image block directly store the index values in the palette, looking for the corresponding color and transparent color according to the index. The specified transparent color is specified by the Trns image transparent data block after the Plte. The difference between Boolean transparency and alpha transparency is that alpha transparency attaches a transparent level of 8 bits (1byte) to the transparent color. The length of the trns image transparent data block corresponds to the palette as follows.
The Plte block format is :?
Cycle?
Red:1byte?
Green:1byte?
Blue:1byte?
END
Trns Block Boolean transparent format is :?
Cycle?
if (corresponding palette color is not transparent)?
0xff:1byte?
Else?
0x00:1byte?
END?
Trns block Alpha Transparent format is:?
Cycle?
if (corresponding palette color is not transparent)?
0xff:1byte?
Else?
0x**: 1byte? (Specific transparency level of 256 levels)
END?
The loop length of the Trns block is the color number of the palette, which corresponds to a table of color palettes, identifies whether the color is transparent, 0xFF (255) is opaque, and 0x00 (0) is fully transparent.
2. True Color Storage (non-professional terminology). The class store does not have a color palette (or there is a color palette for a non-true color display program that uses it to quantify image data to display the image.) ), storing the color information directly in the pixel of the data block. There are often said rgb_888 (24bit), RGB565 (16bit),rgba_8888 (32bit),rgba_4444 (16bit), RGBA5551 (16bit) and so on. Png24 and PNG32 are all of this type of storage.
From the color of the image of the number of bits commonly used following several
1.png8. This 8 is understood as bit depth, but this bit depth can be reduced. Storage can be stored for indexed colors. The index color bit depth can be 1,2,4,8. With the decrease in bit depth the supported colors are also reduced. Can support 8-bit color of 256 (2 of the 8-square) color.
1.png16. This 8 is understood as bit depth and can be stored in RGB565 (16bit), rgba_8888 (32bit), rgba_4444 (16bit), RGBA5551 (16bit). But this bit deep can be reduced. The index color bit depth can be 1,2,4,8. With the decrease in bit depth the supported colors are also reduced. Can support 8-bit color of 256 (2 of the 8-square) color.
2.png24. 24 is also understood as bit depth and is stored in rgb_888. can support 24-bit color of more than 16 million (2 of the 24-square) color.
3.png32. 32 is also understood as bit depth and is stored in rgb_888. is actually a transparent channel for the PNG24+8 bit. also supports 24-bit color for a total of more than 16 million (2 of the 24-square) colors.
But the bit depth is uncertain, the above only a few commonly used, but also can be non-transparent channel 3*2^ (often 8, 16, 32) or transparent channel 4*2^ (often 8, 16, 32).
So we use libpng how to determine the format of PNG.
/* Get bit depth, color type */
Channels= Png_get_channels (png_ptr , Info_ptr/* get the number of channels */
bit_ Depth = Png_get_bit_depth (png_ptr, Info_ptr/* get bit depth */
Color_type = Png_get_color_ Type (png_ptr, info_ptr /* color type */
< Span class= "PLN" >< Span class= "PLN" >< Span class= "pun" >< Span class= "com" >< Span class= "pun" >
Bit depth |
1 byte |
Image depth: Indexed color Image: 1,2,4 or 8 grayscale Image: 1,2,4,8 or 16 True color Image: 24 or 32 or 48 |
ColorType |
1 byte |
Color Type: 0: Grayscale image 2: True Color image 3: Indexed color image 4: Grayscale image with alpha channel data 6: True color image with alpha channel data |
Reference:
Http://baike.baidu.com/link?url=FckD48sfXstBMBnODg40OJvyMGNsiEy1-4SbwE_TSN9WK1WFaIkyjVe5d7YeUlbwKaAe_4swGsSg21PFKzAoba
Http://www.cnblogs.com/PeunZhang/archive/2013/05/30/3050394.html
Http://blog.163.com/[email protected]/blog/static/16947232820124411174877/
PNG format and pixel storage analysis