Using RLE Bitmaps for Animation Applications In Windows

Last reviewed: November 2, 1995
Article ID: Q75214
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.1 and 3.0
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.5 and 3.51
        - Microsoft Windows 95 version 4.0
    

SUMMARY

Animation that uses a "brute-force" animation scheme, displaying successive complete bitmaps, can be slow and choppy. The alternative approach, displaying an initial frame and then modifying the elements that change, can save a great deal of time, memory, and disk space.

MORE INFORMATION

Animation applications typically use a very simple algorithm to display a sequence of bitmaps, or frames, one right over another, on the same display surface. When the application stores an entire frame in the device-independent bitmap (DIB) format, it suffers from three particular bottlenecks:

  1. With large frames or long sequences, the storage file becomes quite large.

  2. Loading an entire sequence requires a large amount of memory.

  3. Available Windows functions, such as BitBlt or SetDIBitsToDevice, may be too slow to animate the sequence smoothly.

For an animation sequence of bitmaps with a consistent set of colors, preprocessing the animation sequence and storing it in the run-length- encoded (RLE) format enables an application to run faster with a smaller storage file and memory requirement. Note that this RLE file is different from an RLE compressed DIB. This RLE format consists of several frames that are compressed according to the differences between frames. This process is straightforward and consists of five steps:

  1. Select the first frame in the sequence and store it in the DIB format.

  2. Compare the DIB bitmaps of consecutive frames. Due to the nature of animation sequences, the number of differences is often quite small compared to the size of the entire frame.

  3. Encode the set of changed pixels into RLE format. The encoded frame will contain information only on the pixels that change, the delta records will skip the unchanged pixels. The RLE bitmap is stored instead of the latter frame. For example, the RLE-encoded difference between the first and second frames is stored as the second frame.

  4. When the entire sequence is preprocessed, bring each frame into the system as a BITMAPINFO structure and stream of bits. Since only the first frame is in the DIB format, the memory requirement is quite low. Moreover, frames that contain an identical set of colors can share the BITMAPINFO structure, only the biCompression and biSizeImage fields must be changed.

  5. At display time, load the first frame as a DIB. Then use the SetDIBitsToDevice function to display subsequent frames in the sequence. Because this function requires much less information, the sequence can be animated much more quickly and smoothly.


Additional reference words: 3.00 3.10 3.50 4.00 95 rle
KBCategory: kbgraphic
KBSubcategory: GdiBmp


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.