LBitmapSettings::CreateUserMatchTable

#include "ltwrappr.h"

static L_UINT L_FAR * LBitmapSettings::CreateUserMatchTable(pPalette, uColors)

LPRGBQUAD pPalette;

/* array of values that is your palette */

L_UINT uColors;

/* number of colors in your palette */

Creates a table that speeds color conversion when using a palette that you create. The table is referenced by the LBitmapBase::ColorRes function.

Parameter

Description

pPalette

The array of values that is your palette.

 

Each item in the array can have one of the following values:

 

Value

Meaning

 

Actual RGBQUAD value

Use the specified color as a fixed color.

 

RGB_RESERVED

[0x01] Leave the item blank, for possible later use.

 

RGB_EMPTY

[0x02] Let the LBitmapBase::ColorRes function fill in the color. The function supplies optimized colors to fill the RGB_EMPTY items.

uColors

The number of colors in your palette.

Returns

The pointer to the table, or NULL if the function fails.

Comments

This function is used with other functions in the following sequence:

1.

Call LBitmapSettings::CreateUserMatchTable to create the table.

2.

Call LBitmapSettings::SetUserMatchTable to make this the current table. (Having this as a separate function allows you to save tables in files and get the one you need, without creating it again.)

3.

Call LBitmapBase::ColorRes with the CRF_USERPALETTE and CRF_FASTMATCHPALETTE options.

4.

Call LBitmapSettings::FreeUserMatchTable when the table is no longer needed.

The completed table is a 32K array of integers. On a 32-bit system, it occupies 128K bytes of memory. Creation of the table is a slow, memory-intensive process that is useful only if you are using your own palette more than once. For example, you may want to create the table once, save it to a file, and ship that file with your application.

Required DLLs and Libraries

LTDIS

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

See Also

Functions:

LBitmapBase::ColorRes, LBitmapSettings::DefaultDithering, LBitmapSettings::SetUserMatchTable, LBitmapSettings::FreeUserMatchTable

Topics:

Raster Image Functions: Doing Color Expansion or Reduction

 

Raster Image Functions: Doing Color Space Conversions

 

Raster Image Functions: Palettes

Example

L_VOID BitmapSettingsSample(HWND hWnd)
{
   LBitmap LeadBitmap, ColorResBitmap;
   L_UINT L_FAR * pMatchTable; /* Pointer to the user match table */
   RECT rcClientRect;
   HDC hDC;
   RGBQUAD Rainbow[64] = /* 64-color rainbow palette */
   {
      {0, 0, 0, 0}, {85, 0, 0, 0}, {170, 0, 0, 0}, {255, 0, 0, 0}, {0, 85, 0, 0}, 
      {85, 85, 0, 0}, {170, 85, 0, 0}, {255, 85, 0, 0}, {0, 170, 0, 0}, {85, 170, 0, 0}, 
      {170, 170, 0, 0}, {255, 170, 0, 0}, {0, 255, 0, 0}, {85, 255, 0, 0}, {170, 255, 0, 0}, 
      {255, 255, 0, 0}, {0, 0, 85, 0}, {85, 0, 85, 0}, {170, 0, 85, 0}, {255, 0, 85, 0}, 
      {0, 85, 85, 0}, {85, 85, 85, 0}, {170, 85, 85, 0}, {255, 85, 85, 0}, {0, 170, 85, 0}, 
      {85, 170, 85, 0}, {170, 170, 85, 0}, {255, 170, 85, 0}, {0, 255, 85, 0}, 
      {85, 255, 85, 0}, {170, 255, 85, 0}, {255, 255, 85, 0}, {0, 0, 170, 0}, {85, 0, 170, 0}, 
      {170, 0, 170, 0}, {255, 0, 170, 0}, {0, 85, 170, 0}, {85, 85, 170, 0}, {170, 85, 170, 0}, 
      {255, 85, 170, 0}, {0, 170, 170, 0}, {85, 170, 170, 0}, {170, 170, 170, 0}, 
      {255, 170, 170, 0}, {0, 255, 170, 0}, {85, 255, 170, 0}, {170, 255, 170, 0}, 
      {255, 255, 170, 0}, {0, 0, 255, 0}, {85, 0, 255, 0}, {170, 0, 255, 0}, {255, 0, 255, 0}, 
      {0, 85, 255, 0}, {85, 85, 255, 0}, {170, 85, 255, 0}, {255, 85, 255, 0}, {0, 170, 255, 0},
      {85, 170, 255, 0}, {170, 170, 255, 0}, {255, 170, 255, 0}, {0, 255, 255, 0}, 
      {85, 255, 255, 0}, {170, 255, 255, 0}, {255, 255, 255, 0},
   };

   /* Create and set the user match table */
   pMatchTable = LBitmapSettings::CreateUserMatchTable(Rainbow, 64);
   LBitmapSettings::SetUserMatchTable(pMatchTable);
   /* Change the color resolution using the new palette. Note that the user match table
   is makes your code faster only if you use it more than once. It is included here only 
   to show how it can be coded. */
   // get DC
   hDC = GetDC(hWnd);
   GetClientRect(hWnd, &rcClientRect);
   LeadBitmap.Load(TEXT("image1.cmp"), 24, ORDER_BGR);
   LeadBitmap.ColorRes(8,
                 CRF_FLOYDSTEINDITHERING|CRF_USERPALETTE|CRF_FASTMATCHPALETTE, 
                    Rainbow, 64);

   /* Free the user match table when it is no longer needed */
   LBitmapSettings::FreeUserMatchTable(pMatchTable);

   /* Get the new palette as the current paint palette */
   SendMessage (hWnd, WM_QUERYNEWPALETTE, 0, 0L);
     // Paint the image
   LeadBitmap.Paint()->SetDC(hDC);
   LeadBitmap.SetDstRect(&rcClientRect);
   LeadBitmap.Paint()->PaintDC();
   ReleaseDC(hWnd, hDC);
  return;
}