ImageGear for C and C++ on Windows v20.5 - Updated
Working with Variable Channel Depths
User Guide > Concepts > Migrating from ImageGear v14 > Working with Variable Channel Depths

When you access pixel data by using the pixel access functions in new mode, or directly via IG_image_DIB_raster_pntr_get, you may need to pay special attention to channel depths. Let's consider the example of an image in ImageGear 14.5 whose color space is reported as IG_COLOR_SPACE_ID_RGB. It has no alpha or extra channels. In the past, it was safe to assume that an RGB image had 24 bits per pixel, using 8 bits for each channel: red, green, and blue. In ImageGear 14.5, this may not be true. It's possible to have an RGB image with 36 bits per pixel, using 12 bits for each channel. Or the image could be "24-bit RGB" but the red and blue channels are 6 bits and the green channel is 12 bits. (This is an odd channel configuration, but it's easy to create such an image using the function IG_image_channel_depths_change.)

Fortunately, ImageGear gives you functions to query the relevant properties of an image and easily perform color space and channel depth conversions. This lets you prepare an image ahead of time to simplify your pixel access code. You can choose the level of flexibility and complexity you want to target by looking at the following properties of an image and taking action based on them:

Image property ImageGear function(s) to get it Notes
Color space IG_image_colorspace_get / IG_DIB_colorspace_get Specifies configuration and number of color channels
Number of channels IG_DIB_channel_count_get Includes color, alpha, and extra
Channel depths IG_DIB_channel_depth_get, IG_DIB_channel_depths_get Specifies number of bits used for each channel

Consider an example in which you want to access any kind of input image as a typical 24-bit RGB image (having 8-bit R, G, and B channels) with no alpha or extra channels. With one call to IG_image_colorspace_convert, you can make sure the image is RGB and get rid of any alpha or extra channels at the same time. Then you can use IG_image_channel_depths_change to make sure that the channel depths are each 8 bits. Here's an example function to prepare an image in this way:

 
Copy Code
// Convert any (raster) image to 24-bit RGB with no alpha/extra channels
void convertToRGB24(HIGEAR hImage)
{
        IG_image_colorspace_convert(hImage, IG_COLOR_SPACE_ID_RGB, NULL);
        AT_INT d[3] = { 8, 8, 8 };  // 8 bits for each channel - R, G, and B
        IG_image_channel_depths_change(hImage, d, IG_DEPTH_CHANGE_SCALE);
}
Is this page helpful?
Yes No
Thanks for your feedback.