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

发布时间:2024-4-12 20:04    发布者:swiftman
关键词: T113-i , 米尔 , 全志 , 国产MPU , G2D
本篇测评由电子工程世界的优秀测评者“jf_99374259”提供。
本文将介绍基于米尔电子MYD-YT113i开发板的G2D图像处理硬件调用和测试。

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


7.webp.jpg

8.webp.jpg
9.webp.jpg


全志 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图像处理,包括颜色空间转换,分辨率缩放,图层叠加,旋转等
2.png

开发环境配置
基础开发环境搭建参考上上上一篇
]https://bbs.elecfans.com/jishu_2408808_1_1.html
除了工具链外,我们使用 opencv-mobile 加载输入图片和保存结果,用来查看颜色转换是否正常g2d硬件直接采用标准的 Linux ioctl 操纵,只需要引入相关结构体定义即可,无需链接so
https://github.com/MYIR-ALLWINNER/framework/blob/develop-yt113-framework/auto/sdk_lib/include/g2d_driver.h
此外,g2d的输入和输出数据必须在dmaion buffer上,因此还需要dmaion.h头文件,用来分配和释放dmaion buffer
https://github.com/MYIR-ALLWINNER/framework/blob/develop-yt113-framework/auto/sdk_lib/include/DmaIon.h

基于C语言实现的YUV转RGB
这里复用之前T113-i JPG解码的函数
  1. void yuv420sp2rgb(const unsigned char* yuv420sp, int w, int h, unsigned char* rgb)
  2. {
  3.     const unsigned char* yptr = yuv420sp;
  4.     const unsigned char* vuptr = yuv420sp + w * h;
  5.    
  6.     for (int y = 0; y < h; y += 2)
  7.     {
  8.        const unsigned char* yptr0 = yptr;
  9.        const unsigned char* yptr1 = yptr + w;
  10.        unsigned char* rgb0 = rgb;
  11.        unsigned char* rgb1 = rgb + w * 3;
  12.       
  13.        int remain = w;
  14.       
  15. #define SATURATE_CAST_UCHAR(X) (unsigned char)::std::min(::std::max((int)(X), 0), 255);
  16.        for (; remain > 0; remain -= 2)
  17.        {
  18.           // R = 1.164 * yy + 1.596 * vv
  19.           // G = 1.164 * yy - 0.813 * vv - 0.391 * uu
  20.           // B = 1.164 * yy              + 2.018 * uu
  21.          
  22.           // R = Y + (1.370705 * (V-128))
  23.           // G = Y - (0.698001 * (V-128)) - (0.337633 * (U-128))
  24.           // B = Y + (1.732446 * (U-128))
  25.          
  26.           // R = ((Y << 6) + 87.72512 * (V-128)) >> 6
  27.           // G = ((Y << 6) - 44.672064 * (V-128) - 21.608512 * (U-128)) >> 6
  28.           // B = ((Y << 6) + 110.876544 * (U-128)) >> 6
  29.          
  30.           // R = ((Y << 6) + 90 * (V-128)) >> 6
  31.           // G = ((Y << 6) - 46 * (V-128) - 22 * (U-128)) >> 6
  32.           // B = ((Y << 6) + 113 * (U-128)) >> 6
  33.          
  34.           // R = (yy + 90 * vv) >> 6
  35.           // G = (yy - 46 * vv - 22 * uu) >> 6
  36.           // B = (yy + 113 * uu) >> 6
  37.          
  38.           int v = vuptr[0] - 128;
  39.           int u = vuptr[1] - 128;
  40.          
  41.           int ruv = 90 * v;
  42.           int guv = -46 * v + -22 * u;
  43.           int buv = 113 * u;
  44.          
  45.           int y00 = yptr0[0] << 6;
  46.           rgb0[0] = SATURATE_CAST_UCHAR((y00 + ruv) >> 6);
  47.           rgb0[1] = SATURATE_CAST_UCHAR((y00 + guv) >> 6);
  48.           rgb0[2] = SATURATE_CAST_UCHAR((y00 + buv) >> 6);
  49.          
  50.           int y01 = yptr0[1] << 6;
  51.           rgb0[3] = SATURATE_CAST_UCHAR((y01 + ruv) >> 6);
  52.           rgb0[4] = SATURATE_CAST_UCHAR((y01 + guv) >> 6);
  53.           rgb0[5] = SATURATE_CAST_UCHAR((y01 + buv) >> 6);
  54.          
  55.           int y10 = yptr1[0] << 6;
  56.           rgb1[0] = SATURATE_CAST_UCHAR((y10 + ruv) >> 6);
  57.           rgb1[1] = SATURATE_CAST_UCHAR((y10 + guv) >> 6);
  58.           rgb1[2] = SATURATE_CAST_UCHAR((y10 + buv) >> 6);
  59.          
  60.           int y11 = yptr1[1] << 6;
  61.           rgb1[3] = SATURATE_CAST_UCHAR((y11 + ruv) >> 6);
  62.           rgb1[4] = SATURATE_CAST_UCHAR((y11 + guv) >> 6);
  63.           rgb1[5] = SATURATE_CAST_UCHAR((y11 + buv) >> 6);
  64.          
  65.           yptr0 += 2;
  66.           yptr1 += 2;
  67.           vuptr += 2;
  68.           rgb0 += 6;
  69.           rgb1 += 6;
  70.        }
  71. #undef SATURATE_CAST_UCHAR

  72.        yptr += 2 * w;
  73.        rgb += 2 * 3 * w;
  74.     }
  75. }
复制代码

基于ARM neon指令集优化的YUV转RGB
考虑到armv7编译器的自动neon优化能力较差,这里针对性的编写 arm neon inline assembly 实现YUV2RGB内核部分,达到最优化的性能,榨干cpu性能
  1. void yuv420sp2rgb_neon(const unsigned char* yuv420sp, int w, int h, unsigned char* rgb)
  2. {
  3.     const unsigned char* yptr = yuv420sp;
  4.     const unsigned char* vuptr = yuv420sp + w * h;
  5.    
  6. #if __ARM_NEON
  7.     uint8x8_t _v128 = vdup_n_u8(128);
  8.     int8x8_t _v90 = vdup_n_s8(90);
  9.     int8x8_t _v46 = vdup_n_s8(46);
  10.     int8x8_t _v22 = vdup_n_s8(22);
  11.     int8x8_t _v113 = vdup_n_s8(113);
  12. #endif // __ARM_NEON

  13.     for (int y = 0; y < h; y += 2)
  14.     {
  15.        const unsigned char* yptr0 = yptr;
  16.        const unsigned char* yptr1 = yptr + w;
  17.        unsigned char* rgb0 = rgb;
  18.        unsigned char* rgb1 = rgb + w * 3;
  19.       
  20. #if __ARM_NEON
  21.        int nn = w >> 3;
  22.        int remain = w - (nn << 3);
  23.    
  24. #else
  25.        int remain = w;
  26. #endif // __ARM_NEON

  27. #if __ARM_NEON
  28. #if __aarch64__
  29.        for (; nn > 0; nn--)
  30.        {
  31.           int16x8_t _yy0 = vreinterpretq_s16_u16(vshll_n_u8(vld1_u8(yptr0), 6));
  32.           int16x8_t _yy1 = vreinterpretq_s16_u16(vshll_n_u8(vld1_u8(yptr1), 6));
  33.          
  34.           int8x8_t _vvuu = vreinterpret_s8_u8(vsub_u8(vld1_u8(vuptr), _v128));
  35.           int8x8x2_t _vvvvuuuu = vtrn_s8(_vvuu, _vvuu);
  36.           int8x8_t _vv = _vvvvuuuu.val[0];
  37.           int8x8_t _uu = _vvvvuuuu.val[1];
  38.          
  39.           int16x8_t _r0 = vmlal_s8(_yy0, _vv, _v90);
  40.           int16x8_t _g0 = vmlsl_s8(_yy0, _vv, _v46);
  41.           _g0 = vmlsl_s8(_g0, _uu, _v22);
  42.           int16x8_t _b0 = vmlal_s8(_yy0, _uu, _v113);
  43.          
  44.           int16x8_t _r1 = vmlal_s8(_yy1, _vv, _v90);
  45.           int16x8_t _g1 = vmlsl_s8(_yy1, _vv, _v46);
  46.           _g1 = vmlsl_s8(_g1, _uu, _v22);
  47.           int16x8_t _b1 = vmlal_s8(_yy1, _uu, _v113);
  48.          
  49.           uint8x8x3_t _rgb0;
  50.           _rgb0.val[0] = vqshrun_n_s16(_r0, 6);
  51.           _rgb0.val[1] = vqshrun_n_s16(_g0, 6);
  52.           _rgb0.val[2] = vqshrun_n_s16(_b0, 6);
  53.          
  54.           uint8x8x3_t _rgb1;
  55.           _rgb1.val[0] = vqshrun_n_s16(_r1, 6);
  56.           _rgb1.val[1] = vqshrun_n_s16(_g1, 6);
  57.           _rgb1.val[2] = vqshrun_n_s16(_b1, 6);
  58.          
  59.           vst3_u8(rgb0, _rgb0);
  60.           vst3_u8(rgb1, _rgb1);
  61.          
  62.           yptr0 += 8;
  63.           yptr1 += 8;
  64.           vuptr += 8;
  65.           rgb0 += 24;
  66.           rgb1 += 24;
  67.        }
  68. #else
  69.        if (nn > 0)
  70.        {
  71.           asm volatile(
  72.              "0:                             n"
  73.              "pld        [%3, #128]          n"
  74.              "vld1.u8    {d2}, [%3]!         n"
  75.              "vsub.s8    d2, d2, %12         n"
  76.              "pld        [%1, #128]          n"
  77.              "vld1.u8    {d0}, [%1]!         n"
  78.              "pld        [%2, #128]          n"
  79.              "vld1.u8    {d1}, [%2]!         n"
  80.              "vshll.u8   q2, d0, #6          n"
  81.              "vorr       d3, d2, d2          n"
  82.              "vshll.u8   q3, d1, #6          n"
  83.              "vorr       q9, q2, q2          n"
  84.              "vtrn.s8    d2, d3              n"
  85.              "vorr       q11, q3, q3         n"
  86.              "vmlsl.s8   q9, d2, %14         n"
  87.              "vorr       q8, q2, q2          n"
  88.              "vmlsl.s8   q11, d2, %14        n"
  89.              "vorr       q10, q3, q3         n"
  90.              "vmlal.s8   q8, d2, %13         n"
  91.              "vmlal.s8   q2, d3, %16         n"
  92.              "vmlal.s8   q10, d2, %13        n"
  93.              "vmlsl.s8   q9, d3, %15         n"
  94.              "vmlal.s8   q3, d3, %16         n"
  95.              "vmlsl.s8   q11, d3, %15        n"
  96.              "vqshrun.s16 d24, q8, #6        n"
  97.              "vqshrun.s16 d26, q2, #6        n"
  98.              "vqshrun.s16 d4, q10, #6        n"
  99.              "vqshrun.s16 d25, q9, #6        n"
  100.              "vqshrun.s16 d6, q3, #6         n"
  101.              "vqshrun.s16 d5, q11, #6        n"
  102.              "subs       %0, #1              n"
  103.              "vst3.u8    {d24-d26}, [%4]!    n"
  104.              "vst3.u8    {d4-d6}, [%5]!      n"
  105.              "bne        0b                  n"
  106.              : "=r"(nn),    // %0
  107.              "=r"(yptr0), // %1
  108.              "=r"(yptr1), // %2
  109.              "=r"(vuptr), // %3
  110.              "=r"(rgb0),  // %4
  111.              "=r"(rgb1)   // %5
  112.              : "0"(nn),
  113.              "1"(yptr0),
  114.              "2"(yptr1),
  115.              "3"(vuptr),
  116.              "4"(rgb0),
  117.              "5"(rgb1),
  118.              "w"(_v128), // %12
  119.              "w"(_v90),  // %13
  120.              "w"(_v46),  // %14
  121.              "w"(_v22),  // %15
  122.              "w"(_v113)  // %16
  123.              : "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "d26");
  124.           }
  125.          
  126. #endif // __aarch64__
  127. #endif // __ARM_NEON

  128. #define SATURATE_CAST_UCHAR(X) (unsigned char)::std::min(::std::max((int)(X), 0), 255);
  129.        for (; remain > 0; remain -= 2)
  130.        {
  131.           // R = 1.164 * yy + 1.596 * vv
  132.           // G = 1.164 * yy - 0.813 * vv - 0.391 * uu
  133.           // B = 1.164 * yy              + 2.018 * uu
  134.          
  135.           // R = Y + (1.370705 * (V-128))
  136.           // G = Y - (0.698001 * (V-128)) - (0.337633 * (U-128))
  137.           // B = Y + (1.732446 * (U-128))
  138.          
  139.           // R = ((Y << 6) + 87.72512 * (V-128)) >> 6
  140.           // G = ((Y << 6) - 44.672064 * (V-128) - 21.608512 * (U-128)) >> 6
  141.           // B = ((Y << 6) + 110.876544 * (U-128)) >> 6
  142.          
  143.           // R = ((Y << 6) + 90 * (V-128)) >> 6
  144.           // G = ((Y << 6) - 46 * (V-128) - 22 * (U-128)) >> 6
  145.           // B = ((Y << 6) + 113 * (U-128)) >> 6
  146.          
  147.           // R = (yy + 90 * vv) >> 6
  148.           // G = (yy - 46 * vv - 22 * uu) >> 6
  149.           // B = (yy + 113 * uu) >> 6
  150.          
  151.           int v = vuptr[0] - 128;
  152.           int u = vuptr[1] - 128;
  153.          
  154.           int ruv = 90 * v;
  155.           int guv = -46 * v + -22 * u;
  156.           int buv = 113 * u;
  157.          
  158.           int y00 = yptr0[0] << 6;
  159.           rgb0[0] = SATURATE_CAST_UCHAR((y00 + ruv) >> 6);
  160.           rgb0[1] = SATURATE_CAST_UCHAR((y00 + guv) >> 6);
  161.           rgb0[2] = SATURATE_CAST_UCHAR((y00 + buv) >> 6);
  162.          
  163.           int y01 = yptr0[1] << 6;
  164.           rgb0[3] = SATURATE_CAST_UCHAR((y01 + ruv) >> 6);
  165.           rgb0[4] = SATURATE_CAST_UCHAR((y01 + guv) >> 6);
  166.           rgb0[5] = SATURATE_CAST_UCHAR((y01 + buv) >> 6);
  167.          
  168.           int y10 = yptr1[0] << 6;
  169.           rgb1[0] = SATURATE_CAST_UCHAR((y10 + ruv) >> 6);
  170.           rgb1[1] = SATURATE_CAST_UCHAR((y10 + guv) >> 6);
  171.           rgb1[2] = SATURATE_CAST_UCHAR((y10 + buv) >> 6);
  172.          
  173.           int y11 = yptr1[1] << 6;
  174.           rgb1[3] = SATURATE_CAST_UCHAR((y11 + ruv) >> 6);
  175.           rgb1[4] = SATURATE_CAST_UCHAR((y11 + guv) >> 6);
  176.           rgb1[5] = SATURATE_CAST_UCHAR((y11 + buv) >> 6);
  177.          
  178.           yptr0 += 2;
  179.           yptr1 += 2;
  180.           vuptr += 2;
  181.           rgb0 += 6;
  182.           rgb1 += 6;
  183.        }
  184. #undef SATURATE_CAST_UCHAR

  185.        yptr += 2 * w;
  186.        rgb += 2 * 3 * w;
  187.     }
  188. }
复制代码

基于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用法习惯
  1. struct ion_memory
  2. {
  3.     size_t size;
  4.     int fd;
  5.     void* virt_addr;
  6.     unsigned int phy_addr;
  7. };

  8. class ion_allocator
  9. {
  10. public:
  11.     ion_allocator();
  12.     ~ion_allocator();
  13.    
  14.     int open();
  15.     void close();
  16.    
  17.     int alloc(size_t size, struct ion_memory* mem);
  18.     int free(struct ion_memory* mem);
  19.    
  20.     int flush(struct ion_memory* mem);
  21.    
  22. public:
  23.     int ion_fd;
  24.     int cedar_fd;
  25. };

  26.     ion_allocator::ion_allocator()
  27. {
  28.     ion_fd = -1;
  29.     cedar_fd = -1;
  30. }

  31. ion_allocator::~ion_allocator()
  32. {
  33.     close();
  34. }

  35. int ion_allocator::open()
  36. {
  37.     close();
  38.    
  39.     ion_fd = ::open("/dev/ion", O_RDWR);
  40.     cedar_fd = ::open("/dev/cedar_dev", O_RDONLY);
  41.    
  42.     ioctl(cedar_fd, IOCTL_ENGINE_REQ, 0);
  43.    
  44.     return 0;
  45. }

  46. void ion_allocator::close()
  47. {
  48.     if (cedar_fd != -1)
  49.     {
  50.        ioctl(cedar_fd, IOCTL_ENGINE_REL, 0);
  51.        ::close(cedar_fd);
  52.        cedar_fd = -1;
  53.     }
  54.    
  55.     if (ion_fd != -1)
  56.     {
  57.        ::close(ion_fd);
  58.        ion_fd = -1;
  59.     }
  60. }

  61. int ion_allocator::alloc(size_t size, struct ion_memory* mem)
  62. {
  63.     struct aw_ion_new_alloc_data alloc_data;
  64.     alloc_data.len = size;
  65.     alloc_data.heap_id_mask = AW_ION_SYSTEM_HEAP_MASK;
  66.     alloc_data.flags = AW_ION_CACHED_FLAG | AW_ION_CACHED_NEEDS_SYNC_FLAG;
  67.     alloc_data.fd = 0;
  68.     alloc_data.unused = 0;
  69.     ioctl(ion_fd, AW_ION_IOC_NEW_ALLOC, &alloc_data);
  70.    
  71.     void* virt_addr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, alloc_data.fd, 0);
  72.    
  73.     struct aw_user_iommu_param iommu_param;
  74.     iommu_param.fd = alloc_data.fd;
  75.     iommu_param.iommu_addr = 0;
  76.     ioctl(cedar_fd, IOCTL_GET_IOMMU_ADDR, &iommu_param);
  77.    
  78.     mem->size = size;
  79.     mem->fd = alloc_data.fd;
  80.     mem->virt_addr = virt_addr;
  81.     mem->phy_addr = iommu_param.iommu_addr;
  82.    
  83.     return 0;
  84. }

  85. int ion_allocator::free(struct ion_memory* mem)
  86. {
  87.     if (mem->fd == -1)
  88.         return 0;
  89.         
  90.         struct aw_user_iommu_param iommu_param;
  91.         iommu_param.fd = mem->fd;
  92.         ioctl(cedar_fd, IOCTL_FREE_IOMMU_ADDR, &iommu_param);
  93.         
  94.         munmap(mem->virt_addr, mem->size);
  95.         
  96.         ::close(mem->fd);
  97.         
  98.         mem->size = 0;
  99.         mem->fd = -1;
  100.         mem->virt_addr = 0;
  101.         mem->phy_addr = 0;
  102.         
  103.         return 0;
  104. }

  105. int ion_allocator::flush(struct ion_memory* mem)
  106. {
  107.         struct dma_buf_sync sync;
  108.         sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_RW;
  109.         ioctl(mem->fd, DMA_BUF_IOCTL_SYNC, &sync);
  110.         
  111.         return 0;
  112. }
