The CImagePalette class is a specialized class for image renderers that must create and manage palettes. It can be used to create palette handles from a media format containing a VIDEOINFO structure in the format block. To maximize performance, the class attempts to create a palette that is an identity palette (that is, one that exactly matches the current system palette), and compares palettes before updating to ensure that palettes are changed only when actually required.
Protected Data Members
Name | Description |
m_hPalette | Palette handle owned by this object. |
m_pBaseWindow | Window in which to realize the palette. |
m_pDrawImage | Object that will perform the drawing. |
m_pMediaFilter | Media filter to send events to. |
Member Functions
Name | Description |
CImagePalette | Constructs a CImagePalette object. |
CopyPalette | Copies the palette out of any YUV or true-color VIDEOINFOHEADER structure into a palettized VIDEOINFOHEADER structure. |
MakeIdentityPalette | Ensures the palette entries will become an identity palette. |
MakePalette | Retrieves the color palette from the specified video image. |
PreparePalette | Specifies an entry point for updating and creating palettes. |
RemovePalette | Releases any palette resources allocated. |
ShouldUpdate | Specifies an internal helper member function for updating palettes dynamically. |
Constructs a CImagePalette object.
CImagePalette(
CBaseFilter *pBaseFilter,
CBaseWindow *pBaseWindow,
CDrawImage *pDrawImage
);
No return value.
This class looks after the creation, management, and deletion of a window palette. It is passed in a number of other objects that might be interested in palettes. The class is optimized so that requested palette changes will be acted on only if the new set of colors differs from the current set. This is a performance optimization, because changing palettes is an expensive process.
This constructor is passed in the owning filter (pBaseFilter), which must be a valid pointer. When the class actually creates a palette, it tells the owning filter to send an EC_PALETTE_CHANGED message to the filter graph manager. The constructor might also be passed two further object pointers. If pBaseWindow is not null, when the renderer creates a new palette the class automatically installs it in this window. When told to remove a palette, the class also removes the palette from the base window and installs a standard VGA palette instead.
The constructor can also be passed a drawing object derived from the CDrawImage class. If this is non-NULL, when creating a new palette the class will inform the drawing object that the palette has changed (this is normally used in conjunction with a window object). This ensures that the drawing object is notified when the palette changes so that it can update any samples it has that were created using CreateDIBSection (because they might need their internal color tables updated).
Copies the palette out of any YUV or true-color VIDEOINFOHEADER structure into a palettized VIDEOINFOHEADER structure.
HRESULT CopyPalette(
const CMediaType *pSrc,
const CMediaType *pDest
);
Returns an HRESULT value.
This member function is used when changing palettes on DirectDraw® samples. A filter acting as a source to the renderer can attach a palette to any buffer and pass it to the renderer as a new VIDEOINFOHEADER format. The renderer can then call CopyPalette to make a new palette from that format, and copy the palette colors into the new connection type.
Modifies the PALETTEENTRY structure to create an identity palette.
HRESULT MakeIdentityPalette(
PALETTEENTRY *pEntry,
INT iColours,
LPSTR szDevice
);
Returns an HRESULT value.
When a palette is installed in a window, GDI does a fair job of compressing the requested colors where possible. So, for example, if the array contains five entries of black, they will be compressed into one palette entry. This is useful for most applications; however, when drawing video it will force GDI to map the pixels in the supplied image to the compressed palette (which results in serious performance penalties).
Therefore, the PALETTEENTRY fields supplied must be adjusted so that they will never have colors compressed. This means that when the window displaying the image has the foreground focus, the palette created by this object will map directly to the palette selected in the display device: a so-called identity palette.
Retrieves the color palette from the specified video image.
HPALETTE MakePalette(
const VIDEOINFOHEADER *pVideoInfo,
LPSTR szDevice
);
Returns a handle to the new palette (NULL if it fails).
Specifies an entry point for creating and installing palettes.
HRESULT PreparePalette(
const CMediaType *pmtNew,
const CMediaType *pmtOld,
LPSTR szDevice
);
Returns an HRESULT value.
This is the main entry point for creating new palettes. It tries to detect situations where the palette colors requested have not changed (in which case it does not need to create a new palette). It uses the old media type to determine if the colors have changed. It also handles optionally installing the palette in a window (if supplied) and notifying the filter graph manager of a change in palettes (it uses the filter passed in to the constructor for this). Finally, it handles notifying the draw object of palette changes (also optional, depending on whether a draw object was passed in to the constructor).
Removes and deletes any palette previously created.
HRESULT RemovePalette( );
Returns an HRESULT value.
Help member function that checks if two sets of colors match.
BOOL ShouldUpdate(
const VIDEOINFOHEADER *pNewInfo,
const VIDEOINFOHEADER *pOldInfo
);
Returns one of the following values.
Value | Meaning |
TRUE | A new palette is required. |
FALSE | The existing palette suffices. |
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.