The PNG Guide is an eBook based on Greg Roelofs' book, originally published by O'Reilly. |
![]() |
Home ![]() ![]() |
||||||||||||||||||||
See also: Chunks | ||||||||||||||||||||
![]() ![]() ![]() ![]() ![]() ![]() |
||||||||||||||||||||
PNG Signature
The 8-byte PNG file signature can detect this sort of problem because it simulates a text file in some respects. The 8 bytes are given in Table 8-1.
The first byte is used to detect transmission over a 7-bit channel--for example, email transfer programs often strip the 8th bit, thus changing the PNG signature. The 2nd, 3rd, and 4th bytes simply spell ``PNG'' (in ASCII, that is). Bytes 5 and 6 are end-of-line characters for Macintosh and Unix, respectively, and the combination of the two is the standard line ending for DOS, Windows, and OS/2. Byte 7 (CTRL-Z) is the end-of-file character for DOS text files, which allows one to TYPE the PNG file under DOS-like operating systems and see only the acronym ``PNG'' preceded by one strange character, rather than page after page of gobbledygook. Byte 8 is another Unix end-of-line character. Text-mode transfer of a PNG file from a DOS-like system to Unix will strip off the carriage return (byte 5); the reverse transfer will replace byte 8 with a CR/LF pair. Transfer to or from a Macintosh will strip off the line feeds or replace the carriage return with a line feed, respectively. Either way, the signature is altered, and in all likelihood the remainder of the file is irreversibly damaged. Note that the 9th, 10th, and 11th bytes are guaranteed to be 0 (that
is, the ASCII NUL character) by the fact that the first chunk is required to
be IHDR, whose first 4 bytes are its length--a value that is currently
13 and, according to the spec, will never change. (Instead, ``new chunk types
will be added to carry new information.'') The fact that the 0 bytes in
the length come first is another benefit of the big-endian integer format,
which stores the high-order bytes first. Since NUL bytes are also often
stripped out by text-mode transfer protocols, the detection of damaged PNG
files is even more robust than the signature alone would suggest.
|
||||||||||||||||||||
Home ![]() ![]() |