home *** CD-ROM | disk | FTP | other *** search
/ Compressed Image File Formats / CompressedImageFileFormatsJohnMiano.iso / pc / Specs / mng-0.91-19990202-pdg.txt < prev    next >
Encoding:
Text File  |  1999-02-09  |  262.2 KB  |  5,474 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.        MNG (Multiple-image Network Graphics) Format Version 0.91
  7.  
  8. For list of authors, see Credits (Chapter 16).
  9.  
  10.    Status of this Memo
  11.  
  12.       This document is an informal draft of the PNG development group.
  13.  
  14.       It is a proposal, and the format is subject to change.
  15.  
  16.       Comments on this document can be sent to the PNG specification
  17.       maintainers at one of the following addresses:
  18.  
  19.           * mpng-list@ccrc.wustl.edu
  20.  
  21.           * png-group@w3.org
  22.  
  23.           * png-info@uunet.uu.net
  24.  
  25.       Distribution of this memo is unlimited.
  26.  
  27.       At present, the latest version of this document is available on
  28.       the World Wide Web from
  29.  
  30.          ftp://swrinde.nde.swri.edu/pub/mng/documents/.
  31.  
  32. Changes from fifty-fifth MNG draft (mng-0.9-19981231)
  33.  
  34.        * Relaxed requirement for sample_depth to be the same as that of
  35.          the parent object of a delta-PNG.  This implies that the object
  36.          buffer must carry two additional pieces of information: a
  37.          "pixel sample depth" and an "alpha sample depth", for use in
  38.          decoding Delta-PNG IDAT chunk data.
  39.  
  40.        * Added two new Delta-PNG delta_types, for updating the color
  41.          channels of GA and RGBA objects, and renumbered the old
  42.          delta_types 3, 4 and 5 to 4, 5, and 7.  The new types are 3 and
  43.          6.
  44.  
  45.        * Revised the LOOP specification to allow the iteration_min and
  46.          iteration_max fields to be omitted, with default values 1 and
  47.          infinity.  This is to encourage people to use "iteration_min=1"
  48.          whenever possible, with only a one-byte penalty instead of a
  49.          nine-byte penalty per LOOP.
  50.  
  51.        * Revised the simplicity profile,
  52.              * to use a separate flag for Delta-PNG
  53.              * to allow DEFI to appear in "simple" MNGs when it defines
  54.                object 0
  55.              * to allow LOOP to appear in "simple" MNGs when it has
  56.                "iteration_min=1"
  57.              * to allow the FRAM chunk in "simple" MNGs
  58.        * Revised the minimal support chapter to make references to the
  59.          simplicity profile.  Added JSEP to the list of chunks that need
  60.          to be supported in Delta-PNGs.
  61.  
  62. Abstract
  63.  
  64.    This document presents the format of a MNG (Multiple-image Network
  65.    Graphics) datastream.  MNG is a multiple-image member of the PNG
  66.    (Portable Network Graphics) format family, that can contain
  67.    animations (slide shows) comprised of PNG single-image datastreams.
  68.    It can also incorporate images in a highly compressible "Delta-PNG"
  69.    format, defined herein, or a lossy JNG (JPEG Network Graphics)
  70.    format, also defined herein.
  71.  
  72.    The MNG format provides a mechanism for reusing image data without
  73.    having to retransmit it.  Multiple images can be composed into a
  74.    "frame" and a group of images can be used as an animated "sprite"
  75.    that moves from one location to another in subsequent frames.
  76.    "Palette animations" are also possible.
  77.  
  78.    A MNG frame normally contains a two-dimensional image or a two-
  79.    dimensional layout of smaller images.  It could also contain three-
  80.    dimensional "voxel" data arranged as a series of two-dimensional
  81.    planes (or tomographic slices), each plane being represented by a PNG
  82.    or Delta-PNG datastream.
  83.  
  84.    A Delta-PNG datastream defines an image in terms of a parent PNG or
  85.    Delta-PNG image and the differences from that image.  This has been
  86.    demonstrated to provide a much more compact way of representing
  87.    subsequent images than using a complete PNG datastream for each.
  88.  
  89.    The MNG and JNG formats use the same chunk structure that is defined
  90.    in the PNG specification, and they share other features of the PNG
  91.    format.  Any valid PNG or JNG datastream is also a valid MNG
  92.    datastream.
  93.  
  94.    This document includes examples that demonstrate various capabilities
  95.    of MNG including simple movies, composite frames, loops, fades,
  96.    tiling, scrolling, storage of voxel data, and converting GIF
  97.    animations to MNG format.
  98.  
  99. Table of Contents
  100.  
  101.    1. Introduction ................................................... 1
  102.    2. Terminology .................................................... 1
  103.    3. Objects ........................................................ 1
  104.       3.1. Embedded objects .......................................... 1
  105.       3.2. Object attributes ......................................... 1
  106.       3.3. Object buffers ............................................ 1
  107.    4. MNG Chunks ..................................................... 1
  108.       4.1. Critical MNG control chunks ............................... 1
  109.           4.1.1. MHDR MNG datastream header .......................... 1
  110.           4.1.2. MEND End of MNG datastream .......................... 1
  111.           4.1.3. LOOP, ENDL Define a loop ............................ 1
  112.       4.2. Critical MNG image defining chunks ........................ 1
  113.           4.2.1. DEFI Define an object ............................... 1
  114.           4.2.2. PLTE Global palette ................................. 1
  115.           4.2.3. IHDR, PNG chunks, IEND .............................. 1
  116.           4.2.4. JHDR, JNG chunks, IEND .............................. 1
  117.           4.2.5. BASI, PNG chunks, IEND .............................. 1
  118.           4.2.6. CLON Clone an object ................................ 1
  119.           4.2.7. DHDR, Delta-PNG chunks, IEND ........................ 1
  120.           4.2.8. PAST Paste an image into another .................... 1
  121.           4.2.9. DISC Discard objects ................................ 1
  122.       4.3. Critical MNG image displaying chunks ...................... 1
  123.           4.3.1. BACK Background ..................................... 1
  124.           4.3.2. FRAM Frame definitions .............................. 1
  125.           4.3.3. MOVE New image location ............................. 1
  126.           4.3.4. CLIP Object clipping boundaries ..................... 1
  127.           4.3.5. SHOW Show images .................................... 1
  128.           4.3.6. TERM Termination action ............................. 1
  129.       4.4. SAVE and SEEK chunks ...................................... 1
  130.           4.4.1. SAVE Save information ............................... 1
  131.           4.4.2. SEEK Seek point ..................................... 1
  132.       4.5. Ancillary MNG chunks ...................................... 1
  133.           4.5.1. eXPI Export image ................................... 1
  134.           4.5.2. fPRI Frame priority ................................. 1
  135.           4.5.3. nEED Resources needed ............................... 1
  136.           4.5.4. pHYs Physical pixel size ............................ 1
  137.           4.5.5. PNG ancillary chunks ................................ 1
  138.    5. The JPEG Network Graphics (JNG) Format ......................... 1
  139.       5.1. JNG critical chunks ....................................... 1
  140.           5.1.1. JHDR JNG header ..................................... 1
  141.           5.1.2. JDAT JNG image data ................................. 1
  142.           5.1.3. IDAT JNG alpha data ................................. 1
  143.           5.1.4. JSEP 8-bit/12-bit image separator ................... 1
  144.       5.2. JNG ancillary chunks ...................................... 1
  145.    6. The Delta-PNG Format ........................................... 1
  146.       6.1. Delta-PNG critical chunks ................................. 1
  147.           6.1.1. DHDR Delta-PNG datastream header .................... 1
  148.           6.1.2. IEND End of Delta-PNG datastream .................... 1
  149.           6.1.3. PROM Promotion of parent object ..................... 1
  150.           6.1.4. IHDR PNG image header ............................... 1
  151.           6.1.5. IPNG Incomplete PNG ................................. 1
  152.           6.1.6. PLTE and tRNS ....................................... 1
  153.           6.1.7. PPLT Partial palette ................................ 1
  154.           6.1.8. JHDR JNG image header ............................... 1
  155.           6.1.9. IJNG Incomplete JNG ................................. 1
  156.           6.1.10. DROP Drop chunks ................................... 1
  157.           6.1.11. DBYK Drop chunks by keyword ........................ 1
  158.           6.1.12. ORDR Ordering restrictions ......................... 1
  159.           6.1.13. Delta-PNG ancillary chunks ......................... 1
  160.           6.1.14. gAMA, cHRM, iCCP, sRGB Color space chunks .......... 1
  161.           6.1.15. oFFs and pHYs ...................................... 1
  162.       6.2. Chunk ordering requirements ............................... 1
  163.    7. Chunk Copying Rules ............................................ 1
  164.    8. Minimum Requirements for MNG-Compliant Viewers ................. 1
  165.       8.1. Required PNG chunk support ................................ 1
  166.       8.2. Required JNG chunk support ................................ 1
  167.       8.3. Required MNG chunk support ................................ 1
  168.       8.4. Required Delta-PNG chunk support .......................... 1
  169.    9. Recommendations for Encoders ................................... 1
  170.       9.1. Use a common color space .................................. 1
  171.       9.2. Use the right framing mode ................................ 1
  172.       9.3. Embedded images in LOOPs .................................. 1
  173.       9.4. Including optional index in SAVE chunk .................... 1
  174.       9.5. Interleaving JDAT and IDAT chunks ......................... 1
  175.    10. Recommendations for Decoders .................................. 1
  176.       10.1. ENDL without matching LOOP ............................... 1
  177.       10.2. Note on compositing ...................................... 1
  178.       10.3. Retaining object data .................................... 1
  179.       10.4. Decoder handling of fatal errors ......................... 1
  180.       10.5. Decoder handling of interlaced images .................... 1
  181.       10.6. Decoder handling of palettes ............................. 1
  182.       10.7. Behavior of single-frame viewers ......................... 1
  183.       10.8. Clipping ................................................. 1
  184.    11. Recommendations for Editors ................................... 1
  185.       11.1. Editing datastreams with optional index .................. 1
  186.    12. Miscellaneous Topics .......................................... 1
  187.       12.1. File name extension ...................................... 1
  188.       12.2. Internet media type ...................................... 1
  189.       12.3. Uniform Resource Identifier (URI) ........................ 1
  190.    13. References .................................................... 1
  191.    14. Security Considerations ....................................... 1
  192.    15. Appendix: Examples ............................................ 1
  193.       15.1. Example 1: A single image ................................ 1
  194.       15.2. Example 2: Very simple movie ............................. 1
  195.       15.3. Example 3: Simple slideshow .............................. 1
  196.       15.4. Example 4: A more storage-efficient slideshow ............ 1
  197.       15.5. Example 5: Simple movie .................................. 1
  198.       15.6. Example 6: Single composite frame ........................ 1
  199.       15.7. Example 7: Movie with sprites ............................ 1
  200.       15.8. Example 8: Movie with an animated sprite ................. 1
  201.       15.9. Example 9: "Fading in" a transparent image ............... 1
  202.       15.10. Example 10: Storing three-dimensional images ............ 1
  203.       15.11. Example 11: Tiling ...................................... 1
  204.       15.12. Example 12: Scrolling ................................... 1
  205.       15.13. Example 13: Converting a GIF animation to MNG ........... 1
  206.    16. Credits ....................................................... 1
  207.  
  208. 1. Introduction
  209.  
  210.    This specification defines the format of the MNG (Multiple-image
  211.    Network Graphics) and JNG (JPEG Network Graphics) datastreams.
  212.  
  213.    Note: This specification depends on the PNG (Portable Network
  214.    Graphics) [PNG].  and the JPEG (Joint Photographic Experts Group)
  215.    specifications.  The PNG specification is available at the PNG home
  216.    page,
  217.  
  218.       http://www.cdrom.com/pub/png/
  219.  
  220.    A MNG datastream describes a sequence of single frames, each of which
  221.    can be composed of zero or more embedded images or directives to show
  222.    previously defined images.
  223.  
  224.    A typical MNG datastream consists of:
  225.  
  226.        * The 8-byte MNG signature.
  227.  
  228.        * The MHDR chunk.
  229.  
  230.        * Frame definitions.  A frame is one or more subframes, the last
  231.          of which has a nonzero interframe delay.
  232.  
  233.        * Subframe definitions.  A subframe contains one or more layers,
  234.          together with clipping information and an interframe delay.
  235.  
  236.        * Layer definitions.  A layer is:
  237.  
  238.              * An embedded image.
  239.  
  240.              * An image that is generated in response to a SHOW
  241.                directive.
  242.  
  243.              * An instance of the background image.
  244.  
  245.              * A rectangle filled with the background color.
  246.  
  247.              * Sometimes, an empty rectangle.
  248.  
  249.        * LOOP-ENDL chunks.
  250.  
  251.        * SEEK chunks that mark points in the datastream where processing
  252.          can be restarted.
  253.  
  254.        * Various chunks for creating and manipulating images and other
  255.          objects.
  256.  
  257.        * The MEND chunk.
  258.  
  259.    Images can be "concrete" or "abstract".  The distinction allows
  260.    decoders to use more efficient ways of manipulating images when it is
  261.    not necessary to retain the image data in its original form or
  262.    equivalent in order to show it properly on the target display system.
  263.  
  264.    MNG is pronounced "Ming."
  265.  
  266.    When a MNG datastream is stored in a file, it is recommended that
  267.    ".mng" be used as the file suffix.  In network applications, the
  268.    Media Type "video/x-mng" can be used.  Registration of the media type
  269.    "video/mng" might be pursued at some future date.
  270.  
  271.    The first eight bytes of a MNG datastream are
  272.  
  273.       138 77 78 71 13 10 26 10
  274.  
  275.    (decimal) which is similar to the PNG signature with "\212 M N G"
  276.    instead of "\211 P N G" in bytes 0-3.
  277.  
  278.    MNG does not yet accommodate sound or complex sequencing information,
  279.    but these capabilities might be added at a later date, in a
  280.    backward-compatible manner.  These issues are being discussed in the
  281.    mpng-list@ccrc.wustl.edu mailing list.
  282.  
  283.    Chunk structure (length, name, data, CRC) and the chunk-naming system
  284.    are identical to those defined in the PNG specification.  As in PNG,
  285.    all integers that require more than one byte must be in network byte
  286.    order.
  287.  
  288.    The chunk copying rules for MNG employ the same mechanism as PNG, but
  289.    with rules that are explained more fully (see below, Chapter 7).  A
  290.    MNG editor is not permitted to move unknown chunks across the SAVE
  291.    and SEEK chunks, across any chunks that can cause images to be
  292.    displayed, or into or out of a IHDR-IEND or similar sequence.
  293.  
  294.    Note that decoders are not required to follow any decoding models
  295.    described in this specification nor to follow the instructions in
  296.    this specification, as long as they produce results identical to
  297.    those that could be produced by a decoder that did use this model and
  298.    did follow the instructions.
  299.  
  300.    Each chunk of the MNG datastream or of any embedded object is an
  301.    independent entity, i.e., no chunk is ever enclosed in the data
  302.    segment of another chunk.
  303.  
  304.    An independent PNG or JNG datastream, with a PNG or JNG signature, is
  305.    also a valid MNG datastream that must be recognized and decoded by
  306.    MNG-compliant decoders.  This kind of MNG datastream will contain
  307.    only a single embedded image.
  308.  
  309.    Because the embedded objects making up a MNG are normally in PNG
  310.    format, MNG shares the good features of PNG:
  311.  
  312.        * It is unencumbered by patents.
  313.  
  314.        * It is streamable.
  315.  
  316.        * It has excellent, lossless compression.
  317.  
  318.        * It stores up to four channels (red, green, blue, alpha), with
  319.          up to 16 bits per channel.
  320.  
  321.        * It provides transparency and an alpha channel.
  322.  
  323.        * It provides platform-independent rendition of colors by
  324.          inclusion of gamma and chromaticity information.
  325.  
  326.        * It provides early detection of common file transmission errors
  327.          and robust detection of file corruption.
  328.  
  329.        * Single-image GIF files can be losslessly converted to PNG.
  330.  
  331.        * It is complementary to JPEG and does not attempt to replace
  332.          JPEG for lossy storage of images (however, MNG can accommodate
  333.          JPEG-encoded images that are wrapped in the PNG-like JNG format
  334.          that is defined herein).
  335.  
  336.    In addition:
  337.  
  338.        * It provides animation with variable interframe delays.
  339.  
  340.        * It allows composition of frames containing multiple images.
  341.  
  342.        * It facilitates the use of images as "sprites" or groups of
  343.          images as "animated sprites" that can be reused in subsequent
  344.          frames.
  345.  
  346.        * It capitalizes on frame-to-frame similarities to reduce the
  347.          amount of data that must be included in a datastream.
  348.  
  349.        * It provides "restart" points at which an animation can be
  350.          safely resumed in case of data loss or corruption, or to which
  351.          applications can jump if they have random access to the file.
  352.  
  353.        * A "frame priority" chunk allows authors to indicate which frame
  354.          should be displayed by single-image viewers, and a subset of
  355.          the frames that should be displayed by slow viewers.
  356.  
  357.        * Images and frames can be given names, allowing authors to mark
  358.          them for export outside the scope of MNG, where they can be
  359.          used for icons or similar purposes.
  360.  
  361.        * A series of PNG and JNG images can be losslessly converted to
  362.          MNG and back to a series of equivalent PNG or JNG images, even
  363.          when the delta format is used to store them in the MNG.
  364.  
  365.        * JNG provides JPEG with transparency, alpha, and color space
  366.          information.
  367.  
  368.        * Multiple-image GIF files can be losslessly converted to MNG.
  369.  
  370.        * Most JPEG files can be losslessly converted to JNG or MNG, and
  371.          all JNG datastreams can be losslessly converted to JPEG files.
  372.  
  373.        * It is complementary to MPEG and does not attempt to replace
  374.          MPEG for lossy storage of video (MNG does, however, provide the
  375.          capability of including animations consisting of JPEG-encoded
  376.          images that have been wrapped in the PNG format).
  377.  
  378. 2. Terminology
  379.  
  380.    See also the glossary in the PNG specification.
  381.  
  382.    requirement levels
  383.       The words "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT",
  384.       "RECOMMENDED", and "OPTIONAL" in this document are to be
  385.       interpreted as described in RFC-2119, and the word "CAN" is
  386.       equivalent to the word "MAY" as described therein.  "NOT ALLOWED"
  387.       and "NOT PERMITTED" describe conditions that "MUST NOT" occur.
  388.       "ALLOWED" and "PERMITTED" describe conditions that "CAN" occur.
  389.  
  390.    abstract image or object
  391.       An image whose pixels have a hidden representation, and which does
  392.       not necessarily carry PNG or JNG chunk data.  An image delta
  393.       cannot be applied to an abstract image.  All abstract objects are
  394.       viewable.
  395.  
  396.    child, or child image
  397.       An image produced by applying an image delta to a parent object.
  398.  
  399.    color encoding
  400.       File gamma and chromaticity values, or an sRGB rendering intent,
  401.       iCCP profile, or whatever is involved in mapping between RGB
  402.       values and colors.
  403.  
  404.    concrete image or object
  405.       An image or object whose pixels have a publicly known
  406.       representation, and which uses a publicly known color encoding.  A
  407.       concrete PNG or JNG image also carries data from other known PNG
  408.       or JNG chunks that are present.
  409.  
  410.    pixel sample depth and alpha sample depth
  411.       The sample depth used for decoding IDAT data in Delta-PNG
  412.       datastreams.  They are not necessarily the same as the sample
  413.       depth of the object, which is called "sample depth" or "object
  414.       sample depth" in this document.
  415.  
  416.    embedded object or image
  417.       A concrete object or image that appears in-line in a MNG
  418.       datastream.
  419.  
  420.    frame
  421.       A layout of a background and zero or more images, followed by a
  422.       specified nonzero delay time or by the MEND chunk, that is to be
  423.       displayed as a still frame or as part of an animation.  An
  424.       animation would ideally appear to a perfect observer (with an
  425.       inhumanly fast visual system) as a sequence of still frames.  A
  426.       group of MNG images whose interframe delay time is zero makes up a
  427.       "subframe" (see below) instead of a "frame".  The final subframe
  428.       in a segment completes a frame, regardless of its interframe
  429.       delay.
  430.  
  431.    frame area
  432.       The portion of the display surface whose pixels are inside the
  433.       subframe clipping boundaries as defined by the FRAM chunk (see the
  434.       FRAM chunk specification below, Paragraph 4.3.2).
  435.  
  436.    frame duration
  437.       The amount of time a frame should be visible when an animation is
  438.       played.  In reality, it takes a nonzero amount of time to display
  439.       a frame.  No matter which moment is picked as the "start" of the
  440.       frame, the frame duration measures the time to the "start" of the
  441.       next frame.
  442.  
  443.    frame origin
  444.       The upper left corner of the output device (frame buffer, screen,
  445.       window, page, etc.) where the pixels are to be displayed.  This is
  446.       the {0,0} position for the purpose of defining frame clipping
  447.       boundaries, image locations, and image clipping boundaries.  Note
  448.       that in a windowing system, the frame origin might be moved
  449.       offscreen, but MOVE and CLIP values would still be measured from
  450.       this offscreen origin.
  451.  
  452.    frozen object
  453.       An object whose object attributes set and whose object buffer are
  454.       not allowed to be discarded, replaced, or modified.
  455.  
  456.    image delta
  457.       An object that can be applied to a concrete image or object to
  458.       produce another concrete image.  For any two concrete images,
  459.       there exists an image delta that will produce one from the other.
  460.  
  461.    image N or object N
  462.       Shorthand for "the object with the object attribute set pointed to
  463.       by `object_id=N'".
  464.  
  465.    layer
  466.       A visible embedded image or a stored image that is displayed in
  467.       response to a SHOW chunk directive, located with respect to the
  468.       frame boundaries and clipped with respect to the subframe clipping
  469.       boundaries and the image's own clipping boundaries, or the
  470.       background image, clipped, located, and displayed against the
  471.       background color at the beginning of a subframe.  Note that a
  472.       layer can be completely empty if the image is entirely outside the
  473.       clipping boundaries.  A layer can be thought of as a transparent
  474.       rectangle with the same dimensions as the frame, with an image
  475.       composited into it, or it can be thought of as a rectangle having
  476.       the same dimensions (possibly zero) and location as those of the
  477.       object after it has been located and clipped.
  478.  
  479.       An embedded visible PNG or JNG datastream generates a single
  480.       layer, even though it might be interlaced or progressive.  If the
  481.       background consists of both a background color and a background
  482.       image, these are combined into a single layer.
  483.  
  484.    object, object_id
  485.       An image or a nonviewable basis object.  The object_id is an
  486.       unsigned sixteen-bit number that serves as the identifier of a set
  487.       of object attributes.
  488.  
  489.    object attributes
  490.       Properties of an object such as its existence, potential
  491.       visibility, location, clipping boundaries, and a pointer to an
  492.       object buffer.  See Object attributes below.
  493.  
  494.    object buffer
  495.       A 2D array of pixels or pixel deltas, each of which has color and
  496.       transparency information.  More than one object can point to a
  497.       given object buffer.  See Object buffers below.
  498.  
  499.    parent, parent object, or parent image
  500.       An object to which a delta is applied.
  501.  
  502.    potentially visible image
  503.       A potentially visible image is
  504.  
  505.           * a not-yet-defined viewable object that is "marked" for on-
  506.             the-fly display while the embedded image that defines it is
  507.             being decoded, by setting its do_not_show flag to zero.
  508.  
  509.           * an existing viewable object that is potentially visible
  510.             (i.e., it is marked for being made visible by subsequent
  511.             SHOW chunks), by setting its do_not_show flag to zero.
  512.  
  513.    prologue segment
  514.       The first segment, when there is more than one segment.
  515.  
  516.    regular segment
  517.       Any segment other than the first (also the first segment, when
  518.       there is only one).
  519.  
  520.    segment
  521.       A part of a MNG datastream starting with the MHDR chunk or with a
  522.       SEEK chunk and extending to just before the next SEEK chunk (or
  523.       the MEND chunk if there is no next SEEK chunk).  The MHDR, MEND,
  524.       SAVE, SEEK, and TERM chunks are not considered to be a part of any
  525.       segment.
  526.  
  527.    signal
  528.       An entity with a number that can arrive asynchronously at the
  529.       decoder.  More detailed semantics, like whether multiple signals
  530.       of the same number (or even different numbers) can be queued, are
  531.       beyond the scope of this specification.
  532.  
  533.    subframe
  534.       A group of one or more layers, with nonzero delay time between
  535.       them and following them, that are to be displayed as a part of a
  536.       still frame or as part of an animation.  Subframes are defined in
  537.       MNG for convenience in applying frame parameters only to a subset
  538.       of the layers making up a complete frame.
  539.  
  540.    viewable image
  541.       A stored object that is capable of being made visible.  An image
  542.       is viewable, while some objects resulting from decoding a BASI
  543.       datastream are not viewable.
  544.  
  545.    visible image
  546.       Actually drawn on a display.  If an object is visible, a person
  547.       looking at the display can see it.
  548.  
  549. 3. Objects
  550.  
  551.    An "object", which is identified by an object_id, is an image or it
  552.    is a nonviewable entity that is created by the BASI chunk.  The
  553.    object_id is an unsigned sixteen-bit number that serves as the
  554.    identifier of a set of object attributes.
  555.  
  556.    An "image" is a viewable object.
  557.  
  558.    3.1. Embedded objects
  559.  
  560.       An embedded object is:
  561.  
  562.           * A PNG datastream (IHDR, PNG chunks, IEND).
  563.  
  564.           * A JNG datastream (JHDR, JNG chunks, IEND).
  565.  
  566.           * A BASI datastream (BASI, PNG chunks, IEND).
  567.  
  568.    3.2. Object attributes
  569.  
  570.       Objects have object attributes that can be defined and modified by
  571.       the contents of various MNG chunks.  Decoders are responsible for
  572.       keeping track of them.  The simplest decoder might establish a
  573.       65,536-element array for each attribute, but real applications
  574.       will undoubtedly use a more memory-efficient method.  Object
  575.       attributes include:
  576.  
  577.       Object exists.
  578.          An object comes into existence when
  579.  
  580.              * an embedded object appears in the MNG datastream.
  581.  
  582.              * a CLON chunk creates it.
  583.  
  584.       Object does not exist.
  585.          An object ceases to exist when it does not have the "frozen"
  586.          attribute and
  587.  
  588.              * it is the subject of a DISC chunk.
  589.  
  590.              * an empty DISC chunk appears.
  591.  
  592.              * a SEEK chunk appears.
  593.  
  594.              * the MEND chunk appears (or the IEND chunk appears in a
  595.                simple PNG or JNG file).
  596.  
  597.              * a DEFI chunk with the same object_id appears.
  598.  
  599.              * a new embedded object with the same object_id replaces it
  600.                without an intervening DEFI chunk (in this case, the new
  601.                object inherits the object attribute set from the
  602.                previous object with the same nonzero object_id; when
  603.                object_id = 0, it receives the default DEFI attribute
  604.                set).
  605.  
  606.              * it has object_id = 0 and its IEND chunk appears (in this
  607.                case, the object attribute set can be immediately
  608.                discarded).
  609.  
  610.       Pointer to an object buffer.
  611.          Every object (except for object 0) has an object buffer.
  612.          Multiple objects can point to the same object buffer.  The
  613.          representation of a pointer is decided by the application;
  614.          pointers never appear explicitly in a MNG datastream.  Decoders
  615.          can also create an object buffer for object 0, if that is more
  616.          convenient, but the information in that buffer cannot be
  617.          depended upon to exist after the image has been displayed, nor
  618.          can that buffer become "frozen".
  619.  
  620.       Frozen or not frozen.
  621.          All objects are initially "not frozen".  Any objects in
  622.          existence (except for object 0) when the SAVE chunk is
  623.          encountered become "frozen", along with the object buffers that
  624.          they point to.
  625.  
  626.       Potential visibility.
  627.          The "potential visibility" of an object is determined by the
  628.          do_not_show byte of the DEFI or CLON chunk that introduced it.
  629.          The "potential visibility" of viewable objects can be changed
  630.          by the SHOW chunk.  When an embedded object is "potentially
  631.          visible," it can be displayed "on-the-fly" as it is being
  632.          decoded.  Later, the SHOW chunk can direct that a "potentially
  633.          visible" object be displayed.
  634.  
  635.       Location.
  636.          The X and Y location of an object is determined by the DEFI
  637.          chunk that introduced it, and can be changed by the MOVE chunk.
  638.  
  639.       Clipping boundaries.
  640.          The clipping boundaries of an object are determined by the DEFI
  641.          chunk that introduced it, and can be changed by means of the
  642.          CLIP chunk.
  643.  
  644.    3.3. Object buffers
  645.  
  646.       An object buffer is created by the appearance of an embedded
  647.       object in the datastream, with a nonzero object_id, or by the
  648.       appearance of a CLON chunk that specifies a "full clone".  The
  649.       contents of an object buffer can be modified by processing an
  650.       image delta or a PAST chunk.
  651.  
  652.       Object buffers contain a 2D array of pixel data and can contain
  653.       additional information.  In addition, decoders are responsible for
  654.       keeping track of some properties of the data in the object buffer:
  655.  
  656.       Object is viewable.
  657.          Any object that points to a viewable object buffer can be made
  658.          potentially visible, but one that points to a nonviewable one
  659.          cannot.  Any attempt to do so must be ignored.
  660.  
  661.              * A PNG or JNG datastream always has the "viewable"
  662.                attribute.
  663.  
  664.              * The "viewable" attribute of a BASI datastream is defined
  665.                in the BASI chunk.  Only BASI datastreams that produce
  666.                legal PNG files can be declared "viewable".
  667.  
  668.              * When a Delta-PNG is applied to a parent object, the
  669.                resulting object buffer always has the "viewable"
  670.                attribute.
  671.  
  672.       Format of data in the object buffer.
  673.          The data format can be:
  674.  
  675.              * A concrete PNG or JNG object.  A concrete object must be
  676.                stored by the decoder in a form that retains the complete
  677.                object description, sufficient to regenerate the original
  678.                object description or its equivalent without loss.  Its
  679.                pixels have a publicly known representation, and it uses
  680.                a publicly known color encoding.
  681.  
  682.                    * In the case of a PNG image, the object also carries
  683.                      data from other known PNG chunks that are present.
  684.                      This means that the decoder must store sufficient
  685.                      information to make it possible to restore exactly
  686.                      the original decoded and unfiltered pixel samples
  687.                      as they existed prior to any gamma correction (but
  688.                      not the original compressed datastream or line-by-
  689.                      line filter selections and "zlib" compression
  690.                      flags), and data from the IHDR and PLTE chunks and
  691.                      any additional recognized PNG chunks such as gAMA,
  692.                      cHRM, and tRNS that the application plans to use.
  693.                      The sample depth, color type, filter method,
  694.                      compression method, and interlacing method of the
  695.                      image must be retained, and if the object has been
  696.                      modified by a Delta-PNG, the "pixel sample depth"
  697.                      and "alpha sample depth" must also be retained for
  698.                      use in decoding subsequent Delta-PNG datastreams.
  699.  
  700.                    * In the case of a JNG image, the object also carries
  701.                      data from other known JNG chunks that are present.
  702.                      This means that the decoder must store sufficient
  703.                      information to make it possible to restore exactly
  704.                      the original JPEG datastream and decoded alpha
  705.                      channel as they existed in the original JNG file,
  706.                      and data from the JHDR chunk and any additional
  707.                      recognized JNG chunks such as gAMA and cHRM that
  708.                      the application plans to use.  As with PNG objects,
  709.                      when the object has been modified by a Delta-PNG,
  710.                      the "alpha sample depth" must also be retained for
  711.                      use in decoding subsequent Delta-PNG datastreams.
  712.  
  713.                    * A decoder that recreates PNG or JNG files from a
  714.                      series of PNG, JNG, and Delta-PNG datastreams will
  715.                      also have to store the contents of any unknown
  716.                      chunks that it finds, in case they turn out to be
  717.                      safe to copy (see DROP (Paragraph 6.1.10), DBYK
  718.                      (Paragraph 6.1.11), and ORDR (Paragraph 6.1.12),
  719.                      below).
  720.  
  721.              * An abstract image.  An abstract image can be stored by
  722.                the decoder in any form that is convenient, such as an X
  723.                Window System "pixmap", even though that form might not
  724.                have sufficient resolution for exact, lossless
  725.                conversion.  In the case of a PNG image, the pixels could
  726.                be stored after the gamma and chromaticity corrections
  727.                have been made, and the sample depth could be the same as
  728.                the display hardware, even though it is smaller than the
  729.                original sample depth.  Similarly, a JNG image could be
  730.                stored in the same form, after the pixels have been
  731.                decoded, converted to RGB form, and gamma-corrected.  It
  732.                is always safe, however, to store an abstract image as
  733.                though it were concrete, if decoders do not wish to take
  734.                advantage of the distinction between abstract and
  735.                concrete objects.
  736.  
  737.       Frozen or not frozen.
  738.          All object buffers are initially "not frozen".  Any object
  739.          buffers in existence when the SAVE chunk is encountered become
  740.          "frozen".  Decoders do not actually have to store this flag
  741.          except as a sanity check, because they can depend on the fact
  742.          that a "frozen" object buffer will always have at least one
  743.          "frozen" object whose "buffer pointer" points to it.
  744.  
  745.       A reference count.
  746.          When an object buffer is first created, its reference count is
  747.          set to 1.
  748.  
  749.          When a partial clone is made of an object via the CLON chunk,
  750.          the reference count for the object buffer is incremented, and
  751.          no new object buffer is created.
  752.  
  753.          When an object is discarded, the reference count of the object
  754.          buffer that it points to is decremented, and the object buffer
  755.          is also discarded if the resulting reference count is zero.
  756.  
  757. 4. MNG Chunks
  758.  
  759.    This chapter describes chunks that can appear at the top level of a
  760.    MNG datastream.  Unless otherwise specified in the Delta-PNG chapter
  761.    of this specification, they need not be recognized there.
  762.  
  763.    4.1. Critical MNG control chunks
  764.  
  765.       This section describes critical MNG control chunks.  MNG-compliant
  766.       decoders must recognize and process them.
  767.  
  768.       4.1.1. MHDR MNG datastream header
  769.  
  770.          The MHDR chunk is always first in all MNG datastreams except
  771.          for those that consist of a PNG datastream with a PNG
  772.          signature.
  773.  
  774.          The MHDR chunk contains exactly 28 bytes:
  775.  
  776.             Frame width:  4 bytes (unsigned integer).
  777.             Frame height: 4 bytes (unsigned integer).
  778.             Ticks per
  779.              second:      4 bytes (unsigned integer).
  780.             Nominal layer
  781.              count:       4 bytes (unsigned integer).
  782.             Nominal frame
  783.              count:       4 bytes (unsigned integer).
  784.             Nominal play
  785.              time:        4 bytes (unsigned integer).
  786.             Simplicity
  787.              profile:     4 bytes:(unsigned integer).
  788.                             bit 0:
  789.                                    0: Presence or absence of any
  790.                                       features is unspecified.  All
  791.                                       other bits of the simplicity
  792.                                       profile must be zero (i.e, all
  793.                                       other even numbers are invalid).
  794.                                    1: Presence or absence of certain
  795.                                       features is specified by the
  796.                                       remaining bits of the simplicity
  797.                                       profile.
  798.                             bit 1:
  799.                                    0: complex MNG features are absent.
  800.                                    1: complex MNG features are present.
  801.                             bit 2:
  802.                                    0: transparency is absent or can be
  803.                                       ignored.
  804.                                    1: transparency is present and is
  805.                                       essential (critical) for proper
  806.                                       display of the images.
  807.                             bit 3:
  808.                                    0: JNG is absent.
  809.                                    1: JNG is present.
  810.                             bit 4:
  811.                                    0: Delta-PNG is absent.
  812.                                    1: Delta-PNG is present.
  813.                             bits 5-15:
  814.                                    Reserved for public expansion.  Must
  815.                                    be zero in this version.
  816.                             bits 16-30:
  817.                                    Available for private or experimental
  818.                                    expansion.  Undefined in this version
  819.                                    and can be ignored.
  820.                             bit 31:
  821.                                    Must be zero.
  822.  
  823.          Decoders can ignore the "informative" frame-count, layer-count,
  824.          play-time, and simplicity-profile fields.
  825.  
  826.          The frame_width and frame_height fields give the intended
  827.          display size (measured in pixels) and provide default clipping
  828.          boundaries (see below, Paragraph 4.3.4).  It is strongly
  829.          recommended that these be set to zero if the MNG datastream
  830.          contains no visible images.
  831.  
  832.          The ticks_per_second field gives the unit used by the FRAM
  833.          chunk to specify frame duration and sync timeout.  It must be
  834.          nonzero if the datastream contains an animation.  When the
  835.          datastream contains exactly one frame, this field should be set
  836.          to zero.  When this field is zero, the length of a tick is
  837.          infinite, and decoders will ignore any attempt to define
  838.          interframe delay, timeout, or any other variable that depends
  839.          on the length of a tick.  If the frames are intended to be
  840.          displayed one at a time under user control, such as a slide
  841.          show or a multi-page FAX, the tick length can be set to any
  842.          positive number and a FRAM chunk can be used to set an infinite
  843.          sync_timeout.  Unless the user intervenes, viewers will only
  844.          display the first frame in the datastream.
  845.  
  846.          When ticks_per_second is nonzero, and there is no other
  847.          information available about frame duration, viewers should
  848.          display animations at the rate of one frame per tick.
  849.  
  850.          If the frame-count field contains a zero, the frame count is
  851.          unspecified.  If it is nonzero, it contains the number of
  852.          frames that would be displayed, ignoring the fPRI and TERM
  853.          chunks.  If the frame count is greater than (2^31)-1, encoders
  854.          should write (2^31)-1, representing an infinite frame count.
  855.  
  856.          If the layer-count field contains a zero, the layer count is
  857.          unspecified.  If it is nonzero, it contains the number of
  858.          layers in the datastream, ignoring the fPRI and TERM chunks.
  859.          If the layer count is greater than (2^31)-1, encoders should
  860.          write (2^31)-1, representing an infinite layer count.
  861.  
  862.          If the nominal-play-time field contains a zero, the nominal
  863.          play time is unspecified.  Otherwise, it gives the play time,
  864.          in ticks, when the file is displayed ignoring the fPRI and TERM
  865.          chunks.  Authors who write this field should choose a value of
  866.          "ticks_per_second" that will allow the nominal play time to be
  867.          expressed in a four-bit integer.  If the nominal play time is
  868.          greater than (2^31)-1 ticks, encoders should write (2^31)-1,
  869.          representing an infinite nominal play time.
  870.  
  871.          When the simplicity profile is zero, the simplicity (or
  872.          complexity) of the MNG datastream is unspecified.
  873.  
  874.          If the simplicity profile is nonzero, it can be regarded as a
  875.          31-bit profile, with the ones bit being a "profile-validity"
  876.          flag, the twos bit being a "simple MNG" flag, the fours bit
  877.          being a "transparency" flag, the eights bit being a "JNG" flag,
  878.          and the sixteens bit being a "Delta-PNG" flag.  The upper 15
  879.          bits (except for the most significant bit, which must be zero)
  880.          are available for private test or experimental versions, and
  881.          the remaining bits are reserved for future MNG versions, and
  882.          must be zero in this version.  If a bit is zero, the
  883.          corresponding feature is guaranteed to be absent, and if a bit
  884.          is one, the corresponding feature may be present in the MNG
  885.          datastream.
  886.  
  887.          A "simple MNG" (simplicity profile = 1, 5, 9, or 13) does not
  888.          contain the BASI/IEND, CLON, DHDR/IEND, PAST, DISC, MOVE, CLIP,
  889.          and SHOW chunks.  If the DEFI chunk is present, it only defines
  890.          object 0.  If the BACK chunk is present, it does not define a
  891.          background image. If the LOOP chunk is present, it has
  892.          iteration_min <= 1.  A MNG with a "complex MNG feature"
  893.          (simplicity profile = 3, 7, 11, 15, or other value that has bit
  894.          1 set to 1) may contain at least one of these chunks.  A simple
  895.          decoder can display "simple" MNGs without having to store any
  896.          objects or dealing with the SAVE/SEEK mechanism, and can
  897.          execute all loops exactly once.
  898.  
  899.          "Transparency is absent or can be ignored" means that the MNG
  900.          or PNG tRNS chunk is not present and no PNG or JNG image has an
  901.          alpha channel, or that if they are present they are not
  902.          essential (or critical) for displaying the images.
  903.  
  904.          Encoders that write a nonzero simplicity profile should
  905.          endeavor to be accurate, so that decoders that process it will
  906.          not unnecessarily reject datastreams.  For example, the
  907.          simplicity profile 15 indicates that JNG, critical
  908.          transparency, and at least one "complex" MNG feature are all
  909.          present, but Delta-PNG is not.  If the simplicity profile
  910.          promises that certain features are absent, but they are
  911.          actually present in the MNG datastream, the datastream is
  912.          invalid.
  913.  
  914.       4.1.2. MEND End of MNG datastream
  915.  
  916.          The MEND chunk's data length is zero.  It signifies the end of
  917.          a MNG datastream.
  918.  
  919.       4.1.3. LOOP, ENDL Define a loop
  920.  
  921.          The LOOP chunk provides a "shorthand" notation that can be used
  922.          to avoid having to repeat identical chunks in a MNG datastream.
  923.          Its contents are the first two or more of the following fields:
  924.  
  925.             Nest level:      1 byte (unsigned integer).
  926.             Repeat count:    4 bytes (unsigned integer),
  927.                                range [0..2^31-1].
  928.             Termination
  929.               condition:     1 byte (unsigned integer).
  930.                                Omit if termination_condition=0,
  931.                                which means Deterministic.
  932.                                1: Decoder discretion.
  933.                                2: User discretion.
  934.                                3: External signal.
  935.             Iteration min:   4 bytes(unsigned integer).  Can be
  936.                                omitted if termination_condition
  937.                                != 3.  If omitted, the default
  938.                                value is 1.
  939.             Iteration max:   4 bytes (unsigned integer).  Can be
  940.                                omitted if termination_condition
  941.                                != 3; must be omitted if
  942.                                iteration_min is omitted; if
  943.                                omitted, the default
  944.                                value is infinity.
  945.             Signal number:   4 bytes (unsigned integer).  Omit
  946.                                if termination_condition != 3.
  947.             Additional
  948.               signal number: 4 bytes.  Omit if
  949.                                termination_condition != 3.
  950.             ...etc...
  951.  
  952.          Decoders must treat the chunks enclosed in a loop exactly as if
  953.          they had been repeatedly spelled out.  Therefore, during the
  954.          first iteration of the loop, the parent objects for any Delta-
  955.          PNG datastreams in the loop are the images in existence prior
  956.          to entering the LOOP chunk, but in subsequent iterations these
  957.          parent objects might have been modified.  The
  958.          termination_condition field can be used to inform decoders that
  959.          it is safe to change the number of loop iterations.
  960.  
  961.          Simple decoders can ignore all fields except for the
  962.          repeat_count.
  963.  
  964.          When the LOOP chunk is present, an ENDL chunk with the same
  965.          nest_level must be present later in the MNG datastream.  Loops
  966.          can be nested.  Each inner loop must have a higher value of
  967.          nest_level than the loop that encloses it, though not
  968.          necessarily exactly one greater.
  969.  
  970.          The termination condition specifies how the actual number of
  971.          iterations is determined.  It is very similar to the
  972.          termination condition field of the FRAM chunk, and can take the
  973.          same values:
  974.  
  975.          Deterministic
  976.             This is the default behavior, when the termination condition
  977.             field is omitted.  The loop terminates after exactly the
  978.             number of iterations specified by the iteration count.  This
  979.             value must be used if altering the number of repetitions
  980.             would mess up the MNG datastream, but can be used merely to
  981.             preserve the author's intent.
  982.  
  983.          Decoder-discretion
  984.             The number of iterations can be chosen by the decoder, and
  985.             must not be less than iteration_min nor more than
  986.             iteration_max.  If the decoder has no reason to choose its
  987.             own value, it should use the iteration count.  One example
  988.             of a decoder wishing to choose its own value is a real-time
  989.             streaming decoder hovering at a loop while waiting for its
  990.             input buffer to fill to a comfortable level.
  991.  
  992.          User-discretion
  993.             The number of iterations should be chosen by the user (e.g.,
  994.             by pressing the <escape> key), but the decoder must enforce
  995.             the iteration_min and iteration_max limits.  Some decoders
  996.             might not be able to interact with the user, and many
  997.             decoders will find that nested user-discretion loops present
  998.             too great of a user-interface challenge, so the <user-
  999.             discretion> condition will probably usually degenerate into
  1000.             the <decoder-discretion> condition.
  1001.  
  1002.          External-signal
  1003.             The number of iterations must not be less than iteration_min
  1004.             nor more than iteration_max.  The exact number can be
  1005.             determined by the arrival of a signal whose number matches
  1006.             one of the signal_number fields.
  1007.  
  1008.          The iteration_min and iteration_max can be omitted.  If the
  1009.          condition is <deterministic> the values are not used.
  1010.          Otherwise, defaults of 1 and <infinity> are used.  The
  1011.          repeat_count, iteration_min, and iteration_max can be any non-
  1012.          negative integers or <infinity>, but they must satisfy
  1013.          iteration_min <= repeat_count <= iteration_max.  Infinity is
  1014.          represented by 0x7fffffff.  If all of the loops in a MNG
  1015.          datastream have iteration_min=1, the datastream can qualify as
  1016.          a "simple" MNG for the purpose of setting bit 1 of the
  1017.          "simplicity profile" to zero, unless there are other reasons
  1018.          for setting it to one.
  1019.  
  1020.          If repeat_count is zero, the loop is done zero times.  Upon
  1021.          encountering a LOOP chunk with repeat_count=0, decoders simply
  1022.          skip chunks until the matching ENDL chunk is found, and resume
  1023.          processing with the chunk immediately following it.
  1024.  
  1025.          The signal_number can be omitted only if the termination
  1026.          condition is not <external-signal>.  There can be any number of
  1027.          signal_number fields.  Signal_number = 0 is reserved to
  1028.          represent any input from a keyboard or pointing device, and
  1029.          1-255 are reserved to represent the corresponding ASCII
  1030.          character, received from a keyboard or simulated keyboard, and
  1031.          values 256-1023 are reserved for future definition by this
  1032.          specification.
  1033.  
  1034.          The ENDL chunk ends a loop that begins with the LOOP chunk.  It
  1035.          contains a single one-byte field:
  1036.  
  1037.             Nest_level: 1 byte (unsigned integer),
  1038.                           range [0..255].
  1039.  
  1040.          When the ENDL chunk is encountered, the loop repeat_count is
  1041.          decremented, if it is not already zero.  If the result is
  1042.          nonzero, processing resumes at the beginning of the loop.
  1043.          Otherwise processing resumes with the chunk immediately
  1044.          following the ENDL chunk.
  1045.  
  1046.          When the ENDL chunk is present, a LOOP chunk with the same
  1047.          nest_level must be present earlier in the MNG datastream.  See
  1048.          below.
  1049.  
  1050.          The SAVE and SEEK chunks are not permitted inside a LOOP-ENDL
  1051.          pair.  To rerun an entire datastream that includes these
  1052.          chunks, use the TERM chunk instead.  See below (Paragraph
  1053.          4.3.6).
  1054.  
  1055.    4.2. Critical MNG image defining chunks
  1056.  
  1057.       4.2.1. DEFI Define an object
  1058.  
  1059.          The DEFI chunk sets the default object attribute set
  1060.          (object_id, potential_visibility, concrete_flag, location, and
  1061.          clipping boundaries) for any subsequent images that are defined
  1062.          with IHDR-IEND, JHDR-IEND, or BASI-IEND datastreams.  The DEFI
  1063.          chunk contains 2, 3, 4, 12, or 28 bytes:
  1064.  
  1065.             Object id:     2 bytes (unsigned integer) identifier
  1066.                              to be given to the objects that
  1067.                              follow the DEFI chunk.
  1068.  
  1069.             Do_not_show
  1070.              flag:         1 byte (unsigned integer)
  1071.                              0:  Make the objects potentially
  1072.                                  visible.
  1073.                              1:  Do not make the objects potentially
  1074.                                  visible.  This field can be omitted
  1075.                                  if the concrete_flag, location, and
  1076.                                  clipping boundary fields are also
  1077.                                  omitted.  When it is omitted, the
  1078.                                  image is potentially visible
  1079.                                  (do_not_show=0).
  1080.  
  1081.             Concrete flag: 1 byte (unsigned integer)
  1082.                              0:  Make the objects "abstract" (image
  1083.                                  can not be the source for a
  1084.                                  Delta-PNG)
  1085.                              1:  Make the objects "concrete" (object
  1086.                                  can be the source for a Delta-PNG).
  1087.                              This field can be omitted if the
  1088.                              location and clipping boundary fields
  1089.                              are also omitted.  When it is omitted,
  1090.                              the object is made "abstract"
  1091.                              (concrete_flag=0).
  1092.  
  1093.             X_location:    4 bytes (signed integer).
  1094.                              The X_location and Y_location fields can
  1095.                              be omitted if the clipping boundaries
  1096.                              are also omitted.  If so, decoders must
  1097.                              assume default values {X_location=0,
  1098.                              Y_location=0}.
  1099.  
  1100.             Y_location:    4 bytes (signed integer).
  1101.  
  1102.             Left_cb:       4 bytes (signed integer).  Left clipping
  1103.                              boundary.  The left_cb, right_cb,
  1104.                              top_cb, and bottom_cb fields can be
  1105.                              omitted as a group.  If so, decoders
  1106.                              must assume default values
  1107.                              {0, frame_width, 0, frame_height}.
  1108.  
  1109.             Right_cb:      4 bytes (signed integer).
  1110.  
  1111.             Top_cb:        4 bytes (signed integer).
  1112.  
  1113.             Bottom_cb:     4 bytes (signed integer).
  1114.  
  1115.          If the object number for an object is nonzero, subsequent
  1116.          chunks can use this number to identify it.
  1117.  
  1118.          When the object number for an object is zero, its object buffer
  1119.          can be discarded immediately after it has been processed, and
  1120.          it can be treated as an "abstract" image, regardless of the
  1121.          contents of the concrete_flag field.
  1122.  
  1123.          Negative values are permitted for the X and Y location and
  1124.          clipping boundaries.  The positive directions are downward and
  1125.          rightward from the frame origin.
  1126.  
  1127.          Multiple IHDR-IEND, JHDR-IEND, and BASI-IEND objects can follow
  1128.          a single DEFI chunk.  When object_id is nonzero, the DEFI chunk
  1129.          values remain in effect until another DEFI chunk or a SEEK
  1130.          chunk appears, unless they are modified by SHOW, MOVE, or CLIP
  1131.          chunks.  When object_id=0, the DEFI chunk values are discarded
  1132.          after the object's IEND chunk is processed.  The object_id and
  1133.          concrete_flag can only be changed by using another DEFI chunk.
  1134.          If no DEFI chunk is in effect (either because there is none in
  1135.          the datastream, or because a SEEK chunk has caused it to be
  1136.          discarded), the decoder must use the following default values:
  1137.  
  1138.                          Object_id = 0
  1139.                        Do_not_show = 0
  1140.                      Concrete_flag = 0
  1141.                         X_location = 0
  1142.                         Y_location = 0
  1143.                            Left_cb = 0
  1144.                           Right_cb = frame_width
  1145.                             Top_cb = 0
  1146.                          Bottom_cb = frame_height
  1147.  
  1148.          If object_id is an identifier that already exists when a DEFI
  1149.          chunk appears, the object attribute set (except for the pointer
  1150.          to the object buffer) is immediately replaced, but the contents
  1151.          of the object buffer do not change until an IHDR, JHDR, or BASI
  1152.          chunk is encountered; then the contents of the object buffer
  1153.          previously associated with the identifier are replaced with the
  1154.          new embedded object data.  Note that if the object has partial
  1155.          clones, the clones will also be affected.
  1156.  
  1157.       4.2.2. PLTE Global palette
  1158.  
  1159.          The PLTE chunk has the same format as a PNG PLTE chunk.  It
  1160.          provides a global palette that is inherited by PNG datastreams
  1161.          that contain an empty PLTE chunk.
  1162.  
  1163.       4.2.3. IHDR, PNG chunks, IEND
  1164.  
  1165.          A PNG (Portable Network Graphics) datastream.
  1166.  
  1167.          See the PNG specification [PNG] and the PNG Special Purpose
  1168.          Chunks document [PNG-EXT] for the format of the PNG chunks.
  1169.  
  1170.          Any chunks between IHDR and IEND are written and decoded
  1171.          according to the PNG specification.
  1172.  
  1173.          If a global PLTE chunk appears in the top-level MNG datastream,
  1174.          the PNG datastream can have an empty PLTE chunk, to direct that
  1175.          the global PLTE data be used.  If an empty PLTE chunk is not
  1176.          present, the data is not inherited.  MNG applications that
  1177.          recreate PNG files must write the global PLTE chunk rather than
  1178.          the empty one in the output PNG file.  It is an error for the
  1179.          PNG datastream to contain an empty PLTE chunk when the global
  1180.          PLTE chunk is not present or has been nullified.
  1181.  
  1182.          If the PNG sRGB, gAMA, iCCP, or cHRM chunks appear in the top-
  1183.          level MNG datastream (and have not been nullified), but none of
  1184.          them appear in the PNG datastream, then the values are
  1185.          inherited from the top level as though the chunks had actually
  1186.          appeared in the PNG datastream.  Data from such chunks
  1187.          appearing in the PNG datastream take preference over the
  1188.          inherited values.  If any one of these chunks, or any future
  1189.          chunk that defines the color space, appears in the PNG
  1190.          datastream, none of them is inherited.  MNG applications that
  1191.          recreate PNG files must write these chunks, if they are
  1192.          inherited, in the output PNG files.  If the sRGB chunk is
  1193.          present, it need not be accompanied by gAMA and cHRM chunks, as
  1194.          recommended in the PNG specification.  Any viewer that
  1195.          processes the gAMA chunk must also recognize and process the
  1196.          sRGB chunk.  It can treat it as if it were a gAMA chunk
  1197.          containing the value .45455 and it can ignore its "intent"
  1198.          field.  If the sRGB chunk is present, editors that write PNG
  1199.          files should add the gAMA and cHRM chunks, even though they are
  1200.          not present in the MNG datastream.
  1201.  
  1202.          If the PNG sPLT chunk appears in the top-level MNG datastream,
  1203.          it takes preference over any sPLT chunk appearing in the PNG
  1204.          datastream.  MNG applications that recreate PNG files should
  1205.          not copy top-level sPLT chunks to the output PNG files, because
  1206.          a suggested palette for rendering a group of images is not
  1207.          necessarily the best palette for rendering a single image.
  1208.  
  1209.          When the framing mode is 2 or 4 in the MNG FRAM chunk, the PNG
  1210.          oFFs and pHYs chunks and any future chunks that attempt to set
  1211.          the pixel dimensions or the drawing location must be ignored by
  1212.          MNG viewers and simply copied (according to the copying rules)
  1213.          by MNG editors.  When the framing mode is 1 or 3 (i.e., when
  1214.          each PNG image is an individual frame), these chunks must be
  1215.          treated as described in the PNG specification.
  1216.  
  1217.          The PNG gIFg, gIFt, and gIFx chunks must be ignored by viewers
  1218.          and must be copied according to the copying rules by MNG
  1219.          editors.
  1220.  
  1221.          If do_not_show=0 for the image when the IHDR chunk is
  1222.          encountered, a viewer can choose to display the image while it
  1223.          is being decoded, perhaps taking advantage of the PNG
  1224.          interlacing method, or to display it after decoding is
  1225.          complete.
  1226.  
  1227.          If object_id=0, there is no need to store the pixel data after
  1228.          displaying it.
  1229.  
  1230.          If concrete_flag=1 and object_id != 0, the decoder must store
  1231.          the original pixel data losslessly, along with data from other
  1232.          recognized PNG chunks, because it is possible that a subsequent
  1233.          Delta-PNG datastream might want to modify it.  If
  1234.          concrete_flag=0, the decoder can store the pixel data in any
  1235.          form that it chooses.
  1236.  
  1237.          If an object already exists with the same object_id, the
  1238.          contents of its object buffer are replaced with the new data.
  1239.  
  1240.       4.2.4. JHDR, JNG chunks, IEND
  1241.  
  1242.          A JNG (JPEG Network Graphics) datastream.
  1243.  
  1244.          See the JNG specification below (Chapter 5) for the format of
  1245.          the JNG datastream.
  1246.  
  1247.          Any chunks between JHDR and IEND are written and decoded
  1248.          according to the JNG specification.
  1249.  
  1250.          The remaining discussion in the previous paragraph about PNG
  1251.          datastreams also applies to JNG datastreams.
  1252.  
  1253.       4.2.5. BASI, PNG chunks, IEND
  1254.  
  1255.          The BASI chunk introduces a basis object that, while it might
  1256.          be incomplete, can serve as a parent object to which a delta
  1257.          image can be applied.
  1258.  
  1259.          The first 13 bytes of the BASI chunk are identical to those of
  1260.          the IHDR chunk.  An optional 8 additional bytes provide
  1261.          sixteen-bit {red, green, blue, alpha} values that are used to
  1262.          fill the entire basis object when the IDAT chunk is not
  1263.          present, and a 1-byte "viewable" flag can be present.
  1264.  
  1265.             Width:              4 bytes (unsigned integer).
  1266.             Height:             4 bytes (unsigned integer).
  1267.             Sample_depth:       1 byte (unsigned integer).
  1268.             Color_type:         1 byte (unsigned integer).
  1269.             Compression_method: 1 byte (unsigned integer).
  1270.             Filter_type:        1 byte (unsigned integer).
  1271.             Interlace_type:     1 byte (unsigned integer).
  1272.             Red_sample or
  1273.               gray_sample:      2 bytes (unsigned integer).
  1274.             Green_sample:       2 bytes (unsigned integer).
  1275.             Blue_sample:        2 bytes (unsigned integer)
  1276.             Alpha_sample:       2 bytes (unsigned integer).
  1277.             Viewable:           1 byte (unsigned integer).
  1278.                                   0: Basis object is not viewable.
  1279.                                   1: Basis object is viewable.
  1280.  
  1281.          The alpha_sample can be omitted if the viewable field is also
  1282.          omitted.  If so, and the color_type is one that requires alpha,
  1283.          the alpha value corresponding to an opaque pixel will be used.
  1284.          If the color samples are omitted, zeroes will be used.  The
  1285.          decoder is responsible for converting the color and alpha
  1286.          samples to the appropriate format and sample depth for the
  1287.          specified color_type.  When color_type=3, the decoder must
  1288.          generate a palette of length 2^sample_depth, whose first entry
  1289.          contains the given {red_sample, green_sample, blue_sample}
  1290.          triple, and whose remaining entries are filled with zeroes.  If
  1291.          the viewable field is omitted, the object is not viewable.
  1292.  
  1293.          The color and alpha samples are written as four sixteen-bit
  1294.          samples regardless of the color_type and sample_depth.  When
  1295.          the sample_depth is less than sixteen, the least significant
  1296.          bits are used and the remaining bits must be zero filled.  When
  1297.          color_type=3, the least significant byte of each color sample
  1298.          is used and the upper byte must be zero.  When color_type=0 or
  1299.          color_type=4, the green and blue samples must be present but
  1300.          must be ignored by decoders.
  1301.  
  1302.          The BASI datastream contains PNG chunks, but is not necessarily
  1303.          a PNG datastream.  It can be incomplete or empty and it can
  1304.          deviate in certain ways from the PNG specification.  It can
  1305.          serve as a parent object for a Delta-PNG datastream, which must
  1306.          supply the missing data or correct the other deviations before
  1307.          the image is displayed.  The end of the datastream is denoted
  1308.          by an IEND chunk.
  1309.  
  1310.          The permitted deviations from the PNG format are:
  1311.  
  1312.              * Multiple instances of some chunks can be present even
  1313.                though the PNG specification allows only one.  The
  1314.                subsequent Delta-PNG that uses this as the parent object
  1315.                must select only one, through the DBYK or similar
  1316.                mechanism.
  1317.  
  1318.              * The IDAT chunk can be omitted or there can be a single
  1319.                empty IDAT chunk.  If so, all of the pixels are filled
  1320.                with the given color and alpha samples.  A subsequent
  1321.                Delta-PNG that uses this as the parent object can supply
  1322.                the IDAT chunk or chunks.
  1323.  
  1324.              * The PLTE chunk can be omitted or incomplete even when the
  1325.                color_type=3.  If so, the subsequent Delta-PNG that uses
  1326.                this as the parent object can supply a complete PLTE
  1327.                chunk, if the single-entry palette that is generated is
  1328.                not desired.
  1329.  
  1330.          The BASI chunk can be used to introduce such things as a
  1331.          library of faLT chunks from which one or another can be
  1332.          selected for use with any single image, or it can be used to
  1333.          introduce a simple blank or colored rectangle into which other
  1334.          images will be pasted by means of the PAST chunk.
  1335.  
  1336.          A BASI chunk appearing in a MNG datastream must be preceded by
  1337.          a DEFI chunk that gives the object_id, location, and potential
  1338.          visibility for the basis object.  The concrete_flag can be
  1339.          either 0 (abstract) or 1 (concrete), depending on whether the
  1340.          basis image is intended for subsequent use by a Delta-PNG
  1341.          datastream or not.  When it is abstract it must also be
  1342.          viewable.  When do_not_show=0 or viewable=1, the resulting
  1343.          image, after the pixel samples are filled in, must be a legal
  1344.          PNG image.  If do_not_show=0, a viewer is expected to display
  1345.          it immediately, as if it were decoding a PNG datastream.
  1346.  
  1347.          If an object already exists with the same object_id, the
  1348.          contents of its object buffer are replaced with the new data.
  1349.  
  1350.          Top-level gAMA, sRGB, cHRM, iCCP, and sPLT chunks are inherited
  1351.          by a BASI datastream in the same manner as by a PNG datastream.
  1352.  
  1353.          No provision is made in this specification for storing a BASI
  1354.          datastream as a standalone file.  A BASI datastream will
  1355.          normally be found as a component of a MNG datastream.
  1356.          Applications that need to store a BASI datastream separately
  1357.          should use a different file signature and filename extension,
  1358.          or they can wrap it in a MNG datastream consisting of the MNG
  1359.          signature, the MHDR chunk, the BASI datastream, and the MEND
  1360.          chunk.
  1361.  
  1362.       4.2.6. CLON Clone an object
  1363.  
  1364.          Create a clone (a new copy) of an image, with a new object_id.
  1365.          The CLON chunk contains 4, 5, 6, 7, or 16 bytes.
  1366.  
  1367.             Source_id:   2 bytes (nonzero unsigned integer).
  1368.                            Identifier of the parent object to be
  1369.                            cloned.
  1370.  
  1371.             Clone_id:    2 bytes (nonzero unsigned integer).
  1372.                            Identifier of the child object that is
  1373.                            created.
  1374.  
  1375.             Clone_type:  1 byte (unsigned integer).
  1376.  
  1377.                            0: Full clone of the object attributes
  1378.                               set and the object buffer.
  1379.  
  1380.                            1: Partial clone; only object attributes
  1381.                               set (the location, clipping boundaries,
  1382.                               and potential visibility) are copied
  1383.                               and a link is made to the object
  1384.                               buffer.
  1385.  
  1386.                            2: Renumber object (this is equivalent to
  1387.                               "CLON source_id clone_id 1
  1388.                                DISC source_id").
  1389.  
  1390.                          This field can be omitted if the
  1391.                          do_not_show field is also omitted.
  1392.                          If it is omitted, the clone_type defaults
  1393.                          to zero (full clone).
  1394.  
  1395.             Do_not_show: 1 byte (unsigned integer).
  1396.                            0:  Make the clone potentially visible.
  1397.                            1:  Do not make the clone potentially
  1398.                                visible.
  1399.                          This field can be omitted if the concrete
  1400.                          flag and location fields are also omitted.
  1401.                          When it is omitted, the object retains the
  1402.                          potential visibility of the parent object.
  1403.  
  1404.             Concrete
  1405.               flag:      1 byte (unsigned integer).
  1406.                            0:  Concrete_flag is the same as
  1407.                                that of the parent object.
  1408.                            1:  Make the clone "abstract"
  1409.                                (concrete_flag=0).
  1410.  
  1411.                          This field can be omitted if the location
  1412.                          fields are also omitted.  When it is
  1413.                          omitted, the object retains the concrete
  1414.                          flag of the parent object.
  1415.  
  1416.             Loca
  1417.              delta_type: 1 byte (unsigned integer)
  1418.  
  1419.                            0: Location data gives X_location and
  1420.                               Y_location directly.
  1421.  
  1422.                            1: New positions are determined by
  1423.                               adding the location data to the
  1424.                               position of the parent object.
  1425.  
  1426.                          This field, together with the X_location
  1427.                          and Y_location fields, can be omitted.
  1428.                          When they are omitted, the clone has the
  1429.                          same location as the parent object.
  1430.  
  1431.             X_location or delta
  1432.               X_location:4 bytes (signed integer).
  1433.  
  1434.             Y_location or delta
  1435.               Y_location:4 bytes (signed integer).
  1436.  
  1437.          The source_id must be an existing object identifier, and the
  1438.          clone_id must not be an existing object identifier.
  1439.  
  1440.          Negative values are permitted for the X and Y position.  The
  1441.          positive directions are downward and rightward from the frame
  1442.          origin.
  1443.  
  1444.          The clone is initially identical to the parent object except
  1445.          for the location and potential visibility.  It has the same
  1446.          clipping boundaries as the parent object.  Subsequent DHDR,
  1447.          SHOW, CLON, CLIP, MOVE, PAST, and DISC chunks can use the
  1448.          clone_id to identify it.  If the parent object is not a
  1449.          viewable image, neither is the clone.
  1450.  
  1451.          Subsequent chunks can modify, show, or discard a full clone or
  1452.          modify its potential visibility, location and clipping
  1453.          boundaries without affecting the parent object, or they can
  1454.          modify, show, or discard the parent object or modify its object
  1455.          attribute set without affecting the clone.
  1456.  
  1457.          The concrete_flag byte must be zero when the clone_type byte is
  1458.          nonzero.
  1459.  
  1460.          If an object has partial clones, and the data in the object
  1461.          buffer of a parent object or any of its partial clones is
  1462.          modified, the parent object and all of its partial clones are
  1463.          changed.  Decoders must take care that when the parent object
  1464.          or any partial clone is discarded, the object buffer is not
  1465.          discarded until the last remaining one of them is discarded.
  1466.          Only the location, potential visibility, and clipping
  1467.          boundaries can be changed independently for each partial clone.
  1468.  
  1469.       4.2.7. DHDR, Delta-PNG chunks, IEND
  1470.  
  1471.          A Delta-PNG (PNG-Delta) datastream.
  1472.  
  1473.          See The Delta-PNG Format (Chapter 6), below, for the format of
  1474.          the Delta-PNG datastream.  Any chunks between DHDR and IEND are
  1475.          written and decoded according to the Delta-PNG format.  The
  1476.          object_id of the Delta-PNG DHDR chunk must point to an existing
  1477.          parent object.  The resulting image is immediately displayed if
  1478.          its do_not_show=0.  The parent object must be concrete (i.e.,
  1479.          it must have concrete_flag=1).
  1480.  
  1481.       4.2.8. PAST Paste an image into another
  1482.  
  1483.          Paste an image or images identified by source_id, or part of
  1484.          it, into an existing abstract image identified by
  1485.          destination_id.
  1486.  
  1487.          The PAST chunk contains a 2-byte destination_id and 9 bytes
  1488.          giving a "target location", plus one or more 30-byte source
  1489.          data sequences.
  1490.  
  1491.             Destination_id: 2 bytes (unsigned integer).
  1492.  
  1493.             Target
  1494.               delta_type:   1 byte (unsigned integer).
  1495.                               0:  Target_x and target_y are given
  1496.                                   directly.
  1497.                               1:  Target_x and target_y are deltas
  1498.                                   from their previous values in a
  1499.                                   PAST chunk with the same
  1500.                                   destination_id.
  1501.                               2:  Target_x and target_y are deltas
  1502.                                   from their previous values in the
  1503.                                   immediately preceding PAST chunk
  1504.                                   regardless of its destination_id.
  1505.  
  1506.             Target_x:         4 bytes (signed integer), measured
  1507.                                 rightward from the left edge of the
  1508.                                 destination image.
  1509.  
  1510.             Target_y:         4 bytes (signed integer), measured
  1511.                                 downward from the top edge of the
  1512.                                 destination image.
  1513.  
  1514.             Source_id:        2 bytes (unsigned nonzero integer).
  1515.                                 An image to be pasted in.
  1516.  
  1517.             Composition
  1518.               mode:           1 byte (unsigned integer).
  1519.                                  0:  Composite_over.
  1520.                                  1:  Replace.
  1521.                                  2:  Composite_under.
  1522.  
  1523.             Orientation:      1 byte (unsigned integer).
  1524.                                 The source image is flipped to
  1525.                                 another orientation.
  1526.  
  1527.                                 0:  Same as source image.
  1528.                                 2:  Flipped left-right, then up-down.
  1529.                                 4:  Flipped left-right.
  1530.                                 6:  Flipped up-down.
  1531.                                 8:  Tiled with source image, to fill
  1532.                                     the clipping boundaries.  The
  1533.                                     upper left corner of the assembly
  1534.                                     is positioned according to the
  1535.                                     prescribed offsets.
  1536.  
  1537.             Offset
  1538.              delta_type:      1 byte (unsigned integer).
  1539.                                 0: Offsets are measured from the
  1540.                                    {0,0} pixel in the destination
  1541.                                    image.
  1542.                                 1: Offsets are measured from the
  1543.                                    {target_x,target_y} pixel in the
  1544.                                    destination image.
  1545.  
  1546.             Xoffset or
  1547.               delta xoffset:  4 bytes (signed integer).
  1548.             Yoffset or
  1549.               delta yoffset:  4 bytes (signed integer).
  1550.  
  1551.             Boundary
  1552.               delta_type:     1 byte (unsigned integer).
  1553.                                 0: Boundaries are measured from
  1554.                                    the {0,0} pixel in the
  1555.                                    destination image.
  1556.                                 1: Boundaries are measured from the
  1557.                                    {target_x,target_y} pixel in the
  1558.                                    destination image.
  1559.  
  1560.             Left_pb or delta
  1561.               left_pb:        4 bytes (signed integer).
  1562.             Right_pb or delta
  1563.               right_pb:       4 bytes (signed integer).
  1564.             Top_pb or delta
  1565.               top_pb:         4 bytes (signed integer).
  1566.             Bottom_pb or delta
  1567.               bottom_pb:      4 bytes (signed integer).
  1568.             ...etc...
  1569.  
  1570.          The destination image must have the "abstract" property
  1571.          (concrete_flag=0).  When destination_id=0, the resulting image
  1572.          is "write-only" and therefore only "composite-over"
  1573.          (composition_mode=0) operations are permitted.
  1574.  
  1575.          The source images can be "abstract" or "concrete" and have any
  1576.          color_type and sample_depth.  They must have the "viewable"
  1577.          property.  The number of source images is
  1578.          ((chunk_length-11)/30).
  1579.  
  1580.          The x_offset and y_offset distances and the clipping boundaries
  1581.          are measured, in pixels, positive rightward and downward from
  1582.          either the {0,0} pixel of the destination image or the
  1583.          {target_x, target_y} position in the destination image.  They
  1584.          do not necessarily have to fall within the destination image.
  1585.          Only those pixels of the source image that fall within the
  1586.          destination image and also within the specified clipping
  1587.          boundaries will be copied into the destination image.  Note
  1588.          that the coordinate system for offsets and clipping is with
  1589.          respect to the upper lefthand corner of the destination image,
  1590.          which is not necessarily the same coordinate system used by the
  1591.          MOVE and CLIP chunks.  If the source image has been flipped or
  1592.          rotated, X_offset and Y_offset give the location of its new
  1593.          upper left hand corner.  When it is tiled, the offsets give the
  1594.          location of the upper left hand corner of the assembly of
  1595.          tiles.
  1596.  
  1597.          When composition_mode=0, any non-opaque pixels in the source
  1598.          image are combined with those of the destination image.  If the
  1599.          destination pixel is also non-opaque, the resulting pixel will
  1600.          be non-opaque.
  1601.  
  1602.          When composition_mode=1, all pixels simply replace those in the
  1603.          destination image.  This mode can be used to make a transparent
  1604.          hole in an opaque image.
  1605.  
  1606.          When composition_mode=2, any non-opaque pixels in the
  1607.          destination image are combined with those of the source image.
  1608.          If the source pixel is also non-opaque, the resulting pixel
  1609.          will be non-opaque.
  1610.  
  1611.          The order of composition is the same as the order that the
  1612.          source_id's appear in the list (but a decoder can do the
  1613.          composition in any order it pleases, or all at once, provided
  1614.          that the resulting destination image is the same as if it had
  1615.          actually performed each composition in the specified order).
  1616.          Decoders must be careful when the destination image equals the
  1617.          source image--the pixels to be drawn are the ones that existed
  1618.          before the drawing operation began.
  1619.  
  1620.          The MOVE or CLIP information associated with the destination_id
  1621.          and the source_id's is not used in the PAST operation (but if a
  1622.          decoder is simultaneously updating and displaying the
  1623.          destination_id, the MOVE and CLIP for the destination_id is
  1624.          used in the display operation).
  1625.  
  1626.       4.2.9. DISC Discard objects
  1627.  
  1628.          The DISC chunk can be used to inform the decoder that it can
  1629.          discard the object data associated with the associated object
  1630.          identifiers.  Whether the decoder actually discards the data or
  1631.          not, it must not use it after encountering the DISC chunk.
  1632.  
  1633.          The chunk contains a sequence of zero or more two-byte object
  1634.          identifiers.  The number of objects to be discarded is the
  1635.          chunk's data length, divided by two.
  1636.  
  1637.             Discard_id: 2 bytes (nonzero unsigned integer).
  1638.             ...etc...
  1639.  
  1640.          If the DISC chunk is empty, all objects except those preceding
  1641.          the SAVE chunk (i.e., the "frozen" objects) can be discarded.
  1642.          If a SAVE chunk has not been encountered, all objects can be
  1643.          discarded.  Note that each appearance of a SEEK chunk in the
  1644.          datastream implies an empty DISC chunk.
  1645.  
  1646.          If the DISC chunk is not empty, the listed objects can be
  1647.          discarded.
  1648.  
  1649.          When an object is discarded, any location, potential
  1650.          visibility, and clipping boundary data associated with it is
  1651.          also discarded.
  1652.  
  1653.          It is not an error to include an object_id in the discard_id
  1654.          list, when no such object has been stored, or when the object
  1655.          has already been discarded.
  1656.  
  1657.          It is an error to name explicitly any "frozen" object in the
  1658.          DISC list.
  1659.  
  1660.          When the object is a partial clone or is the source of a
  1661.          partial clone that has not been discarded, only the object
  1662.          attribute set (location, potential visibility, and clipping
  1663.          boundaries) can be discarded.  The data in the object buffer
  1664.          must be retained until the last remaining partial clone is
  1665.          discarded.
  1666.  
  1667.    4.3. Critical MNG image displaying chunks
  1668.  
  1669.       4.3.1. BACK Background
  1670.  
  1671.          The BACK chunk suggests a background color against which
  1672.          transparent, clipped, or less-than-full-frame images can be
  1673.          displayed.
  1674.  
  1675.             Red_background:   2 bytes (unsigned integer).
  1676.  
  1677.             Green_background: 2 bytes (unsigned integer).
  1678.  
  1679.             Blue_background:  2 bytes (unsigned integer).
  1680.  
  1681.             Mandatory
  1682.               background:     1 byte (unsigned integer).
  1683.                                  0: Background color and background
  1684.                                     image are advisory.  Applications
  1685.                                     can use them if they choose to.
  1686.                                  1: Background color is mandatory.
  1687.                                     Applications must use it.
  1688.                                     Background image is advisory.
  1689.                                  2: Background image is mandatory.
  1690.                                     Applications must use it.
  1691.                                     Background color is advisory.
  1692.                                  3: Background color and background
  1693.                                     image are both mandatory.
  1694.                                     Applications must use them.
  1695.                                  This byte can be omitted if the
  1696.                                  background_image_id is also omitted.
  1697.                                  If so, the background color is
  1698.                                  advisory.
  1699.  
  1700.             Background
  1701.               image_id:        2 bytes (unsigned nonzero integer).
  1702.                                  Object_id of an image that is to be
  1703.                                  displayed as the background of each
  1704.                                  frame.  If it is not full-frame, the
  1705.                                  remainder of the frame is filled
  1706.                                  with the background color.  This
  1707.                                  field can be omitted; if so, no
  1708.                                  background image is defined, and the
  1709.                                  background image from a previous
  1710.                                  BACK chunk becomes undefined.
  1711.  
  1712.             Background
  1713.               tiling:          1 byte (unsigned integer).
  1714.                                  0: Do not tile the background.
  1715.                                  1: Tile the background with the
  1716.                                     background image.  This field
  1717.                                     can be omitted; if so, do not
  1718.                                     tile the background.
  1719.  
  1720.          Viewers are expected to composite every subframe in the MNG
  1721.          datastream against a fresh copy of the background, if the
  1722.          framing mode given in the FRAM chunk is 3 or 4.  The images and
  1723.          the background are both clipped to the frame boundaries given
  1724.          in the FRAM chunk.  The background image (or tiled assembly) is
  1725.          also clipped to its own boundaries and located like any other
  1726.          image.  When the background image is used for tiling, the upper
  1727.          left tile is located according to the background image's
  1728.          location attributes and the entire assembly is clipped
  1729.          according to its clipping attributes.  Viewers might actually
  1730.          follow some other procedure, but the final appearance of each
  1731.          frame must be the same as if they had filled the area within
  1732.          the frame boundaries with the background color, then displayed
  1733.          the background image, and then displayed the foreground image
  1734.          (or images), without delay.
  1735.  
  1736.          It is not an error to specify a background_image_id when such
  1737.          an image does not exist or ceases to exist for some reason.
  1738.          Viewers must be prepared to fall back to using the background
  1739.          color in this event.  They also must be prepared for the
  1740.          contents, location, and clipping boundaries of the background
  1741.          image to change, just like any other object, if it has not been
  1742.          "frozen".
  1743.  
  1744.          The three BACK components are always interpreted in the current
  1745.          color space as defined by any top-level gAMA, cHRM, iCCP, sRGB
  1746.          chunks that have appeared prior to the BACK chunk in the MNG
  1747.          datastream.  If no such chunks appear, the color space is
  1748.          unknown.
  1749.  
  1750.          The color space of the background image, if one is used, is
  1751.          determined in the same manner as the color space of any other
  1752.          image.
  1753.  
  1754.          When the BACK chunk appears between FRAM chunks, it applies to
  1755.          the upcoming frame, not to the current one.  When the
  1756.          framing_mode is 3, it takes effect immediately prior to the
  1757.          next IHDR, JHDR, DHDR, PAST, or SHOW chunk in the datastream.
  1758.  
  1759.          For the purpose of counting layers, when the background
  1760.          consists of both a background color and a background image,
  1761.          these are considered to generate a single layer and there is no
  1762.          delay between displaying the background color and the
  1763.          background image.
  1764.  
  1765.          Multiple instances of the BACK chunk are permitted in a MNG
  1766.          datastream.
  1767.  
  1768.          The BACK chunk can be omitted.  If a background is required and
  1769.          the BACK chunk is omitted, then the viewer must supply its own
  1770.          background.
  1771.  
  1772.          In practice, most applications that use MNG as part of a larger
  1773.          composition should ignore the BACK data if
  1774.          mandatory_background=0 and the application already has its own
  1775.          background definition.  This will frequently be the case in
  1776.          World Wide Web pages, to achieve nonrectangular transparent
  1777.          animations displayed against the background of the page.
  1778.  
  1779.       4.3.2. FRAM Frame definitions
  1780.  
  1781.          The FRAM chunk provides information that a decoder needs for
  1782.          generating layers, subframes, and frames.  The FRAM parameters
  1783.          govern how the decoder is to behave when it encounters a FRAM
  1784.          chunk, a SHOW chunk, or an embedded image.  The FRAM chunk also
  1785.          delimits subframes.
  1786.  
  1787.          An empty FRAM chunk is just a subframe delimiter.  A nonempty
  1788.          one is a subframe delimiter, and it also changes FRAM
  1789.          parameters, either for the upcoming subframe or until reset.
  1790.          When the FRAM chunk is not empty, it contains a framing-mode
  1791.          byte, an optional name string, a zero-byte separator, plus four
  1792.          1-byte fields plus a variable number of optional fields.
  1793.  
  1794.             Framing mode:  1 byte.
  1795.  
  1796.                              0:  Don't change framing mode.
  1797.  
  1798.                              1:  Each embedded image or SHOW'ed
  1799.                                  image generates a subframe
  1800.                                  consisting of a single image layer.
  1801.                                  There is no background layer.
  1802.                                  Use this mode to avoid unnecessary
  1803.                                  clearing of the display when the
  1804.                                  first image covers the entire
  1805.                                  frame area, and subsequent frames can
  1806.                                  be displayed properly by simply
  1807.                                  overlaying them on the prior frame.
  1808.                                  This is the default framing mode.
  1809.  
  1810.                              2:  The group of embedded images or
  1811.                                  SHOW'ed images appearing prior
  1812.                                  to the next FRAM chunk form a
  1813.                                  composite subframe consisting of
  1814.                                  zero or more image layers.  The
  1815.                                  level, or stacking order, of each
  1816.                                  layer is given by its order of
  1817.                                  appearance in the datastream.
  1818.                                  No interframe delay occurs between
  1819.                                  the layers.
  1820.  
  1821.                              3:  This is the same as framing_mode=1,
  1822.                                  except that a background layer is
  1823.                                  generated.  Each embedded image or
  1824.                                  SHOW'ed image generates a subframe
  1825.                                  consisting of a background layer
  1826.                                  followed by an image layer.  No
  1827.                                  interframe delay occurs between the
  1828.                                  background layer and the image layer.
  1829.  
  1830.                              4:  This is the same as framing_mode=2,
  1831.                                  except that a background layer is
  1832.                                  generated prior to the image layers.
  1833.  
  1834.             Subframe name: 0 or more bytes (Latin-1 Text).  Can be
  1835.                              omitted; if so, the subframe is nameless.
  1836.  
  1837.             Separator:     1 byte:  (null).  Must be omitted if all
  1838.                              remaining fields are also omitted.
  1839.  
  1840.             Change interframe
  1841.                 delay:     1 byte.
  1842.  
  1843.                              0:  No.
  1844.                              1:  Yes, for the next subframe only.
  1845.                              2:  Yes, also reset default.
  1846.  
  1847.                            This field and the next three must be
  1848.                            omitted as a group if no frame parameters
  1849.                            other than the framing mode are changed.
  1850.  
  1851.             Change sync timeout and
  1852.               termination: 1 byte
  1853.                              0:  No.
  1854.                              1:  Deterministic, for the next subframe
  1855.                                  only.
  1856.                              2:  Deterministic, also reset default.
  1857.                              3:  Decoder-discretion, for the next
  1858.                                  subframe only.
  1859.                              4:  Decoder-discretion, also reset
  1860.                                  default.
  1861.                              5:  User-discretion, for the next subframe
  1862.                                  only.
  1863.                              6:  User-discretion, also reset default.
  1864.                              7:  External-signal, for the next subframe
  1865.                                  only.
  1866.                              8:  External-signal, also reset default.
  1867.  
  1868.             Change subframe clipping
  1869.              boundaries:   1 byte.
  1870.                              0:  No.
  1871.                              1:  Yes, for the next subframe only.
  1872.                              2:  Yes, also reset default.
  1873.  
  1874.             Change sync id
  1875.               list:        1 byte.
  1876.                              0:  No.
  1877.                              1:  Yes, for this subframe only.
  1878.                              2:  Yes, also reset default list.
  1879.  
  1880.             Interframe
  1881.               delay:       4 bytes (unsigned integer).  Must
  1882.                              be omitted if change_interframe_delay=0.
  1883.                              The range is [0..2^31-1] ticks.
  1884.  
  1885.             Sync timeout:  4 bytes (unsigned integer).  Omit if
  1886.                              change_sync_timeout=0.  The range is
  1887.                              [0..2^31-1].  The value 2^31-1
  1888.                              (0x7fffffff) ticks represents an
  1889.                              infinite timeout period.
  1890.  
  1891.             Subframe boundary
  1892.               delta type:  1 byte (unsigned integer).
  1893.                              0: Subframe clipping boundary values are
  1894.                                 given directly.
  1895.                              1: Subframe clipping boundaries
  1896.                                 are determined by adding the FRAM
  1897.                                 data to their previous values.
  1898.                            This and the following four
  1899.                            fields must be omitted if
  1900.                            change_frame_clipping_boundaries=0.
  1901.  
  1902.             Left_fb or delta
  1903.               left_fb:     4 bytes (signed integer).
  1904.  
  1905.             Right_fb or delta
  1906.               right_fb:    4 bytes (signed integer).
  1907.  
  1908.             Top_fb or delta
  1909.               top_fb:      4 bytes (signed integer).
  1910.  
  1911.             Bottom_fb or delta
  1912.               bottom_fb:   4 bytes (signed integer).
  1913.  
  1914.             Sync id:       4 bytes (unsigned integer).  Omit if
  1915.                              change_sync_id_list=0 or if the new
  1916.                              list is empty; repeat until all
  1917.                              sync_id's have been listed.  The
  1918.                              range is [0..2^31-1].
  1919.  
  1920.          When the FRAM parameters are changed, the new parameters affect
  1921.          the subframe that is about to be defined, not the one that is
  1922.          being terminated by the FRAM chunk.
  1923.  
  1924.          Framing modes:
  1925.  
  1926.          Framing mode 1.
  1927.             When framing_mode=1, each image generates a separate
  1928.             subframe consisting of a single image layer.  In the usual
  1929.             case, the interframe delay is nonzero, so each subframe is a
  1930.             frame.  FRAM chunks need not appear to separate them.
  1931.  
  1932.             The following events generate a subframe:
  1933.  
  1934.                 * Decoding a IHDR-IEND sequence at the MNG level, when
  1935.                   it defines a potentially visible image.
  1936.  
  1937.                 * Decoding a JHDR-IEND sequence at the MNG level, when
  1938.                   it defines a potentially visible image.
  1939.  
  1940.                 * Decoding a DHDR-IEND sequence, when it defines a
  1941.                   potentially visible image.
  1942.  
  1943.                 * Decoding a BASI-IEND sequence, when it defines a
  1944.                   potentially visible image.
  1945.  
  1946.                 * Decoding a PAST chunk, when its destination is a
  1947.                   potentially visible image.
  1948.  
  1949.                 * Decoding a SHOW chunk, when it directs that a
  1950.                   potentially visible image be displayed.  When the SHOW
  1951.                   chunk requests that several images be displayed, each
  1952.                   one in turn generates a separate frame.
  1953.  
  1954.             Any of these events generates a subframe, even if the
  1955.             visible image is outside the clipping boundaries and no
  1956.             pixels are actually changed.
  1957.  
  1958.             For example (assuming that objects 1 through 5 are all
  1959.             viewable objects and a nonzero interframe delay time), the
  1960.             sequence
  1961.  
  1962.                FRAM 1
  1963.                SHOW 1 5
  1964.  
  1965.             will generate five frames, each containing a single subframe
  1966.             consisting of an image layer.
  1967.  
  1968.             If the BACK chunk is present, encoders should insert a
  1969.             background layer, with a zero delay, ahead of the first
  1970.             image layer in a segment, even when the framing_mode is 1.
  1971.             Such layers must be included in the layer count but not in
  1972.             the frame count.  If the BACK chunk is not present, the
  1973.             contents of the display become undefined at the beginning of
  1974.             each segment.
  1975.  
  1976.          Framing mode 2.
  1977.             Framing mode 2 is the same as framing mode 1, except that
  1978.             the interframe delay occurs between subframes rather than
  1979.             between images.  In the usual case, the interframe delay is
  1980.             nonzero, so the subframes are composite frames.  When
  1981.             framing_mode=2, viewers are expected to display all of the
  1982.             images at once, if possible, or as fast as can be managed,
  1983.             without clearing the display or restoring the background.
  1984.             The next FRAM chunk delimits the subframe.  A subframe
  1985.             boundary also occurs when a SEEK chunk or the MEND chunk
  1986.             appears.
  1987.  
  1988.             For example, the sequence
  1989.  
  1990.                FRAM 2
  1991.                SHOW 1 5   (shows images 1, 2, 3, 4, and 5)
  1992.                FRAM
  1993.  
  1994.             will result in a single subframe containing five layers,
  1995.             each consisting of one image displayed according to its
  1996.             location and CLIP data.  If the images do not cover the
  1997.             entire frame, whatever was already on the display shows
  1998.             through.
  1999.  
  2000.             When images in a subframe overlap, viewers are expected to
  2001.             composite the later images against the partially completed
  2002.             subframe that includes all earlier images.
  2003.  
  2004.             This framing_mode is fundamentally declarative; it describes
  2005.             the elements that go into an individual subframe.  It is up
  2006.             to the decoder to work out an efficient way of making the
  2007.             screen match the desired composition.  Simple decoders can
  2008.             handle it as if it were procedural, compositing the images
  2009.             into the frame buffer in the order that they appear, but
  2010.             efficient decoders might do something different, as long as
  2011.             the final appearance of the frame is the same.
  2012.  
  2013.             If the BACK chunk is present, encoders should insert a
  2014.             background layer, with a zero delay, ahead of the first
  2015.             image layer in a segment, even when the framing_mode is 2.
  2016.             Such layers must be included in the layer count but not in
  2017.             the frame count.  If the BACK chunk is not present, the
  2018.             contents of the display become undefined at the beginning of
  2019.             each segment.
  2020.  
  2021.          Framing mode 3.
  2022.             When framing_mode=3, a subframe consisting of the background
  2023.             layer and an image layer is generated for each image.  A
  2024.             subframe boundary occurs after each image appears.
  2025.             Otherwise, framing_mode=3 is identical to framing_mode=1.
  2026.             Subframes are triggered by the same events that trigger a
  2027.             subframe when framing_mode=1.
  2028.  
  2029.             You can use this mode to show a frame containing only the
  2030.             background, with its own time delay, as in
  2031.  
  2032.                FRAM 3     (shows background with interframe delay)
  2033.                FRAM 1
  2034.                SHOW 1 5   (shows images 1, 2, 3, 4, and 5, each with
  2035.                            its own interframe delay)
  2036.  
  2037.             In this example, the background and the five images will be
  2038.             displayed one at a time against the background, like cards
  2039.             being dealt.
  2040.  
  2041.          Framing mode 4.
  2042.             When framing_mode=4, a subframe boundary and interframe
  2043.             delay occurs when each FRAM chunk appears.  A background
  2044.             layer, consisting of the background image composited against
  2045.             the background color, is generated immediately after the
  2046.             FRAM chunk, Otherwise, framing_mode=4 is identical to
  2047.             framing_mode=2.  A subframe boundary also occurs when a SEEK
  2048.             chunk or the MEND chunk appears, but neither of these
  2049.             generates a background layer.
  2050.  
  2051.             You can make a composite frame consisting of six layers (a
  2052.             background layer and 5 images) with
  2053.  
  2054.                FRAM 4    (show background, no delay)
  2055.                SHOW 1 5  (show images 1, 2, 3, 4, and 5, no delay)
  2056.                FRAM      (interframe delay, then start next frame)
  2057.  
  2058.          Summary of framing modes.
  2059.             This table summarizes the behavior of a viewer under the
  2060.             various framing modes.
  2061.  
  2062.                +--------------+--------------------+-------------------+
  2063.                | Framing mode | Restore background | Interframe delay  |
  2064.                +--------------+--------------------+-------------------+
  2065.                |      1       | Before first image*| Before each FRAM  |
  2066.                |              | after first FRAM   | after the first   |
  2067.                |              | in the datastream  | in the datastream |
  2068.                |              | (or segment, if    |                   |
  2069.                |              | jumped to segment) |                   |
  2070.                +--------------+--------------------+-------------------+
  2071.                |      2       | Before first image | Before each image |
  2072.                |              | after first FRAM   | after the first   |
  2073.                |              | in the datastream  | in the datastream |
  2074.                |              | (or segment, if    |                   |
  2075.                |              | jumped to segment) |                   |
  2076.                +--------------+--------------------+-------------------+
  2077.                |      3       | Before each image  | Before each image |
  2078.                |              |                    | after the first   |
  2079.                |              |                    | in the datastream |
  2080.                +--------------+--------------------+-------------------+
  2081.                |      4       | Before first image | Before each FRAM  |
  2082.                |              | following each     | after the first   |
  2083.                |              | FRAM chunk         | in the datastream |
  2084.                +--------------+--------------------+-------------------+
  2085.                | *"image" means an image layer that is generated in    |
  2086.                | response to decoding an embedded object or a SHOW     |
  2087.                | directive, even if no pixels are actually drawn due   |
  2088.                | to the image being outside the clipping boundaries.   |
  2089.                +-------------------------------------------------------+
  2090.  
  2091.             The framing_mode also affects the way decoders handle the
  2092.             pHYs chunk (see below, Paragraph 4.5.4).
  2093.  
  2094.          The subframe name must conform to the same formatting rules as
  2095.          those for a SEEK keyword:  It must consist only of printable
  2096.          Latin-1 characters and must not have leading or trailing
  2097.          blanks, but can have single embedded blanks.  There must be at
  2098.          least one (unless the subframe name is omitted) and no more
  2099.          than 79 characters in the keyword.  Keywords are case-
  2100.          sensitive.  There is no null byte within the keyword.  No
  2101.          specific use for the subframe name is specified in this
  2102.          document, except that it can be included in the optional index
  2103.          that can appear in the SAVE chunk.  Applications can use this
  2104.          field for such purposes as constructing an external list of
  2105.          subframes in the datastream.  The subframe name only applies to
  2106.          the upcoming subframe; subsequent subframes are unnamed unless
  2107.          they also have their own frame_name field.  It is recommended
  2108.          that the same name not appear in any other FRAM chunk or in any
  2109.          SEEK or eXPI chunk.  Subframe names should not begin with the
  2110.          case-insensitive strings "clock(", "frame(", or "frames(",
  2111.          which are reserved for use in URI queries and fragments.
  2112.  
  2113.          The interframe delay value is the desired minimum time to
  2114.          elapse from the beginning of displaying one frame until the
  2115.          beginning of displaying the next frame.  When the interframe
  2116.          delay is nonzero, which will probably be the usual case,
  2117.          subframes are frames.  When it is zero, a frame consists of any
  2118.          number of consecutive subframes, until a nonzero delay subframe
  2119.          is encountered and completed.  Decoders are not obligated to
  2120.          display such subframes individually; they can composite them
  2121.          offscreen and only display the complete frame.
  2122.  
  2123.          The sync timeout field can be a number or <infinity>.  Infinity
  2124.          can be represented by 0x7fffffff.
  2125.  
  2126.          The termination condition given in the
  2127.          change_sync_timeout_and_termination field specifies how much
  2128.          longer, after the normal interframe delay has elapsed, the
  2129.          frame will endure.  It can take the following values:
  2130.  
  2131.          deterministic
  2132.             The frame endures no longer than the normal interframe
  2133.             delay.  Even though this is the default, a streaming encoder
  2134.             talking to a real-time decoder might write a FRAM with a
  2135.             termination condition of "deterministic" to force the
  2136.             display to be updated while the encoder decides its next
  2137.             move.
  2138.  
  2139.          decoder-discretion
  2140.             The decoder can lengthen the duration of the frame, but by
  2141.             no more than the timeout.  A streaming decoder could take
  2142.             the opportunity to wait for its input buffer to fill to a
  2143.             comfortable level.
  2144.  
  2145.          user-discretion
  2146.             After the interframe delay has expired, the decoder should
  2147.             wait for permission from the user (e.g., via a keypress)
  2148.             before proceeding, but must wait no longer than the timeout.
  2149.             If the decoder cannot interact with the user, this condition
  2150.             degenerates into "decoder-discretion".
  2151.  
  2152.          external-signal
  2153.             After the interframe delay has expired, the decoder should
  2154.             wait for the arrival of a signal whose number matches a
  2155.             sync_id, but must wait no longer than the timeout.
  2156.  
  2157.          The sync_id list can be omitted if the termination condition is
  2158.          not "external-signal".
  2159.  
  2160.          When the sync_id list is changed, the number of sync_id entries
  2161.          is determined by the remaining length of the chunk data,
  2162.          divided by four.  This number can be zero, which either
  2163.          inactivates the existing sync_id list for one frame or deletes
  2164.          it.
  2165.  
  2166.          The initial values of the FRAM parameters are:
  2167.  
  2168.               Framing mode             = 1
  2169.               Subframe name            = <empty string>
  2170.               Interframe delay         = 0
  2171.               Left subframe boundary   = 0
  2172.               Right subframe boundary  = frame width
  2173.               Top subframe boundary    = 0
  2174.               Bottom subframe boundary = frame height
  2175.               termination              = deterministic
  2176.               Sync timeout             = 0x7fffffff (infinite)
  2177.               Sync id                  = <empty list>
  2178.  
  2179.          The MOVE chunk can be used to specify the placement of each
  2180.          image within the layer.  The CLIP chunk can be used to specify
  2181.          clipping boundaries for each image.  The subframe boundaries
  2182.          are only used for clipping, not for placement.  Even when the
  2183.          left and top frame boundaries are nonzero, the image locations
  2184.          are measured with respect to the {0,0} position in the display
  2185.          area.  If the layers are transparent or do not cover the entire
  2186.          area defined by the subframe clipping boundaries, they are
  2187.          composited against the background defined by the BACK chunk, or
  2188.          against an application-defined background, if the BACK chunk is
  2189.          not present or is not recognized by the decoder.  The
  2190.          background, as well as the images, is clipped to the subframe
  2191.          clipping boundaries.  Any pixels outside the subframe clipping
  2192.          boundaries remain unchanged.
  2193.  
  2194.          The frame_duration field gives the duration of display, which
  2195.          is the minimum time that must elapse from the beginning of
  2196.          displaying one frame until the beginning of displaying the next
  2197.          (or between images, when framing_mode=1).  It is measured in
  2198.          "ticks" using the tick length determined from ticks_per_second
  2199.          defined in the MHDR chunk.
  2200.  
  2201.          A viewer does not actually have to follow the procedure of
  2202.          erasing the screen, redisplaying the background, and
  2203.          recompositing the images against it, but what is displayed when
  2204.          the frame is complete must be the same as if it had.  It is
  2205.          sufficient to redraw the parts of the display that change from
  2206.          one frame to the next.
  2207.  
  2208.          The sync_id list provides a point at which the processor must
  2209.          wait for all pending processes to reach the synchronization
  2210.          point having the same sync_id before resuming, perhaps because
  2211.          of a need to synchronize a sound datastream (not defined in
  2212.          this specification) with the display, to synchronize stereo
  2213.          images, and the like.  When the period defined by the sum of
  2214.          the frame_duration and the sync_timeout fields elapses,
  2215.          processing can resume even though the processor has not
  2216.          received an indication that other processes have reached the
  2217.          synchronization point.
  2218.  
  2219.          Note that the synchronization point does not occur immediately,
  2220.          but at the end of the subframe that follows the FRAM chunk.  If
  2221.          it is necessary to establish a synchronization point
  2222.          immediately, this can be done by using two consecutive FRAM
  2223.          chunks, the first setting a temporary frame_duration=0,
  2224.          sync_timeout, and sync_id, and the second establishing the
  2225.          synchronization point:
  2226.  
  2227.             FRAM 2 0 1 1 0 1 0000 sync_timeout sync_id
  2228.             FRAM 0 name
  2229.  
  2230.          The identifier sync_id=0 is reserved to represent
  2231.          synchronization with a user input from a keyboard or pointing
  2232.          device.  The sync_id values 1-255 are reserved to represent the
  2233.          corresponding ASCII letter, received from the keyboard (or a
  2234.          simulated keyboard), and values 256-1023 are reserved for
  2235.          future definition by this specification.  If multiple channels
  2236.          (not defined in this specification) are not present, viewers
  2237.          can ignore other values appearing in the sync_id list.
  2238.  
  2239.       4.3.3. MOVE New image location
  2240.  
  2241.          New location of an existing object or objects (replacing or
  2242.          incrementing the location given in the DEFI chunk).
  2243.  
  2244.          The MOVE chunk gives the position, measured downward and to the
  2245.          right of the frame origin, in pixels, where the named object or
  2246.          group of objects is to be located.
  2247.  
  2248.          The chunk's contents are:
  2249.  
  2250.             First object:       2 bytes (nonzero unsigned integer).
  2251.  
  2252.             Last object:        2 bytes (nonzero unsigned integer).
  2253.  
  2254.             Location
  2255.               delta type:       1 byte (unsigned integer).
  2256.                                   0: MOVE data gives X_location and
  2257.                                      Y_location directly.
  2258.                                   1: New locations are determined
  2259.                                      by adding the MOVE data to the
  2260.                                      location of the parent object.
  2261.  
  2262.             X_location or
  2263.               delta X_location: 4 bytes (signed integer).
  2264.  
  2265.             Y_location or
  2266.               delta Y_location: 4 bytes (signed integer).
  2267.  
  2268.          The new location applies to a single object, if
  2269.          first_object=last_object, or to a group of consecutive
  2270.          object_ids, if they are different.  Last_object must not be
  2271.          less than first_object.  Negative values are permitted for the
  2272.          X and Y location.  The positive directions are downward and
  2273.          rightward from the frame origin.  The MOVE chunk can specify an
  2274.          image placement that is partially or wholly outside the display
  2275.          boundaries.  In such cases, the resulting image must be clipped
  2276.          to fit within its clipping boundaries, or not displayed at all
  2277.          if it falls entirely outside its clipping boundaries.  The
  2278.          clipping boundaries are determined as described in the
  2279.          specification for the CLIP chunk below (Paragraph 4.3.4).
  2280.  
  2281.          It is not an error for the MOVE chunk to name an object that
  2282.          has not previously been defined.  In such cases, nothing is
  2283.          done to the nonexistent object.
  2284.  
  2285.          When an object is discarded, its object attribute set, which
  2286.          includes the MOVE data, is also discarded.
  2287.  
  2288.       4.3.4. CLIP Object clipping boundaries
  2289.  
  2290.          This chunk gives the new boundaries (replacing or incrementing
  2291.          those from the DEFI chunk) to which an existing object or group
  2292.          of objects must be clipped for display.  It contains the
  2293.          following 21 bytes:
  2294.  
  2295.             First object:      2 bytes: (nonzero unsigned integer).
  2296.  
  2297.             Last object:       2 bytes: (nonzero unsigned integer).
  2298.  
  2299.             Clip delta type:   1 byte (unsigned integer).
  2300.                                  0: CLIP data gives boundary values
  2301.                                     directly.
  2302.                                  1: CLIP boundaries are determined
  2303.                                     by adding the CLIP data to their
  2304.                                     previous values for this object.
  2305.  
  2306.             Left_cb or
  2307.               delta_left_cb:   4 bytes (signed integer).
  2308.  
  2309.             Right_cb or
  2310.               delta_right_cb:  4 bytes (signed integer).
  2311.  
  2312.             Top_cb or
  2313.               delta_top_cb:    4 bytes (signed integer).
  2314.  
  2315.             Bottom_cb or
  2316.               delta_bottom_cb: 4 bytes (signed integer).
  2317.  
  2318.          The new clipping boundaries apply to a single object, if
  2319.          first_object=last_object, or to a group of consecutive objects,
  2320.          if they are different.  Last_object must not be less than
  2321.          first_object.
  2322.  
  2323.          The clipping boundaries are expressed in pixels, measured
  2324.          rightward and downward from the frame origin.
  2325.  
  2326.          The left and top clipping boundaries are inclusive and the
  2327.          right and bottom clipping boundaries are exclusive, i.e., the
  2328.          pixel located at {x,y} is only displayed if the pixel falls
  2329.          within the physical limits of the display hardware and all of
  2330.          the following are true:
  2331.  
  2332.             0       <= x < frame_width   (from the MHDR chunk)
  2333.             0       <= y < frame_height
  2334.             Left_fb <= x < right_fb      (from the FRAM chunk)
  2335.             Top_fb  <= y < bottom_fb
  2336.             Left_cb <= x < right_cb      (from the CLIP chunk)
  2337.             Top_cb  <= y < bottom_cb
  2338.  
  2339.          It is not an error for the CLIP chunk to name an object that
  2340.          has not previously been defined.  In such cases, nothing is
  2341.          done to the nonexistent object.
  2342.  
  2343.          When an object is discarded, its object attribute set, which
  2344.          includes the CLIP data, is also discarded.
  2345.  
  2346.       4.3.5. SHOW Show images
  2347.  
  2348.          The SHOW chunk is used to change the potential visibility of
  2349.          one or more previously-defined objects and to direct that they
  2350.          be displayed.  It contains 2, 4, or 5 bytes, or it can be
  2351.          empty.
  2352.  
  2353.             First image: 2 bytes (nonzero unsigned integer).
  2354.  
  2355.             Last image:  2 bytes  (nonzero unsigned integer).
  2356.                          This field can be omitted if the show_mode
  2357.                          byte is also omitted.  If so, decoders must
  2358.                          assume the default values, show_mode=0
  2359.                          and last_image=first_image.
  2360.  
  2361.             Show_mode:   1 byte (unsigned integer).
  2362.                            0:  Make the images potentially visible.
  2363.                            and display them (set do_not_show=0).
  2364.                        1:  Make the images invisible (set
  2365.                            do_not_show=1).
  2366.                        2:  Don't change do_not_show flag;
  2367.                            display those that are potentially
  2368.                            visible.
  2369.                        3:  Mark images "potentially visible"
  2370.                            (do_not_show=0), but do not display
  2371.                            them.
  2372.                        4:  Toggle do_not_show flag; display
  2373.                            any that are potentially visible after
  2374.                            toggling.
  2375.                        5:  Toggle do_not_show flag, but do
  2376.                            not display even if potentially visible
  2377.                            after toggling.
  2378.                        6:  Step through the images in the given
  2379.                            range, making the next image potentially
  2380.                            visible (set do_not_show=0) and display
  2381.                            it.  Set do_not_show=1 for all other
  2382.                            images in the range.  Cycle back to the
  2383.                            beginning of the range when reaching the
  2384.                            end of the range.  Perform one step for
  2385.                            each SHOW chunk (in reverse order if
  2386.                            last_image < first_image).
  2387.                        7.  Make the next image in the range (cycle)
  2388.                            potentially visible (do_not_show=0),
  2389.                            but do not display it.  Set
  2390.                            do_not_show=1 for the rest of the
  2391.                            images in the range.
  2392.  
  2393.                       This field can be omitted.  If so, decoders
  2394.                       must assume the default, show_mode=0.
  2395.  
  2396.          The decoder processes the objects (or images) named in the SHOW
  2397.          chunk in the order first_image through last_image, and resets
  2398.          the do_not_show flag for each of the objects.  If show_mode is
  2399.          even-valued, it also displays the images if they are
  2400.          potentially visible and are viewable images.
  2401.  
  2402.          When the SHOW chunk is empty, the decoder displays all existing
  2403.          potentially visible images, without changing their do_not_show
  2404.          status.  The empty SHOW chunk is equivalent to
  2405.  
  2406.             SHOW 1 65535 2
  2407.  
  2408.          If last_image < first_image the images are processed in reverse
  2409.          order.
  2410.  
  2411.          When show_mode is odd-valued, nothing is displayed unless a
  2412.          subsequent SHOW chunk with an even-valued show_mode appears.
  2413.  
  2414.          Interactions with the framing mode
  2415.             When show_mode is even-valued, each visible image that is
  2416.             displayed generates a separate layer, even if it is
  2417.             offscreen and no pixels are actually displayed.  In such
  2418.             cases, the layer is totally transparent.  When show_mode is
  2419.             odd, or when show_mode=2 or 4 or is empty and no image is
  2420.             visible, no layer is generated.
  2421.  
  2422.             When show_mode is 1, 4, 5, 6, or 7, images can be made
  2423.             invisible.  This is not permitted when the framing mode is 2
  2424.             or 4 in the FRAM chunk and the images have already appeared
  2425.             in the frame, because simple viewers will have already drawn
  2426.             them and have no way to make them invisible again without
  2427.             redrawing the entire frame.
  2428.  
  2429.          When show_mode is 6 or 7, a single layer is generated.  The
  2430.          decoder must make the next image in the "cycle" visible.  To do
  2431.          this, it must examine the do_not_show flag for each image in
  2432.          the range first_image through last_image, and make the next one
  2433.          (the one with the next higher value of image_id that exists and
  2434.          is "viewable") after the first visible one it finds visible and
  2435.          the rest invisible.  When first_image > last_image, the cycle
  2436.          is reversed, and the "next" image is the one with the next
  2437.          lower value of image_id.  In either case, if the first visible
  2438.          one was last_id, or none were visible, it must make first_image
  2439.          visible.  These modes are useful for manipulating a group of
  2440.          sequential images that represent different views of an animated
  2441.          icon.  See Example 8, below (Chapter 15).  If no "visible"
  2442.          object is in the specified range, an empty layer must be
  2443.          generated.
  2444.  
  2445.          When show_mode=0, 2, 4, or 6, separate layers will be
  2446.          generated, each containing an instance of one visible image at
  2447.          the location specified by the DEFI, CLON, or MOVE chunk and
  2448.          clipped according to the boundaries specified by the CLIP and
  2449.          FRAM chunks.  When the MOVE or CLON chunk is used in the delta
  2450.          form, which will frequently be the case, each image must be
  2451.          displaced from its previous position by the values given in the
  2452.          MOVE or CLON chunk.
  2453.  
  2454.          Assuming a nonzero interframe delay, any of the following
  2455.          sequences would cause the image identified by object_id=6 in a
  2456.          composite frame to blink:
  2457.  
  2458.             LOOP 0 0 10
  2459.             FRAM 4       # Show background
  2460.             SHOW 1 10    # Show images 1 thru 10.
  2461.             FRAM         # Show background
  2462.             SHOW 1 5     # Show images 1 thru 5.
  2463.             SHOW 7 10    # Show images 7 thru 10.
  2464.             ENDL
  2465.  
  2466.             FRAM 4       # Show background
  2467.             LOOP 0 0 10
  2468.             SHOW 1 5     # Show images 1 thru 5.
  2469.             SHOW 6 6 4   # Toggle potential visibility of image 6
  2470.             SHOW 7 10    # and show it; show images 7 thru 10.
  2471.             FRAM
  2472.             ENDL
  2473.  
  2474.             FRAM 4       # Show background
  2475.             LOOP 0 0 10
  2476.             SHOW 6 6 5   # Toggle potential visibility of image 6.
  2477.             SHOW 1 10 2  # Show potentially visible images in 1
  2478.             FRAM         # through 10.
  2479.             ENDL
  2480.  
  2481.          It is not necessary to follow an IHDR-IEND, JHDR-IEND, BASI-
  2482.          IEND, or DHDR-IEND sequence or PAST chunk with a SHOW chunk to
  2483.          display the resulting image, if it was already caused to appear
  2484.          by do_not_show=0 in the DEFI chunk that introduced the image.
  2485.          Similarly, the CLON chunk need not be followed by a SHOW chunk,
  2486.          if do_not_show=0 in the CLON chunk.
  2487.  
  2488.          It is not an error for the SHOW chunk to name an object that
  2489.          has not previously been defined.  In such cases, nothing is
  2490.          done to the nonexistent object.
  2491.  
  2492.          If a nonviewable object is named, its do_not_show flag is
  2493.          changed, but it is not displayed even if the SHOW chunk
  2494.          requests it.
  2495.  
  2496.       4.3.6. TERM Termination action
  2497.  
  2498.          The TERM chunk suggests how the end of the MNG datastream
  2499.          should be handled, when a MEND chunk is found.  It contains
  2500.          either a single byte or ten bytes:
  2501.  
  2502.             Termination
  2503.               action:     1 byte (unsigned integer)
  2504.                             0: Show the last frame indefinitely.
  2505.                             1: Cease displaying anything.
  2506.                             2: Show the first frame after the TERM
  2507.                                chunk.  If processing the fPRI chunk,
  2508.                                use a "cost" of 255.
  2509.                             3: Repeat the animation starting
  2510.                                immediately after the TERM chunk.
  2511.  
  2512.             Action after
  2513.               iterations: 1 byte
  2514.                             0: Show the last frame indefinitely after
  2515.                                iteration_max iterations have been
  2516.                                done.
  2517.                             1: Cease displaying anything.
  2518.                             2: Show the first frame after the TERM
  2519.                                chunk.  If processing the fPRI chunk,
  2520.                                use a "cost" of 255.
  2521.  
  2522.                            This and the remaining fields must be
  2523.                            omitted if termination_action<=2, and
  2524.                            must be present otherwise.
  2525.  
  2526.             Delay:         4 bytes (unsigned integer).  Delay, in
  2527.                            ticks, before repeating the animation.
  2528.  
  2529.             Iteration max: 4 bytes (unsigned integer).  Maximum
  2530.                            number of times to repeat the animation.
  2531.  
  2532.          The loop created by processing a TERM must always be treated by
  2533.          the decoder as if it were a <user-discretion> loop, with
  2534.          iteration_min=1.
  2535.  
  2536.          The TERM chunk, if present, must appear either immediately
  2537.          after the MHDR chunk or immediately prior to a SEEK chunk.  The
  2538.          TERM chunk is not considered to be a part of any segment for
  2539.          the purpose of determining the copy-safe status of any chunk.
  2540.          Only one TERM chunk is permitted in a MNG datastream.
  2541.  
  2542.          Simple viewers and single-frame viewers can ignore the TERM
  2543.          chunk.  It has been made critical only so MNG editors will not
  2544.          inadvertently relocate it.
  2545.  
  2546.    4.4. SAVE and SEEK chunks
  2547.  
  2548.       The SAVE chunk marks a point in the datastream at which objects
  2549.       are "frozen" and other chunk information is "saved".  The SEEK
  2550.       chunk marks positions in the MNG datastream where a restart is
  2551.       possible, and where the decoder must restore the "saved"
  2552.       information, if they have jumped or skipped to a SEEK point.  They
  2553.       only need to restore information that they will use, e.g., a
  2554.       viewer that processes gAMA and global PLTE, but ignores iCCP and
  2555.       sPLT, need only restore the value of gamma and the global PLTE
  2556.       data from the prologue segment but not the values of the iCCP and
  2557.       sPLT data.
  2558.  
  2559.       Simple decoders that only read MNG datastreams sequentially can
  2560.       safely ignore the SAVE and SEEK chunks, although it is recommended
  2561.       that, for efficient use of memory, they at least mark existing
  2562.       objects as "frozen" when the SAVE chunk is processed and discard
  2563.       all "unfrozen" objects whenever the SEEK or empty DISC chunk is
  2564.       processed.
  2565.  
  2566.       4.4.1. SAVE Save information
  2567.  
  2568.          The SAVE chunk marks a point in the datastream at which objects
  2569.          are "frozen" and other chunk information is "saved"; a decoder
  2570.          skipping or jumping to a SEEK chunk must restore the "saved"
  2571.          chunk information if it has been redefined or discarded.  In
  2572.          addition, the SAVE chunk can contain an optional index to the
  2573.          MNG datastream.
  2574.  
  2575.          The SAVE chunk can be empty, or it can contain an index
  2576.          consisting of the following:
  2577.  
  2578.             Offset size: 1 byte (unsigned integer).
  2579.                            4: Offsets and nominal start times are
  2580.                               expressed as 32-bit integers.
  2581.                            8: Offsets and nominal start times are
  2582.                               expressed as 64-bit integers.
  2583.  
  2584.          plus zero or more of the following index entries:
  2585.  
  2586.             Entry type:  1 byte (unsigned integer).
  2587.                            0: Segment with nominal start time,
  2588.                               nominal layer number, and nominal
  2589.                               frame number.
  2590.                            1: Segment.
  2591.                            2: Subframe.
  2592.                            3: Exported image.
  2593.             Offset:     4 or 8 bytes (unsigned integer).  Omit if
  2594.                           entry_type > 1, set equal to zero
  2595.                           if the offset is unknown.
  2596.             Nominal start
  2597.               time:     4 or 8 bytes: (unsigned integer).  Start
  2598.                           time of the segment, measured in ticks
  2599.                           from the beginning of the animation,
  2600.                           assuming that all prior segments were
  2601.                           played as intended on an ideal player,
  2602.                           ignoring any fPRI chunks.  Omit if
  2603.                           entry_type > 0.
  2604.             Nominal layer
  2605.               number:   4 bytes (unsigned integer).  Sequence
  2606.                           number of the first layer in the segment,
  2607.                           assuming that all prior segments were
  2608.                           played as intended on an ideal player,
  2609.                           ignoring any fPRI chunks; the first
  2610.                           layer of the first segment being layer 0.
  2611.                           Omit if entry_type > 0.
  2612.             Nominal frame
  2613.               number:   4 bytes (unsigned integer).  Sequence
  2614.                           number of the first frame in the segment,
  2615.                           assuming that all prior segments were
  2616.                           played as intended on an ideal player,
  2617.                           ignoring any fPRI chunks; the first
  2618.                           frame of the first segment being frame 0.
  2619.                           Omit if entry_type > 0.
  2620.             Name:       1-79 bytes (Latin-1 text).  Omit for
  2621.                           unnamed segments.
  2622.             Separator:  1 byte (null) (must be omitted after
  2623.                           the final entry).
  2624.  
  2625.          The SAVE chunk must be present when the SEEK chunk is present.
  2626.          It appears after the set of chunks that define information that
  2627.          must be retained for the remainder of the datastream.  These
  2628.          chunks, collectively referred to as the prologue segment, are
  2629.          no different from chunks in other segments.  They can be chunks
  2630.          that define objects, or they can be chunks that define other
  2631.          information such as gAMA, cHRM, and sPLT.  If any chunks appear
  2632.          between the SAVE chunk and the first SEEK chunk, these chunks
  2633.          also form a part of the prologue segment, but their contents
  2634.          are lost when the SEEK chunk appears.
  2635.  
  2636.          Only one instance of the SAVE chunk is permitted in a MNG
  2637.          datastream.  It is not allowed anywhere after the first SEEK
  2638.          chunk.
  2639.  
  2640.          It is not permitted, at any point beyond the SAVE chunk, to
  2641.          modify or discard any object that was defined ahead of the SAVE
  2642.          chunk.
  2643.  
  2644.          An object appearing ahead of the SAVE chunk can be the subject
  2645.          of a CLON chunk.  If the clone is a partial clone, modifying it
  2646.          is not permitted, because this would also modify the object
  2647.          buffer that the original object points to.
  2648.  
  2649.          A chunk like gAMA that overwrites a single current value is
  2650.          permitted after the SAVE chunk, even if the chunk has appeared
  2651.          ahead of the SAVE chunk.  Decoders are responsible for saving a
  2652.          copy of the chunk data (in any convenient form) when the SAVE
  2653.          chunk is encountered and restoring it when skipping or jumping
  2654.          to a SEEK chunk.  If no instance of the chunk appeared ahead of
  2655.          the SAVE chunk, the decoder must restore the chunk data to its
  2656.          original "unknown" condition when it skips or jumps to a SEEK
  2657.          chunk.
  2658.  
  2659.          It is the encoder's responsibility, if it changes or discards
  2660.          any "saved" data, to restore it to its "saved" condition (or
  2661.          nullifying it, if it was unknown) prior to the end of the
  2662.          segment.  This makes it safe for simple decoders to ignore the
  2663.          SAVE/SEEK mechanism.
  2664.  
  2665.          Known chunks in this category include DEFI, FRAM, BACK, PLTE,
  2666.          cHRM, eXPI, fPRI, gAMA, iCCP, pHYs, and sRGB.
  2667.  
  2668.          In the case of chunks like sPLT that can occur multiple times,
  2669.          with different "purpose" fields, additional instances of the
  2670.          chunk are permitted after the SAVE chunk, but not with the same
  2671.          keyword as any instances that occurred ahead of the SAVE chunk.
  2672.          The decoder is required to forget such additional instances
  2673.          when it skips or jumps to a SEEK chunk, but it must retain
  2674.          those instances that were defined prior to the SAVE chunk.
  2675.          Encoders are required to nullify such additional instances
  2676.          prior to the end of the segment.  Known chunks in this category
  2677.          include only sPLT.
  2678.  
  2679.          If the optional index is present, every segment, whether named
  2680.          or not, except for the prologue segment, must be listed in it.
  2681.          All entries must appear in the index in the same order that
  2682.          they appear in the MNG datastream.  Only named images or
  2683.          subframes are permitted, and it is not an error to omit any or
  2684.          all named images or subframes from the index.
  2685.  
  2686.          Offsets are calculated from the first byte of the MNG 8-byte
  2687.          signature, which has offset=0.  This is true even if the MNG
  2688.          datastream happens to be embedded in some other file and the
  2689.          signature bytes are not actually present.
  2690.  
  2691.          Applications with direct access to the datastream can use the
  2692.          index to find segments, subframes, and exported images quickly.
  2693.          After processing the prologue segment, they can jump directly
  2694.          to any segment and then process the remaining datastream until
  2695.          the desired subframe, image, or time is found.  Applications
  2696.          that have only streaming access to the datastream can still use
  2697.          the index to decide whether to decode the chunks in a segment
  2698.          or to skip over them.
  2699.  
  2700.          Only one instance of the SAVE chunk is permitted in a MNG
  2701.          datastream.  If the SEEK chunk is present, the SAVE chunk must
  2702.          be present, prior to the first SEEK chunk.  The only chunks not
  2703.          allowed ahead of the SAVE chunk are the SEEK chunk and the MEND
  2704.          chunk.  The SAVE chunk must not appear inside a LOOP-ENDL pair.
  2705.  
  2706.       4.4.2. SEEK Seek point
  2707.  
  2708.          The SEEK chunk marks positions in the MNG datastream where a
  2709.          restart is possible, and where the decoder must restore certain
  2710.          information to the condition that existed when the SAVE chunk
  2711.          was processed, if it has skipped or jumped to the SEEK chunk.
  2712.  
  2713.          The SEEK can be empty, or it can contain a segment name.
  2714.  
  2715.             Segment name: 1-79 bytes (Latin-1 string).
  2716.  
  2717.          The segment name is optional.  It must follow the format of a
  2718.          tEXt keyword:  It must consist only of printable Latin-1
  2719.          characters and must not have leading or trailing blanks, but
  2720.          can have single embedded blanks.  There must be at least one
  2721.          and no more than 79 characters in the keyword.  There is no
  2722.          null byte terminator within the segment name, nor is there a
  2723.          separate null byte terminator.  Segment names are case-
  2724.          sensitive.  Use caution when printing or displaying keywords
  2725.          (Refer to Security considerations, below, Chapter 14). No
  2726.          specific use for the segment name is specified in this
  2727.          document, but applications can use the segment name for such
  2728.          purposes as constructing a menu of SEEK points for a slide-show
  2729.          viewer.  It can be included in the optional index that can
  2730.          appear in the SAVE chunk.  It is recommended that the same name
  2731.          not appear in any other SEEK chunk or in any FRAM or eXPI
  2732.          chunk.  Segment names should not begin with the case-
  2733.          insensitive strings "clock(", "frame(", or "frames(", which are
  2734.          reserved for use in URI queries and fragments.
  2735.  
  2736.          Applications must not use any information preceding the SEEK
  2737.          chunk, except for:
  2738.  
  2739.              * Data appearing in the MHDR chunk.
  2740.  
  2741.              * Anything appearing ahead of the SAVE chunk.
  2742.  
  2743.          When the SEEK chunk is encountered, the decoder can discard any
  2744.          objects appearing after the SAVE chunk, as though an empty DISC
  2745.          chunk were present.
  2746.  
  2747.          In addition to providing a mechanism for skipping frames or
  2748.          backspacing over frames, the SEEK chunk provides a means of
  2749.          dealing with a corrupted datastream.  The viewer would abandon
  2750.          processing and simply look for the next SEEK chunk before
  2751.          resuming.  Note that looking for a PNG IHDR chunk would not be
  2752.          sufficient because the PNG datastream might be inside a loop or
  2753.          a Delta-PNG datastream, or it might need data from preceding
  2754.          MOVE or CLIP chunks.
  2755.  
  2756.          When the SEEK chunk is encountered, a decoder must restore the
  2757.          information that it saved when it processed the SAVE chunk.
  2758.  
  2759.          Multiple instances of the SEEK chunk are permitted.  The SEEK
  2760.          chunk must not appear prior to the SAVE chunk.  The SAVE chunk
  2761.          must also be present if the SEEK chunk is present.  The SEEK
  2762.          must not appear between a LOOP chunk and its ENDL chunk.
  2763.  
  2764.    4.5. Ancillary MNG chunks
  2765.  
  2766.       This section describes ancillary MNG chunks.  MNG-compliant
  2767.       decoders are not required to recognize and process them.
  2768.  
  2769.       4.5.1. eXPI Export image
  2770.  
  2771.          The eXPI chunk takes a snapshot of a viewable object (either
  2772.          concrete or abstract), associates the name with that snapshot,
  2773.          and makes the name available to the "outside world" (like a
  2774.          scripting language).
  2775.  
  2776.          The chunk contains an object identifier and a name:
  2777.  
  2778.             Snapshot id:   2 bytes (unsigned nonzero integer).
  2779.             Snapshot name: 1-79 bytes (Latin-1 text).
  2780.  
  2781.          Note that the snapshot_name is associated with the snapshot,
  2782.          not with the snapshot_id nor its future contents; discarding
  2783.          the image identified by snapshot_id will not affect the
  2784.          snapshot.  The snapshot_name means nothing inside the scope of
  2785.          the MNG specification, except that it can be included in the
  2786.          optional index that can appear in the SAVE chunk.  If two eXPI
  2787.          chunks use the same name, it is the outside world's problem
  2788.          (and the outside world's prerogative to regard it as an error).
  2789.          It is recommended, however, that the snapshot_name not be the
  2790.          same as that appearing in any other eXPI chunk or in any FRAM
  2791.          or SEEK chunk.  A decoder that knows of no "outside world" can
  2792.          simply ignore the eXPI chunk.  This chunk could be used in MNG
  2793.          datastreams that define libraries of related images, rather
  2794.          than animations.
  2795.  
  2796.          Names beginning with the word "thumbnail" are reserved for
  2797.          snapshot images that are intended to make good icons for the
  2798.          MNG.  Thumbnail images are regular PNG or Delta-PNG images, but
  2799.          they would normally have smaller dimensions and fewer colors
  2800.          than the MNG frames.  They can be defined with the potential
  2801.          visibility field set to "invisible" if they are not intended to
  2802.          be shown as a part of the regular display.
  2803.  
  2804.          The snapshot_name string must follow the format of a tEXt
  2805.          keyword:  It must consist only of printable Latin-1 characters
  2806.          and must not have leading or trailing blanks, but can have
  2807.          single embedded blanks.  There must be at least one and no more
  2808.          than 79 characters in the keyword.  Keywords are case-
  2809.          sensitive.  There is no null byte terminator within the
  2810.          snapshot_name string, nor is there a separate null byte
  2811.          terminator.  Snapshot names should not begin with the case-
  2812.          insensitive strings "clock(", "frame(", or "frames(" which are
  2813.          reserved for use in URI queries and fragments.
  2814.  
  2815.          Multiple instances of the eXPI chunk are permitted in a MNG
  2816.          datastream, and they need not have different values of
  2817.          snapshot_id.
  2818.  
  2819.       4.5.2. fPRI Frame priority
  2820.  
  2821.          The fPRI chunk allows authors to assign a priority to a portion
  2822.          of the MNG datastream.  Decoders can decide whether or not to
  2823.          decode and process that part of the datastream based on its
  2824.          "priority" compared to some measure of "cost."
  2825.  
  2826.          The fPRI chunk contains two bytes:
  2827.  
  2828.             fPRI delta type:  1 byte (unsigned integer).
  2829.                                 0: Priority is given directly.
  2830.                                 1: Priority is determined by adding
  2831.                                    the fPRI data to the previous
  2832.                                    value, modulo 256.
  2833.  
  2834.             Priority or
  2835.               delta priority: 1 byte (signed integer).  Value to be
  2836.                                 assigned to subsequent chunks until
  2837.                                 another fPRI chunk is reached.
  2838.  
  2839.          While 256 distinct values of priority are possible, it is
  2840.          recommended that only the values 0 (low priority), 128 (medium
  2841.          priority), and 255 (high priority) be used.  Viewers that can
  2842.          only display a single image can look for one with priority=255
  2843.          and stop after displaying it.  If the datastream contains a
  2844.          large number of frames and includes periodic "initial" frames
  2845.          that do not contain Delta-PNG datastreams, each "initial" frame
  2846.          could be preceded by a fPRI with priority=128 and followed by
  2847.          one with priority=0, and the best representative initial frame
  2848.          could be preceded by a fPRI chunk with priority=255.  Then
  2849.          single-image viewers would just display the representative
  2850.          frame, slow viewers would display just the "initial" frames,
  2851.          and fast viewers would display everything.
  2852.  
  2853.          If a viewer has established a nonzero "cost," it must skip any
  2854.          portion of the datastream whose priority is less than that
  2855.          "cost."  The "cost" must be established prior to processing the
  2856.          proloque segment, and it cannot be changed unless the prologue
  2857.          segment is processed again according to the new "cost."
  2858.  
  2859.          The SAVE, SEEK, and MEND chunks always have priority=255;
  2860.          decoders must look for these chunks in addition to the fPRI
  2861.          chunk while skipping a low-priority portion of the datastream.
  2862.  
  2863.          It is not permissible for a portion of the datastream to depend
  2864.          on any portion of the datastream having a lower value, because
  2865.          a decoder might have skipped the lower value portion.  Use of
  2866.          the fPRI chunk is illustrated in Example 5 and Example 9.
  2867.  
  2868.          Viewers that care about the priority must assume priority=255
  2869.          for any portion of the MNG datastream that is processed prior
  2870.          to the first fPRI chunk.
  2871.  
  2872.          Multiple instances of the fPRI chunk are permitted.
  2873.  
  2874.       4.5.3. nEED Resources needed
  2875.  
  2876.          The nEED chunk can be used to specify needed resources, to
  2877.          provide a quick exit path for viewers that are not capable of
  2878.          displaying the MNG datastream.
  2879.  
  2880.          The nEED chunk contains a list of keywords that the decoder
  2881.          must recognize.  Keywords are typically private critical chunk
  2882.          names.
  2883.  
  2884.             Keyword:   1-79 bytes.
  2885.             Separator: 1 byte (null).
  2886.             ...etc...
  2887.  
  2888.          The nEED chunk should be placed early in the MNG datastream,
  2889.          preferably immediately after the MHDR chunk.
  2890.  
  2891.          The keywords are typically 4-character private critical chunk
  2892.          names, but they could be any string that a decoder is required
  2893.          to recognize.  No critical chunks defined in this specification
  2894.          or in the PNG specification should be named in a nEED chunk,
  2895.          because MNG-compliant decoders are required to recognize all of
  2896.          them, whether they appear in a nEED chunk or not.  The purpose
  2897.          of the nEED chunk is only to identify requirements that are
  2898.          above and beyond the requirements of this document and of the
  2899.          PNG specification.
  2900.  
  2901.          Each keyword string must follow the format of a tEXt keyword:
  2902.          It must consist only of printable Latin-1 characters and must
  2903.          not have leading or trailing blanks, but can have single
  2904.          embedded blanks.  There must be at least one and no more than
  2905.          79 characters in the keyword.  Keywords are case-sensitive.
  2906.          There is no null byte terminator within the keyword.  A null
  2907.          separator byte must appear after each keyword in the nEED chunk
  2908.          except for the last one.
  2909.  
  2910.          Decoders that do not recognize a chunk name or keyword in the
  2911.          list should abandon the MNG datastream or request user
  2912.          intervention.  The normal security precautions should be taken
  2913.          when displaying the keywords.
  2914.  
  2915.       4.5.4. pHYs Physical pixel size
  2916.  
  2917.          The MNG pHYs chunk is identical in syntax to the PNG pHYs
  2918.          chunk.  When the framing mode is 2 or 4 in the FRAM chunk, it
  2919.          applies to complete MNG layers and not to the individual images
  2920.          within them.  When the framing mode is 1 or 3, the MNG pHYs
  2921.          chunk provides a default value if the subsequent PNG datastream
  2922.          does not contain one.
  2923.  
  2924.          The MNG top-level pHYs chunk can be nullified by a subsequent
  2925.          empty pHYs chunk appearing in the MNG top level.
  2926.  
  2927.       4.5.5. PNG ancillary chunks
  2928.  
  2929.          The namespace for MNG chunk names is separate from that of PNG.
  2930.          Only those PNG chunks named in this paragraph are also defined
  2931.          at the MNG top level.  They have exactly the same syntax and
  2932.          semantics as when they appear in a PNG datastream:
  2933.  
  2934.              * -[iTXt]
  2935.  
  2936.              * tEXt
  2937.  
  2938.              * tIME Same format as in PNG.  Can appear at most once in
  2939.                the prologue segment (before the first SEEK chunk), and
  2940.                at most once per segment (between two consecutive SEEK
  2941.                chunks).  In the prologue it indicates the last time any
  2942.                part of the MNG was modified.  In a regular segment
  2943.                (between SEEK chunks), it indicates the last time that
  2944.                segment was modified.
  2945.  
  2946.              * zTXt
  2947.  
  2948.          A MNG editor that writes PNG datastreams should not include the
  2949.          top-level [iTXt,] tEXt, tIME, and zTXt chunks in the generated
  2950.          PNG datastreams.
  2951.  
  2952.          The following PNG chunks are also defined at the MNG top level.
  2953.          They provide default values to be used in case they are not
  2954.          provided in subsequent PNG datastreams.  Any of these chunks
  2955.          can be nullified by the appearance of a subsequent empty chunk
  2956.          with the same chunk name.  Such empty chunks are not legal PNG
  2957.          or JNG chunks and must only appear in the MNG top level.
  2958.  
  2959.              * cHRM
  2960.  
  2961.              * gAMA
  2962.  
  2963.              * iCCP
  2964.  
  2965.              * sRGB
  2966.  
  2967.          A MNG editor that writes PNG or JNG datastreams is expected to
  2968.          include the top-level cHRM, gAMA, iCCP, and sRGB chunks in the
  2969.          generated PNG or JNG datastreams, if the embedded image does
  2970.          not contain its own chunks that define the color space.  When
  2971.          it writes the sRGB chunk, it should write the gAMA chunk (and
  2972.          perhaps the cHRM chunk), in accordance with the PNG
  2973.          specification, even though no gAMA or cHRM chunk is present in
  2974.          the MNG datastream.
  2975.  
  2976.          The following PNG chunk is also defined at the MNG top level.
  2977.          It provides a value that takes precedence over those that might
  2978.          be provided in subsequent PNG or JNG datastreams and provides a
  2979.          value to be used when it is not provided in subsequent PNG or
  2980.          JNG datastreams:
  2981.  
  2982.              * sPLT (this chunk also takes precedence over the PLTE
  2983.                chunk in a subsequent PNG datastream when the PLTE and
  2984.                hIST chunks are being used as a suggested palette (i.e.,
  2985.                color_type != 3).  This chunk can appear for any color
  2986.                type.  There can be multiple sPLT chunks in a MNG
  2987.                datastream.  If a palette_name is repeated, the previous
  2988.                palette having the same palette_name is replaced.  It is
  2989.                not permitted, at the MNG top level, to redefine a
  2990.                palette after the SAVE chunk with the same palette_name
  2991.                as one that appears ahead of the SAVE chunk.  It is
  2992.                permitted, however, to define and redefine other palettes
  2993.                with other palette_name fields.  A single empty sPLT
  2994.                chunk can be used to nullify all sPLT chunks that have
  2995.                been previously defined in the MNG top level, except for
  2996.                those that appeared ahead of the SAVE chunk, when the
  2997.                SAVE chunk has been read.
  2998.  
  2999.                When a decoder needs to choose between a suggested
  3000.                palette defined at the MNG level and a suggested palette
  3001.                defined in the PNG datastream (either with the sPLT
  3002.                chunk, or with the PLTE/hIST chunks for grayscale or
  3003.                truecolor images), it should give preference to the
  3004.                palette from the MNG level, to avoid spurious layer-to-
  3005.                layer color changes.
  3006.  
  3007.                MNG editors that write PNG datastreams should ignore the
  3008.                sPLT and pHYs data from the MNG level and simply copy any
  3009.                sPLT and pHYs chunks appearing within the PNG
  3010.                datastreams.
  3011.  
  3012. 5. The JPEG Network Graphics (JNG) Format
  3013.  
  3014.    JNG (JPEG Network Graphics) is the lossy sub-format for MNG objects.
  3015.  
  3016.    Note: This specification depends on the PNG Portable Network Graphics
  3017.    specification [PNG].  The PNG specification is available at the PNG
  3018.    home page,
  3019.  
  3020.       http://www.cdrom.com/pub/png/
  3021.  
  3022.    A JNG datastream consists of a header chunk (JHDR), JDAT chunks that
  3023.    contain a complete JPEG datastream, and optionally, IDAT chunks that
  3024.    contain a PNG-encoded grayscale image that is to be used as an alpha
  3025.    mask.  Such a mask must have the same dimensions as the image itself.
  3026.    The JDAT and IDAT chunks can be interleaved.  Some of the PNG
  3027.    ancillary chunks are also recognized in JNG datastreams.
  3028.  
  3029.    While JNG is primarily intended for use as a sub-format within MNG, a
  3030.    single-image JNG datastream can be written in a standalone file.  If
  3031.    so, the first eight bytes of a JNG datastream are
  3032.  
  3033.       139 80 78 74 13 10 26 10
  3034.  
  3035.    (decimal) which is similar to the PNG signature with "\213 J N G"
  3036.    instead of "\211 P N G" in bytes 0-3.
  3037.  
  3038.    JNG is pronounced "Jing."
  3039.  
  3040.    5.1. JNG critical chunks
  3041.  
  3042.       This section specifies the critical chunks that are defined in the
  3043.       JNG format.
  3044.  
  3045.       5.1.1. JHDR JNG header
  3046.  
  3047.          The format of the JHDR chunk introduces a JNG datastream.  It
  3048.          contains:
  3049.  
  3050.             Width:      4 bytes (unsigned integer, range 0..65535).
  3051.             Height:     4 bytes (unsigned integer, range 0..65535).
  3052.             Color type: 1 byte
  3053.                           8: Gray (Y).
  3054.                          10: Color (YCbCr).
  3055.                          12: Gray-alpha (Y-alpha).
  3056.                          14: Color-alpha (YCbCr-alpha).
  3057.  
  3058.             JDAT sample
  3059.               depth:    1 byte
  3060.                           8: 8-bit samples and quantization tables.
  3061.                          12: 12-bit samples and quantization
  3062.                              tables.
  3063.                          20: 8-bit image followed by a 12-bit
  3064.                              image.
  3065.  
  3066.             JDAT compression
  3067.               method:   1 byte
  3068.                           8: ISO-10918-1 Huffman-coded baseline JPEG.
  3069.  
  3070.             JDAT interlace
  3071.               method:   1 byte.
  3072.                           0: Sequential JPEG, single scan.
  3073.                           8: Progressive JPEG.
  3074.  
  3075.             IDAT sample
  3076.               depth:    1 byte.
  3077.                           0, 1, 2, 4, 8, or 16.
  3078.  
  3079.             IDAT compression
  3080.               method:   1 byte.
  3081.                           0: Zlib DEFLATE.
  3082.  
  3083.             IDAT filter
  3084.               method:   1 byte.
  3085.                           0: Adaptive (see PNG spec).
  3086.  
  3087.             IDAT interlace
  3088.               method:   1 byte.
  3089.                           0: Not interlaced.
  3090.  
  3091.          The width, height, JDAT_sample_depth, JDAT_compression_method,
  3092.          and JDAT_interlace_method fields are redundant because
  3093.          equivalent information is also embedded in the JDAT datastream.
  3094.          They appear in the JHDR chunk for convenience.  Their values
  3095.          must be identical to their equivalents embedded in the JDAT
  3096.          chunk.  We use four bytes in the width and height fields for
  3097.          similarity to MNG and PNG, and to leave room for future
  3098.          expansion, even though two bytes would have been sufficient.
  3099.  
  3100.          When the color_type is 8 or 10 (no alpha channel), the last
  3101.          four bytes, which describe the IDAT data, must be set to zero.
  3102.          The IDAT_sample_depth must be nonzero when the alpha channel is
  3103.          present.
  3104.  
  3105.       5.1.2. JDAT JNG image data
  3106.  
  3107.          A JNG datastream must contain one or more JDAT chunks, whose
  3108.          data, when concatenated, forms a complete JNG JPEG datastream.
  3109.          JNG decoders are required to read all baseline JNG JPEG and
  3110.          eight-bit progressive JNG JPEG datastreams.  Twelve-bit
  3111.          capability is not required.
  3112.  
  3113.          JDAT chunks are like PNG IDAT chunks in that there may be
  3114.          multiple JDAT chunks, the data from which are concatenated to
  3115.          form a single datastream that can be sent to the decompressor.
  3116.          No chunks are permitted among the sequence of JDAT chunks,
  3117.          except for interleaved IDAT chunks.  The ordering requirements
  3118.          of other ancillary chunks are the same with respect to JDAT as
  3119.          they are in PNG with respect to the IDAT chunk.
  3120.  
  3121.          A JNG JPEG is a baseline, extended-sequential, or progressive
  3122.          JPEG as defined by JPEG Part 1 [ISO/IEC-10918-1].  JNG uses
  3123.          only JFIF-compatible [JFIF] component interpretations, and
  3124.          imposes a few additional restrictions that reflect limitations
  3125.          of many existing JPEG implementations.  In particular, only
  3126.          Huffman entropy coding is permitted.
  3127.  
  3128.          Actually, a JNG may contain two separate JNG JPEG datastreams
  3129.          (one eight-bit and one twelve-bit), each contained in a series
  3130.          of JDAT chunks, and separated by a JSEP chunk (see the JSEP
  3131.          chunk specification below, Paragraph 5.1.4).  Decoders that are
  3132.          unable to handle twelve-bit datastreams are allowed to display
  3133.          the eight-bit datastream instead, if one is present.
  3134.  
  3135.          The core of the JNG JPEG definition is baseline JNG JPEG, which
  3136.          is JPEG Part 1's definition of baseline JPEG further restricted
  3137.          by JFIF restrictions and JNG-specific restrictions.  JPEG,
  3138.          which is also defined in JPEG Part 1 and has JNG-specific
  3139.          restrictions.
  3140.  
  3141.              * Baseline JNG JPEG restrictions
  3142.  
  3143.                A baseline JPEG according to JPEG Part 1 is DCT-based
  3144.                (lossy) sequential JPEG, using 8-bit sample precision and
  3145.                Huffman entropy coding, with the following further
  3146.                restrictions:
  3147.  
  3148.                    * Quantization table precision must be 8 bits for
  3149.                      baseline JPEG.
  3150.  
  3151.                    * Huffman code tables can have table numbers 0 and 1
  3152.                      only.
  3153.  
  3154.                The SOF marker type for baseline JPEG is SOF0.
  3155.  
  3156.                JDAT datastreams must always follow "interchange JPEG"
  3157.                rules: all necessary quantization and Huffman tables must
  3158.                be included in the datastream; no tables can be omitted.
  3159.  
  3160.              * JFIF-compatible restrictions
  3161.  
  3162.                The image data is always stored left-to-right, top-to-
  3163.                bottom.
  3164.  
  3165.                The encoded data shall have one of the two color space
  3166.                interpretations allowed by the JFIF specification:
  3167.  
  3168.                    * Grayscale: a single component representing
  3169.                      luminance, ranging from 0 for black to 255 for
  3170.                      white (or 0 to 4095 when dealing with twelve-bit
  3171.                      data).  This component shall have JPEG component
  3172.                      identifier 1.
  3173.  
  3174.                    * YCbCr: three components representing luminance,
  3175.                      chroma blue, and chroma red, in that order.  The
  3176.                      components shall be assigned JPEG component
  3177.                      identifiers 1, 2, 3 respectively.  YCbCr is defined
  3178.                      as a linear transformation from RGB color space:
  3179.  
  3180.                         Y = Luma_red*R + Luma_green*G + Luma_blue*B
  3181.                         Cb = (B - Y) / (2 - 2*Luma_blue) + Half_scale
  3182.                         Cr = (R - Y) / (2 - 2*Luma_red)  + Half_scale
  3183.  
  3184.                      By convention, the luminance coefficients are
  3185.                      always those defined by CCIR Recommendation 601-1:
  3186.  
  3187.                         Luma_red   = 0.299
  3188.                         Luma_green = 0.587
  3189.                         Luma_blue  = 0.114
  3190.  
  3191.                      The constant Half_scale is 128 when dealing with
  3192.                      eight-bit data, 2048 for twelve-bit data.  With
  3193.                      these equations, Y, Cb, and Cr all have the same
  3194.                      range as R, G, and B: 0 to 255 for eight-bit data,
  3195.                      0 to 4095 for twelve-bit data.
  3196.  
  3197.                      The JFIF convention for YCbCr differs from typical
  3198.                      digital television practice in that no
  3199.                      headroom/footroom is reserved: the coefficient
  3200.                      values range over the full available 8 or 12 bits.
  3201.  
  3202.                      Intercomponent sample alignment shall be such that
  3203.                      the first (upper leftmost) samples of each
  3204.                      component share a common upper left corner
  3205.                      position.  This again differs from common digital
  3206.                      TV practice, in which the first samples share a
  3207.                      common center position.  The JFIF convention is
  3208.                      simpler to visualize: subsampled chroma samples
  3209.                      always cover an integral number of luminance sample
  3210.                      positions, whereas with co-centered alignment,
  3211.                      chroma samples only partially overlap some
  3212.                      luminance samples.
  3213.  
  3214.              * Additional JNG restrictions
  3215.  
  3216.                JNG imposes three additional restrictions not found in
  3217.                the text of either JPEG Part 1 or the JFIF specification:
  3218.  
  3219.                    * The sampling factors for YCbCr images must be one
  3220.                      of these sets:
  3221.  
  3222.                          * 1h1v,1h1v,1h1v (also called 4:4:4 or 1x1
  3223.                            sampling)
  3224.  
  3225.                          * 2h1v,1h1v,1h1v (also called 4:2:2 or 2x1
  3226.                            sampling)
  3227.  
  3228.                          * 2h2v,1h1v,1h1v (also called 4:2:0 or 2x2
  3229.                            sampling)
  3230.  
  3231.                          * 1h2v,1h1v,1h1v (also called 1x2 sampling)
  3232.  
  3233.                      In other words, the chroma components may be
  3234.                      downsampled 2:1 or 1:2 horizontally or vertically
  3235.                      relative to luminance, or they may be left full
  3236.                      size.  These four sampling ratios are the only ones
  3237.                      supported by a wide spectrum of implementations
  3238.                      (1x2 is relatively uncommon, and is usually the
  3239.                      result of a lossless rotation of a 2x1 sampling).
  3240.  
  3241.                      For grayscale images, the sampling factors are
  3242.                      irrelevant according to a strict reading of JPEG
  3243.                      Part 1.  Hence decoder authors should accept any
  3244.                      sampling factors for grayscale.  However, we
  3245.                      recommend that encoders always emit sampling
  3246.                      factors 1h1v for grayscale, since some decoders
  3247.                      have been observed to malfunction when presented
  3248.                      with other sampling factors.
  3249.  
  3250.                    * There must be only one scan in an image: that is,
  3251.                      YCbCr images must be fully interleaved.  There is
  3252.                      little advantage to be gained by encoding a
  3253.                      baseline image in multiple scans, and many baseline
  3254.                      decoders do not support multiple scans at all.
  3255.  
  3256.                    * The DNL (Define Number of Lines) marker is
  3257.                      prohibited.  The image height must always be
  3258.                      specified accurately in the SOFn marker and in the
  3259.                      JHDR chunk.
  3260.  
  3261.              * Recommended progressive JPEG subset
  3262.  
  3263.                For JNG progressive JPEG datastreams, the JPEG process is
  3264.                progressive Huffman coding (SOF marker type SOF2) rather
  3265.                than baseline (SOF0).  All JNG-compliant decoders must
  3266.                support full progression, including both spectral-
  3267.                selection and successive-approximation modes, with any
  3268.                sequence of scan progression parameters allowed by the
  3269.                JPEG Part 1 standard.
  3270.  
  3271.                Otherwise, all the restrictions listed above apply,
  3272.                except these:
  3273.  
  3274.                    * Multiple-scan support is obviously required for
  3275.                      progressive JPEG.
  3276.  
  3277.                    * Huffman table numbers up to 3 (the full JPEG limit)
  3278.                      may be used, since the baseline two-table limit is
  3279.                      unlikely to be needed by any decoder that can
  3280.                      handle progressive JPEG.
  3281.  
  3282.                We require full progression support since relatively
  3283.                little code savings can be achieved by subsetting the
  3284.                JPEG progression features.  In particular, successive
  3285.                approximation offers significant gains in the visual
  3286.                quality of early scans.  Omitting successive-
  3287.                approximation support from a decoder does not save nearly
  3288.                enough code to justify restricting JNG progressive
  3289.                encoders to spectral selection only.
  3290.  
  3291.                No particular progressive scan sequence is specified or
  3292.                recommended by this specification.  Not enough experience
  3293.                has been gained with progressive JPEG to warrant making
  3294.                such a recommendation.  To allow for future
  3295.                experimentation with scan sequences, decoders are
  3296.                expected to handle any JPEG-legal sequence.  Again, the
  3297.                code savings that might be had by making restrictive
  3298.                assumptions are too small to justify a limitation.
  3299.  
  3300.                When the JSEP chunk is present, both images must be
  3301.                progressive if one of them is progressive.
  3302.  
  3303.              * Recommended 12-bit JPEG subset
  3304.  
  3305.                JNG JPEGs may optionally use 12-bit sample precision as
  3306.                defined in JPEG Part 1.
  3307.  
  3308.                For a sequential image, the SOF marker type must be SOF1
  3309.                (extended sequential) not SOF0, and the baseline
  3310.                restriction of two Huffman tables is removed.  Also, the
  3311.                encoder may use either 8-bit or 16-bit quantization
  3312.                tables.  All other JNG baseline restrictions still apply.
  3313.                It is recommended that JNG encoders not use extended-
  3314.                sequential mode except to encode 12-bit data.
  3315.  
  3316.                For a progressive image, the only difference between 8-
  3317.                bit and 12-bit modes is that the sample precision is 12
  3318.                bits and the encoder may use either 8-bit or 16-bit
  3319.                quantization tables.  All other JNG restrictions still
  3320.                apply.
  3321.  
  3322.       5.1.3. IDAT JNG alpha data
  3323.  
  3324.          This chunk is exactly like the IDAT chunk in a PNG grayscale
  3325.          image, except that it is interpreted as an alpha mask to be
  3326.          applied to the image data from the JDAT chunks.  The alpha
  3327.          channel, if present, can have sample depths 1, 2, 4, 8, or 16.
  3328.          The IDAT chunks can be interleaved with the JDAT chunks (see
  3329.          Recommendations for Encoders:  JNG interleaving below).  No
  3330.          other chunk type can appear among the sequence of IDAT and JDAT
  3331.          chunks.  No other chunk type can appear between the sequences
  3332.          of IDAT and JDAT chunks when they are not interleaved.  The
  3333.          samples in the IDAT must be presented in noninterlaced order,
  3334.          left to right, top to bottom.  As in PNG, zero means fully
  3335.          transparent and 2^IDAT_sample_depth-1 means fully opaque.
  3336.  
  3337.          The IDAT chunks must precede the JSEP chunk, if the JSEP chunk
  3338.          is present.  Minimal viewers that ignore the twelve-bit JDAT
  3339.          chunks must read the IDAT chunks and apply the alpha samples to
  3340.          the eight-bit image that is contained in the JDAT chunks that
  3341.          precede the JSEP chunk.  Viewers that skip the eight-bit JDAT
  3342.          chunks must read the IDAT chunks that precede the JSEP chunk
  3343.          and apply the alpha samples to the twelve-bit image that is
  3344.          contained in the JDAT chunks that follow the JSEP chunk.
  3345.  
  3346.          The JNG IEND chunk is identical to its counterpart in PNG.  Its
  3347.          data length is zero, and it serves to mark the end of the JNG
  3348.          datastream.
  3349.  
  3350.       5.1.4. JSEP 8-bit/12-bit image separator
  3351.  
  3352.          The JSEP chunk is empty.
  3353.  
  3354.          A JSEP chunk must appear between the JDAT chunks of an eight-
  3355.          bit datastream and those of a twelve-bit datastream, when
  3356.          JDAT_sample_depth=20 in the JHDR chunk.  The eight-bit
  3357.          datastream must appear first.  Both images must have the same
  3358.          width, height, color type, compression method, and interlace
  3359.          type.  Viewers can choose to display one or the other image,
  3360.          but not both.
  3361.  
  3362.    5.2. JNG ancillary chunks
  3363.  
  3364.       Some PNG ancillary chunks can also appear in JNG datastreams, and
  3365.       are used for the same purposes as described in the PNG
  3366.       specification:
  3367.  
  3368.       If the bKGD chunk is present, it must be written as if it were
  3369.       written for a PNG datastream with sample_depth=8.  It has one 2-
  3370.       byte entry for grayscale JNGs and three 2-byte entries for color
  3371.       JNGs.  The first (most significant) byte of each entry must be 0.
  3372.  
  3373.       The following chunks have exactly the same meaning and have the
  3374.       same format as given in the PNG specification: cHRM, gAMA, iCCP,
  3375.       sRGB, pHYs, oFFs, [iTXt,] tEXt, tIME, and zTXt.
  3376.  
  3377.       The PNG PLTE, hIST, pCAL, sBIT, and tRNS chunks are not defined in
  3378.       JNG.
  3379.  
  3380.       When cHRM, gAMA, iCCP, or sRGB are present, they provide
  3381.       information about the color space of the decoded JDAT image, and
  3382.       they have no effect on the decoded alpha samples from the IDAT
  3383.       chunks.  Any viewer that processes the gAMA chunk must also
  3384.       recognize and process the sRGB chunk.  It can treat it as if it
  3385.       were a gAMA chunk containing the value .45455 and it can ignore
  3386.       its "intent" field.
  3387.  
  3388.       The chunk copying and ordering rules for JNG are the same as those
  3389.       in PNG, except for the fact that JDAT and IDAT chunks can be
  3390.       interleaved.
  3391.  
  3392. 6. The Delta-PNG Format
  3393.  
  3394.    A Delta-PNG datastream describes a single image, by giving the
  3395.    changes from a previous PNG (Portable Network Graphics), a JNG (JPEG
  3396.    Network Graphics), or another Delta-PNG image.
  3397.  
  3398.    No provision is made in this specification for storing a Delta-PNG
  3399.    datastream as a standalone file.  A Delta-PNG datastream will
  3400.    normally be found as a component of a MNG datastream.  Applications
  3401.    that need to store a Delta-PNG datastream separately should use a
  3402.    different file signature and filename extension, or they can wrap it
  3403.    in a MNG datastream consisting of the MNG signature, the MHDR chunk,
  3404.    a BASI chunk with the appropriate dimensions and an IEND chunk, the
  3405.    Delta-PNG datastream, and the MEND chunk.
  3406.  
  3407.    The decoder must have available a parent (decoded) object from which
  3408.    the original chunk data is known.  The parent object can be the
  3409.    result of decoding a PNG, another Delta-PNG datastream, or it could
  3410.    have been generated by a PNG-like datastream introduced by a BASI
  3411.    chunk.
  3412.  
  3413.    The child image is always of the same basic type (at present only PNG
  3414.    and JNG are defined) as the parent object.  The child is always a
  3415.    viewable image even if the parent is not.
  3416.  
  3417.    The decoder must not have modified the pixel data in the parent
  3418.    object by applying output transformations such as gAMA or cHRM, or by
  3419.    compositing the image against a background.  Instead, the decoder
  3420.    must make available to the Delta-PNG decoder the unmodified pixel
  3421.    data along with the values for the gAMA, cHRM, and any other
  3422.    recognized chunks from the parent object datastream.
  3423.  
  3424.    A Delta-PNG datastream consists of a DHDR and IEND enclosing other
  3425.    optional chunks (if there are no other chunks, the decoder simply
  3426.    copies the parent image, and displays it if its do_not_show=0).
  3427.  
  3428.    Chunk structure (length, name, CRC) and the chunk-naming system are
  3429.    identical to those defined in the PNG specification.  Definitions of
  3430.    compression_type, filter_type, and interlace_type are also the same
  3431.    as defined in the PNG specification.
  3432.  
  3433.    6.1. Delta-PNG critical chunks
  3434.  
  3435.       This section describes critical Delta-PNG chunks.  MNG-compliant
  3436.       decoders must recognize and process them.
  3437.  
  3438.       6.1.1. DHDR Delta-PNG datastream header
  3439.  
  3440.          The DHDR chunk introduces a Delta-PNG datastream.  Subsequent
  3441.          chunks, through the next IEND chunk, are interpreted according
  3442.          to the Delta-PNG format.
  3443.  
  3444.          The DHDR chunk can contain 4, 12, or 20 bytes:
  3445.  
  3446.             Object id:    2 bytes (nonzero unsigned integer).
  3447.                             Identifies the parent object from which
  3448.                             changes will be made.  This is also the
  3449.                             object_id of the child image, which can
  3450.                             be used as the parent image for a
  3451.                             subsequent Delta-PNG.
  3452.  
  3453.             Image type:   1 byte.
  3454.  
  3455.                             0: Image type is unspecified.  An IHDR,
  3456.                                JHDR, IPNG, or IJNG chunk must be
  3457.                                present.  If JHDR or IJNG is present,
  3458.                                delta_type must not be 1, 3, 4, or 6.
  3459.  
  3460.                             1: Image type is PNG.  IHDR and IPNG can
  3461.                                be omitted under certain conditions.
  3462.  
  3463.                             2: Image type is JNG.  JHDR and IJNG can
  3464.                                be omitted under certain conditions.
  3465.                                Delta_type must not be 1, 3, 4, or 6.
  3466.  
  3467.             Delta type:   1 byte.
  3468.  
  3469.                             0: Entire image replacement.
  3470.  
  3471.                             1: Block pixel addition, by samples,
  3472.                                modulo 2^sample_depth.
  3473.  
  3474.                             2: Block alpha addition, by samples,
  3475.                                modulo 2^sample_depth.  Regardless of
  3476.                                the color type of the parent image,
  3477.                                the IDAT data are written as a
  3478.                                grayscale image (color type 0), but
  3479.                                the decoded samples are used as deltas
  3480.                                to the alpha samples in the parent
  3481.                                image.  The parent image must have
  3482.                                (or be promoted to via the PROM chunk)
  3483.                                a color type that has an alpha channel.
  3484.  
  3485.                             3: Block color addition.  Similar to
  3486.                                delta type 1 except that only the
  3487.                                color channels are updated even when
  3488.                                the parent has an alpha channel.
  3489.  
  3490.                             4: Block pixel replacement.
  3491.  
  3492.                             5: Block alpha replacement.
  3493.  
  3494.                             6: Block color replacement.
  3495.  
  3496.                             7: No change to pixel data.
  3497.  
  3498.             Block width:  4 bytes (unsigned integer).  Omit when
  3499.                             delta_type=7.
  3500.  
  3501.             Block height: 4 bytes (unsigned integer).  Omit when
  3502.                             delta_type=7.
  3503.  
  3504.             Block
  3505.               X_location: 4 bytes (unsigned integer),
  3506.                             measured in pixels from the left edge
  3507.                             of the parent object.  Omit when
  3508.                             delta_type=0 or when delta_type=7.
  3509.  
  3510.             Block
  3511.               Y_location: 4 bytes (unsigned integer),
  3512.                             measured in pixels from the top edge
  3513.                             of the parent object.  Omit when
  3514.                             delta_type=0 or when delta_type=7.
  3515.  
  3516.          The object_id must identify an existing object, and the object
  3517.          must be a "concrete" object, i.e., it must have the property
  3518.          concrete_flag=1.
  3519.  
  3520.          The image_type, whether given explicitly as 1 or 2 or implied
  3521.          by the presence of an IHDR, IPNG, JHDR, or IJNG chunk, must be
  3522.          the same as that of the parent object.
  3523.  
  3524.          When delta_type=0, the width and height of the child image are
  3525.          given by the block_width and block_height fields.
  3526.  
  3527.          For all other values of delta_type, the width and height of the
  3528.          child image are inherited from the parent object.
  3529.  
  3530.          When delta_type=1-6, the block_width and block_height fields
  3531.          give the size of the block of pixels to be modified or
  3532.          replaced, and block_X_location and block_Y_location give its
  3533.          location with respect to the top left corner of the parent
  3534.          object.  The block must fall entirely within the parent object.
  3535.  
  3536.          Entire image replacement
  3537.             When delta_type=0 in the DHDR chunk, the pixel data in the
  3538.             IDAT chunks represent a completely new image, with
  3539.             dimensions given by the block_width and block_height fields
  3540.             of the DHDR chunk.  Data from chunks other than IDAT or JDAT
  3541.             can be inherited from the parent object.  If the IHDR or
  3542.             JHDR chunk is present, all of its fields except width and
  3543.             height (which must be ignored by decoders) provide new
  3544.             values that are inherited by subsequent objects.  The "pixel
  3545.             sample depth" and "alpha sample depth" are also reset equal
  3546.             to the IHDR sample_depth value (in the case of a JNG object,
  3547.             the new "alpha sample depth" is taken from the JHDR
  3548.             IDAT_sample_depth field).  If the IHDR or JHDR chunk is not
  3549.             present, the IDAT chunks are decoded according to the parent
  3550.             object's sample depth, and not according to the "pixel
  3551.             sample depth" or "alpha sample depth" which are used for
  3552.             decoding the IDAT chunks in subsequent Delta-PNG datastreams
  3553.             when delta_type is nonzero.
  3554.  
  3555.          Block pixel addition
  3556.             When delta_type=1 in the DHDR chunk, the pixel data in the
  3557.             IDAT chunks represent deltas from the pixel data in a parent
  3558.             object known to the decoder, including the alpha channel, if
  3559.             the parent object has an alpha channel.
  3560.  
  3561.             The IDAT chunk data contains a filtered and perhaps
  3562.             interlaced set of delta pixel samples.  The delta samples
  3563.             are presented in the order specified by interlace_method,
  3564.             filtered according to the filter_method and compressed
  3565.             according to the compression_method given in the IHDR chunk.
  3566.             The pixel data includes alpha samples, if the parent object
  3567.             has an alpha channel.
  3568.  
  3569.             An encoder calculates the delta sample values from the
  3570.             samples in the parent object and those in the child image by
  3571.             subtracting the parent object samples from the child image
  3572.             samples, modulo 2^sample_depth.  When decoding the IDAT
  3573.             chunk, the child image bytes are obtained by adding the
  3574.             delta bytes to the parent object bytes, modulo
  3575.             2^sample_depth.  This is similar in operation to the PNG SUB
  3576.             filter, except that it works by samples instead of by bytes.
  3577.  
  3578.             Only the pixels in the block defined by the block location
  3579.             and dimensions given in the DHDR chunk are changed.  The
  3580.             size of the IDAT data must correspond exactly to this
  3581.             rectangle.
  3582.  
  3583.             When the parent object has color_type=3, the deltas are
  3584.             differences between index values, not between color samples.
  3585.  
  3586.             The color type must match that of the parent, except that
  3587.             when the parent has PNG color_type=3, the delta can have
  3588.             color_type=0, and vice versa, since the contents of the IDAT
  3589.             chunks of either color type are indistinguishable.
  3590.  
  3591.             If the pixel_sample_depth does not match the
  3592.             object_sample_depth, the delta must be scaled to the
  3593.             object_sample_depth using the zero-fill method described in
  3594.             the PNG specification, before performing the pixel addition.
  3595.  
  3596.             When the IHDR chunk is present, the compression method,
  3597.             filter method, and interlace method need not be the same as
  3598.             those of the parent object.  The new values are used in
  3599.             decoding the IDAT data, and the new values are inherited by
  3600.             the child object.
  3601.  
  3602.             Whenever the sample depth differs from that of the parent
  3603.             object, the resulting object inherits the original value
  3604.             from the parent.  The value from the IHDR chunk is only used
  3605.             for decoding the IDAT data in this and subsequent Delta-
  3606.             PNGs.  Implicit in this is the requirement for decoders to
  3607.             remember in the object buffer not only the sample depth of
  3608.             the object but (separately) the "pixel sample depth" for use
  3609.             in decoding the IDAT chunks of subsequent Delta-PNG
  3610.             datastreams that do not contain their own IHDR chunk.
  3611.  
  3612.          Block alpha addition
  3613.             When delta_type=2 in the DHDR chunk, the pixel data in the
  3614.             IDAT chunks represent deltas from the alpha data in a parent
  3615.             object known to the decoder.  The color samples are not
  3616.             changed, and the updated alpha samples are calculated in the
  3617.             same manner as the updated pixel samples are calculated when
  3618.             delta_type=1.
  3619.  
  3620.             The color_type is 0 (grayscale), regardless of the
  3621.             color_type of the parent object.  The parent object must
  3622.             have an alpha channel or must have been promoted to a type
  3623.             that has an alpha channel.  The compression method, filter
  3624.             method, and interlace method need not be the same.  If they
  3625.             are different, the child object inherits the new values, and
  3626.             the new values will be used in decoding the data in any
  3627.             subsequent IDAT chunks.
  3628.  
  3629.             The sample_depth value from the IHDR chunk is interpreted as
  3630.             a new value of alpha_sample_depth and is only used for
  3631.             decoding the IDAT data in this and subsequent Delta-PNGs.
  3632.             Implicit in this is the requirement for decoders to remember
  3633.             in the object buffer not only the sample depth of the object
  3634.             but (separately) the alpha_sample_depth for use in decoding
  3635.             the IDAT chunks in any subsequent Delta-PNG datastreams.
  3636.  
  3637.             If the alpha_sample_depth does not match the
  3638.             object_sample_depth, the delta must be scaled to the
  3639.             object_sample_depth, using the zero-fill method described in
  3640.             the PNG specification, before performing the pixel
  3641.             subtraction.
  3642.  
  3643.          Block color addition
  3644.             delta_type=3 is similar to delta_type=1 except that the
  3645.             alpha channel is not included in the IDAT pixels; the alpha
  3646.             channel is inherited from the parent object.  The color type
  3647.             of the parent must be one that has an alpha channel (4 or 6)
  3648.             and the color type of the delta must be the corresponding
  3649.             color type (0 or 2) that does not have an alpha channel.
  3650.  
  3651.          Block pixel replacement
  3652.             When delta_type=4 in the DHDR chunk, the pixel data in the
  3653.             IDAT chunks represent replacement values for the pixel
  3654.             samples in the rectangle given by the block location and
  3655.             dimension fields in the DHDR chunk, including the alpha
  3656.             channel, if the parent object has an alpha channel.
  3657.  
  3658.             If the pixel_sample_depth does not match the
  3659.             object_sample_depth, the pixel data must be linearly scaled
  3660.             to the object_sample_depth before making the replacements.
  3661.             This can be accomplished by using the left bit replication
  3662.             method described in the PNG specification, or by the right
  3663.             shift method in the unlikely event that the
  3664.             pixel_sample_depth is larger than the object_sample_depth.
  3665.  
  3666.             The color type must match that of the parent, except for the
  3667.             cases mentioned for delta type 1, above.
  3668.  
  3669.          Block alpha replacement
  3670.             When delta_type=5 in the DHDR chunk, the pixel data in the
  3671.             IDAT chunks represent replacement values of the alpha
  3672.             samples in the rectangle given by the block location and
  3673.             dimension fields in the DHDR chunk.  The sample depth of the
  3674.             data (i.e. the "alpha sample depth") need not match the
  3675.             sample depth of the parent object, and color_type is 0
  3676.             (grayscale), regardless of the color_type of the parent
  3677.             object.  If the sample depths differ, the samples must be
  3678.             scaled to the object_sample_depth by linear scaling, which
  3679.             can be achieved with the left bit replication method or
  3680.             right shift method described in the PNG specification,
  3681.             depending on whether the alpha_sample_depth is larger or
  3682.             smaller than the object_sample_depth.  The parent object
  3683.             must have an alpha channel or must have been promoted to a
  3684.             type that has an alpha channel.  The compression method,
  3685.             filter method, and interlace method need not be the same.
  3686.             If they differ, the child object inherits the new values.
  3687.  
  3688.          Block color replacement
  3689.             delta_type=6 is similar to delta_type=4 except that the
  3690.             alpha channel is not included in the IDAT pixels; the alpha
  3691.             channel is inherited from the parent object.  The color type
  3692.             of the parent must be one that has an alpha channel (4 or 6)
  3693.             and the color type of the delta must be the corresponding
  3694.             color type (0 or 2) that does not have an alpha channel.
  3695.  
  3696.          No change to pixel data
  3697.             When delta_type=7 in the DHDR chunk, there is no change to
  3698.             the pixel data, and it is an error for IDAT, or JDAT to
  3699.             appear.  If the IHDR or JHDR chunk appears, the width,
  3700.             height, and color_type fields are ignored, the PNG sample
  3701.             depth (or JNG IDAT_sample_depth) is used to update the
  3702.             pixel_sample_depth and alpha_sample_depth, and the data in
  3703.             the remaining fields are inherited by the child object.
  3704.  
  3705.          Pixel sample depth, alpha sample depth
  3706.             As mentioned above, the sample depth of the deltas is not
  3707.             necessarily the same as that of the object, when delta_type
  3708.             != 0.  The decoder needs to remember the pixel_sample_depth
  3709.             and alpha_sample_depth to use with each object.  They are
  3710.             initialized to the sample_depth value from the IHDR chunk
  3711.             that appears when the object is first created but can be
  3712.             changed by the appearance of the IHDR chunk in a Delta-PNG
  3713.             datastream that has delta_type != 0.  If the object is a JNG
  3714.             image, they are initialized from the value of
  3715.             IDAT_sample_depth from the original JHDR chunk, and can be
  3716.             changed by the appearance of the JHDR chunk in a Delta-PNG
  3717.             datastream that has delta_type != 0.
  3718.  
  3719.       6.1.2. IEND End of Delta-PNG datastream
  3720.  
  3721.          End of Delta-PNG datastream.  An IEND chunk must be present for
  3722.          each DHDR chunk in a MNG datastream.
  3723.  
  3724.          The IEND chunk is empty.
  3725.  
  3726.       6.1.3. PROM Promotion of parent object
  3727.  
  3728.          This chunk is used to "promote" a parent object to a higher bit
  3729.          depth or to add an alpha channel, before making changes to it.
  3730.  
  3731.             New color type:   1 byte.
  3732.             New sample depth: 1 byte.
  3733.             Fill method:      1 byte.
  3734.                                 0: Left-bit-replication
  3735.                                 1: Zero fill
  3736.  
  3737.          When a decoder encounters the PROM chunk, it must promote the
  3738.          pixel data.  The cases are:
  3739.  
  3740.          G -> GA (color_type 0 -> 4)
  3741.             Don't change the gray values.  Set all the alpha values to
  3742.             fully opaque, except for pixels marked transparent by cheap
  3743.             transparency--set their alpha values to fully transparent.
  3744.             Discard the cheap transparency information (the PNG tRNS
  3745.             chunk data).
  3746.  
  3747.          RGB -> RBGA (color_type 2 -> 6)
  3748.             Don't change the RGB values.  Convert the tRNS chunk data to
  3749.             alpha values as in the G -> GA promotion.
  3750.  
  3751.          G -> RGB (color_type 0 -> 2)
  3752.             Set R, G, and B equal to the gray value.  Apply the same
  3753.             operation to the cheap transparency data (if any).  Expand
  3754.             any bKGD or sBIT data.
  3755.  
  3756.          GA -> RGBA (color_type 4 -> 6)
  3757.             Set R, G, and B equal to the gray value.  Don't change the
  3758.             alpha values.  Expand any bKGD or sBIT data.
  3759.  
  3760.          G -> RGBA (color_type 0 -> 6)
  3761.             Set R, G, and B equal to the gray value.  Handle
  3762.             transparency as in the G -> GA promotion.  Expand any bKGD
  3763.             or sBIT data.
  3764.  
  3765.          indexed -> RGB (color_type 3 -> 2)
  3766.             Set R, G, and B according to the palette entry corresponding
  3767.             to the index.  Discard the cheap transparency information
  3768.             (if any).  Expand any bKGD or sBIT data.
  3769.  
  3770.          indexed -> RGBA (color_type 3 -> 6)
  3771.             Set R, G, and B as in indexed -> RGB.  Set the alpha value
  3772.             according to the cheap transparency information (if any).
  3773.             Discard the cheap transparency information.  Expand any bKGD
  3774.             or sBIT data.
  3775.  
  3776.          JNG-G -> JNG-C (JNG color_type 8 -> 10)
  3777.             Expand the gray values to color.  Expand any bKGD data.
  3778.  
  3779.          JNG-G -> JNG-GA (JNG color_type 8 -> 12)
  3780.             Don't change the gray values.  Set all the alpha values to
  3781.             fully opaque.  The given sample depth is the new sample
  3782.             depth for the alpha channel.
  3783.  
  3784.          JNG-G -> JNG-CA (JNG color_type 8 -> 14)
  3785.             Expand the gray values to color.  Set all the alpha values
  3786.             to fully opaque.  The given sample depth is the new sample
  3787.             depth for the alpha channel.  Expand any bKGD data.
  3788.  
  3789.          JNG-C -> JNG-CA (JNG color_type 10 -> 14)
  3790.             Don't change the color values.  Set all the alpha values to
  3791.             fully opaque.  The given sample depth is the new sample
  3792.             depth for the alpha channel.
  3793.  
  3794.          JNG-GA -> JNG-CA (JNG color_type 12 -> 14)
  3795.             Expand the gray values to color.  Don't change the alpha
  3796.             values.  Expand any bKGD data.
  3797.  
  3798.          No change in color_type
  3799.             Only the sample depth is changed.  The new sample depth must
  3800.             be larger than the old one.
  3801.  
  3802.          If the sample depth has been changed, the sample values must be
  3803.          widened.  The decoder must use left-bit-replication or zero-
  3804.          fill according to the specified fill_method to fill the
  3805.          additional bits of each sample.  If cheap transparency
  3806.          information is present in a grayscale or truecolor object, its
  3807.          sample values must also be widened in the same manner.  If the
  3808.          image type is JNG, then the new sample depth refers to the
  3809.          IDAT_sample_depth and only the alpha channel is affected, if
  3810.          one is present.  If the color_type has been promoted from
  3811.          indexed-color, the original bit depth is always considered to
  3812.          be 8.  See the PNG specification [PNG] for further information
  3813.          on these filling methods.
  3814.  
  3815.          If the basis object contains data from the PNG bKGD chunk, this
  3816.          data must be promoted as well.  If a grayscale object is being
  3817.          promoted to a truecolor object, the background RGB samples are
  3818.          set equal to the grayscale background sample.  If the bit depth
  3819.          has been changed, the background samples are widened in
  3820.          accordance with the specified fill_method.  If the basis object
  3821.          is a JNG, the bKGD chunk is not affected.
  3822.  
  3823.          If the basis object contains data from the PNG sBIT chunk, this
  3824.          data must also be promoted.  If a grayscale object is being
  3825.          promoted to a truecolor object, the new RGB bytes are set equal
  3826.          to the grayscale byte.  When an alpha channel is added, the
  3827.          alpha byte is set equal to the sample depth of the basis image.
  3828.          If the sample depth has been changed, the sBIT bytes do not
  3829.          change.
  3830.  
  3831.          The PROM chunk is not permitted to "demote" a parent object to
  3832.          an object with a lesser bit depth or from one with an alpha
  3833.          channel to one without an alpha channel.
  3834.  
  3835.          The PROM chunk must appear ahead of the IHDR chunk, if IHDR is
  3836.          present, and ahead of any chunks that would have followed IHDR,
  3837.          if IHDR is omitted.
  3838.  
  3839.       6.1.4. IHDR PNG image header
  3840.  
  3841.          Inside a Delta-PNG datastream, the IHDR chunk introduces an
  3842.          incomplete PNG (Portable Network Graphics) datastream.  The
  3843.          parent object must be a PNG or PNG-based Delta-PNG.  The
  3844.          datastream can be introduced by a complete PNG IHDR chunk or by
  3845.          an IPNG chunk, which is empty.
  3846.  
  3847.          If the IHDR chunk is present, its width, and height fields are
  3848.          ignored.  The values for these parameters are inherited from
  3849.          the parent object or from the PROM chunk.  different from those
  3850.          of the parent, they are only used for decoding the data in the
  3851.          IDAT chunks, and the child object inherits the original values
  3852.          from the parent.
  3853.  
  3854.          The sample_depth, color_type, compression_method,
  3855.          interlace_type, and filter_type fields, if different from those
  3856.          of the parent object, are used in decoding any subsequent IDAT
  3857.          chunks, and the new values will be inherited by any subsequent
  3858.          image that uses this object as its parent.  These do not change
  3859.          the sample_depth and color_type of the object itself; those can
  3860.          only be changed by using the PROM chunk or by using
  3861.          delta_type=0.
  3862.  
  3863.          See the PNG specification for the format of the PNG chunks.
  3864.          The PNG datastream must contain at least IHDR and IEND (whether
  3865.          actually present in the datastream or omitted and included by
  3866.          implication, as described below), but can inherit other chunk
  3867.          data from the parent object.  Except for IDAT and PPLT, any
  3868.          chunks appearing between IHDR and IEND are always treated as
  3869.          replacements or additions and not as deltas.
  3870.  
  3871.       6.1.5. IPNG Incomplete PNG
  3872.  
  3873.          The IPNG chunk is empty.
  3874.  
  3875.          The IPNG chunk can be used instead of the IHDR chunk if the
  3876.          IHDR chunk is not needed for resetting the value of
  3877.          compression_method, filter_type, or interlace_type.  The
  3878.          purpose of this chunk is to identify the beginning of the PNG
  3879.          datastream, so decoders can start interpreting PNG chunks
  3880.          instead of Delta-PNG chunks.  The decoder must treat this
  3881.          datastream as though the IHDR chunk were present in the
  3882.          location occupied by the IPNG chunk.
  3883.  
  3884.          The IHDR chunk can also be omitted when image_type=1 and the
  3885.          PNG datastream begins with a PLTE chunk, a PPLT chunk, or an
  3886.          IDAT chunk.  In this case, no IPNG chunk is required, either.
  3887.          The decoder must treat this datastream as though the IHDR chunk
  3888.          were present, immediately preceding the first PNG chunk.  If
  3889.          the first PNG chunk is neither a PLTE chunk, a PPLT chunk, nor
  3890.          an IDAT chunk, then either the IPNG or IHDR must be present to
  3891.          introduce the PNG datastream.
  3892.  
  3893.       6.1.6. PLTE and tRNS
  3894.  
  3895.          If the PLTE chunk is present, it need not have the same length
  3896.          as that inherited from the parent object, but it must contain
  3897.          the complete palette needed in the child image.  If it is
  3898.          shorter than the palette of the parent object, decoders can
  3899.          discard the remaining entries and the child image must not
  3900.          refer to them.  Decoders can also truncate any tRNS data
  3901.          inherited from an indexed-color parent object.  If the new
  3902.          palette is longer than the parent palette, and a new tRNS chunk
  3903.          is not present in an indexed-color image, the tRNS data must be
  3904.          extended with opaque entries.  The new palette must not be
  3905.          longer than the object's sample_depth would allow, and must not
  3906.          have more than 256 entries.
  3907.  
  3908.          When processing the tRNS chunk, if color_type=3 and PLTE is not
  3909.          supplied, then the number of allowable entries is determined
  3910.          from the number of PLTE entries in the parent object.  A tRNS
  3911.          chunk appearing in a Delta-PNG datastream is always treated as
  3912.          a complete replacement for the tRNS chunk data in the parent
  3913.          object.  All entries beyond those actually supplied are
  3914.          overwritten with the "opaque" value (255).
  3915.  
  3916.       6.1.7. PPLT Partial palette
  3917.  
  3918.          If it is desired only to overwrite or add palette entries, the
  3919.          PPLT chunk can be used.  This might be useful for palette-
  3920.          animation applications.  This chunk can also be used to
  3921.          overwrite or add entries to the transparency (alpha) data from
  3922.          the parent's tRNS chunk.
  3923.  
  3924.          The PPLT chunk contains a delta_type byte and one or more
  3925.          groups of palette entries:
  3926.  
  3927.             PPLT delta type: 1 byte.
  3928.                                0: Values are replacement RGB samples.
  3929.                                1: Values are delta RGB samples.
  3930.                                2: Values are replacement alpha
  3931.                                   samples.
  3932.                                3: Values are delta alpha samples.
  3933.                                4: Values are replacement RGBA
  3934.                                   samples.
  3935.                                5: Values are delta RGBA samples.
  3936.             First index,
  3937.               first group:   1 byte.
  3938.             Last index,
  3939.               first group:   1 byte.
  3940.             First set of
  3941.               samples:       1, 3, or 4 bytes.
  3942.             ...etc...
  3943.             Last set of
  3944.               samples:       1, 3, or 4 bytes.
  3945.             First index,
  3946.               second group:  1 byte.
  3947.             ...etc...
  3948.  
  3949.          The last_index must be equal to or greater than first_index.
  3950.          The groups are not required to appear in ascending order.  If
  3951.          any index of any group is beyond the end of the parent object's
  3952.          palette, the palette and tRNS data must be extended just as if
  3953.          a longer complete PLTE chunk had appeared.  If there are gaps
  3954.          in the resulting extended palette, the colors must be filled
  3955.          with {0,0,0} and the alphas filled with 255.  If alpha samples
  3956.          are supplied (PPLT_delta_type > 1) and no tRNS data is present
  3957.          in the parent object, a tRNS chunk must be created in the child
  3958.          object as though a complete tRNS chunk had appeared.  The new
  3959.          palette must not be longer than the object's sample_depth would
  3960.          allow.
  3961.  
  3962.          When PPLT_delta_type=0, the values are replacements for the
  3963.          existing samples in the palette.
  3964.  
  3965.          When PPLT_delta_type=1, the values are added to the existing
  3966.          samples (modulo 256) to obtain the new samples.
  3967.  
  3968.          If the new entry is beyond the range of the original palette,
  3969.          the values are simply appended, regardless of the contents of
  3970.          PPLT_delta_type.
  3971.  
  3972.       6.1.8. JHDR JNG image header
  3973.  
  3974.          Inside a Delta-PNG datastream, the JHDR chunk introduces an
  3975.          incomplete JNG (JPEG Network Graphics) datastream.  The parent
  3976.          object must be a JNG or JNG-based Delta-PNG.  The datastream is
  3977.          introduced by a complete JNG JHDR chunk.
  3978.  
  3979.          If the JHDR chunk is present, its width, height,
  3980.          JDAT_sample_depth, JDAT_color_type, JDAT_Filter_type, and
  3981.          JDAT_interlace_type fields are ignored.  The values for these
  3982.          parameters are inherited from the parent object.
  3983.  
  3984.          The IDAT_compression_method, IDAT_interlace_type, and
  3985.          IDAT_filter_type fields, if different from those of the parent
  3986.          object, are used in decoding any subsequent IDAT chunks, and
  3987.          the new values will be inherited by any subsequent image that
  3988.          uses this object as its parent.  If the IDAT_sample_depth
  3989.          differs, it will be used in decoding the IDAT chunk data of the
  3990.          Delta-PNG and subsequent Delta-PNG datastreams; but the child
  3991.          object itself will retain the original sample depth, and must
  3992.          also retain the "alpha sample depth" for use in decoding
  3993.          subsequent Delta-PNG datastreams.  The decoded alpha samples
  3994.          must be scaled to the object's sample depth before the
  3995.          replacements or delta calculations are done.
  3996.  
  3997.          See the JNG specification above for the format of the JNG
  3998.          chunks.  The PNG datastream must contain at least JHDR and
  3999.          IEND, but can inherit other chunk data from the parent object.
  4000.          Except for IDAT, any chunks appearing between IHDR and IEND are
  4001.          always treated as replacements or additions and not as deltas.
  4002.  
  4003.       6.1.9. IJNG Incomplete JNG
  4004.  
  4005.          The IJNG chunk is empty.
  4006.  
  4007.          The IJNG chunk can be used instead of the JHDR chunk if the
  4008.          JHDR chunk is not needed for resetting the value of any of the
  4009.          JHDR fields.  The purpose of this chunk is to identify the
  4010.          beginning of the JNG datastream, so decoders can start
  4011.          interpreting JNG chunks instead of Delta-PNG chunks.  The
  4012.          decoder must treat this datastream as though the JHDR chunk
  4013.          were present in the location occupied by the IJNG chunk.
  4014.  
  4015.          The JHDR chunk can also be omitted when image_type=2 and the
  4016.          JNG datastream begins with a JDAT chunk.  Note: Be sure that
  4017.          the first JDAT chunk precedes the first IDAT chunk.  In this
  4018.          case, no IJNG chunk is required, either.  The decoder must
  4019.          treat this datastream as though the JHDR chunk were present,
  4020.          immediately preceding the first JDAT chunk.  If the first JNG
  4021.          chunk is not a JDAT chunk, then either the IJNG or JHDR must be
  4022.          present to introduce the JNG datastream.
  4023.  
  4024.       6.1.10. DROP Drop chunks
  4025.  
  4026.          All chunks in the parent object with the specified name are
  4027.          inhibited from being copied into the child image.
  4028.  
  4029.             Chunk name: 4 bytes (ASCII text).
  4030.             etc.
  4031.  
  4032.          If multiple names appear in the DROP chunk, it is shorthand for
  4033.          multiple DROP chunks.
  4034.  
  4035.       6.1.11. DBYK Drop chunks by keyword
  4036.  
  4037.             Chunk name: 4 bytes (ASCII text).
  4038.  
  4039.             Polarity:   1 byte (unsigned integer).
  4040.                           0: Only.
  4041.                           1: All-but.
  4042.  
  4043.             Keywords (null-separated Latin-1 text strings).
  4044.  
  4045.          The chunk name must be the name of a chunk whose data begins
  4046.          with a null-terminated text string.  Some parent object chunks
  4047.          with the specified chunk name are inhibited from being copied
  4048.          into the child image.  If polarity is <only>, then any parent
  4049.          chunk whose keyword appears in the keywords list is inhibited.
  4050.          If polarity is <all-but>, then any parent object chunk whose
  4051.          keyword does not appear in the keywords list is inhibited.
  4052.  
  4053.          The format of the keyword is the same as that specified for the
  4054.          parent chunk.  Comparisons of keywords in the parent chunk and
  4055.          the DBYK chunk are case sensitive.
  4056.  
  4057.          Use caution when printing or displaying keywords (Refer to
  4058.          Security considerations, below, Chapter 14).
  4059.  
  4060.       6.1.12. ORDR Ordering restrictions
  4061.  
  4062.          The ORDR chunk informs the applier of the Delta-PNG of the
  4063.          ordering restrictions for ancillary chunks.  It contains one or
  4064.          more 5-byte sequences:
  4065.  
  4066.             Chunk name: 4 bytes (ASCII text).
  4067.             Order type: 1 byte.
  4068.                           0: Anywhere.
  4069.                           1: After IDAT and/or JDAT.
  4070.                           2: Before IDAT and/or JDAT.
  4071.                           3: Before IDAT, but not before PLTE.
  4072.                           4: Before IDAT, but not after PLTE.
  4073.             etc.
  4074.  
  4075.          Critical chunk names must not appear in the ORDR chunk.  The
  4076.          applier needs to know everything about them anyway.
  4077.  
  4078.          If a chunk name appears in the ORDR chunk, it is a promise that
  4079.          any chunk of that name appearing in the parent object which is
  4080.          not inhibited by DROP/DBYK will not be broken by this Delta-
  4081.          PNG, and therefore the applier must copy it into the child
  4082.          image at a location compatible with its ordering restrictions.
  4083.  
  4084.          If any ancillary chunk appears in the parent object, and it is
  4085.          not inhibited, and its name does not appear in the ORDR chunk,
  4086.          then the applier should copy it into the child only if it knows
  4087.          the chunk well enough to be sure that it is consistent with the
  4088.          changes made by the Delta-PNG, and knows where it can be placed
  4089.          in the child.  Those conditions are always true of safe-to-copy
  4090.          chunks.
  4091.  
  4092.          If any critical chunk defined in neither this specification nor
  4093.          the PNG specification appears in the parent object or in the
  4094.          Delta-PNG, it is a fatal error unless the applier knows how to
  4095.          handle it.  The specification of the critical chunk can include
  4096.          provisions for this scenario.
  4097.  
  4098.       6.1.13. Delta-PNG ancillary chunks
  4099.  
  4100.          This section describes ancillary Delta-PNG chunks.  MNG-
  4101.          compliant decoders should recognize and process them, but are
  4102.          not required to.
  4103.  
  4104.       6.1.14. gAMA, cHRM, iCCP, sRGB Color space chunks
  4105.  
  4106.          A gAMA, cHRM, iCCP, sRGB or similar chunk existing in the
  4107.          parent object would not affect the pixel data in a concrete
  4108.          object inherited by this Delta-PNG datastream because they are
  4109.          not used in decoding the pixel data.  Applications are
  4110.          responsible for ensuring that the pixel values that are
  4111.          inherited from the parent object are the raw pixel data that
  4112.          existed prior to any transformations that were applied while
  4113.          displaying the parent image.  These color transformations are
  4114.          applied to the resulting pixel data for display purposes.
  4115.  
  4116.       6.1.15. oFFs and pHYs
  4117.  
  4118.          MNG viewers must ignore oFFs and pHYs chunks that appear inside
  4119.          a PNG datastream, when the framing mode is 2 or 4 in the MNG
  4120.          FRAM chunk.  When the framing mode is 1 or 3 and when the FRAM
  4121.          chunk is not present, viewers must treat these chunks in the
  4122.          same manner as they would treat them in single-image PNG files.
  4123.          MNG editors are expected to treat them as unknown chunks that
  4124.          will be handled as described in above (Paragraph 6.1.12).
  4125.  
  4126.    6.2. Chunk ordering requirements
  4127.  
  4128.       The PNG specification places ordering requirements on many chunks
  4129.       with respect to the PLTE and IDAT chunks.  If neither of these two
  4130.       chunks is present, and the ORDR chunk is not present, known chunks
  4131.       (always including all standard chunks described in the PNG
  4132.       specification) are considered to have appeared in their proper
  4133.       order with respect to the critical chunks.  Unknown chunks are
  4134.       ordered as described in above (Paragraph 6.1.12).
  4135.  
  4136. 7. Chunk Copying Rules
  4137.  
  4138.    The chunk copying rules for MNG are the same as those in PNG, except
  4139.    that a MNG editor is not permitted to move unknown chunks across any
  4140.    of the following chunks:
  4141.  
  4142.        * SAVE
  4143.  
  4144.        * SEEK
  4145.  
  4146.        * IHDR
  4147.  
  4148.        * JHDR
  4149.  
  4150.        * IEND
  4151.  
  4152.        * DHDR
  4153.  
  4154.        * BASI
  4155.  
  4156.        * PAST
  4157.  
  4158.        * SHOW
  4159.  
  4160.    The copy-safe status of an unknown chunk is determined from the chunk
  4161.    name, just as in PNG.  If bit 5 of the first byte of the name is 0
  4162.    (Normally corresponding to an uppercase ASCII letter), the unknown
  4163.    chunk is critical and cannot be processed or copied.  If it is 1
  4164.    (usually corresponding to a lowercase ASCII letter), the unknown
  4165.    chunk is ancillary and its copy-safe status is determined by bit 5 of
  4166.    the fourth byte of the name, 0 meaning copy-unsafe and 1 meaning
  4167.    copy-safe.
  4168.  
  4169.    If an editor makes changes to the MNG datastream that render unknown
  4170.    chunks unsafe-to-copy, this does not affect the copy-safe status of
  4171.    any chunks beyond the next SEEK chunk or prior to the previous one.
  4172.    However, if it makes such changes prior the SAVE chunk, this affects
  4173.    the copy-safe status of all top-level unknown chunks in the entire
  4174.    MNG datastream.
  4175.  
  4176.    Changes to the MHDR chunk do not affect the copy-safe status of any
  4177.    other chunk.
  4178.  
  4179.    The SAVE, SEEK, and TERM chunks are not considered to be a part of
  4180.    any segment.  Changes to the data in the SAVE or SEEK chunks do not
  4181.    affect the copy-safe status of any other chunks.  Adding or removing
  4182.    a SEEK chunk affects the copy-safe status of unknown chunks in the
  4183.    newly-merged or newly-separated segments.  Adding, removing, or
  4184.    changing the TERM chunk has no effect on the copy-safe status of any
  4185.    chunk.
  4186.  
  4187.    As in PNG, unsafe-to-copy ancillary chunks in the top-level MNG
  4188.    datastream can have ordering rules only with respect to critical
  4189.    chunks.  Safe-to-copy ancillary chunks in the top-level MNG
  4190.    datastream can have ordering rules only with respect to the SAVE,
  4191.    SEEK, SHOW, and PAST chunks, IHDR-IEND, DHDR-IEND, JHDR-IEND, and
  4192.    BASI-IEND sequences, or with respect to any other critical "header-
  4193.    end" sequence that might be defined in the future that could contain
  4194.    IDAT or similar chunks.
  4195.  
  4196.    The copying rules for unknown chunks inside IHDR-IEND, BASI-IEND,
  4197.    DHDR-IEND, and JHDR-IEND sequences are governed by the PNG and JNG
  4198.    specifications, and any changes inside such sequences have no effect
  4199.    on the copy-safe status of any top-level MNG chunks.
  4200.  
  4201.    The copy-safe status of chunks inside a DHDR-IEND sequence depends on
  4202.    the copy-safe status of the chunks in its parent object.
  4203.  
  4204. 8. Minimum Requirements for MNG-Compliant Viewers
  4205.  
  4206.    This section specifies the minimum level of support that is expected
  4207.    of MNG-compliant decoders, and provides recomendations for viewers
  4208.    that will support slightly more than the minimum requirements.  All
  4209.    critical chunks must be recognized, but some of them can be ignored
  4210.    after they have been read and recognized.  Ancillary chunks can be
  4211.    ignored, and do not even have to be recognized.
  4212.  
  4213.    Anything less than this level of support would require subsetting.
  4214.    Applications that provide less than minimal support should check the
  4215.    MHDR "simplicity profile" for the presence of features that they are
  4216.    unable to support.  We are allowing minimal decoders to skip twelve-
  4217.    bit JNGs because those are likely to be rarely encountered and used
  4218.    only for special purposes.
  4219.  
  4220.    8.1. Required PNG chunk support
  4221.  
  4222.       IHDR, PLTE, IDAT, IEND
  4223.          All PNG critical chunks must be fully supported.  All values of
  4224.          color_type, bit_depth, compression_method, filter_method and
  4225.          interlace_method must be supported (interlacing, as in PNG,
  4226.          need not necessarily be displayed on-the-fly; the image can be
  4227.          displayed after it is fully decoded).  The alpha-channel must
  4228.          be supported, at least to the degree that fully opaque pixels
  4229.          are opaque and fully transparent ones are transparent.  It is
  4230.          recommended that alpha be fully supported.
  4231.  
  4232.       tRNS
  4233.          The PNG tRNS chunk, while it is an ancillary chunk, must be
  4234.          supported in MNG-compliant viewers, at least to the degree that
  4235.          fully opaque pixels are opaque and fully transparent ones are
  4236.          transparent.  It is recommended that alpha data from the tRNS
  4237.          chunk be fully supported in the same manner as alpha data from
  4238.          an RGBA image or a JNG with an alpha channel contained in IDAT
  4239.          chunks.
  4240.  
  4241.       Other PNG ancillary chunks
  4242.          Ancillary chunks other than PNG tRNS can be ignored, and do not
  4243.          even have to be recognized.
  4244.  
  4245.       Color management
  4246.          It is highly recommended that decoders support at least the
  4247.          gAMA chunk to allow platform-independent color rendering.
  4248.  
  4249.    8.2. Required JNG chunk support
  4250.  
  4251.       JHDR, JDAT, IDAT, JSEP, IEND
  4252.          All JNG critical chunks must be fully supported.  All values of
  4253.          color_type, bit_depth, compression_method, filter_method and
  4254.          interlace_method must be supported (interlacing, as in PNG,
  4255.          need not necessarily be displayed on-the-fly; the image can be
  4256.          displayed after it is fully decoded).  The alpha-channel must
  4257.          be supported, at least to the degree that fully opaque pixels
  4258.          are opaque and fully transparent ones are transparent.  It is
  4259.          recommended that alpha be fully supported.  Bit 3 of the
  4260.          simplicity profile can be used to promise that none of these
  4261.          chunks are present.
  4262.  
  4263.       JNG ancillary chunks
  4264.          All JNG ancillary chunks can be ignored, and do not even have
  4265.          to be recognized.
  4266.  
  4267.       JDAT sample depth
  4268.          Only sample_depth=8 must be supported.  The JSEP chunk must be
  4269.          recognized and must be used by minimal decoders to select the
  4270.          eight-bit version of the image, when both eight-bit and
  4271.          twelve-bit versions are present, as indicated by
  4272.          JDAT_sample_depth=20 in the JHDR chunk.  When
  4273.          JDAT_sample_depth=12, minimal decoders are not obligated to
  4274.          display anything, but should display an empty transparent
  4275.          rectangle of the width and height specified in the JHDR chunk.
  4276.          This can be done by processing the JNG as though a viewable
  4277.          transparent BASI object had appeared:
  4278.  
  4279.             BASI width height 1 4 0 0 0 0 00 00 00 00 1
  4280.             IEND
  4281.  
  4282.    8.3. Required MNG chunk support
  4283.  
  4284.       MHDR
  4285.          The ticks_per_second must be supported by animation viewers.
  4286.          The simplicity profile, frame count, layer count, and nominal
  4287.          play time can be ignored.  Decoders that provide less than
  4288.          minimal support can use the simplicity profile to identify
  4289.          datastreams that they are incapable of processing.
  4290.  
  4291.       MEND
  4292.          The MEND chunk must be recognized but does not require any
  4293.          processing other than completing the last frame.
  4294.  
  4295.       LOOP, ENDL
  4296.          The repeat_count must be supported.  The nest_level should be
  4297.          used as a sanity check but is not required.  When iteration_min
  4298.          <= 1 either explicitly or when it is omitted and
  4299.          termination_condition != 0, the LOOP and its ENDL chunk can be
  4300.          ignored (bit 1 of the simplicity profile can be used to promise
  4301.          that this is true for all loops).
  4302.  
  4303.       DEFI, CLON
  4304.          Must be fully supported.  All objects can be treated as
  4305.          "concrete" if the decoder does not wish to take advantage of
  4306.          the distinction between "abstract" and "concrete".  Bit 1 of
  4307.          the simplicity profile can be used to promise that the CLON
  4308.          chunk is not present and that if the DEFI chunk is present it
  4309.          only defines object 0, which does not need to be stored.
  4310.  
  4311.       BASI, BACK, DISC, PAST
  4312.          Must be fully supported.  Bit 1 of the simplicity profile can
  4313.          be used to promise that the DISC and PAST chunks are not
  4314.          present, and that if the BACK chunk is present it does not
  4315.          define a background image.
  4316.  
  4317.       FRAM
  4318.          The framing_mode and clipping parameters must be supported.
  4319.          The interframe_delay must be supported except by single-frame
  4320.          viewers.  The sync_id and sync_timeout data can be ignored.
  4321.  
  4322.       MOVE, CLIP, SHOW
  4323.          Must be fully supported.  Bit 1 of the simplicity profile can
  4324.          be used to promise that none of these chunks are present.
  4325.  
  4326.       SAVE and SEEK
  4327.          Partial support is required: All existing objects must be
  4328.          marked "frozen" when the SAVE chunk is processed, so that
  4329.          unneeded objects can be discarded when the SEEK chunk or an
  4330.          empty DISC chunk is processed.  The SEEK chunk must be
  4331.          processed as if it were an empty DISC chunk, as a minimum.
  4332.          Other information need only be "saved" and "restored" when the
  4333.          viewer is able to skip or jump to random SEEK chunk locations.
  4334.          The optional index can be ignored.  Slide-show controllers may
  4335.          wish to support SAVE and SEEK fully.  Bit 1 of the simplicity
  4336.          profile can be used to promise that the SAVE and SEEK chunks
  4337.          can be ignored entirely (because there will be nothing to
  4338.          discard).
  4339.  
  4340.       TERM
  4341.          Can be ignored.
  4342.  
  4343.    8.4. Required Delta-PNG chunk support
  4344.  
  4345.       DHDR, PROM, IHDR, IDAT, IPNG, JHDR, JDAT, JSEP, PLTE, tRNS, IEND,
  4346.          PPLT
  4347.          Must be fully supported.  Bit 1 of the simplicity profile can
  4348.          be used to promise that none of these are present (because the
  4349.          DHDR chunk is absent).  Bit 3 of the simplicity profile can be
  4350.          used to promise that the JHDR and JDAT chunks are not present.
  4351.  
  4352.       DROP, DBYK, ORDR
  4353.          Can be recognized and ignored.  These are only of concern to
  4354.          MNG editors and to MNG viewers that handle private chunks or
  4355.          chunks that can be selected by keyword, such as pCAL and iCCP.
  4356.          If you decide to support such chunks, then you will also have
  4357.          to support these three chunks.
  4358.  
  4359.       Ancillary chunks
  4360.          Ancillary chunks appearing in Delta-PNG datastreams must be
  4361.          treated in the same manner as if they appeared in a PNG or JNG
  4362.          datastream.  See the recommendations, above.  Note that the PNG
  4363.          tRNS chunk must be supported, despite its being an ancillary
  4364.          chunk in PNG.
  4365.  
  4366. 9. Recommendations for Encoders
  4367.  
  4368.    The following recommendations do not form a part of the
  4369.    specification.
  4370.  
  4371.    9.1. Use a common color space
  4372.  
  4373.       It is a good idea to use a single color space for all of the
  4374.       layers in an animation, where speed and fluidity are more
  4375.       important than exact color rendition.  This is best accomplished
  4376.       by defining a single color space at the top level of MNG, using
  4377.       gAMA and cHRM chunks, and either an sRGB or iCCP chunk, and
  4378.       removing any color space chunks from the individual images after
  4379.       converting them to the common color space.
  4380.  
  4381.       When the encoder converts all images to a single color space
  4382.       before putting them in the MNG datastream, this will allow
  4383.       decoders to improve the speed and consistency of the display.
  4384.  
  4385.       For single-frame MNG datastreams, however, where decoding speed is
  4386.       less important and exact color rendition might be more important,
  4387.       it is best to leave the images in their original color space, as
  4388.       recommended in the PNG specification, to avoid any loss of data
  4389.       due to conversion, and to retain the individual color space chunks
  4390.       if the images have different color spaces.
  4391.  
  4392.    9.2. Use the right framing mode
  4393.  
  4394.       Always use framing mode 1 or 2 when all of the images are opaque.
  4395.       This avoids unnecessary screen clearing, which can cause
  4396.       flickering.
  4397.  
  4398.    9.3. Embedded images in LOOPs
  4399.  
  4400.       Embedded images should not be enclosed in loops unless absolutely
  4401.       necessary.  It is better to store them ahead of time and then use
  4402.       SHOW chunks inside the loops.  Otherwise, decoders will be forced
  4403.       to repeatedly decode them.  See Examples 2, 8, 11, and 12, below
  4404.       (Chapter 15).
  4405.  
  4406.    9.4. Including optional index in SAVE chunk
  4407.  
  4408.       Authors of MNG files that are intended for transmission over a
  4409.       network should consider whether it is more economical for the
  4410.       client to rebuild the index from scratch than it is to transmit
  4411.       it.  Web pages that are likely to be downloaded over slow lines,
  4412.       and whose clients are unlikely to use the index anyway, generally
  4413.       should have empty SAVE chunks.  No information is lost by deleting
  4414.       the index, because the MNG datastream contains all of the
  4415.       information needed to build the index.  If an application does
  4416.       build an index, and the file is going to be kept as a local file,
  4417.       the application should replace the empty SAVE chunk with one
  4418.       containing the index.  See above (Paragraph 4.4.1).
  4419.  
  4420.    9.5. Interleaving JDAT and IDAT chunks
  4421.  
  4422.       When a JNG datastream contains an alpha channel, and the file is
  4423.       intended for transmission over a network, it is useful to
  4424.       interleave the IDAT and JDAT chunks.  In the case of sequential
  4425.       JPEG, the interleaving should be arranged so that the alpha data
  4426.       arrives more or less in sync with the color data for the
  4427.       scanlines.  In the case of progressive JPEG, the alpha data should
  4428.       be interleaved with the first JPEG pass, so that all of the alpha
  4429.       data has arrived before beginning the second JPEG pass.
  4430.  
  4431. 10. Recommendations for Decoders
  4432.  
  4433.    10.1. ENDL without matching LOOP
  4434.  
  4435.       If a decoder reads an ENDL chunk for which the matching LOOP chunk
  4436.       is missing, or has been skipped for some reason, any active loops
  4437.       with a higher nest_level should be terminated, and processing can
  4438.       resume after the next SEEK chunk.  Simple viewers that do not
  4439.       process the SAVE chunk should abandon the MNG datastream.  See
  4440.       above.
  4441.  
  4442.    10.2. Note on compositing
  4443.  
  4444.       The PNG specification gives a good explanation of how to composite
  4445.       a partially transparent image over an opaque image, but things get
  4446.       more complicated when both images are partially transparent.
  4447.  
  4448.       Pixels in PNG and JNG images are represented using gamma-encoded
  4449.       RGB (or gray) samples along with a linear alpha value.  Alpha
  4450.       processing can only be performed on linear samples.  This chapter
  4451.       assumes that R, G, B, and A values have all been converted to real
  4452.       numbers in the range [0..1], and that any gamma encoding has been
  4453.       undone.
  4454.  
  4455.       For a top pixel {Rt,Gt,Bt,At} and a bottom pixel {Rb,Gb,Bb,Ab},
  4456.       the composite pixel {Rc,Gc,Bc,Ac} is given by:
  4457.  
  4458.          Ac = 1 - (1 - At)(1 - Ab)
  4459.          if (Ac != 0) then
  4460.            s = At / Ac
  4461.            t = (1 - At) Ab / Ac
  4462.          else
  4463.            s = 0.0
  4464.            t = 1.0
  4465.          endif
  4466.          Rc = s Rt + t Rb
  4467.          Gc = s Gt + t Gb
  4468.          Bc = s Bt + t Bb
  4469.  
  4470.       When the bottom pixel is fully opaque (Ab = 1.0), the function
  4471.       reduces to:
  4472.  
  4473.          Ac = 1
  4474.          Rc = At Rt + (1 - At) Rb
  4475.          Gc = At Gt + (1 - At) Gb
  4476.          Bc = At Bt + (1 - At) Bb
  4477.  
  4478.       When the bottom pixel is not fully opaque, the function is much
  4479.       simpler if premultiplied alpha is used.  A pixel that uses non-
  4480.       premultiplied alpha can be converted to premultiplied alpha by
  4481.       multiplying R, G, and B by A.
  4482.  
  4483.       For a premultiplied top pixel {Rt,Gt,Bt,At} and a premultiplied
  4484.       bottom pixel {Rb,Gb,Bb,Ab}, the premultiplied composite pixel
  4485.       {Rc,Gc,Bc,Ac} is given by:
  4486.  
  4487.          Ac = 1 - (1 - At)(1 - Ab)
  4488.          Rc = Rt + (1 - At) Rb
  4489.          Gc = Gt + (1 - At) Gb
  4490.          Bc = Bt + (1 - At) Bb
  4491.  
  4492.       As mentioned in the PNG specification, the equations become much
  4493.       simpler when no pixel has an alpha value other than 0.0 or 1.0,
  4494.       and the RGB samples need not be linear in that case.
  4495.  
  4496.    10.3. Retaining object data
  4497.  
  4498.       The decoder must retain information about each object (except for
  4499.       objects with object_id=0) for possible redisplay with the SHOW
  4500.       chunk or for possible use as the parent object for a subsequent
  4501.       Delta-PNG datastream.
  4502.  
  4503.       The following information must be retained, for each nonzero
  4504.       object that is defined and not subsequently discarded:
  4505.  
  4506.           * The object attribute set (potential visibility, location,
  4507.             clipping boundary data from the DEFI, MOVE, CLIP, and SHOW
  4508.             chunks, and pointer to an object buffer).
  4509.  
  4510.           * The pixel data and the values associated with other
  4511.             recognized PNG chunks such as PLTE and gAMA, subject to the
  4512.             chunk copying rules and the DROP/DBYK chunks.  If the object
  4513.             is "abstract", the data can be stored in any convenient
  4514.             form.  If it is "concrete", it must be stored in an object
  4515.             buffer in a manner that would permit the complete
  4516.             restoration of the original PNG or JNG file or its
  4517.             equivalent.
  4518.  
  4519.           * The most recent values of target_x and target_y, if the
  4520.             object was the destination of a PAST chunk.
  4521.  
  4522.       When the encoder knows that data in the object buffer will not be
  4523.       needed by subsequent frames, it can make life easier for decoders
  4524.       by using object_id=0 or by using the DISC or the SEEK chunk.
  4525.       Abstract images rather than concrete objects should be used if the
  4526.       encoder knows that the data will not later be used as the parent
  4527.       object for a Delta-PNG.
  4528.  
  4529.    10.4. Decoder handling of fatal errors
  4530.  
  4531.       When a fatal error is encountered, such as a bad CRC or an unknown
  4532.       critical MNG chunk, minimal viewers that do not implement the
  4533.       SAVE/SEEK mechanism should simply abandon the MNG datastream.
  4534.       More capable MNG viewers should attempt to recover gracefully by
  4535.       abandoning processing of the segment and searching for a SEEK
  4536.       chunk.  If such errors occur before the SAVE chunk is reached, the
  4537.       viewer should abandon the MNG datastream.
  4538.  
  4539.       When an error occurs within a image datastream, such as an unknown
  4540.       critical PNG chunk or a missing parent object where one was
  4541.       required, only that image should be abandoned and the associated
  4542.       object should be discarded.  If a bad CRC is found, indicating a
  4543.       corrupted datastream, the entire segment should be abandoned, as
  4544.       above.
  4545.  
  4546.       MNG editors, on the other hand, should be more strict and reject
  4547.       any datastream with errors unless the user intervenes.
  4548.  
  4549.    10.5. Decoder handling of interlaced images
  4550.  
  4551.       Decoders are required to be able to interpret datastreams that
  4552.       contain interlaced PNG images, but are only required to display
  4553.       the completed frames; they are not required to display the images
  4554.       as they evolve.  Viewers that are decoding datastreams coming in
  4555.       over a slow communication link might want to do that, but MNG
  4556.       authors should not assume that the frames will be displayed in
  4557.       other than their final form.
  4558.  
  4559.    10.6. Decoder handling of palettes
  4560.  
  4561.       When a PLTE chunk is received, it only affects the display of the
  4562.       PNG or Delta-PNG datastream that includes it, and any subsequent
  4563.       Delta-PNG datastreams that depend on it.
  4564.  
  4565.       If PLTE or PPLT is present in a Delta-PNG datastream, the new
  4566.       palette is used in displaying the image defined by the Delta-PNG;
  4567.       if no IDAT chunk is present and the image type is PNG indexed-
  4568.       color, then the resulting image is displayed using the old pixel
  4569.       samples as indices into the new palette, which provides a "palette
  4570.       animation" capability.
  4571.  
  4572.       If a frame contains two or more images, the PLTE chunk in one
  4573.       image does not affect the display of the other, unless one image
  4574.       is a subsequent Delta-PNG without a PLTE chunk, that has been
  4575.       declared by the DHDR object_id field to depend on the other.
  4576.  
  4577.       A composite frame consisting only of indexed-color images should
  4578.       not be assumed to contain 256 or fewer colors, since the
  4579.       individual palettes do not necessarily contain the same set of
  4580.       colors.  Encoders can supply a top-level sPLT chunk with a
  4581.       suggested reduced global palette, to help decoders build an
  4582.       appropriate palette when necessary.
  4583.  
  4584.    10.7. Behavior of single-frame viewers
  4585.  
  4586.       Viewers that can only display a single frame must display the
  4587.       first frame that they encounter.  It is strongly recommended that
  4588.       such viewers understand the fPRI chunk above (Paragraph 4.5.2),
  4589.       which will enable them to find and display the best representative
  4590.       frame, if the encoder has identified one.
  4591.  
  4592.    10.8. Clipping
  4593.  
  4594.       MNG provides four types of clipping, in addition to any clipping
  4595.       that might be required due to the physical limitations of the
  4596.       display device.
  4597.  
  4598.       Frame width and frame height
  4599.          The frame_width and frame_height are defined in the MHDR chunk
  4600.          and cannot be changed.
  4601.  
  4602.          Decoders can use these parameters to establish the size of a
  4603.          window in which to display the MNG frames.  When the
  4604.          frame_width or frame_height exceeds the physical dimensions of
  4605.          the display hardware, the contents of the area outside those
  4606.          dimensions is undefined.  If a viewer chooses, it can create
  4607.          "scroll bars" or the like, to enable persons to pan and scroll
  4608.          to the offscreen portion of the frame.  If this is done, then
  4609.          the viewer is responsible for maintaining and updating the
  4610.          offscreen portion of the frame.
  4611.  
  4612.          In the case of a MNG datastream that consists of a PNG or JNG
  4613.          datastream, with the PNG or JNG signature, the frame_width and
  4614.          frame_height are defined by the width and height fields of the
  4615.          IHDR (or JHDR) chunk.
  4616.  
  4617.       Subframe clipping boundaries
  4618.          The subframe clipping boundaries are optionally defined in the
  4619.          FRAM chunk, and cannot be changed within a subframe.  When the
  4620.          framing mode is 3 or 4, viewers must, prior to displaying each
  4621.          subframe, clear the area within the subframe clipping
  4622.          boundaries to the background color, and display the background
  4623.          image if one has been defined.  Viewers must not change any
  4624.          pixels outside the subframe boundaries; encoders must be able
  4625.          to rely on the fact that the part of the display that is
  4626.          outside the subframe clipping boundaries (but inside the area
  4627.          defined by frame_width and frame_height) will remain on the
  4628.          display from frame to frame without being explicitly
  4629.          redisplayed.  See Example 8, which displays a large background
  4630.          image once, and then, in each frame, only redisplays the
  4631.          portion of the background surrounding the moving sprite.
  4632.  
  4633.       Image clipping boundaries
  4634.          The image clipping boundaries are defined in the DEFI and CLIP
  4635.          chunks.  They are associated with individual objects, not with
  4636.          the subframes, and they can be changed within a subframe.  They
  4637.          are useful for exposing only a portion of an image in a frame,
  4638.          to achieve effects such as scrolling, panning, or gradual
  4639.          exposure.
  4640.  
  4641.       PAST clipping boundaries
  4642.          The clipping performed in PAST gives a fourth type that has no
  4643.          dependencies on the other types, since the object CLIP data is
  4644.          ignored and the destination object defines its own boundaries.
  4645.  
  4646. 11. Recommendations for Editors
  4647.  
  4648.    11.1. Editing datastreams with optional index
  4649.  
  4650.       Editors must recreate or delete the optional SAVE chunk index
  4651.       whenever they make any change that affects the offsets of chunks
  4652.       following the portion of the datastream that is changed.  If the
  4653.       changes do not involve the addition, deletion, or relocation of
  4654.       segments, frames, and images, then it is sufficient to zero out
  4655.       the offsets.
  4656.  
  4657.       The SAVE chunk is not considered to be in any MNG segment, so
  4658.       changing it has no effect on the copy-safe status of unknown
  4659.       chunks in any other part of the MNG datastream.
  4660.  
  4661.       When the SAVE chunk is expanded to include an index, all chunks
  4662.       that follow will have their offsets changed by an amount equal to
  4663.       the change in the length of the data segment of the SAVE chunk, so
  4664.       the offset table will have to be adjusted accordingly.  If a SAVE
  4665.       chunk is already present with zero offsets, the correct offsets
  4666.       can be written without adjustment.
  4667.  
  4668. 12. Miscellaneous Topics
  4669.  
  4670.    12.1. File name extension
  4671.  
  4672.       On systems where file names customarily include an extension
  4673.       signifying file type, the extension .mng is recommended for MNG
  4674.       files.  Lowercase .mng is preferred if file names are
  4675.       case-sensitive.  The extension .jng is recommended for JNG files.
  4676.  
  4677.    12.2. Internet media type
  4678.  
  4679.       When and if the MNG format becomes finalized, the MNG authors
  4680.       intend to register video/mng as the Internet Media Type for MNG
  4681.       [RFC-2045], [RFC-2048].
  4682.  
  4683.       At the date of this document, the media type registration process
  4684.       had not been started.  It is recommended that implementations also
  4685.       recognize the interim media type video/x-mng.
  4686.  
  4687.       Although we define a standalone JNG format, we recommend that such
  4688.       files be used only temporarily while compiling or disassembling
  4689.       MNG datastreams.  We do not intend to register an Internet Media
  4690.       Type for JNG files.
  4691.  
  4692.    12.3. Uniform Resource Identifier (URI)
  4693.  
  4694.       Segments, subframes, and objects are externally accessible via
  4695.       named SEEK, FRAM, and eXPI chunk names.  They can be referred to
  4696.       by URI, as in
  4697.  
  4698.          SRC=file.mng#segment_name
  4699.          SRC=file.mng#subframe_name
  4700.          SRC=file.mng#snapshot_name
  4701.          SRC=file.mng?segment_name#segment_name
  4702.          SRC=file.mng?snapshot_name#snapshot_name
  4703.  
  4704.       When the URI specializer ("#" or "?") is "#", and the fragment
  4705.       identifier (the string following the specializer) is the name of a
  4706.       segment, i.e., a named SEEK chunk, the viewer should display the
  4707.       animation from the beginning of the named segment up to the next
  4708.       segment.  When it refers to a subframe or an image, i.e., a named
  4709.       FRAM or eXPI chunk, it should display the single frame (as it
  4710.       exists when the next FRAM chunk is encountered) or image that is
  4711.       identified by the fragment identifier.  If the SAVE chunk is
  4712.       present and contains the optional index, this can help the client
  4713.       find the needed segment quickly.
  4714.  
  4715.       When the URI specializer is "?" (server side query), the "query
  4716.       component" is the string following the "?" specializer and up to
  4717.       but not including the "#" if the "#" specializer is also present.
  4718.       The server should find the segment that is named in the query
  4719.       component or the segment that contains the subframe or image named
  4720.       in the query component, and it should return a datastream
  4721.       consisting of:
  4722.  
  4723.           * all chunks prior to the SAVE chunk,
  4724.  
  4725.           * an empty SAVE chunk,
  4726.  
  4727.           * the SEEK chunk for the segment being returned,
  4728.  
  4729.           * all chunks in the segment, and
  4730.  
  4731.           * a MEND chunk.
  4732.  
  4733.       If no SAVE chunk is present, the server must simply return the
  4734.       entire MNG datastream.  Servers that are unwilling to parse the
  4735.       MNG datastream and are unconcerned about bandwidth can return the
  4736.       entire MNG datastream even when the SAVE chunk is present.
  4737.       Authors should defend against this behavior by including both a
  4738.       query and a fragment in the URI even when a segment is being
  4739.       requested.
  4740.  
  4741.       The client can process this as a complete MNG datastream, either
  4742.       displaying the entire segment, if no fragment identifier is
  4743.       present, or extracting the segment, subframe or image that is
  4744.       named in a fragment identifier and displaying it, if a fragment
  4745.       identifier is present (a fragment identifier must be present if a
  4746.       frame or image is being requested).
  4747.  
  4748.       A part of the MNG datastream can also be requested by timecode, as
  4749.       in
  4750.  
  4751.          SRC=file.mng#clock(10s-20s)
  4752.          SRC=file.mng#clock(0:00-0:15)
  4753.          SRC=file.mng?clock(0:00-0:15#clock=0:00-0:15)
  4754.  
  4755.       or by frame number, as in
  4756.  
  4757.          SRC=file.mng#frame(10)
  4758.          SRC=file.mng#frames(30-60)
  4759.          SRC=file.mng?frames(30-60#frames=30-60)
  4760.  
  4761.       The timecode must consist of starting and ending clock values, as
  4762.       defined in the W3C SMIL recommendation, separated by a hyphen
  4763.       (ASCII code 45).
  4764.  
  4765.       When the URI specializer is "#", the viewer should play that part
  4766.       of the animation beginning and ending at the requested times,
  4767.       measuring from zero time at the beginning of the MNG datastream,
  4768.       or beginning and ending with the specified frame numbers.
  4769.  
  4770.       When the URI specializer is "?", the server can send the entire
  4771.       MNG datastream, or, preferably, it should construct a complete MNG
  4772.       file containing:
  4773.  
  4774.           * the chunks prior to the SAVE chunk,
  4775.  
  4776.           * the SAVE chunk itself with an optional index, and
  4777.  
  4778.           * the one or more consecutive set of segments, with their SEEK
  4779.             chunks, that contain the animation beginning and ending at
  4780.             the requested times, or frame numbers, at the proper framing
  4781.             rate.
  4782.  
  4783.       If the server does not send the entire MNG datastream, and the
  4784.       first segment after the SAVE chunk is not sent, the optional index
  4785.       must be written even if it does not exist in the source file.  The
  4786.       index must contain at least one "type 0" entry that gives the
  4787.       nominal start time and frame number for the first segment that is
  4788.       sent after the SAVE chunk.  The offset field can be set to zero
  4789.       and the segment name can be omitted.
  4790.  
  4791.       The query component should always be repeated as a fragment
  4792.       identifier, so clients can find the requested item in case the
  4793.       server sends more than what was requested.
  4794.  
  4795.       MNG datastreams should not contain segment, subframe, or image
  4796.       names that begin with the case-insensitive strings "clock(",
  4797.       "frame(", or "frames(", which are reserved for use in URI queries
  4798.       and fragments.
  4799.  
  4800.       See [RFC-2396] and the W3C SMIL recommendation at
  4801.       http://www.w3.org/TR/.
  4802.  
  4803. 13. References
  4804.  
  4805.    [ISO/IEC-10918-1]
  4806.       International Organization for Standardization and International
  4807.       Electrotechnical Commission, "Digital Compression and Coding of
  4808.       Continuous-tone Still Images, Part 1: Requirements and guidelines"
  4809.       ISO/IEC IS 10918-1, ITU-T T.81.
  4810.  
  4811.       See also Pennebaker, William B., and  Joan L. Mitchell, "JPEG :
  4812.       Still Image Data Compression Standard" Van Nostrand Reinhold,
  4813.       ISBN:0442012721, September 1992
  4814.  
  4815.    [JFIF]
  4816.       C-Cube Microsystems, "JPEG File Interchange Format, Version 1.02",
  4817.       September 1992.
  4818.  
  4819.    [PNG]
  4820.       Boutell, T., et. al.,  "PNG (Portable Network Graphics Format)
  4821.       Version 1.0", RFC 2083,
  4822.        ftp://ftp.isi.edu/in-notes/rfc2083.txt also available at
  4823.        ftp://swrinde.nde.swri.edu/pub/png/documents/. This specification
  4824.       has also been published as a W3C Recommendation, which is
  4825.       available at
  4826.        http://www.w3.org/TR/REC-png.html.
  4827.  
  4828.       See also the PNG-1.1 draft:
  4829.       Randers-Pehrson, G., et. al.,  "PNG (Portable Network Graphics
  4830.       Format) Version 1.1", which is available at
  4831.        ftp://swrinde.nde.swri.edu/pub/png/documents/.
  4832.  
  4833.    [PNG-EXT]
  4834.       Extensions to the PNG 1.1 Specification,
  4835.        ftp://swrinde.nde.swri.edu/pub/png/documents/pngext-*.
  4836.  
  4837.    [RFC-2119]
  4838.       Bradner, S., "Key words for use in RFCs to Indicate Requirement
  4839.       Levels", RFC 2119/BCP 14, Harvard University, March 1997.
  4840.  
  4841.    [RFC-2045]
  4842.       Freed, N., and N. Borenstein, "Multipurpose Internet Mail
  4843.       Extensions (MIME) Part One: Format of Internet Message Bodies",
  4844.       RFC 2045, Innosoft, First Virtual, November 1996.
  4845.        ftp://ftp.isi.edu/in-notes/rfc2045.txt
  4846.  
  4847.    [RFC-2048]
  4848.       Freed, N., Klensin, J., and J. Postel, "Multipurpose Internet Mail
  4849.       Extensions (MIME) Part Four: Registration Procedures", RFC 2048,
  4850.       Innosoft, MCI, USC/Information Sciences Institute, November 1996.
  4851.        ftp://ftp.isi.edu/in-notes/rfc2048.txt
  4852.  
  4853.    [RFC-2396]
  4854.       Berners-Lee, T., R. Fielding, U. C. Irvine, and L. Masinter,
  4855.       "Uniform Resource Identifiers (URI): Generic Syntax", RFC 2396,
  4856.       MIT/LCS, Xerox Corporation, University of Minnesota, August 1998.
  4857.        ftp://ftp.isi.edu/in-notes/rfc2396.txt
  4858.  
  4859. 14. Security Considerations
  4860.  
  4861.    Security considerations are addressed in the basic PNG specification.
  4862.  
  4863.    An infinite or just overly long loop could give the appearance of
  4864.    having locked up the machine, as could an unreasonably long
  4865.    interframe delay or a misplaced sync_id with a long sync_timeout
  4866.    value.  Therefore a decoder should always provide a simple method for
  4867.    users to escape out of a loop or delay, either by abandoning the MNG
  4868.    entirely or just proceeding to the next SEEK chunk.  (The SEEK chunk
  4869.    makes it safe for a viewer to resume processing after it encounters a
  4870.    corrupted portion of a MNG datastream.)
  4871.  
  4872.    Some people may experience epileptic seizures when they are exposed
  4873.    to certain kinds of flashing lights or patterns that are common in
  4874.    everyday life.  This can happen even if the person has never had any
  4875.    epileptic seizures.  All graphics software and file formats that
  4876.    support animation and/or color cycling make it possible to encode
  4877.    effects that may induce an epileptic seizure in these individuals.
  4878.    It is the responsibility of authors and software publishers to issue
  4879.    appropriate warnings to the public in general and to animation
  4880.    creators in particular.
  4881.  
  4882.    No known additional security concerns are raised by this format.
  4883.  
  4884. 15. Appendix: Examples
  4885.  
  4886.    We use the "#" character to denote commentary in these examples; such
  4887.    comments are not present in actual MNG datastreams.
  4888.  
  4889.    15.1. Example 1: A single image
  4890.  
  4891.       The simplest MNG datastream is a single-image PNG datastream.  The
  4892.       simplest way to create a MNG from a PNG is:
  4893.  
  4894.          copy file.png file.mng
  4895.  
  4896.       The resulting MNG file looks like:
  4897.  
  4898.          \211 P N G \r \n ^z \n  # PNG signature.
  4899.          IHDR 720 468 8 0 0 0 0  # Width and Height, etc.
  4900.          IDAT ...
  4901.          IEND
  4902.  
  4903.    15.2. Example 2: Very simple movie
  4904.  
  4905.       This example demonstrates a very simple movie, such as might
  4906.       result from directly converting an animated GIF that contains a
  4907.       simple series of full-frame images:
  4908.  
  4909.          \212 M N G \r \n ^z \n  # MNG signature.
  4910.          MHDR 256 300   # Width and height.
  4911.               30        # 30 ticks per second.
  4912.  
  4913.          tERm 2 0 120 10   # When done, repeat from SAVE 10 times.
  4914.  
  4915.          FRAM 1 0 2 0 0 0 30 # Set framing_mode=1 (because the
  4916.                  #  images are opaque) and frame_duration to 1 sec.
  4917.  
  4918.          DEFI 1 IHDR ...  IDAT ...  IEND # Eight PNG datastreams
  4919.          DEFI 2 IHDR ...  IDAT ...  IEND # are read and stored as
  4920.          DEFI 3 IHDR ...  IDAT ...  IEND # abstract images, and
  4921.          DEFI 4 IHDR ...  IDAT ...  IEND # are displayed as they
  4922.          DEFI 5 IHDR ...  IDAT ...  IEND # are read.
  4923.          DEFI 6 IHDR ...  IDAT ...  IEND
  4924.          DEFI 7 IHDR ...  IDAT ...  IEND
  4925.          DEFI 8 IHDR ...  IDAT ...  IEND
  4926.  
  4927.          SAVE
  4928.          SHOW 1 8
  4929.          MEND
  4930.  
  4931.    15.3. Example 3: Simple slideshow
  4932.  
  4933.          \212 M N G \r \n ^z \n  # MNG signature.
  4934.          MHDR 720 468   # Width and height.
  4935.               1         # 1 tick per second.
  4936.          FRAM 1 0 2 2 0  2 0 600 0 # Set frame_duration to 0,
  4937.            # sync_timeout to 600 sec, and sync_id list to {0}.
  4938.          SAVE
  4939.          SEEK "Briefing to the Workforce"
  4940.          IHDR ...  IDAT ...  IEND  # DEFI 0, visible, abstract
  4941.          SEEK "Outline"            # is implied.
  4942.          IHDR ...  IDAT ...  IEND
  4943.          SEEK "Our Vision"       IHDR ...  IDAT ...  IEND
  4944.          SEEK "Our Mission"      IHDR ...  IDAT ...  IEND
  4945.          SEEK "Downsizing Plans" IHDR ...  IDAT ...  IEND
  4946.          MEND
  4947.  
  4948.    15.4. Example 4: A more storage-efficient slideshow
  4949.  
  4950.       This slideshow gives exactly the same output as Example 3, but the
  4951.       storage in the datastream is more efficient (the IDAT chunks will
  4952.       be smaller) while the memory requirements in the decoder are
  4953.       larger.  Image ID 1 is used to store the ornate logos and frame
  4954.       design that appear on every slide.  The DHDR-IEND datastreams only
  4955.       contain deltas due to the text and other information that is
  4956.       unique to each slide.
  4957.  
  4958.          \212 M N G \r \n ^z \n  # MNG signature.
  4959.          MHDR 720 468   # Width and height.
  4960.               1         # 1 tick per second.
  4961.          DEFI 1 1 1     # Define image 1, invisible, concrete.
  4962.          IHDR ...  IDAT ...  IEND
  4963.          FRAM  1 0  2 2 0 2  0 600 0 # set frame_duration to 0,
  4964.            # sync_timeout to 600 sec and sync_id list to {0}.
  4965.          SAVE
  4966.          SEEK "Briefing to the Workforce"
  4967.          CLON 1 2 DHDR 2 ...  IDAT ...  IEND SHOW 2
  4968.          SEEK "Outline"
  4969.          CLON 1 2 DHDR 2 ...  IDAT ...  IEND SHOW 2
  4970.          SEEK "Our Vision"
  4971.          CLON 1 2 DHDR 2 ...  IDAT ...  IEND SHOW 2
  4972.          SEEK "Our Mission"
  4973.          CLON 1 2 DHDR 2 ...  IDAT ...  IEND SHOW 2
  4974.          SEEK "Downsizing Plans"
  4975.          CLON 1 2 DHDR 2 ...  IDAT ...  IEND SHOW 2
  4976.          MEND
  4977.  
  4978.    15.5. Example 5: Simple movie
  4979.  
  4980.       This movie is still fairly simple, but it capitalizes on frame-
  4981.       to-frame similarities by use of Delta-PNG datastreams, and also
  4982.       demonstrates the use of the fPRI chunk.
  4983.  
  4984.          \212 M N G \r \n ^z \n  # MNG signature.
  4985.          MHDR 720 468   # Width and height.
  4986.               30        # 30 ticks per second.
  4987.          tEXtTitle\0Sample Movie
  4988.          fPRI 0 128     # Default frame priority is "medium".
  4989.          FRAM 1 0  2 0 0 0  3 # Set frame_duration to 1/10 sec.
  4990.          DEFI 1 0 1       # Set default image to 1 (concrete).
  4991.          SAVE
  4992.          SEEK "start"
  4993.  
  4994.          IHDR 720 468 8 2 0 0 0   # DEFI 1 is implied.
  4995.          IDAT ...
  4996.          IEND
  4997.  
  4998.          DHDR 1 1 1 20 30 100 220   # A PNG-delta frame.
  4999.          IDAT ...       # The IDAT gives the 20x30 block
  5000.          IEND           # of deltas.
  5001.  
  5002.          DHDR 1 1 1 20 30 102 222   # Another PNG-delta frame.
  5003.          IDAT ...       # This time the deltas are in a 20 x 30
  5004.          IEND           # block at a slightly different location.
  5005.  
  5006.          SEEK "frame 3"  # OK to restart here because a
  5007.                          # complete PNG frame follows.
  5008.          fPRI 0 255      # This is the representative frame that
  5009.          IHDR 720 468 ...# will be displayed by single-frame
  5010.          IDAT ...        # viewers.
  5011.          IEND
  5012.          fPRI 0 128      # Return to medium frame priority.
  5013.  
  5014.          DHDR 1 1 1 720 468 0 0     # Another PNG-delta frame.
  5015.          IDAT ...   # The entire 720x468 rectangle changes
  5016.          IEND       # this time.
  5017.  
  5018.          SEEK "end"
  5019.          MEND            # End of MNG datastream.
  5020.  
  5021.    15.6. Example 6: Single composite frame
  5022.  
  5023.       Here is an example single-composite-frame MNG, with thumbnails,
  5024.       which takes a grayscale image and draws it side-by-side with a
  5025.       false-color version of the same image:
  5026.  
  5027.          \212 M N G \r \n ^z \n # MNG signature.
  5028.          MHDR 1024 512 0 # Width, height, ticklength.
  5029.          BACK 16448 16448 52800 1 # Must use sky blue background.
  5030.  
  5031.          DEFI 1 1     # Define invisible abstract thumbnail image.
  5032.          IHDR 64 64 4 3 0 0 0
  5033.          IDAT
  5034.          IEND
  5035.          eXPI 1 "thumbnail 1"
  5036.          DEFI 1 1       # Also define a larger thumbnail.
  5037.          IHDR 96 96 4 3 0 0 0
  5038.          IDAT
  5039.          IEND
  5040.          eXPI 1 "thumbnail 2"
  5041.          DISC           # Discard the thumbnail image.
  5042.  
  5043.          FRAM 4 "Two views of the data"
  5044.          DEFI 1 0 1 6 6     # Define first (bottom) image.
  5045.          IHDR 500 500 16 0 .. # A 16-bit graylevel image.
  5046.          gAMA 50000
  5047.          IDAT ...
  5048.          IEND                 # End of image.
  5049.  
  5050.          CLON 1 2 0 0 1 0 518 6 # Make a full "concrete" clone.
  5051.          DHDR 2 1 7           #  Modify it (no change to pixels).
  5052.          ORDR faLT 2          #  Establish chunk placement.
  5053.          gAMA 100000   # Gamma value is 100000 (gamma=1.0).
  5054.          tEXtComment\0The faLT chunk is described in ftp://swrinde...
  5055.          faLT ...             # Apply pseudocolor to parent image.
  5056.          IEND                 # End of image.
  5057.          DEFI 3 0 0 900 400   # Overlay near lower right-hand corner.
  5058.          IHDR 101 101 2 3 ...
  5059.          gAMA 50000           # We need a new gAMA because
  5060.          PLTE ...             # this is not a Delta-PNG datastream.
  5061.          tRNS ...             # It is transparent (maybe a logo).
  5062.          IDAT ...             # Note that the color type can differ
  5063.          IDAT ...             # from that of the other images.
  5064.          IEND                 # End of image.
  5065.  
  5066.          MEND                 # End of MNG datastream.
  5067.  
  5068.    15.7. Example 7: Movie with sprites
  5069.  
  5070.       Here is another movie, illustrating the use of Delta-PNG
  5071.       datastreams as sprites:
  5072.  
  5073.          \212 M N G \r \n ^z \n  # MNG signature.
  5074.          MHDR 512 512 30  # Start of MNG datastream.
  5075.          FRAM 2 "frame 1" 0  2 0 0 0  3 # First frame
  5076.                           # sets frame_duration=3 ticks.
  5077.          DEFI 1           # Define image 1 (abstract, LOCA 0 0).
  5078.          IHDR 512 512 ... # It is a full-display PNG image.
  5079.          etc              # Chunks according to PNG spec.
  5080.          IEND             # SHOW 1 is implied by DEFI 1.
  5081.          DEFI 2 0 1 300 200 # Define image 2, concrete.
  5082.          IHDR 32 32 ...   # It is a small PNG.
  5083.          gAMA 50000
  5084.          IDAT ...
  5085.          IEND
  5086.          FRAM 0 "frame 2"   # Start new frame.
  5087.                           # New location for image 1 is still 0,0.
  5088.          SHOW 1           # Display image 1 from previous frame.
  5089.          MOVE 2 2 1 10 5  # New (delta) location for image 2.
  5090.          SHOW 2           # Retrieve image 2 from previous frame,
  5091.          CLON 2 3 0 0 1   # make a full clone of it as image 3.
  5092.               0 400 500   # Location for image 3.
  5093.          DHDR 3 1 7 0 0 0 0 # Modify image 3 (no change to pixels).
  5094.          tRNS ...         # Make it semitransparent.
  5095.          IEND             # SHOW 3 is implied by CLON visibility.
  5096.          FRAM 0 "frame 3" # Next frame (repeat this FRAM-SHOW 1 3
  5097.                           #   sequence with different locations to
  5098.                           #   move the images around).
  5099.                           # New location for image 1 is still 0,0.
  5100.          MOVE 2 2 1 10 5  # New (delta) location for image 2.
  5101.          MOVE 3 3 1 5 -2  # New location for image 3.
  5102.          SHOW 1 3         # Show images 1 through 3.
  5103.          FRAM 0 "frame 4" # Another frame.
  5104.          etc.
  5105.          FRAM 0 "frame 99"
  5106.          etc.             # More frames.
  5107.          MEND             # End of MNG datastream.
  5108.  
  5109.    15.8. Example 8: Movie with an animated sprite
  5110.  
  5111.       This movie illustrates the use of several abstract images with
  5112.       Show_mode=6 to describe an animated sprite, and the PAST chunk to
  5113.       turn it around.  The sprite runs back and forth across the
  5114.       background ten times.  The FRAM clipping boundaries restrict the
  5115.       screen updates to the small region that changes, with a little
  5116.       "wiggle room" to make sure the disturbed part of the background
  5117.       gets updated.
  5118.  
  5119.          \212 M N G \r \n ^z \n  # MNG signature.
  5120.          MHDR 512 512 30  # Start of MNG datastream.
  5121.          FRAM 2 "frame 1" 0  2 0 0 0  3 # First frame.
  5122.          DEFI 1 IHDR 512 512 ... # Background PNG image.
  5123.          etc ... IEND     # Chunks according to PNG spec.
  5124.  
  5125.          DEFI 10 1 0 x0 y0 # Static part of sprite.
  5126.          IHDR 64 64 ...  IDAT ...  IEND
  5127.          DEFI 11 1 0 x0 y1 # View 1 of animated part.
  5128.          IHDR 64 32 ...  IDAT ...  IEND # (y1=y0+64)
  5129.          DEFI 12 1 0 x0 y1 # View 2 of animated part.
  5130.          IHDR 64 32 ...  IDAT ...  IEND
  5131.          DEFI 13 1 0 x0 y1 # View 3 of animated part.
  5132.          IHDR 64 32 ...  IDAT ...  IEND
  5133.  
  5134.          FRAM 0  0  0 0 2 0  0 x0-dx x0+64+dx y0-dy y1+32+dy
  5135.          LOOP 0 0 10
  5136.          LOOP 1 0 150
  5137.          FRAM 0 "left-to-right" 0 0 2 0 1 dx dx dy dy
  5138.          MOVE 10 13 1 dx dy # Move animated icon {dx, dy}.
  5139.          SHOW  1 SHOW 10    # Show background and static part.
  5140.          SHOW 11 13 6       # Select the next view of the
  5141.          ENDL 1             # animated part and show it.
  5142.  
  5143.          FRAM SHOW 1
  5144.          PAST 10  0 0 0  10  1 4  0 0 0  0 0 64 64
  5145.          PAST 11  0 0 0  11  1 4  0 0 0  0 0 64 32
  5146.          PAST 12  0 0 0  12  1 4  0 0 0  0 0 64 32
  5147.          PAST 13  0 0 0  13  1 4  0 0 0  0 0 64 32
  5148.          LOOP 1 0 150
  5149.          FRAM 0 "right-to-left" 0 0 2 0 1 -dx -dx -dy -dy
  5150.          MOVE 10 13 1 -dx -dy # Move animated icon {-dx, -dy}.
  5151.          SHOW  1 SHOW 10    # Show background and static part.
  5152.          SHOW 11 13 6       # Select the next view of the
  5153.          ENDL 1             # animated part and show it.
  5154.          ENDL 0 FRAM
  5155.          MEND
  5156.  
  5157.    15.9. Example 9: "Fading in" a transparent image
  5158.  
  5159.       The opaque parts of this image will "fade in" gradually.  This
  5160.       example also illustrates the use of the PPLT and fPRI chunks.
  5161.  
  5162.          \212 M N G \r \n ^z \n # MNG signature.
  5163.          MHDR 64 64 30     # Width, height, ticklength.
  5164.          BACK 52800 52800 52800 # "Browser gray" default background.
  5165.  
  5166.          FRAM 3 0  2 0 0 0  3 #  Set frame_duration=3 ticks.  Use
  5167.                      # framing mode 3 so background gets restored.
  5168.          DEFI 1 1 1  # Invisible and "concrete".
  5169.          IHDR ...    # PNG header.
  5170.          PLTE ...
  5171.          tRNS 0      # Entries are zero for the transparent (0)
  5172.                      # color and 255 for the nontransparent ones.
  5173.          IDAT ...
  5174.          IEND
  5175.          fPRI 0 0    # Give the fade-in sequence a low priority.
  5176.          CLON 1 2 1  # Make a working concrete copy of the image
  5177.                      # that will be modified during the low-priority
  5178.                      # part of the datastream.  It is a full clone.
  5179.          DHDR 2 1 7  # No change to pixel data.
  5180.          tRNS 0 0 0 0 0 0 ...  # Make all pixels fully transparent.
  5181.          IEND
  5182.          SHOW 2 2 3  # Make it visible but don't show it now.
  5183.  
  5184.          LOOP 0 0 15
  5185.          DHDR 2 1 7  # An image delta.
  5186.                      # Delta-type 7 means no change to pixels.
  5187.          PPLT 1 10 3 16 16 16 16 ... # Increment all alphas except
  5188.          IEND                        # for entry 0 by 16.
  5189.          SHOW 2
  5190.          ENDL 0      # Nontransparent pixel alpha=15, 31, ... 240.
  5191.  
  5192.          DISC 2      # Discard the working copy.
  5193.          fPRI 0 255  # Give the final frame the highest value
  5194.          FRAM 0 0  1 0 0 0  60 # Hold the last frame for at least
  5195.            # 60 ticks (2 sec).  Applications might show it longer.
  5196.          SHOW 1      # This copy still has alpha=255 for the
  5197.                      # opaque pixels and alpha=0 for the others.
  5198.          MEND        # End of MNG.
  5199.  
  5200.    15.10. Example 10: Storing three-dimensional images
  5201.  
  5202.       In this example, we store a series of twenty-four 150 x 150 x 150
  5203.       blocks of eight-bit voxels.  Each block is stored as a composite
  5204.       frame with the first image being a PNG whose pixels represent the
  5205.       top layer of voxels, which is followed by 149 Delta-PNG images
  5206.       representing the rest of the layers of voxels.  Only one image is
  5207.       defined, through which the parent image is passed along from PNG
  5208.       to Delta-PNG to Delta-PNG.  This example also illustrates the use
  5209.       of unregistered ancillary chunks that describe the x, y, and z
  5210.       scales and pixel calibration.
  5211.  
  5212.          \212 M N G \r \n ^z \n # MNG signature.
  5213.          MHDR 150 150 1   # Width, height, ticklength.
  5214.  
  5215.          tEXtTitle\0Weather modeling results
  5216.          tEXtComment\0The xxSC, yySC, zzSC, and ttSC chunks
  5217.           in this file are written according to the Proposed
  5218.           chunk specifications version 19970203 and Sci-Vis
  5219.           chunks specification version 19970203 available at
  5220.           ftp://swrinde.nde.swri.edu/pub/png-group/documents/
  5221.          xxSC kch\0 [sig\0] kilometers\0 0\0 150
  5222.          yySC kch\0 [sig\0] kilometers\0 0\0 150
  5223.          zzSC kch\0 [sig\0] Height (kilometers)\0 0\0 15
  5224.          ttSC kch\0 [sig\0] Time (hours)\0 0\0 24
  5225.          pCAL kch\0 0 255 0 2 Degrees Celsius\0 0\0 45
  5226.          DEFI 1 0 1       # All images will have image = 1
  5227.          SAVE             # and be visible and "concrete".
  5228.          SEEK
  5229.          FRAM 2      # Initial composite image.
  5230.          IHDR 150 150 16  # Width, height, bit depth for top layer.
  5231.               0 0 0 0     # Color, comp, filter, interlace.
  5232.          IDAT ...
  5233.          IEND             # No DEFI chunk, so it is image 0.
  5234.          DHDR 1 1 0       # Source=0, PNG, pixel addition,
  5235.               150 150 0 0 # Block is entire image.
  5236.          IDAT ...     # IHDR is omitted; everything matches top.
  5237.          IEND         # IEND is also omitted.
  5238.          etc.         # Repeat DHDR through IEND 148 more times.
  5239.          SEEK
  5240.          FRAM         # End of first block.
  5241.          etc.         # Repeat FRAM through SEEK 19 more times.
  5242.          SEEK
  5243.          MEND         # End of MNG.
  5244.  
  5245.    15.11. Example 11: Tiling
  5246.  
  5247.       Here is another composite frame, illustrating the use of the LOOP
  5248.       syntax to tile a large (1024 by 768) image area with a small (128
  5249.       by 64) image.
  5250.  
  5251.          \212 M N G \r \n ^z \n  # MNG signature.
  5252.          MHDR 1024 768 0 # Start of MNG datastream.
  5253.          FRAM 2
  5254.          DEFI 1 1 0 0 -64 # Set up an offscreen "abstract" copy
  5255.          IHDR 128 64 ... PLTE ... IDAT ... IEND  # of the tile.
  5256.          LOOP 0 0 12   # Y loop -- make 12 rows of tiles.
  5257.          MOVE 1 1 1 0 64 # Move the first copy down 64 rows.
  5258.          SHOW 1        # Display it.
  5259.          CLON 1 2 1    # Create a partial clone of the tile.
  5260.          LOOP 1 0 7    # X loop - 7 additional columns.
  5261.          MOVE 2 2 1 0 128 # Move it to the right 128 columns.
  5262.          SHOW 2        # Use the second copy.
  5263.          ENDL 1
  5264.          ENDL 0
  5265.          MEND
  5266.  
  5267.       Here is a better approach, which creates a reusable tiled image by
  5268.       means of the PAST chunk.
  5269.  
  5270.          \212 M N G \r \n ^z \n  # MNG signature.
  5271.          MHDR 1024 768 0 # Start of MNG datastream.
  5272.          DEFI 1 1 # Set up an offscreen "abstract" copy
  5273.          IHDR 128 64 ...  PLTE ... IDAT ... IEND  # of the tile.
  5274.          DEFI 2        # The abstract, visible, viewable image to
  5275.          BASI 1024 768 8 2 0 0 0 0 0 0 0 1 #  be tiled.  Initially
  5276.          IEND          # all pixels are zero.
  5277.          PAST 2 0 0 0  # Destination and target location.
  5278.            # src mod orient  offset        clipping
  5279.               1   0    8     0   0 512   0 0 1024 0 768
  5280.            #  End of PAST chunk data.
  5281.          MEND
  5282.  
  5283.    15.12. Example 12: Scrolling
  5284.  
  5285.       Here is an example of scrolling a 3000-line-high image (perhaps an
  5286.       image of some text, but could be anything) through a 256-line-high
  5287.       window with an alpha-blended border.
  5288.  
  5289.          \212 M N G \r \n ^z \n  # MNG signature.
  5290.          MHDR 512 256 30   # Width and height on screen.
  5291.          BACK 50000 50000 50000 0 #  advisory gray background
  5292.          DEFI 1 1 0 0 256  # Define image 1 but don't display now.
  5293.                            # Initially it is offscreen, just
  5294.                            # below the 512 by 256 window.
  5295.          IHDR 512 3000 1 0 ... # A PNG datastream containing the
  5296.          PLTE ...          # text (or whatever) to be scrolled.
  5297.          IDAT ...
  5298.          IEND
  5299.  
  5300.          DEFI 2
  5301.          IHDR 512 256 8 6 ... # A PNG datastream containing some kind
  5302.          PLTE ...             # of alpha-blended border that is
  5303.          tRNS ...             # transparent in the center.
  5304.          IDAT ...
  5305.          IEND
  5306.  
  5307.          LOOP 0 0 3256
  5308.          MOVE 1 1 1 0 -1 # Jack image 1 up one scanline, 3256 times.
  5309.                     # It ends up just above the 512 by 256 window.
  5310.                     # The border does not move.
  5311.          FRAM 1  0  2 0 0 0  0 # Frame_duration = 0 ticks.
  5312.                     # We use Framing_mode=1 to avoid unnecessary
  5313.                     # screen clearing between frames.
  5314.          SHOW 1     # Show first image and continue without delay.
  5315.          FRAM 1  0  2 0 0 0  1 # Frame_duration = 1 tick.
  5316.          SHOW 2     # Composite second image over first, wait 1 tick.
  5317.          ENDL 0
  5318.          MEND
  5319.  
  5320.       Alternatively, we can declare the scrolling object to be the
  5321.       background and use framing-mode 3:
  5322.  
  5323.                          (Same as above down to the LOOP chunk.)
  5324.          BACK 50000 50000 50000 2 1 #  Advisory gray background.
  5325.                                     #  Mandatory image background.
  5326.          FRAM 3  0  2 0 0 0  1 # Frame_duration = 1 tick.
  5327.          LOOP 0 0 3256
  5328.          MOVE 1 1 1 0 -1 # Jack background up one scanline, 3256 times.
  5329.          SHOW 2     # Composite the second image over it, wait 1 tick.
  5330.          ENDL 0
  5331.          MEND
  5332.  
  5333.    15.13. Example 13: Converting a GIF animation to MNG
  5334.  
  5335.       Outline of a program to convert GIF animations to MNG format:
  5336.  
  5337.          begin
  5338.              write "MHDR" and "BACK" chunks
  5339.              saved_images := 0
  5340.              Frame_duration := 0
  5341.              First_frame := TRUE
  5342.              if(loops>1) "write tERm 2 0 0 loops" chunk
  5343.              for subimage in gif89a file do
  5344.                 if(Frame_duration != gif_duration) then
  5345.                   Frame_duration := gif_duration
  5346.                   write "FRAM 4 0 2 2 0 2 0 Frame_duration 0" chunk
  5347.                   First_frame := FALSE
  5348.                 else if(First_frame == TRUE)then
  5349.                   write "FRAM 4" chunk
  5350.                   First_frame := FALSE
  5351.                 else
  5352.                   write "FRAM" chunk
  5353.                 endif
  5354.                 if(X_loc == 0 AND Y_loc == 0) then
  5355.                    write "DEFI saved_images 1 1" chunk
  5356.                 else
  5357.                    write "DEFI saved_images 1 1 X_loc Y_loc" chunk
  5358.                 write "<image>"
  5359.                 write "SHOW 0 saved_images" chunk
  5360.                 if (gif_disposal_method == 0
  5361.                    OR gif_disposal_method == 2) then
  5362.                    /* (undefined or restore background) */
  5363.                       write "DISC" chunk
  5364.                       saved_images := 0
  5365.                 else if (gif_disposal_method == 1) then
  5366.                    /* (keep) */
  5367.                    saved_images := saved_images + 1
  5368.                 else if (gif_disposal_method == 3) then
  5369.                    /* (restore previous) */
  5370.                    write "DISC saved_images" chunk
  5371.                 endif
  5372.              endfor
  5373.              write "FRAM" and "MEND" chunks
  5374.          end
  5375.  
  5376.       Where "<image>" represents a PNG or Delta-PNG containing a GIF
  5377.       frame converted to PNG format.
  5378.  
  5379.       Caution: if you write such a program, you might have to pay
  5380.       royalties in order to convey it to anyone else.
  5381.  
  5382. 16. Credits
  5383.  
  5384.    Editor
  5385.  
  5386.           * Glenn Randers-Pehrson (PNG 1.1), randeg @ alumni.rpi.edu
  5387.  
  5388.    Contributors
  5389.  
  5390.       Contributors' names are presented in alphabetical order:
  5391.  
  5392.           * Mark Adler, madler @ alumni.caltech.edu
  5393.           * Thomas Boutell, boutell @ boutell.com
  5394.           * John Bowler, jbowler @ acm.org
  5395.           * Christian Brunschen, cb @ df.lth.se
  5396.           * Glen Chapman, glenc @ clark.net
  5397.           * Adam M. Costello, amc @ cs.berkeley.edu
  5398.           * Lee Daniel Crocker, lee @ piclab.com
  5399.           * Peter da Silva, peter @ starbase.neosoft.com
  5400.           * Andreas Dilger, adilger @ enel.ucalgary.ca
  5401.           * Oliver Fromme, oliver @ fromme.com
  5402.           * Jean-loup Gailly, jloup @ gzip.org
  5403.           * Chris Herborth, chrish @ qnx.com
  5404.           * Alex Jakulin, Aleks.Jakulin @ snet.fri.uni-lj.si
  5405.           * Gerard Juyn, gjuyn @ xs4all.nl
  5406.           * Neal Kettler, neal @ westwood.com
  5407.           * Tom Lane, tgl @ sss.pgh.pa.us
  5408.           * Alexander Lehmann, alex @ hal.rhein-main.de
  5409.           * Chris Lilley, chris @ w3.org
  5410.           * Dave Martindale, davem @ cs.ubc.ca
  5411.           * Carl Morris, msftrncs @ htcnet.com
  5412.           * Owen Mortensen, ojm @ acm.org
  5413.           * Josh M. Osborne, stripes @ va.pubnix.com
  5414.           * Keith S. Pickens, ksp @ swri.edu
  5415.           * Glenn Randers-Pehrson, randeg @ alumni.rpi.edu
  5416.           * Nancy M. Randers-Pehrson, randeg @ alumni.rpi.edu
  5417.           * Greg Roelofs, newt @ pobox.com
  5418.           * Willem van Schaik, willem @ schaik.com
  5419.           * Guy Schalnat, gschal @ infinet.com
  5420.           * Paul Schmidt, pschmidt @ photodex.com
  5421.           * Smarry Smarasderagd, smar @ reptiles.org
  5422.           * Thomas R. Tanner, ttehtann @ argonet.co.uk
  5423.           * Guido Vollbeding, guivol @ esc.de
  5424.           * Tim Wegner, twegner @ phoenix.net
  5425.           * Alaric B. Williams, png @ abwillms.demon.co.uk
  5426.  
  5427.    Trademarks
  5428.  
  5429.           * GIF is a service mark of CompuServe Incorporated.
  5430.  
  5431.           * PostScript is a trademark of Adobe Systems.
  5432.  
  5433.           * X Window System is a trademark of the Massachusetts
  5434.             Institute of Technology.
  5435.  
  5436.    Document source
  5437.  
  5438.       This document was built from the file mng-master-19990202 on
  5439.       02 February 1999.
  5440.  
  5441.    Copyright Notice
  5442.  
  5443.       Copyright (c) 1998, 1999 by:  Glenn Randers-Pehrson
  5444.  
  5445.       This specification is being provided by the copyright holder under
  5446.       the following license.  By obtaining, using and/or copying this
  5447.       specification, you agree that you have read, understood, and will
  5448.       comply with the following terms and conditions:
  5449.  
  5450.       Permission to use, copy, and distribute this specification for any
  5451.       purpose and without fee or royalty is hereby granted, provided
  5452.       that the full text of this NOTICE appears on ALL copies of the
  5453.       specification or portions thereof, including modifications, that
  5454.       you make.
  5455.  
  5456.       THIS SPECIFICATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDER MAKES
  5457.       NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.  BY WAY OF
  5458.       EXAMPLE, BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO
  5459.       REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR
  5460.       ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SPECIFICATION WILL
  5461.       NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR
  5462.       OTHER RIGHTS.  COPYRIGHT HOLDER WILL BEAR NO LIABILITY FOR ANY USE
  5463.       OF THIS SPECIFICATION.
  5464.  
  5465.       The name and trademarks of copyright holder may NOT be used in
  5466.       advertising or publicity pertaining to the specification without
  5467.       specific, written prior permission.  Title to copyright in this
  5468.       specification and any associated documentation will at all times
  5469.       remain with copyright holder.
  5470.  
  5471. End of MNG Specification.
  5472.  
  5473.  
  5474.