Specifications
Image Creation and Access
4-49
4
Example 4-8 Translating a DIB Image Into an IplImage (continued)
// fill in colors of the bitmap
for( i=0; i<256; i++)
rgb[i].rgbBlue = rgb[i].rgbGreen = rgb[i].rgbRed =
(unsigned char)i;
// set the bitmap data
for( i=0; i<WIDTH*HEIGHT; i++)
data[i] = (unsigned char)(100 + i);
// create ipl image using the bitmap
if( NULL==(img = iplTranslateDIB( dibh,&cloneData )))
return 0;
}
__finally {
int flags = IPL_IMAGE_HEADER;
if( cloneData ) flags |= IPL_IMAGE_DATA;
if( dib ) free( dib );
iplDeallocate( img, flags );
}
return IPL_StsOk == iplGetErrStatus();
}
A 4-bit-per-pixel gray-scale DIB image with a standard gray palette will be
converted into an 8-bit-per-pixel gray-scale
IplImage and the image data
will be copied, returning
cloneData
=true.
If
cloneData
is false, the data in the output image will be 4-byte-aligned;
if
cloneData
is true, the output image will have 32-byte-aligned data.
Note that if image data is not copied, the library functions inefficiently
access the data. This is because DIB image data is aligned on doubleword
(4-byte) boundaries. Alternatively, when
cloneData
is true, the DIB image
data is replicated into newly allocated image data memory and
automatically aligned to 32-byte boundaries, which results in a better
memory access.