3.5 PNG. Portable Network Graphics
Cf.
This is pronounced ``ping''.
Colors can be coded up to 6*8=48 bits.
It uses (non-patented) LZ77 compression.
From png-1.2-pdg.html:
- GIF features retained in PNG include:
- Indexed-color images of up to 256 colors.
- Streamability: files can be read and written serially, thus allowing the file format to be used as a communications protocol for on-the-fly generation and display of images.
- Progressive display: a suitably prepared image file can be displayed as it is received over a communications link, yielding a low-resolution image very quickly followed by gradual improvement of detail.
- Transparency: portions of the image can be marked as transparent, creating the effect of a non-rectangular image.
- Ancillary information: textual comments and other data can be stored within the image file.
- Complete hardware and platform independence.
- Effective, 100% lossless compression.
- Important new features of PNG, not available in GIF, include:
- Truecolor images of up to 48 bits per pixel.
- Grayscale images of up to 16 bits per pixel.
- Full alpha channel (general transparency masks).
- Image gamma information, which supports automatic display of images with correct brightness/contrast regardless of the machines used to originate and display the image.
- Reliable, straightforward detection of file corruption.
- Faster initial presentation in progressive display mode.
- PNG is designed to be:
- Simple and portable: developers should be able to implement PNG easily.
- Legally unencumbered: to the best knowledge of the PNG authors, no algorithms under legal challenge are used. (Some considerable effort has been spent to verify this.)
- Well compressed: both indexed-color and truecolor images are compressed as effectively as in any other widely used lossless format, and in most cases more effectively.
- Interchangeable: any standard-conforming PNG decoder must read all conforming PNG files.
- Flexible: the format allows for future extensions and private add-ons, without compromising interchangeability of basic PNG.
- Robust: the design supports full file integrity checking as well as simple, quick detection of common transmission errors.
File Structure:
- Signature
(decimal) |
137 |
80 |
78 |
71 |
13 |
10 |
26 |
10 |
(hexadecimal) |
89 |
50 |
4e |
47 |
0d |
0a |
1a |
0a |
(ASCII C notation) |
211 |
P |
N |
G |
r |
n |
032 |
n |
- Chunk layout
- length ...4 bytes
- chunk type ...4 bytes (chars)
- data ...length bytes
- CRC (Cyclic Redundancy Check) ...4 bytes
- IHDR Image Header
- Width: 4 bytes
- Height: 4 bytes
- Bit depth: 1 byte
- Color type: 1 byte
- Compression method: 1 byte
- Filter method: 1 byte
- Interlace method: 1 byte
- PLTE Palette
- Red: 1 byte (0 = black, 255 = red)
- Green: 1 byte (0 = black, 255 = green)
- Blue: 1 byte (0 = black, 255 = blue)
- IDAT Image data
- IEND Image trailer
Optional Chunks:
- tRNS Transparency
- gAMA Image gamma
- cHRM Primary chromaticities
- sRGB Standard RGB color space
- iCCP Embedded ICC profile
- tEXt Textual data
- zTXt Compressed textual data
- iTXt International textual data
- bKGD Background color
- pHYs Physical pixel dimensions
- sBIT Significant bits
- sPLT Suggested palette
- hIST Palette histogram
- tIME Image last-modification time
About the motivation for introducing this new format:
From png-1.2-pdg.html:
We considered numerous existing formats before deciding to develop PNG. None
could meet the requirements that we felt were important for PNG.
GIF is no longer suitable as a universal standard because of legal
entanglements. Although just replacing GIF's compression method would avoid
that problem, GIF does not support truecolor images, alpha channels, or gamma
correction. The spec has more subtle problems too. Only a small subset of the
GIF89 spec is actually portable across a variety of implementations, but there
is no codification of the most portable part of the spec.
TIFF (the Tagged Image File Format) is far too complex to meet our goals of
simplicity and interchangeability. Defining a TIFF subset would meet that
objection, but would frustrate users making the reasonable assumption that a
file saved as TIFF from their existing software would load into a program
supporting our flavor of TIFF. Furthermore, TIFF is not designed for stream
processing, has no provision for progressive display, and does not currently
provide any good, legally unencumbered, lossless compression method.
IFF has also been suggested, but is not suitable in detail: available image
representations are too machine-specific or not adequately compressed. The
overall chunk structure of IFF is a useful concept that PNG has liberally
borrowed from, but we did not attempt to be bit-for-bit compatible with IFF
chunk structure. Again this is due to detailed issues, notably the fact that
IFF FORMs are not designed to be serially writable.
Lossless JPEG is not suitable because it does not provide for the storage of
indexed-color images. Furthermore, its lossless truecolor compression is often
inferior to that of PNG.
From png-1.2-pdg.html:
Deflate/Inflate Compression
PNG compression method 0 (the only compression method presently defined for
PNG) specifies deflate/ inflate compression with a sliding window of at most
32768 bytes. Deflate compression is an LZ77 derivative used in zip, gzip,
pkzip, and related programs. Extensive research has been done supporting its
patent-free status. Portable C implementations are freely available.
Deflate-compressed datastreams within PNG are stored in the "zlib" format, ...
Andreas Kriegl 2003-07-23