L_CreateUserMatchTable

#include "l_bitmap.h"

L_UINT L_FAR * EXT_FUNCTION L_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 L_ColorResBitmap 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 L_ColorResBitmap 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 L_CreateUserMatchTable to create the table.

2.

Call L_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 L_ColorResBitmap with the CRF_USERPALETTE and CRF_FASTMATCHPALETTE options.

4.

Call L_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

LTKRN

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

Platforms

Windows 95 / 98 / Me, Windows 2000 / XP, Windows CE.

See Also

Functions:

L_ColorResBitmap, L_DefaultDithering, L_SetUserMatchTable, L_FreeUserMatchTable

Topics:

Raster Image Functions: Doing Color Expansion or Reduction

 

Raster Image Functions: Doing Color Space Conversions

 

Raster Image Functions: Palettes

Example

/* This example changes the color resolution of a bitmap, using a user-defined
palette and a match table for fast color matching. */
BITMAPHANDLE LeadBitmap;   /* Bitmap handle to hold the loaded image */
void TestFunction(HWND hWnd)
{
   L_UINT L_FAR * pMatchTable; /* Pointer to the user match table */
   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 = L_CreateUserMatchTable(Rainbow, 64);
   L_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. */
   L_ColorResBitmap(&LeadBitmap, &LeadBitmap, sizeof(BITMAPHANDLE), 8,
                 CRF_FLOYDSTEINDITHERING|CRF_USERPALETTE|CRF_FASTMATCHPALETTE, 
                    Rainbow, NULL, 64, NULL, NULL );
   /* Free the user match table when it is no longer needed */
   L_FreeUserMatchTable(pMatchTable);
   /* Get the new palette as the current paint palette */
   SendMessage (hWnd, WM_QUERYNEWPALETTE, 0, 0L);
   return;
}