PNG (Portable Network Graphics) Specification Version
Total Page:16
File Type:pdf, Size:1020Kb
PNG (Portable Network Graphics) Speci®cation Version 1.0 For list of authors, see Credits (Chapter 19). Status of this document This document has been reviewed by W3C members and other interested parties and has been endorsed by the Director as a W3C Recommendation. It is a stable document and may be used as reference material or cited as a normative reference from another document. W3C's role in making the Recommendation is to draw attention to the speci®cation and to promote its widespread deployment. This enhances the functionality and interoperability of the Web. A list of current W3C Recommendations and other technical documents can be found at http://www.w3.org/ pub/WWW/TR/. The Consortium staff have encouraged the development of PNG, as have Compuserve, Inc. Most of the work has been done by the PNG Development Group, [email protected]. The Consortium does not currently have plans to work on any future versions of PNG, though were the necessity to arise, and were an activity in that area to receive the support of Members, the Consortium could in principle support some future activity. Abstract This document describes PNG (Portable Network Graphics), an extensible ®le 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 ®le 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 speci®cation de®nes a proposed Internet Media Type image/png. 2 PNG (PORTABLE NETWORK GRAPHICS) SPECIFICATION Contents 1 Introduction 5 2 Data Representation 6 2.1 Integersandbyteorder.................................... 6 2.2 Colorvalues.......................................... 6 2.3 Image layout . ....................................... 7 2.4 Alphachannel......................................... 8 2.5 Filtering ............................................ 8 2.6 Interlaced data order ...................................... 9 2.7 Gammacorrection....................................... 10 2.8 Textstrings........................................... 10 3 File Structure 10 3.1 PNG®lesignature....................................... 10 3.2 Chunk layout . ....................................... 11 3.3 Chunk naming conventions .................................. 11 3.4 CRC algorithm . ....................................... 13 4 Chunk Speci®cations 14 4.1 Critical chunks . ....................................... 14 4.1.1 IHDR Imageheader.................................. 14 4.1.2 PLTE Palette..................................... 15 4.1.3 IDAT Imagedata................................... 16 4.1.4 IEND Imagetrailer.................................. 17 4.2 Ancillary chunks . ....................................... 17 4.2.1 bKGD Background color . ............................ 17 4.2.2 cHRM Primary chromaticities and white point . ................. 18 4.2.3 gAMA Imagegamma................................. 18 4.2.4 hIST Imagehistogram................................ 19 4.2.5 pHYs Physicalpixeldimensions........................... 19 4.2.6 sBIT Signi®cantbits................................. 20 4.2.7 tEXt Textualdata.................................. 20 4.2.8 tIME Imagelast-modi®cationtime......................... 22 4.2.9 tRNS Transparency.................................. 22 4.2.10 zTXt Compressedtextualdata............................ 23 4.3 Summary of standard chunks ................................. 24 4.4 Additional chunk types . .................................. 25 5 De¯ate/In¯ate Compression 25 PNG (PORTABLE NETWORK GRAPHICS) SPECIFICATION 3 6 Filter Algorithms 26 6.1 Filter types ........................................... 26 6.2 Filter type 0: None ....................................... 27 6.3 Filter type 1: Sub ....................................... 27 6.4 Filter type 2: Up . ....................................... 28 6.5 Filter type 3: Average . .................................. 29 6.6 Filter type 4: Paeth ...................................... 29 7 Chunk Ordering Rules 30 7.1 BehaviorofPNGeditors................................... 31 7.2 Ordering of ancillary chunks ................................. 31 7.3 Ordering of critical chunks .................................. 32 8 Miscellaneous Topics 32 8.1 Filenameextension...................................... 32 8.2 Internetmediatype...................................... 32 8.3 Macintosh ®le layout . .................................. 32 8.4 Multiple-image extension . .................................. 33 8.5 Security considerations . .................................. 33 9 Recommendations for Encoders 33 9.1 Sampledepthscaling..................................... 34 9.2 Encodergammahandling................................... 35 9.3 Encodercolorhandling.................................... 37 9.4 Alphachannelcreation.................................... 38 9.5 Suggested palettes ....................................... 38 9.6 Filter selection . ....................................... 39 9.7 Text chunk processing . .................................. 39 9.8 Use of private chunks . .................................. 40 9.9 Privatetypeandmethodcodes................................ 41 10 Recommendations for Decoders 41 10.1 Errorchecking......................................... 41 10.2 Pixeldimensions........................................ 42 10.3 Truecolorimagehandling................................... 42 10.4 Sampledepthrescaling.................................... 42 10.5 Decodergammahandling................................... 43 10.6 Decodercolorhandling.................................... 45 10.7 Background color ....................................... 46 10.8 Alphachannelprocessing................................... 46 10.9 Progressivedisplay...................................... 50 10.10 Suggested-palette and histogram usage ............................ 51 10.11 Text chunk processing . .................................. 52 4 PNG (PORTABLE NETWORK GRAPHICS) SPECIFICATION 11 Glossary 52 12 Appendix: Rationale 56 12.1 Whyanew®leformat?.................................... 56 12.2 Whythesefeatures?...................................... 56 12.3 Whynotthesefeatures?.................................... 57 12.4 WhynotuseformatX?.................................... 58 12.5 Byteorder........................................... 58 12.6 Interlacing........................................... 59 12.7 Whygamma?......................................... 59 12.8 Non-premultiplied alpha . .................................. 60 12.9 Filtering ............................................ 60 12.10Textstrings........................................... 61 12.11PNG®lesignature....................................... 61 12.12 Chunk layout . ....................................... 62 12.13 Chunk naming conventions .................................. 62 12.14Palettehistograms....................................... 63 13 Appendix: Gamma Tutorial 64 14 Appendix: Color Tutorial 70 15 Appendix: Sample CRC Code 74 16 Appendix: Online Resources 76 17 Appendix: Revision History 76 18 References 77 19 Credits 79 1. INTRODUCTION 5 1 Introduction The PNG format provides a portable, legally unencumbered, well-compressed, well-speci®ed standard for lossless bitmapped image ®les. Although the initial motivation for developing PNG was to replace GIF, 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: ®les can be read and written serially, thus allowing the ®le format to be used as a com- munications protocol for on-the-¯y generation and display of images. Progressive display: a suitably prepared image ®le 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 ®le. 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 ®le 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.