Problems with G2D API

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Problems with G2D API

跳至解决方案
4,758 次查看
christhi
Contributor II

Hi everybody,

I use the I.MX 8M Plus with Hardknott Yocto.

I have a problem understanding and using the G2D API. I try to implement the following:

Input Image ( ARGB32 format, Size(x1,y1)  ) should be converted to Output Image ( RGB format, Size(x2, y2) )

I create the input and output buffers and surfaces in the constructor like that:

g2dInputBuffer  = g2d_alloc(m_inputCameraFormat.height * m_inputCameraFormat.width * 4, 1);
g2dOutputBuffer = g2d_alloc(m_modelInputInformations.height * m_modelInputInformations.width * 3, 1);
inputSurface = new g2d_surface();
inputSurface->format = G2D_XRGB8888;
inputSurface->left = 0;
inputSurface->top = 0;
inputSurface->right = m_inputCameraFormat.width;
inputSurface->bottom = m_inputCameraFormat.height;
inputSurface->stride = m_inputCameraFormat.width;
inputSurface->width = m_inputCameraFormat.width;
inputSurface->height = m_inputCameraFormat.height;
inputSurface->rot = G2D_ROTATION_0;

outputSurface = new g2d_surface();
outputSurface->format = G2D_RGB888;
outputSurface->left = 0;
outputSurface->top = 0;
outputSurface->right = m_modelInputInformations.width;
outputSurface->bottom = m_modelInputInformations.height;
outputSurface->stride = m_modelInputInformations.width;
outputSurface->width = m_modelInputInformations.width;
outputSurface->height = m_modelInputInformations.height;
outputSurface->rot = G2D_ROTATION_0;

 

After that I want the converting for every incoming input frame like that:

    void *handle = nullptr;
g2d_open(&handle);
g2dInputBuffer->buf_vaddr = const_cast<void*>(inputBuffer);
inputSurface->planes[0] = g2dInputBuffer->buf_paddr;
outputSurface->planes[0] = g2dOutputBuffer->buf_paddr;
g2d_blit(handle, inputSurface, outputSurface);
g2d_close(handle);

 

I get the following error message: g2d_blit_2d, line1397: Invalid dst format 10!

Has anybody some help or advice?

Thank you !

标记 (2)
0 项奖励
回复
1 解答
4,722 次查看
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hello christhi,

RGB888 is not supported for CSC. Supported SRC/DST CSC format can be found in i.MX_Graphics_User's_Guide.pdf:

Bio_TICFSL_0-1635423072730.png

 

RGBs format: { (string)RGB16, (string)RGBx, (string)RGBA, (string)BGRA, (string)BGRx, (string)BGR16, (string)ARGB, (string)ABGR, (string)xRGB, (string)xBGR }

Regards

在原帖中查看解决方案

6 回复数
4,723 次查看
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hello christhi,

RGB888 is not supported for CSC. Supported SRC/DST CSC format can be found in i.MX_Graphics_User's_Guide.pdf:

Bio_TICFSL_0-1635423072730.png

 

RGBs format: { (string)RGB16, (string)RGBx, (string)RGBA, (string)BGRA, (string)BGRx, (string)BGR16, (string)ARGB, (string)ABGR, (string)xRGB, (string)xBGR }

Regards

1,765 次查看
ZHIYUANSONG
Contributor I
Hi, There was a problem with the g2d module, My board is IMX8QM, Linux version 5.4.129-5.4.0-devel+git.cb88cc157bfb (oe-user@oe-host) (gcc version 9.3.0 (GCC)) #1 SMP PREEMPT Wed Sep 29 18:17:21 UTC 2021.

My code as follow, All api return is success, but output_buffer->buf_vaddr value is 0.

Could you help me to solve this problem? Thank you~

