中国自动化学会专家咨询工作委员会指定宣传媒体
新闻详情
isee-

G2D图像处理硬件调用和测试-基于米尔-全志T113-i国产开发板

http://www.gkong.com 2024-04-10 16:52 来源:米尔电子

MYC-YT113i核心板及开发板

真正的国产核心板,100%国产物料认证

国产T113-i处理器配备2*Cortex-A7@1.2GHz ,RISC-V

外置DDR3接口、支持视频编解码器、HiFi4 DSP

接口丰富:视频采集接口、显示器接口、USB2.0 接口、CAN 接口、千兆以太网接口

工业级:-40℃~+85℃、尺寸37mm*39mm

邮票孔+LGA,140+50PIN

米尔-全志T113-i国产核心板

米尔-全志T113-i国产开发板

全志 T113-i 2D图形加速硬件支持情况

Supports layer size up to 2048 x 2048 pixels

Supports pre-multiply alpha image data

Supports color key

Supports two pipes Porter-Duff alpha blending

Supports multiple video formats 4:2:0, 4:2:2, 4:1:1 and multiple pixel formats (8/16/24/32 bits graphics

layer)

Supports memory scan order option

Supports any format convert function

Supports 1/16× to 32× resize ratio

Supports 32-phase 8-tap horizontal anti-alias filter and 32-phase 4-tap vertical anti-alias filter

Supports window clip

Supports FillRectangle, BitBlit, StretchBlit and MaskBlit

Supports horizontal and vertical flip, clockwise 0/90/180/270 degree rotate for normal buffer

Supports horizontal flip, clockwise 0/90/270 degree rotate for LBC buffer

可以看到 g2d 硬件支持相当多的2D图像处理,包括颜色空间转换,分辨率缩放,图层叠加,旋转等。

备注:本文不具体介绍代码,代码参见:

https://mp.weixin.qq.com/s/x3NFPAxgt3A8KFLjYPYLlA

1.    开发环境配置

基础开发环境搭建参考上上上一篇

除了工具链外,我们使用 opencv-mobile 加载输入图片和保存结果,用来查看颜色转换是否正常

g2d硬件直接采用标准的 Linux ioctl 操纵,只需要引入相关结构体定义即可,无需链接so

此外,g2d的输入和输出数据必须在dmaion buffer上,因此还需要dmaion.h头文件,用来分配和释放dmaion buffer

https://github.com/MYIR-ALLWINNER/framework/blob/develop-yt113-framework/auto/sdk_lib/include/DmaIon.h

2.    基于C语言实现的YUV转RGB

这里复用之前T113-i JPG解码的函数

3.    基于ARM neon指令集优化的YUV转RGB

考虑到armv7编译器的自动neon优化能力较差,这里针对性的编写 arm neon inline assembly 实现YUV2RGB内核部分,达到最优化的性能,榨干cpu性能。

4.    基于G2D图形硬件的YUV转RGB

我们先实现 dmaion buffer 管理器,参考

https://github.com/MYIR-ALLWINNER/framework/blob/develop-yt113-framework/auto/sdk_lib/sdk_memory/DmaIon.cpp

这里贴的代码省略了异常错误处理的逻辑,有个坑是 linux-4.9 和 linux-5.4 用法不一样,米尔电子的这个T113-i系统是linux-5.4,所以不兼容4.9内核的ioctl用法习惯。

5.    然后再实现 G2D图形硬件 YUV转RGB 的转换器

1.    提前分配好YUV和RGB的dmaion buffer

2.    将YUV数据拷贝到dmaion buffer,flush cache完成同步

3.    配置转换参数,ioctl调用G2D_CMD_BITBLT_H完成转换

4.    flush cache完成同步,从dmaion buffer拷贝出RGB数据

5.    释放dmaion buffer

6.    G2D图像硬件YUV转RGB测试

考虑到dmaion buffer分配和释放都比较耗时,我们提前做好,循环调用步骤3的G2D转换,统计耗时,并在top工具中查看CPU占用率

sh-4.4# LD_LIBRARY_PATH=. ./g2dtest

INFO   : cedarc <CedarPluginVDInit:84>: register mjpeg decoder success!

this device is not whitelisted for jpeg decoder cvi

this device is not whitelisted for jpeg decoder cvi

this device is not whitelisted for jpeg decoder cvi

this device is not whitelisted for jpeg encoder rkmpp

INFO   : cedarc <log_set_level:43>: Set log level to 5 from /vendor/etc/cedarc.conf

ERROR  : cedarc <DebugCheckConfig:316>: now cedarc log level:5

ERROR  : cedarc <VideoEncCreate:241>: now cedarc log level:5

yuv420sp2rgb 46.61

yuv420sp2rgb 42.04

yuv420sp2rgb 41.32

yuv420sp2rgb 42.06

yuv420sp2rgb 41.69

yuv420sp2rgb 42.05

yuv420sp2rgb 41.29

yuv420sp2rgb 41.30

yuv420sp2rgb 42.14

yuv420sp2rgb 41.33

yuv420sp2rgb_neon 10.57

yuv420sp2rgb_neon 7.21

yuv420sp2rgb_neon 6.77

yuv420sp2rgb_neon 8.31

yuv420sp2rgb_neon 7.60

yuv420sp2rgb_neon 6.80

yuv420sp2rgb_neon 6.77

yuv420sp2rgb_neon 7.01

yuv420sp2rgb_neon 7.11

yuv420sp2rgb_neon 7.06

yuv420sp2rgb_g2d 4.32

yuv420sp2rgb_g2d 4.69

yuv420sp2rgb_g2d 4.56

yuv420sp2rgb_g2d 4.57

yuv420sp2rgb_g2d 4.52

yuv420sp2rgb_g2d 4.54

yuv420sp2rgb_g2d 4.52

yuv420sp2rgb_g2d 4.58

yuv420sp2rgb_g2d 4.60

yuv420sp2rgb_g2d 4.67

可以看到 ARM neon 的优化效果非常明显,而使用G2D图形硬件能获得进一步加速,并且能显著降低CPU占用率!

7.    转换结果对比和分析

C和neon的转换结果完全一致,但是g2d转换后的图片有明显的色差

G2D图形硬件只支持 G2D_BT601,G2D_BT709,G2D_BT2020 3种YUV系数,而JPG所使用的YUV系数是改版BT601,因此产生了色差

https://github.com/MYIR-ALLWINNER/myir-t1-kernel/blob/develop-yt113-L5.4.61/drivers/char/sunxi_g2d/g2d_bsp_v2.c

从g2d内核驱动中也可以得知,暂时没有方法为g2d设置自定义的YUV系数,g2d不适合用于JPG的编解码,但依然适合摄像头和视频编解码的颜色空间转换

版权所有 中华工控网 Copyright©2024 Gkong.com, All Rights Reserved