C++ NDI SDK get Red Green Blue values

201 Views Asked by At

Please bear with me. I haven't done any C++ before. I've been experimenting with the NDI SDK and I'm trying to get the RGB values from an NDI source. I've been using this code to produce pixel data:

unsigned char *pixels = new unsigned char[video_frame.xres * video_frame.yres * 4];
ofxNDIutils::CopyImage((const unsigned char *)video_frame.p_data, pixels, video_frame.xres, video_frame.yres, (unsigned int)video_frame.line_stride_in_bytes, false, false);

and I'm attempting to get the values with this:

for (int y = 0; y < video_frame.yres; y++)
{
    for (int x = 0; x < video_frame.xres; x++)
    {
        printf("r:%d g:%d b:%d a:%d", pixels[4 * x * y + 0],pixels[4 * x * y + 1],pixels[4 * x * y + 2],pixels[4 * x * y + 3]);
    }
}

I'm getting values but when I use them to construct an image it doesn't look right. Any help would be appreciated.

1

There are 1 best solutions below

0
On

It turns out I had my logic wrong. Here is my current solution:

int offset = 0;
for (int y = 0; y < video_frame.yres; y++)
{
    for (int x = 0; x < video_frame.xres; x++)
    {
        printf("r:%d g:%d b:%d a:%d", pixels[offset + 0],pixels[offset + 1],pixels[offset + 2],pixels[offset + 3]);
        offset += 4;
    }
}