g2d_buf* input_buffer = nullptr;
g2d_buf* output_buffer = nullptr;
void* g2d_handle = nullptr;
g2d_surface* src_surface = new g2d_surface;
g2d_surface* dst_surface = new g2d_surface;
g2d_open(&g2d_handle);
input_buffer = g2d_alloc(1280*800*4, 1);
output_buffer = g2d_alloc(1280*800*4, 1);
FILE* fp = fopen("/home/root/user_test/P118_1280x800-32_0001_FB152.rgb", "rb");
if(fp != nullptr){
fread(input_buffer->buf_vaddr, 1, input_buffer->buf_size, fp);
fclose(fp);
}else{}

memset(src_surface, 0, sizeof(g2d_surface));
memset(dst_surface, 0, sizeof(g2d_surface));

src_surface->planes[0] = input_buffer->buf_paddr;
src_surface->left = 0;
src_surface->top = 0;
src_surface->right = 1280;
src_surface->bottom = 800;
src_surface->stride = 1280;
src_surface->width = 1280;
src_surface->height = 800;
src_surface->rot = G2D_ROTATION_0;
src_surface->format = G2D_RGBX8888;


dst_surface->planes[0] = input_buffer->buf_paddr;
dst_surface->left = 0;
dst_surface->top = 0;
dst_surface->right = 1280;
dst_surface->bottom = 800;
dst_surface->stride = 1280;
dst_surface->width = 1280;
dst_surface->height = 800;
dst_surface->rot = G2D_ROTATION_0;
dst_surface->format = G2D_RGBX8888;

std::cout << input_buffer << " " << input_buffer->buf_size << " " << input_buffer->buf_vaddr << std::endl;

std::cout << g2d_blit(g2d_handle, src_surface, dst_surface) << std::endl;
std::cout << g2d_finish(g2d_handle) << std::endl;

fp = fopen("/home/root/user_test/P118_1280x800-32_0001_FB152-test111.rgb", "wb");
if(fp != nullptr){
std::cout << fwrite(output_buffer->buf_vaddr, 1, 1280*800*4, fp) << std::endl ;
fclose(fp);
}else{}

0 项奖励
回复
4,574 次查看
quercuspau
Contributor II

Hello,

From this table, I understand that all the formats from src column can be converted to RGB.

Regarding to RGB888, IMX Graphics user guide mentions:

• RGB pixel buffer only uses planes [0], buffer address is with 16 bytes alignment on i.MX 6 (except i.MX 6Quad Plus), 1 pixel alignment on i.MX 6Quad Plus, i.MX 7ULP and i.MX 8 family devices.
• NV12: Y in planes [0], UV in planes [1], with 64bytes alignment,
• I420: Y in planes [0], U in planes [1], U in planes [2], with 64 bytes alignment
• The cropped region in source surface is specified with left, top, right and bottom parameters.
• RGB stride alignment is 16 bytes on i.MX 6 (except i.MX 6Quad Plus), 1 pixel alignment on i.MX 6Quad Plus, i.MX 7ULP and i.MX 8 family devices, both for source and destination surface.
....

If I understood correctly, i.MX 6 (except i.MX 6Quad Plus) only support 16/32 bits RGB. However other IMX that uses G2D doesn't have this limitation, only requires pixel alignment that can be 8/16/24/32 bits. In this case, RGB888 should work.

Am I wrong?

Thanks for you support

 

0 项奖励
回复
4,695 次查看
christhi
Contributor II

Hello,

is it possible to "delete" the alpha channel from the RGBA8888 image using only the G2D API? I need a RGB888 image and at this moment I use the sharing buffers mechanism. For scaling I use the g2d API and after that I convert the image to RGB888 using OpenCV. Because I can't use OpenCV for GPU acceleration I would prefer only using the G2D API.

Thank you for your help !

0 项奖励
回复
3,804 次查看
malik_cisse
Senior Contributor I

Hi Christhi,
Could you solve this issue.
I am using imx8mp CPU and YUYV to RGB G2D conversion can only output RGBs8888 (32bit).
Like you I need RGB888 (24bit). I don't want to use OpenCV or other processing. I would like to do this entirely in the GPU.
Thank you,

0 项奖励
回复
4,699 次查看
christhi
Contributor II

Hello,

thank you for that !

I thought the RGBs format contains the RGB888 format.

0 项奖励
回复