复制代码

然后再实现 G2D图形硬件 YUV转RGB 的转换器
  • 提前分配好YUV和RGB的dmaion buffer
  • 将YUV数据拷贝到dmaion buffer,flush cache完成同步
  • 配置转换参数,ioctl调用G2D_CMD_BITBLT_H完成转换
  • flush cache完成同步,从dmaion buffer拷贝出RGB数据
  • 释放dmaion buffer


  1. // 步骤1
  2. ion_allocator ion;
  3. ion.open();

  4. struct ion_memory yuv_ion;
  5. ion.alloc(rgb_size, &rgb_ion);

  6. struct ion_memory rgb_ion;
  7. ion.alloc(yuv_size, &yuv_ion);

  8. int g2d_fd = ::open("/dev/g2d", O_RDWR);

  9. // 步骤2
  10. memcpy((unsigned char*)yuv_ion.virt_addr, yuv420sp, yuv_size);
  11. ion.flush(&yuv_ion);

  12. // 步骤3
  13. g2d_blt_h blit;
  14. memset(&blit, 0, sizeof(blit));

  15. blit.flag_h = G2D_BLT_NONE_H;

  16. blit.src_image_h.format = G2D_FORMAT_YUV420UVC_V1U1V0U0;
  17. blit.src_image_h.width = width;
  18. blit.src_image_h.height = height;
  19. blit.src_image_h.align[0] = 0;
  20. blit.src_image_h.align[1] = 0;
  21. blit.src_image_h.clip_rect.x = 0;
  22. blit.src_image_h.clip_rect.y = 0;
  23. blit.src_image_h.clip_rect.w = width;
  24. blit.src_image_h.clip_rect.h = height;
  25. blit.src_image_h.gamut = G2D_BT601;
  26. blit.src_image_h.bpremul = 0;
  27. blit.src_image_h.mode = G2D_PIXEL_ALPHA;
  28. blit.src_image_h.use_phy_addr = 0;
  29. blit.src_image_h.fd = yuv_ion.fd;

  30. blit.dst_image_h.format = G2D_FORMAT_RGB888;
  31. blit.dst_image_h.width = width;
  32. blit.dst_image_h.height = height;
  33. blit.dst_image_h.align[0] = 0;
  34. blit.dst_image_h.clip_rect.x = 0;
  35. blit.dst_image_h.clip_rect.y = 0;
  36. blit.dst_image_h.clip_rect.w = width;
  37. blit.dst_image_h.clip_rect.h = height;
  38. blit.dst_image_h.gamut = G2D_BT601;
  39. blit.dst_image_h.bpremul = 0;
  40. blit.dst_image_h.mode = G2D_PIXEL_ALPHA;
  41. blit.dst_image_h.use_phy_addr = 0;
  42. blit.dst_image_h.fd = rgb_ion.fd;

  43. ioctl(g2d_fd, G2D_CMD_BITBLT_H, &blit);

  44. // 步骤4
  45. ion.flush(&rgb_ion);
  46. memcpy(rgb, (const unsigned char*)rgb_ion.virt_addr, rgb_size);

  47. // 步骤5
  48. ion.free(&rgb_ion);
  49. ion.free(&yuv_ion);
  50. ion.close();
  51. ::close(g2d_fd);
