RGB64

RGB64 is a 64 bit color format. It is like RGB32. Every pixel consists of 8 bytes. As for the RGB32 pixel format, IC Imaging Control uses the BGRA byte order for the RGB64 pixel format. The organization of the pixels in the image buffer is from left to right and bottom up.

How to read and write pixel data

A video capture device, video format, FrameSnapSink, which defines the image data color format must have been setup. The following code fragments show step-by-step how to access and manipulate the pixel data of RGB64.

First of all, we have to capture an image. Otherwise, the image buffer would be empty. To do so, live mode is started and FrameSnapSink::snapSingle is called.

Accessing the buffer

The following code retrieves a byte pointer to the image data. We use a structure, RGB24Pixel to access the pixel's components, and reduce coordinate calculation to the level of Y800:

struct RGB64Pixel
{
    uint16_t b;
    uint16_t g;
    uint16_t r;
    uint16_t reserved;
};
RGB64Pixel* pImgData = (RGB64Pixel*)pActiveBuf->getPtr();

In this example, we want to output the first (upper left hand) two pixels of the image. In a second step, we are going to manipulate the first 3 pixels. As mentioned before, the image data is stored bottom up. Therefore, pImgData points to the first pixel of the last line of the image. To get access to the first pixel of the first line of the image, the following calculation has to be performed:

        // Calculate the index of the upper left pixel
        // Images are stored upside down in the image buffer
SIZE dim = pActiveBuf->getFrameType().dim;
int offset_upper_left = (dim.cy - 1) * dim.cx;

At first, we retrieve the width and height of the image in terms of pixels. Then, the offset to the upper left pixel is calculated. Since every pixel is exactly 1 byte in size, we can calculate the offset as:

(Height-1) * Width

Now that we have the offset to the the first pixel, we can read it out:

// The RGB64 pixel values exactly map unsigned 16-bit integers:
RGB64Pixel pix0 = pImgData[offset_upper_left + 0];
RGB64Pixel pix1 = pImgData[offset_upper_left + 1];
printf( "\nImage buffer pixel format is MEDIASUBTYPE_RGB64\n" );
printf( "Pixel 1(RGBA): %d %d %d %d\n",
        pix0.r,
        pix0.g,
        pix0.b,
        pix0.reserved );
printf( "Pixel 2(RGBA): %d %d %d %d\n",
        pix1.r,
        pix1.g,
        pix1.b,
        pix1.reserved );

Manipulating Image Data

Instead of only reading pixel data, it is, of course, possible to manipulate the data as well. The following code sets the upper left hand pixel to red and the next 2 pixels to green and blue. After this manipulation, the image is saved as a .bmp file.

// overwrite first 3 pixels and save image to disk
// Set the first pixel to RED
pImgData[offset_upper_left + 0].r = 0xffFF;
pImgData[offset_upper_left + 0].g = 0;
pImgData[offset_upper_left + 0].b = 0;
pImgData[offset_upper_left + 0].reserved = 0;
// Set the second pixel to GREEN
pImgData[offset_upper_left + 1].r = 0;
pImgData[offset_upper_left + 1].g = 0xffFF;
pImgData[offset_upper_left + 1].b = 0;
pImgData[offset_upper_left + 1].reserved = 0;
// Set the third pixel to BLUE
pImgData[offset_upper_left + 2].r = 0;
pImgData[offset_upper_left + 2].g = 0;
pImgData[offset_upper_left + 2].b = 0xfFFf;
pImgData[offset_upper_left + 2].reserved = 0;
// We save the buffer as TIFF, so that other software can view it.
saveToFileTIFF( *pActiveBuf, "rgb64.tiff" );

To check the result, open the saved image and take a look at the upper left hand pixels. They should look as follows:

image

<< Accessing an Image Buffer