static L_UINT * LBitmapSettings::CreateUserMatchTable(pPalette, uColors)
Creates a table that speeds color conversion when using a palette that you create. The table is referenced by the LBitmapBase::ColorRes function.
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. |
The number of colors in your palette.
The pointer to the table, or NULL if the function fails.
This function is used with other functions in the following sequence:
Call [LBitmapSettings:CreateUserMatchTable to create the table.
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.)
Call LBitmapBase::ColorRes with the CRF_USERPALETTE and CRF_FASTMATCHPALETTE options.
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.
Win32, x64.
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 Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document