L_ClrConvertBitmap

Summary

Converts image data from a source bitmap based on its ICC profile. The output will be in the same bitmap or a destination bitmap.

Syntax

#include "ltkrn.h"
#include "ltclr.h"

L_LTCLR_API L_INT L_ClrConvertBitmap(ClrHandle, pSrcBitmap, pDstBitmap)

Parameters

L_HANDLE ClrHandle

Handle to an existing color conversion. This handle is obtained by calling the L_ClrInit function.

pBITMAPHANDLE pSrcBitmap

Pointer to the buffer holding the input bitmap. The bitmap should be allocated and not NULL.

pBITMAPHANDLE pDstBitmap

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.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

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:

  1. An image is loaded to a viewer.
  2. The image in the viewer displays colors that are visibly off from a reference image.
  3. To correct the colors, the source image is converted using the embedded ICC profile with this method.

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.

Platforms

Win32, x64.

Required DLLs and Libraries

See Also

Functions

Topics

Example

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, &params); 
         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; 
} 

Help Version 22.0.2023.2.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Color Conversion C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.