Does NvBufferComposite work with RGBA buffer?

Hi, I am trying to use NvBufferComposite to put 9 nv_buffers into one nv_buffer. But I only get my defined background color as output. Does is work with RGBA color format or am I doing something wrong?

my code:

// ARGB output size is half of the Bayer size after demosaicing.
m_outputSize.width() = m_bayerSize.width() / 2;
m_outputSize.height() = m_bayerSize.height() / 2;

NvBufferRect dstRect[9] = {{0,0,m_outputSize.width(), m_outputSize.height()},{0,m_outputSize.width(),m_outputSize.width(), m_outputSize.height()},{0,m_outputSize.width()*2,m_outputSize.width(), m_outputSize.height()},
                           {m_outputSize.height(),0,m_outputSize.width(), m_outputSize.height()},{m_outputSize.height(),m_outputSize.width(),m_outputSize.width(), m_outputSize.height()},{m_outputSize.height(),m_outputSize.width()*2,m_outputSize.width(), m_outputSize.height()},
                           {m_outputSize.height()*2,0,m_outputSize.width(), m_outputSize.height()},{m_outputSize.height()*2,m_outputSize.width(),m_outputSize.width(), m_outputSize.height()},{m_outputSize.height()*2,m_outputSize.width()*2,m_outputSize.width(), m_outputSize.height()}};
NvBufferRect srcRect[9] = {0,0,m_outputSize.width(),m_outputSize.height(),0,0,m_outputSize.width(),m_outputSize.height(),0,0,m_outputSize.width(),m_outputSize.height(),0,0,m_outputSize.width(),m_outputSize.height(),0,0,m_outputSize.width(),m_outputSize.height(),0,0,m_outputSize.width(),m_outputSize.height(),0,0,m_outputSize.width(),m_outputSize.height(),0,0,m_outputSize.width(),m_outputSize.height(),0,0,m_outputSize.width(),m_outputSize.height()};

memset(&compParams, 0, sizeof(compParams));

compParams.input_buf_count = 9;
compParams.composite_flag = NVBUFFER_COMPOSITE;
compParams.composite_bgcolor = {255,255,255};
for (int i = 0; i<9;i++){
    compParams.dst_comp_rect[i] = dstRect[i];
    compParams.dst_comp_rect_alpha[i] = 1.0f;
    printf("dst top:%u, left:%u, width:%u, height:%u\n", dstRect[i].top, dstRect[i].left, dstRect[i].width, dstRect[i].height);
}
for (int i = 0; i<9;i++){
    compParams.src_comp_rect[i] = srcRect[i];
    printf("src top:%u, left:%u, width:%u, height:%u\n", srcRect[i].top, srcRect[i].left, srcRect[i].width, srcRect[i].height);
}

output of my prints:

dst top:0, left:0, width:480, height:270
dst top:0, left:480, width:480, height:270
dst top:0, left:960, width:480, height:270
dst top:270, left:0, width:480, height:270
dst top:270, left:480, width:480, height:270
dst top:270, left:960, width:480, height:270
dst top:540, left:0, width:480, height:270
dst top:540, left:480, width:480, height:270
dst top:540, left:960, width:480, height:270
src top:0, left:0, width:480, height:270
src top:0, left:0, width:480, height:270
src top:0, left:0, width:480, height:270
src top:0, left:0, width:480, height:270
src top:0, left:0, width:480, height:270
src top:0, left:0, width:480, height:270
src top:0, left:0, width:480, height:270
src top:0, left:0, width:480, height:270
src top:0, left:0, width:480, height:270

creating buffers

int fps=90; int image_w=m_outputSize.width()*3; int image_h=m_outputSize.height()*3;

NvBufferCreateParams cParams = {0};
cParams.colorFormat = NvBufferColorFormat_ABGR32;
cParams.width = m_outputSize.width();
cParams.height = m_outputSize.height();
cParams.layout = NvBufferLayout_Pitch;
cParams.payloadType = NvBufferPayload_SurfArray;
cParams.nvbuf_tag = NvBufferTag_CAMERA;
//NvBufferCreateEx(&cudaOutput, &cParams);

//vpiImageCreateNvBufferWrapper(cudaOutput, NULL, 0, &input);

for (unsigned int index = 0; index < 9; index++)
{
    if (NvBufferCreateEx(&grid_fd[index], &cParams) != 0)
        printf("Could not create dma_buf.\n");
}

cParams.width = image_w;
cParams.height = image_h;
for (unsigned int index = 0; index < RGBA_BUFFER_COUNT; index++)
{
    if (NvBufferCreateEx(&render_fd[index], &cParams) != 0)
        printf("Could not create dma_buf.\n");
}

and use composite:

NvBufferComposite(grid_fd, current_fd, &compParams);

but my output is just white.

Decreasing the buf_count variable in the parameter struct also didn’t help.

Best regards,
jb

Hi,
RGBA format should be supported and you may exceed the maximum instances:
[mmapi] how many input buffer is supported by function "NvBufferComposite" - #5 by DaneLLL

Please try with 8 buffers.

Hi, thanks for your fast response! I was thinking that too, but as I wrote I tried this and it did not work neither. :/

Hi,
We have sample code in

/usr/src/jetson_multimedia_api/samples/13_multi_camera

And it works by modifying the formats to NvBufferColorFormat_ABGR32. The sample has to be launched with Bayer sensors such as Rasp Pi camera v2. Do you have the sensors for a try?

Hey, thank you for your support.
I actually got it fixed a few minutes ago. My example was based on argus example cudaBayerDemosaic. In the example, there is no value set for the alpha channel of the RGBA output (uchar4). This did not make a difference when I was displaying right away after CUDA work was done, but when using NvComposite in between the alpha channel did matter. So the reason I was seeing just my background color was that the alpha value did matter and was always 0 because I did not set it.

Best regards!

1 Like