#include "l_bitmap.h"
L_LTDIS_API L_INT L_ConvertColorSpace(pBufferSrc, pBufferDst, nWidth, nFormatSrc, nFormatDst)
L_UCHAR* pBufferSrc; |
pointer to the input buffer |
L_UCHAR* pBufferDst; |
pointer to the output buffer |
L_INT nWidth; |
number of pixels to be processed |
L_INT nFormatSrc; |
format of the source data |
L_INT nFormatDst; |
format of the output data |
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.
Parameter | Description | |
pBufferSrc | Pointer to the buffer holding the input data. | |
pBufferDst | Pointer to the buffer that will hold the converted data. | |
nWidth | The number of pixels to be processed. | |
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_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. | |
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_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. |
SUCCESS |
The function was successful. |
< 1 |
An error occurred. Refer to Return Codes. |
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).
Before calling this function, your program must allocate buffers for the input and output data. The format of data may be:
24 bits per pixel, except CMYK which is 32. In this case the nFormatSrc and nFormatDst must be selected from the first group.
48 bits per pixel except CMYK which is 64. In this case the nFormatSrc and nFormatDst must be selected from the second group
When using a 48 bit format, the data must be allocated in an integer (short) buffer. However, this function's buffer parameters expect unsigned characters. Therefore, when allocating space for data, to use as a parameter, you should allocate a buffer of integers, then cast the buffer pointer to the appropriate data type.
YUV or YIQ data must be always allocated in an integer (short) buffer. Therefore, when allocating space for YUV or YIQ data, to use a s a parameter, you should allocate a buffer of integers then cast the buffer pointer to the appropriate data type.
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.
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
For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application. |
Win32, x64, Linux.
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.
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName
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;
}
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET