Comments on this document can be sent to the PNG specification maintainers at one of the following addresses:
png-list@dworkin.wustl.edu. png-group@w3.org png-info@uunet.uu.net
Distribution of this memo is unlimited.
At present, the latest version of this document is available on the World Wide Web from
ftp://swrinde.nde.swri.edu/pub/png/documents/.
Permission is granted to copy and distribute this document for any purpose and without charge, provided that the copyright notice and this notice are preserved, and that any substantive changes or deletions from the original are clearly marked.
<URL:ftp://swrinde.nde.swri.edu/pub/png/documents/:gt;
.
chunk name Multiple Ordering OK? constraints pCAL No Before IDAT
The "pCAL" chunk's contents are are a zero-byte-terminated text string (purpose) that names the equation, followed by original sample limits "X0" and "X1", an equation type, and a set of parameters for the equation:
n bytes: purpose (Latin-1 text) 1 byte: null separator 4 bytes: X0 (signed integer) Lower limit of original sample range. This original sample value is mapped to the stored sample value 0. 4 bytes: X1 (signed integer) Upper limit of original sample range. This original sample value is mapped to the stored sample value (2^sample_depth - 1). Must not equal X0. 1 byte: Equation type (unsigned integer). 0: Linear mapping 1: Base-e exponential mapping 2: Arbitrary-base exponential mapping 3: Hypberbolic mapping 1 byte: N (unsigned integer), number of parameters. u bytes: Unit (Latin-1 string). Symbol or description of the unit, eg. K, Population Density, MPa, etc). A zero-length string can be used if the data is dimensionless. 1 byte: null separator p0 bytes: P0 (ASCII text). First parameter, a real number written as a text floating-point value [link to Floating-Point Values in PNG extensions document] 1 byte: null separator p1 bytes: P1 (ASCII text). Second parameter. etc.There is no null separator after the final parameter (or after the "Unit" field, if N=0). The number of parameters present must agree with the "N" field and must be correct for the specified "equation_type".
The "purpose" identifies the equation, which can permit applications or people to choose the appropriate one when more than one "pCAL" chunk is present (this could occur in a multiple-image file, but not in a PNG file). The "purpose" string must follow the format of a "tEXt" keyword, i.e. 1-79 printable Latin-1 characters. One way the "purpose" field could be used s to identify the system of units. A "purpose" string such as "SI" or "English" could be used in the "pCAL" chunk as well as in other chunk types, to permit a decoder to select an appropriate set of chunks based on the contents of their "purpose" fields.
The "pCAL" chunk defines two mappings:
original_sample = (stored_sample * (X1 - X0) + M/2) / M + X0using integer arithmetic, where (a / b) means (integer(floor(real(a) / real(b)))). Note that this is the same as the "/" operator in the C programming language when "a" and "b" are nonnegative, but not necessarily when "a" or "b" is negative.
if equation_type = 0 then physical_value = P0 + P1 * original_sample/(X1-X0) else if equation_type = 1 then physical_value = P0 + P1 * EXP(P2 * original_sample/(X1-X0)) else if equation_type = 2 then physical_value = P0 + P1 * P2^(original_sample/(X1-X0)) else if equation_type = 3 then physical_value = P0 + P1*SINH(P2*(original_sample - P3)/(X1-X0))using floating point arithmetic, in which
SINH(x) = 0.5 * ( EXP(x) - EXP(-x) )
stored_sample = ((original_sample - X0) * M + (X1 - X0) / 2) / (X1 - X0) (limited to the range [0..M])This mapping is lossless and reversible when (ABS(X1-X0) <= M) and the original sample is in the range [X0..X1]. If (ABS(X1-X0) > M) then there can be no lossless reversible mapping, but the functions provide the best integer approximations to floating-point affine transformations.
For color_types 2, 3, and 6, the mapping algorithms are applied independently to each of the color sample values. In the case of color type 3 (indexed color), the mapping refers to the RGB samples and not to the index values.
Linear data can be expressed with equation_type 1.
Pure logarithmic data can be expressed either with
X0 = 0 X0 = 0 X1 = M X1 = M Equation_type = 1 Equation_type = 2 N = 3 or with N = 3 P0 = 0 P0 = 0 P1 = min P1 = min P2 = LOGe(max/min) P2 = max/minEquation types 1 and 2 are functionally equivalent; both are defined because authors may find one or the other more convenient.
Using equation type 3, floating point data in the range {-v0..v1} can be reduced (with loss) to a set of integer samples such that the resolution of the stored data is roughly proportional to its magnitude. For example, floating point data ranging from -10^31 to 10^31 (the usual range of floating point numbers on 32-bit machines) can be represented with
X0 = 0 X1 = 65536 Equation_type = 3 N = 4 P0 = 0.0 P1 = 1.0e-30 P2 = 280.0 P3 = 32767.0The resolution near zero is about 10^-33, while the resolution around +/-10^31 is about 10^28. Everywhere the resolution is about 0.4 percent of the magnitude.
Applications should use double precision arithmetic (or take other precautions) while performing the mappings for equation types 1, 2, and 3, to prevent overflow of intermediate results when the parameter "P1" is small and the exponential or power functions are large.
If present, the "pCAL" chunk must appear before the first "IDAT" chunk. Only one instance of the "pCAL" chunk is permitted in a PNG stream.
Boutell, T., et. al.,
PNG (Portable Network Graphics Format Version 1.0),
RFC 2083,
<URL:ftp://ds.internic.net/rfc/rfc2083.txt>
also available at
<URL:ftp://swrinde.nde.swri.edu/pub/png/documents/>.
This specification has also been published as a W3C Recommendation, which
is available at <URL:http://www.w3.org>.
PNG Special-Purpose Public Chunks, <URL:ftp://swrinde.nde.swri.edu/pub/png/documents/>.
Applications must take care to avoid underflow and overflow of intermediate results when converting data from one form to another according to the "pCAL" mappings.