Windows Dev Center

XMConvertFloatToHalfStream
XMConvertHalfToFloatStream
XMMatrixDecompose
XMPlaneTransformStream
XMVector2TransformCoordStream
XMVector2TransformNormalStream
XMVector2TransformStream
XMVector3ProjectStream
XMVector3TransformCoordStream
XMVector3TransformNormalStream
XMVector3TransformStream
XMVector3UnprojectStream
XMVector4TransformStream
Expand Minimize

IWICPalette interface

Exposes methods for accessing and building a color table, primarily for indexed pixel formats.

Members

The IWICPalette interface inherits from the IUnknown interface. IWICPalette also has these types of members:

Methods

The IWICPalette interface has these methods.

MethodDescription
GetColorCount

Retrieves the number of colors in the color table.

GetColors

Fills out the supplied color array with the colors from the internal color table. The color array should be sized according to the return results from GetColorCount.

GetType

Retrieves the WICBitmapPaletteType that describes the palette.

HasAlpha

Retrieves a value that describes whether the palette contains an alpha transparent color.

InitializeCustom

Initializes a palette to the custom color entries provided.

InitializeFromBitmap

Initializes a palette using a computed optimized values based on the reference bitmap.

InitializeFromPalette

Initialize the palette based on a given palette.

InitializePredefined

Initializes the palette to one of the pre-defined palettes specified by WICBitmapPaletteType and optionally adds a transparent color.

IsBlackWhite

Retrieves a value that describes whether the palette is black and white.

IsGrayscale

Retrieves a value that describes whether a palette is grayscale.

 

Remarks

If the WICBitmapPaletteType is not WICBitmapPaletteCustom, then the colors are automatically generated based on the table above. If the user subsequently changes a color palette entry the WICBitmapPalette is set to Custom by that action.

InitializeFromBitmap's fAddTransparentColor parameter will add a transparent color to the end of the color collection if its size if less than 256, otherwise index 255 will be replaced with the transparent color. If a pre-defined palette type is used, it will change to BitmapPaletteTypeCustom since it no longer matches the predefined palette.

The palette interface is an auxiliary imaging interface in that it does not directly concern bitmaps and pixels; rather it provides indexed color translation for indexed bitmaps. For an indexed pixel format with M bits per pixels: (The number of colors in the palette) greater than 2^M.

Traditionally the basic operation of the palette is to provide a translation from a byte (or smaller) index into a 32bpp color value. This is often accomplished by a 256 entry table of color values.

Examples


    IWICImagingFactory *pFactory = NULL;
    IWICBitmapDecoder *pDecoder = NULL;
    IWICBitmapFrameDecode *pBitmapFrameDecode = NULL;
    IWICPalette *pPalette = NULL;

    UINT uiFrameCount = 0;

    HRESULT hr = CoCreateInstance(
        CLSID_WICImagingFactory,
        NULL,
        CLSCTX_INPROC_SERVER,
        IID_IWICImagingFactory,
        (LPVOID*)&pFactory
        );

    if (SUCCEEDED(hr))
    {
        hr = pFactory->CreateDecoderFromFilename(
                           L"test.gif",
                           NULL,
                           GENERIC_READ,
                           &pDecoder);
    }

    if (SUCCEEDED(hr))
    {
        hr = pDecoder->GetFrameCount(&uiFrameCount);
    }

    if (SUCCEEDED(hr) && (uiFrameCount > 0))
    {
        hr = pDecoder->GetFrame(0, &pBitmapFrameDecode);

        if (SUCCEEDED(hr))
        {
            hr = pFactory->CreatePalette(&pPalette);
        }

        if (SUCCEEDED(hr))
        {
            hr = pBitmapFrameDecode->CopyPalette(pPalette);
        }

        if (SUCCEEDED(hr))
        {
            UINT uiColorCount = 0;
            UINT uiActualColorCount = 0;
            WICColor *pColors = NULL;

            hr = pPalette->GetColorCount(&uiColorCount);

            if (SUCCEEDED(hr) && (uiColorCount > 0))
            {
                pColors = new WICColor[uiColorCount];

                if (pColors)
                {
                    hr = pPalette->GetColors(uiColorCount, pColors, &uiActualColorCount);

                    // Do something with the colors here...

                    delete[] pColors;
                }
                else
                {
                    hr = E_OUTOFMEMORY;
                }
            }
        }
    }

    if (pPalette)
    {
        pPalette->Release();
    }

    if (pBitmapFrameDecode)
    {
        pBitmapFrameDecode->Release();
    }

    if (pDecoder)
    {
        pDecoder->Release();
    }

    if (pFactory)
    {
        pFactory->Release();
    }

    return hr;

In this example code, WICColor is defined as a UINT32 value with this layout:

0xAARRGGBB

The wincodec.h header type-defines WICColor as UINT32.

Requirements

Minimum supported client

Windows XP with SP2, Windows Vista [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2008 [desktop apps | Windows Store apps]

Header

Wincodec.h

IDL

Wincodec.idl

Library

Windowscodecs.lib

DLL

Windowscodecs.dll

 

 

Community Additions

ADD
Show:
© 2015 Microsoft