This legacy article remains on the web site for historical and research purposes. For a list of current article by Jan Ozer, please click here:

PALETTES
 

Authors Note: A good source of information on working with active palette and palettes in general can be found at Intel's compuserve site go intela or their home page www.intel.com.

In many ways, working with Video for Windows is like living in a haunted house. You can't predict when strange things will happen, but the longer you live there, the more likely some seemingly innocent step will lead to totally bizarre results.

Imagine, if you will, the 8-bit environment. A video-friendly environment with low decompression bandwidths accelerating playback for even the slowest codec. But then, you inadvertently apply the wrong palette and

SHRIEK!!!!!!

the video that played at 30 frames per second just a moment ago is now crawling at 10 fps. You can almost hear it gasping for air. Your computer performs like an old AT and your fellow programmers start to edge away slowly with averted eyes. You've entered .... the Palette Zone.

The Problem

Most Windows-based video graphics cards display in 8-bit, 16-bit or 24-bit color depth with 8-bit systems predominating. Most codecs work faster in 8-bit mode - especially native 24-bit codecs like Indeo and Cinepak. That's because there's less data to display to the Windows buffer and less to pump from main memory to the video card.

8-bit displays are limited to 256 colors. This collection of 256 colors is called the palette, since all screen elements must be painted with colors contained in the palette. The 256 color combination is not fixed - palettes can and do frequently change. But at any one point, only 256 colors can be used to describe all the objects on the screen.

When displaying in 8-bit mode, all codecs are limited to 256 colors. For 8-bit codecs (Video 1 and RLE) this isn't a problem - their video is already described in 256 colors or less. This means that 8-bit codecs look as good in 8-bit mode as they do in the higher color depths.

24-bit codecs (Cinepak, Indeo) use over 16 million colors to describe their true-color video. To drop from 16-million to 256 colors, 24-bit codecs dither, or draw geometric pixel patterns of various sizes to simulate colors not contained in the palette. Both Indeo and Cinepak always decompress to their own unique 256 color palettes, irrespective of video content.

Palette Flashing

As noted above, all 8-bit displays use a set palette. In general, when a new graphic object displays, the display palette changes to the palette of the new object. If that palette is different, the screen "flashes," momentarily blanking out and realizing the colors of the new palette. Often accompanied by psychadelic screen pyrotechnics, palette flashing is a programming faux paus to be avoided at all costs.

8-bit codecs can "hold a palette," which allows developers to select one palette for a screen or presentation, and compress all videos and other graphics to that palette. However, while Video 1 and RLE make it simple to avoid palette flashing, they can't match Indeo or Cinepak in quality, especially in higher motion sequences.

The higher performance 24-bit codecs, Cinepak and Indeo, can't hold a palette and always decompress to their own unique palettes unless otherwise commanded in Windows. There are four ways to avoid palette flashing when using these codecs. These are:

  1. Limit backgrounds and graphics to the 20 system colors reserved all palettes.
  2. Make sure that backgrounds/graphics using additional colors not in the selected palette are never on screen during video playback.
  3. Force these two 24-bit codecs to decompress to a fixed palette (see below).
  4. Use the inherent palette of the codec as the background palette for the entire presentation.

Most developers find alternative 1 too restrictive, and that alternative 2 requires too much administration and planning. In most instances, 3 and 4 are the only practical alternatives. Let's explore the implications of the two approaches.

Decompressing to a Fixed Palette

Most presentations involve a varied group of graphic objects including icons, bit-mapped graphics, animations and, of course, video. The goal in palette design is to maximize the appearance of all the graphic objects, which can be tough given that you have to use the same 256 colors for all objects. Many programs, including Microsoft's VidEdit and Adobe Premiere, provide a convenient mechanism to build an optimal palette for these graphic objects.

Forcing video to decompress to this palette is also fairly simple. If you're programming with MCI controls, you can use the following command documented on page F-10 of the Video for Windows User's Guide.

SETVIDEO <alias> PALETTE HANDLE TO <palette-handle>

