L_ClrConvertCMYKArray

Summary

Converts an array of CMYK planes (with an optional alpha plane) to BGR. The function stores the output to a destination bitmap.

Syntax

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

L_LTCLR_API L_INT L_ClrConvertCMYKArray(ClrHandle, ppSrcBitmapArray, uSrcBitmapArrayCount, pDstBitmap, uStructSize)

Parameters

L_HANDLE ClrHandle

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

pBITMAPHANDLE *ppSrcBitmapArray

An array of pointers to BITMAPHANDLE structures containing the input CMYK planes. The bitmaps must be 8-bit grayscale.

L_UINT uSrcBitmapArrayCount

Number of bitmaps in the ppSrcBitmapArray. This must be set to 4 or 5.

pBITMAPHANDLE pDstBitmap

A pointer to the destination bitmap that will be allocated by the function if succeeded, to store the output bitmap in. This should not be allocated by the user.

L_UINT uStructSize

The size of the BITMAPHANDLE structure. This must be set to sizeof(BITMAPHANDLE).

Returns

Value Meaning
SUCCESS The function was successful.
ERROR_NULL_PTR One of the input parameters (ClrHandle, ppSrcBitmapArray, ppSrcBitmapArray[k], with k=0..3 or pDstBitmap) is NULL.
ERROR_INV_PARAMETER uSrcBitmapArrayCount is not 4 or 5.
< 1 An error occurred. Refer to Return Codes.

Comments

This function is designed to convert the alpha plane bitmaps returned by L_LoadFileCMYKArray. A typical reason for using this function is to perform the CMYK->BGR conversion using a particular ICC profile or CMYK color conversion settings.

By default, if the CMYK file is loaded using the (L_LoadBitmap, L_LoadFile, etc.) functions, LEADTOOLS will automatically convert the CMYK data to BGR during the load. The conversion will be performed using the CMYK ICC profile embedded in the input file (if exists), or using the default LEADTOOLS CMYK ICC profile.

To change the default behavior to perform the conversion using a particular ICC profile, do the following:

  1. Load the CMYK planes using L_LoadFileCMYKArray.
  2. Initialize the color conversion engine using L_ClrInit.
  3. Convert the CMYK planes to BGR using L_ClrConvertCMYKArray.
  4. Free the CMYK planes using L_FreeBitmap for each plane.

If successful, L_ClrConvertCMYKArray will allocate a bitmap and store it in the bitmap pointed by the pDstBitmap parameter. The user should free it by calling L_FreeBitmap when it is no longer needed.

The color conversion will be performed only on the first 4 planes. If a 5th plane exists, it will be considered an alpha plane and will be stored without being converted into the target bitmap.

Therefore, the output bitmap will be:

If there are 5 pointers in the array but the 5th bitmap is not allocated, the output bitmap will be 24-bit.

The first 4 pointers must be valid and point to bitmaps of same size and bits per pixel. The 5th pointer is optional and can be NULL or point to an unallocated bitmap. The 5th pointer will be ignored if it does not point to a valid allocated bitmap.

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

This function will load a CMYK file as an array of CMYK planes, convert the planes to BGR using a custom ICC profile and save the output to the disk.

L_INT ClrConvertToBitmapExample(L_TCHAR* 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 */ 
         } 
      } 
 
      /* Free the ICC profile data */ 
      L_FreeICCProfile(&ICCProfile); 
   } 
   return nRet; 
} 

Help Version 23.0.2024.10.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 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.