The Y800 color format is an 8 bit monochrome format. Every pixel is represented by one byte. The organization of the pixels in the image buffer is from left to right and top down. In other words: The first byte of the image buffer corresponds to the first pixel of the first line of the image.
How to read and write pixel data
A video capture device, video format, FrameHandlerSink with a MemBufferCollection, which defines the image data color format must first have been setup. The following code fragments show step-by-step how to access and manipulate the pixel data of Y800.
First of all, we have to capture an image. Otherwise, the image buffer would be empty. To do so, we start live mode and call Grabber::snapImages.
Accessing the buffer
The following code retrieves a byte pointer to the image data:
BYTE* pbImgData = pActiveBuf->getPtr();
In this example, we want to output the first (upper left) two pixels of the image. In a second step we are going to manipulate the first 3 pixels. Because Y800 images are stored top-down, the index of the upper left pixel is 0:
int iOffsUpperLeft = 0;
Now that we have the offset to the the first pixel, we can read it out:
printf( "\nImage buffer pixel format is eY800\n" );
printf( "Pixel 1: %d\n", pbImgData[iOffsUpperLeft ] );
printf( "Pixel 2: %d\n", pbImgData[iOffsUpperLeft+1] );
Manipulating Image Data
Instead of only reading pixel data, it is, of course, possible to manipulate the data as well. The following code will set the upper left hand pixel to black and the next 2 pixels to gray and white. After this manipulation, the image is saved as a BMP file.
pbImgData[iOffsUpperLeft ] = 0;
pbImgData[iOffsUpperLeft+1] = 128;
pbImgData[iOffsUpperLeft+2] = 255;
pActiveBuf->save( "Y800.bmp" );
To check the result, open the saved image and take a look at the upper left hand pixels. They should look as follows:
<< Accessing an Image Buffer