File proposed_filter_methods_20000909.txt It is proposed to replace the relevant paragraphs in the MNG-0.97 specification with the following: 4.2.3. IHDR, PNG chunks, IEND A PNG (Portable Network Graphics) datastream. See the PNG specification [PNG] and the Extensions to the PNG Specification document [PNG-EXT] for the format of the PNG chunks. The IHDR and IEND chunks and any chunks between them are written and decoded according to the PNG specification, except as extended in this section. These extensions do not apply to standalone PNG datastreams that have the PNG signature, but only to PNG datastreams that are embedded in a MNG datastream that begins with a MNG signature and the MHDR chunk. * If a global PLTE chunk appears in the top-level MNG datastream, the PNG datastream can have an empty PLTE chunk, to direct that the global PLTE and tRNS data be used. If an empty PLTE chunk is not present, the data is not inherited. MNG applications that recreate PNG files must write the global PLTE chunk rather than the empty one in the output PNG file, along with the global tRNS data if it is present. The global tRNS data can be subsequently overridden by a tRNS chunk in the PNG datastream. It is an error for the PNG datastream to contain an empty PLTE chunk when the global PLTE chunk is not present or has been nullified. * Additional PNG filter methods are defined: 1: Implicit "none" filtering of every scanline; filter bytes are omitted from the compressed datastream in the IDAT chunk(s). 64: Adaptive filtering with five basic types, intrapixel differencing, and leveling. A set of level samples appears immediately prior to the filter byte for the first scanline in the IDAT chunk. 65: Intrapixel differencing and pixel leveling, with implicit "none" scanline filtering. This transformation, which is a modification of a method previously used in the LOCO image format [LOCO], is S0 = Red - Green - L0 (when color_type 2 or 6) or S0 = Index - L0 (when color_type 3) or S0 = Gray - L0 (when color_type 0 or 4) S1 = Green - L1 (when color_type 2 or 6) or S1 = Alpha - L1 (when color_type 4) S2 = Blue - Green - L2 (when color_type 2 or 6) S3 = Alpha - L3 (when color_type 6) The transformation is done in integer arithmetic in sufficient precision to hold intermediate results, and the result is stored modulo the sample depth. Intrapixel differencing (subtracting the green sample) is only done for color types 2 and 6, and only when the filter method is 64 or 65. When the filter method is 64 or 65, the level values are inserted at the beginning of the compressed datastream contained in the IDAT chunk, immediately ahead of the first filter byte for the first row of pixels. [Experiments with putting a separate level set ahead of each filter byte have not been promising; the savings in filesize was offset by the extra storage for the level sets.] The filter method can be understood and implemented as two separate bit fields: bit 0: Scanline filtering method 0: Adaptive filtering with five basic types, with a filter_type byte for each scanline. 1: No scanline filtering, and no filter_type bytes (implicit filter_type "none"). bit 6: Intrapixel methods 0: No pixel leveling or intrapixel filtering. 1: Pixel leveling and intrapixel differencing. The level set contains 16-bit samples if the image sample depth is 16, otherwise it contains 8-bit samples. In indexed-color images, the level is applied to the raw palette index, not to the decoded colors. When the sample depth is less than 8, it is not an error for the level to be greater than 15; the modulo arithmetic will simply ignore the most significant bits. In tests, the set (132, 0, 132) has worked well with a large set of truecolor images. It has been demonstrated to improve the compressibility of natural images by 10 to 15 percent of the compressibility of RGB data. This seems to be due to the intrapixel correlation between color samples, which is ignored by the PNG filters. The RGB samples are recovered, after undoing the basic filtering, by the inverse of the transformation, which for RGBA images is Green = S1 + L1 Red = S0 + L0 + Green Blue = S2 + L2 + Green Alpha = S3 + L3 As in the forward transformation, the inverse transformation is done in integer arithmetic in sufficient precision to hold intermediate results, and the result taken modulo the sample depth. Applications that convert a MNG datastream to a series of PNG datastreams must convert any PNG datastream with one of the additional filter methods to a standard PNG datastream with a PNG filter method (currently 0 is the only valid filter method). These extra filter methods can also be used in PNG datastreams that are embedded in Delta-PNG and BASI datastreams and in the JNG IDAT chunks that carry the JNG alpha channel. It is suggested that encoders write a "nEED MNG-1.0" chunk if they use this feature, for the benefit of pre-MNG-1.0 decoders. Applications must not write independent PNG datastreams (with either the .png or .mng file extension) with these new filter methods, unless they should become officially approved for use in PNG datastreams. For experimenting and testing, applications can use a value greater than 128 for this purpose, as permitted in the PNG specification. [...] 4.2.5. BASI, PNG chunks, IEND [...] The sample depth, color type, compression method, and interlace method must be valid PNG types, and the width and height must be within the valid range for PNG datastreams. The filter method must be one of the filter methods allowed in PNG datastreams or one of the additional filter methods (1, 64, or 65) allowed in PNG datastreams that are embedded in MNG datastreams. [...] 5.1.3. IDAT JNG PNG-encoded alpha data This chunk is exactly like the IDAT chunk in a PNG grayscale image, except that it is interpreted as an alpha mask to be applied to the image data from the JDAT chunks, when alpha_compression_method=0. The alpha channel, if present, can have sample depths 1, 2, 4, 8, or 16. The filter method can be any filter method that is defined for PNG datastreams that are embedded in MNG datastreams. Besides the filter methods defined in the PNG specification, MNG defines additional filter methods: 1: Implicit "none" filtering of every scanline; filter bytes are omitted from the compressed datastream in the IDAT chunk(s). 64: Adaptive filtering with five basic types, intrapixel differencing, and leveling. A set of level samples appears immediately prior to the filter byte for the first scanline in the IDAT chunk. 65: Intrapixel differencing and pixel leveling, with implicit "none" scanline filtering. For grayscale PNG datastreams, this means that when the filter method is 1 or 65, the filter byte is omitted from the beginning of each scanline, and when it is 64 or 65, a single "level" sample appears as the first byte (or first two bytes, if the sample depth is 16) of the compressed data; this value is subtracted from each pixel (modulo the sample depth) when encoding (prior to applying the basic filtering), and added to each pixel (modulo the sample depth) when decoding (after undoing the basic filtering). Because there is only one sample per pixel, there is no intrapixel differencing. The IDAT chunks can be interleaved with the JDAT chunks (see Recommendations for Encoders: JNG interleaving below). No other chunk type can appear among the sequence of IDAT and JDAT chunks. No other chunk type can appear between the sequences of IDAT and JDAT chunks when they are not interleaved. The samples in the IDAT must be presented in noninterlaced order, left to right, top to bottom. As in PNG, zero means fully transparent and 2^alpha_sample_depth-1 means fully opaque. The IDAT chunks must precede the JSEP chunk, if the JSEP chunk is present. [...] 6. The Delta-PNG Format [...] Chunk structure (length, name, CRC) and the chunk-naming system are identical to those defined in the PNG specification. Definitions of compression_method and interlace_method are also the same as defined in the PNG specification. The definition of filter_method is the same as for PNG datastreams that are embedded in MNG datastreams (see the IHDR chunk specification, above, Paragraph 4.2.3). [...] 13. Rationale This (incomplete as of version 0.97) section does not form a part of the specification. It provides the rationale behind some of the design decisions in MNG. New critical chunk versus filter method 64 Filter method 64 could have been implemented as a new critical chunk in PNG or in MNG, e.g. FILT type L0 L1 L2 L3 in which L0-L3 are 16-bit values that convey the levels for the various color channels, type is one of the additional filter methods, and an empty FILT chunk turns off this type of filtering. The choice of using a new filter method instead of a new critical chunk was made based on simplicity of implementation and eventual inclusion of this method in PNG. We did not have any experimental evidence suggesting that it would be useful to have a separate level set for each scanline. It is possible that this would be effective for very wide images, however, and more filter methods could be defined to achieve this. We considered additional filter methods in which the level samples were implicitly zero, but this saves an insignificant amount of space (up to 8 bytes per PNG datastream) and the additional complexity is not warranted. [...]