It is a proposal, and the format is subject to change.
Comments on this document can be sent to the PNG specification maintainers at one of the following addresses:
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/mng/documents/.In the case of any discrepancy between this extract and the full MNG specification, the full MNG specification shall take precedence.
JNG (JPEG Network Graphics) is the lossy sub-format for MNG objects.
Note: This specification depends on the PNG Portable Network Graphics specification [PNG]. The PNG specification is available at the PNG home page,
http://www.cdrom.com/pub/png/A JNG datastream consists of a header chunk (JHDR), JDAT chunks that contain a complete JPEG datastream, and optionally, IDAT chunks that contain a PNG-encoded grayscale image that is to be used as an alpha mask. Such a mask must have the same dimensions as the image itself. The JDAT and IDAT chunks can be interleaved. Some of the PNG ancillary chunks are also recognized in JNG datastreams.
While JNG is primarily intended for use as a sub-format within MNG, a single-image JNG datastream can be written in a standalone file. If so, the first eight bytes of a JNG datastream are
139 80 78 74 13 10 26 10(decimal) which is similar to the PNG signature with "\213 J N G" instead of "\211 P N G" in bytes 0-3.
JNG is pronounced "Jing."
Width: 4 bytes (unsigned integer, range 0..65535). Height: 4 bytes (unsigned integer, range 0..65535). Color type: 1 byte 8: Gray (Y). 10: Color (YCbCr). 12: Gray-alpha (Y-alpha). 14: Color-alpha (YCbCr-alpha). JDAT sample depth: 1 byte 8: 8-bit samples and quantization tables. 12: 12-bit samples and quantization tables. 20: 12-bit image followed by an eight-bit image. JDAT compression method: 1 byte 8: ISO-10918-1 Huffman-coded baseline JPEG. JDAT interlace method: 1 byte. 0: Sequential JPEG, single scan. 8: Progressive JPEG. IDAT sample depth: 1 byte. 0, 1, 2, 4, 8, or 16. IDAT compression method: 1 byte. 0: Zlib DEFLATE. IDAT filter method: 1 byte. 0: Adaptive (see PNG spec). IDAT interlace method: 1 byte. 0: Not interlaced.The width, height, JDAT_sample_depth, JDAT_compression_method, and JDAT_interlace_method fields are redundant because equivalent information is also embedded in the JDAT datastream. They appear in the JHDR chunk for convenience. Their values must be identical to their equivalents embedded in the JDAT chunk. We use four bytes in the width and height fields for similarity to MNG and PNG, and to leave room for future expansion, even though two bytes would have been sufficient.
When the color_type is 8 or 10 (no alpha channel), the last four bytes, which describe the IDAT data, must be set to zero. The IDAT_sample_depth must be nonzero when the alpha channel is present.
A JNG baseline JPEG is a baseline JPEG as defined by JPEG Part 1 (ISO IS 10918-1), using only JFIF-compatible component interpretations, with a few additional restrictions that reflect limitations of many existing JPEG implementations.
A baseline JPEG according to Part 1 is DCT-based (lossy) sequential JPEG, using Huffman entropy encoding, with the following further restrictions:
JDAT datastreams must always follow "interchange JPEG" rules: all necessary quantization and Huffman tables must be included in the datastream, no tables can be omitted.
The image data is always stored left-to-right, top-to-bottom, ie, only the default SPIFF orientation is permissible.
The encoded data shall have one of the two colorspace interpretations allowed by the JFIF specification:
Y = Luma_red*R + Luma_green*G + Luma_blue*B Cb = (B - Y) / (2 - 2*Luma_blue) + Half_scale Cr = (R - Y) / (2 - 2*Luma_red) + Half_scaleBy convention, the luminance coefficients are always those defined by CCIR Recommendation 601-1:
Luma_red = 0.299 Luma_green = 0.587 Luma_blue = 0.114The constant Half_scale is 128 when dealing with 8-bit data, 2048 for 12-bit data. With these equations, Y, Cb, and Cr all have the same range as R, G, and B: 0 to 255 for 8-bit data, 0 to 4095 for 12-bit data.
The JFIF convention for YCbCr differs from typical digital television practice in that no headroom/footroom is reserved: the coefficient values range over the full available 8 or 12 bits.
Intercomponent sample alignment shall be such that the first (upper leftmost) samples of each component share a common upper left corner position. This again differs from common digital TV practice, in which the first samples share a common center position. The JFIF convention is simpler to visualize: subsampled chroma samples always cover an integral number of luminance sample positions, whereas with co-centered alignment, chroma samples only partially overlap some luminance samples.
JNG imposes three additional restrictions not found in the text of either JPEG Part 1 or the JFIF specification:
In other words, the chroma components may be downsampled 2:1 or 1:2 horizontally or vertically relative to luminancey, or they may be left full size. These four sampling ratios are the only ones supported by a wide spectrum of implementations (1x2 is relatively new, and is usually the result of a lossless rotation of a 2x1 sampling).
For grayscale images, the sampling factors are irrelevant according to a strict reading of JPEG Part 1. Hence decoder authors should accept any sampling factors for grayscale. However, we recommend that encoders always emit sampling factors 1h1v for grayscale, since some decoders have been observed to malfunction when presented with other sampling factors.
For JNG progressive JPEG datastreams, the JPEG process is progressive Huffman coding (SOF marker type SOF2) rather than baseline (SOF0). All JNG-compliant decoders must support full progression, including both spectral-selection and successive-approximation modes, with any sequence of scan progression parameters allowed by the JPEG Part 1 standard.
Otherwise, all the restrictions listed above apply, except these:
No particular progressive scan sequence is specified or recommended by this specification. Not enough experience has been gained with progressive JPEG to warrant making such a recommendation. To allow for future experimentation with scan sequences, decoders are expected to handle any JPEG-legal sequence. Again, the code savings that might be had by making restrictive assumptions are too small to justify a limitation.
When the JSEP chunk is present, both images must be progressive if one of them is progressive.
The IDAT chunks must precede the JSEP chunk, if the JSEP chunk is present. Minimal viewers that skip the 12-bit JDAT chunks must read the IDAT chunks and apply the alpha samples to the 8-bit image that is contained in the JDAT chunks that follow the JSEP chunk.
A JSEP chunk must appear between the JDAT chunks of a 12-bit datastream and those of an 8-bit datastream, when JDAT_sample_depth=20 in the JHDR chunk. The 12-bit datastream must appear first. Both images must have the same width, height, color type, compression method, and interlace type. Viewers can choose to display one or the other image, but not both.
If the bKGD chunk is present, it must be written as if it were written for a PNG datastream with sample_depth=8. It has one 2-byte entry for grayscale JNGs and three 2-byte entries for color JNGs. The first (most significant) byte of each entry must be 0.
The following chunks have exactly the same meaning and have the same format as given in the PNG specification: cHRM, gAMA, iCCP, sRGB, pHYs, oFFs, tEXt, tIME, and zTXt.
The PNG PLTE, hIST, pCAL, sBIT, and tRNS chunks are not defined in JNG.
When cHRM, gAMA, iCCP, or sRGB are present, they provide information about the colorspace of the decoded JDAT image, and they have no effect on the decoded alpha samples from the IDAT chunks.
The chunk copying and ordering rules for JNG are the same as those in PNG, except for the fact that JDAT and IDAT chunks can be interleaved.
Phone: (410) 278-6554
EMail: randeg @ alumni.rpi.edu
End of JNG Specification.
This document expires on 30 March 1999