复制代码

G2D图像硬件YUV转RGB测试
考虑到dmaion buffer分配和释放都比较耗时,我们提前做好,循环调用步骤3的G2D转换,统计耗时,并在top工具中查看CPU占用率
  1. sh-4.4# LD_LIBRARY_PATH=. ./g2dtest
  2. INFO   : cedarc : register mjpeg decoder success!
  3. this device is not whitelisted for jpeg decoder cvi
  4. this device is not whitelisted for jpeg decoder cvi
  5. this device is not whitelisted for jpeg decoder cvi
  6. this device is not whitelisted for jpeg encoder rkmpp
  7. INFO   : cedarc : Set log level to 5 from /vendor/etc/cedarc.conf
  8. ERROR  : cedarc : now cedarc log level:5
  9. ERROR  : cedarc : now cedarc log level:5
  10. yuv420sp2rgb 46.61
  11. yuv420sp2rgb 42.04
  12. yuv420sp2rgb 41.32
  13. yuv420sp2rgb 42.06
  14. yuv420sp2rgb 41.69
  15. yuv420sp2rgb 42.05
  16. yuv420sp2rgb 41.29
  17. yuv420sp2rgb 41.30
  18. yuv420sp2rgb 42.14
  19. yuv420sp2rgb 41.33
  20. yuv420sp2rgb_neon 10.57
  21. yuv420sp2rgb_neon 7.21
  22. yuv420sp2rgb_neon 6.77
  23. yuv420sp2rgb_neon 8.31
  24. yuv420sp2rgb_neon 7.60
  25. yuv420sp2rgb_neon 6.80
  26. yuv420sp2rgb_neon 6.77
  27. yuv420sp2rgb_neon 7.01
  28. yuv420sp2rgb_neon 7.11
  29. yuv420sp2rgb_neon 7.06
  30. yuv420sp2rgb_g2d 4.32
  31. yuv420sp2rgb_g2d 4.69
  32. yuv420sp2rgb_g2d 4.56
  33. yuv420sp2rgb_g2d 4.57
  34. yuv420sp2rgb_g2d 4.52
  35. yuv420sp2rgb_g2d 4.54
  36. yuv420sp2rgb_g2d 4.52
  37. yuv420sp2rgb_g2d 4.58
  38. yuv420sp2rgb_g2d 4.60
  39. yuv420sp2rgb_g2d 4.67
复制代码

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

耗时(ms)
CPU占用率(%)
C41.3050
neon6.7750
g2d4.3212
3.png


转换结果对比和分析
C和neon的转换结果完全一致,但是g2d转换后的图片有明显的色差
4.png
5.png
6.png

G2D图形硬件只支持 G2D_BT601,G2D_BT709,G2D_BT2020 3种YUV系数,而JPG所使用的YUV系数是改版BT601,因此产生了色差
[color=var(--weui-LINK)]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的编解码,但依然适合摄像头和视频编解码的颜色空间转换

本文地址:https://www.eechina.com/thread-855095-1-1.html     【打印本页】

本站部分文章为转载或网友发布,目的在于传递和分享信息,并不代表本网赞同其观点和对其真实性负责;文章版权归原作者及原出处所有,如涉及作品内容、版权和其它问题,我们将根据著作权人的要求,第一时间更正或删除。
您需要登录后才可以发表评论 登录 | 立即注册

厂商推荐

关于我们  -  服务条款  -  使用指南  -  站点地图  -  友情链接  -  联系我们
电子工程网 © 版权所有   京ICP备16069177号 | 京公网安备11010502021702
快速回复 返回顶部 返回列表