home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / formats / anim / animspec.880 < prev   
Internet Message Format  |  1989-03-02  |  25KB

  1. From: baer@percival.UUCP (Ken Baer)
  2. Subject: New ANIM specs
  3. Date: 30 Apr 88 18:57:12 GMT
  4. Organization: Percy's UNIX, Portland, OR.
  5.  
  6.  
  7. Here is the latest OFFICIAL version of the ANIM standard.  This document
  8. was posted on BIX by Carolyn Scheppner last week.  It was written in the most
  9. part by Gary Bonham.  After talking with Gary the other day, there are a
  10. few errors which I corrected (indicated by [KB]).  If you are planning on
  11. writing software to read and write ANIM files, plan to read OP 3 and OP5,
  12. and write OP 5.  If you want to read or write Byte-by-Byte (Scupt/Animate 3D)
  13. files, you're out of luck.  They are still keeping their format to themselves.
  14. If you are writing an animation program and would like to support their
  15. format (especially as input), give them a call and let them know.  Maybe
  16. enough people will bug them to convince them to change their minds.
  17.  
  18.         -Ken Baer.
  19.  
  20. ------------------------------------------------------------------------
  21.  
  22.                               A N I M
  23.                   An IFF Format For CEL Animations
  24.  
  25.                     Revision date:  17 March 1988
  26.  
  27.                      prepared by:
  28.                           SPARTA Inc.
  29.                           23041 de la Carlota
  30.                           Laguna Hills, Calif 92653
  31.                           714) 768-8161
  32.                           contact: Gary Bonham
  33.  
  34.                      also by:
  35.                           Aegis Development Co.
  36.                           2115 Pico Blvd.
  37.                           Santa Monica, Calif 90405
  38.                           213) 392-9972
  39.  
  40.  
  41. 1.0 Introduction
  42.  
  43.    The ANIM IFF format was developed at Sparta originally for the
  44.    production of animated video sequences on the Amiga computer.  The
  45.    intent was to be able to store, and play back, sequences of frames
  46.    and to minimize both the storage space on disk (through compression)
  47.    and playback time (through efficient de-compression algorithms).
  48.    It was desired to maintain maximum compatibility with existing
  49.    IFF formats and to be able to display the initial frame as a normal
  50.    still IFF picture.
  51.  
  52.    Several compression schemes have been introduced in the ANIM format.
  53.    Most of these are strictly of historical interest as the only one
  54.    currently being placed in new code is the vertical run length
  55.    encoded byte encoding developed by Jim Kent.
  56.  
  57.    1.1 ANIM Format Overview
  58.  
  59.       The general philosophy of ANIMs is to present the initial frame
  60.       as a normal, run-length-encoded, IFF picture.  Subsequent
  61.       frames are then described by listing only their differences
  62.       from a previous frame.  Normally, the "previous" frame is two
  63.       frames back as that is the frame remaining in the hidden
  64.       screen buffer when double-buffering is used.  To better
  65.       understand this, suppose one has two screens, called A and B,
  66.       and the ability to instantly switch the display from one to
  67.       the other.  The normal playback mode is to load the initial
  68.       frame into A and duplicate it into B.  Then frame A is displayed
  69.       on the screen.  Then the differences for frame 2 are used to
  70.       alter screen B and it is displayed.  Then the differences for
  71.       frame 3 are used to alter screen A and it is displayed, and so
  72.       on.  Note that frame 2 is stored as differences from frame 1,
  73.       but all other frames are stored as differences from two frames
  74.       back.
  75.  
  76.       ANIM is an IFF FORM and its basic format is as follows (this
  77.       assumes the reader has a basic understanding of IFF format
  78.       files):
  79.                       FORM ANIM
  80.                       . FORM ILBM         first frame
  81.                       . . BMHD                normal type IFF data
  82.                       . . ANHD                optional animation header
  83.                                               chunk for timing of 1st frame.
  84.                       . . CMAP
  85.                       . . BODY
  86.                       . FORM ILBM         frame 2
  87.                       . . ANHD                animation header chunk
  88.                       . . DLTA                delta mode data
  89.                       . FORM ILBM         frame 3
  90.                       . . ANHD
  91.                       . . DLTA
  92.                            ...
  93.  
  94.       The initial FORM ILBM can contain all the normal ILBM chunks,
  95.       such as CRNG, etc.  The BODY will normally be a standard
  96.       run-length-encoded data chunk (but may be any other legal
  97.       compression mode as indicated by the BMHD).  If desired, an ANHD
  98.       chunk can appear here to provide timing data for the first
  99.       frame.  If it is here, the operation field should be =0.
  100.  
  101.       The subsequent FORMs ILBM contain an ANHD, instead of a BMHD,
  102.       which duplicates some of BMHD and has additional parameters
  103.       pertaining to the animation frame.  The DLTA chunk contains
  104.       the data for the delta compression modes.  If
  105.       the older XOR compression mode is used, then a BODY chunk
  106.       will be here.  In addition, other chunks may be placed in each
  107.       of these as deemed necessary (and as code is placed in player
  108.       programs to utilize them).  A good example would be CMAP chunks
  109.       to alter the color palette.  A basic assumption in ANIMs is
  110.       that the size of the bitmap, and the display mode (e.g. HAM)
  111.       will not change through the animation.  Take care when playing
  112.       an ANIM that if a CMAP occurs with a frame, then the change must
  113.       be applied to both buffers.
  114.  
  115.       Note that the DLTA chunks are not interleaved bitmap representations,
  116.       thus the use of the ILBM form is inappropriate for these frames.
  117.       However, this inconsistency was not noted until there were a number
  118.       of commercial products either released or close to release which
  119.       generated/played this format.  Therefore, this is probably an
  120.       inconsistency which will have to stay with us.
  121.  
  122.    1.2 Recording ANIMs
  123.  
  124.       To record an ANIM will require three bitmaps - one for
  125.       creation of the next frame, and two more for a "history" of the
  126.       previous two frames for performing the compression calculations
  127.       (e.g. the delta mode calculations).
  128.  
  129.       There are five frame-to-frame compression methods currently
  130.       defined.  The first three are mainly for historical interest.
  131.       The product Aegis VideoScape 3D utilizes the third method in
  132.       version 1.0, but switched to method 5 on 2.0 [KB].  This is
  133.       the only instance known of a commercial product generating
  134.       ANIMs of any of the first three methods.  The fourth method
  135.       is a general short or long word compression scheme which has
  136.       several options including whether the compression is horizontal
  137.       or vertical, and whether or not it is XOR format.  This offers
  138.       a choice to the user for the optimization of file size and/or
  139.       playback speed.  The fifth method is the byte vertical run length
  140.       encoding as designed by Jim Kent.  Do not confuse
  141.       this with Jim's RIFF file format which is different than ANIM.
  142.       Here we utilized his compression/decompression routines within the
  143.       ANIM file structure.
  144.  
  145.       The following paragraphs give a general outline of each of the
  146.       methods of compression currently included in this spec.
  147.  
  148.       1.2.1 XOR mode
  149.  
  150.          This mode is the original and is included here for historical
  151.          interest.  In general, the delta modes are far superior.
  152.          The creation of XOR mode is quite simple.  One simply
  153.          performs an exclusive-or (XOR) between all corresponding
  154.          bytes of the new frame and two frames back.  This results
  155.          in a new bitmap with 0 bits wherever the two frames were
  156.          identical, and 1 bits where they are different.  Then this
  157.          new bitmap is saved using run-length-encoding.  A major
  158.          obstacle of this mode is in the time consumed in performing
  159.          the XOR upon reconstructing the image.
  160.  
  161.       1.2.2 Long Delta mode
  162.  
  163.          This mode stores the actual new frame long-words which are
  164.          different, along with the offset in the bitmap.  The
  165.          exact format is shown and discussed in section 2 below.
  166.          Each plane is handled separately, with no data being saved
  167.          if no changes take place in a given plane.  Strings of
  168.          2 or more long-words in a row which change can be run
  169.          together so offsets do not have to be saved for each one.
  170.  
  171.          Constructing this data chunk usually consists of having
  172.          a buffer to hold the data, and calculating the data as
  173.          one compares the new frame, long-word by long-word, with
  174.          two frames back.
  175.  
  176.       1.2.3 Short Delta mode
  177.  
  178.          This mode is identical to the Long Delta mode except that
  179.          short-words are saved instead of long-words.  In most
  180.          instances, this mode results in a smaller DLTA chunk.
  181.          The Long Delta mode is mainly of interest in improving
  182.          the playback speed when used on a 32-bit 68020 Turbo Amiga.
  183.  
  184.       1.2.4 General Delta mode
  185.  
  186.          The above two delta compression modes were hastily put together.
  187.          This mode was an attempt to provide a well-thought-out delta
  188.          compression scheme.  Options provide for both short and long
  189.          word compression, either vertical or horizontal compression,
  190.          XOR mode (which permits reverse playback), etc.  About the time
  191.          this was being finalized, the fifth mode, below, was developed
  192.          by Jim Kent.  In practice the short-vertical-run-length-encoded
  193.          deltas in this mode play back faster than the fifth mode (which
  194.          is in essence a byte-vertical-run-length-encoded delta mode) but
  195.          does not compress as well - especially for very noisy data such
  196.          as digitized images.  In most cases, playback speed not being
  197.          terrifically slower, the better compression (sometimes 2x) is
  198.          preferable due to limited storage media in most machines.
  199.  
  200.          Details on this method are contained in section 2.2.2 below.
  201.  
  202.       1.2.5 Byte Vertical Compression
  203.  
  204.          This method does not offer the many options that method 4 offers,
  205.          but is very successful at producing decent compression even for
  206.          very noisy data such as digitized images.  The method was devised
  207.          by Jim Kent and is utilized in his RIFF file format which is
  208.          different than the ANIM format.  The description of this method
  209.          in this document is taken from Jim's writings.  Further, he has
  210.          released both compression and decompression code to public domain.
  211.  
  212.          Details on this method are contained in section 2.2.3 below.
  213.  
  214.    1.3 Playing ANIMs
  215.  
  216.       Playback of ANIMs will usually require two buffers, as mentioned
  217.       above, and double-buffering between them.  The frame data from
  218.       the ANIM file is used to modify the hidden frame to the next
  219.       frame to be shown.  When using the XOR mode, the usual run-
  220.       length-decoding routine can be easily modified to do the
  221.       exclusive-or operation required.  Note that runs of zero bytes,
  222.       which will be very common, can be ignored, as an exclusive or
  223.       of any byte value to a byte of zero will not alter the original
  224.       byte value.
  225.  
  226.       The general procedure, for all compression techniques, is to first
  227.       decode the initial ILBM picture into the hidden buffer and double-
  228.       buffer it into view.  Then this picture is copied to the other (now
  229.       hidden) buffer.  At this point each frame is displayed with the
  230.       same procedure.  The next frame is formed in the hidden buffer by
  231.       applying the DLTA data (or the XOR data from the BODY chunk in the
  232.       case of the first XOR method) and the new frame is double-buffered
  233.       into view.  This process continues to the end of the file.
  234.  
  235.       A master colormap should be kept for the entire ANIM which would
  236.       be initially set from the CMAP chunk in the initial ILBM.  This
  237.       colormap should be used for each frame.  If a CMAP chunk appears
  238.       in one of the frames, then this master colormap is updated and the
  239.       new colormap applies to all frames until the occurrance of another
  240.       CMAP chunk.
  241.  
  242.       Looping ANIMs may be constructed by simply making the last two frames
  243.       identical to the first two.  Since the first two frames are special
  244.       cases (the first being a normal ILBM and the second being a delta from
  245.       the first) one can continually loop the anim by repeating from frame
  246.       three.  In this case the delta for creating frame three will modify
  247.       the next to the last frame which is in the hidden buffer (which is
  248.       identical to the first frame), and the delta for creating frame four
  249.       will modify the last frame which is identical to the second frame.
  250.  
  251.       Multi-File ANIMs are also supported so long as the first two frames
  252.       of a subsequent file are identical to the last two frames of the
  253.       preceeding file.  Upon reading subsequent files, the ILBMs for the
  254.       first two frames are simply ignored, and the remaining frames are
  255.       simply appended to the preceeding frames.  This permits splitting
  256.       ANIMs across multiple floppies and also permits playing each section
  257.       independently and/or editing it independent of the rest of the ANIM.
  258.  
  259.       Timing of ANIM playback is easily achieved using the vertical blank
  260.       interrupt of the Amiga.  There is an example of setting up such
  261.       a timer in the ROM Kernel Manual.  Be sure to remember the timer
  262.       value when a frame is flipped up, so the next frame can be flipped
  263.       up relative to that time.  This will make the playback independent
  264.       of how long it takes to decompress a frame (so long as there is enough
  265.       time between frames to accomplish this decompression).
  266.  
  267. 2.0 Chunk Formats
  268.    2.1 ANHD Chunk
  269.       The ANHD chunk consists of the following data structure:
  270.  
  271.            UBYTE operation  The compression method:
  272.                             =0 set directly (normal ILBM BODY),
  273.                             =1 XOR ILBM mode,
  274.                             =2 Long Delta mode,
  275.                             =3 Short Delta mode,
  276.                             =4 Generalized short/long Delta mode,
  277.                             =5 [KB] Byte Vertical Delta mode
  278.                             =74 (ascii 'J') reserved for Eric Graham's
  279.                                compression technique (details to be
  280.                                released later).
  281.  
  282.            UBYTE mask      (XOR mode only - plane mask where each
  283.                             bit is set =1 if there is data and =0
  284.                             if not.)
  285.            UWORD w,h       (XOR mode only - width and height of the
  286.                             area represented by the BODY to eliminate
  287.                             unnecessary un-changed data)
  288.            WORD  x,y       (XOR mode only - position of rectangular
  289.                             area representd by the BODY)
  290.            ULONG abstime   (currently unused - timing for a frame
  291.                             relative to the time the first frame
  292.                             was displayed - in jiffies (1/60 sec))
  293.            ULONG reltime   (timing for frame relative to time
  294.                             previous frame was displayed - in
  295.                             jiffies (1/60 sec))
  296.            UBYTE interleave (unused so far - indicates how may frames
  297.                              back this data is to modify.  =0 defaults
  298.                              to indicate two frames back (for double
  299.                              buffering). =n indicates n frames back.
  300.                              The main intent here is to allow values
  301.                              of =1 for special applications where
  302.                              frame data would modify the immediately
  303.                              previous frame)
  304.            UBYTE pad0        Pad byte, not used at present.
  305.            ULONG bits        32 option bits used by options=4 and 5.
  306.                              At present only 6 are identified, but the
  307.                              rest are set =0 so they can be used to
  308.                              implement future ideas.  These are defined
  309.                              for option 4 only at this point.  It is
  310.                              recommended that all bits be set =0 for
  311.                              option 5 and that any bit settings
  312.                              used in the future (such as for XOR mode)
  313.                              be compatible with the option 4
  314.                              bit settings.   Player code should check
  315.                              undefined bits in options 4 and 5 to assure
  316.                              they are zero.
  317.  
  318.                              The six bits for current use are:
  319.  
  320.                              bit #              set =0               set =1
  321.                              ===============================================
  322.                              0              short data           long data
  323.                              1                 set                  XOR
  324.                              2             separate info        one info list
  325.                                            for each plane       for all planes
  326.                              3               not RLC        RLC (run length code
  327. d)
  328.                              4              horizontal           vertical
  329.                              5           short info offsets   long info offsets
  330.  
  331.            UBYTE pad[16]     This is a pad for future use for future
  332.                              compression modes.
  333.  
  334.    2.2 DLTA Chunk
  335.  
  336.       This chunk is the basic data chunk used to hold delta compression
  337.       data.  The format of the data will be dependent upon the exact
  338.       compression format selected.  At present there are two basic
  339.       formats for the overall structure of this chunk.
  340.  
  341.       2.2.1 Format for methods 2 & 3
  342.  
  343.          This chunk is a basic data chunk used to hold the delta
  344.          compression data.  The minimum size of this chunk is 32 bytes
  345.          as the first 8 long-words are byte pointers into the chunk for
  346.          the data for each of up to 8 bitplanes.  The pointer for the
  347.          plane data starting immediately following these 8 pointers will
  348.          have a value of 32 as the data starts in the 33-rd byte of the
  349.          chunk (index value of 32 due to zero-base indexing).
  350.  
  351.          The data for a given plane consists of groups of data words.  In
  352.          Long Delta mode, these groups consist of both short and long
  353.          words - short words for offsets and numbers, and long words for
  354.          the actual data.  In Short Delta mode, the groups are identical
  355.          except data words are also shorts so all data is short words.
  356.          Each group consists of a starting word which is an offset.  If
  357.          the offset is positive then it indicates the increment in long
  358.          or short words (whichever is appropriate) through the bitplane.
  359.          In other words, if you were reconstructing the plane, you would
  360.          start a pointer (to shorts or longs depending on the mode) to
  361.          point to the first word of the bitplane.  Then the offset would
  362.          be added to it and the following data word would be placed at
  363.          that position.  Then the next offset would be added to the
  364.          pointer and the following data word would be placed at that
  365.          position.  And so on...  The data terminates with an offset
  366.          equal to 0xFFFF.
  367.  
  368.          A second interpretation is given if the offset is negative.  In
  369.          that case, the absolute value is the offset+2.  Then the
  370.          following short-word indicates the number of data words that
  371.          follow.  Following that is the indicated number of contiguous
  372.          data words (longs or shorts depending on mode) which are to
  373.          be placed in contiguous locations of the bitplane.
  374.  
  375.          If there are no changed words in a given plane, then the pointer
  376.          in the first 32 bytes of the chunk is =0.
  377.  
  378.       2.2.2 Format for method 4
  379.  
  380.          The DLTA chunk is modified slightly to have 16 long pointers at
  381.          the start.  The first 8 are as before - pointers to the start of
  382.          the data for each of the bitplanes (up to a theoretical max of 8
  383.          planes).  The next 8 are pointers to the start of the offset/numbers
  384.          data list.  If there is only one list of offset/numbers for all
  385.          planes, then the pointer to that list is repeated in all positions
  386.          so the playback code need not even be aware of it.  In fact, one
  387.          could get fancy and have some bitplanes share lists while others
  388.          have different lists, or no lists (the problems in these schemes
  389.          lie in the generation, not in the playback).
  390.  
  391.          The best way to show the use of this format is in a sample playback
  392.          routine.
  393.  
  394.             SetDLTAshort(bm,deltaword)
  395.             struct BitMap *bm;
  396.             WORD *deltaword;
  397.             {
  398.                int i;
  399.                LONG *deltadata;
  400.                WORD *ptr,*planeptr;
  401.                register int s,size,nw;
  402.                register WORD *data,*dest;
  403.  
  404.                deltadata = (LONG *)deltaword;
  405.                nw = bm->BytesPerRow >>1;
  406.  
  407.                for (i=0;i<bm->Depth;i++) {
  408.                   planeptr = (WORD *)(bm->Planes[i]);
  409.                   data = deltaword + deltadata[i];
  410.                   ptr  = deltaword + deltadata[i+8];
  411.                   while (*ptr != 0xFFFF) {
  412.                      dest = planeptr + *ptr++;
  413.                      size = *ptr++;
  414.                      if (size < 0) {
  415.                         for (s=size;s<0;s++) {
  416.                            *dest = *data;
  417.                            dest += nw;
  418.                         }
  419.                         data++;
  420.                      }
  421.                      else {
  422.                         for (s=0;s<size;s++) {
  423.                            *dest = *data++;
  424.                            dest += nw;
  425.                         }
  426.                      }
  427.                   }
  428.                }
  429.                return(0);
  430.             }
  431.  
  432.          The above routine is for short word vertical compression with
  433.          run length compression.  The most efficient way to support
  434.          the various options is to replicate this routine and make
  435.          alterations for, say, long word or XOR.  The variable nw
  436.          indicates the number of words to skip to go down the vertical
  437.          column.  This one routine could easily handle horizontal
  438.          compression by simply setting nw=1.  For ultimate playback
  439.          speed, the core, at least, of this routine should be coded in
  440.          assembly language.
  441.  
  442.       2.2.2 Format for method 5
  443.  
  444.          In this method the same 16 pointers are used as in option 4.
  445.          The first 8 are pointers to the data for up to 8 planes.
  446.          The second set of 8 are not used but were retained for several
  447.          reasons.  First to be somewhat compatible with code for option
  448.          4 (although this has not proven to be of any benefit) and
  449.          second, to allow extending the format for more bitplanes (code
  450.          has been written for up to 12 planes).
  451.  
  452.          Compression/decompression is performed on a plane-by-plane basis.
  453.          For each plane, compression can be handled by the skip.c code
  454.          (provided Public Domain by Jim Kent) and decompression can be
  455.          handled by unvscomp.asm (also provided Public Domain by Jim Kent).
  456.  
  457.          Compression/decompression is performed on a plane-by-plane basis.
  458.          The following description of the method is taken directly from
  459.          Jim Kent's code with minor re-wording.  Please refer to Jim's
  460.          code (skip.c and unvscomp.asm) for more details:
  461.  
  462.             Each column of the bitplane is compressed separately.
  463.             A 320x200 bitplane would have 40 columns of 200 bytes each.
  464.             Each column starts with an op-count followed by a number
  465.             of ops.  If the op-count is zero, that's ok, it just means
  466.             there's no change in this column from the last frame.
  467.             The ops are of three classes, and followed by a varying
  468.             amount of data depending on which class:
  469.               1. Skip ops - this is a byte with the hi bit clear that
  470.                  says how many rows to move the "dest" pointer forward,
  471.                  ie to skip. It is non-zero.
  472.               2. Uniq ops - this is a byte with the hi bit set.  The hi
  473.                  bit is masked down and the remainder is a count of the
  474.                  number of bytes of data to copy literally.  It's of
  475.                  course followed by the data to copy.
  476.               3. Same ops - this is a 0 byte followed by a count byte,
  477.                  followed by a byte value to repeat count times.
  478.             Do bear in mind that the data is compressed vertically rather
  479.             than horizontally, so to get to the next byte in the destination
  480.             we add the number of bytes per row instead of one!
  481.  
  482. Read:
  483.  
  484. --
  485.         -Ken Baer.
  486.    //   Hash Enterprises: When the Going gets Weird, the Weird go Professional
  487.  \X/    USENET - ...tektronix!reed!percival!baer   OR   baer@percival.UUCP,
  488.         BIX - kbaer,  "while (AINTGOTNOSATISFACTION) { do stuff }" - RJ Mical
  489.  
  490.