LBitmapSettings::CreateUserMatchTable

Summary

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

Syntax

#include "ltwrappr.h"

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

Parameters

LPRGBQUAD 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.

L_UINT 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

Platforms

Win32, x64.

See Also

Functions

Topics

Example

L_INT LBitmapSettings__CreateUserMatchTableExample(HWND hWnd) 
{ 
   L_INT nRet; 
   LBitmap  LeadBitmap; 
   L_UINT  * 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); 
   if(pMatchTable == NULL ) 
      return FAILURE; 
 
   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); 
   nRet = LeadBitmap.Load(MAKE_IMAGE_PATH(TEXT("image1.cmp")), 24, ORDER_BGR); 
   if(nRet !=SUCCESS) 
      return nRet; 
   /*nRet =LeadBitmap.ColorRes(8, 
                             CRF_FLOYDSTEINDITHERING|CRF_USERPALETTE|CRF_FASTMATCHPALETTE,  
                             Rainbow, 64);*/ 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   /* Free the user match table when it is no longer needed */ 
   nRet =LBitmapSettings::FreeUserMatchTable(pMatchTable); 
   if(nRet < 0 ) 
      return nRet; 
 
   /* 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 SUCCESS; 
} 
Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.