L_ConvertColorSpace

#include "l_bitmap.h"

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

L_UCHAR L_FAR * pBufferSrc;

/* pointer to the input buffer */

L_UCHAR L_FAR * 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:

image\sqrblit.gif The nFormatSrc and nFormatDst must be selected from the same group (the first or second group shown above).

image\sqrblit.gif 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

image\sqrblit.gif 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.

image\sqrblit.gif 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.

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

image\sqrblit.gif 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 only in the Document/Medical 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 95 / 98 / Me, Windows 2000 / XP, 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_UCHAR L_FAR *pInBuf; /* Buffer to hold the input row */
HGLOBAL hInBuf; /* Handle to the input buffer */
L_UCHAR L_FAR *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 */
L_LoadBitmap
 (TEXT("IMAGE3.CMP"), &TmpBitmap, sizeof(BITMAPHANDLE), 24, ORDER_BGR, NULL, NULL);
/* Allocate the input buffer for 24-bit RGB data */
hInBuf = GlobalAlloc(GMEM_MOVEABLE, TmpBitmap.Width * 3);
pInBuf = (L_UCHAR L_FAR *)GlobalLock( hInBuf );
/* Allocate the output buffer for 32-bit CMYK data */
hOutBuf = GlobalAlloc(GMEM_MOVEABLE, TmpBitmap.Width * 4);
pOutBuf = (L_UCHAR L_FAR *)GlobalLock( hOutBuf );
/* Get one row of data from the bitmap */
L_AccessBitmap
(&TmpBitmap);
L_GetBitmapRow
(&TmpBitmap, pInBuf, 0, TmpBitmap.BytesPerLine);
L_ReleaseBitmap
(&TmpBitmap);
/* Convert the data from RGB in pInBuf to CMYK in pOutBuf */
L_ConvertColorSpace
(pInBuf, pOutBuf, TmpBitmap.Width, CCS_RGB, CCS_CMYK);
/* Free memory that we no longer need */
GlobalUnlock(hInBuf);
GlobalFree(hInBuf);
GlobalUnlock(hOutBuf);
GlobalFree(hOutBuf);
L_FreeBitmap
(&TmpBitmap);