RFC2083 - PNG (Portable Network Graphics) Specification Vers(5)

时间:2005-02-15 来源: 作者: 点击:
15. Appendix: Sample CRC Code The following sample code represents a practical implementation of the CRC (Cyclic Redundancy Check) employed in PNG chunks. (See also ISO 3309 [ISO-3309] or ITU-T V.42
  

15. Appendix: Sample CRC Code

The following sample code represents a practical implementation of
the CRC (Cyclic Redundancy Check) employed in PNG chunks. (See also
ISO 3309 [ISO-3309] or ITU-T V.42 [ITU-V42] for a formal
specification.)

The sample code is in the ANSI C programming language. Non C users
may find it easier to read with these hints:

&
Bitwise AND operator.

^
Bitwise exclusive-OR operator. (Caution: elsewhere in this
document, ^ represents exponentiation.)

>>
Bitwise right shift operator. When applied to an unsigned
quantity, as here, right shift inserts zeroes at the left.

!
Logical NOT operator.

++
"n++" increments the variable n.

0xNNN
0x introduces a hexadecimal (base 16) constant. Suffix L
indicates a long value (at least 32 bits).

/* Table of CRCs of all 8-bit messages. */
unsigned long crc_table[256];

/* Flag: has the table been computed? Initially false. */
int crc_table_computed = 0;

/* Make the table for a fast CRC. */
void make_crc_table(void)
{
unsigned long c;
int n, k;
for (n = 0; n < 256; n++) {
c = (unsigned long) n;
for (k = 0; k < 8; k++) {
if (c & 1)
c = 0xedb88320L ^ (c >> 1);
else
c = c >> 1;
}
crc_table[n] = c;
}
crc_table_computed = 1;
}

/* Update a running CRC with the bytes buf[0..len-1]--the CRC
should be initialized to all 1's, and the transmitted value
is the 1's complement of the final running CRC (see the
crc() routine below)). */

unsigned long update_crc(unsigned long crc, unsigned char *buf,
int len)
{
unsigned long c = crc;
int n;

if (!crc_table_computed)
make_crc_table();
for (n = 0; n < len; n++) {
c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
}
return c;
}

/* Return the CRC of the bytes buf[0..len-1]. */
unsigned long crc(unsigned char *buf, int len)
{
return update_crc(0xffffffffL, buf, len) ^ 0xffffffffL;
}

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 is freely usable in all applications,
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 png-info@uunet.uu.net or at png-group@w3.org.

PNG home page

There is a World Wide Web home page for PNG at
http://quest.jpl.nasa.gov/PNG/. This page 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 March 7,
1995, and all future changes are intended to be backwards compatible.
The revisions since the Ninth Draft are simply clarifications,
improvements in presentation, and additions of supporting material.

On 1 October 1996, the PNG specification was approved as a W3C (World
Wide Web Consortium) Recommendation.

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
* 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.
Also available from
<URL:http://info.mcc.ac.uk/CGU/ITTI/Col/colour_announce.html>

[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.

[GAMMA-FAQ]
Poynton, C., "Gamma FAQ".
<URL:http://www.inforamp.net/%7Epoynton/Poynton-colour.html>

[ISO-3309]
International Organization for Standardization, "Information
Processing Systems --- Data Communication High-Level Data Link
Control Procedure --- Frame Structure", IS 3309, October 1984, 3rd
Edition.

[ISO-8859]
International Organization for Standardization, "Information
Processing --- 8-bit Single-Byte Coded Graphic Character Sets ---
Part 1: Latin Alphabet No. 1", IS 8859-1, 1987.
Also see sample files at
ftp://ftp.uu.net/graphics/png/documents/iso_8859-1.*

[ITU-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-V42]
International Telecommunications Union, "Error-correcting
Procedures for DCEs Using Asynchronous-to-Synchronous Conversion",
ITU-T Recommendation V.42, 1994, Rev. 1.

[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.

[POSTSCRIPT]
Adobe Systems Incorporated, PostScript Language Reference Manual,
2nd edition. Addison-Wesley, Reading, 1990. ISBN 0-201-18127-4.

[PNG-EXTENSIONS]
PNG Group, "PNG Special-Purpose Public Chunks". Available in
several formats from
ftp://ftp.uu.net/graphics/png/documents/pngextensions.*

[RFC-1123]
Braden, R., Editor, "Requirements for Internet Hosts ---
Application and Support", STD 3, RFC1123, USC/Information
Sciences Institute, October 1989.
<URL:ftp://ds.internic.net/rfc/rfc1123.txt>

[RFC-2045]
Freed, N., and N. Borenstein, "Multipurpose Internet Mail
Extensions (MIME) Part One: Format of Internet Message Bodies",
RFC2045, Innosoft, First Virtual, November 1996.
<URL:ftp://ds.internic.net/rfc/rfc2045.txt>

[RFC-2048]
Freed, N., Klensin, J., and J. Postel, "Multipurpose Internet Mail
Extensions (MIME) Part Four: Registration Procedures", RFC2048,
Innosoft, MCI, USC/Information Sciences Institute, November 1996.
<URL:ftp://ds.internic.net/rfc/rfc2048.txt>

[RFC-1950]
Deutsch, P. and J-L. Gailly, "ZLIB Compressed Data Format
Specification version 3.3", RFC1950, Aladdin Enterprises, May
1996.
<URL:ftp://ds.internic.net/rfc/rfc1950.txt>

[RFC-1951]
Deutsch, P., "DEFLATE Compressed Data Format Specification version
1.3", RFC1951, Aladdin Enterprises, May 1996.
<URL:ftp://ds.internic.net/rfc/rfc1951.txt>

[SMPTE-170M]
Society of Motion Picture and Television Engineers, "Television
--- Composite Analog Video Signal --- NTSC for Studio
Applications", SMPTE-170M, 1994.

19. Credits

Editor

Thomas Boutell, boutell@boutell.com

Contributing Editor

Tom Lane, tgl@sss.pgh.pa.us

Authors

Authors' names are presented in alphabetical order.

* Mark Adler, madler@alumni.caltech.edu
* Thomas Boutell, boutell@boutell.com
* Christian Brunschen, cb@df.lth.se
* Adam M. Costello, amc@cs.berkeley.edu
* Lee Daniel Crocker, lee@piclab.com
* Andreas Dilger, adilger@enel.ucalgary.ca
* Oliver Fromme, fromme@rz.tu-clausthal.de
* Jean-loup Gailly, gzip@prep.ai.mit.edu
* Chris Herborth, chrish@qnx.com
* Alex Jakulin, Aleks.Jakulin@snet.fri.uni-lj.si
* Neal Kettler, kettler@cs.colostate.edu
* 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, 104707.650@compuserve.com
* Keith S. Pickens, ksp@swri.edu
* Robert P. Poole, lionboy@primenet.com
* Glenn Randers-Pehrson, glennrp@arl.mil or
randeg@alumni.rpi.edu
* Greg Roelofs, newt@pobox.com
* Willem van Schaik, willem@gintic.gov.sg
* Guy Schalnat
* Paul Schmidt, pschmidt@photodex.com
* Tim Wegner, 71320.675@compuserve.com
* Jeremy Wohl, jeremyw@anders.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.

Trademarks

GIF is a service mark of CompuServe Incorporated. IBM PC is a
trademark of International Business Machines Corporation.
Macintosh is a trademark of Apple Computer, Inc. Microsoft 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.

COPYRIGHT NOTICE

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
EXAMPLE, 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.

Security Considerations

Security issues are discussed in Security considerations (Section
8.5).

Author's Address

Thomas Boutell
PO Box 20837
Seattle, WA 98102

Phone: (206) 329-4969
EMail: boutell@boutell.com
------分隔线----------------------------
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
最新评论 查看所有评论
发表评论 查看所有评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码:
推荐内容