Is this page helpful?
Converts image data from a source bitmap based on its ICC profile. The output will be in the same bitmap or a destination bitmap.
#include "ltkrn.h"
#include "ltclr.h"
L_LTCLR_API L_INT L_ClrConvertBitmap(ClrHandle, pSrcBitmap, pDstBitmap)
Handle to an existing color conversion. This handle is obtained by calling the L_ClrInit function.
Pointer to the buffer holding the input bitmap. The bitmap should be allocated and not NULL.
Optional pointer to the buffer that will hold the converted data bitmap. Can be NULL or equal to pSrcBitmap
, in which case the input bitmap will contain the result of the conversion.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
There are various conversion methods available in the LEADTOOLS Color Conversion toolkit, however, to get optimal conversion results use L_ClrConvertBitmap as it relies on the embedded ICC profile of the source image.
Here is a scenario where this method is invaluable:
Conversion is done by setting the active method value specified in the CONVERSION_PARAMS structure when calling L_ClrInit. To change the active method, use L_ClrSetConversionParams. Only methods supported by the initialized converter should be specified.
The conversion is done if it was initialized with BGR or RGB Color Spaces as source and destination.
The conversion is performed in place if pDstBitmap
is NULL or equal to pSrcBitmap
. If pDstBitmap
is valid and != pSrcBitmap
, both bitmaps should have the same width and height.
The bits per pixel should be 24 for both bitmaps. If there are two bitmaps, both bitmaps should be allocated.
Win32, x64.
This example loads a bitmap containing an embedded ICC BGR profile. It converts the image data using the embedded profile.
L_INT ClrConvertToBitmapExample(L_UCHAR* pInput, pBITMAPHANDLE pBitmap)
{
ICCPROFILEEXT ICCProfile = { sizeof(ICCPROFILEEXT) };
L_INT nRet = L_LoadICCProfile(pszSrcFile, &ICCProfile, NULL);
if (nRet == SUCCESS)
{
/* Load the image stored in the input file */
nRet = L_LoadBitmap(pInput, pBitmap, sizeof(BITMAPHANDLE), 24, ORDER_BGR, NULL, NULL);
if (nRet == SUCCESS)
{
/* Set up the conversion to use the embedded BGR profile */
MEMICCPROFILE memICCProfile = { sizeof(MEMICCPROFILE), ICCProfile.pData, ICCProfile.uDataSize };
CONVERSION_PARAMS params = { sizeof(CONVERSION_PARAMS) };
params.nActiveMethod = USE_CUSTOM_ICC;
params.nMethod = USE_CUSTOM_ICC;
params.nQuantization = 8;
params.pMemInputProfile = &memICCProfile;
L_HANDLE hClrHandle;
nRet = L_ClrInit(&hClrHandle, CCS_BGR, CCS_BGR, ¶ms);
if (nRet == SUCCESS)
{
/* Do an in-place conversion of the data stored in pBitmap */
nRet = L_ClrConvertBitmap(hClrHandle, pBitmap, NULL);
/* Uncomment the next lines to save the bitmap to an output file
if (nRet == SUCCESS)
nRet = L_SaveBitmap(L_TEXT("out-converted.jpg"), pBitmap, FILE_JPEG_411, 0, 20, NULL);
*/
L_ClrFree(hClrHandle); /* Free the color conversion handle */
}
}
L_FreeICCProfile(&ICCProfile); /* Free the ICC profile data */
}
return nRet;
}