Microsoft KB Archive/149855

From BetaArchive Wiki

FADEIN App Uses Palette Animation & Identity Palettes

Q149855



The information in this article applies to:


  • Microsoft Win32 Software Development Kit (SDK)
  • Microsoft Windows 2000 Advanced Server
  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Professional





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.



MORE INFORMATION

The following file is available for download from the Microsoft Download Center:


Fadein.exe

For additional information about how to download Microsoft Support files, click the article number below to view the article in the Microsoft Knowledge Base:

Q119591 How to Obtain Microsoft Support Files from Online Services

Microsoft used the most current virus detection software available on the date of posting to scan this file for viruses. Once posted, the file is housed on secure servers that prevent any unauthorized changes to the file.



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

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.

Additional query words: AnimatePalette CreateDIBSection kbgraphic kbfile

Keywords : kbfile kbgraphic kbOSWinNT350 kbOSWin2000 kbSDKWin32 kbOSWin95
Issue type : kbinfo
Technology : kbwin2000AdvServ kbwin2000AdvServSearch kbwin2000Serv kbwin2000ServSearch kbwin2000Search kbwin2000ProSearch kbwin2000Pro kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWinAdvServSearch kbWin32sSearch


Last Reviewed: October 21, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.