Otherwise, an increasing number of authoring programs also comprehend this command through their controls.

This would seem to be the best approach - you can comprehend the video in computing the optimal palette, and use a palette that's well suited for all screen objects. However ... you can almost hear the music ... do de do do, do de do do ... what happens when you force these codecs to decompress to a palette other than their own?

Consider this before you guess. Both Intel and Radius designed their palette to accomplish two goals, the first appearance and the second decompression speed. I'll say it again. So what's the first thing that goes when you won't let them play with their own ball?

Yup. Decompression speed. Table 1 shows what happens when you force Indeo and Cinepak files to decompress and display in a palette other than their own. I'm sure you'll find the results ... quite strange.

   Test Description        Native Palette           Other Palette      

                                                                       

Indeo 3.2 - 30 fps             30 fps                  1o fps          
320x240 video -                                                        
playback on 486/66                                                     
Gateway with ATI Mach                                                  
32 video card in                                                       
8-bit mode                                                             

Indeo 3.1 - 15 fps             15 fps                  10 fps          
320x240 Indeo 3.1                                                      
video - playback on                                                    
486/66 clone from                                                      
double speed CD-ROM                                                    
drive with ATI Mach                                                    
32 video card.                                                         

Cinepak - 30fps                30 fps                  11 fps          
320x240 on Gateway                                                     

Cinepak - 30fps                30 fps                  10 fps          
320x240 on clone                                                       

Table 1 : Display rates in and out of native palettes - before Active Palette.

These worst case results stem from the fact that the video is dithered twice; once by the codec to its native palette, and once again by Windows to the assigned palette. This was one of the two problems addressed by Microsoft with Active Palette Technology.

Active Palette

Through Video for Windows 1.1c, when codecs decompressed to a fixed palette, they blindly assumed that palette, which created some fairly bizarre results. For example, if color 14 in the assumed palette was navy blue, and color 14 in the codec's palette was red, your local boy scout troop looked like a communist youth organization.

Active Palette Technology, introduced with Video for Windows release 1.1d, lets codecs intelligently reorder their palette to match the system palette. In our example above, if color 124 in the codec's palette was navy blue, it could use that color in the place of system color 14. This makes all videos displayed in 8-bit mode more lifelike.

In addition to improving appearance, Active Palette also lets codecs dither directly to the assigned palette, avoiding the double dithering that previously occurred, and speeding display rates significantly. However, direct dithering works only on computers with DCI-enabled graphics cards, and display rates are still slower than when the codec displays under its native palette. Most important is that Table 1 results still apply for older, pre-1995 computers without DCI, which constitutes the bulk of the installed base of computers.

Which places Indeo and Cinepak developers in a real tough position. They can force the optimal palette on the video and slow display rates by up to sixty six percent, or use Indeo or Cinepak's palette as the native palette for the entire presentation. This maintains the video display rate but may detract from the overall appearance of the presentation. Significantly, Intel has always recommended the latter approach, even after the introduction of Active Palette.

Indeo and Cinepak Palettes

You can download Indeo and Cinepak's palettes on CompuServe - search for the file vidpal.zip in Microsoft's multimedia forum - it was put together by Ron Wadaski of Multimedia Madness fame. Intel's Indeo forum library on Compuserve also contains a very helpful article on using Indeo's palette under Video for Windows.

You can use BitEdit or other image editing programs to apply the palette to other bit-mapped images in your presentation. Animation files must be handled in the program that created them like Animator Pro.

Overall, using the native palette of the primary codec seems to be the simplest way to avoid palette flashing and maintain video display rates. It takes much of the art out of creating a presentation, but keeps you firmly outside the dreaded Palette Zone.

This article is derived from Jan's book, Video Compression for Multimedia, published in November 1994 by AP Professional. The book provides detailed look at video capture and compression. Jan can be reached at 568 14th Street, NW, Suite 200, Atlanta, GA 30318, at (404) 892-2889, or jan@doceo.com.


Top of Page