png-1.2.pdf
Document Details
Uploaded by Deleted User
Full Transcript
PNG Development Group G. Randers-Pehrson, et. al. PNG 1.2 July 1999 PNG (Portable Network Graphics) Specification, Version 1.2 For list of auth...
PNG Development Group G. Randers-Pehrson, et. al. PNG 1.2 July 1999 PNG (Portable Network Graphics) Specification, Version 1.2 For list of authors, see Credits (Chapter 19). Status of this Document This is a revision of the PNG 1.0 specification, which has been published as RFC-2083 and as a W3C Rec- ommendation. The revision has been released by the PNG Development Group but has not been approved by any standards body. The PNG specification is on a standards track under the purview of ISO/IEC JTC 1 SC 24 and is expected to be released eventually as ISO/IEC International Standard 15948. It is the intent of the standards bodies to maintain backward compatibility with this specification. Implementors should periodically check the PNG online resources (see Online Resources, Chapter 16) for the current status of PNG documentation. Abstract This document describes PNG (Portable Network Graphics), an extensible file format for the lossless, portable, well-compressed storage of raster images. PNG provides a patent-free replacement for GIF and can also replace many common uses of TIFF. Indexed-color, grayscale, and truecolor images are supported, plus an optional alpha channel. Sample depths range from 1 to 16 bits. PNG is designed to work well in online viewing applications, such as the World Wide Web, so it is fully streamable with a progressive display option. PNG is robust, providing both full file integrity checking and simple detection of common transmission errors. Also, PNG can store gamma and chromaticity data for improved color matching on heterogeneous platforms. This specification defines the Internet Media Type “image/png”. 2 PNG (PORTABLE NETWORK GRAPHICS) SPECIFICATION Table of Contents 1 Introduction 6 2 Data Representation 7 2.1 Integers and byte order.................................... 7 2.2 Color values.......................................... 8 2.3 Image layout.......................................... 8 2.4 Alpha channel......................................... 9 2.5 Filtering............................................ 9 2.6 Interlaced data order...................................... 10 2.7 Gamma correction....................................... 11 2.8 Text strings........................................... 11 3 File Structure 12 3.1 PNG file signature....................................... 12 3.2 Chunk layout.......................................... 12 3.3 Chunk naming conventions.................................. 13 3.4 CRC algorithm......................................... 15 4 Chunk Specifications 15 4.1 Critical chunks......................................... 15 4.1.1 IHDR Image header.................................. 15 4.1.2 PLTE Palette..................................... 16 4.1.3 IDAT Image data................................... 17 4.1.4 IEND Image trailer.................................. 18 4.2 Ancillary chunks........................................ 18 4.2.1 Transparency information............................... 18 4.2.1.1 tRNS Transparency............................. 18 4.2.2 Color space information................................ 19 4.2.2.1 gAMA Image gamma........................... 19 4.2.2.2 cHRM Primary chromaticities....................... 20 4.2.2.3 sRGB Standard RGB color space..................... 21 4.2.2.4 iCCP Embedded ICC profile........................ 22 4.2.3 Textual information.................................. 23 4.2.3.1 tEXt Textual data.............................. 24 4.2.3.2 zTXt Compressed textual data....................... 24 4.2.3.3 iTXt International textual data....................... 25 4.2.4 Miscellaneous information.............................. 26 4.2.4.1 bKGD Background color.......................... 26 4.2.4.2 pHYs Physical pixel dimensions...................... 26 4.2.4.3 sBIT Significant bits............................ 27 4.2.4.4 sPLT Suggested palette........................... 28 4.2.4.5 hIST Palette histogram........................... 29 PNG (PORTABLE NETWORK GRAPHICS) SPECIFICATION 3 4.2.4.6 tIME Image last-modification time.................... 29 4.3 Summary of standard chunks................................. 30 4.4 Additional chunk types.................................... 31 5 Deflate/Inflate Compression 31 6 Filter Algorithms 33 6.1 Filter types........................................... 33 6.2 Filter type 0: None....................................... 34 6.3 Filter type 1: Sub....................................... 34 6.4 Filter type 2: Up........................................ 34 6.5 Filter type 3: Average..................................... 35 6.6 Filter type 4: Paeth...................................... 36 7 Chunk Ordering Rules 37 7.1 Behavior of PNG editors................................... 37 7.2 Ordering of ancillary chunks................................. 38 7.3 Ordering of critical chunks.................................. 38 8 Miscellaneous Topics 38 8.1 File name extension...................................... 38 8.2 Internet media type...................................... 39 8.3 Macintosh file layout..................................... 39 8.4 Multiple-image extension................................... 39 8.5 Security considerations.................................... 39 9 Recommendations for Encoders 40 9.1 Sample depth scaling..................................... 40 9.2 Encoder gamma handling................................... 41 9.3 Encoder color handling.................................... 44 9.4 Alpha channel creation.................................... 45 9.5 Suggested palettes....................................... 46 9.6 Filter selection......................................... 47 9.7 Text chunk processing..................................... 47 9.8 Use of private chunks..................................... 48 9.9 Private type and method codes................................ 48 10 Recommendations for Decoders 49 10.1 Error checking......................................... 49 10.2 Pixel dimensions........................................ 49 10.3 Truecolor image handling................................... 50 10.4 Sample depth rescaling.................................... 50 10.5 Decoder gamma handling................................... 51 10.6 Decoder color handling.................................... 52 4 PNG (PORTABLE NETWORK GRAPHICS) SPECIFICATION 10.7 Background color....................................... 53 10.8 Alpha channel processing................................... 54 10.9 Progressive display...................................... 57 10.10 Suggested-palette and histogram usage............................ 58 10.11 Text chunk processing..................................... 59 11 Glossary 60 12 Appendix: Rationale 64 12.1 Why a new file format?.................................... 64 12.2 Why these features?...................................... 64 12.3 Why not these features?.................................... 65 12.4 Why not use format X?.................................... 66 12.5 Byte order........................................... 66 12.6 Interlacing........................................... 66 12.7 Why gamma?......................................... 67 12.8 Non-premultiplied alpha.................................... 68 12.9 Filtering............................................ 68 12.10 Text strings........................................... 69 12.11 iTXt.............................................. 69 12.12 PNG file signature....................................... 71 12.13 Chunk layout.......................................... 71 12.14 Chunk naming conventions.................................. 71 12.15 Palette histograms....................................... 73 13 Appendix: Gamma Tutorial 73 13.1 Nonlinear transfer functions.................................. 73 13.2 Combining exponents..................................... 74 13.3 End-to-end exponent...................................... 74 13.4 CRT exponent......................................... 74 13.5 Gamma correction....................................... 75 13.6 Benefits of gamma encoding................................. 76 13.7 General gamma handling................................... 76 13.8 Some specific examples.................................... 77 13.9 Video camera transfer functions................................ 78 13.10 Further reading......................................... 79 14 Appendix: Color Tutorial 79 14.1 About chromaticity...................................... 79 14.2 The problem of color..................................... 79 14.3 Device-dependent color.................................... 79 14.4 Device-independent color................................... 80 14.5 Calibrated device-dependent color.............................. 80 14.6 Chromaticity and luminance.................................. 81 PNG (PORTABLE NETWORK GRAPHICS) SPECIFICATION 5 14.7 Characterizing computer monitors.............................. 81 14.8 Uses for XYZ......................................... 81 14.9 Converting between RGB and XYZ.............................. 82 14.10 Device gamut......................................... 82 14.11 Further reading......................................... 83 15 Appendix: Sample CRC Code 83 16 Appendix: Online Resources 85 17 Appendix: Revision History 85 18 References 87 19 Credits 90 6 PNG (PORTABLE NETWORK GRAPHICS) SPECIFICATION 1 Introduction The Portable Network Graphics (PNG) format provides a portable, legally unencumbered, well-compressed, well-specified standard for lossless bitmapped image files. Although the initial motivation for developing PNG was to replace GIF (CompuServe’s Graphics Interchange Format), the design provides some useful new features not available in GIF, with minimal cost to developers. 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 com- munications 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 communi- cations 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. 2. DATA REPRESENTATION 7 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 inter- changeability of basic PNG. Robust: the design supports full file integrity checking as well as simple, quick detection of common transmission errors. The main part of this specification gives the definition of the file format and recommendations for encoder and decoder behavior. An appendix gives the rationale for many design decisions. Although the rationale is not part of the formal specification, reading it can help implementors understand the design. Cross-references in the main text point to relevant parts of the rationale. Additional appendixes, also not part of the formal specification, provide tutorials on gamma and color theory as well as other supporting material. The words “must”, “required”, “should”, “recommended”, “may”, and “optional” in this document are to be interpreted as described in [RFC-2119], which is consistent with their plain English meanings. The word “can” carries the same force as “may”. See Rationale: Why a new file format? (Section 12.1), Why these features? (Section 12.2), Why not these features? (Section 12.3), Why not use format X? (Section 12.4). Pronunciation PNG is pronounced “ping”. 2 Data Representation This chapter discusses basic data representations used in PNG files, as well as the expected representation of the image data. 2.1 Integers and byte order All integers that require more than one byte must be in network byte order: the most significant byte comes first, then the less significant bytes in descending order of significance (MSB LSB for two-byte integers, B3 B2 B1 B0 for four-byte integers). The highest bit (value 128) of a byte is numbered bit 7; the lowest bit (value 1) is numbered bit 0. Values are unsigned unless otherwise noted. Values explicitly noted as signed are represented in two’s complement notation. Unless otherwise stated, four-byte unsigned integers are limited to the range 0 to 231 − 1 to accommodate languages that have difficulty with unsigned four-byte values. Similarly, four-byte signed integers are limited to the range −(231 − 1) to 231 − 1 to accommodate languages that have difficulty with the value −231. See Rationale: Byte order (Section 12.5). 8 PNG (PORTABLE NETWORK GRAPHICS) SPECIFICATION 2.2 Color values Colors can be represented by either grayscale or RGB (red, green, blue) sample data. Grayscale data repre- sents luminance; RGB data represents calibrated color information (if the cHRM chunk is present) or uncal- ibrated device-dependent color (if cHRM is absent). All color values range from zero (representing black) to most intense at the maximum value for the sample depth. Note that the maximum value at a given sample depth is 2sampledepth − 1, not 2sampledepth. Sample values are not necessarily proportional to light intensity; the gAMA chunk specifies the relation- ship between sample values and display output intensity, and viewers are strongly encouraged to compensate properly. See Gamma correction (Section 2.7). Source data with a precision not directly supported in PNG (for example, 5 bit/sample truecolor) must be scaled up to the next higher supported bit depth. This scaling is reversible with no loss of data, and it reduces the number of cases that decoders have to cope with. See Recommendations for Encoders: Sample depth scaling (Section 9.1) and Recommendations for Decoders: Sample depth rescaling (Section 10.4). 2.3 Image layout Conceptually, a PNG image is a rectangular pixel array, with pixels appearing left-to-right within each scan- line, and scanlines appearing top-to-bottom. (For progressive display purposes, the data may actually be transmitted in a different order; see Interlaced data order, Section 2.6.) The size of each pixel is determined by the bit depth, which is the number of bits per sample in the image data. Three types of pixel are supported: An indexed-color pixel is represented by a single sample that is an index into a supplied palette. The image bit depth determines the maximum number of palette entries, but not the color precision within the palette. A grayscale pixel is represented by a single sample that is a grayscale level, where zero is black and the largest value for the bit depth is white. A truecolor pixel is represented by three samples: red (zero = black, max = red) appears first, then green (zero = black, max = green), then blue (zero = black, max = blue). The bit depth specifies the size of each sample, not the total pixel size. Optionally, grayscale and truecolor pixels can also include an alpha sample, as described in the next section. Pixels are always packed into scanlines with no wasted bits between pixels. Pixels smaller than a byte never cross byte boundaries; they are packed into bytes with the leftmost pixel in the high-order bits of a byte, the rightmost in the low-order bits. Permitted bit depths and pixel types are restricted so that in all cases the packing is simple and efficient. PNG permits multi-sample pixels only with 8- and 16-bit samples, so multiple samples of a single pixel are never packed into one byte. All 16-bit samples are stored in network byte order (MSB first). 2. DATA REPRESENTATION 9 Scanlines always begin on byte boundaries. When pixels have fewer than 8 bits and the scanline width is not evenly divisible by the number of pixels per byte, the low-order bits in the last byte of each scanline are wasted. The contents of these wasted bits are unspecified. An additional “filter-type” byte is added to the beginning of every scanline (see Filtering, Section 2.5). The filter-type byte is not considered part of the image data, but it is included in the datastream sent to the com- pression step. 2.4 Alpha channel An alpha channel, representing transparency information on a per-pixel basis, can be included in grayscale and truecolor PNG images. An alpha value of zero represents full transparency, and a value of 2bitdepth − 1 represents a fully opaque pixel. Intermediate values indicate partially transparent pixels that can be combined with a background image to yield a composite image. (Thus, alpha is really the degree of opacity of the pixel. But most people refer to alpha as providing transparency information, not opacity information, and we continue that custom here.) Alpha channels can be included with images that have either 8 or 16 bits per sample, but not with images that have fewer than 8 bits per sample. Alpha samples are represented with the same bit depth used for the image samples. The alpha sample for each pixel is stored immediately following the grayscale or RGB samples of the pixel. The color values stored for a pixel are not affected by the alpha value assigned to the pixel. This rule is some- times called “unassociated” or “non-premultiplied” alpha. (Another common technique is to store sample values premultiplied by the alpha fraction; in effect, such an image is already composited against a black background. PNG does not use premultiplied alpha.) Transparency control is also possible without the storage cost of a full alpha channel. In an indexed-color image, an alpha value can be defined for each palette entry. In grayscale and truecolor images, a single pixel value can be identified as being “transparent”. These techniques are controlled by the tRNS ancillary chunk type. If no alpha channel nor tRNS chunk is present, all pixels in the image are to be treated as fully opaque. Viewers can support transparency control partially, or not at all. See Rationale: Non-premultiplied alpha (Section 12.8), Recommendations for Encoders: Alpha channel cre- ation (Section 9.4), and Recommendations for Decoders: Alpha channel processing (Section 10.8). 2.5 Filtering PNG allows the image data to be filtered before it is compressed. Filtering can improve the compressibility of the data. The filter step itself does not reduce the size of the data. All PNG filters are strictly lossless. 10 PNG (PORTABLE NETWORK GRAPHICS) SPECIFICATION PNG defines several different filter algorithms, including “None” which indicates no filtering. The filter al- gorithm is specified for each scanline by a filter-type byte that precedes the filtered scanline in the precom- pression datastream. An intelligent encoder can switch filters from one scanline to the next. The method for choosing which filter to employ is up to the encoder. See Filter Algorithms (Chapter 6) and Rationale: Filtering (Section 12.9). 2.6 Interlaced data order A PNG image can be stored in interlaced order to allow progressive display. The purpose of this feature is to allow images to “fade in” when they are being displayed on-the-fly. Interlacing slightly expands the file size on average, but it gives the user a meaningful display much more rapidly. Note that decoders are required to be able to read interlaced images, whether or not they actually perform progressive display. With interlace method 0, pixels are stored sequentially from left to right, and scanlines sequentially from top to bottom (no interlacing). Interlace method 1, known as Adam7 after its author, Adam M. Costello, consists of seven distinct passes over the image. Each pass transmits a subset of the pixels in the image. The pass in which each pixel is transmitted is defined by replicating the following 8-by-8 pattern over the entire image, starting at the upper left corner: 1 6 4 6 2 6 4 6 7 7 7 7 7 7 7 7 5 6 5 6 5 6 5 6 7 7 7 7 7 7 7 7 3 6 4 6 3 6 4 6 7 7 7 7 7 7 7 7 5 6 5 6 5 6 5 6 7 7 7 7 7 7 7 7 Within each pass, the selected pixels are transmitted left to right within a scanline, and selected scanlines sequentially from top to bottom. For example, pass 2 contains pixels 4, 12, 20, etc. of scanlines 0, 8, 16, etc. (numbering from 0,0 at the upper left corner). The last pass contains the entirety of scanlines 1, 3, 5, etc. The data within each pass is laid out as though it were a complete image of the appropriate dimensions. For example, if the complete image is 16 by 16 pixels, then pass 3 will contain two scanlines, each containing four pixels. When pixels have fewer than 8 bits, each such scanline is padded as needed to fill an integral number of bytes (see Image layout, Section 2.3). Filtering is done on this reduced image in the usual way, and a filter-type byte is transmitted before each of its scanlines (see Filter Algorithms, Chapter 6). Notice that the transmission order is defined so that all the scanlines transmitted in a pass will have the same number of pixels; this is necessary for proper application of some of the filters. Caution: If the image contains fewer than five columns or fewer than five rows, some passes will be entirely empty. Encoders and decoders must handle this case correctly. In particular, filter-type bytes are associated only with nonempty scanlines; no filter-type bytes are present in an empty pass. 2. DATA REPRESENTATION 11 See Rationale: Interlacing (Section 12.6) and Recommendations for Decoders: Progressive display (Section 10.9). 2.7 Gamma correction PNG images can specify, via the gAMA chunk, the power function relating the desired display output with the image samples. Display programs are strongly encouraged to use this information, plus information about the display system they are using, to present the image to the viewer in a way that reproduces what the image’s original author saw as closely as possible. See Gamma Tutorial (Chapter 13) if you aren’t already familiar with gamma issues. Gamma correction is not applied to the alpha channel, if any. Alpha samples always represent a linear fraction of full opacity. For high-precision applications, the exact chromaticity of the RGB data in a PNG image can be specified via the cHRM chunk, allowing more accurate color matching than gamma correction alone will provide. If the RGB data conforms to the sRGB specification [sRGB], this can be indicated with the sRGB chunk, enabling even more accurate reproduction. Alternatively, the iCCP chunk can be used to embed an ICC profile [ICC] containing detailed color space information. See Color Tutorial (Chapter 14) if you aren’t already familiar with color representation issues. See Rationale: Why gamma? (Section 12.7), Recommendations for Encoders: Encoder gamma handling (Section 9.2), and Recommendations for Decoders: Decoder gamma handling (Section 10.5). 2.8 Text strings A PNG file can store text associated with the image, such as an image description or copyright notice. Key- words are used to indicate what each text string represents. ISO/IEC 8859-1 (Latin-1) is the character set recommended for use in the text strings appearing in tEXt and zTXt chunks [ISO/IEC-8859-1]. It is a superset of 7-bit ASCII. If it is necessary to convey characters outside of the Latin-1 set, the iTXt chunk should be used instead. Character codes not defined in Latin-1 should not be used in tEXt and zTXt chunks, because they have no platform-independent meaning. If a non-Latin-1 code does appear in a PNG text string, its interpretation will vary across platforms and decoders. Some systems might not even be able to display all the characters in Latin-1, but most modern systems can. Provision is also made for the storage of compressed text. See Rationale: Text strings (Section 12.10). 12 PNG (PORTABLE NETWORK GRAPHICS) SPECIFICATION 3 File Structure A PNG file consists of a PNG signature followed by a series of chunks. This chapter defines the signature and the basic properties of chunks. Individual chunk types are discussed in the next chapter. 3.1 PNG file signature The first eight bytes of a PNG file always contain the following (decimal) values: 137 80 78 71 13 10 26 10 This signature indicates that the remainder of the file contains a single PNG image, consisting of a series of chunks beginning with an IHDR chunk and ending with an IEND chunk. See Rationale: PNG file signature (Section 12.12). 3.2 Chunk layout Each chunk consists of four parts: Length A 4-byte unsigned integer giving the number of bytes in the chunk’s data field. The length counts only the data field, not itself, the chunk type code, or the CRC. Zero is a valid length. Although encoders and decoders should treat the length as unsigned, its value must not exceed 231 − 1 bytes. Chunk Type A 4-byte chunk type code. For convenience in description and in examining PNG files, type codes are restricted to consist of uppercase and lowercase ASCII letters (A–Z and a–z, or 65–90 and 97–122 decimal). However, encoders and decoders must treat the codes as fixed binary values, not character strings. For example, it would not be correct to represent the type code IDAT by the EBCDIC equivalents of those letters. Additional naming conventions for chunk types are discussed in the next section. Chunk Data The data bytes appropriate to the chunk type, if any. This field can be of zero length. CRC A 4-byte CRC (Cyclic Redundancy Check) calculated on the preceding bytes in the chunk, in- cluding the chunk type code and chunk data fields, but not including the length field. The CRC is always present, even for chunks containing no data. See CRC algorithm (Section 3.4). The chunk data length can be any number of bytes up to the maximum; therefore, implementors cannot as- sume that chunks are aligned on any boundaries larger than bytes. 3. FILE STRUCTURE 13 Chunks can appear in any order, subject to the restrictions placed on each chunk type. (One notable restriction is that IHDR must appear first and IEND must appear last; thus the IEND chunk serves as an end-of-file marker.) Multiple chunks of the same type can appear, but only if specifically permitted for that type. See Rationale: Chunk layout (Section 12.13). 3.3 Chunk naming conventions Chunk type codes are assigned so that a decoder can determine some properties of a chunk even when it does not recognize the type code. These rules are intended to allow safe, flexible extension of the PNG format, by allowing a decoder to decide what to do when it encounters an unknown chunk. The naming rules are not normally of interest when the decoder does recognize the chunk’s type. Four bits of the type code, namely bit 5 (value 32) of each byte, are used to convey chunk properties. This choice means that a human can read off the assigned properties according to whether each letter of the type code is uppercase (bit 5 is 0) or lowercase (bit 5 is 1). However, decoders should test the properties of an un- known chunk by numerically testing the specified bits; testing whether a character is uppercase or lowercase is inefficient, and even incorrect if a locale-specific case definition is used. It is worth noting that the property bits are an inherent part of the chunk name, and hence are fixed for any chunk type. Thus, BLOB and bLOb would be unrelated chunk type codes, not the same chunk with different properties. Decoders must recognize type codes by a simple four-byte literal comparison; it is incorrect to perform case conversion on type codes. The semantics of the property bits are: Ancillary bit: bit 5 of first byte 0 (uppercase) = critical, 1 (lowercase) = ancillary. Chunks that are not strictly necessary in order to meaningfully display the contents of the file are known as “ancillary” chunks. A decoder encountering an unknown chunk in which the ancillary bit is 1 can safely ignore the chunk and proceed to display the image. The time chunk (tIME) is an example of an ancillary chunk. Chunks that are necessary for successful display of the file’s contents are called “critical” chunks. A decoder encountering an unknown chunk in which the ancillary bit is 0 must indicate to the user that the image contains information it cannot safely interpret. The image header chunk (IHDR) is an example of a critical chunk. Private bit: bit 5 of second byte 0 (uppercase) = public, 1 (lowercase) = private. A public chunk is one that is part of the PNG specification or is registered in the list of PNG special- purpose public chunk types. Applications can also define private (unregistered) chunks for their own purposes. The names of private chunks must have a lowercase second letter, while public chunks will always be assigned names with uppercase second letters. Note that decoders do not need to test the 14 PNG (PORTABLE NETWORK GRAPHICS) SPECIFICATION private-chunk property bit, since it has no functional significance; it is simply an administrative con- venience to ensure that public and private chunk names will not conflict. See Additional chunk types (Section 4.4), and Recommendations for Encoders: Use of private chunks (Section 9.8). Reserved bit: bit 5 of third byte Must be 0 (uppercase) in files conforming to this version of PNG. The significance of the case of the third letter of the chunk name is reserved for possible future ex- pansion. At the present time all chunk names must have uppercase third letters. (Decoders should not complain about a lowercase third letter, however, as some future version of the PNG specification could define a meaning for this bit. It is sufficient to treat a chunk with a lowercase third letter in the same way as any other unknown chunk type.) Safe-to-copy bit: bit 5 of fourth byte 0 (uppercase) = unsafe to copy, 1 (lowercase) = safe to copy. This property bit is not of interest to pure decoders, but it is needed by PNG editors (programs that modify PNG files). This bit defines the proper handling of unrecognized chunks in a file that is being modified. If a chunk’s safe-to-copy bit is 1, the chunk may be copied to a modified PNG file whether or not the software recognizes the chunk type, and regardless of the extent of the file modifications. If a chunk’s safe-to-copy bit is 0, it indicates that the chunk depends on the image data. If the pro- gram has made any changes to critical chunks, including addition, modification, deletion, or reorder- ing of critical chunks, then unrecognized unsafe chunks must not be copied to the output PNG file. (Of course, if the program does recognize the chunk, it can choose to output an appropriately modified version.) A PNG editor is always allowed to copy all unrecognized chunks if it has only added, deleted, modified, or reordered ancillary chunks. This implies that it is not permissible for ancillary chunks to depend on other ancillary chunks. PNG editors that do not recognize a critical chunk must report an error and refuse to process that PNG file at all. The safe/unsafe mechanism is intended for use with ancillary chunks. The safe-to-copy bit will always be 0 for critical chunks. Rules for PNG editors are discussed further in Chunk Ordering Rules (Chapter 7). For example, the hypothetical chunk type name bLOb has the property bits: bLOb > 8); } return c; } unsigned long crc(unsigned char *buf, int len) { return update crc(0xffffffffL, buf, len) ˆ 0xffffffffL; } 16. APPENDIX: ONLINE RESOURCES 85 16 Appendix: Online Resources (This appendix is not part of the formal PNG specification.) This appendix gives the locations of some Internet resources for PNG software developers. By the nature of the Internet, the list is incomplete and subject to change. Archive sites The latest released versions of this document and related information can always be found at the PNG FTP archive site, ftp://ftp.uu.net/graphics/png/. The PNG specification is available in several formats, including HTML, plain text, and PostScript. Reference implementation and test images A reference implementation in portable C is available from the PNG FTP archive site, ftp://ftp.uu.net/graphics/png/src/. The reference implementation (libpng) is freely usable in all appli- cations, including commercial applications. Test images are available from ftp://ftp.uu.net/graphics/png/images/. Electronic mail The maintainers of the PNG specification can be contacted by e-mail at [email protected] or at [email protected]. PNG web site There is a World Wide Web site for PNG at http://www.cdrom.com/pub/png/. This is a central location for current information about PNG and PNG-related tools. 17 Appendix: Revision History (This appendix is not part of the formal PNG specification.) The PNG format has been frozen since the Ninth Draft of 7 March 1995, and all future changes are intended to be backward compatible. The revisions since the Ninth Draft are simply clarifications, improvements in presentation, additions of supporting material, and specifications for additional chunks. On 1 October 1996, the PNG 1.0 specification was approved as a W3C (World Wide Web Consortium) Rec- ommendation. 86 PNG (PORTABLE NETWORK GRAPHICS) SPECIFICATION In January 1997 it was published as RFC-2083 (informational) with technical content identical to that of the W3C Recommendation. In October 1998, the PNG 1.1 specification was approved by the PNG Development Group, and it was re- leased in December 1998. In February 1999, changes were approved by the PNG Development Group, and the PNG 1.2 specification containing the changes was released in July 1999. Changes since version 1.1 Note: These changes have been approved by the PNG Development Group, but not by any standards body. Added the iTXt chunk Rearranged the order of presentation of ancillary chunks. Updated the authors’ email addresses Changes since version 1.0 (W3C Recommendation 01-October-1996, RFC 2083 January 1997) Note: These changes have been approved by the PNG Development Group, but not by any standards body. Redefined gAMA to be in terms of the desired display output rather than the original scene, and revised all discussions of gamma and references to gamma accordingly Added the iCCP, sPLT, and sRGB chunks Extended the scope of the 31-bit limit on chunk lengths and image dimensions to apply to all four-byte unsigned integers, and disallowed the value −231 in four-byte signed integers Mentioned the possibility of dithering the alpha channel when converting it to binary transparency Clarified that zlib window sizes smaller than 32K are valid Updated the PNG web site URL and authors’ email addresses Editing and reformatting Changes since the Tenth Draft of 5 May 1995 Clarified meaning of a suggested-palette PLTE chunk in a truecolor image that uses transparency Clarified exact semantics of sBIT and allowed sample depth scaling procedures Clarified status of spaces in text chunk keywords 18. REFERENCES 87 Distinguished private and public extension values in type and method fields Added a “Creation Time” text keyword Macintosh representation of PNG specified Added discussion of security issues Added more extensive discussion of gamma and chromaticity handling, including tutorial appendixes Clarified terminology, notably sample depth vs. bit depth Added a glossary Editing and reformatting 18 References [COLOR-1] Hall, Roy, Illumination and Color in Computer Generated Imagery. Springer-Verlag, New York, 1989. ISBN 0-387-96774-5. [COLOR-2] Kasson, J., and W. Plouffe, “An Analysis of Selected Computer Interchange Color Spaces”, ACM Transactions on Graphics, vol 11 no 4 (1992), pp 373–405. [COLOR-3] Lilley, C., F. Lin, W.T. Hewitt, and T.L.J. Howard, Colour in Computer Graphics. CVCP, Sheffield, 1993. ISBN 1-85889-022-5. [COLOR-4] Stone, M.C., W.B. Cowan, and J.C. Beatty, “Color gamut mapping and the printing of digital images”, ACM Transactions on Graphics, vol 7 no 3 (1988), pp 249–292. [COLOR-5] Travis, David, Effective Color Displays—Theory and Practice. Academic Press, London, 1991. ISBN 0-12-697690-2. [DIGITAL-VIDEO] Poynton, Charles, A Technical Introduction to Digital Video. John Wiley & Sons, 1996. ISBN 0-471-12253-X. http://www.inforamp.net/˜poynton/Poynton-T-I-Digital-Video.html [GAMMA-FAQ] Poynton, C., “Gamma FAQ”. http://www.inforamp.net/ ˜poynton/Poynton-colour.html 88 PNG (PORTABLE NETWORK GRAPHICS) SPECIFICATION [ICC] The International Color Consortium http://www.color.org/ [ISO-639] International Organization for Standardization, “Code for the representation of names of languages”, 1st edition, 1988. [ISO-646] International Organization for Standardization and International Electrotechnical Commission, “Information Technology—ISO 7-bit Coded Character Set for Information Exchange”, 1991. [ISO-3309] International Organization for Standardization, “Information Processing Systems—Data Com- munication High-Level Data Link Control Procedure—Frame Structure”, IS 3309, October 1984, 3rd Edition. [ISO-3664] International Organization for Standardization, “Photography—Illumination Conditions for Viewing Colour Transparencies and their Representation”, IS 3664, 1975. [ISO/IEC-8859-1] International Organization for Standardization and International Electrotechnical Commission, “Information Technology—8-bit Single-Byte Coded Graphic Character Sets—Part 1: Latin Alphabet No. 1”, IS 8859-1, 1998. Also see sample files at ftp://ftp.uu.net/graphics/png/documents/iso 8859-1.* [ISO/IEC-10646-1] International Organization for Standardization and International Electrotechnical Commission, “Information Technology—Universal Multiple-Octet Coded Character Set (UCS)—Part 1: Architec- ture and Basic Multilingual Plane”, 1993. See also “The Unicode Standard” published by the Unicode Consortium http://www.unicode.org and RFC 2279 (F. Yergeau, “UTF-8, a transformation format of ISO 10646”, January 1998) ftp://ftp.isi.edu/in-notes/rfc2279.txt [ITU-R-BT709] International Telecommunications Union, “Basic Parameter Values for the HDTV Standard for the Studio and for International Programme Exchange”, ITU-R Recommendation BT.709 (formerly CCIR Rec. 709), 1990. [ITU-T-V42] International Telecommunications Union, “Error-correcting Procedures for DCEs Using Asynchronous-to-Synchronous Conversion”, ITU-T Recommendation V.42, 1994, Rev. 1. 18. REFERENCES 89 [MNG] Randers-Pehrson, G., et. al., “MNG (Multiple-image Network Graphics Format) Version 0.95”, the latest version of which is available in various formats at ftp://swrinde.nde.swri.edu/pub/mng/documents/. [PAETH] Paeth, A.W., “Image File Compression Made Easy”, in Graphics Gems II, James Arvo, editor. Academic Press, San Diego, 1991. ISBN 0-12-064480-0. [PNG-EXTENSIONS] PNG Group, “Extensions to the PNG 1.2 Specification, Version 1.2.0”. The latest version of this document is available in various formats from ftp://ftp.uu.net/graphics/png/documents/pngext-* [POSTSCRIPT] Adobe Systems Incorporated, PostScript Language Reference Manual, 2nd edition. Addison-Wesley, Reading, 1990. ISBN 0-201-18127-4. [RFC-1123] Braden, R., Editor, “Requirements for Internet Hosts—Application and Support”, STD 3, RFC 1123, USC/Information Sciences Institute, October 1989. ftp://ftp.isi.edu/in-notes/rfc1123.txt [RFC-1766] Harald T. Alvestrand, “Tags for the Identification of Languages”, RFC 1766, UNINETT, March 1995. ftp://ftp.isi.edu/in-notes/rfc1766.txt [RFC-1950] Deutsch, P. and J-L. Gailly, “ZLIB Compressed Data Format Specification version 3.3”, RFC 1950, Aladdin Enterprises, May 1996. ftp://ftp.isi.edu/in-notes/rfc1950.txt [RFC-1951] Deutsch, P., “DEFLATE Compressed Data Format Specification version 1.3”, RFC 1951, Al- addin Enterprises, May 1996. ftp://ftp.isi.edu/in-notes/rfc1951.txt [RFC-2045] Freed, N., and N. Borenstein, “Multipurpose Internet Mail Extensions (MIME) Part One: For- mat of Internet Message Bodies”, RFC 2045, Innosoft, First Virtual, November 1996. ftp://ftp.isi.edu/in-notes/rfc2045.txt [RFC-2048] Freed, N., Klensin, J., and J. Postel, “Multipurpose Internet Mail Extensions (MIME) Part Four: Registration Procedures”, RFC 2048, Innosoft, MCI, USC/Information Sciences Institute, Novem- ber 1996. ftp://ftp.isi.edu/in-notes/rfc2048.txt 90 PNG (PORTABLE NETWORK GRAPHICS) SPECIFICATION [RFC-2119] Bradner, Scott, “Key words for use in RFCs to Indicate Requirement Levels”, RFC 2119, Har- vard University, March 1997. ftp://ftp.isi.edu/in-notes/rfc2119.txt [SMPTE-170M] Society of Motion Picture and Television Engineers, “Television—Composite Analog Video Signal—NTSC for Studio Applications”, SMPTE-170M, 1994. [sRGB] Stokes, Michael, Matthew Anderson, Srinivasan Chandrasekar, and Ricardo Motta, A Standard Default Color Space for the Internet - sRGB. http://www.w3.org/Graphics/Color/sRGB The key portions of this document are being adopted with revisions into: International Electrotechnical Commission, “Colour Measurement and Management in Multimedia Systems and Equipment - Part 2-1: Default RGB Colour Space - sRGB”, IEC 61966-2-1. http://w3.hike.te.chiba-u.ac.jp/IEC/100/PT61966/parts/part2/ 19 Credits Editors Glenn Randers-Pehrson (PNG 1.1 and PNG 1.2), randeg @ alum.rpi.edu Thomas Boutell (PNG 1.0), boutell @ boutell.com Contributing Editors Adam M. Costello (PNG 1.1 and PNG 1.2), amc @ cs.berkeley.edu Tom Lane (PNG 1.0), tgl @ sss.pgh.pa.us Authors Authors’ names are presented in alphabetical order. Spaces have been added to e-mail addresses (around the @ symbols) to minimize the amount of unwanted e-mail via automated harvesters. Mark Adler, madler @ alumni.caltech.edu Thomas Boutell, boutell @ boutell.com John Bowler, jbowler @ acm.org 19. CREDITS 91 Christian Brunschen, christian @ brunschen.com Adam M. Costello, amc @ cs.berkeley.edu Lee Daniel Crocker, lee @ piclab.com Andreas Dilger, adilger @ enel.ucalgary.ca Oliver Fromme, oliver @ fromme.com Jean-loup Gailly, jloup @ gzip.org Chris Herborth, chrish @ qnx.com Alex Jakulin, Aleks.Jakulin @ snet.fri.uni-lj.si Neal Kettler, neal @ westwood.com Tom Lane, tgl @ sss.pgh.pa.us Alexander Lehmann, alex @ hal.rhein-main.de Chris Lilley, chris @ w3.org Dave Martindale, davem @ cs.ubc.ca Owen Mortensen, ojm @ acm.org Keith S. Pickens, ksp @ swri.edu Robert P. Poole Glenn Randers-Pehrson, randeg @ alum.rpi.edu Greg Roelofs, newt @ pobox.com Willem van Schaik, willem @ schaik.com Guy Schalnat, gschal @ infinet.com Paul Schmidt, pschmidt @ photodex.com Michael Stokes, Michael Stokes @ hp.com Tim Wegner, twegner @ phoenix.net Jeremy Wohl, jeremyw @ evantide.com The authors wish to acknowledge the contributions of the Portable Network Graphics mailing list, the readers of comp.graphics, and the members of the World Wide Web Consortium (W3C). The Adam7 interlacing scheme is not patented and it is not the intention of the originator of that scheme to patent it. The scheme may be freely used by all PNG implementations. The name “Adam7” may be freely used to describe interlace method 1 of the PNG specification. 92 PNG (PORTABLE NETWORK GRAPHICS) SPECIFICATION Trademarks GIF is a service mark of CompuServe Incorporated. IBM PC is a trademark of International Business Ma- chines Corporation. Macintosh is a trademark of Apple Computer, Inc. Microsoft, Windows, and MS-DOS are trademarks of Microsoft Corporation. PhotoCD is a trademark of Eastman Kodak Company. PostScript and TIFF are trademarks of Adobe Systems Incorporated. SGI is a trademark of Silicon Graphics, Inc. X Window System is a trademark of the Massachusetts Institute of Technology. Document source This document was built from the file png-master-19990714 on 14 July 1999. Copyright notice Copyright c 1998, 1999 by: Glenn Randers-Pehrson This specification is a modification of the PNG 1.0 specification. It is being provided by the copyright holder under the provisions of the 1996 MIT copyright and license: Copyright c 1996 by: Massachusetts Institute of Technology (MIT) This W3C specification is being provided by the copyright holders under the following license. By obtaining, using and/or copying this specification, you agree that you have read, understood, and will comply with the following terms and conditions: Permission to use, copy, and distribute this specification for any purpose and without fee or royalty is hereby granted, provided that the full text of this NOTICE appears on ALL copies of the specification or portions thereof, including modifications, that you make. THIS SPECIFICATION IS PROVIDED “AS IS,” AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAM- PLE, BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SPECIFICATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SPECIFICATION. The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to the specification without specific, written prior permission. Title to copyright in this specification and any associated documentation will at all times remain with copyright holders. End of PNG Specification