L_ConvertColorSpace

#include "l_bitmap.h"

L_LTDIS_API L_INT L_ConvertColorSpace(pBufferSrc, pBufferDst, nWidth, nFormatSrc, nFormatDst)

Converts image data in a buffer from one color space model to another. The supported models are RGB, YUV, CMYK, CMY, YIQ, HSV, and HLS.

Parameters

L_UCHAR* pBufferSrc

Pointer to the buffer holding the input data.

L_UCHAR* pBufferDst

Pointer to the buffer that will hold the converted data.

L_INT nWidth

The number of pixels to be processed.

L_INT nFormatSrc

Format of the input data. There are two groups. The valid values for the first group are:

Value Meaning
CCS_RGB [0x00] RGB color space model (in BGR order).
CCS_YUV [0x01] YUV color space model.
CCS_CMYK [0x02] CMYK color space model.
CCS_CMY [0x06] CMY color space model.
CCS_YIQ [0x05] YIQ color space model.
CCS_HSV [0x03] HSV color space model.
CCS_HLS [0x04] HLS color space model.
CCS_BGR [0x0C] BGR color space model.
CCS_ARGB4 [0x90] Color space is ARGB4444.

The valid values for the second group are:

Value Meaning
CCS_RGB16 [0x10] RGB color space model (in BGR order).
CCS_YUV16 [0x20] YUV color space model.
CCS_YIQ16 [0x30] YIQ color space model.
CCS_HSV16 [0x40] HSV color space model.
CCS_HLS16 [0x50] HLS color space model.
CCS_CMY16 [0x60] CMY color space model.
CCS_CMYK16 [0x70] CMYK color space model.

L_INT nFormatDst

Format of the output data. There are two groups. The valid values for the first group are:

Value Meaning
CCS_RGB [0x00] RGB color space model (in BGR order).
CCS_YUV [0x01] YUV color space model.
CCS_CMYK [0x02] CMYK color space model.
CCS_CMY [0x06] CMY color space model.
CCS_YIQ [0x05] YIQ color space model.
CCS_HSV [0x03] HSV color space model.
CCS_HLS [0x04] HLS color space model.
CCS_BGR [0x0C] BGR color space model.
CCS_ARGB4 [0x90] Color space is ARGB4444.

The valid values for the second group are:

Value Meaning
CCS_RGB16 [0x10] RGB color space model (in BGR order).
CCS_YUV16 [0x20] YUV color space model.
CCS_YIQ16 [0x30] YIQ color space model.
CCS_HSV16 [0x40] HSV color space model.
CCS_HLS16 [0x50] HLS color space model.
CCS_CMY16 [0x60] CMY color space model.
CCS_CMYK16 [0x70] CMYK color space model.

Returns

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

Comments

RGB is commonly used for displaying images on monitors and for storing images in files. YUV and YIQ are used for data that is stored using JPEG compression. CMYK is used when printing images. HSV and HLS are used in applications that let human beings manipulate the color plane values.

Note the following:

This function also supports 12 and 16 - bit grayscale bitmaps. Support for 12 and 16 - bit grayscale images is available in the Document and Medical Imaging toolkits.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

For complete sample code, refer to the CLRSPACE example. This example converts one row of image data from RGB to CMYK. It does not produce any output.

L_INT ConvertColorSpaceExample(L_VOID) 
{ 
   L_INT nRet; 
   L_UCHAR*       pInBuf;     /* Buffer to hold the input row */ 
   HGLOBAL        hInBuf;     /* Handle to the input buffer */ 
   L_UCHAR*       pOutBuf;    /* Buffer to hold the output row */ 
   HGLOBAL        hOutBuf;    /* Handle to the output buffer */ 
   BITMAPHANDLE   TmpBitmap;  /* Bitmap containing input data */ 
 
   /* Load the input bitmap, at 24 bits per pixel */ 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\Image3.cmp")), &TmpBitmap, sizeof(BITMAPHANDLE), 24, ORDER_BGR, NULL, NULL); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Allocate the input buffer for 24-bit RGB data */ 
   hInBuf = GlobalAlloc(GMEM_MOVEABLE, TmpBitmap.Width * 3); 
   pInBuf = (L_UCHAR *)GlobalLock( hInBuf ); 
   /* Allocate the output buffer for 32-bit CMYK data */ 
   hOutBuf = GlobalAlloc(GMEM_MOVEABLE, TmpBitmap.Width * 4); 
   pOutBuf = (L_UCHAR *)GlobalLock( hOutBuf ); 
   /* Get one row of data from the bitmap */ 
   L_AccessBitmap(&TmpBitmap); 
   nRet =(L_INT)L_GetBitmapRow(&TmpBitmap, pInBuf, 0, TmpBitmap.BytesPerLine); 
   if(nRet < 1) 
      return nRet; 
   L_ReleaseBitmap(&TmpBitmap); 
   /* Convert the data from RGB in pInBuf to CMYK in pOutBuf */ 
   nRet = L_ConvertColorSpace(pInBuf, pOutBuf, TmpBitmap.Width, CCS_RGB, CCS_CMYK); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Free memory that we no longer need */ 
   GlobalUnlock(hInBuf); 
   GlobalFree(hInBuf); 
   GlobalUnlock(hOutBuf); 
   GlobalFree(hOutBuf); 
   L_FreeBitmap(&TmpBitmap); 
   return SUCCESS; 
} 

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

LEADTOOLS Raster Imaging C API Help