LBuffer::ConvertColorSpace

#include "ltwrappr.h"

virtual L_INT LBuffer::ConvertColorSpace(LBufferSrc, nWidth, nFormatSrc, nFormatDst)

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

Parameters

LBuffer& LBufferSrc

The LBuffer object holding the input data.

L_INT nWidth

The number of pixels to be processed.

L_INT nFormatSrc

Format of the source data. There are two possible groups of values. The first group of values is:

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 second group of values is:

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 possible groups of values. The first group of values is:

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 second group of values is:

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:

The nFormatSrc and nFormatDst must be selected from the same group (the first or second group shown above). The format of data may be:

When using a 48-bit format, the data must be allocated in an integer (short) buffer, but this function's buffer parameters expect unsigned characters. Therefore, when allocating space for data, you should allocate a buffer of integers; then cast the buffer pointer to the appropriate data type when using it as a parameter.

YUV or YIQ data must be always allocated in an integer (short) buffer. Therefore, when allocating space for YUV or YIQ data, you should allocate a buffer of integers; then cast the buffer pointer to the appropriate data type when using it as a parameter.

RGB input data for this function must be 24-bit or 48-bit in BGR order.

Color-plane values for all models of 24 bits, except YUV and YIQ, are scaled from 0 to 255. For example, a hue, which is normally represented as 0-359, is instead scaled to fit the 0-255 range. For YUV or YIQ, color plane values are scaled from 0 to 16383.

The parameter LBufferSrc is passed by reference, and is a required parameter.

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

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

L_INT LBuffer__ConvertColorSpaceExample() 
{ 
   L_INT nRet; 
   LBitmapBase LeadBitmap; 
 
   nRet = LeadBitmap.Load(MAKE_IMAGE_PATH(TEXT("image1.cmp"))) ; 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   LBuffer LeadBuffer(LeadBitmap.GetWidth() * 3); 
   LBuffer TmpBuffer (LeadBitmap.GetWidth() * 4); 
 
   nRet =(L_INT)LeadBitmap.GetRow(&LeadBuffer,0); 
   if(nRet < 1) 
      return nRet; 
 
   nRet =TmpBuffer.ConvertColorSpace(LeadBuffer,LeadBitmap.GetWidth(), CCS_RGB, CCS_CMYK); 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   LeadBuffer = TmpBuffer ; 
 
   nRet =TmpBuffer.Free() ; 
   if(nRet !=SUCCESS) 
      return nRet; 
   nRet =LeadBuffer.Free() ; 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   return SUCCESS; 
} 
Help Version 21.0.2021.4.8
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help