L_ConvertColorSpace

#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.

 

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.

 

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

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

LTDIS

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Windows 2000 / XP/Vista, Windows CE.

See Also

Functions:

L_ColorSeparateBitmap, L_ColorMergeBitmap, L_ChannelMix, L_DeinterlaceBitmap, L_DesaturateBitmap, L_EdgeDetectStatisticalBitmap, L_LightControlBitmap, L_SmoothEdgesBitmap, L_AutoColorLevelBitmap, L_ColorLevelBitmap, L_CorrelationBitmap, L_GrayScaleToDuotone, L_GrayScaleToMultitone, L_HolesRemovalBitmapRgn, L_SelectiveColorBitmap, L_SkeletonBitmap

Topics:

Processing an Image

 

Color Halftone and Halftone Images

 

Raster Image Functions: Processing an Image

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 (TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\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;
}