SplitColorChannels

#include "BIImage.H"

 

int CALLBACK SplitColorChannels(HDIB hDib, HDIB *hDibChannels, BYTE colorFormat)

Description

This function will blast the image to its color components. The function works for only 24 bit per pixel or 32 bit per pixel images. The image must be in RGB color space. Splitting a 24 bit per pixel image will produce 3 result images, and splitting a 32 bit per pixel image will produce 4 result images. This function needs a lot of memory so be sure there is enough memory available before using this function. The method will return with the number of splitted color channels, and hDibChannels pointer will contain the result image pointers as a pointer array. If the input image is 32 bit per pixel, the colorFormat parameter must be FORMAT_RGB. If the third parameter is not FORMAT_RGB, the function will convert the image into the specified color space, and then split the image. It’s important, that the hDibChannels pointer array must be already allocated by the user when this function is called. The outgoing images will be allocated by the function. Splitting of a channel generates an image where only the splitted color channel remains, and all other channels are all-zero matrices.

Parameters

HDIB

hDib

The input image (24 or 32 bit/pixel).

HDIB*

hDibChannels

This parameter will contain the result images. See the description for further information.

BYTE

colorFormat

Color space format code. E.g.: FORMAT_RGB, FORMAT_HSI, etc.

Return values

The function will return the number of splited color channels. Return value only can be 0 if an error occurred, or 3 and 4 if successed.

Programming notes

Requirements

Header :     Declared in BIImage.h; include BIImage.h.

Library :    Use BIImage.lib.

DLLs :       BIimage.dll.

Code example

#include <stdlib.H>

#include <malloc.H>

#include "BIImage.H"

 

HDIB     * hDibChannels;

HDIB     Image, ImageRED=NULL, ImageGREEN=NULL, ImageBLUE=NULL, ImageQUAD=NULL;

int           channels;

 

hDibChannels = (HDIB*)calloc(4,sizeof(HDIB*));

                if (!Images)

                // error - not enough memory

 

// Load input image

 

channels = SplitColorChannels(hDIB, hDibChannels,FORMAT_RGB);

if (!channels)

{

                free(hDibChannels);

                // error

} else

{

ImageRED = hDibChannels[0];

ImageGREEN = hDibChannels[1];

ImageBLUE = hDibChannels[2];

if  (channels == 4)

ImageQUAD = hDibChannels[3];

                free(hDibChannels);

 

// operation with images

               

GlobalFree(ImageRED);

GlobalFree(ImageGREEN);

GlobalFree(ImageBLUE);

if (ImageQUAD)

GlobalFree(ImageQUAD);

}