FADEIN: Sample App Uses Palette Animation & Identity Palettes

Last reviewed: June 21, 1996
Article ID: Q149855
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK)

SUMMARY

A popular method used to perform a fade on an image is to animate the palette. An application displays a bitmap, and then animates the palette to all black, fading the image into blackness.

To perform the fade in the opposite direction, starting with all black and fading into color, requires some additional ingenuity. The original BitBlt() that gets the image's bits on the screen must be done without color matching. Because all of the pixels are intended to be black, if color matching were used, the pixels would be matched to the same palette entry. A subsequent palette animation would result in a single- colored rectangle.

You can take advantage of an optimization in Windows to work around this issue. When Windows is performing a BitBlt and it detects that an identity palette is being used, no color matching is performed. The source bits are moved to the destination unchanged. To perform a fade from black to color, use an identity palette to get the bits onto the screen and then fade the palette from all black to the original bitmap's desired colors.

To prepare a bitmap to use an identity palette, you must reduce the image from 256 colors to 236. An identity palette must contain the system entries in its first and last ten entries. The code in the sample below that reduces the image to 236 colors must first calculate the optimal 236 colors from a 256 color table. It then determines how close the colors are to each other, and discards colors that have close matches while keeping colors that have no close matches. Once it determines the best 236 colors, BitBlt() maps the 256 color image to 236 colors. Everything is then moved up ten to allow for the system colors in the identity palette.

This sample application in FADEIN.EXE contains code that performs the following tasks:

  • Creates a DIBSection from a bitmap stored as a resource
  • Chooses the optimal 236 colors from a 256 color table
  • Reduces a 256 color DIBSection to 236 colors
  • Creates an identity palette
  • Performs palette animation to fade from black to color

MORE INFORMATION

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

You can find FADEIN.EXE (size: 51811 bytes) 
                       , a self-extracting file, on these services:

  • Microsoft's World Wide Web site on the Internet

          On the www.microsoft.com home page, click the Support icon
          Click Knowledge Base, and select the product
    
          Enter kbfile FADEIN.EXE (size: 51811 bytes) 
                                 , and click GO!
          Open the article, and click the button to download the file
    
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the Softlib/Mslfiles folder
          Get FADEIN.EXE (size: 51811 bytes) 
    
  • The Microsoft Network

          On the Edit menu, click Go To, and then click Other Location
          Type "mssupport" (without the quotation marks)
          Double-click the MS Software Library icon
          Find the appropriate product area
          Locate and Download FADEIN.EXE
    
  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download FADEIN.EXE (size: 51811 bytes) 
    

    For additional information about downloading, please see the following article in the Microsoft Knowledge Base:

       ARTICLE-ID: Q119591
       TITLE     : How to Obtain Microsoft Support Files from Online Services
    

  • Additional reference words: 3.50 AnimatePalette CreateDIBSection
    KBCategory: kbgraphic kbfile kbcode kbhowto
    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: June 21, 1996
    © 1998 Microsoft Corporation. All rights reserved. Terms of Use.