home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / formats / fli / fli.for
Text File  |  1980-02-04  |  7KB  |  178 lines

  1.  
  2. From: kdarling@hobbes.ncsu.edu (Kevin Darling)
  3. Newsgroups: comp.graphics
  4. Subject: Re: FLI file-format?
  5. Message-ID: <1991Mar12.202026.5005@ncsu.edu>
  6. Date: 12 Mar 91 20:20:26 GMT
  7. Organization: North Carolina State University
  8.  
  9. >Has someone a description of the FLI-format?
  10.  
  11. Autodesk Animator files explanation (.FLI only excerpted).  I believe
  12. that the original programmer wrote up this doc.  It's correct, as I've
  13. used the info to realtime playback stock .FLIs on a 680x0 machine.
  14. All numbers in a .FLI file are in Intel format, so you may have to
  15. compensate for that, of course. - kevin
  16.  
  17. 8.1 Flic Files (.FLI)
  18.  
  19.      The details of a FLI file are moderately complex, but the
  20. idea behind it is simple: don't bother storing the parts of a
  21. frame that are the same as the last frame.  Not only does this
  22. save space, but it's very quick.  It's faster to leave a pixel
  23. alone than to set it.
  24.  
  25.      A FLI file has a 128-byte header followed by a sequence of
  26. frames. The first frame is compressed using a bytewise run-length
  27. compression scheme.  Subsequent frames are stored as the
  28. difference from the previous frame.  (Occasionally the first
  29. frame and/or subsequent frames are uncompressed.)  There is one
  30. extra frame at the end of a FLI which contains the difference
  31. between the last frame and the first frame.
  32.  
  33.      The FLI header:
  34.  
  35.      byte size name      meaning
  36.      offset
  37.  
  38.      0    4    size      Length of file, for programs that want
  39.                          to read the FLI all at once if possible.
  40.      4    2    magic     Set to hex AF11.  Please use another
  41.                          value here if you change format (even to
  42.                          a different resolution) so Autodesk
  43.                          Animator won't crash trying to read it.
  44.      6    2    frames    Number of frames in FLI.  FLI files have
  45.                          a maxium length of 4000 frames.
  46.      8    2    width     Screen width (320).
  47.      10   2    height    Screen height (200).
  48.      12
  49.      14   2    flags     Must be 0.
  50.      16   2    speed     Number of video ticks between frames.
  51.      18   4    next      Set to 0.
  52.      22   4    frit      Set to 0.
  53.      26   102  expand    All zeroes -- for future enhancement.
  54.  
  55.      Next are the frames, each of which has a header:
  56.  
  57.      byte size name      meaning
  58.      offset
  59.      0    4    size      Bytes in this frame.  Autodesk Animator
  60.                          demands that this be less than 64K.
  61.      4    2    magic     Always hexadecimal F1FA
  62.      6    2    chunks    Number of 'chunks' in frame.
  63.      8    8    expand    Space for future enhancements. All zeros.
  64.  
  65.      After the frame header come the chunks that make up the
  66. frame.  First comes a color chunk if the color map has changed
  67. from the last frame.  Then comes a pixel chunk if the pixels have
  68. changed.  If the frame is absolutely identical to the last frame
  69. there will be no chunks at all.
  70.  
  71.      A chunk itself has a header, followed by the data.  The
  72. chunk header is:
  73.  
  74.      byte size name meaning
  75.      offset
  76.      0    4    size Bytes in this chunk.
  77.      4    2    type Type of chunk (see below).
  78.  
  79.      There are currently five types of chunks you'll see in a FLI
  80. file:
  81.  
  82.      number    name      meaning
  83.      11        FLI_COLOR Compressed color map
  84.      12        FLI_LC    Line compressed -- the most common type
  85.                          of compression for any but the first
  86.                          frame.  Describes the pixel difference
  87.                          from the previous frame.
  88.      13        FLI_BLACK Set whole screen to color 0 (only occurs
  89.                          on the first frame).
  90.      15        FLI_BRUN  Bytewise run-length compression -- first
  91.                          frame only
  92.      16        FLI_COPY  Indicates uncompressed 64000 bytes soon
  93.                          to follow.  For those times when
  94.                          compression just doesn't work!
  95.  
  96.      The compression schemes are all byte-oriented.  If the
  97. compressed data ends up being an odd length a single pad byte is
  98. inserted so that the FLI_COPY's always start at an even address
  99. for faster DMA.
  100.  
  101. FLI_COLOR Chunks
  102.  
  103.      The first word is the number of packets in this chunk. This
  104. is followed directly by the packets.  The first byte of a packet
  105. says how many colors to skip.  The next byte says how many colors
  106. to change.  If this byte is zero it is interpreted to mean 256. 
  107. Next follows 3 bytes for each color to change (one each for red,
  108. green and blue).
  109.  
  110. FLI_LC Chunks
  111.  
  112.      This is the most common, and alas, most complex chunk.   The
  113. first word (16 bits) is the number of lines starting from the top
  114. of the screen that are the same as the previous frame. (For
  115. example, if there is motion only on the bottom line of screen
  116. you'd have a 199 here.)  The next word is the number of lines
  117. that do change.  Next there is the data for the changing lines
  118. themselves.  Each line is compressed individually; among other
  119. things this makes it much easier to play back the FLI at a
  120. reduced size.
  121.  
  122.      The first byte of a compressed line is the number of packets
  123. in this line.  If the line is unchanged from the last frame this 
  124. is zero.  The format of an individual packet is:
  125.  
  126.  skip_count
  127.  size_count
  128.  data
  129.  
  130.      The skip count is a single byte.  If more than 255 pixels
  131. are to be skipped it must be broken into 2 packets. The size
  132. count is also a byte.  If it is positive, that many bytes of data
  133. follow and are to be copied to the screen.  If it's negative a
  134. single byte follows, and is repeated -skip_count times.
  135.  
  136.      In the worst case a FLI_LC frame can be about 70K.  If it
  137. comes out to be 60000 bytes or more Autodesk Animator decides
  138. compression isn't worthwhile and saves the frame as FLI_COPY.
  139.  
  140. FLI_BLACK Chunks
  141.  
  142.      These are very simple.  There is no data associated with
  143. them at all. In fact they are only generated for the first frame
  144. in Autodesk Animator after the user selects NEW under the FLIC menu.
  145.  
  146. FLI_BRUN Chunks
  147.  
  148.      These are much like FLI_LC chunks without the skips.  They
  149. start immediately with the data for the first line, and go line-
  150. by-line from there.  The first byte contains the number of
  151. packets in that line.  The format for a packet is:
  152.  
  153.  size_count
  154.  data
  155.  
  156.      If size_count is positive the data consists of a single byte
  157. which is repeated size_count times. If size_count is negative
  158. there are -size_count bytes of data which are copied to the
  159. screen. In Autodesk Animator if the "compressed" data shows signs
  160. of exceeding 60000 bytes the frame is stored as FLI_COPY instead.
  161.  
  162. FLI_COPY Chunks
  163.  
  164.      These are 64000 bytes of data for direct reading onto the
  165. screen.
  166.  
  167.  -eof-
  168.  
  169. Notes: Since these are animations, the last frame will delta into a
  170. copy of the first one (which was usually a large BRUN chunk).  Therefore,
  171. looping should go back to the _second_ frame chunk (usually a LC
  172. or COLOR chunk) instead of all the way back to the file beginning, to
  173. avoid a "stutter" caused by unnecessarily redecoding the original frame.
  174. Also, a very few files may have palette animation, so write your code
  175. so that COLOR chunks can be found at any time.  - kevin
  176.  
  177.  
  178.