SAMPLE: Fade a Bitmap Using Palette Animation

Last reviewed: February 15, 1996
Article ID: Q130804
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

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

SUMMARY

PALFADE is a sample application available in the Microsoft Software Library. It demonstrates:

  • How to use the AnimatePalette function to fade a bitmap to black.
  • How to use the DIBAPI32.DLL library that can be built by the WINCAP32 sample that ships with the Microsoft Win32 SDK.

To perform palette animation, the sample creates a logical palette for a device-independent bitmap (DIB) with the PC_RESERVED flag set for each palette entry. PALFADE loads, displays, and animates both Windows-style and OS/2-style DIB files.

Download PALFADE.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download PALFADE.EXE (size: 70256 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the SOFTLIB\MSLFILES directory
          Get PALFADE.EXE (size: 70256 bytes) 
    

MORE INFORMATION

Before performing palette animation on a logical palette entry, ensure that the palette entry has the PC_RESERVED flag set. To fade a bitmap drawn on a device context with a PC_RESERVED palette selected, you can lower the RGB values for each color in the palette in a loop until all colors are black.

The default system palette contains 20 static colors. These static colors take up the first ten and last ten colors of the system palette; these palette entries are not available for animation. If you try to fade a bitmap that has 256 unique colors by creating a 256-color palette with each palette entry set to PC_RESERVED, you are not guaranteed that every logical palette entry will map to an entry in the system palette that is available for palette animation.

One solution to this is to create a logical palette that contains only 236 colors. The PALFADE sample demonstrates one way to create an optimal palette of 236 colors given a device-independent bitmap with 256 colors in its color table.

Given a 256-color DIB, PALFADE traverses through every bit in the bitmap to find the least-used 20 colors in the color table. Then it creates a logical palette out of the 236 most-used colors. This ensures that all entries in the logical palette will animate.

This sample uses many of the DIB support functions included with the DIBAPI32.DLL library. It does not use the LoadDIB() function, because it was not written to handle OS/2-style DIB files. Instead, PALFADE implements the DIB-loading routines found in the Win32 SDK SHOWDIB sample.

NOTE: DIBAPI32.DLL is included with this sample.


Additional reference words: 3.10 3.50 4.00 95
KBCategory: kbgraphic kbfile kbgraphic
KBSubcategory: GdiPal


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: February 15, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.