<var id="fnfpo"><source id="fnfpo"></source></var>
<rp id="fnfpo"></rp>

<em id="fnfpo"><object id="fnfpo"><input id="fnfpo"></input></object></em>
<em id="fnfpo"><acronym id="fnfpo"></acronym></em>
  • <th id="fnfpo"><track id="fnfpo"></track></th>
  • <progress id="fnfpo"><track id="fnfpo"></track></progress>
  • <tbody id="fnfpo"><pre id="fnfpo"></pre></tbody>

  • 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






    全志 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://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



    轉換結果對比和分析
    C和neon的轉換結果完全一致,但是g2d轉換后的圖片有明顯的色差

    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的編解碼,但依然適合攝像頭和視頻編解碼的顏色空間轉換

    本文地址:http://www.portaltwn.com/thread-855095-1-1.html     【打印本頁】

    本站部分文章為轉載或網友發布,目的在于傳遞和分享信息,并不代表本網贊同其觀點和對其真實性負責;文章版權歸原作者及原出處所有,如涉及作品內容、版權和其它問題,我們將根據著作權人的要求,第一時間更正或刪除。
    您需要登錄后才可以發表評論 登錄 | 立即注冊

    廠商推薦

    • Microchip視頻專區
    • Dev Tool Bits——使用MPLAB® Discover瀏覽資源
    • Dev Tool Bits——使用條件軟件斷點宏來節省時間和空間
    • Dev Tool Bits——使用DVRT協議查看項目中的數據
    • Dev Tool Bits——使用MPLAB® Data Visualizer進行功率監視
    • 貿澤電子(Mouser)專區
    關于我們  -  服務條款  -  使用指南  -  站點地圖  -  友情鏈接  -  聯系我們
    電子工程網 © 版權所有   京ICP備16069177號 | 京公網安備11010502021702
    快速回復 返回頂部 返回列表
    精品一区二区三区自拍图片区_国产成人亚洲精品_亚洲Va欧美va国产综合888_久久亚洲国产精品五月天婷